6 #include "guipixbufs.h"
12 set_title ("no file");
13 set_default_size(WIN_WIDTH,WIN_HEIGHT);
17 // custom icons for the toolbar
18 Glib::RefPtr<Gtk::IconFactory> p_icon_factory = Gtk::IconFactory::create();
20 Glib::RefPtr<Gdk::Pixbuf> p_move_pixbuf = Gdk::Pixbuf::create_from_inline(
21 2328, gui_icons_move);
22 Glib::RefPtr<Gdk::Pixbuf> p_addnode_pixbuf = Gdk::Pixbuf::create_from_inline(
23 2328, gui_icons_addnode);
24 Glib::RefPtr<Gdk::Pixbuf> p_addlink_pixbuf = Gdk::Pixbuf::create_from_inline(
25 2328, gui_icons_addlink);
26 Glib::RefPtr<Gdk::Pixbuf> p_delete_pixbuf = Gdk::Pixbuf::create_from_inline(
27 2328, gui_icons_delete);
28 Glib::RefPtr<Gdk::Pixbuf> p_editlink_pixbuf = Gdk::Pixbuf::create_from_inline(
29 2328, gui_icons_editlink);
30 Glib::RefPtr<Gdk::Pixbuf> p_newmap_pixbuf = Gdk::Pixbuf::create_from_inline(
31 2328, gui_icons_newmap);
33 Gtk::IconSource move_icon_source;
34 move_icon_source.set_pixbuf(p_move_pixbuf);
35 Gtk::IconSet move_icon_set;
36 move_icon_set.add_source(move_icon_source);
37 p_icon_factory->add(Gtk::StockID("gd-move"), move_icon_set);
39 Gtk::IconSource addnode_icon_source;
40 addnode_icon_source.set_pixbuf(p_addnode_pixbuf);
41 Gtk::IconSet addnode_icon_set;
42 addnode_icon_set.add_source(addnode_icon_source);
43 p_icon_factory->add(Gtk::StockID("gd-addnode"), addnode_icon_set);
45 Gtk::IconSource addlink_icon_source;
46 addlink_icon_source.set_pixbuf(p_addlink_pixbuf);
47 Gtk::IconSet addlink_icon_set;
48 addlink_icon_set.add_source(addlink_icon_source);
49 p_icon_factory->add(Gtk::StockID("gd-addlink"), addlink_icon_set);
51 Gtk::IconSource delete_icon_source;
52 delete_icon_source.set_pixbuf(p_delete_pixbuf);
53 Gtk::IconSet delete_icon_set;
54 delete_icon_set.add_source(delete_icon_source);
55 p_icon_factory->add(Gtk::StockID("gd-delete"), delete_icon_set);
57 Gtk::IconSource editlink_icon_source;
58 editlink_icon_source.set_pixbuf(p_editlink_pixbuf);
59 Gtk::IconSet editlink_icon_set;
60 editlink_icon_set.add_source(editlink_icon_source);
61 p_icon_factory->add(Gtk::StockID("gd-editlink"), editlink_icon_set);
63 Gtk::IconSource newmap_icon_source;
64 newmap_icon_source.set_pixbuf(p_newmap_pixbuf);
65 Gtk::IconSet newmap_icon_set;
66 newmap_icon_set.add_source(newmap_icon_source);
67 p_icon_factory->add(Gtk::StockID("gd-newmap"), newmap_icon_set);
69 p_icon_factory->add_default();
71 ag=Gtk::ActionGroup::create();
73 ag->add( Gtk::Action::create("FileMenu", _("_File")) );
74 ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
75 sigc::mem_fun(*this, &MainWin::newTab));
76 ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
77 sigc::mem_fun(*this, &MainWin::openFile));
78 ag->add( Gtk::Action::create("FileClearTab", _("Clear Tab")),
79 sigc::mem_fun(*this, &MainWin::newFile));
80 ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
81 sigc::mem_fun(*this, &MainWin::saveFile));
82 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
83 sigc::mem_fun(*this, &MainWin::saveFileAs));
84 ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
85 sigc::mem_fun(*this, &MainWin::closeTab));
86 ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
87 sigc::mem_fun(*this, &MainWin::hide));
89 ag->add( Gtk::Action::create("ViewMenu", _("_View")) );
90 ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
91 sigc::mem_fun(*this, &MainWin::zoomIn));
92 ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
93 sigc::mem_fun(*this, &MainWin::zoomOut));
94 ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
95 sigc::mem_fun(*this, &MainWin::zoomFit));
96 ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
97 sigc::mem_fun(*this, &MainWin::zoom100));
99 ag->add( Gtk::Action::create("ShowMenu", _("_Show")) );
100 ag->add( Gtk::Action::create("ShowMaps", _("_Maps")),
101 sigc::mem_fun(*this, &MainWin::createMapWin));
102 ag->add( Gtk::Action::create("ShowDesign", _("_Design")),
103 sigc::mem_fun(*this, &MainWin::createDesignWin));
105 ag->add( Gtk::Action::create("AlgoMenu", _("_Algorithms")) );
106 ag->add( Gtk::Action::create("AlgoGeneral", _("_General")),
107 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 0) );
108 ag->add( Gtk::Action::create("AlgoKruskal", _("_Kruskal")),
109 sigc::bind( sigc::mem_fun ( *this, &MainWin::createAlgoWin ), 1) );
111 Gtk::RadioAction::Group tool_group;
112 ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::StockID("gd-move"), _("Move")),
113 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 0) );
114 ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::StockID("gd-addnode"), _("Create node")),
115 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 1) );
116 ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::StockID("gd-addlink"), _("Create edge")),
117 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 2) );
118 ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::StockID("gd-delete"), _("Delete")),
119 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 3) );
121 ag->add( Gtk::RadioAction::create(tool_group, "EditEdgeMap", Gtk::StockID("gd-editlink"), _("Edit edge map")),
122 sigc::bind( sigc::mem_fun ( *this, &MainWin::changeEditorialTool ), 4) );
124 ag->add( Gtk::Action::create("AddMap", Gtk::StockID("gd-newmap")),
125 sigc::mem_fun ( *this , &MainWin::createNewMapWin ) );
127 ag->add( Gtk::Action::create("DesignGraph", Gtk::Stock::REFRESH),
128 sigc::mem_fun ( *this , &MainWin::reDesignGraph ) );
130 uim=Gtk::UIManager::create();
131 uim->insert_action_group(ag);
132 add_accel_group(uim->get_accel_group());
137 Glib::ustring ui_info =
139 " <menubar name='MenuBar'>"
140 " <menu action='FileMenu'>"
141 " <menuitem action='FileNew'/>"
142 " <menuitem action='FileOpen'/>"
143 " <menuitem action='FileClearTab'/>"
144 " <menuitem action='FileSave'/>"
145 " <menuitem action='FileSaveAs'/>"
146 " <menuitem action='Close'/>"
147 " <menuitem action='Quit'/>"
149 " <menu action='ViewMenu'>"
150 " <menuitem action='ViewZoomIn' />"
151 " <menuitem action='ViewZoomOut' />"
152 " <menuitem action='ViewZoom100' />"
153 " <menuitem action='ViewZoomFit' />"
155 " <menu action='ShowMenu'>"
156 " <menuitem action='ShowMaps'/>"
157 " <menuitem action='ShowDesign'/>"
159 " <menu action='AlgoMenu'>"
160 " <menuitem action='AlgoGeneral'/>"
161 " <menuitem action='AlgoKruskal'/>"
164 " <toolbar name='ToolBar'>"
165 " <toolitem action='FileNew' />"
166 " <toolitem action='FileOpen' />"
167 " <toolitem action='FileSave' />"
168 " <toolitem action='Close' />"
170 " <toolitem action='ViewZoomIn' />"
171 " <toolitem action='ViewZoomOut' />"
172 " <toolitem action='ViewZoom100' />"
173 " <toolitem action='ViewZoomFit' />"
175 " <toolitem action='MoveItem' />"
176 " <toolitem action='CreateNode' />"
177 " <toolitem action='CreateEdge' />"
178 " <toolitem action='EraseItem' />"
179 " <toolitem action='EditEdgeMap' />"
181 " <toolitem action='AddMap' />"
182 " <toolitem action='DesignGraph' />"
186 uim->add_ui_from_string(ui_info);
189 catch(const Glib::Error& ex)
191 std::cerr << "building menus failed: " << ex.what();
194 Gtk::Widget* menubar = uim->get_widget("/MenuBar");
196 //vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
197 table.attach(*menubar, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
200 Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
203 static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
204 //hbox.pack_start(*toolbar, Gtk::PACK_EXPAND_WIDGET);
206 table.attach(*toolbar, 0, 1, 1, 2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK);
210 table2.set_row_spacings(10);
211 table2.set_col_spacings(5);
213 auto_scale = new Gtk::CheckButton("Autoscale");
214 auto_scale->set_active(false);
215 auto_scale->signal_toggled().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
216 table2.attach(*auto_scale, 0,2,0,1);
218 Gtk::Label * width_label= new Gtk::Label("Edge Width:");
219 table2.attach(*width_label, 0,1,1,2);
221 Gtk::Adjustment * adjustment_width=new Gtk::Adjustment(20, 1, 200, 5, 10);
223 edge_width = new Gtk::SpinButton(*adjustment_width, 5,0);
224 edge_width->signal_value_changed().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
225 table2.attach(*edge_width, 1,2,1,2);
227 Gtk::Label * radius_label= new Gtk::Label("Node Radius:");
228 table2.attach(*radius_label, 2,3,1,2);
230 Gtk::Adjustment * adjustment_radius=new Gtk::Adjustment(20, 0, 500, 5, 10);
232 radius_size = new Gtk::SpinButton(*adjustment_radius, 5,0);
233 radius_size->signal_value_changed().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
234 table2.attach(*radius_size, 3,4,1,2);
236 zoom_track = new Gtk::CheckButton("Zoom tracking");
237 zoom_track->set_active(false);
238 zoom_track->signal_toggled().connect(sigc::mem_fun(*this, &MainWin::nodeViewChanged));
239 table2.attach(*zoom_track, 2,4,0,1);
242 table.attach(table2, 1, 2, 0, 2, Gtk::SHRINK, Gtk::SHRINK);
244 tooltips.set_tip(*(uim->get_widget("/ToolBar/CreateNode")),"Create Node");
248 notebook.signal_switch_page().connect(sigc::mem_fun(*this, &MainWin::onChangeTab));
252 table.attach(notebook,0,2,2,3, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL);
257 void MainWin::set_tabtitle(std::string name)
259 if(strinst.find(name)==strinst.end())
261 tabnames[active_tab]=name;
267 std::ostringstream o;
269 tabnames[active_tab]=name+" - "+o.str();
271 set_title(tabnames[active_tab] + " - " + prog_name);
272 notebook.set_tab_label_text((Widget&)*(tabs[active_tab]), tabnames[active_tab]);
276 void MainWin::readFile(const std::string & filename)
279 tabs[active_tab]->readFile(filename);
282 void MainWin::newTab()
284 int size=tabs.size();
286 tabnames.resize(size+1);
288 tabs[active_tab]=new NoteBookTab();
289 tabs[active_tab]->signal_title_ch().connect(sigc::mem_fun(*this, &MainWin::set_tabtitle));
290 tabs[active_tab]->signal_newmap_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinAfterSignal));
291 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
292 notebook.append_page((Gtk::Widget&)(*(tabs[active_tab])));
293 notebook.set_current_page(size);
294 set_tabtitle(_("unsaved file"));
298 void MainWin::closeTab()
302 if (tabs[active_tab]->mapstorage.modified)
304 Gtk::MessageDialog mdialog(_("<b>Save changes before closing?</b>"), true,
305 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
306 mdialog.add_button(_("Close file _without Saving"), Gtk::RESPONSE_REJECT);
307 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
308 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
309 switch (mdialog.run())
311 case Gtk::RESPONSE_CANCEL:
313 case Gtk::RESPONSE_REJECT:
315 case Gtk::RESPONSE_ACCEPT:
316 tabs[active_tab]->saveFile();
320 //tabs vector will be decreased with the deleted value
321 int size=tabs.size();
324 for(int i=active_tab+1;i<size;i++)
326 tabnames[i-1]=tabnames[i];
330 //if size==1 resize will delete the only element
332 tabnames.resize(size-1);
334 int old_active_tab=active_tab;
335 notebook.remove_page(active_tab);
337 //If the first tab was active, upon delete notebook
338 //will first switch one tab upper and not lower like
339 //in the case, when not the first tab was active.
340 //But after deletion it will become the first tab,
341 //and this should be registrated in tabs vector,
343 if((old_active_tab==0)&&(size!=1))
348 //if this was the last page in notebook, there is
359 void MainWin::onChangeTab(GtkNotebookPage* page, guint page_num)
363 tabs[active_tab]->gd_canvas->changeEditorialTool(active_tool);
364 set_title(tabnames[active_tab]);
369 tabs[active_tab]->getView(autoscale, zoomtrack, width, radius);
370 edge_width->set_value(width);
371 radius_size->set_value(radius);
372 zoom_track->set_active(zoomtrack);
373 auto_scale->set_active(autoscale);
377 void MainWin::newFile()
381 tabs[active_tab]->newFile();
385 void MainWin::openFile()
391 tabs[active_tab]->openFile();
394 void MainWin::saveFile()
398 tabs[active_tab]->saveFile();
402 void MainWin::saveFileAs()
406 tabs[active_tab]->saveFileAs();
410 void MainWin::close()
414 tabs[active_tab]->close();
418 void MainWin::zoomIn()
422 tabs[active_tab]->gd_canvas->zoomIn();
426 void MainWin::zoomOut()
430 tabs[active_tab]->gd_canvas->zoomOut();
434 void MainWin::zoomFit()
438 tabs[active_tab]->gd_canvas->zoomFit();
442 void MainWin::zoom100()
446 tabs[active_tab]->gd_canvas->zoom100();
450 void MainWin::createMapWin()
454 tabs[active_tab]->createMapWin(tabnames[active_tab]);
458 void MainWin::createDesignWin()
462 tabs[active_tab]->createDesignWin(tabnames[active_tab]);
466 void MainWin::createAlgoWin(int algoid)
468 AlgoWin * aw=new AlgoWin(algoid, tabnames);
469 aw->signal_closing().connect(sigc::mem_fun(*this, &MainWin::deRegisterAlgoWin));
470 aw->signal_maplist_needed().connect(sigc::mem_fun(*this, &MainWin::updateAlgoWinMaps));
471 aw->signal_newmapwin_needed().connect(sigc::mem_fun(*this, &MainWin::createNewMapWinTabString));
476 void MainWin::updateAlgoWinTabs()
478 std::set< AlgoWin* >::iterator awsi=aws.begin();
479 for(;awsi!=aws.end();awsi++)
481 (*awsi)->update_tablist(tabnames);
485 void MainWin::updateAlgoWinMaps(AlgoWin * awp, std::string tabname)
488 for(;(i<(int)tabnames.size())&&(tabnames[i]!=tabname);i++)
491 awp->update_maplist(&(tabs[i]->mapstorage));
494 void MainWin::deRegisterAlgoWin(AlgoWin * awp)
499 void MainWin::changeEditorialTool(int tool)
504 tabs[active_tab]->gd_canvas->changeEditorialTool(tool);
508 void MainWin::createNewMapWin()
512 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[active_tab], *(tabs[active_tab]));
517 void MainWin::createNewMapWinTabString(std::string tabname, bool itisedge)
520 for(;((i<(int)tabnames.size())&&(tabnames[i]!=tabname));i++)
523 createNewMapWinAfterSignal(tabs[i], itisedge);
526 void MainWin::createNewMapWinAfterSignal(NoteBookTab * nbt, bool itisedge)
528 std::vector<NoteBookTab*>::iterator nbti=tabs.begin();
530 for(;nbti!=tabs.end();nbti++)
541 NewMapWin * nmw=new NewMapWin(_("Create New Map - ")+tabnames[i], *nbt, itisedge, false);
546 void MainWin::nodeViewChanged()
548 double width=edge_width->get_value();
549 double radius=radius_size->get_value();
550 bool zoomtrack=zoom_track->get_active();
551 bool autoscale=auto_scale->get_active();
552 tabs[active_tab]->setView(autoscale, zoomtrack, width, radius);
555 void MainWin::reDesignGraph()
557 tabs[active_tab]->reDesignGraph();