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