Showed map is loaded even if ArrowPos not.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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.
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
24 #include "guipixbufs.h"
30 set_title ("no file");
31 set_default_size(WIN_WIDTH,WIN_HEIGHT);
35 // custom icons for the toolbar
36 Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
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);
51 Gtk::IconSource move_icon_source;
52 move_icon_source.set_pixbuf(p_move_pixbuf);
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);
57 Gtk::IconSource addnode_icon_source;
58 addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
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);
63 Gtk::IconSource addlink_icon_source;
64 addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
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);
69 Gtk::IconSource delete_icon_source;
70 delete_icon_source.set_pixbuf(p_delete_pixbuf);
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);
75 Gtk::IconSource editlink_icon_source;
76 editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
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);
81 Gtk::IconSource newmap_icon_source;
82 newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
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);
87 p_icon_factory->add_default();
89 ag=Gtk::ActionGroup::create();
91 ag->add( Gtk::Action::create("FileMenu", _("_File")) );
92 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
93 sigc::mem_fun(*this, &MainWin::newTab));
94 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
95 sigc::mem_fun(*this, &MainWin::openFile));
96 ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
97 sigc::mem_fun(*this, &MainWin::newFile));
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));
102 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
103 sigc::mem_fun(*this, &MainWin::closeTab));
104 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
105 sigc::mem_fun(*this, &MainWin::hide));
107 ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
108 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
109 sigc::mem_fun(*this, &MainWin::zoomIn));
110 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
111 sigc::mem_fun(*this, &MainWin::zoomOut));
112 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
113 sigc::mem_fun(*this, &MainWin::zoomFit));
114 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
115 sigc::mem_fun(*this, &MainWin::zoom100));
117 ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
118 ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
119 sigc::mem_fun(*this, &MainWin::createMapWin));
120 ag->add( Gtk::Action::create("ShowDesign", _("_Design")),
121 sigc::mem_fun(*this, &MainWin::createDesignWin));
123 ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
124 ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
125 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
126 ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
127 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
128 ag->add( Gtk::Action::create("AlgoDijkstra", _("_Dijkstra")),
129 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 2) );
130 ag->add( Gtk::Action::create("AlgoSuurballe", _("_Suurballe")),
131 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 3) );
133 Gtk::RadioAction::Group tool_group;
134 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
135 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
136 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
137 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
138 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")),
139 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
140 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
141 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
143 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")),
144 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
146 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
147 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
149 ag->add( Gtk::Action::create("DesignGraph", Gtk::Stock::REFRESH),
150 sigc::mem_fun ( *this , &MainWin::reDesignGraph ) );
152 uim=Gtk::UIManager::create();
153 uim->insert_action_group(ag);
154 add_accel_group(uim->get_accel_group());
159 Glib::ustring ui_info =
161 " <menubar name='MenuBar'>"
162 " <menu action='FileMenu'>"
163 " <menuitem action='FileNew'/>"
164 " <menuitem action='FileOpen'/>"
165 " <menuitem action='FileClearTab'/>"
166 " <menuitem action='FileSave'/>"
167 " <menuitem action='FileSaveAs'/>"
168 " <menuitem action='Close'/>"
169 " <menuitem action='Quit'/>"
171 " <menu action='ViewMenu'>"
172 " <menuitem action='ViewZoomIn' />"
173 " <menuitem action='ViewZoomOut' />"
174 " <menuitem action='ViewZoom100' />"
175 " <menuitem action='ViewZoomFit' />"
177 " <menu action='ShowMenu'>"
178 " <menuitem action='ShowMaps'/>"
179 " <menuitem action='ShowDesign'/>"
181 " <menu action='AlgoMenu'>"
182 " <menuitem action='AlgoGeneral'/>"
183 " <menuitem action='AlgoKruskal'/>"
184 " <menuitem action='AlgoDijkstra'/>"
185 " <menuitem action='AlgoSuurballe'/>"
188 " <toolbar name='ToolBar'>"
189 " <toolitem action='FileNew' />"
190 " <toolitem action='FileOpen' />"
191 " <toolitem action='FileSave' />"
192 " <toolitem action='Close' />"
194 " <toolitem action='ViewZoomIn' />"
195 " <toolitem action='ViewZoomOut' />"
196 " <toolitem action='ViewZoom100' />"
197 " <toolitem action='ViewZoomFit' />"
199 " <toolitem action='MoveItem' />"
200 " <toolitem action='CreateNode' />"
201 " <toolitem action='CreateEdge' />"
202 " <toolitem action='EraseItem' />"
203 " <toolitem action='EditEdgeMap' />"
205 " <toolitem action='AddMap' />"
206 " <toolitem action='DesignGraph' />"
210 uim->add_ui_from_string(ui_info);
213 catch(const Glib::Error& ex)
215 std::cerr << "building menus failed: " << ex.what();
218 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
220 //vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
221 table.attach(*menubar, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
224 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
227 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
228 //hbox.pack_start(*toolbar, Gtk::PACK_EXPAND_WIDGET);
230 table.attach(*toolbar, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
234 table2.set_row_spacings(10);
235 table2.set_col_spacings(5);
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));
240 table2.attach(*auto_scale, 0,2,0,1);
242 Gtk::Label * width_label= new Gtk::Label("Edge Width:");
243 table2.attach(*width_label, 0,1,1,2);
245 Gtk::Adjustment * adjustment_width=new Gtk::Adjustment(20, 1, 200, 5, 10);
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);
251 Gtk::Label * radius_label= new Gtk::Label("Node Radius:");
252 table2.attach(*radius_label, 2,3,1,2);
254 Gtk::Adjustment * adjustment_radius=new Gtk::Adjustment(20, 0, 500, 5, 10);
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);
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);
266 table.attach(table2, 1, 2, 0, 2, Gtk::SHRINK, Gtk::SHRINK);
268 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
272 notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
276 table.attach(notebook,0,2,2,3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL);
281 void MainWin::set_tabtitle(std::string name)
283 if(strinst.find(name)==strinst.end())
285 tabnames[active_tab]=name;
291 std::ostringstream o;
293 tabnames[active_tab]=name+" - "+o.str();
295 set_title(tabnames[active_tab] + " - " + prog_name);
296 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
300 void MainWin::readFile(const std::string & filename)
303 tabs[active_tab]->readFile(filename);
306 void MainWin::newTab()
308 int size=tabs.size();
310 tabnames.resize(size+1);
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);
318 set_tabtitle(_("unsaved file"));
322 void MainWin::closeTab()
326 if (tabs[active_tab]->mapstorage.modified)
328 Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true,
329 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
330 mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
331 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
332 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
333 switch (mdialog.run())
335 case Gtk::RESPONSE_CANCEL:
337 case Gtk::RESPONSE_REJECT:
339 case Gtk::RESPONSE_ACCEPT:
340 tabs[active_tab]->saveFile();
344 //tabs vector will be decreased with the deleted value
345 int size=tabs.size();
348 for(int i=active_tab+1;i<size;i++)
350 tabnames[i-1]=tabnames[i];
354 //if size==1 resize will delete the only element
356 tabnames.resize(size-1);
358 int old_active_tab=active_tab;
359 notebook.remove_page(active_tab);
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,
367 if((old_active_tab==0)&&(size!=1))
372 //if this was the last page in notebook, there is
383 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
387 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
388 set_title(tabnames[active_tab]);
393 tabs[active_tab]->getView(autoscale, zoomtrack, width, radius);
394 edge_width->set_value(width);
395 radius_size->set_value(radius);
396 zoom_track->set_active(zoomtrack);
397 auto_scale->set_active(autoscale);
401 void MainWin::newFile()
405 tabs[active_tab]->newFile();
409 void MainWin::openFile()
415 tabs[active_tab]->openFile();
418 void MainWin::saveFile()
422 tabs[active_tab]->saveFile();
426 void MainWin::saveFileAs()
430 tabs[active_tab]->saveFileAs();
434 void MainWin::close()
438 tabs[active_tab]->close();
442 void MainWin::zoomIn()
446 tabs[active_tab]->gd_canvas->zoomIn();
450 void MainWin::zoomOut()
454 tabs[active_tab]->gd_canvas->zoomOut();
458 void MainWin::zoomFit()
462 tabs[active_tab]->gd_canvas->zoomFit();
466 void MainWin::zoom100()
470 tabs[active_tab]->gd_canvas->zoom100();
474 void MainWin::createMapWin()
478 tabs[active_tab]->createMapWin(tabnames[active_tab]);
482 void MainWin::createDesignWin()
486 tabs[active_tab]->createDesignWin(tabnames[active_tab]);
490 void MainWin::createAlgoWin(int algoid)
492 AlgoWin * aw=new AlgoWin(algoid, tabnames);
493 aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
494 aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
495 aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString));
500 void MainWin::updateAlgoWinTabs()
502 std::set< AlgoWin* >::iterator awsi=aws.begin();
503 for(;awsi!=aws.end();awsi++)
505 (*awsi)->update_tablist(tabnames);
509 void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
512 for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
515 awp->update_maplist(&(tabs[i]->mapstorage));
518 void MainWin::deRegisterAlgoWin(AlgoWin * awp)
523 void MainWin::changeEditorialTool(int tool)
528 tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
532 void MainWin::createNewMapWin()
536 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab]));
541 void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
544 for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++)
547 createNewMapWinAfterSignal(tabs[i], itisedge);
550 void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
552 std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
554 for(;nbti!=tabs.end();nbti++)
565 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false);
570 void MainWin::nodeViewChanged()
572 double width=edge_width->get_value();
573 double radius=radius_size->get_value();
574 bool zoomtrack=zoom_track->get_active();
575 bool autoscale=auto_scale->get_active();
576 tabs[active_tab]->setView(autoscale, zoomtrack, width, radius);
579 void MainWin::reDesignGraph()
581 tabs[active_tab]->reDesignGraph();