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