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