COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 174:95872af46fc4

Last change on this file since 174:95872af46fc4 was 174:95872af46fc4, checked in by Alpar Juttner, 15 years ago

Add copyright headers

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