main_win.cc
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/main_win.cc	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,657 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#ifdef HAVE_CONFIG_H
    1.23 +#include <config.h>
    1.24 +#endif
    1.25 +
    1.26 +#include "main_win.h"
    1.27 +#include "guipixbufs.h"
    1.28 +#include "save_details_dialog.h"
    1.29 +#include "background_chooser_dialog.h"
    1.30 +
    1.31 +#include <mapstorage.h>
    1.32 +#include <graph_displayer_canvas.h>
    1.33 +#include <algowin.h>
    1.34 +#include <new_map_win.h>
    1.35 +#include <nbtab.h>
    1.36 +
    1.37 +#include "i18n.h"
    1.38 +
    1.39 +MainWin::MainWin()
    1.40 +{
    1.41 +  set_title ("no file");
    1.42 +  set_default_size(WIN_WIDTH,WIN_HEIGHT);
    1.43 +  //add(vbox);
    1.44 +  add(table);
    1.45 +
    1.46 +  // custom icons for the toolbar
    1.47 +  Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
    1.48 + 
    1.49 +  Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.50 +      2328, gui_icons_move);
    1.51 +  Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.52 +      2328, gui_icons_addnode);
    1.53 +  Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.54 +      2328, gui_icons_addlink);
    1.55 +  Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.56 +      2328, gui_icons_delete);
    1.57 +  Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.58 +      2328, gui_icons_editlink);
    1.59 +  Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.60 +      2328, gui_icons_newmap);
    1.61 +  Glib::RefPtr<Gdk::Pixbuf> p_eps_pixbuf = Gdk::Pixbuf::create_from_inline(
    1.62 +      2328, gui_icons_eps);
    1.63 +
    1.64 +  Gtk::IconSource move_icon_source;
    1.65 +  move_icon_source.set_pixbuf(p_move_pixbuf);
    1.66 +  Gtk::IconSet move_icon_set;
    1.67 +  move_icon_set.add_source(move_icon_source);
    1.68 +  p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
    1.69 +
    1.70 +  Gtk::IconSource addnode_icon_source;
    1.71 +  addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
    1.72 +  Gtk::IconSet addnode_icon_set;
    1.73 +  addnode_icon_set.add_source(addnode_icon_source);
    1.74 +  p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
    1.75 +
    1.76 +  Gtk::IconSource addlink_icon_source;
    1.77 +  addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
    1.78 +  Gtk::IconSet addlink_icon_set;
    1.79 +  addlink_icon_set.add_source(addlink_icon_source);
    1.80 +  p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
    1.81 +
    1.82 +  Gtk::IconSource delete_icon_source;
    1.83 +  delete_icon_source.set_pixbuf(p_delete_pixbuf);
    1.84 +  Gtk::IconSet delete_icon_set;
    1.85 +  delete_icon_set.add_source(delete_icon_source);
    1.86 +  p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
    1.87 +
    1.88 +  Gtk::IconSource editlink_icon_source;
    1.89 +  editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
    1.90 +  Gtk::IconSet editlink_icon_set;
    1.91 +  editlink_icon_set.add_source(editlink_icon_source);
    1.92 +  p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
    1.93 +
    1.94 +  Gtk::IconSource newmap_icon_source;
    1.95 +  newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
    1.96 +  Gtk::IconSet newmap_icon_set;
    1.97 +  newmap_icon_set.add_source(newmap_icon_source);
    1.98 +  p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
    1.99 +
   1.100 +  Gtk::IconSource eps_icon_source;
   1.101 +  eps_icon_source.set_pixbuf(p_eps_pixbuf);
   1.102 +  Gtk::IconSet eps_icon_set;
   1.103 +  eps_icon_set.add_source(eps_icon_source);
   1.104 +  p_icon_factory->add(Gtk::StockID("gd-eps"), eps_icon_set);
   1.105 +
   1.106 +  p_icon_factory->add_default();
   1.107 +  
   1.108 +  ag=Gtk::ActionGroup::create();
   1.109 +
   1.110 +  ag->add( Gtk::Action::create("FileMenu", _("_File")) );
   1.111 +  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
   1.112 +      sigc::mem_fun(*this, &MainWin::newTab));
   1.113 +  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
   1.114 +      sigc::mem_fun(*this, &MainWin::openFile));
   1.115 +  ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
   1.116 +      sigc::mem_fun(*this, &MainWin::newFile));
   1.117 +  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
   1.118 +      sigc::mem_fun(*this, &MainWin::saveFile));
   1.119 +  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
   1.120 +      sigc::mem_fun(*this, &MainWin::saveFileAs));
   1.121 +  ag->add( Gtk::Action::create("SaveDetails", _("Save _Details...")),
   1.122 +	   sigc::mem_fun(*this, &MainWin::createSaveDetailsDialog));
   1.123 +  ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
   1.124 +      sigc::mem_fun(*this, &MainWin::closeTab));
   1.125 +  ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
   1.126 +      sigc::mem_fun(*this, &MainWin::hide));
   1.127 +
   1.128 +  ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
   1.129 +  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
   1.130 +      sigc::mem_fun(*this, &MainWin::zoomIn));
   1.131 +  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
   1.132 +      sigc::mem_fun(*this, &MainWin::zoomOut));
   1.133 +  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
   1.134 +      sigc::mem_fun(*this, &MainWin::zoomFit));
   1.135 +  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
   1.136 +      sigc::mem_fun(*this, &MainWin::zoom100));
   1.137 +  ag->add( Gtk::Action::create("SetBackground", _("Set Background...")),
   1.138 +	    sigc::mem_fun(*this, &MainWin::createBackgroundChooser));
   1.139 +  
   1.140 +  ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
   1.141 +  ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
   1.142 +	   sigc::mem_fun(*this, &MainWin::createMapWin));
   1.143 +  ag->add( Gtk::Action::create("ShowDesign", _("_Design")),
   1.144 +	   sigc::mem_fun(*this, &MainWin::createDesignWin));
   1.145 +
   1.146 +  ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
   1.147 +  ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
   1.148 +	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
   1.149 +  ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
   1.150 +	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
   1.151 +  ag->add( Gtk::Action::create("AlgoDijkstra", _("_Dijkstra")),
   1.152 +	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 2) );
   1.153 +  ag->add( Gtk::Action::create("AlgoSuurballe", _("_Suurballe")),
   1.154 +	   sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 3) );
   1.155 +
   1.156 +  Gtk::RadioAction::Group tool_group;
   1.157 +  ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
   1.158 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
   1.159 +  ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
   1.160 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
   1.161 +  ag->add( Gtk::RadioAction::create(tool_group, "CreateArc", Gtk::StockID("gd-addlink"), _("Create arc")),
   1.162 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
   1.163 +  ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
   1.164 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
   1.165 +
   1.166 +  ag->add( Gtk::RadioAction::create(tool_group, "EditArcMap", Gtk::StockID("gd-editlink"), _("Edit arc map")),
   1.167 +      sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
   1.168 +
   1.169 +  ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap"), "New map"),
   1.170 +      sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
   1.171 +
   1.172 +  ag->add( Gtk::Action::create("DesignDigraph", Gtk::Stock::REFRESH),
   1.173 +      sigc::mem_fun ( *this , &MainWin::reDesignDigraph ) );
   1.174 +
   1.175 +  ag->add( Gtk::Action::create("Eps", Gtk::StockID("gd-eps"), "Export to EPS"),
   1.176 +      sigc::mem_fun ( *this , &MainWin::exportToEPS ) );
   1.177 +
   1.178 +  uim=Gtk::UIManager::create();
   1.179 +  uim->insert_action_group(ag);
   1.180 +  add_accel_group(uim->get_accel_group());
   1.181 +
   1.182 +  try
   1.183 +  {
   1.184 +
   1.185 +    Glib::ustring ui_info =
   1.186 +      "<ui>"
   1.187 +      "  <menubar name='MenuBar'>"
   1.188 +      "    <menu action='FileMenu'>"
   1.189 +      "      <menuitem action='FileNew'/>"
   1.190 +      "      <menuitem action='FileOpen'/>"
   1.191 +      "      <menuitem action='FileClearTab'/>"
   1.192 +      "      <menuitem action='FileSave'/>"
   1.193 +      "      <menuitem action='FileSaveAs'/>"
   1.194 +      "      <menuitem action='SaveDetails'/>"
   1.195 +      "      <menuitem action='Close'/>"
   1.196 +      "      <menuitem action='Quit'/>"
   1.197 +      "    </menu>"
   1.198 +      "    <menu action='ViewMenu'>"
   1.199 +      "      <menuitem action='ViewZoomIn' />"
   1.200 +      "      <menuitem action='ViewZoomOut' />"
   1.201 +      "      <menuitem action='ViewZoom100' />"
   1.202 +      "      <menuitem action='ViewZoomFit' />"
   1.203 +      "      <menuitem action='SetBackground' />"
   1.204 +      "    </menu>"
   1.205 +      "    <menu action='ShowMenu'>"
   1.206 +      "      <menuitem action='ShowMaps'/>"
   1.207 +      "      <menuitem action='ShowDesign'/>"
   1.208 +      "    </menu>"
   1.209 +      "    <menu action='AlgoMenu'>"
   1.210 +      "      <menuitem action='AlgoGeneral'/>"
   1.211 +      "      <menuitem action='AlgoKruskal'/>"
   1.212 +      "      <menuitem action='AlgoDijkstra'/>"
   1.213 +      "      <menuitem action='AlgoSuurballe'/>"
   1.214 +      "    </menu>"
   1.215 +      "  </menubar>"
   1.216 +      "  <toolbar name='ToolBar'>"
   1.217 +      "    <toolitem action='FileNew' />"
   1.218 +      "    <toolitem action='FileOpen' />"
   1.219 +      "    <toolitem action='FileSave' />"
   1.220 +      "    <toolitem action='Close' />"
   1.221 +      "    <separator />"
   1.222 +      "    <toolitem action='ViewZoomIn' />"
   1.223 +      "    <toolitem action='ViewZoomOut' />"
   1.224 +      "    <toolitem action='ViewZoom100' />"
   1.225 +      "    <toolitem action='ViewZoomFit' />"
   1.226 +      "    <separator />"
   1.227 +      "    <toolitem action='MoveItem' />"
   1.228 +      "    <toolitem action='CreateNode' />"
   1.229 +      "    <toolitem action='CreateArc' />"
   1.230 +      "    <toolitem action='EraseItem' />"
   1.231 +      "    <toolitem action='EditArcMap' />"
   1.232 +      "    <separator />"
   1.233 +      "    <toolitem action='AddMap' />"
   1.234 +      "    <toolitem action='DesignDigraph' />"
   1.235 +      "    <toolitem action='Eps' />"
   1.236 +      "  </toolbar>"
   1.237 +      "</ui>";
   1.238 +
   1.239 +    uim->add_ui_from_string(ui_info);
   1.240 +
   1.241 +  }
   1.242 +  catch(const Glib::Error& ex)
   1.243 +  {
   1.244 +    std::cerr << "building menus failed: " <<  ex.what();
   1.245 +  }
   1.246 +
   1.247 +  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
   1.248 +  if (menubar){
   1.249 +    //vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
   1.250 +    table.attach(*menubar, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
   1.251 +  }
   1.252 +
   1.253 +  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
   1.254 +  if (toolbar)
   1.255 +  {
   1.256 +    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
   1.257 +    static_cast<Gtk::Toolbar*>(toolbar)->set_tooltips(true);
   1.258 +    //hbox.pack_start(*toolbar, Gtk::PACK_EXPAND_WIDGET);
   1.259 +
   1.260 +    table.attach(*toolbar, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
   1.261 +
   1.262 +  }
   1.263 + 
   1.264 +  table2.set_row_spacings(10);
   1.265 +  table2.set_col_spacings(5);
   1.266 +
   1.267 +  auto_scale = Gtk::manage(new Gtk::CheckButton("Autoscale"));
   1.268 +  auto_scale->set_active(false);
   1.269 +  auto_scale->signal_toggled().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
   1.270 +  table2.attach(*auto_scale, 0,2,0,1);
   1.271 +
   1.272 +  Gtk::Label * width_label=Gtk::manage(new Gtk::Label("Arc Width:"));
   1.273 +  table2.attach(*width_label, 0,1,1,2);
   1.274 +  
   1.275 +  Gtk::Adjustment * adjustment_width=Gtk::manage(new Gtk::Adjustment(20, 1, 200, 5, 10));
   1.276 +  
   1.277 +  arc_width = Gtk::manage(new Gtk::SpinButton(*adjustment_width, 5,0));
   1.278 +  arc_width->signal_value_changed().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
   1.279 +  table2.attach(*arc_width, 1,2,1,2);
   1.280 +
   1.281 +  Gtk::Label * radius_label= Gtk::manage(new Gtk::Label("Node Radius:"));
   1.282 +  table2.attach(*radius_label, 2,3,1,2);
   1.283 +  
   1.284 +  Gtk::Adjustment * adjustment_radius=Gtk::manage(new Gtk::Adjustment(20, 0, 500, 5, 10));
   1.285 +
   1.286 +  radius_size = Gtk::manage(new Gtk::SpinButton(*adjustment_radius, 5,0));
   1.287 +  radius_size->signal_value_changed().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
   1.288 +  table2.attach(*radius_size, 3,4,1,2);
   1.289 +
   1.290 +  zoom_track = Gtk::manage(new Gtk::CheckButton("Zoom tracking"));
   1.291 +  zoom_track->set_active(false);
   1.292 +  zoom_track->signal_toggled().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
   1.293 +  table2.attach(*zoom_track, 2,4,0,1);
   1.294 +
   1.295 +
   1.296 +  table.attach(table2, 1, 2, 0, 2, Gtk::SHRINK, Gtk::SHRINK);
   1.297 +
   1.298 +  tooltips=Gtk::manage(new Gtk::Tooltips());
   1.299 +  if(tooltips)
   1.300 +    {
   1.301 +      tooltips->set_tip(*zoom_track, "If on, arc widths and node radiuses are constant, independent from zooming");
   1.302 +      tooltips->set_tip(*auto_scale, "If on, glemon automatically determines the size of arcs and nodes");
   1.303 +      tooltips->set_tip(*radius_size, "Sets maximum node radius, if auto-scale is off");
   1.304 +      tooltips->set_tip(*arc_width, "Sets maximum arc width, if auto-scale is off");
   1.305 +
   1.306 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileNew"))->set_tooltip(*tooltips, "Inserts new tab");
   1.307 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileOpen"))->set_tooltip(*tooltips, "Lets you open a file");
   1.308 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/FileSave"))->set_tooltip(*tooltips, "Saves the digraph on the active tab");
   1.309 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/Close"))->set_tooltip(*tooltips, "Closes the active tab");
   1.310 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomIn"))->set_tooltip(*tooltips, "Zoom in the digraph");
   1.311 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomOut"))->set_tooltip(*tooltips, "Zoom out the digraph");
   1.312 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoom100"))->set_tooltip(*tooltips, "Shows actual size of digraph");
   1.313 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/ViewZoomFit"))->set_tooltip(*tooltips, "Fits digraph into window");
   1.314 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/MoveItem"))->set_tooltip(*tooltips, "Moves the clicked item (arc/node)");
   1.315 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/CreateNode"))->set_tooltip(*tooltips, "Adds new node");
   1.316 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/CreateArc"))->set_tooltip(*tooltips, "Lets you create new arc");
   1.317 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/EraseItem"))->set_tooltip(*tooltips, "Erases the clicked item (arc/node)");
   1.318 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/EditArcMap"))->set_tooltip(*tooltips, "Lets you edit the values written on the items");
   1.319 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/AddMap"))->set_tooltip(*tooltips, "Adds arc/nodemap");
   1.320 +      static_cast<Gtk::ToolItem*>(uim->get_widget("/ToolBar/DesignDigraph"))->set_tooltip(*tooltips, "Redesigns your digraph, supposing elastic arcs and propulsation of nodes.");
   1.321 +
   1.322 +      tooltips->enable();
   1.323 +    }
   1.324 +
   1.325 +  active_tab=-1;
   1.326 +  notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
   1.327 +
   1.328 +  active_tool = MOVE;
   1.329 +
   1.330 +  table.attach(notebook,0,2,2,3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL);
   1.331 +  
   1.332 +  show_all_children();
   1.333 +}
   1.334 +
   1.335 +MainWin::~MainWin()
   1.336 +{
   1.337 +}
   1.338 +
   1.339 +void MainWin::set_tabtitle(std::string name)
   1.340 +{
   1.341 +  if(strinst.find(name)==strinst.end())
   1.342 +    {
   1.343 +      tabnames[active_tab]=name;
   1.344 +      strinst[name]=1;
   1.345 +    }
   1.346 +  else
   1.347 +    {
   1.348 +      strinst[name]++;
   1.349 +      std::ostringstream o;
   1.350 +      o << strinst[name];
   1.351 +      tabnames[active_tab]=name+" - "+o.str();
   1.352 +    }
   1.353 +  set_title(tabnames[active_tab] + " - " + prog_name);
   1.354 +  notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
   1.355 +  updateAlgoWinTabs();
   1.356 +}
   1.357 +
   1.358 +void MainWin::readFile(const std::string & filename)
   1.359 +{
   1.360 +  newTab();
   1.361 +  tabs[active_tab]->readFile(filename);
   1.362 +}
   1.363 +
   1.364 +void MainWin::newTab()
   1.365 +{
   1.366 +  int size=tabs.size();
   1.367 +  tabs.resize(size+1);
   1.368 +  tabnames.resize(size+1);
   1.369 +  active_tab=size;
   1.370 +  tabs[active_tab]=Gtk::manage(new NoteBookTab());
   1.371 +  tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
   1.372 +  tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
   1.373 +  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
   1.374 +  notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
   1.375 +  notebook.set_current_page(size);
   1.376 +  set_tabtitle(_("unsaved file"));
   1.377 +  updateAlgoWinTabs();
   1.378 +}
   1.379 +
   1.380 +void MainWin::closeTab()
   1.381 +{
   1.382 +  if(active_tab!=-1)
   1.383 +    {
   1.384 +      if (tabs[active_tab]->mapstorage->getModified())
   1.385 +	{
   1.386 +	  Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true, 
   1.387 +				     Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   1.388 +	  mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
   1.389 +	  mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.390 +	  mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.391 +	  switch (mdialog.run())
   1.392 +	    {
   1.393 +	    case Gtk::RESPONSE_CANCEL:
   1.394 +	      return;
   1.395 +	    case Gtk::RESPONSE_REJECT:
   1.396 +	      break;
   1.397 +	    case Gtk::RESPONSE_ACCEPT:
   1.398 +	      tabs[active_tab]->saveFile();
   1.399 +	      break;
   1.400 +	    }
   1.401 +	}
   1.402 +      //tabs vector will be decreased with the deleted value
   1.403 +      int size=tabs.size();
   1.404 +      if(size>1)
   1.405 +	{
   1.406 +	  for(int i=active_tab+1;i<size;i++)
   1.407 +	    {
   1.408 +	      tabnames[i-1]=tabnames[i];
   1.409 +	      tabs[i-1]=tabs[i];
   1.410 +	    }
   1.411 +	}
   1.412 +      //if size==1 resize will delete the only element
   1.413 +      tabs.resize(size-1);
   1.414 +      tabnames.resize(size-1);
   1.415 +
   1.416 +      int old_active_tab=active_tab;
   1.417 +      notebook.remove_page(active_tab);
   1.418 +
   1.419 +      //If the first tab was active, upon delete notebook
   1.420 +      //will first switch one tab upper and not lower like
   1.421 +      //in the case, when not the first tab was active.
   1.422 +      //But after deletion it will become the first tab,
   1.423 +      //and this should be registrated in tabs vector,
   1.424 +      //as well.
   1.425 +      if((old_active_tab==0)&&(size!=1))
   1.426 +	{
   1.427 +	  onChangeTab(NULL,0);
   1.428 +	}
   1.429 +
   1.430 +      //if this was the last page in notebook, there is
   1.431 +      //no active_tab now
   1.432 +      if(size==1)
   1.433 +	{
   1.434 +	  active_tab=-1;
   1.435 +	}
   1.436 +
   1.437 +      updateAlgoWinTabs();
   1.438 +    }
   1.439 +}
   1.440 +
   1.441 +void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
   1.442 +{
   1.443 +  page=page;
   1.444 +  active_tab=page_num;
   1.445 +  tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
   1.446 +  set_title(tabnames[active_tab]);
   1.447 +  bool autoscale;
   1.448 +  bool zoomtrack;
   1.449 +  double width;
   1.450 +  double radius;
   1.451 +  tabs[active_tab]->getView(autoscale, zoomtrack, width, radius);
   1.452 +  arc_width->set_value(width);
   1.453 +  radius_size->set_value(radius);
   1.454 +  zoom_track->set_active(zoomtrack);
   1.455 +  auto_scale->set_active(autoscale);
   1.456 +
   1.457 +}
   1.458 +
   1.459 +void MainWin::newFile()
   1.460 +{
   1.461 +  if(active_tab!=-1)
   1.462 +    {
   1.463 +      tabs[active_tab]->newFile();
   1.464 +    }
   1.465 +}
   1.466 + 
   1.467 +void MainWin::openFile()
   1.468 +{
   1.469 +  if(active_tab==-1)
   1.470 +    {
   1.471 +      newTab();
   1.472 +    }
   1.473 +  tabs[active_tab]->openFile();
   1.474 +}
   1.475 + 
   1.476 +void MainWin::saveFile()
   1.477 +{
   1.478 +  if(active_tab!=-1)
   1.479 +    {
   1.480 +      tabs[active_tab]->saveFile();
   1.481 +    }
   1.482 +}
   1.483 + 
   1.484 +void MainWin::saveFileAs()
   1.485 +{
   1.486 +  if(active_tab!=-1)
   1.487 +    {
   1.488 +      tabs[active_tab]->saveFileAs();
   1.489 +    }
   1.490 +}
   1.491 + 
   1.492 +void MainWin::close()
   1.493 +{
   1.494 +  if(active_tab!=-1)
   1.495 +    {
   1.496 +      tabs[active_tab]->close();
   1.497 +    }
   1.498 +}
   1.499 +
   1.500 +void MainWin::zoomIn()
   1.501 +{
   1.502 +  if(active_tab!=-1)
   1.503 +    {
   1.504 +      tabs[active_tab]->gd_canvas->zoomIn();
   1.505 +    }
   1.506 +}
   1.507 +
   1.508 +void MainWin::zoomOut()
   1.509 +{
   1.510 +  if(active_tab!=-1)
   1.511 +    {
   1.512 +      tabs[active_tab]->gd_canvas->zoomOut();
   1.513 +    }
   1.514 +}
   1.515 +
   1.516 +void MainWin::zoomFit()
   1.517 +{
   1.518 +  if(active_tab!=-1)
   1.519 +    {
   1.520 +      tabs[active_tab]->gd_canvas->zoomFit();
   1.521 +    }
   1.522 +}
   1.523 +
   1.524 +void MainWin::zoom100()
   1.525 +{
   1.526 +  if(active_tab!=-1)
   1.527 +    {
   1.528 +      tabs[active_tab]->gd_canvas->zoom100();
   1.529 +    }
   1.530 +}
   1.531 +
   1.532 +void MainWin::createMapWin()
   1.533 +{
   1.534 +  if(active_tab!=-1)
   1.535 +    {
   1.536 +      tabs[active_tab]->createMapWin(tabnames[active_tab]);
   1.537 +    }
   1.538 +}
   1.539 +
   1.540 +void MainWin::createDesignWin()
   1.541 +{
   1.542 +  if(active_tab!=-1)
   1.543 +    {
   1.544 +      tabs[active_tab]->createDesignWin(tabnames[active_tab]);
   1.545 +    }
   1.546 +}
   1.547 +
   1.548 +void MainWin::createAlgoWin(int algoid)
   1.549 +{
   1.550 +  AlgoWin * aw=Gtk::manage(new AlgoWin(algoid, tabnames));
   1.551 +  aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
   1.552 +  aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
   1.553 +  aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString));
   1.554 +  aws.insert(aw);
   1.555 +  aw->show();
   1.556 +}
   1.557 +
   1.558 +void MainWin::updateAlgoWinTabs()
   1.559 +{
   1.560 +  std::set< AlgoWin* >::iterator awsi=aws.begin();
   1.561 +  for(;awsi!=aws.end();awsi++)
   1.562 +    {
   1.563 +      (*awsi)->update_tablist(tabnames);
   1.564 +    }
   1.565 +}
   1.566 +
   1.567 +void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
   1.568 +{
   1.569 +  int i=0;
   1.570 +  for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
   1.571 +    {
   1.572 +    }
   1.573 +  awp->update_maplist(tabs[i]->mapstorage);
   1.574 +}
   1.575 +
   1.576 +void MainWin::deRegisterAlgoWin(AlgoWin * awp)
   1.577 +{
   1.578 +  aws.erase(awp);
   1.579 +}
   1.580 +
   1.581 +void MainWin::changeEditorialTool(int tool)
   1.582 +{
   1.583 +  active_tool=tool;
   1.584 +  if(active_tab!=-1)
   1.585 +    {
   1.586 +      tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
   1.587 +    }
   1.588 +}
   1.589 +
   1.590 +void MainWin::createNewMapWin()
   1.591 +{
   1.592 +  if(active_tab!=-1)
   1.593 +    {
   1.594 +      NewMapWin * nmw=Gtk::manage(new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab])));
   1.595 +      nmw->show();
   1.596 +    }
   1.597 +}
   1.598 +
   1.599 +void MainWin::createNewMapWinTabString(std::string tabname, bool itisarc)
   1.600 +{
   1.601 +  int i=0;
   1.602 +  for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++)
   1.603 +    {
   1.604 +    }
   1.605 +  createNewMapWinAfterSignal(tabs[i], itisarc);
   1.606 +}
   1.607 +
   1.608 +void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisarc)
   1.609 +{
   1.610 +  std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
   1.611 +  int i=0;
   1.612 +  for(;nbti!=tabs.end();nbti++)
   1.613 +    {
   1.614 +      if(*nbti!=nbt)
   1.615 +	{
   1.616 +	  i++;
   1.617 +	}
   1.618 +      else
   1.619 +	{
   1.620 +	  continue;
   1.621 +	}
   1.622 +    }
   1.623 +  NewMapWin * nmw=Gtk::manage(new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisarc, false));
   1.624 +  nmw->run();
   1.625 +}
   1.626 +
   1.627 +
   1.628 +void MainWin::nodeViewChanged()
   1.629 +{
   1.630 +  double width=arc_width->get_value();
   1.631 +  double radius=radius_size->get_value();
   1.632 +  bool zoomtrack=zoom_track->get_active();
   1.633 +  bool autoscale=auto_scale->get_active();
   1.634 +  tabs[active_tab]->setView(autoscale, zoomtrack, width, radius);
   1.635 +}
   1.636 +
   1.637 +void MainWin::reDesignDigraph()
   1.638 +{
   1.639 +  tabs[active_tab]->reDesignDigraph();
   1.640 +}
   1.641 +
   1.642 +void MainWin::createSaveDetailsDialog()
   1.643 +{
   1.644 +  SaveDetailsDialog dialog(tabs[active_tab]->mapstorage);
   1.645 +  dialog.run();
   1.646 +}
   1.647 +
   1.648 +void MainWin::exportToEPS()
   1.649 +{
   1.650 +  if(active_tab!=-1)
   1.651 +    {
   1.652 +      tabs[active_tab]->createExportToEPSWin(tabnames[active_tab]);
   1.653 +    }
   1.654 +}
   1.655 +
   1.656 +void MainWin::createBackgroundChooser()
   1.657 +{
   1.658 +  BackgroundChooserDialog dialog(tabs[active_tab]->mapstorage);
   1.659 +  dialog.run();
   1.660 +}