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