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