algobox.h
changeset 3 2cc5ed6e6255
equal deleted inserted replaced
-1:000000000000 0:c5a62f927f95
       
     1 /* -*- C++ -*-
       
     2  *
       
     3  * This file is a part of LEMON, a generic C++ optimization library
       
     4  *
       
     5  * Copyright (C) 2003-2006
       
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
       
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
       
     8  *
       
     9  * Permission to use, modify and distribute this software is granted
       
    10  * provided that this copyright notice appears in all copies. For
       
    11  * precise terms see the accompanying LICENSE file.
       
    12  *
       
    13  * This software is provided "AS IS" with no warranty of any kind,
       
    14  * express or implied, and with no claim as to its suitability for any
       
    15  * purpose.
       
    16  *
       
    17  */
       
    18 
       
    19 #ifndef ALGOBOX_H
       
    20 #define ALGOBOX_H
       
    21 
       
    22 class MapStorage;
       
    23 class MapSelector;
       
    24 
       
    25 #include <all_include.h>
       
    26 #include <libgnomecanvasmm.h>
       
    27 #include <libgnomecanvasmm/polygon.h>
       
    28 #include "map_value.h"
       
    29 
       
    30 ///Ancestor class of algorithm digraphical interface classes.
       
    31 
       
    32 ///It also demonstrates, how should an algorithm digraphical interface
       
    33 ///work. Children of this class have the same functions and attributes,
       
    34 ///therefore with all of them can the holder \ref AlgoWin communicate
       
    35 ///in the same way.
       
    36 ///
       
    37 ///IMPORTANT! In a child class only the following tasks are to do:
       
    38 ///
       
    39 ///-call \ref init function with correct parameters from correctly parametrized constructor
       
    40 ///
       
    41 ///-implement \ref build_box function
       
    42 ///
       
    43 ///-implement \ref run function
       
    44 ///
       
    45 ///because all other thing is automatically done in \ref init function!
       
    46 
       
    47 class AlgoBox : public Gtk::VBox
       
    48 {
       
    49   ///Signal emitted in case of need for list of maps.
       
    50 
       
    51   ///If the user has selected different tab to work on
       
    52   ///new maps are selected as well. These new maps should be
       
    53   ///provided for \ref AlgoBox. To get these maps, \ref AlgoBox
       
    54   ///emits this signal.
       
    55   sigc::signal<void, std::string> signal_maplist_need;
       
    56 
       
    57   ///Signal emitted in case of need for \ref NewMapWin.
       
    58 
       
    59   ///If user wants to create a new for an input, or output
       
    60   ///it can let \ref NewMapWin popped up from here as well.
       
    61   ///In that case will be this signal emitted.
       
    62   sigc::signal<void, std::string, bool> signal_newmapwin_need;
       
    63 
       
    64   ///Signal emitted when maplists are updated after tab change
       
    65   sigc::signal<void> signal_maplist_updated;
       
    66 
       
    67 
       
    68 protected:
       
    69   ///Holder of tabnames.
       
    70   Gtk::ComboBoxText tabcbt;
       
    71 
       
    72   ///Holder of widgets, in which nodemaps can be selected to work on.
       
    73   std::vector<MapSelector *> nodemapcbts;
       
    74 
       
    75   ///Holder of widgets, in which arcmaps can be selected to work on.
       
    76   std::vector<MapSelector *> arcmapcbts;
       
    77 
       
    78   ///Maps of selected tabs.
       
    79   MapStorage * mapstorage;
       
    80 
       
    81 public:
       
    82   ///Empty constructor called by children.
       
    83   AlgoBox(){};
       
    84 
       
    85   ///Constructor
       
    86 
       
    87   ///Calls \ref init function
       
    88   ///with the provided parameters. \ref init function
       
    89   ///is needed, because it is virtual, therefore the
       
    90   ///functions of the proper class will be called when
       
    91   ///running.
       
    92   ///\param tablist list of tabs in \ref MainWin
       
    93   AlgoBox(std::vector<std::string> tablist);
       
    94 
       
    95   ///Initiates \ref AlgoBox.
       
    96 
       
    97   ///Creates the digraphical interface for the realized algorithm, initiates variables, connects signals.
       
    98   ///
       
    99   ///List of tabs in \ref MainWin is required, but no one
       
   100   ///will be selected automatically. Every other
       
   101   ///entry field remains empty (unselected), until a \ref NoteBookTab
       
   102   ///is selected.
       
   103   ///
       
   104   ///It also have to bind all the signals to the correct place.
       
   105   ///This function is virtual, in all type of children of
       
   106   ///\ref AlgoBox the correct function willbe called.
       
   107   ///
       
   108   ///Therefore it is IMPORTANT that only \ref run and \ref build_box
       
   109   ///has to be implemented in children of \ref AlgoBox, every other
       
   110   ///thing will automatically work properly by the help of this
       
   111   ///function that must be called in constructor of child!!!
       
   112   virtual void init(std::vector<std::string>);
       
   113 
       
   114   ///Signal emitted, when selected tab changes, and new list of maps required.
       
   115   sigc::signal<void, std::string> signal_maplist_needed();
       
   116 
       
   117   ///Emitted if user wants to create a new map for inpuit or output.
       
   118   sigc::signal<void, std::string, bool> signal_newmapwin_needed(){return signal_newmapwin_need;};
       
   119 
       
   120   sigc::signal<void> signal_upon_maplist_updated(){return signal_maplist_updated;};
       
   121 
       
   122   ///Emits signal that requires list of maps for the recently selected \ref NoteBookTab.
       
   123   void emit_tab_change();
       
   124 
       
   125   ///Interface, through which \ref AlgoBox can be notified about tab addition, deletion in \ref MainWin
       
   126 
       
   127   ///\param tl list
       
   128   ///of new tab state.
       
   129   void update_tablist( std::vector< std::string > tl );
       
   130 
       
   131   ///Interface, through which \ref AlgoBox can get the maps of the recently selected \ref NoteBookTab
       
   132 
       
   133   ///\param ms the maps
       
   134   ///of the recently selected \ref NoteBookTab
       
   135   void update_maplist( MapStorage * ms);
       
   136 
       
   137   ///Interface, through which \ref AlgoBox can be notified about nodemap addition.
       
   138 
       
   139   ///If new map was added to \ref MapStorage of currently selected \ref NoteBookTab
       
   140   ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s
       
   141   ///in \ref nodemapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text)
       
   142   void nodemaplist_changed(std::string, MapValue::Type);
       
   143 
       
   144   ///Interface, through which \ref AlgoBox can be notified about arcmap addition.
       
   145 
       
   146   ///If new map was added to \ref MapStorage of currently selected \ref NoteBookTab
       
   147   ///a signal is emitted by it. This signal is connected to this function, so \ref MapSelector s
       
   148   ///in \ref arcmapcbts can be notified, and those can registrate the new map. (\ref MapSelector::append_text)
       
   149   void arcmaplist_changed(std::string, MapValue::Type);
       
   150 
       
   151   ///Aid function to provide data for a given entry.
       
   152 
       
   153   ///At the moment it is only used for updating info
       
   154   ///in \ref tabcbt. It clears it first, after that
       
   155   ///inserts the data got from caller, and if there
       
   156   ///was previously selected item it switches entry
       
   157   ///to that.
       
   158   ///\param tl list of entries (at the moment tabs in \ref MainWin)
       
   159   ///\param cbt the entry to update (at the moment only \ref tabcbt)
       
   160   void update_cbt( std::vector< std::string > tl, Gtk::ComboBoxText & cbt);
       
   161 
       
   162   ///Runs the ralized algorithm.
       
   163 
       
   164   ///Prepare the data for it
       
   165   ///and after that postprocess it if necessary.
       
   166   ///This is only a demo here, but in children it
       
   167   ///runs the algorithm really.
       
   168   virtual void run();
       
   169 
       
   170   ///Creates the layout of the \ref AlgoBox
       
   171 
       
   172   ///Place all the entries
       
   173   ///required. Run and close button is not
       
   174   ///its responsibility!
       
   175   virtual void build_box();
       
   176 
       
   177   ///Emits \ref signal_newmapwin_need if user wants to create new input or output map.
       
   178 
       
   179   ///Called in case of pressing \ref MapSelector::newbut.
       
   180   ///\param itisarc arc or nodemap is required.
       
   181   virtual void emit_new_map_signal(bool itisarc);
       
   182 
       
   183   ///Aid function to make addition of \ref MapSelector easy in \ref build_box.
       
   184 
       
   185   ///\param label label to show in \ref MapSelector
       
   186   ///\param itisarc whether arc or nodemaps stored in \ref MapSelector
       
   187   void addMapSelector(std::string label, bool itisarc, MapType type = ALL);
       
   188 };
       
   189 #endif //ALGOBOX_H