hegyi@1: /* -*- C++ -*- hegyi@1: * hegyi@1: * This file is a part of LEMON, a generic C++ optimization library hegyi@1: * hegyi@1: * Copyright (C) 2003-2006 hegyi@1: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport hegyi@1: * (Egervary Research Group on Combinatorial Optimization, EGRES). hegyi@1: * hegyi@1: * Permission to use, modify and distribute this software is granted hegyi@1: * provided that this copyright notice appears in all copies. For hegyi@1: * precise terms see the accompanying LICENSE file. hegyi@1: * hegyi@1: * This software is provided "AS IS" with no warranty of any kind, hegyi@1: * express or implied, and with no claim as to its suitability for any hegyi@1: * purpose. hegyi@1: * hegyi@1: */ hegyi@1: hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: #include hegyi@1: hegyi@1: hegyi@1: hegyi@1: NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), epswinexists(false) hegyi@1: { hegyi@1: mapstorage=new MapStorage(); hegyi@1: hegyi@1: Gtk::ScrolledWindow *pScrolledWindow = Gtk::manage(new Gtk::ScrolledWindow); hegyi@1: pScrolledWindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN); hegyi@1: gd_canvas=Gtk::manage(new DigraphDisplayerCanvas(*this)); hegyi@1: pScrolledWindow->add(*gd_canvas); hegyi@1: add(*pScrolledWindow); hegyi@1: hegyi@1: //connecting signals - controller character hegyi@1: mapstorage->signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::propertyChange)); hegyi@1: mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap)); hegyi@1: mapstorage->signal_arc_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewArcMap)); hegyi@1: mapstorage->signal_background_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::setBackground)); hegyi@1: show_all_children(); hegyi@1: show(); hegyi@1: } hegyi@1: hegyi@1: NoteBookTab::~NoteBookTab() hegyi@1: { hegyi@1: delete mapstorage; hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::readFile(const std::string &file) hegyi@1: { hegyi@1: mapstorage->readFromFile(file); hegyi@1: mapstorage->setFileName(file); hegyi@1: mapstorage->setModified(false); hegyi@1: gd_canvas->drawDigraph(); hegyi@1: if(mapwinexists) hegyi@1: { hegyi@1: mapwin->update( hegyi@1: mapstorage->getArcMapList(NUM), hegyi@1: mapstorage->getArcMapList(STR), hegyi@1: mapstorage->getNodeMapList(NUM), hegyi@1: mapstorage->getNodeMapList(STR)); hegyi@1: } hegyi@1: title_changed(Glib::filename_display_basename(file)); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::newFile() hegyi@1: { hegyi@1: if (mapstorage->getModified()) hegyi@1: { hegyi@1: Gtk::MessageDialog mdialog("Save changes before closing?", true, hegyi@1: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); hegyi@1: mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT); hegyi@1: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); hegyi@1: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); hegyi@1: switch (mdialog.run()) hegyi@1: { hegyi@1: case Gtk::RESPONSE_CANCEL: hegyi@1: return; hegyi@1: case Gtk::RESPONSE_REJECT: hegyi@1: break; hegyi@1: case Gtk::RESPONSE_ACCEPT: hegyi@1: saveFile(); hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: gd_canvas->clear(); hegyi@1: mapstorage->clear(); hegyi@1: if(mapwinexists) hegyi@1: { hegyi@1: mapwin->update( hegyi@1: mapstorage->getArcMapList(NUM), hegyi@1: mapstorage->getArcMapList(STR), hegyi@1: mapstorage->getNodeMapList(NUM), hegyi@1: mapstorage->getNodeMapList(STR)); hegyi@1: } hegyi@1: title_changed("unsaved file"); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::openFile() hegyi@1: { hegyi@1: if (mapstorage->getModified()) hegyi@1: { hegyi@1: Gtk::MessageDialog mdialog("Save changes before closing?", true, hegyi@1: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); hegyi@1: mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT); hegyi@1: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); hegyi@1: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); hegyi@1: switch (mdialog.run()) hegyi@1: { hegyi@1: case Gtk::RESPONSE_CANCEL: hegyi@1: return; hegyi@1: case Gtk::RESPONSE_REJECT: hegyi@1: break; hegyi@1: case Gtk::RESPONSE_ACCEPT: hegyi@1: saveFile(); hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: Gtk::FileChooserDialog fcdialog("Open File"); hegyi@1: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); hegyi@1: fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT); hegyi@1: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) hegyi@1: { hegyi@1: gd_canvas->clear(); hegyi@1: std::cout << mapstorage << std::endl; hegyi@1: mapstorage->clear(); hegyi@1: Glib::ustring filename = fcdialog.get_filename(); hegyi@1: if (!mapstorage->readFromFile(filename)) hegyi@1: { hegyi@1: mapstorage->setFileName(filename); hegyi@1: mapstorage->setModified(false); hegyi@1: gd_canvas->drawDigraph(); hegyi@1: if(mapwinexists) hegyi@1: { hegyi@1: mapwin->update( hegyi@1: mapstorage->getArcMapList(NUM), hegyi@1: mapstorage->getArcMapList(STR), hegyi@1: mapstorage->getNodeMapList(NUM), hegyi@1: mapstorage->getNodeMapList(STR)); hegyi@1: } hegyi@1: title_changed(Glib::filename_display_basename(filename)); hegyi@1: } hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::saveFile() hegyi@1: { hegyi@1: if (mapstorage->getFileName() == "") { hegyi@1: saveFileAs(); hegyi@1: } hegyi@1: else hegyi@1: { hegyi@1: mapstorage->writeToFile(mapstorage->getFileName()); hegyi@1: mapstorage->setModified(false); hegyi@1: title_changed(Glib::filename_display_basename(mapstorage->getFileName())); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::saveFileAs() hegyi@1: { hegyi@1: Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE); hegyi@1: fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); hegyi@1: fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); hegyi@1: if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) hegyi@1: { hegyi@1: Glib::ustring filename = fcdialog.get_filename(); hegyi@1: mapstorage->setFileName(filename); hegyi@1: mapstorage->writeToFile(filename); hegyi@1: mapstorage->setModified(false); hegyi@1: title_changed(Glib::filename_display_basename(filename)); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::close() hegyi@1: { hegyi@1: if (mapstorage->getModified()) hegyi@1: { hegyi@1: Gtk::MessageDialog mdialog("Save changes before closing?", true, hegyi@1: Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE); hegyi@1: mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT); hegyi@1: mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); hegyi@1: mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT); hegyi@1: switch (mdialog.run()) hegyi@1: { hegyi@1: case Gtk::RESPONSE_CANCEL: hegyi@1: return; hegyi@1: case Gtk::RESPONSE_REJECT: hegyi@1: break; hegyi@1: case Gtk::RESPONSE_ACCEPT: hegyi@1: saveFile(); hegyi@1: break; hegyi@1: } hegyi@1: } hegyi@1: gd_canvas->clear(); hegyi@1: mapstorage->clear(); hegyi@1: if(mapwinexists) hegyi@1: { hegyi@1: mapwin->update( hegyi@1: mapstorage->getArcMapList(NUM), hegyi@1: mapstorage->getArcMapList(STR), hegyi@1: mapstorage->getNodeMapList(NUM), hegyi@1: mapstorage->getNodeMapList(STR)); hegyi@1: } hegyi@1: title_changed("unsaved file"); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::propertyChange(bool itisarc, int prop, std::string mapname) hegyi@1: { hegyi@1: mapstorage->changeActiveMap(itisarc, prop, mapname); hegyi@1: } hegyi@1: hegyi@1: sigc::signal NoteBookTab::signal_newmap_needed() hegyi@1: { hegyi@1: return signal_newmap; hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::popupNewMapWin(bool itisarc) hegyi@1: { hegyi@1: signal_newmap.emit(this, itisarc); hegyi@1: } hegyi@1: hegyi@1: std::string NoteBookTab::getActiveArcMap(int prop) hegyi@1: { hegyi@1: return mapstorage->getActiveArcMap(prop); hegyi@1: } hegyi@1: hegyi@1: std::string NoteBookTab::getActiveNodeMap(int prop) hegyi@1: { hegyi@1: return mapstorage->getActiveNodeMap(prop); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::registerNewArcMap(std::string mapname, MapValue::Type type) hegyi@1: { hegyi@1: if(mapwinexists) hegyi@1: { hegyi@1: mapwin->registerNewArcMap(mapname, type); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::registerNewNodeMap(std::string mapname, MapValue::Type type) hegyi@1: { hegyi@1: if(mapwinexists) hegyi@1: { hegyi@1: mapwin->registerNewNodeMap(mapname, type); hegyi@1: } hegyi@1: if(epswinexists) hegyi@1: { hegyi@1: epswin->registerNewNodeMap(mapname, type); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::createMapWin(std::string name) hegyi@1: { hegyi@1: if(!mapwinexists) hegyi@1: { hegyi@1: mapwin=new MapWin("Map Setup - "+name, hegyi@1: mapstorage->getArcMapList(NUM), hegyi@1: mapstorage->getArcMapList(STR), hegyi@1: mapstorage->getNodeMapList(NUM), hegyi@1: mapstorage->getNodeMapList(STR), hegyi@1: *this); hegyi@1: mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry)); hegyi@1: mapwin->show(); hegyi@1: mapwinexists=true; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::createExportToEPSWin(std::string name) hegyi@1: { hegyi@1: if(!epswinexists) hegyi@1: { hegyi@1: epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList(NUM), mapstorage->getNodeMapList(STR)); hegyi@1: epswin->show(); hegyi@1: epswinexists=true; hegyi@1: epswin->signal_eps_details_ch().connect(sigc::mem_fun(*this, &NoteBookTab::exportDigraphToEPS)); hegyi@1: epswin->signal_eps_close_ch().connect(sigc::mem_fun(*this, &NoteBookTab::closeEpsWin)); hegyi@1: epswin->signal_new_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::popupNewMapWin)); hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: hegyi@1: void NoteBookTab::createDesignWin(std::string name) hegyi@1: { hegyi@1: if(!designwinexists) hegyi@1: { hegyi@1: double attraction, propulsation; hegyi@1: int iterations; hegyi@1: mapstorage->get_design_data(attraction, propulsation, iterations); hegyi@1: designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations); hegyi@1: hegyi@1: designwin->signal_attraction().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_attraction)); hegyi@1: designwin->signal_propulsation().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_propulsation)); hegyi@1: designwin->signal_iteration().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_iteration)); hegyi@1: designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::reDesignDigraph)); hegyi@1: hegyi@1: designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin)); hegyi@1: hegyi@1: mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data)); hegyi@1: hegyi@1: designwin->show(); hegyi@1: designwinexists=true; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::closeMapWin() hegyi@1: { hegyi@1: mapst2mapwin.disconnect(); hegyi@1: mapwinexists=false; hegyi@1: delete mapwin; hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::closeEpsWin() hegyi@1: { hegyi@1: epswinexists=false; hegyi@1: delete epswin; hegyi@1: } hegyi@1: hegyi@1: bool NoteBookTab::closeDesignWin(GdkEventAny * e) hegyi@1: { hegyi@1: if(e->type==GDK_DELETE) hegyi@1: { hegyi@1: designwinexists=false; hegyi@1: mapst2designwin.disconnect(); hegyi@1: delete designwin; hegyi@1: } hegyi@1: } hegyi@1: hegyi@1: sigc::signal NoteBookTab::signal_title_ch() hegyi@1: { hegyi@1: return signal_title; hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius) hegyi@1: { hegyi@1: gd_canvas->setView(autoscale, zoomtrack, width, radius); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius) hegyi@1: { hegyi@1: gd_canvas->getView(autoscale, zoomtrack, width, radius); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::reDesignDigraph() hegyi@1: { hegyi@1: gd_canvas->reDesignDigraph(); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::active_maps_needed() hegyi@1: { hegyi@1: mapstorage->broadcastActiveMaps(); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::exportDigraphToEPS(std::vector options, std::string filename, std::string shapemap) hegyi@1: { hegyi@1: mapstorage->exportDigraphToEPS(options, filename, shapemap); hegyi@1: } hegyi@1: hegyi@1: void NoteBookTab::title_changed(std::string newtitle) hegyi@1: { hegyi@1: signal_title.emit(newtitle); hegyi@1: if(epswinexists) hegyi@1: { hegyi@1: epswin->set_title(newtitle); hegyi@1: } hegyi@1: if(designwinexists) hegyi@1: { hegyi@1: designwin->set_title(newtitle); hegyi@1: } hegyi@1: }