COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 160:14a76109b561

Last change on this file since 160:14a76109b561 was 160:14a76109b561, checked in by Hegyi Péter, 13 years ago

Node antigravity and edge elasticity based graph layout redesigner.

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