main_win.cc
author hegyi
Tue, 20 Feb 2007 17:45:44 +0000
changeset 190 2cac5b936a2b
parent 184 4e8704aae278
child 191 af2ed974ab68
permissions -rw-r--r--
Working tooltips are added. No segmentation fault is occured if empty graphs are redesigned.
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
 */
alpar@174
    18
ladanyi@130
    19
#ifdef HAVE_CONFIG_H
ladanyi@130
    20
#include <config.h>
ladanyi@130
    21
#endif
ladanyi@130
    22
ladanyi@53
    23
#include "main_win.h"
ladanyi@100
    24
#include "guipixbufs.h"
ladanyi@184
    25
#include "background_chooser_dialog.h"
ladanyi@6
    26
ladanyi@133
    27
#include "i18n.h"
ladanyi@130
    28
hegyi@96
    29
MainWin::MainWin()
ladanyi@6
    30
{
hegyi@96
    31
  set_title ("no file");
ladanyi@6
    32
  set_default_size(WIN_WIDTH,WIN_HEIGHT);
hegyi@154
    33
  //add(vbox);
hegyi@154
    34
  add(table);
ladanyi@6
    35
ladanyi@60
    36
  // custom icons for the toolbar
ladanyi@60
    37
  Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
ladanyi@60
    38
 
ladanyi@61
    39
  Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@61
    40
      2328, gui_icons_move);
ladanyi@61
    41
  Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@61
    42
      2328, gui_icons_addnode);
ladanyi@61
    43
  Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@61
    44
      2328, gui_icons_addlink);
ladanyi@61
    45
  Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@61
    46
      2328, gui_icons_delete);
ladanyi@61
    47
  Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@61
    48
      2328, gui_icons_editlink);
ladanyi@61
    49
  Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
ladanyi@61
    50
      2328, gui_icons_newmap);
ladanyi@60
    51
ladanyi@60
    52
  Gtk::IconSource move_icon_source;
ladanyi@61
    53
  move_icon_source.set_pixbuf(p_move_pixbuf);
ladanyi@60
    54
  Gtk::IconSet move_icon_set;
ladanyi@60
    55
  move_icon_set.add_source(move_icon_source);
ladanyi@60
    56
  p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
ladanyi@60
    57
ladanyi@60
    58
  Gtk::IconSource addnode_icon_source;
ladanyi@61
    59
  addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
ladanyi@60
    60
  Gtk::IconSet addnode_icon_set;
ladanyi@60
    61
  addnode_icon_set.add_source(addnode_icon_source);
ladanyi@60
    62
  p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
ladanyi@60
    63
ladanyi@60
    64
  Gtk::IconSource addlink_icon_source;
ladanyi@61
    65
  addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
ladanyi@60
    66
  Gtk::IconSet addlink_icon_set;
ladanyi@60
    67
  addlink_icon_set.add_source(addlink_icon_source);
ladanyi@60
    68
  p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
ladanyi@60
    69
ladanyi@60
    70
  Gtk::IconSource delete_icon_source;
ladanyi@61
    71
  delete_icon_source.set_pixbuf(p_delete_pixbuf);
ladanyi@60
    72
  Gtk::IconSet delete_icon_set;
ladanyi@60
    73
  delete_icon_set.add_source(delete_icon_source);
ladanyi@60
    74
  p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
ladanyi@60
    75
ladanyi@60
    76
  Gtk::IconSource editlink_icon_source;
ladanyi@61
    77
  editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
ladanyi@60
    78
  Gtk::IconSet editlink_icon_set;
ladanyi@60
    79
  editlink_icon_set.add_source(editlink_icon_source);
ladanyi@60
    80
  p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
ladanyi@60
    81
ladanyi@60
    82
  Gtk::IconSource newmap_icon_source;
ladanyi@61
    83
  newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
ladanyi@60
    84
  Gtk::IconSet newmap_icon_set;
ladanyi@60
    85
  newmap_icon_set.add_source(newmap_icon_source);
ladanyi@60
    86
  p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
ladanyi@60
    87
ladanyi@60
    88
  p_icon_factory->add_default();
