COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 204:8fec6a6472fe

Last change on this file since 204:8fec6a6472fe was 186:013afe9ee040, checked in by Akos Ladanyi, 13 years ago

Removed this extra widget thing, because it is now developed in my private branch.

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