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