nbtab.cc
author hegyi
Mon, 02 Oct 2006 18:52:00 +0000
changeset 157 7e6ad28aeb9e
parent 156 c5cdf6690cdf
child 160 14a76109b561
permissions -rw-r--r--
View settings also for edges.
hegyi@96
     1
#include <nbtab.h>
hegyi@96
     2
hegyi@96
     3
NoteBookTab::NoteBookTab():mapwinexists(false)
hegyi@96
     4
{
ladanyi@136
     5
  Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
hegyi@96
     6
  gd_canvas=new GraphDisplayerCanvas(*this);
ladanyi@136
     7
  pScrolledWindow->add(*gd_canvas);
ladanyi@136
     8
  add(*pScrolledWindow);
hegyi@96
     9
hegyi@96
    10
  //connecting signals - controller character
hegyi@96
    11
  mapstorage.signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
hegyi@108
    12
  mapstorage.signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap));
hegyi@108
    13
  mapstorage.signal_edge_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewEdgeMap));
hegyi@96
    14
  show_all_children();
hegyi@96
    15
  show();
hegyi@96
    16
}
hegyi@96
    17
hegyi@96
    18
void NoteBookTab::readFile(const std::string &file)
hegyi@96
    19
{
hegyi@96
    20
  mapstorage.readFromFile(file);
hegyi@96
    21
  mapstorage.file_name = file;
hegyi@96
    22
  mapstorage.modified = false;
hegyi@96
    23
  gd_canvas->drawGraph();
hegyi@96
    24
  if(mapwinexists)
hegyi@96
    25
    {
hegyi@96
    26
      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
hegyi@96
    27
    }
hegyi@96
    28
  signal_title.emit(Glib::filename_display_basename(file));
hegyi@96
    29
}
hegyi@96
    30
hegyi@96
    31
void NoteBookTab::newFile()
hegyi@96
    32
{
hegyi@96
    33
  if (mapstorage.modified)
hegyi@96
    34
  {
hegyi@96
    35
    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
hegyi@96
    36
        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
hegyi@102
    37
    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
hegyi@96
    38
    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@96
    39
    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
hegyi@96
    40
    switch (mdialog.run())
hegyi@96
    41
    {
hegyi@96
    42
      case Gtk::RESPONSE_CANCEL:
hegyi@96
    43
        return;
hegyi@96
    44
      case Gtk::RESPONSE_REJECT:
hegyi@96
    45
        break;
hegyi@96
    46
      case Gtk::RESPONSE_ACCEPT:
hegyi@96
    47
        saveFile();
hegyi@96
    48
        break;
hegyi@96
    49
    }
hegyi@96
    50
  }
hegyi@96
    51
  gd_canvas->clear();
hegyi@96
    52
  mapstorage.clear();
hegyi@96
    53
  if(mapwinexists)
hegyi@96
    54
    {
hegyi@96
    55
      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
hegyi@96
    56
    }
hegyi@96
    57
  signal_title.emit("unsaved file");
hegyi@96
    58
}
hegyi@96
    59
hegyi@96
    60
void NoteBookTab::openFile()
hegyi@96
    61
{
hegyi@96
    62
  if (mapstorage.modified)
hegyi@96
    63
  {
hegyi@96
    64
    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
hegyi@96
    65
        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
hegyi@102
    66
    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
hegyi@96
    67
    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@96
    68
    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
hegyi@96
    69
    switch (mdialog.run())
hegyi@96
    70
    {
hegyi@96
    71
      case Gtk::RESPONSE_CANCEL:
hegyi@96
    72
        return;
hegyi@96
    73
      case Gtk::RESPONSE_REJECT:
hegyi@96
    74
        break;
hegyi@96
    75
      case Gtk::RESPONSE_ACCEPT:
hegyi@96
    76
        saveFile();
hegyi@96
    77
        break;
hegyi@96
    78
    }
hegyi@96
    79
  }
hegyi@96
    80
  Gtk::FileChooserDialog fcdialog("Open File");
hegyi@96
    81
  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@96
    82
  fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
hegyi@96
    83
  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
hegyi@96
    84
  {
hegyi@96
    85
    gd_canvas->clear();
hegyi@96
    86
    mapstorage.clear();
hegyi@96
    87
    Glib::ustring filename = fcdialog.get_filename();
hegyi@96
    88
    if (!mapstorage.readFromFile(filename))
hegyi@96
    89
    {
hegyi@96
    90
      mapstorage.file_name = filename;
hegyi@96
    91
      mapstorage.modified = false;
hegyi@96
    92
      gd_canvas->drawGraph();
hegyi@96
    93
      if(mapwinexists)
hegyi@96
    94
	{
hegyi@96
    95
	  mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
hegyi@96
    96
	}
hegyi@96
    97
      signal_title.emit(Glib::filename_display_basename(filename));
hegyi@96
    98
    }
hegyi@96
    99
  }
hegyi@96
   100
}
hegyi@96
   101
hegyi@96
   102
void NoteBookTab::saveFile()
hegyi@96
   103
{
hegyi@96
   104
  if (mapstorage.file_name == "") {
hegyi@96
   105
    saveFileAs();
hegyi@96
   106
  }
hegyi@96
   107
  else
hegyi@96
   108
  {
hegyi@96
   109
    mapstorage.writeToFile(mapstorage.file_name);
hegyi@96
   110
    mapstorage.modified = false;
hegyi@96
   111
    signal_title.emit(Glib::filename_display_basename(mapstorage.file_name));
hegyi@96
   112
  }
hegyi@96
   113
}
hegyi@96
   114
