COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 198:d6cc0579b94b

Last change on this file since 198:d6cc0579b94b was 198:d6cc0579b94b, checked in by Hegyi Péter, 13 years ago

Shape feature of EPS can be used.

File size: 9.4 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 = 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  title_changed(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  title_changed("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      title_changed(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    title_changed(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    title_changed(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  title_changed("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  if(epswinexists)
227    {
228      epswin->registerNewNodeMap(mapname);
229    }
230}
231
232void NoteBookTab::createMapWin(std::string name)
233{
234  if(!mapwinexists)
235    {
236      mapwin=new MapWin("Map Setup - "+name, mapstorage->getEdgeMapList(), mapstorage->getNodeMapList(), *this);
237      mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
238      mapwin->show();
239      mapwinexists=true;
240    }
241}
242
243void NoteBookTab::createExportToEPSWin(std::string name)
244{
245  if(!epswinexists)
246    {
247      epswin=new EpsWin("Export to EPS - "+name, mapstorage->getNodeMapList());
248      epswin->show();
249      epswinexists=true;
250      epswin->signal_eps_details_ch().connect(sigc::mem_fun(*this, &NoteBookTab::exportGraphToEPS));
251      epswin->signal_eps_close_ch().connect(sigc::mem_fun(*this, &NoteBookTab::closeEpsWin));
252      epswin->signal_new_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::popupNewMapWin));
253    }
254}
255
256
257void NoteBookTab::createDesignWin(std::string name)
258{
259  if(!designwinexists)
260    {
261      double attraction, propulsation;
262      int iterations;
263      mapstorage->get_design_data(attraction, propulsation, iterations);
264      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
265
266      designwin->signal_attraction().connect(sigc::mem_fun(mapstorage, &MapStorage::set_attraction));
267      designwin->signal_propulsation().connect(sigc::mem_fun(mapstorage, &MapStorage::set_propulsation));
268      designwin->signal_iteration().connect(sigc::mem_fun(mapstorage, &MapStorage::set_iteration));
269      designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::reDesignGraph));
270
271      designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
272
273      mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data));
274
275      designwin->show();
276      designwinexists=true;
277    }
278}
279
280void NoteBookTab::closeMapWin()
281{
282  mapst2mapwin.disconnect();
283  mapwinexists=false;
284  delete mapwin;
285}
286
287void NoteBookTab::closeEpsWin()
288{
289  epswinexists=false;
290  delete epswin;
291}
292
293bool NoteBookTab::closeDesignWin(GdkEventAny * e)
294{
295  if(e->type==GDK_DELETE)
296    {
297      designwinexists=false;
298      mapst2designwin.disconnect();
299      delete designwin;
300    }
301}
302
303sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
304{
305  return signal_title;
306}
307
308void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
309{
310  gd_canvas->setView(autoscale, zoomtrack, width, radius);
311}
312
313void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
314{
315  gd_canvas->getView(autoscale, zoomtrack, width, radius);
316}
317
318void NoteBookTab::reDesignGraph()
319{
320  gd_canvas->reDesignGraph();
321}
322
323void NoteBookTab::active_maps_needed()
324{
325  mapstorage->broadcastActiveMaps();
326}
327
328void NoteBookTab::exportGraphToEPS(std::vector<bool> options, std::string filename, std::string shapemap)
329{
330  mapstorage->exportGraphToEPS(options, filename, shapemap);
331}
332
333void NoteBookTab::title_changed(std::string newtitle)
334{
335  signal_title.emit(newtitle);
336  if(epswinexists)
337    {
338      epswin->set_title(newtitle);
339    }
340  if(designwinexists)
341    {
342      designwin->set_title(newtitle);
343    }
344}
Note: See TracBrowser for help on using the repository browser.