File : plot_windows.ads


-----------------------------------------------------------------------
--                              Win_IO                               --
--     A simple set of packages for graphical input and output       --
--                                                                   --
--                       Copyright (C) 2001-2010                     --
--                 Universidad de Cantabria, SPAIN                   --
--                                                                   --
-- Author: Michael Gonzalez       mgh@unican.es                      --
--                                                                   --
-- This is free software; you can redistribute it and/or             --
-- modify it under the terms of the GNU General Public               --
-- License as published by the Free Software Foundation; either      --
-- version 2 of the License, or (at your option) any later version.  --
--                                                                   --
-- This software is distributed in the hope that it will be useful,  --
-- but WITHOUT ANY WARRANTY; without even the implied warranty of    --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU --
-- General Public License for more details.                          --
--                                                                   --
-- You should have received a copy of the GNU General Public         --
-- License along with this program; if not, write to the             --
-- Free Software Foundation, Inc., 59 Temple Place - Suite 330,      --
-- Boston, MA 02111-1307, USA.                                       --
--                                                                   --
-----------------------------------------------------------------------
--                                                                   --
-- The Plot_Windows package provides a simple window for drawing     --
-- two-dimensional graphs from sets of points                        --
--                                                                   --
-- This package requires Gtkada-2.2.0 or later                       --
--                                                                   --
-----------------------------------------------------------------------

with Plot_Window_Pkg; use Plot_Window_Pkg;
with Gtk.Extra.Plot; use Gtk.Extra.Plot;
with Gtk.Extra.Plot_Canvas; use Gtk.Extra.Plot_Canvas;
with Gtk.Extra.Plot_Data; use Gtk.Extra.Plot_Data;
with Gdk.Window; use Gdk.Window;
with Indexed_Lists;

package Plot_Windows is

   Max_Graphs : constant Integer:=5; -- Maximum graphs in a plot window

   -----------------------------------------------------------------------
   --
   --                           PLOT_WINDOW
   --
   --  A Plot Window provides an area for displaying several graphs
   --  each derived from a set of points.
   --  It also provides an OK button for which a Wait operation is
   --  provided.
   --
   --  A Plot Window has an associated title, X Axis title and Y Axis title
   --
   --  Each Graph has a set of points and the following attributes:
   --  a title, a colour, a symbol, and the line style property which
   --  can be true (with lines) or false (without lines).
   --  Operations are provided to add points to the set
   --  and to change each of the attributes.
   --  Another operation, New_Graph, is used to switch to a new graph once
   --  the previous one has been built.
   --
   -----------------------------------------------------------------------

   type Plot_Window_Type is private;

   -----------------------------------------------------------------------
   --                         PLOT_WINDOW Operations
   --
   --    Plot_Window     (Plot_Title,   -- Creates a new Plot window with
   --                     X_Axis_Title, -- the specified title and axes
   --                     Y_Axis_Title) -- titles. The first graph in this
   --                                   -- plot will be ready to accept
   --                                   -- points and attribute changes
   --
   --    Add_Point       (Plot,         -- Adds a point to the current graph
   --                     X,Y)          -- (X,Y) are the coordinates
   --
   --    Wait            (Plot)         -- Draws the graphs in the plot_Window
   --                                   -- and then waits for the OK button
   --                                   -- to be pressed. Then, it hides the
   --                                   -- window
   --
   --    New_Graph       (Plot)         -- Switches to a new graph. All
   --                                   -- subsequent operations to add points
   --                                   -- or set graph attributes will refer
   --                                   -- to the new graph
   --                                   -- may raise Too_Many_Graphs if
   --                                   -- Max_Graphs is exceeded
   --
   --    Set_Colour      (Plot,         -- Sets the colour of the current graph
   --                     Colour)       -- to this value.
   --
   --    Set_Color       (Plot,         -- Same as above
   --                     Colour)
   --
   --    Set_Symbol      (Plot,         -- Sets the symbol of the current graph
   --                     Symbol)       -- to this value
   --
   --    Set_Lines       (Plot,         -- Sets the lines attribute of the
   --                     With_Lines)   -- current graph. If true, lines will
   --                                   -- be drawn between points.
   --
   --    Set_Graph_Title (Plot,         -- Sets the title of the current graph
   --                     Graph_Title)  -- to this value
   --
   -----------------------------------------------------------------------

   function Plot_Window
     (Plot_Title, X_Axis_Title, Y_Axis_Title : String)
     return Plot_Window_Type;

   procedure Add_Point (Plot : in out Plot_Window_Type; X,Y : in Float);

   procedure Wait (Plot : in out Plot_Window_Type);

   procedure New_Graph (Plot : in out Plot_Window_Type);
   -- may raise Too_Many_Graphs

   type Colour_Type is (Black, White, Red, Green, Blue,
                        Gray, Yellow, Cyan, Magenta);

   subtype Color_Type is Colour_Type;

   procedure Set_Colour (Plot : in out Plot_Window_Type; Colour : Colour_Type);

   procedure Set_Color (Plot : in out Plot_Window_Type; Color : Color_Type)
     renames Set_Colour;

   type Symbol_Type is (No_Symbol, Square, Circle,
                        Up_Triangle, Down_Triangle);

   procedure Set_Symbol (Plot : in out Plot_Window_Type;
                         Symbol : Symbol_Type);

   procedure Set_Lines (Plot : in out Plot_Window_Type;
                        With_Lines : Boolean);

   procedure Set_Graph_Title (Plot : in out Plot_Window_Type;
                              Graph_Title : String);

   Too_Many_Graphs : exception;

private

   subtype Num_Graph is Integer range 1..Max_Graphs;

   type String_Ptr is access all String;

   type Point is record
      X,Y : Float;
   end record;

   package Lists is new Indexed_Lists(Point,"=");

   type Plot_Data_Record is record
      Dataset : Gtk_Plot_Data;
      DataX, DataY, DataDX, DataDy : Gdouble_Array_Access;
      Point_List : Lists.List;
      Graph_Colour : Colour_Type;
      Graph_Symbol : Symbol_Type;
      Lines : Boolean;
      Title : String_Ptr;
   end record;

   type Plot_Data_Array is array(Num_Graph) of Plot_Data_Record;

   type Plot_Window_Type is record
      Win : Plot_Window_Access;
      Canvas : Gtk_Plot_Canvas;
      Plot : Gtk_Plot;
      Gdkw : Gdk.Window.Gdk_Window;
      Plot_Data : Plot_Data_Array;
      Current : Integer range 0..Max_Graphs:=0;
      Last_Drawn : Integer range 0..Max_Graphs:=0;
   end record;

end Plot_Windows;