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