COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 194:6b2b718420eb

Last change on this file since 194:6b2b718420eb was 194:6b2b718420eb, checked in by Hegyi Péter, 13 years ago

Header reorganising

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