No segmentation fault will be occured if two nodes are exactly overlap each other, AND they are connected.
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
21 NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), mapstorage(*this)
23 Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
24 gd_canvas=new GraphDisplayerCanvas(*this);
25 pScrolledWindow->add(*gd_canvas);
26 add(*pScrolledWindow);
28 //connecting signals - controller character
29 mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
30 mapstorage.signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap));
31 mapstorage.signal_edge_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewEdgeMap));
36 void NoteBookTab::readFile(const std::string &file)
38 mapstorage.readFromFile(file);
39 mapstorage.file_name = file;
40 mapstorage.modified = false;
41 gd_canvas->drawGraph();
44 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
46 signal_title.emit(Glib::filename_display_basename(file));
49 void NoteBookTab::newFile()
51 if (mapstorage.modified)
53 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
54 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
55 mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
56 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
57 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
58 switch (mdialog.run())
60 case Gtk::RESPONSE_CANCEL:
62 case Gtk::RESPONSE_REJECT:
64 case Gtk::RESPONSE_ACCEPT:
73 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
75 signal_title.emit("unsaved file");
78 void NoteBookTab::openFile()
80 if (mapstorage.modified)
82 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
83 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
84 mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
85 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
86 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
87 switch (mdialog.run())
89 case Gtk::RESPONSE_CANCEL:
91 case Gtk::RESPONSE_REJECT:
93 case Gtk::RESPONSE_ACCEPT:
98 Gtk::FileChooserDialog fcdialog("Open File");
99 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
100 fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
101 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
105 Glib::ustring filename = fcdialog.get_filename();
106 if (!mapstorage.readFromFile(filename))
108 mapstorage.file_name = filename;
109 mapstorage.modified = false;
110 gd_canvas->drawGraph();
113 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
115 signal_title.emit(Glib::filename_display_basename(filename));
120 void NoteBookTab::saveFile()
122 if (mapstorage.file_name == "") {
127 mapstorage.writeToFile(mapstorage.file_name);
128 mapstorage.modified = false;
129 signal_title.emit(Glib::filename_display_basename(mapstorage.file_name));
133 void NoteBookTab::saveFileAs()
135 Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
136 fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
137 fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
138 if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
140 Glib::ustring filename = fcdialog.get_filename();
141 mapstorage.file_name = filename;
142 mapstorage.writeToFile(filename);
143 mapstorage.modified = false;
144 signal_title.emit(Glib::filename_display_basename(filename));
148 void NoteBookTab::close()
150 if (mapstorage.modified)
152 Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
153 Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
154 mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
155 mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
156 mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
157 switch (mdialog.run())
159 case Gtk::RESPONSE_CANCEL:
161 case Gtk::RESPONSE_REJECT:
163 case Gtk::RESPONSE_ACCEPT:
172 mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
174 signal_title.emit("unsaved file");
177 void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
179 mapstorage.changeActiveMap(itisedge, prop, mapname);
182 sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
184 return signal_newmap;
187 void NoteBookTab::popupNewMapWin(bool itisedge)
189 signal_newmap.emit(this, itisedge);
192 std::string NoteBookTab::getActiveEdgeMap(int prop)
194 return mapstorage.getActiveEdgeMap(prop);
197 std::string NoteBookTab::getActiveNodeMap(int prop)
199 return mapstorage.getActiveNodeMap(prop);
202 void NoteBookTab::registerNewEdgeMap(std::string mapname)
206 mapwin->registerNewEdgeMap(mapname);
210 void NoteBookTab::registerNewNodeMap(std::string mapname)
214 mapwin->registerNewNodeMap(mapname);
218 void NoteBookTab::createMapWin(std::string name)
222 mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
223 mapst2mapwin=mapstorage.signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
229 void NoteBookTab::createDesignWin(std::string name)
233 double attraction, propulsation;
235 mapstorage.get_design_data(attraction, propulsation, iterations);
236 designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations, *this);
238 designwin->signal_attraction().connect(sigc::mem_fun(mapstorage, &MapStorage::set_attraction));
239 designwin->signal_propulsation().connect(sigc::mem_fun(mapstorage, &MapStorage::set_propulsation));
240 designwin->signal_iteration().connect(sigc::mem_fun(mapstorage, &MapStorage::set_iteration));
241 designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::reDesignGraph));
243 designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
245 mapst2designwin=mapstorage.signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data));
248 designwinexists=true;
252 void NoteBookTab::closeMapWin()
254 mapst2mapwin.disconnect();
259 bool NoteBookTab::closeDesignWin(GdkEventAny * e)
261 if(e->type==GDK_DELETE)
263 designwinexists=false;
264 mapst2designwin.disconnect();
269 sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
274 void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
276 gd_canvas->setView(autoscale, zoomtrack, width, radius);
279 void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
281 gd_canvas->getView(autoscale, zoomtrack, width, radius);
284 void NoteBookTab::reDesignGraph()
286 gd_canvas->reDesignGraph();
289 void NoteBookTab::active_maps_needed()
291 mapstorage.broadcastActiveMaps();