ladanyi@60
    89
  
ladanyi@6
    90
  ag=Gtk::ActionGroup::create();
ladanyi@6
    91
ladanyi@130
    92
  ag->add( Gtk::Action::create("FileMenu", _("_File")) );
hegyi@102
    93
  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
hegyi@96
    94
      sigc::mem_fun(*this, &MainWin::newTab));
ladanyi@6
    95
  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
ladanyi@6
    96
      sigc::mem_fun(*this, &MainWin::openFile));
ladanyi@130
    97
  ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
hegyi@102
    98
      sigc::mem_fun(*this, &MainWin::newFile));
ladanyi@6
    99
  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
ladanyi@6
   100
      sigc::mem_fun(*this, &MainWin::saveFile));
ladanyi@6
   101
  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
ladanyi@6
   102
      sigc::mem_fun(*this, &MainWin::saveFileAs));
ladanyi@53
   103
  ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
hegyi@102
   104
      sigc::mem_fun(*this, &MainWin::closeTab));
ladanyi@53
   105
  ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
hegyi@47
   106
      sigc::mem_fun(*this, &MainWin::hide));
ladanyi@6
   107
ladanyi@130
   108
  ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
ladanyi@6
   109
  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
hegyi@96
   110
      sigc::mem_fun(*this, &MainWin::zoomIn));
ladanyi@6
   111
  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
hegyi@96
   112
      sigc::mem_fun(*this, &MainWin::zoomOut));
ladanyi@6
   113
  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
hegyi@96
   114
      sigc::mem_fun(*this, &MainWin::zoomFit));
ladanyi@6
   115
  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
hegyi@96
   116
      sigc::mem_fun(*this, &MainWin::zoom100));
ladanyi@184
   117
  ag->add( Gtk::Action::create("SetBackground", _("Set Background...")),
ladanyi@184
   118
	    sigc::mem_fun(*this, &MainWin::createBackgroundChooser));
ladanyi@6
   119
  
ladanyi@130
   120
  ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
ladanyi@130
   121
  ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
hegyi@95
   122
	   sigc::mem_fun(*this, &MainWin::createMapWin));
hegyi@160
   123
  ag->add( Gtk::Action::create("ShowDesign", _("_Design")),
hegyi@160
   124
	   sigc::mem_fun(*this, &MainWin::createDesignWin));
ladanyi@6
   125
ladanyi@130
   126
  ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
ladanyi@130
   127
  ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
hegyi@103
   128
	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
ladanyi@130
   129
  ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
hegyi@106
   130
	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
hegyi@162
   131
  ag->add( Gtk::Action::create("AlgoDijkstra", _("_Dijkstra")),
hegyi@162
   132
	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 2) );
hegyi@165
   133
  ag->add( Gtk::Action::create("AlgoSuurballe", _("_Suurballe")),
hegyi@165
   134
	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 3) );
hegyi@103
   135
ladanyi@53
   136
  Gtk::RadioAction::Group tool_group;
ladanyi@130
   137
  ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
hegyi@96
   138
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
ladanyi@130
   139
  ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
hegyi@96
   140
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
ladanyi@130
   141
  ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")),
hegyi@96
   142
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
ladanyi@130
   143
  ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
hegyi@96
   144
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
ladanyi@60
   145
ladanyi@130
   146
  ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")),
hegyi@96
   147
      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
ladanyi@60
   148
ladanyi@60
   149
  ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
hegyi@96
   150
      sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
hegyi@22
   151
hegyi@160
   152
  ag->add( Gtk::Action::create("DesignGraph", Gtk::Stock::REFRESH),
hegyi@160
   153
      sigc::mem_fun ( *this , &MainWin::reDesignGraph ) );
hegyi@160
   154
ladanyi@6
   155
  uim=Gtk::UIManager::create();
ladanyi@6
   156
  uim->insert_action_group(ag);
ladanyi@6
   157
  add_accel_group(uim->get_accel_group());
ladanyi@6
   158
ladanyi@6
   159
  try
