COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 191:af2ed974ab68

Last change on this file since 191:af2ed974ab68 was 191:af2ed974ab68, checked in by Hegyi Péter, 18 years ago

GUI can now export graph to EPS.

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