main_win.h
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Mon, 07 Jul 2008 15:20:43 +0100
changeset 3 2cc5ed6e6255
permissions -rw-r--r--
Use hg changeset hash instead of svn revision.
     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 MAIN_WIN_H
    20 #define MAIN_WIN_H
    21 
    22 #include "all_include.h"
    23 #include <libgnomecanvasmm.h>
    24 #include <libgnomecanvasmm/polygon.h>
    25 #include <set>
    26 
    27 class AlgoWin;
    28 class NoteBookTab;
    29 
    30 ///This class is the main window of GUI.
    31 
    32 ///It has menus, and a notebook. Notebook has different pages,
    33 ///the so called tabs (\ref NoteBookTab). Each \ref NoteBookTab contains a canvas on which digraphs can be drawn.
    34 ///To manage creation and close of tabs and tabswitching is the task of MainWin.
    35 class MainWin : public Gtk::Window
    36 {
    37   ///Container in which the menus and the notebook is.
    38   //Gtk::VBox vbox;
    39   Gtk::Table table;
    40   Gtk::Table table2;
    41 
    42   ///Container in which the toolbar and the node parametrizer is.
    43   Gtk::HBox hbox;
    44 
    45   ///Should nodes be autoscaled or not?
    46   Gtk::CheckButton * auto_scale;
    47 
    48   ///Should node size track zoom factor?
    49   Gtk::CheckButton * zoom_track;
    50 
    51   ///Minimum and maximum node radius entry
    52   Gtk::SpinButton * radius_size, * arc_width;
    53 
    54   ///The notebook that has tabs (\ref NoteBookTab) with different digraphs.
    55   Gtk::Notebook notebook;
    56 
    57   ///The tool selected to manipulate digraph.
    58 
    59   ///It has to be stored, because in case of tabswitching
    60   ///the correct tool has to be set for the actual digraph.
    61   int active_tool;
    62 
    63   ///The number of active tab in the notebook.
    64   int active_tab;
    65 
    66   ///Vector of existing tabs in the notebook.
    67   std::vector<NoteBookTab *> tabs;
    68 
    69   ///Vector of the name of tabs.
    70 
    71   ///All \ref NoteBookTab has a name that is stored here. The index of the name
    72   ///is the same as the index of the \ref NoteBookTab in \ref tabs.
    73   std::vector<std::string> tabnames;
    74 
    75   ///Counter of occurence of the same file names.
    76 
    77   ///If a file is opened more than once we have to score
    78   ///the occurences to let the titles on tabs different.
    79   ///If more than one occurence is present, from the second
    80   ///one near the filename the number of the occurence appear.
    81   std::map<std::string, int> strinst;
    82 
    83   ///Set of opened \ref AlgoWin s.
    84 
    85   ///More than one \refAlgoWin can be opened. We have to
    86   ///communicate with them in case of new \ref NoteBookTab creation,
    87   ///\ref NoteBookTab close, or map change. Therefore we have to score
    88   ///their occurences.
    89   std::set< AlgoWin* > aws;
    90 
    91 public:
    92   
    93   ///Constructor of the \ref MainWin.
    94 
    95   ///It creates the menus, the toolbar and the notebook in which
    96   ///\ref NoteBookTab s take place. \ref NoteBookTab s are the
    97   ///holder of the canvases on which the digraphs are drawn.
    98   MainWin();
    99 
   100   ~MainWin();
   101   ///Sets title of tabs.
   102 
   103   ///It alse registrates it in \ref tabnames. If more than one
   104   ///occurence is in the notebook of the same file it has to
   105   ///extend tabname with the number of occurence.
   106   void set_tabtitle(std::string);
   107 
   108   ///ActionGroup for menu
   109   Glib::RefPtr<Gtk::ActionGroup> ag;
   110 
   111   ///UIManager for menu
   112   Glib::RefPtr<Gtk::UIManager> uim;
   113 
   114   ///Creates a new \ref NoteBookTab and opens the given file.
   115 
   116   ///It is called only with command line parameters at stratup.
   117   void readFile(const std::string &);
   118 
   119   ///Tooltips
   120   Gtk::Tooltips * tooltips;
   121 
   122   //Call-backs of buttons
   123 
   124   ///Callback for 'FileNew' action.
   125   virtual void newFile();
   126   ///Callback for 'FileOpen' action.
   127   virtual void openFile();
   128   ///Callback for 'FileSave' action.
   129   virtual void saveFile();
   130   ///Callback for 'FileSaveAs' action.
   131   virtual void saveFileAs();
   132   ///Callback for 'Close' action.
   133   virtual void close();
   134 
   135   //Toolbar
   136 
   137   ///Callback for 'zoomIn' action.
   138 
   139   ///It calls the appropriate function in
   140   ///\ref DigraphDisplayerCanvas
   141   virtual void zoomIn();
   142   ///Callback for 'zoomOut' action.
   143 
   144   ///It calls the appropriate function in
   145   ///\ref DigraphDisplayerCanvas
   146   virtual void zoomOut();
   147   ///Callback for 'zoomFit' action.
   148 
   149   ///It calls the appropriate function in
   150   ///\ref DigraphDisplayerCanvas
   151   virtual void zoomFit();
   152   ///Callback for 'zoom100' action.
   153 
   154   ///It calls the appropriate function in
   155   ///\ref DigraphDisplayerCanvas
   156   virtual void zoom100();
   157 
   158   ///Callback for Show Maps menupoint.
   159 
   160   ///It calls the appropriate function in
   161   ///\ref NoteBookTab
   162   virtual void createMapWin();
   163 
   164   ///Callback for Show Design menupoint.
   165 
   166   ///It calls the appropriate function in
   167   ///\ref NoteBookTab
   168   virtual void createDesignWin();
   169 
   170   ///Pops up an Algorithm window.
   171 
   172   ///It not only creates but registrates the newly created \ref AlgoWin.
   173   ///It is necessary, because in case of changement between tabs or maps
   174   ///we have to communicate with it. Signals are also have to be connected
   175   ///to it, because \ref AlgoWin emits signals if it needs anything (maplist, deregistration).
   176   ///\param algo type of the algorithm to run.
   177   virtual void createAlgoWin(int algo);
   178 
   179   ///Deregisters AlgoWin
   180 
   181   ///This is the function connected to the closing signal of \ref AlgoWin.
   182   ///It only deletes the sender \ref AlgoWin from \ref aws. This function
   183   ///is called only by the closing \ref AlgoWin itself.
   184   ///\param aw the \ref AlgoWin to delete.
   185   virtual void deRegisterAlgoWin(AlgoWin * aw);
   186 
   187   ///Updates list of tabs in all of the \ref AlgoWin
   188 
   189   ///When \ref NoteBookTab inserted somewhere or closed one tablist in all \ref AlgoWin
   190   ///have to be updated. That is why we score all the opened \ref AlgoWin.
   191   ///During update \ref tabnames will be passed to each \ref AlgoWin.
   192   virtual void updateAlgoWinTabs();
   193 
   194   ///Refresh list of maps in the AlgoWin that requested it.
   195 
   196   ///In an \ref AlgoWin there is a ComboBoxText, in which
   197   ///a \ref NoteBookTab can be chosen that contains the digraph and the maps,
   198   ///on which we would like to run algorithms. If we change the
   199   ///tab the available maps also have to be updated, because
   200   ///in the different tabs different maps are available. Therefore
   201   ///on tab change the \ref AlgoWin emits a signal that contains itself
   202   ///so that the appropriate maps can be sent to it. For the sake of simplicity
   203   ///the program answers this call with the mapstorage of the newly selected tab.
   204   ///\param aw the caller \ref AlgoWin
   205   ///\param tabname the newly selected tab in the \ref AlgoWin
   206   virtual void updateAlgoWinMaps(AlgoWin * aw, std::string tabname);
   207 
   208   ///Registrates the new digraph-editor tool in hand.
   209 
   210   ///The editor-tool in hand is global, it is the same for all tab
   211   ///at the same time. Therefore the active tool has to be scored here (\ref active_tool).
   212   ///This function is the callback function of the editor-tool buttons. It sets \ref active_tool
   213   ///to the correct value.
   214   ///\param tool the newly selected digraph-editor tool (See all_include.h)
   215   virtual void changeEditorialTool(int tool);
   216 
   217   ///Pops up a \ref NewMapWin dialog after requested by a \ref MapWin
   218 
   219   ///Each tab can pop-up a \ref MapWin. In \ref MapWin new tab can be created.
   220   ///In this case \ref NoteBookTab emits a signal. This function is connected to that signal.
   221   ///It sends the caller \ref NoteBookTab and whether an arcmap or a nodemap should be created.
   222   ///Caller \ref NoteBookTab is necessary for the window to be able to place the new map in its
   223   ///correct place.
   224   ///\param nbt the caller tab
   225   ///\param itisarc true if arcmap has to be created, false if nodemap
   226   virtual void createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisarc);
   227 
   228   ///Pops up a \ref NewMapWin dialog after requested by an \ref AlgoWin
   229 
   230   ///\ref AlgoWin can also can request a \ref NewMapWin to pop-up. 
   231   ///It emits a signal in this case. This function is bound to that signal.
   232   ///The signal contains the name of \ref NoteBookTab in which the new map has to be
   233   ///placed and whether the new map is an arcmap or a nodemap.
   234   ///\ref tabname the tab in which the new map has to be placed
   235   ///\ref itisarc true if the new map will be arc map, false if it will be nodemap
   236   virtual void createNewMapWinTabString(std::string tabname, bool itisarc);
   237 
   238   ///Pops up a \ref NewMapWin dialog if button on \ref MainWin has been pressed.
   239 
   240   ///In this case a general \ref NewMapWin will be popped up. This means that
   241   ///both arc and nodemap can be created by it. The new map will be placed in
   242   ///\MapStorage of the actual selected \ref NoteBookTab.
   243   virtual void createNewMapWin();
   244 
   245   //Notebook handlers
   246   ///Callback for 'FileNewTab' action.
   247   virtual void newTab();
   248 
   249   ///Callback for 'FileCloseTab' action.
   250 
   251   ///It closes the actual \ref NoteBookTab and registrates this event:
   252   ///data is shifted to the correct places in vectors.
   253   virtual void closeTab();
   254 
   255   ///Tabswitching handler
   256 
   257   ///Sets the variables that have to store the actual state, and it
   258   ///updates the title of window to the actually selected \ref NoteBookTab.
   259   virtual void onChangeTab(GtkNotebookPage*, guint);
   260 
   261   virtual void nodeViewChanged();
   262 
   263   virtual void reDesignDigraph();
   264 
   265   /// Pops up a SaveDetailsDialog.
   266   void createSaveDetailsDialog();
   267 
   268   virtual void exportToEPS();
   269 
   270   void createBackgroundChooser();
   271 };
   272 
   273 #endif //MAIN_WIN_H