nbtab.cc
author alpar
Mon, 30 Oct 2006 12:20:54 +0000
changeset 175 1e0a66d6b45a
parent 173 8339178ae43d
child 177 40f3006fba2e
permissions -rw-r--r--
Add autopackage specfile (not yet working).
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>
ladanyi@173
    20
#include "file_chooser_extra_widget.h"
hegyi@96
    21
hegyi@160
    22
NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false)
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);
ladanyi@173
   139
  FileChooserExtraWidget w(&mapstorage);
ladanyi@173
   140
  fcdialog.set_extra_widget(w);
hegyi@96
   141
  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
hegyi@96
   142
  {
hegyi@96
   143
    Glib::ustring filename = fcdialog.get_filename();
hegyi@96
   144
    mapstorage.file_name = filename;
hegyi@96
   145
    mapstorage.writeToFile(filename);
hegyi@96
   146
    mapstorage.modified = false;
hegyi@96
   147
    signal_title.emit(Glib::filename_display_basename(filename));
hegyi@96
   148
  }
hegyi@96
   149
}
hegyi@96
   150
hegyi@96
   151
void NoteBookTab::close()
hegyi@96
   152
{
hegyi@96
   153
  if (mapstorage.modified)
hegyi@96
   154
  {
hegyi@96
   155
    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
hegyi@96
   156
        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
hegyi@96
   157
    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
hegyi@96
   158
    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@96
   159
    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
hegyi@96
   160
    switch (mdialog.run())
hegyi@96
   161
    {
hegyi@96
   162
      case Gtk::RESPONSE_CANCEL:
hegyi@96
   163
        return;
hegyi@96
   164
      case Gtk::RESPONSE_REJECT:
hegyi@96
   165
        break;
hegyi@96
   166
      case Gtk::RESPONSE_ACCEPT:
hegyi@96
   167
        saveFile();
hegyi@96
   168
        break;
hegyi@96
   169
    }
hegyi@96
   170
  }
hegyi@96
   171
  gd_canvas->clear();
hegyi@96
   172
  mapstorage.clear();
hegyi@96
   173
  if(mapwinexists)
hegyi@96
   174
    {
hegyi@96
   175
      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
hegyi@96
   176
    }
hegyi@96
   177
  signal_title.emit("unsaved file");
hegyi@96
   178
}
hegyi@96
   179
hegyi@96
   180
void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
hegyi@96
   181
{
hegyi@96
   182
  mapstorage.changeActiveMap(itisedge, prop, mapname);
hegyi@96
   183
}
hegyi@96
   184
hegyi@96
   185
sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
hegyi@96
   186
{
hegyi@96
   187
  return signal_newmap;
hegyi@96
   188
}
hegyi@96
   189
hegyi@121
   190
void NoteBookTab::popupNewMapWin(bool itisedge)
hegyi@96
   191
{
hegyi@96
   192
  signal_newmap.emit(this, itisedge);
hegyi@96
   193
}
hegyi@96
   194
hegyi@96
   195
std::string NoteBookTab::getActiveEdgeMap(int prop)
hegyi@96
   196
{
hegyi@96
   197
  return mapstorage.getActiveEdgeMap(prop);
hegyi@96
   198
}
hegyi@96
   199
hegyi@96
   200
std::string NoteBookTab::getActiveNodeMap(int prop)
hegyi@96
   201
{
hegyi@96
   202
  return mapstorage.getActiveNodeMap(prop);
hegyi@96
   203
}
hegyi@96
   204
hegyi@96
   205
void NoteBookTab::registerNewEdgeMap(std::string mapname)
hegyi@96
   206
{
hegyi@96
   207
  if(mapwinexists)
hegyi@96
   208
    {
hegyi@96
   209
      mapwin->registerNewEdgeMap(mapname);
hegyi@96
   210
    }
hegyi@96
   211
}
hegyi@96
   212
hegyi@96
   213
void NoteBookTab::registerNewNodeMap(std::string mapname)
hegyi@96
   214
{
hegyi@96
   215
  if(mapwinexists)
hegyi@96
   216
    {
hegyi@96
   217
      mapwin->registerNewNodeMap(mapname);
hegyi@96
   218
    }
hegyi@96
   219
}
hegyi@96
   220
hegyi@96
   221
void NoteBookTab::createMapWin(std::string name)
hegyi@96
   222
{
hegyi@96
   223
  if(!mapwinexists)
hegyi@96
   224
    {
hegyi@96
   225
      mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
hegyi@172
   226
      mapst2mapwin=mapstorage.signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
hegyi@96
   227
      mapwin->show();
hegyi@96
   228
      mapwinexists=true;
hegyi@96
   229
    }
hegyi@96
   230
}
hegyi@96
   231
hegyi@160
   232
void NoteBookTab::createDesignWin(std::string name)
hegyi@160
   233
{
hegyi@160
   234
  if(!designwinexists)
hegyi@160
   235
    {
hegyi@160
   236
      double attraction, propulsation;
hegyi@160
   237
      int iterations;
hegyi@160
   238
      gd_canvas->get_design_data(attraction, propulsation, iterations);
hegyi@172
   239
      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations, *this);
hegyi@160
   240
hegyi@160
   241
      designwin->signal_attraction().connect(sigc::mem_fun(*this, &NoteBookTab::attraction_ch));
hegyi@160
   242
      designwin->signal_propulsation().connect(sigc::mem_fun(*this, &NoteBookTab::propulsation_ch));
hegyi@160
   243
      designwin->signal_iteration().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::set_iteration));
hegyi@160
   244
      designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::reDesignGraph));
hegyi@160
   245
hegyi@160
   246
      designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
hegyi@160
   247
hegyi@160
   248
      designwin->show();
hegyi@160
   249
      designwinexists=true;
hegyi@160
   250
    }
hegyi@160
   251
}
hegyi@160
   252
hegyi@96
   253
void NoteBookTab::closeMapWin()
hegyi@96
   254
{
hegyi@172
   255
  mapst2mapwin.disconnect();
hegyi@96
   256
  mapwinexists=false;
hegyi@96
   257
  delete mapwin;
hegyi@96
   258
}
hegyi@96
   259
hegyi@160
   260
bool NoteBookTab::closeDesignWin(GdkEventAny * e)
hegyi@160
   261
{
hegyi@160
   262
  if(e->type==GDK_DELETE)
hegyi@160
   263
    {
hegyi@160
   264
      designwinexists=false;
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@160
   289
void NoteBookTab::attraction_ch(double v)
hegyi@160
   290
{
hegyi@160
   291
  gd_canvas->set_attraction(v);
hegyi@160
   292
}
hegyi@160
   293
hegyi@160
   294
void NoteBookTab::propulsation_ch(double v)
hegyi@160
   295
{
hegyi@160
   296
  gd_canvas->set_propulsation(v);
hegyi@160
   297
}
hegyi@160
   298
hegyi@160
   299
void NoteBookTab::iteration_ch(int v)
hegyi@160
   300
{
hegyi@160
   301
  gd_canvas->set_iteration(v);
hegyi@160
   302
}
hegyi@160
   303
hegyi@172
   304
void NoteBookTab::active_maps_needed()
hegyi@172
   305
{
hegyi@172
   306
  mapstorage.broadcastActiveMaps();
hegyi@172
   307
}