ladanyi@6
   160
  {
ladanyi@6
   161
ladanyi@6
   162
    Glib::ustring ui_info =
ladanyi@6
   163
      "<ui>"
ladanyi@6
   164
      "  <menubar name='MenuBar'>"
ladanyi@6
   165
      "    <menu action='FileMenu'>"
ladanyi@6
   166
      "      <menuitem action='FileNew'/>"
ladanyi@6
   167
      "      <menuitem action='FileOpen'/>"
hegyi@102
   168
      "      <menuitem action='FileClearTab'/>"
ladanyi@6
   169
      "      <menuitem action='FileSave'/>"
ladanyi@6
   170
      "      <menuitem action='FileSaveAs'/>"
ladanyi@53
   171
      "      <menuitem action='Close'/>"
ladanyi@53
   172
      "      <menuitem action='Quit'/>"
ladanyi@6
   173
      "    </menu>"
ladanyi@6
   174
      "    <menu action='ViewMenu'>"
ladanyi@6
   175
      "      <menuitem action='ViewZoomIn' />"
ladanyi@6
   176
      "      <menuitem action='ViewZoomOut' />"
ladanyi@6
   177
      "      <menuitem action='ViewZoom100' />"
ladanyi@87
   178
      "      <menuitem action='ViewZoomFit' />"
ladanyi@184
   179
      "      <menuitem action='SetBackground' />"
ladanyi@6
   180
      "    </menu>"
ladanyi@6
   181
      "    <menu action='ShowMenu'>"
ladanyi@6
   182
      "      <menuitem action='ShowMaps'/>"
hegyi@160
   183
      "      <menuitem action='ShowDesign'/>"
ladanyi@6
   184
      "    </menu>"
hegyi@103
   185
      "    <menu action='AlgoMenu'>"
hegyi@103
   186
      "      <menuitem action='AlgoGeneral'/>"
hegyi@106
   187
      "      <menuitem action='AlgoKruskal'/>"
hegyi@162
   188
      "      <menuitem action='AlgoDijkstra'/>"
hegyi@165
   189
      "      <menuitem action='AlgoSuurballe'/>"
hegyi@103
   190
      "    </menu>"
ladanyi@6
   191
      "  </menubar>"
ladanyi@6
   192
      "  <toolbar name='ToolBar'>"
ladanyi@6
   193
      "    <toolitem action='FileNew' />"
ladanyi@6
   194
      "    <toolitem action='FileOpen' />"
ladanyi@6
   195
      "    <toolitem action='FileSave' />"
ladanyi@53
   196
      "    <toolitem action='Close' />"
ladanyi@6
   197
      "    <separator />"
ladanyi@6
   198
      "    <toolitem action='ViewZoomIn' />"
ladanyi@6
   199
      "    <toolitem action='ViewZoomOut' />"
ladanyi@6
   200
      "    <toolitem action='ViewZoom100' />"
ladanyi@87
   201
      "    <toolitem action='ViewZoomFit' />"
hegyi@22
   202
      "    <separator />"
ladanyi@53
   203
      "    <toolitem action='MoveItem' />"
hegyi@22
   204
      "    <toolitem action='CreateNode' />"
hegyi@22
   205
      "    <toolitem action='CreateEdge' />"
hegyi@22
   206
      "    <toolitem action='EraseItem' />"
hegyi@32
   207
      "    <toolitem action='EditEdgeMap' />"
ladanyi@60
   208
      "    <separator />"
hegyi@41
   209
      "    <toolitem action='AddMap' />"
hegyi@160
   210
      "    <toolitem action='DesignGraph' />"
ladanyi@6
   211
      "  </toolbar>"
ladanyi@6
   212
      "</ui>";
ladanyi@6
   213
ladanyi@6
   214
    uim->add_ui_from_string(ui_info);
ladanyi@6
   215
ladanyi@6
   216
  }
ladanyi@6
   217
  catch(const Glib::Error& ex)
ladanyi@6
   218
  {
ladanyi@6
   219
    std::cerr << "building menus failed: " <<  ex.what();
ladanyi@6
   220
  }
ladanyi@6
   221
ladanyi@6
   222
  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
