COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 173:8339178ae43d

Last change on this file since 173:8339178ae43d was 173:8339178ae43d, checked in by Akos Ladanyi, 13 years ago

Added two new classes.

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