COIN-OR::LEMON - Graph Library

source: glemon/nbtab.cc

tip
Last change on this file was 1:67188bd752db, checked in by Peter Hegyi <hegyi@…>, 10 years ago

SVN revision 3500 made compilable with Lemon 1.0.

File size: 10.3 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 <mapstorage.h>
21#include <eps_win.h>
22#include <map_win.h>
23#include <design_win.h>
24#include <graph_displayer_canvas.h>
25
26
27
28NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), epswinexists(false)
29{
30  mapstorage=new MapStorage();
31
32  Gtk::ScrolledWindow *pScrolledWindow = Gtk::manage(new Gtk::ScrolledWindow);
33  pScrolledWindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
34  gd_canvas=Gtk::manage(new DigraphDisplayerCanvas(*this));
35  pScrolledWindow->add(*gd_canvas);
36  add(*pScrolledWindow);
37
38  //connecting signals - controller character
39  mapstorage->signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::propertyChange));
40  mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap));
41  mapstorage->signal_arc_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewArcMap));
42  mapstorage->signal_background_ch().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::setBackground));
43  show_all_children();
44  show();
45}
46
47NoteBookTab::~NoteBookTab()
48{
49  delete mapstorage;
50}
51
52void NoteBookTab::readFile(const std::string &file)
53{
54  mapstorage->readFromFile(file);
55  mapstorage->setFileName(file);
56  mapstorage->setModified(false);
57  gd_canvas->drawDigraph();
58  if(mapwinexists)
59    {
60      mapwin->update(
61          mapstorage->getArcMapList(NUM),
62          mapstorage->getArcMapList(STR),
63          mapstorage->getNodeMapList(NUM),
64          mapstorage->getNodeMapList(STR));
65    }
66  title_changed(Glib::filename_display_basename(file));
67}
68
69void NoteBookTab::newFile()
70{
71  if (mapstorage->getModified())
72  {
73    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
74        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
75    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
76    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
77    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
78    switch (mdialog.run())
79    {
80      case Gtk::RESPONSE_CANCEL:
81        return;
82      case Gtk::RESPONSE_REJECT:
83        break;
84      case Gtk::RESPONSE_ACCEPT:
85        saveFile();
86        break;
87    }
88  }
89  gd_canvas->clear();
90  mapstorage->clear();
91  if(mapwinexists)
92    {
93      mapwin->update(
94          mapstorage->getArcMapList(NUM),
95          mapstorage->getArcMapList(STR),
96          mapstorage->getNodeMapList(NUM),
97          mapstorage->getNodeMapList(STR));
98    }
99  title_changed("unsaved file");
100}
101
102void NoteBookTab::openFile()
103{
104  if (mapstorage->getModified())
105  {
106    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true, 
107        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
108    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
109    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
110    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
111    switch (mdialog.run())
112    {
113      case Gtk::RESPONSE_CANCEL:
114        return;
115      case Gtk::RESPONSE_REJECT:
116        break;
117      case Gtk::RESPONSE_ACCEPT:
118        saveFile();
119        break;
120    }
121  }
122  Gtk::FileChooserDialog fcdialog("Open File");
123  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
124  fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
125  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
126  {
127    gd_canvas->clear();
128    std::cout << mapstorage << std::endl;
129    mapstorage->clear();
130    Glib::ustring filename = fcdialog.get_filename();
131    if (!mapstorage->readFromFile(filename))
132    {
133      mapstorage->setFileName(filename);
134      mapstorage->setModified(false);
135      gd_canvas->drawDigraph();
136      if(mapwinexists)
137        {
138          mapwin->update(
139              mapstorage->getArcMapList(NUM),
140              mapstorage->getArcMapList(STR),
141              mapstorage->getNodeMapList(NUM),
142              mapstorage->getNodeMapList(STR));
143        }
144      title_changed(Glib::filename_display_basename(filename));
145    }
146  }
147}
148
149void NoteBookTab::saveFile()
150{
151  if (mapstorage->getFileName() == "") {
152    saveFileAs();
153  }
154  else
155  {
156    mapstorage->writeToFile(mapstorage->getFileName());
157    mapstorage->setModified(false);
158    title_changed(Glib::filename_display_basename(mapstorage->getFileName()));
159  }
160}
161
162void NoteBookTab::saveFileAs()
163{
164  Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
165  fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
166  fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
167  if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
168  {
169    Glib::ustring filename = fcdialog.get_filename();
170    mapstorage->setFileName(filename);
171    mapstorage->writeToFile(filename);
172    mapstorage->setModified(false);
173    title_changed(Glib::filename_display_basename(filename));
174  }
175}
176
177void NoteBookTab::close()
178{
179  if (mapstorage->getModified())
180  {
181    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
182        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
183    mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
184    mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
185    mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
186    switch (mdialog.run())
187    {
188      case Gtk::RESPONSE_CANCEL:
189        return;
190      case Gtk::RESPONSE_REJECT:
191        break;
192      case Gtk::RESPONSE_ACCEPT:
193        saveFile();
194        break;
195    }
196  }
197  gd_canvas->clear();
198  mapstorage->clear();
199  if(mapwinexists)
200    {
201      mapwin->update(
202          mapstorage->getArcMapList(NUM),
203          mapstorage->getArcMapList(STR),
204          mapstorage->getNodeMapList(NUM),
205          mapstorage->getNodeMapList(STR));
206    }
207  title_changed("unsaved file");
208}
209
210void NoteBookTab::propertyChange(bool itisarc, int prop, std::string mapname)
211{
212  mapstorage->changeActiveMap(itisarc, prop, mapname);
213}
214
215sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
216{
217  return signal_newmap;
218}
219
220void NoteBookTab::popupNewMapWin(bool itisarc)
221{
222  signal_newmap.emit(this, itisarc);
223}
224
225std::string NoteBookTab::getActiveArcMap(int prop)
226{
227  return mapstorage->getActiveArcMap(prop);
228}
229
230std::string NoteBookTab::getActiveNodeMap(int prop)
231{
232  return mapstorage->getActiveNodeMap(prop);
233}
234
235void NoteBookTab::registerNewArcMap(std::string mapname, MapValue::Type type)
236{
237  if(mapwinexists)
238    {
239      mapwin->registerNewArcMap(mapname, type);
240    }
241}
242
243void NoteBookTab::registerNewNodeMap(std::string mapname, MapValue::Type type)
244{
245  if(mapwinexists)
246    {
247      mapwin->registerNewNodeMap(mapname, type);
248    }
249  if(epswinexists)
250    {
251      epswin->registerNewNodeMap(mapname, type);
252    }
253}
254
255void NoteBookTab::createMapWin(std::string name)
256{
257  if(!mapwinexists)
258    {
259      mapwin=new MapWin("Map Setup - "+name,
260          mapstorage->getArcMapList(NUM),
261          mapstorage->getArcMapList(STR),
262          mapstorage->getNodeMapList(NUM),
263          mapstorage->getNodeMapList(STR),
264          *this);
265      mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
266      mapwin->show();
267      mapwinexists=true;
268    }
269}
270
271void NoteBookTab::createExportToEPSWin(std::string name)
272{
273  if(!epswinexists)
274    {
275      epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList(NUM), mapstorage->getNodeMapList(STR));
276      epswin->show();
277      epswinexists=true;
278      epswin->signal_eps_details_ch().connect(sigc::mem_fun(*this, &NoteBookTab::exportDigraphToEPS));
279      epswin->signal_eps_close_ch().connect(sigc::mem_fun(*this, &NoteBookTab::closeEpsWin));
280      epswin->signal_new_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::popupNewMapWin));
281    }
282}
283
284
285void NoteBookTab::createDesignWin(std::string name)
286{
287  if(!designwinexists)
288    {
289      double attraction, propulsation;
290      int iterations;
291      mapstorage->get_design_data(attraction, propulsation, iterations);
292      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
293
294      designwin->signal_attraction().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_attraction));
295      designwin->signal_propulsation().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_propulsation));
296      designwin->signal_iteration().connect(sigc::mem_fun(*mapstorage, &MapStorage::set_iteration));
297      designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &DigraphDisplayerCanvas::reDesignDigraph));
298
299      designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
300
301      mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data));
302
303      designwin->show();
304      designwinexists=true;
305    }
306}
307
308void NoteBookTab::closeMapWin()
309{
310  mapst2mapwin.disconnect();
311  mapwinexists=false;
312  delete mapwin;
313}
314
315void NoteBookTab::closeEpsWin()
316{
317  epswinexists=false;
318  delete epswin;
319}
320
321bool NoteBookTab::closeDesignWin(GdkEventAny * e)
322{
323  if(e->type==GDK_DELETE)
324    {
325      designwinexists=false;
326      mapst2designwin.disconnect();
327      delete designwin;
328    }
329}
330
331sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
332{
333  return signal_title;
334}
335
336void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
337{
338  gd_canvas->setView(autoscale, zoomtrack, width, radius);
339}
340
341void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
342{
343  gd_canvas->getView(autoscale, zoomtrack, width, radius);
344}
345
346void NoteBookTab::reDesignDigraph()
347{
348  gd_canvas->reDesignDigraph();
349}
350
351void NoteBookTab::active_maps_needed()
352{
353  mapstorage->broadcastActiveMaps();
354}
355
356void NoteBookTab::exportDigraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap)
357{
358  mapstorage->exportDigraphToEPS(options, filename, shapemap);
359}
360
361void NoteBookTab::title_changed(std::string newtitle)
362{
363  signal_title.emit(newtitle);
364  if(epswinexists)
365    {
366      epswin->set_title(newtitle);
367    }
368  if(designwinexists)
369    {
370      designwin->set_title(newtitle);
371    }
372}
Note: See TracBrowser for help on using the repository browser.