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