COIN-OR::LEMON - Graph Library

source: glemon-0.x/nbtab.cc @ 197:c1084e2bff10

Last change on this file since 197:c1084e2bff10 was 197:c1084e2bff10, checked in by Hegyi Péter, 18 years ago

Sorry, forgot tu initialize variable.

File size: 9.2 KB
RevLine 
[174]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
[96]19#include <nbtab.h>
[194]20#include <mapstorage.h>
[191]21#include <eps_win.h>
[194]22#include <map_win.h>
23#include <design_win.h>
24#include <graph_displayer_canvas.h>
[96]25
[194]26
27
[197]28NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false), epswinexists(false)
[96]29{
[195]30  mapstorage=new MapStorage();
[194]31
[136]32  Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
[96]33  gd_canvas=new GraphDisplayerCanvas(*this);
[136]34  pScrolledWindow->add(*gd_canvas);
35  add(*pScrolledWindow);
[96]36
37  //connecting signals - controller character
[194]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));
[195]41  mapstorage->signal_background_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::setBackground));
[96]42  show_all_children();
43  show();
44}
45
46void NoteBookTab::readFile(const std::string &file)
47{
[194]48  mapstorage->readFromFile(file);
49  mapstorage->file_name = file;
50  mapstorage->modified = false;
[96]51  gd_canvas->drawGraph();
52  if(mapwinexists)
53    {
[194]54      mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
[96]55    }
[196]56  title_changed(Glib::filename_display_basename(file));
[96]57}
58
59void NoteBookTab::newFile()
60{
[194]61  if (mapstorage->modified)
[96]62  {
63    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
64        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
[102]65    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
[96]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();
[194]80  mapstorage->clear();
[96]81  if(mapwinexists)
82    {
[194]83      mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
[96]84    }
[196]85  title_changed("unsaved file");
[96]86}
87
88void NoteBookTab::openFile()
89{
[194]90  if (mapstorage->modified)
[96]91  {
92    Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
93        Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
[102]94    mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
[96]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();
[194]114    mapstorage->clear();
[96]115    Glib::ustring filename = fcdialog.get_filename();
[194]116    if (!mapstorage->readFromFile(filename))
[96]117    {
[194]118      mapstorage->file_name = filename;
119      mapstorage->modified = false;
[96]120      gd_canvas->drawGraph();
121      if(mapwinexists)
122        {
[194]123          mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
[96]124        }
[196]125      title_changed(Glib::filename_display_basename(filename));
[96]126    }
127  }
128}
129
130void NoteBookTab::saveFile()
131{
[194]132  if (mapstorage->file_name == "") {
[96]133    saveFileAs();
134  }
135  else
136  {
[194]137    mapstorage->writeToFile(mapstorage->file_name);
138    mapstorage->modified = false;
[196]139    title_changed(Glib::filename_display_basename(mapstorage->file_name));
[96]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();
[194]151    mapstorage->file_name = filename;
152    mapstorage->writeToFile(filename);
153    mapstorage->modified = false;
[196]154    title_changed(Glib::filename_display_basename(filename));
[96]155  }
156}
157
158void NoteBookTab::close()
159{
[194]160  if (mapstorage->modified)
[96]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();
[194]179  mapstorage->clear();
[96]180  if(mapwinexists)
181    {
[194]182      mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
[96]183    }
[196]184  title_changed("unsaved file");
[96]185}
186
187void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
188{
[194]189  mapstorage->changeActiveMap(itisedge, prop, mapname);
[96]190}
191
192sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
193{
194  return signal_newmap;
195}
196
[121]197void NoteBookTab::popupNewMapWin(bool itisedge)
[96]198{
199  signal_newmap.emit(this, itisedge);
200}
201
202std::string NoteBookTab::getActiveEdgeMap(int prop)
203{
[194]204  return mapstorage->getActiveEdgeMap(prop);
[96]205}
206
207std::string NoteBookTab::getActiveNodeMap(int prop)
208{
[194]209  return mapstorage->getActiveNodeMap(prop);
[96]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    {
[194]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));
[96]234      mapwin->show();
235      mapwinexists=true;
236    }
237}
238
[191]239void NoteBookTab::createExportToEPSWin(std::string name)
240{
241  if(!epswinexists)
242    {
[196]243      epswin=new EpsWin("Export to EPS - "+name);
[191]244      epswin->show();
245      epswinexists=true;
[196]246      epswin->signal_eps_details_ch().connect(sigc::mem_fun(*this, &NoteBookTab::exportGraphToEPS));
247      epswin->signal_eps_close_ch().connect(sigc::mem_fun(*this, &NoteBookTab::closeEpsWin));
[191]248    }
249}
250
251
[160]252void NoteBookTab::createDesignWin(std::string name)
253{
254  if(!designwinexists)
255    {
256      double attraction, propulsation;
257      int iterations;
[194]258      mapstorage->get_design_data(attraction, propulsation, iterations);
[196]259      designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations);
[160]260
[177]261      designwin->signal_attraction().connect(sigc::mem_fun(mapstorage, &MapStorage::set_attraction));
262      designwin->signal_propulsation().connect(sigc::mem_fun(mapstorage, &MapStorage::set_propulsation));
263      designwin->signal_iteration().connect(sigc::mem_fun(mapstorage, &MapStorage::set_iteration));
[160]264      designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::reDesignGraph));
265
266      designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
267
[194]268      mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data));
[177]269
[160]270      designwin->show();
271      designwinexists=true;
272    }
273}
274
[96]275void NoteBookTab::closeMapWin()
276{
[172]277  mapst2mapwin.disconnect();
[96]278  mapwinexists=false;
279  delete mapwin;
280}
281
[191]282void NoteBookTab::closeEpsWin()
283{
284  epswinexists=false;
285  delete epswin;
286}
287
[160]288bool NoteBookTab::closeDesignWin(GdkEventAny * e)
289{
290  if(e->type==GDK_DELETE)
291    {
292      designwinexists=false;
[177]293      mapst2designwin.disconnect();
[160]294      delete designwin;
295    }
296}
297
[96]298sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
299{
300  return signal_title;
301}
302
[157]303void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
[154]304{
[157]305  gd_canvas->setView(autoscale, zoomtrack, width, radius);
[154]306}
307
[157]308void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
[154]309{
[157]310  gd_canvas->getView(autoscale, zoomtrack, width, radius);
[154]311}
[160]312
313void NoteBookTab::reDesignGraph()
314{
315  gd_canvas->reDesignGraph();
316}
317
[172]318void NoteBookTab::active_maps_needed()
319{
[194]320  mapstorage->broadcastActiveMaps();
[172]321}
[191]322
323void NoteBookTab::exportGraphToEPS(std::vector<bool> options, std::string filename)
324{
[194]325  mapstorage->exportGraphToEPS(options, filename);
[191]326}
[196]327
328void NoteBookTab::title_changed(std::string newtitle)
329{
330  signal_title.emit(newtitle);
331  if(epswinexists)
332    {
333      epswin->set_title(newtitle);
334    }
335  if(designwinexists)
336    {
337      designwin->set_title(newtitle);
338    }
339}
Note: See TracBrowser for help on using the repository browser.