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