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 | |
---|
19 | #include <nbtab.h> |
---|
20 | #include <mapstorage.h> |
---|
21 | #include <eps_win.h> |
---|
22 | #include <map_win.h> |
---|
23 | #include <design_win.h> |
---|
24 | #include <graph_displayer_canvas.h> |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), epswinexists(false) |
---|
29 | { |
---|
30 | mapstorage=new MapStorage(); |
---|
31 | |
---|
32 | Gtk::ScrolledWindow *pScrolledWindow = Gtk::manage(new Gtk::ScrolledWindow); |
---|
33 | pScrolledWindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN); |
---|
34 | gd_canvas=Gtk::manage(new DigraphDisplayerCanvas(*this)); |
---|
35 | pScrolledWindow->add(*gd_canvas); |
---|
36 | add(*pScrolledWindow); |
---|
37 | |
---|
38 | //connecting signals - controller character |
---|
39 | mapstorage->signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::propertyChange)); |
---|
40 | mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap)); |
---|
41 | mapstorage->signal_arc_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewArcMap)); |
---|
42 | mapstorage->signal_background_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::setBackground)); |
---|
43 | show_all_children(); |
---|
44 | show(); |
---|
45 | } |
---|
46 | |
---|
47 | NoteBookTab::~NoteBookTab() |
---|
48 | { |
---|
49 | delete mapstorage; |
---|
50 | } |
---|
51 | |
---|
52 | void NoteBookTab::readFile(const std::string &file) |
---|
53 | { |
---|
54 | mapstorage->readFromFile(file); |
---|
55 | mapstorage->setFileName(file); |
---|
56 | mapstorage->setModified(false); |
---|
57 | gd_canvas->drawDigraph(); |
---|
58 | if(mapwinexists) |
---|
59 | { |
---|
60 | mapwin->update( |
---|
61 | mapstorage->getArcMapList(NUM), |
---|
62 | mapstorage->getArcMapList(STR), |
---|
63 | mapstorage->getNodeMapList(NUM), |
---|
64 | mapstorage->getNodeMapList(STR)); |
---|
65 | } |
---|
66 | title_changed(Glib::filename_display_basename(file)); |
---|
67 | } |
---|
68 | |
---|
69 | void NoteBookTab::newFile() |
---|
70 | { |
---|
71 | if (mapstorage->getModified()) |
---|
72 | { |
---|
73 | Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, |
---|
74 | Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
---|
75 | mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT); |
---|
76 | mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
---|
77 | mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
---|
78 | switch (mdialog.run()) |
---|
79 | { |
---|
80 | case Gtk::RESPONSE_CANCEL: |
---|
81 | return; |
---|
82 | case Gtk::RESPONSE_REJECT: |
---|
83 | break; |
---|
84 | case Gtk::RESPONSE_ACCEPT: |
---|
85 | saveFile(); |
---|
86 | break; |
---|
87 | } |
---|
88 | } |
---|
89 | gd_canvas->clear(); |
---|
90 | mapstorage->clear(); |
---|
91 | if(mapwinexists) |
---|
92 | { |
---|
93 | mapwin->update( |
---|
94 | mapstorage->getArcMapList(NUM), |
---|
95 | mapstorage->getArcMapList(STR), |
---|
96 | mapstorage->getNodeMapList(NUM), |
---|
97 | mapstorage->getNodeMapList(STR)); |
---|
98 | } |
---|
99 | title_changed("unsaved file"); |
---|
100 | } |
---|
101 | |
---|
102 | void NoteBookTab::openFile() |
---|
103 | { |
---|
104 | if (mapstorage->getModified()) |
---|
105 | { |
---|
106 | Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, |
---|
107 | Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
---|
108 | mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT); |
---|
109 | mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
---|
110 | mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
---|
111 | switch (mdialog.run()) |
---|
112 | { |
---|
113 | case Gtk::RESPONSE_CANCEL: |
---|
114 | return; |
---|
115 | case Gtk::RESPONSE_REJECT: |
---|
116 | break; |
---|
117 | case Gtk::RESPONSE_ACCEPT: |
---|
118 | saveFile(); |
---|
119 | break; |
---|
120 | } |
---|
121 | } |
---|
122 | Gtk::FileChooserDialog fcdialog("Open File"); |
---|
123 | fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
---|
124 | fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); |
---|
125 | if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) |
---|
126 | { |
---|
127 | gd_canvas->clear(); |
---|
128 | std::cout << mapstorage << std::endl; |
---|
129 | mapstorage->clear(); |
---|
130 | Glib::ustring filename = fcdialog.get_filename(); |
---|
131 | if (!mapstorage->readFromFile(filename)) |
---|
132 | { |
---|
133 | mapstorage->setFileName(filename); |
---|
134 | mapstorage->setModified(false); |
---|
135 | gd_canvas->drawDigraph(); |
---|
136 | if(mapwinexists) |
---|
137 | { |
---|
138 | mapwin->update( |
---|
139 | mapstorage->getArcMapList(NUM), |
---|
140 | mapstorage->getArcMapList(STR), |
---|
141 | mapstorage->getNodeMapList(NUM), |
---|
142 | mapstorage->getNodeMapList(STR)); |
---|
143 | } |
---|
144 | title_changed(Glib::filename_display_basename(filename)); |
---|
145 | } |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | void NoteBookTab::saveFile() |
---|
150 | { |
---|
151 | if (mapstorage->getFileName() == "") { |
---|
152 | saveFileAs(); |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | mapstorage->writeToFile(mapstorage->getFileName()); |
---|
157 | mapstorage->setModified(false); |
---|
158 | title_changed(Glib::filename_display_basename(mapstorage->getFileName())); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | void NoteBookTab::saveFileAs() |
---|
163 | { |
---|
164 | Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); |
---|
165 | fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
---|
166 | fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
---|
167 | if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) |
---|
168 | { |
---|
169 | Glib::ustring filename = fcdialog.get_filename(); |
---|
170 | mapstorage->setFileName(filename); |
---|
171 | mapstorage->writeToFile(filename); |
---|
172 | mapstorage->setModified(false); |
---|
173 | title_changed(Glib::filename_display_basename(filename)); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | void NoteBookTab::close() |
---|
178 | { |
---|
179 | if (mapstorage->getModified()) |
---|
180 | { |
---|
181 | Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, |
---|
182 | Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); |
---|
183 | mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); |
---|
184 | mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
---|
185 | mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); |
---|
186 | switch (mdialog.run()) |
---|
187 | { |
---|
188 | case Gtk::RESPONSE_CANCEL: |
---|
189 | return; |
---|
190 | case Gtk::RESPONSE_REJECT: |
---|
191 | break; |
---|
192 | case Gtk::RESPONSE_ACCEPT: |
---|
193 | saveFile(); |
---|
194 | break; |
---|
195 | } |
---|
196 | } |
---|
197 | gd_canvas->clear(); |
---|
198 | mapstorage->clear(); |
---|
199 | if(mapwinexists) |
---|
200 | { |
---|
201 | mapwin->update( |
---|
202 | mapstorage->getArcMapList(NUM), |
---|
203 | mapstorage->getArcMapList(STR), |
---|
204 | mapstorage->getNodeMapList(NUM), |
---|
205 | mapstorage->getNodeMapList(STR)); |
---|
206 | } |
---|
207 | title_changed("unsaved file"); |
---|
208 | } |
---|
209 | |
---|
210 | void NoteBookTab::propertyChange(bool itisarc, int prop, std::string mapname) |
---|
211 | { |
---|
212 | mapstorage->changeActiveMap(itisarc, prop, mapname); |
---|
213 | } |
---|
214 | |
---|
215 | sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed() |
---|
216 | { |
---|
217 | return signal_newmap; |
---|
218 | } |
---|
219 | |
---|
220 | void NoteBookTab::popupNewMapWin(bool itisarc) |
---|
221 | { |
---|
222 | signal_newmap.emit(this, itisarc); |
---|
223 | } |
---|
224 | |
---|
225 | std::string NoteBookTab::getActiveArcMap(int prop) |
---|
226 | { |
---|
227 | return mapstorage->getActiveArcMap(prop); |
---|
228 | } |
---|
229 | |
---|
230 | std::string NoteBookTab::getActiveNodeMap(int prop) |
---|
231 | { |
---|
232 | return mapstorage->getActiveNodeMap(prop); |
---|
233 | } |
---|
234 | |
---|
235 | void NoteBookTab::registerNewArcMap(std::string mapname, MapValue::Type type) |
---|
236 | { |
---|
237 | if(mapwinexists) |
---|
238 | { |
---|
239 | mapwin->registerNewArcMap(mapname, type); |
---|
240 | } |
---|
241 | } |
---|
242 | |
---|
243 | void NoteBookTab::registerNewNodeMap(std::string mapname, MapValue::Type type) |
---|
244 | { |
---|
245 | if(mapwinexists) |
---|
246 | { |
---|
247 | mapwin->registerNewNodeMap(mapname, type); |
---|
248 | } |
---|
249 | if(epswinexists) |
---|
250 | { |
---|
251 | epswin->registerNewNodeMap(mapname, type); |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | void NoteBookTab::createMapWin(std::string name) |
---|
256 | { |
---|
257 | if(!mapwinexists) |
---|
258 | { |
---|
259 | mapwin=new MapWin("Map Setup - "+name, |
---|
260 | mapstorage->getArcMapList(NUM), |
---|
261 | mapstorage->getArcMapList(STR), |
---|
262 | mapstorage->getNodeMapList(NUM), |
---|
263 | mapstorage->getNodeMapList(STR), |
---|
264 | *this); |
---|
265 | mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry)); |
---|
266 | mapwin->show(); |
---|
267 | mapwinexists=true; |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | void NoteBookTab::createExportToEPSWin(std::string name) |
---|
272 | { |
---|
273 | if(!epswinexists) |
---|
274 | { |
---|
275 | epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList(NUM), mapstorage->getNodeMapList(STR)); |
---|
276 | epswin->show(); |
---|
277 | epswinexists=true; |
---|
278 | epswin->signal_eps_details_ch().connect(sigc::mem_fun(*this, &NoteBookTab::exportDigraphToEPS)); |
---|
279 | epswin->signal_eps_close_ch().connect(sigc::mem_fun(*this, &NoteBookTab::closeEpsWin)); |
---|
280 | epswin->signal_new_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::popupNewMapWin)); |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | |
---|
285 | void NoteBookTab::createDesignWin(std::string name) |
---|
286 | { |
---|
287 | if(!designwinexists) |
---|
288 | { |
---|
289 | double attraction, propulsation; |
---|
290 | int iterations; |
---|
291 | mapstorage->get_design_data(attraction, propulsation, iterations); |
---|
292 | designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations); |
---|
293 | |
---|
294 | designwin->signal_attraction().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_attraction)); |
---|
295 | designwin->signal_propulsation().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_propulsation)); |
---|
296 | designwin->signal_iteration().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_iteration)); |
---|
297 | designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::reDesignDigraph)); |
---|
298 | |
---|
299 | designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin)); |
---|
300 | |
---|
301 | mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data)); |
---|
302 | |
---|
303 | designwin->show(); |
---|
304 | designwinexists=true; |
---|
305 | } |
---|
306 | } |
---|
307 | |
---|
308 | void NoteBookTab::closeMapWin() |
---|
309 | { |
---|
310 | mapst2mapwin.disconnect(); |
---|
311 | mapwinexists=false; |
---|
312 | delete mapwin; |
---|
313 | } |
---|
314 | |
---|
315 | void NoteBookTab::closeEpsWin() |
---|
316 | { |
---|
317 | epswinexists=false; |
---|
318 | delete epswin; |
---|
319 | } |
---|
320 | |
---|
321 | bool NoteBookTab::closeDesignWin(GdkEventAny * e) |
---|
322 | { |
---|
323 | if(e->type==GDK_DELETE) |
---|
324 | { |
---|
325 | designwinexists=false; |
---|
326 | mapst2designwin.disconnect(); |
---|
327 | delete designwin; |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | sigc::signal<void, std::string> NoteBookTab::signal_title_ch() |
---|
332 | { |
---|
333 | return signal_title; |
---|
334 | } |
---|
335 | |
---|
336 | void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius) |
---|
337 | { |
---|
338 | gd_canvas->setView(autoscale, zoomtrack, width, radius); |
---|
339 | } |
---|
340 | |
---|
341 | void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius) |
---|
342 | { |
---|
343 | gd_canvas->getView(autoscale, zoomtrack, width, radius); |
---|
344 | } |
---|
345 | |
---|
346 | void NoteBookTab::reDesignDigraph() |
---|
347 | { |
---|
348 | gd_canvas->reDesignDigraph(); |
---|
349 | } |
---|
350 | |
---|
351 | void NoteBookTab::active_maps_needed() |
---|
352 | { |
---|
353 | mapstorage->broadcastActiveMaps(); |
---|
354 | } |
---|
355 | |
---|
356 | void NoteBookTab::exportDigraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap) |
---|
357 | { |
---|
358 | mapstorage->exportDigraphToEPS(options, filename, shapemap); |
---|
359 | } |
---|
360 | |
---|
361 | void NoteBookTab::title_changed(std::string newtitle) |
---|
362 | { |
---|
363 | signal_title.emit(newtitle); |
---|
364 | if(epswinexists) |
---|
365 | { |
---|
366 | epswin->set_title(newtitle); |
---|
367 | } |
---|
368 | if(designwinexists) |
---|
369 | { |
---|
370 | designwin->set_title(newtitle); |
---|
371 | } |
---|
372 | } |
---|