hegyi@96
   115
void NoteBookTab::saveFileAs()
hegyi@96
   116
{
hegyi@96
   117
  Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
hegyi@96
   118
  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@96
   119
  fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
hegyi@96
   120
  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
hegyi@96
   121
  {
hegyi@96
   122
    Glib::ustring filename = fcdialog.get_filename();
hegyi@96
   123
    mapstorage.file_name = filename;
hegyi@96
   124
    mapstorage.writeToFile(filename);
hegyi@96
   125
    mapstorage.modified = false;
hegyi@96
   126
    signal_title.emit(Glib::filename_display_basename(filename));
hegyi@96
   127
  }
hegyi@96
   128
}
hegyi@96
   129
hegyi@96
   130
void NoteBookTab::close()
hegyi@96
   131
{
hegyi@96
   132
  if (mapstorage.modified)
hegyi@96
   133
  {
hegyi@96
   134
    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
hegyi@96
   135
        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
hegyi@96
   136
    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
hegyi@96
   137
    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
hegyi@96
   138
    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
hegyi@96
   139
    switch (mdialog.run())
hegyi@96
   140
    {
hegyi@96
   141
      case Gtk::RESPONSE_CANCEL:
hegyi@96
   142
        return;
hegyi@96
   143
      case Gtk::RESPONSE_REJECT:
hegyi@96
   144
        break;
hegyi@96
   145
      case Gtk::RESPONSE_ACCEPT:
hegyi@96
   146
        saveFile();
hegyi@96
   147
        break;
hegyi@96
   148
    }
hegyi@96
   149
  }
hegyi@96
   150
  gd_canvas->clear();
hegyi@96
   151
  mapstorage.clear();
hegyi@96
   152
  if(mapwinexists)
hegyi@96
   153
    {
hegyi@96
   154
      mapwin->update(mapstorage.getEdgeMapList(), mapstorage.getNodeMapList());
hegyi@96
   155
    }
hegyi@96
   156
  signal_title.emit("unsaved file");
hegyi@96
   157
}
hegyi@96
   158
hegyi@96
   159
void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
hegyi@96
   160
{
hegyi@96
   161
  mapstorage.changeActiveMap(itisedge, prop, mapname);
hegyi@96
   162
}
hegyi@96
   163
hegyi@96
   164
sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
hegyi@96
   165
{
hegyi@96
   166
  return signal_newmap;
hegyi@96
   167
}
hegyi@96
   168
hegyi@121
   169
void NoteBookTab::popupNewMapWin(bool itisedge)
hegyi@96
   170
{
hegyi@96
   171
  signal_newmap.emit(this, itisedge);
hegyi@96
   172
}
hegyi@96
   173
hegyi@96
   174
std::string NoteBookTab::getActiveEdgeMap(int prop)
hegyi@96
   175
{
hegyi@96
   176
  return mapstorage.getActiveEdgeMap(prop);
hegyi@96
   177
}
hegyi@96
   178
hegyi@96
   179
std::string NoteBookTab::getActiveNodeMap(int prop)
hegyi@96
   180
{
hegyi@96
   181
  return mapstorage.getActiveNodeMap(prop);
hegyi@96
   182
}
hegyi@96
   183
hegyi@96
   184
void NoteBookTab::registerNewEdgeMap(std::string mapname)
hegyi@96
   185
{
hegyi@96
   186
  if(mapwinexists)
hegyi@96
   187
    {
hegyi@96
   188
      mapwin->registerNewEdgeMap(mapname);
hegyi@96
   189
    }
hegyi@96
   190
}
hegyi@96
   191
hegyi@96
   192
void NoteBookTab::registerNewNodeMap(std::string mapname)
hegyi@96
   193
{
hegyi@96
   194
  if(mapwinexists)
hegyi@96
   195
    {
hegyi@96
   196
      mapwin->registerNewNodeMap(mapname);
hegyi@96
   197
    }
hegyi@96
   198
}
hegyi@96
   199
hegyi@96
   200
void NoteBookTab::createMapWin(std::string name)
hegyi@96
   201
{
hegyi@96
   202
  if(!mapwinexists)
hegyi@96
   203
    {
hegyi@96
   204
      mapwin=new MapWin("Map Setup - "+name, mapstorage.getEdgeMapList(), mapstorage.getNodeMapList(), *this);
hegyi@96
   205
      mapwin->show();
hegyi@96
   206
      mapwinexists=true;
hegyi@96
   207
    }
hegyi@96
   208
}
hegyi@96
   209
hegyi@96
   210
void NoteBookTab::closeMapWin()
hegyi@96
   211
{
hegyi@96
   212
  mapwinexists=false;
hegyi@96
   213
  delete mapwin;
hegyi@96
   214
}
hegyi@96
   215
hegyi@96
   216
sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
hegyi@96
   217
{
hegyi@96
   218
  return signal_title;
hegyi@96
   219
}
hegyi@96
   220
hegyi@157
   221
void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
hegyi@154
   222
{
hegyi@157
   223
  gd_canvas->setView(autoscale, zoomtrack, width, radius);
hegyi@154
   224
}
hegyi@154
   225
hegyi@157
   226
void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
hegyi@154
   227
{
hegyi@157
   228
  gd_canvas->getView(autoscale, zoomtrack, width, radius);
hegyi@154
   229
}