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