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