nbtab.cc
changeset 1 67188bd752db
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nbtab.cc	Mon Jul 07 08:10:39 2008 -0500
     1.3 @@ -0,0 +1,372 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2006
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#include <nbtab.h>
    1.23 +#include <mapstorage.h>
    1.24 +#include <eps_win.h>
    1.25 +#include <map_win.h>
    1.26 +#include <design_win.h>
    1.27 +#include <graph_displayer_canvas.h>
    1.28 +
    1.29 +
    1.30 +
    1.31 +NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), epswinexists(false)
    1.32 +{
    1.33 +  mapstorage=new MapStorage();
    1.34 +
    1.35 +  Gtk::ScrolledWindow *pScrolledWindow = Gtk::manage(new Gtk::ScrolledWindow);
    1.36 +  pScrolledWindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
    1.37 +  gd_canvas=Gtk::manage(new DigraphDisplayerCanvas(*this));
    1.38 +  pScrolledWindow->add(*gd_canvas);
    1.39 +  add(*pScrolledWindow);
    1.40 +
    1.41 +  //connecting signals - controller character
    1.42 +  mapstorage->signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::propertyChange));
    1.43 +  mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap));
    1.44 +  mapstorage->signal_arc_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewArcMap));
    1.45 +  mapstorage->signal_background_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::setBackground));
    1.46 +  show_all_children();
    1.47 +  show();
    1.48 +}
    1.49 +
    1.50 +NoteBookTab::~NoteBookTab()
    1.51 +{
    1.52 +  delete mapstorage;
    1.53 +}
    1.54 +
    1.55 +void NoteBookTab::readFile(const std::string &file)
    1.56 +{
    1.57 +  mapstorage->readFromFile(file);
    1.58 +  mapstorage->setFileName(file);
    1.59 +  mapstorage->setModified(false);
    1.60 +  gd_canvas->drawDigraph();
    1.61 +  if(mapwinexists)
    1.62 +    {
    1.63 +      mapwin->update(
    1.64 +          mapstorage->getArcMapList(NUM),
    1.65 +          mapstorage->getArcMapList(STR),
    1.66 +          mapstorage->getNodeMapList(NUM),
    1.67 +          mapstorage->getNodeMapList(STR));
    1.68 +    }
    1.69 +  title_changed(Glib::filename_display_basename(file));
    1.70 +}
    1.71 +
    1.72 +void NoteBookTab::newFile()
    1.73 +{
    1.74 +  if (mapstorage->getModified())
    1.75 +  {
    1.76 +    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
    1.77 +        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
    1.78 +    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
    1.79 +    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
    1.80 +    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
    1.81 +    switch (mdialog.run())
    1.82 +    {
    1.83 +      case Gtk::RESPONSE_CANCEL:
    1.84 +        return;
    1.85 +      case Gtk::RESPONSE_REJECT:
    1.86 +        break;
    1.87 +      case Gtk::RESPONSE_ACCEPT:
    1.88 +        saveFile();
    1.89 +        break;
    1.90 +    }
    1.91 +  }
    1.92 +  gd_canvas->clear();
    1.93 +  mapstorage->clear();
    1.94 +  if(mapwinexists)
    1.95 +    {
    1.96 +      mapwin->update(
    1.97 +          mapstorage->getArcMapList(NUM),
    1.98 +          mapstorage->getArcMapList(STR),
    1.99 +          mapstorage->getNodeMapList(NUM),
   1.100 +          mapstorage->getNodeMapList(STR));
   1.101 +    }
   1.102 +  title_changed("unsaved file");
   1.103 +}
   1.104 +
   1.105 +void NoteBookTab::openFile()
   1.106 +{
   1.107 +  if (mapstorage->getModified())
   1.108 +  {
   1.109 +    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
   1.110 +        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   1.111 +    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
   1.112 +    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.113 +    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.114 +    switch (mdialog.run())
   1.115 +    {
   1.116 +      case Gtk::RESPONSE_CANCEL:
   1.117 +        return;
   1.118 +      case Gtk::RESPONSE_REJECT:
   1.119 +        break;
   1.120 +      case Gtk::RESPONSE_ACCEPT:
   1.121 +        saveFile();
   1.122 +        break;
   1.123 +    }
   1.124 +  }
   1.125 +  Gtk::FileChooserDialog fcdialog("Open File");
   1.126 +  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.127 +  fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
   1.128 +  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
   1.129 +  {
   1.130 +    gd_canvas->clear();
   1.131 +    std::cout << mapstorage << std::endl;
   1.132 +    mapstorage->clear();
   1.133 +    Glib::ustring filename = fcdialog.get_filename();
   1.134 +    if (!mapstorage->readFromFile(filename))
   1.135 +    {
   1.136 +      mapstorage->setFileName(filename);
   1.137 +      mapstorage->setModified(false);
   1.138 +      gd_canvas->drawDigraph();
   1.139 +      if(mapwinexists)
   1.140 +	{
   1.141 +          mapwin->update(
   1.142 +              mapstorage->getArcMapList(NUM),
   1.143 +              mapstorage->getArcMapList(STR),
   1.144 +              mapstorage->getNodeMapList(NUM),
   1.145 +              mapstorage->getNodeMapList(STR));
   1.146 +	}
   1.147 +      title_changed(Glib::filename_display_basename(filename));
   1.148 +    }
   1.149 +  }
   1.150 +}
   1.151 +
   1.152 +void NoteBookTab::saveFile()
   1.153 +{
   1.154 +  if (mapstorage->getFileName() == "") {
   1.155 +    saveFileAs();
   1.156 +  }
   1.157 +  else
   1.158 +  {
   1.159 +    mapstorage->writeToFile(mapstorage->getFileName());
   1.160 +    mapstorage->setModified(false);
   1.161 +    title_changed(Glib::filename_display_basename(mapstorage->getFileName()));
   1.162 +  }
   1.163 +}
   1.164 +
   1.165 +void NoteBookTab::saveFileAs()
   1.166 +{
   1.167 +  Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
   1.168 +  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.169 +  fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.170 +  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
   1.171 +  {
   1.172 +    Glib::ustring filename = fcdialog.get_filename();
   1.173 +    mapstorage->setFileName(filename);
   1.174 +    mapstorage->writeToFile(filename);
   1.175 +    mapstorage->setModified(false);
   1.176 +    title_changed(Glib::filename_display_basename(filename));
   1.177 +  }
   1.178 +}
   1.179 +
   1.180 +void NoteBookTab::close()
   1.181 +{
   1.182 +  if (mapstorage->getModified())
   1.183 +  {
   1.184 +    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
   1.185 +        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
   1.186 +    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
   1.187 +    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
   1.188 +    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
   1.189 +    switch (mdialog.run())
   1.190 +    {
   1.191 +      case Gtk::RESPONSE_CANCEL:
   1.192 +        return;
   1.193 +      case Gtk::RESPONSE_REJECT:
   1.194 +        break;
   1.195 +      case Gtk::RESPONSE_ACCEPT:
   1.196 +        saveFile();
   1.197 +        break;
   1.198 +    }
   1.199 +  }
   1.200 +  gd_canvas->clear();
   1.201 +  mapstorage->clear();
   1.202 +  if(mapwinexists)
   1.203 +    {
   1.204 +      mapwin->update(
   1.205 +          mapstorage->getArcMapList(NUM),
   1.206 +          mapstorage->getArcMapList(STR),
   1.207 +          mapstorage->getNodeMapList(NUM),
   1.208 +          mapstorage->getNodeMapList(STR));
   1.209 +    }
   1.210 +  title_changed("unsaved file");
   1.211 +}
   1.212 +
   1.213 +void NoteBookTab::propertyChange(bool itisarc, int prop, std::string mapname)
   1.214 +{
   1.215 +  mapstorage->changeActiveMap(itisarc, prop, mapname);
   1.216 +}
   1.217 +
   1.218 +sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
   1.219 +{
   1.220 +  return signal_newmap;
   1.221 +}
   1.222 +
   1.223 +void NoteBookTab::popupNewMapWin(bool itisarc)
   1.224 +{
   1.225 +  signal_newmap.emit(this, itisarc);
   1.226 +}
   1.227 +
   1.228 +std::string NoteBookTab::getActiveArcMap(int prop)
   1.229 +{
   1.230 +  return mapstorage->getActiveArcMap(prop);
   1.231 +}
   1.232 +
   1.233 +std::string NoteBookTab::getActiveNodeMap(int prop)
   1.234 +{
   1.235 +  return mapstorage->getActiveNodeMap(prop);
   1.236 +}
   1.237 +
   1.238 +void NoteBookTab::registerNewArcMap(std::string mapname, MapValue::Type type)
   1.239 +{
   1.240 +  if(mapwinexists)
   1.241 +    {
   1.242 +      mapwin->registerNewArcMap(mapname, type);
   1.243 +    }
   1.244 +}
   1.245 +
   1.246 +void NoteBookTab::registerNewNodeMap(std::string mapname, MapValue::Type type)
   1.247 +{
   1.248 +  if(mapwinexists)
   1.249 +    {
   1.250 +      mapwin->registerNewNodeMap(mapname, type);
   1.251 +    }
   1.252 +  if(epswinexists)
   1.253 +    {
   1.254 +      epswin->registerNewNodeMap(mapname, type);
   1.255 +    }
   1.256 +}
   1.257 +
   1.258 +void NoteBookTab::createMapWin(std::string name)
   1.259 +{
   1.260 +  if(!mapwinexists)
   1.261 +    {
   1.262 +      mapwin=new MapWin("Map Setup - "+name,
   1.263 +          mapstorage->getArcMapList(NUM),
   1.264 +          mapstorage->getArcMapList(STR),
   1.265 +          mapstorage->getNodeMapList(NUM),
   1.266 +          mapstorage->getNodeMapList(STR),
   1.267 +          *this);
   1.268 +      mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
   1.269 +      mapwin->show();
   1.270 +      mapwinexists=true;
   1.271 +    }
   1.272 +}
   1.273 +
   1.274 +void NoteBookTab::createExportToEPSWin(std::string name)
   1.275 +{
   1.276 +  if(!epswinexists)
   1.277 +    {
   1.278 +      epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList(NUM), mapstorage->getNodeMapList(STR));
   1.279 +      epswin->show();
   1.280 +      epswinexists=true;
   1.281 +      epswin->signal_eps_details_ch().connect(sigc::mem_fun(*this, &NoteBookTab::exportDigraphToEPS));
   1.282 +      epswin->signal_eps_close_ch().connect(sigc::mem_fun(*this, &NoteBookTab::closeEpsWin));
   1.283 +      epswin->signal_new_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::popupNewMapWin));
   1.284 +    }
   1.285 +}
   1.286 +
   1.287 +
   1.288 +void NoteBookTab::createDesignWin(std::string name)
   1.289 +{
   1.290 +  if(!designwinexists)
   1.291 +    {
   1.292 +      double attraction, propulsation;
   1.293 +      int iterations;
   1.294 +      mapstorage->get_design_data(attraction, propulsation, iterations);
   1.295 +      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
   1.296 +
   1.297 +      designwin->signal_attraction().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_attraction));
   1.298 +      designwin->signal_propulsation().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_propulsation));
   1.299 +      designwin->signal_iteration().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_iteration));
   1.300 +      designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::reDesignDigraph));
   1.301 +
   1.302 +      designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
   1.303 +
   1.304 +      mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data));
   1.305 +
   1.306 +      designwin->show();
   1.307 +      designwinexists=true;
   1.308 +    }
   1.309 +}
   1.310 +
   1.311 +void NoteBookTab::closeMapWin()
   1.312 +{
   1.313 +  mapst2mapwin.disconnect();
   1.314 +  mapwinexists=false;
   1.315 +  delete mapwin;
   1.316 +}
   1.317 +
   1.318 +void NoteBookTab::closeEpsWin()
   1.319 +{
   1.320 +  epswinexists=false;
   1.321 +  delete epswin;
   1.322 +}
   1.323 +
   1.324 +bool NoteBookTab::closeDesignWin(GdkEventAny * e)
   1.325 +{
   1.326 +  if(e->type==GDK_DELETE)
   1.327 +    {
   1.328 +      designwinexists=false;
   1.329 +      mapst2designwin.disconnect();
   1.330 +      delete designwin;
   1.331 +    }
   1.332 +}
   1.333 +
   1.334 +sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
   1.335 +{
   1.336 +  return signal_title;
   1.337 +}
   1.338 +
   1.339 +void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
   1.340 +{
   1.341 +  gd_canvas->setView(autoscale, zoomtrack, width, radius);
   1.342 +}
   1.343 +
   1.344 +void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
   1.345 +{
   1.346 +  gd_canvas->getView(autoscale, zoomtrack, width, radius);
   1.347 +}
   1.348 +
   1.349 +void NoteBookTab::reDesignDigraph()
   1.350 +{
   1.351 +  gd_canvas->reDesignDigraph();
   1.352 +}
   1.353 +
   1.354 +void NoteBookTab::active_maps_needed()
   1.355 +{
   1.356 +  mapstorage->broadcastActiveMaps();
   1.357 +}
   1.358 +
   1.359 +void NoteBookTab::exportDigraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap)
   1.360 +{
   1.361 +  mapstorage->exportDigraphToEPS(options, filename, shapemap);
   1.362 +}
   1.363 +
   1.364 +void NoteBookTab::title_changed(std::string newtitle)
   1.365 +{
   1.366 +  signal_title.emit(newtitle);
   1.367 +  if(epswinexists)
   1.368 +    {
   1.369 +      epswin->set_title(newtitle);
   1.370 +    }
   1.371 +  if(designwinexists)
   1.372 +    {
   1.373 +      designwin->set_title(newtitle);
   1.374 +    }
   1.375 +}