ladanyi@6
   223
  if (menubar){
hegyi@154
   224
    //vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
hegyi@154
   225
    table.attach(*menubar, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
ladanyi@6
   226
  }
ladanyi@6
   227
ladanyi@6
   228
  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
ladanyi@6
   229
  if (toolbar)
ladanyi@6
   230
  {
ladanyi@6
   231
    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
hegyi@190
   232
    static_cast<Gtk::Toolbar*>(toolbar)->set_tooltips(true);
hegyi@154
   233
    //hbox.pack_start(*toolbar, Gtk::PACK_EXPAND_WIDGET);
hegyi@154
   234
hegyi@154
   235
    table.attach(*toolbar, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
hegyi@154
   236
ladanyi@6
   237
  }
hegyi@156
   238
 
hegyi@154
   239
  table2.set_row_spacings(10);
hegyi@154
   240
  table2.set_col_spacings(5);
hegyi@154
   241
hegyi@156
   242
  auto_scale = new Gtk::CheckButton("Autoscale");
hegyi@156
   243
  auto_scale->set_active(false);
hegyi@156
   244
  auto_scale->signal_toggled().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
hegyi@154
   245
  table2.attach(*auto_scale, 0,2,0,1);
hegyi@156
   246
hegyi@157
   247
  Gtk::Label * width_label= new Gtk::Label("Edge Width:");
hegyi@157
   248
  table2.attach(*width_label, 0,1,1,2);
hegyi@154
   249
  
hegyi@157
   250
  Gtk::Adjustment * adjustment_width=new Gtk::Adjustment(20, 1, 200, 5, 10);
hegyi@157
   251
  
hegyi@157
   252
  edge_width = new Gtk::SpinButton(*adjustment_width, 5,0);
hegyi@157
   253
  edge_width->signal_value_changed().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
hegyi@157
   254
  table2.attach(*edge_width, 1,2,1,2);
hegyi@154
   255
hegyi@157
   256
  Gtk::Label * radius_label= new Gtk::Label("Node Radius:");
hegyi@157
   257
  table2.attach(*radius_label, 2,3,1,2);
hegyi@157
   258
  
hegyi@157
   259
  Gtk::Adjustment * adjustment_radius=new Gtk::Adjustment(20, 0, 500, 5, 10);
hegyi@154
   260
hegyi@157
   261
  radius_size = new Gtk::SpinButton(*adjustment_radius, 5,0);
hegyi@157
   262
  radius_size->signal_value_changed().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
hegyi@157
   263
  table2.attach(*radius_size, 3,4,1,2);
hegyi@154
   264
hegyi@156
   265
  zoom_track = new Gtk::CheckButton("Zoom tracking");
hegyi@156
   266
  zoom_track->set_active(false);
hegyi@156
   267
  zoom_track->signal_toggled().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
hegyi@156
   268
  table2.attach(*zoom_track, 2,4,0,1);
hegyi@156
   269
hegyi@156
   270
hegyi@154
   271
  table.attach(table2, 1, 2, 0, 2, Gtk::SHRINK, Gtk::SHRINK);
hegyi@154
   272
hegyi@190
   273
  tooltips=Gtk::manage(new Gtk::Tooltips());
hegyi@190
   274
  if(tooltips)
hegyi@190
   275
    {
hegyi@190
   276
      tooltips->set_tip(*zoom_track, "If on, edge widths and node radiuses are constant, independent from zooming");
hegyi@190
   277
      tooltips->set_tip(*auto_scale, "If on, glemon automatically determines the size of edges and nodes");
hegyi@190
   278
      tooltips->set_tip(*radius_size, "Sets maximum node radius, if auto-scale is off");
hegyi@190
   279
      tooltips->set_tip(*edge_width, "Sets maximum edge width, if auto-scale is off");
hegyi@190
   280
hegyi@190
   281
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileNew"))->set_tooltip(*tooltips, "Inserts new tab");
hegyi@190
   282
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileOpen"))->set_tooltip(*tooltips, "Lets you open a file");
hegyi@190
   283
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileSave"))->set_tooltip(*tooltips, "Saves the graph on the active tab");
hegyi@190
   284
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/Close"))->set_tooltip(*tooltips, "Closes the active tab");
hegyi@190
   285
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomIn"))->set_tooltip(*tooltips, "Zoom in the graph");
hegyi@190
   286
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomOut"))->set_tooltip(*tooltips, "Zoom out the graph");
hegyi@190
   287
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoom100"))->set_tooltip(*tooltips, "Shows actual size of graph");
hegyi@190
   288
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomFit"))->set_tooltip(*tooltips, "Fits graph into window");
hegyi@190
   289
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/MoveItem"))->set_tooltip(*tooltips, "Moves the clicked item (edge/node)");
hegyi@190
   290
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/CreateNode"))->set_tooltip(*tooltips, "Adds new node");
hegyi@190
   291
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/CreateEdge"))->set_tooltip(*tooltips, "Lets you create new edge");
hegyi@190
   292
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/EraseItem"))->set_tooltip(*tooltips, "Erases the clicked item (edge/node)");
hegyi@190
   293
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/EditEdgeMap"))->set_tooltip(*tooltips, "Lets you edit the values written on the items");
hegyi@190
   294
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/AddMap"))->set_tooltip(*tooltips, "Adds edge/nodemap");
hegyi@190
   295
      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/DesignGraph"))->set_tooltip(*tooltips, "Redesigns your graph, supposing elastic edges and propulsation of nodes.");
hegyi@190
   296
hegyi@190
   297
      tooltips->enable();
hegyi@190
   298
    }
ladanyi@6
   299
hegyi@96
   300
  active_tab=-1;
hegyi@96
   301
  notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
hegyi@96
   302
ladanyi@107
   303
  active_tool = MOVE;
ladanyi@107
   304
hegyi@154
   305
  table.attach(notebook,0,2,2,3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL);
hegyi@96
   306
  
ladanyi@6
   307
  show_all_children();
ladanyi@6
   308
}
ladanyi@6
   309
hegyi@96
   310
void MainWin::set_tabtitle(std::string name)
ladanyi@57
   311
{
hegyi@104
   312
  if(strinst.find(name)==strinst.end())
hegyi@104
   313
    {
hegyi@104
   314
      tabnames[active_tab]=name;
hegyi@104
   315
      strinst[name]=1;
hegyi@104
   316
    }
hegyi@104
   317
  else
hegyi@104
   318
    {
hegyi@104
   319
      strinst[name]++;
hegyi@104
   320
      std::ostringstream o;
hegyi@104
   321
      o << strinst[name];
hegyi@104
   322
      tabnames[active_tab]=name+" - "+o.str();
hegyi@104
   323
    }
hegyi@96
   324
  set_title(tabnames[active_tab] + " - " + prog_name);
hegyi@96
   325
  notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
hegyi@106
   326
  updateAlgoWinTabs();
hegyi@96
   327
}
hegyi@96
   328
hegyi@96
   329
void MainWin::readFile(const std::string & filename)
hegyi@96
   330
{
hegyi@96
   331
  newTab();
hegyi@96
   332
  tabs[active_tab]->readFile(filename);
hegyi@96
   333
}
hegyi@96
   334
hegyi@96
   335
void MainWin::newTab()
hegyi@96
   336
{
hegyi@96
   337
  int size=tabs.size();
hegyi@96
   338
  tabs.resize(size+1);
hegyi@96
   339
  tabnames.resize(size+1);
hegyi@96
   340
  active_tab=size;
hegyi@96
   341
  tabs[active_tab]=new NoteBookTab();
hegyi@96
   342
  tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
hegyi@96
   343
  tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
hegyi@96
   344
  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
hegyi@96
   345
  notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
hegyi@96
   346
  notebook.set_current_page(size);
ladanyi@130
   347
  set_tabtitle(_("unsaved file"));
hegyi@106
   348
  updateAlgoWinTabs();
hegyi@96
   349
}
hegyi@96
   350
hegyi@97
   351
void MainWin::closeTab()
hegyi@97
   352
{
hegyi@97
   353
  if(active_tab!=-1)
hegyi@97
   354
    {
hegyi@102
   355
      if (tabs[active_tab]->mapstorage.modified)
hegyi@102
   356
	{
ladanyi@130
   357
	  Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true, 
hegyi@102
   358
				     Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
ladanyi@130
   359
	  mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
hegyi@102
   360
	  mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@102
   361
	  mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
hegyi@102
   362
	  switch (mdialog.run())
hegyi@102
   363
	    {
hegyi@102
   364
	    case Gtk::RESPONSE_CANCEL:
hegyi@102
   365
	      return;
hegyi@102
   366
	    case Gtk::RESPONSE_REJECT:
hegyi@102
   367
	      break;
hegyi@102
   368
	    case Gtk::RESPONSE_ACCEPT:
hegyi@102
   369
	      tabs[active_tab]->saveFile();
hegyi@102
   370
	      break;
hegyi@102
   371
	    }
hegyi@102
   372
	}
hegyi@97
   373
      //tabs vector will be decreased with the deleted value
hegyi@97
   374
      int size=tabs.size();
hegyi@97
   375
      if(size>1)
hegyi@97
   376
	{
hegyi@97
   377
	  for(int i=active_tab+1;i<size;i++)
hegyi@97
   378
	    {
hegyi@103
   379
	      tabnames[i-1]=tabnames[i];
hegyi@97
   380
	      tabs[i-1]=tabs[i];
hegyi@97
   381
	    }
hegyi@97
   382
	}
hegyi@97
   383
      //if size==1 resize will delete the only element
hegyi@97
   384
      tabs.resize(size-1);
hegyi@103
   385
      tabnames.resize(size-1);
hegyi@97
   386
hegyi@97
   387
      int old_active_tab=active_tab;
hegyi@97
   388
      notebook.remove_page(active_tab);
hegyi@97
   389
hegyi@97
   390
      //If the first tab was active, upon delete notebook
hegyi@97
   391
      //will first switch one tab upper and not lower like
hegyi@97
   392
      //in the case, when not the first tab was active.
hegyi@97
   393
      //But after deletion it will become the first tab,
hegyi@97
   394
      //and this should be registrated in tabs vector,
hegyi@97
   395
      //as well.
hegyi@103
   396
      if((old_active_tab==0)&&(size!=1))
hegyi@97
   397
	{
hegyi@97
   398
	  onChangeTab(NULL,0);
hegyi@97
   399
	}
hegyi@97
   400
hegyi@97
   401
      //if this was the last page in notebook, there is
hegyi@97
   402
      //no active_tab now
hegyi@97
   403
      if(size==1)
hegyi@97
   404
	{
hegyi@97
   405
	  active_tab=-1;
hegyi@97
   406
	}
hegyi@103
   407
hegyi@106
   408
      updateAlgoWinTabs();
hegyi@97
   409
    }
hegyi@97
   410
}
hegyi@97
   411
hegyi@96
   412
void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
hegyi@96
   413
{
hegyi@96
   414
  page=page;
hegyi@96
   415
  active_tab=page_num;
hegyi@96
   416
  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
hegyi@96
   417
  set_title(tabnames[active_tab]);
hegyi@154
   418
  bool autoscale;
hegyi@156
   419
  bool zoomtrack;
hegyi@157
   420
  double width;
hegyi@157
   421
  double radius;
hegyi@157
   422
  tabs[active_tab]->getView(autoscale, zoomtrack, width, radius);
hegyi@157
   423
  edge_width->set_value(width);
hegyi@157
   424
  radius_size->set_value(radius);
hegyi@156
   425
  zoom_track->set_active(zoomtrack);
hegyi@154
   426
  auto_scale->set_active(autoscale);
hegyi@154
   427
hegyi@96
   428
}
hegyi@96
   429
ladanyi@6
   430
void MainWin::newFile()
ladanyi@6
   431
{
hegyi@96
   432
  if(active_tab!=-1)
ladanyi@53
   433
    {
hegyi@96
   434
      tabs[active_tab]->newFile();
ladanyi@53
   435
    }
ladanyi@6
   436
}
hegyi@96
   437
 
ladanyi@6
   438
void MainWin::openFile()
ladanyi@6
   439
{
ladanyi@140
   440
  if(active_tab==-1)
ladanyi@53
   441
    {
ladanyi@140
   442
      newTab();
ladanyi@53
   443
    }
ladanyi@140
   444
  tabs[active_tab]->openFile();
ladanyi@6
   445
}
hegyi@96
   446
 
ladanyi@6
   447
void MainWin::saveFile()
ladanyi@6
   448
{
hegyi@96
   449
  if(active_tab!=-1)
hegyi@96
   450
    {
hegyi@96
   451
      tabs[active_tab]->saveFile();
hegyi@96
   452
    }
ladanyi@6
   453
}
hegyi@96
   454
 
ladanyi@6
   455
void MainWin::saveFileAs()
ladanyi@6
   456
{
hegyi@96
   457
  if(active_tab!=-1)
hegyi@96
   458
    {
hegyi@96
   459
      tabs[active_tab]->saveFileAs();
hegyi@96
   460
    }
ladanyi@6
   461
}
hegyi@96
   462
 
ladanyi@53
   463
void MainWin::close()
ladanyi@53
   464
{
hegyi@96
   465
  if(active_tab!=-1)
ladanyi@53
   466
    {
hegyi@96
   467
      tabs[active_tab]->close();
hegyi@95
   468
    }
hegyi@94
   469
}
hegyi@94
   470
hegyi@96
   471
void MainWin::zoomIn()
hegyi@94
   472
{
hegyi@96
   473
  if(active_tab!=-1)
hegyi@95
   474
    {
hegyi@96
   475
      tabs[active_tab]->gd_canvas->zoomIn();
hegyi@96
   476
    }
hegyi@96
   477
}
hegyi@96
   478
hegyi@96
   479
void MainWin::zoomOut()
hegyi@96
   480
{
hegyi@96
   481
  if(active_tab!=-1)
hegyi@96
   482
    {
hegyi@96
   483
      tabs[active_tab]->gd_canvas->zoomOut();
hegyi@96
   484
    }
hegyi@96
   485
}
hegyi@96
   486
hegyi@96
   487
void MainWin::zoomFit()
hegyi@96
   488
{
hegyi@96
   489
  if(active_tab!=-1)
hegyi@96
   490
    {
hegyi@96
   491
      tabs[active_tab]->gd_canvas->zoomFit();
hegyi@96
   492
    }
hegyi@96
   493
}
hegyi@96
   494
hegyi@96
   495
void MainWin::zoom100()
hegyi@96
   496
{
hegyi@96
   497
  if(active_tab!=-1)
hegyi@96
   498
    {
hegyi@96
   499
      tabs[active_tab]->gd_canvas->zoom100();
hegyi@95
   500
    }
hegyi@94
   501
}
hegyi@95
   502
hegyi@95
   503
void MainWin::createMapWin()
hegyi@95
   504
{
hegyi@96
   505
  if(active_tab!=-1)
hegyi@95
   506
    {
hegyi@96
   507
      tabs[active_tab]->createMapWin(tabnames[active_tab]);
hegyi@95
   508
    }
hegyi@95
   509
}
hegyi@95
   510
hegyi@160
   511
void MainWin::createDesignWin()
hegyi@160
   512
{
hegyi@160
   513
  if(active_tab!=-1)
hegyi@160
   514
    {
hegyi@160
   515
      tabs[active_tab]->createDesignWin(tabnames[active_tab]);
hegyi@160
   516
    }
hegyi@160
   517
}
hegyi@160
   518
hegyi@103
   519
void MainWin::createAlgoWin(int algoid)
hegyi@103
   520
{
hegyi@108
   521
  AlgoWin * aw=new AlgoWin(algoid, tabnames);
hegyi@103
   522
  aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
hegyi@106
   523
  aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
hegyi@114
   524
  aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString));
