algowin.h
changeset 1 67188bd752db
equal deleted inserted replaced
-1:000000000000 0:bcd39048f7ee
       
     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 ALGOWIN_H
       
    20 #define ALGOWIN_H
       
    21 
       
    22 #include <all_include.h>
       
    23 #include <libgnomecanvasmm.h>
       
    24 #include <libgnomecanvasmm/polygon.h>
       
    25 
       
    26 class AlgoBox;
       
    27 class MapStorage;
       
    28 
       
    29 ///Algorithm identifiers.
       
    30 enum {GENERAL, KRUSKAL, ALGO_NUM}; // algorithm IDs;
       
    31 
       
    32 ///Window displaying digraphical interface for different algorithms.
       
    33 
       
    34 ///This class displays a digraphical interface to set up
       
    35 ///and run different algorithms. Different algorithms need
       
    36 ///different inputs, running methods, etc. Therefore
       
    37 ///class \ref AlgoWin is only a holder of a base class, the so
       
    38 ///called AlgoBox. \ref AlgoBox is the ancestor of other
       
    39 ///classes. These child classes realize interfaces of different
       
    40 ///algorithms, but as their common ancestor is \ref AlgoBox
       
    41 ///the interface of them is the same. \ref AlgoWin communicates
       
    42 ///with these classes through this common interface. But it the
       
    43 ///real object to be placed in \ref AlgoWin depends on the algorithm
       
    44 ///which the \ref AlgoWin actually has to display. It gets the
       
    45 ///id of algorithm to display at initialization, and therefore it is
       
    46 ///able to place in itself the requested child of \ref AlgoBox
       
    47 /// visualizing the appropriate algorithm.
       
    48 class AlgoWin : public Gtk::Window
       
    49 {
       
    50 private:
       
    51   ///Algorithm specific part of \ref AlgoWin
       
    52   AlgoBox * ab;
       
    53 
       
    54   ///Run button.
       
    55 
       
    56   ///If pressed, algorithm should run.
       
    57   ///That is why common ancestor of different
       
    58   ///algorithm realizer classes have to be. In case of
       
    59   ///pressing run button a common method can be called.
       
    60   Gtk::Button * runbutton;
       
    61 
       
    62   ///Close button. If pressed, \ref AlgoWin should close.
       
    63   Gtk::Button * closebutton;
       
    64 
       
    65 protected:
       
    66   ///Signal emitted upon close of window
       
    67 
       
    68   ///It is necessary, because \ref MainWin have to
       
    69   ///score the opened \ref AlgoWin s, to be able to communicate
       
    70   ///with them: let them know about changement in tabs, maps, etc.
       
    71   ///If \ref AlgoWin is closed, \ref MainWin has to deregistrate it.
       
    72   ///Therefore signal contains address of emitter \ref AlgoWin.
       
    73   sigc::signal<void, AlgoWin *> signal_closed;
       
    74 
       
    75   ///Signal indicating that informatino on certain maplist is required.
       
    76 
       
    77   ///It is just a forwarded signal from \ref AlgoBox, benefit of common ancestor
       
    78   ///algorithm class. User can select the digraph (the holder \ref NoteBookTab) on
       
    79   ///which the algorithm should run. But different digraphs (\ref NoteBookTab) have
       
    80   ///different maps. If selected tab changes this signal is emitted by \ref AlgoBox,
       
    81   ///caught and reemitted by \ref AlgoWin.
       
    82   ///
       
    83   ///Signal contains the address of \ref AlgoWin to let \ref MainWin know
       
    84   ///where should the information needed forwarded, and the name of
       
    85   ///\ref NoteBookTab, of which maps are inquired.
       
    86   sigc::signal<void, AlgoWin *, std::string> signal_maplist_need;
       
    87 
       
    88   ///Signal that indicates that a \ref NewMapWin should be popped up.
       
    89 
       
    90   ///This is a forwarded signal. If \ref AlgoBox emits a signal
       
    91   ///to let a \ref NewMapWin pop up, |ref AlgoWin catch and reemit it.
       
    92   ///
       
    93   ///Signal contains the name of \ref NoteBookTab, in which the new map
       
    94   ///should be created and a boolean that indicates whether an arc or a
       
    95   ///nodemap should be created.
       
    96   sigc::signal<void, std::string, bool> signal_newmapwin_need;
       
    97 
       
    98 public:
       
    99   ///Close window if escape key is pressed.
       
   100   bool closeIfEscapeIsPressed(GdkEventKey* e);
       
   101 
       
   102   ///Returns \ref signal_closed to be bindable somewhere.
       
   103   sigc::signal<void, AlgoWin *> signal_closing();
       
   104 
       
   105   ///Returns \ref signal_maplist_need to be bindable somewhere.
       
   106   sigc::signal<void, AlgoWin *, std::string> signal_maplist_needed();
       
   107 
       
   108   ///Returns \ref signal_newmapwin_need to be bindable somewhere.
       
   109   sigc::signal<void, std::string, bool> signal_newmapwin_needed(){return signal_newmapwin_need;};
       
   110 
       
   111   ///Forwards signal emitted by \ref AlgoBox, in which it indicates changement in selection of tabs.
       
   112   void emit_tab_change(std::string);
       
   113 
       
   114   ///Forwards signal emitted by \ref AlgoBox, in which it indicates need for \ref NewMapWin.
       
   115   void emit_new_map_signal(std::string tabname, bool itisarc){signal_newmapwin_need.emit(tabname, itisarc);};
       
   116 
       
   117   ///Constructor
       
   118 
       
   119   ///It builds the window according to the information provided
       
   120   ///by the creator. It needs the identifier of the algorithm
       
   121   ///to visualize, and a list of name of \ref NoteBookTab s that can
       
   122   ///be found in \ref MainWin.
       
   123   ///\param algoid identifier of algorithm to show
       
   124   ///\param tablist list of tabs in \ref MainWin
       
   125   AlgoWin(int algoid, std::vector<std::string> tablist);
       
   126 
       
   127   ///Forwards list of \ref NoteBookTabs toward \ref AlgoBox
       
   128 
       
   129   ///In case of changement in tabs in \ref MainWin
       
   130   ///\ref MainWin automatically updates tablist in
       
   131   ///\ref AlgoWin s.
       
   132   void update_tablist(std::vector<std::string> tabnames);
       
   133 
       
   134   ///Forwards list of requested maps toward \ref AlgoBox
       
   135 
       
   136   ///Upon catching the signal in which \ref AlgoBox requests
       
   137   ///list of maps \ref MainWin responds
       
   138   ///through this function.
       
   139   void update_maplist(MapStorage *);
       
   140 
       
   141   ///Called when window is closing.
       
   142 
       
   143   ///\ref AlgoWin has to be deregistrated in \ref MainWin
       
   144   ///thereforeit emits signal \ref signal_closed.
       
   145   void on_hide();
       
   146 };
       
   147 #endif //ALGOWIN_H