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