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