Use hg changeset hash instead of svn revision.
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
20 #include <mapstorage.h>
23 #include <design_win.h>
24 #include <graph_displayer_canvas.h>
28 NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), epswinexists(false)
30 mapstorage=new MapStorage();
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);
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));
47 NoteBookTab::~NoteBookTab()
52 void NoteBookTab::readFile(const std::string &file)
54 mapstorage->readFromFile(file);
55 mapstorage->setFileName(file);
56 mapstorage->setModified(false);
57 gd_canvas->drawDigraph();
61 mapstorage->getArcMapList(NUM),
62 mapstorage->getArcMapList(STR),
63 mapstorage->getNodeMapList(NUM),
64 mapstorage->getNodeMapList(STR));
66 title_changed(Glib::filename_display_basename(file));
69 void NoteBookTab::newFile()
71 if (mapstorage->getModified())
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())
80 case Gtk::RESPONSE_CANCEL:
82 case Gtk::RESPONSE_REJECT:
84 case Gtk::RESPONSE_ACCEPT:
94 mapstorage->getArcMapList(NUM),
95 mapstorage->getArcMapList(STR),
96 mapstorage->getNodeMapList(NUM),
97 mapstorage->getNodeMapList(STR));
99 title_changed("unsaved file");
102 void NoteBookTab::openFile()
104 if (mapstorage->getModified())
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())
113 case Gtk::RESPONSE_CANCEL:
115 case Gtk::RESPONSE_REJECT:
117 case Gtk::RESPONSE_ACCEPT:
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)
128 std::cout << mapstorage << std::endl;
130 Glib::ustring filename = fcdialog.get_filename();
131 if (!mapstorage->readFromFile(filename))
133 mapstorage->setFileName(filename);
134 mapstorage->setModified(false);
135 gd_canvas->drawDigraph();
139 mapstorage->getArcMapList(NUM),
140 mapstorage->getArcMapList(STR),
141 mapstorage->getNodeMapList(NUM),
142 mapstorage->getNodeMapList(STR));
144 title_changed(Glib::filename_display_basename(filename));
149 void NoteBookTab::saveFile()
151 if (mapstorage->getFileName() == "") {
156 mapstorage->writeToFile(mapstorage->getFileName());
157 mapstorage->setModified(false);
158 title_changed(Glib::filename_display_basename(mapstorage->getFileName()));
162 void NoteBookTab::saveFileAs()
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)
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));
177 void NoteBookTab::close()
179 if (mapstorage->getModified())
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())
188 case Gtk::RESPONSE_CANCEL:
190 case Gtk::RESPONSE_REJECT:
192 case Gtk::RESPONSE_ACCEPT:
202 mapstorage->getArcMapList(NUM),
203 mapstorage->getArcMapList(STR),
204 mapstorage->getNodeMapList(NUM),
205 mapstorage->getNodeMapList(STR));
207 title_changed("unsaved file");
210 void NoteBookTab::propertyChange(bool itisarc, int prop, std::string mapname)
212 mapstorage->changeActiveMap(itisarc, prop, mapname);
215 sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
217 return signal_newmap;
220 void NoteBookTab::popupNewMapWin(bool itisarc)
222 signal_newmap.emit(this, itisarc);
225 std::string NoteBookTab::getActiveArcMap(int prop)
227 return mapstorage->getActiveArcMap(prop);
230 std::string NoteBookTab::getActiveNodeMap(int prop)
232 return mapstorage->getActiveNodeMap(prop);
235 void NoteBookTab::registerNewArcMap(std::string mapname, MapValue::Type type)
239 mapwin->registerNewArcMap(mapname, type);
243 void NoteBookTab::registerNewNodeMap(std::string mapname, MapValue::Type type)
247 mapwin->registerNewNodeMap(mapname, type);
251 epswin->registerNewNodeMap(mapname, type);
255 void NoteBookTab::createMapWin(std::string name)
259 mapwin=new MapWin("Map Setup - "+name,
260 mapstorage->getArcMapList(NUM),
261 mapstorage->getArcMapList(STR),
262 mapstorage->getNodeMapList(NUM),
263 mapstorage->getNodeMapList(STR),
265 mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
271 void NoteBookTab::createExportToEPSWin(std::string name)
275 epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList(NUM), mapstorage->getNodeMapList(STR));
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));
285 void NoteBookTab::createDesignWin(std::string name)
289 double attraction, propulsation;
291 mapstorage->get_design_data(attraction, propulsation, iterations);
292 designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
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));
299 designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
301 mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data));
304 designwinexists=true;
308 void NoteBookTab::closeMapWin()
310 mapst2mapwin.disconnect();
315 void NoteBookTab::closeEpsWin()
321 bool NoteBookTab::closeDesignWin(GdkEventAny * e)
323 if(e->type==GDK_DELETE)
325 designwinexists=false;
326 mapst2designwin.disconnect();
331 sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
336 void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
338 gd_canvas->setView(autoscale, zoomtrack, width, radius);
341 void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
343 gd_canvas->getView(autoscale, zoomtrack, width, radius);
346 void NoteBookTab::reDesignDigraph()
348 gd_canvas->reDesignDigraph();
351 void NoteBookTab::active_maps_needed()
353 mapstorage->broadcastActiveMaps();
356 void NoteBookTab::exportDigraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap)
358 mapstorage->exportDigraphToEPS(options, filename, shapemap);
361 void NoteBookTab::title_changed(std::string newtitle)
363 signal_title.emit(newtitle);
366 epswin->set_title(newtitle);
370 designwin->set_title(newtitle);