COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 195:125c56c1efda

Last change on this file since 195:125c56c1efda was 195:125c56c1efda, checked in by Hegyi Péter, 13 years ago

Mapstorage does not need to know NoteBookTab? furthermore.

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