COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/main_win.cc @ 1523:144ab0e4b09c

Last change on this file since 1523:144ab0e4b09c was 1512:e54392395480, checked in by Hegyi Péter, 15 years ago

NodeMap? values are now visualizable. Todo: default map-values

File size: 5.1 KB
Line 
1#include <main_win.h>
2
3MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
4    MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
5{
6  set_title (title);
7  set_default_size(WIN_WIDTH,WIN_HEIGHT);
8  add(vbox);
9
10  ag=Gtk::ActionGroup::create();
11
12  ag->add( Gtk::Action::create("FileMenu", "_File") );
13  ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
14      sigc::mem_fun(*this, &MainWin::newFile));
15  ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
16      sigc::mem_fun(*this, &MainWin::openFile));
17  ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
18      sigc::mem_fun(*this, &MainWin::saveFile));
19  ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
20      sigc::mem_fun(*this, &MainWin::saveFileAs));
21  ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
22      sigc::mem_fun(*this, &MainWin::quit));
23
24  ag->add( Gtk::Action::create("ViewMenu", "_View") );
25  ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
26      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
27  ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
28      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
29  ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
30      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
31  ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
32      sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
33 
34  ag->add( Gtk::Action::create("ShowMenu", "_Show") );
35  ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
36      sigc::mem_fun(*this, &MainWin::showMaps));
37  ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"),
38      sigc::mem_fun(*this, &MainWin::showEditorials));
39
40  ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO),
41      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
42  ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE),
43      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
44  ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE),
45      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
46  ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT),
47      sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
48
49  uim=Gtk::UIManager::create();
50  uim->insert_action_group(ag);
51  add_accel_group(uim->get_accel_group());
52
53  try
54  {
55
56    Glib::ustring ui_info =
57      "<ui>"
58      "  <menubar name='MenuBar'>"
59      "    <menu action='FileMenu'>"
60      "      <menuitem action='FileNew'/>"
61      "      <menuitem action='FileOpen'/>"
62      "      <menuitem action='FileSave'/>"
63      "      <menuitem action='FileSaveAs'/>"
64      "      <menuitem action='FileQuit'/>"
65      "    </menu>"
66      "    <menu action='ViewMenu'>"
67      "      <menuitem action='ViewZoomIn' />"
68      "      <menuitem action='ViewZoomOut' />"
69      "      <menuitem action='ViewZoomFit' />"
70      "      <menuitem action='ViewZoom100' />"
71      "    </menu>"
72      "    <menu action='ShowMenu'>"
73      "      <menuitem action='ShowMaps'/>"
74      "      <menuitem action='ShowEditorials'/>"
75      "    </menu>"
76      "  </menubar>"
77      "  <toolbar name='ToolBar'>"
78      "    <toolitem action='FileNew' />"
79      "    <toolitem action='FileOpen' />"
80      "    <toolitem action='FileSave' />"
81      "    <separator />"
82      "    <toolitem action='ViewZoomIn' />"
83      "    <toolitem action='ViewZoomOut' />"
84      "    <toolitem action='ViewZoomFit' />"
85      "    <toolitem action='ViewZoom100' />"
86      "    <separator />"
87      "    <toolitem action='CreateNode' />"
88      "    <toolitem action='CreateEdge' />"
89      "    <toolitem action='EraseItem' />"
90      "    <toolitem action='MoveItem' />"
91      "  </toolbar>"
92      "</ui>";
93
94    uim->add_ui_from_string(ui_info);
95
96  }
97  catch(const Glib::Error& ex)
98  {
99    std::cerr << "building menus failed: " <<  ex.what();
100  }
101
102  Gtk::Widget* menubar = uim->get_widget("/MenuBar");
103  if (menubar){
104    vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
105  }
106
107  Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
108  if (toolbar)
109  {
110    static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
111    vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
112  }
113
114  Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
115  pScrolledWindow->add(gd_canvas);
116  vbox.pack_start(*pScrolledWindow);
117  //vbox.pack_start(gd_canvas);
118
119  show_all_children();
120}
121
122void MainWin::showMaps()
123{
124  mapwin.show();
125}
126
127void MainWin::showEditorials()
128{
129  editwin.show();
130}
131
132void MainWin::quit()
133{
134  hide();
135}
136
137void MainWin::newFile()
138{
139  std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
140}
141
142void MainWin::openFile()
143{
144  std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
145}
146
147void MainWin::saveFile()
148{
149  std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
150}
151
152void MainWin::saveFileAs()
153{
154  std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
155}
Note: See TracBrowser for help on using the repository browser.