hegyi@103
   525
  aws.insert(aw);
hegyi@103
   526
  aw->show();
hegyi@103
   527
}
hegyi@103
   528
hegyi@106
   529
void MainWin::updateAlgoWinTabs()
hegyi@103
   530
{
hegyi@103
   531
  std::set< AlgoWin* >::iterator awsi=aws.begin();
hegyi@103
   532
  for(;awsi!=aws.end();awsi++)
hegyi@103
   533
    {
hegyi@103
   534
      (*awsi)->update_tablist(tabnames);
hegyi@103
   535
    }
hegyi@103
   536
}
hegyi@103
   537
hegyi@108
   538
void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
hegyi@108
   539
{
hegyi@108
   540
  int i=0;
hegyi@108
   541
  for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
hegyi@108
   542
    {
hegyi@108
   543
    }
hegyi@108
   544
  awp->update_maplist(&(tabs[i]->mapstorage));
hegyi@108
   545
}
hegyi@108
   546
hegyi@108
   547
void MainWin::deRegisterAlgoWin(AlgoWin * awp)
hegyi@108
   548
{
hegyi@108
   549
  aws.erase(awp);
hegyi@108
   550
}
hegyi@108
   551
hegyi@96
   552
void MainWin::changeEditorialTool(int tool)
hegyi@95
   553
{
hegyi@96
   554
  active_tool=tool;
hegyi@96
   555
  if(active_tab!=-1)
hegyi@96
   556
    {
hegyi@96
   557
      tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
hegyi@96
   558
    }
hegyi@95
   559
}
hegyi@96
   560
hegyi@96
   561
void MainWin::createNewMapWin()
hegyi@96
   562
{
hegyi@96
   563
  if(active_tab!=-1)
hegyi@96
   564
    {
ladanyi@130
   565
      NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab]));
hegyi@96
   566
      nmw->show();
hegyi@96
   567
    }
hegyi@96
   568
}
hegyi@96
   569
hegyi@114
   570
void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
hegyi@114
   571
{
hegyi@114
   572
  int i=0;
hegyi@120
   573
  for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++)
hegyi@114
   574
    {
hegyi@114
   575
    }
hegyi@114
   576
  createNewMapWinAfterSignal(tabs[i], itisedge);
hegyi@114
   577
}
hegyi@114
   578
hegyi@96
   579
void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
hegyi@96
   580
{
hegyi@96
   581
  std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
hegyi@96
   582
  int i=0;
hegyi@96
   583
  for(;nbti!=tabs.end();nbti++)
hegyi@96
   584
    {
hegyi@96
   585
      if(*nbti!=nbt)
hegyi@96
   586
	{
hegyi@96
   587
	  i++;
hegyi@96
   588
	}
hegyi@96
   589
      else
hegyi@96
   590
	{
hegyi@96
   591
	  continue;
hegyi@96
   592
	}
hegyi@96
   593
    }
ladanyi@130
   594
  NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false);
hegyi@96
   595
  nmw->run();
hegyi@96
   596
}
hegyi@154
   597
hegyi@154
   598
hegyi@154
   599
void MainWin::nodeViewChanged()
hegyi@154
   600
{
hegyi@157
   601
  double width=edge_width->get_value();
hegyi@157
   602
  double radius=radius_size->get_value();
hegyi@156
   603
  bool zoomtrack=zoom_track->get_active();
hegyi@154
   604
  bool autoscale=auto_scale->get_active();
hegyi@157
   605
  tabs[active_tab]->setView(autoscale, zoomtrack, width, radius);
hegyi@154
   606
}
hegyi@160
   607
hegyi@160
   608
void MainWin::reDesignGraph()
hegyi@160
   609
{
hegyi@160
   610
  tabs[active_tab]->reDesignGraph();
hegyi@160
   611
}
ladanyi@184
   612
ladanyi@184
   613
void MainWin::createBackgroundChooser()
ladanyi@184
   614
{
ladanyi@184
   615
  BackgroundChooserDialog dialog(&(tabs[active_tab]->mapstorage));
ladanyi@184
   616
  dialog.run();
ladanyi@184
   617
}