alpar@174
|
1 |
/* -*- C++ -*-
|
alpar@174
|
2 |
*
|
alpar@174
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@174
|
4 |
*
|
alpar@174
|
5 |
* Copyright (C) 2003-2006
|
alpar@174
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@174
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@174
|
8 |
*
|
alpar@174
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@174
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@174
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@174
|
12 |
*
|
alpar@174
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@174
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@174
|
15 |
* purpose.
|
alpar@174
|
16 |
*
|
alpar@174
|
17 |
*/
|
alpar@174
|
18 |
|
hegyi@96
|
19 |
#include <nbtab.h>
|
hegyi@194
|
20 |
#include <mapstorage.h>
|
hegyi@191
|
21 |
#include <eps_win.h>
|
hegyi@194
|
22 |
#include <map_win.h>
|
hegyi@194
|
23 |
#include <design_win.h>
|
hegyi@194
|
24 |
#include <graph_displayer_canvas.h>
|
hegyi@96
|
25 |
|
hegyi@194
|
26 |
|
hegyi@194
|
27 |
|
hegyi@194
|
28 |
NoteBookTab::NoteBookTab():mapwinexists(false), designwinexists(false)
|
hegyi@96
|
29 |
{
|
hegyi@194
|
30 |
mapstorage=new MapStorage(*this);
|
hegyi@194
|
31 |
|
ladanyi@136
|
32 |
Gtk::ScrolledWindow *pScrolledWindow = manage(new Gtk::ScrolledWindow);
|
hegyi@96
|
33 |
gd_canvas=new GraphDisplayerCanvas(*this);
|
ladanyi@136
|
34 |
pScrolledWindow->add(*gd_canvas);
|
ladanyi@136
|
35 |
add(*pScrolledWindow);
|
hegyi@96
|
36 |
|
hegyi@96
|
37 |
//connecting signals - controller character
|
hegyi@194
|
38 |
mapstorage->signal_prop_ch().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::propertyChange));
|
hegyi@194
|
39 |
mapstorage->signal_node_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewNodeMap));
|
hegyi@194
|
40 |
mapstorage->signal_edge_map_ch().connect(sigc::mem_fun(*this, &NoteBookTab::registerNewEdgeMap));
|
hegyi@96
|
41 |
show_all_children();
|
hegyi@96
|
42 |
show();
|
hegyi@96
|
43 |
}
|
hegyi@96
|
44 |
|
hegyi@96
|
45 |
void NoteBookTab::readFile(const std::string &file)
|
hegyi@96
|
46 |
{
|
hegyi@194
|
47 |
mapstorage->readFromFile(file);
|
hegyi@194
|
48 |
mapstorage->file_name = file;
|
hegyi@194
|
49 |
mapstorage->modified = false;
|
hegyi@96
|
50 |
gd_canvas->drawGraph();
|
hegyi@96
|
51 |
if(mapwinexists)
|
hegyi@96
|
52 |
{
|
hegyi@194
|
53 |
mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
|
hegyi@96
|
54 |
}
|
hegyi@96
|
55 |
signal_title.emit(Glib::filename_display_basename(file));
|
hegyi@96
|
56 |
}
|
hegyi@96
|
57 |
|
hegyi@96
|
58 |
void NoteBookTab::newFile()
|
hegyi@96
|
59 |
{
|
hegyi@194
|
60 |
if (mapstorage->modified)
|
hegyi@96
|
61 |
{
|
hegyi@96
|
62 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
hegyi@96
|
63 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
hegyi@102
|
64 |
mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
|
hegyi@96
|
65 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@96
|
66 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@96
|
67 |
switch (mdialog.run())
|
hegyi@96
|
68 |
{
|
hegyi@96
|
69 |
case Gtk::RESPONSE_CANCEL:
|
hegyi@96
|
70 |
return;
|
hegyi@96
|
71 |
case Gtk::RESPONSE_REJECT:
|
hegyi@96
|
72 |
break;
|
hegyi@96
|
73 |
case Gtk::RESPONSE_ACCEPT:
|
hegyi@96
|
74 |
saveFile();
|
hegyi@96
|
75 |
break;
|
hegyi@96
|
76 |
}
|
hegyi@96
|
77 |
}
|
hegyi@96
|
78 |
gd_canvas->clear();
|
hegyi@194
|
79 |
mapstorage->clear();
|
hegyi@96
|
80 |
if(mapwinexists)
|
hegyi@96
|
81 |
{
|
hegyi@194
|
82 |
mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
|
hegyi@96
|
83 |
}
|
hegyi@96
|
84 |
signal_title.emit("unsaved file");
|
hegyi@96
|
85 |
}
|
hegyi@96
|
86 |
|
hegyi@96
|
87 |
void NoteBookTab::openFile()
|
hegyi@96
|
88 |
{
|
hegyi@194
|
89 |
if (mapstorage->modified)
|
hegyi@96
|
90 |
{
|
hegyi@96
|
91 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
hegyi@96
|
92 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
hegyi@102
|
93 |
mdialog.add_button("Close file _without Saving", Gtk::RESPONSE_REJECT);
|
hegyi@96
|
94 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@96
|
95 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@96
|
96 |
switch (mdialog.run())
|
hegyi@96
|
97 |
{
|
hegyi@96
|
98 |
case Gtk::RESPONSE_CANCEL:
|
hegyi@96
|
99 |
return;
|
hegyi@96
|
100 |
case Gtk::RESPONSE_REJECT:
|
hegyi@96
|
101 |
break;
|
hegyi@96
|
102 |
case Gtk::RESPONSE_ACCEPT:
|
hegyi@96
|
103 |
saveFile();
|
hegyi@96
|
104 |
break;
|
hegyi@96
|
105 |
}
|
hegyi@96
|
106 |
}
|
hegyi@96
|
107 |
Gtk::FileChooserDialog fcdialog("Open File");
|
hegyi@96
|
108 |
fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@96
|
109 |
fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
|
hegyi@96
|
110 |
if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
|
hegyi@96
|
111 |
{
|
hegyi@96
|
112 |
gd_canvas->clear();
|
hegyi@194
|
113 |
mapstorage->clear();
|
hegyi@96
|
114 |
Glib::ustring filename = fcdialog.get_filename();
|
hegyi@194
|
115 |
if (!mapstorage->readFromFile(filename))
|
hegyi@96
|
116 |
{
|
hegyi@194
|
117 |
mapstorage->file_name = filename;
|
hegyi@194
|
118 |
mapstorage->modified = false;
|
hegyi@96
|
119 |
gd_canvas->drawGraph();
|
hegyi@96
|
120 |
if(mapwinexists)
|
hegyi@96
|
121 |
{
|
hegyi@194
|
122 |
mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
|
hegyi@96
|
123 |
}
|
hegyi@96
|
124 |
signal_title.emit(Glib::filename_display_basename(filename));
|
hegyi@96
|
125 |
}
|
hegyi@96
|
126 |
}
|
hegyi@96
|
127 |
}
|
hegyi@96
|
128 |
|
hegyi@96
|
129 |
void NoteBookTab::saveFile()
|
hegyi@96
|
130 |
{
|
hegyi@194
|
131 |
if (mapstorage->file_name == "") {
|
hegyi@96
|
132 |
saveFileAs();
|
hegyi@96
|
133 |
}
|
hegyi@96
|
134 |
else
|
hegyi@96
|
135 |
{
|
hegyi@194
|
136 |
mapstorage->writeToFile(mapstorage->file_name);
|
hegyi@194
|
137 |
mapstorage->modified = false;
|
hegyi@194
|
138 |
signal_title.emit(Glib::filename_display_basename(mapstorage->file_name));
|
hegyi@96
|
139 |
}
|
hegyi@96
|
140 |
}
|
hegyi@96
|
141 |
|
hegyi@96
|
142 |
void NoteBookTab::saveFileAs()
|
hegyi@96
|
143 |
{
|
hegyi@96
|
144 |
Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
|
hegyi@96
|
145 |
fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@96
|
146 |
fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@96
|
147 |
if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
|
hegyi@96
|
148 |
{
|
hegyi@96
|
149 |
Glib::ustring filename = fcdialog.get_filename();
|
hegyi@194
|
150 |
mapstorage->file_name = filename;
|
hegyi@194
|
151 |
mapstorage->writeToFile(filename);
|
hegyi@194
|
152 |
mapstorage->modified = false;
|
hegyi@96
|
153 |
signal_title.emit(Glib::filename_display_basename(filename));
|
hegyi@96
|
154 |
}
|
hegyi@96
|
155 |
}
|
hegyi@96
|
156 |
|
hegyi@96
|
157 |
void NoteBookTab::close()
|
hegyi@96
|
158 |
{
|
hegyi@194
|
159 |
if (mapstorage->modified)
|
hegyi@96
|
160 |
{
|
hegyi@96
|
161 |
Gtk::MessageDialog mdialog("<b>Save changes before closing?</b>", true,
|
hegyi@96
|
162 |
Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
|
hegyi@96
|
163 |
mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
|
hegyi@96
|
164 |
mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
hegyi@96
|
165 |
mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
|
hegyi@96
|
166 |
switch (mdialog.run())
|
hegyi@96
|
167 |
{
|
hegyi@96
|
168 |
case Gtk::RESPONSE_CANCEL:
|
hegyi@96
|
169 |
return;
|
hegyi@96
|
170 |
case Gtk::RESPONSE_REJECT:
|
hegyi@96
|
171 |
break;
|
hegyi@96
|
172 |
case Gtk::RESPONSE_ACCEPT:
|
hegyi@96
|
173 |
saveFile();
|
hegyi@96
|
174 |
break;
|
hegyi@96
|
175 |
}
|
hegyi@96
|
176 |
}
|
hegyi@96
|
177 |
gd_canvas->clear();
|
hegyi@194
|
178 |
mapstorage->clear();
|
hegyi@96
|
179 |
if(mapwinexists)
|
hegyi@96
|
180 |
{
|
hegyi@194
|
181 |
mapwin->update(mapstorage->getEdgeMapList(), mapstorage->getNodeMapList());
|
hegyi@96
|
182 |
}
|
hegyi@96
|
183 |
signal_title.emit("unsaved file");
|
hegyi@96
|
184 |
}
|
hegyi@96
|
185 |
|
hegyi@96
|
186 |
void NoteBookTab::propertyChange(bool itisedge, int prop, std::string mapname)
|
hegyi@96
|
187 |
{
|
hegyi@194
|
188 |
mapstorage->changeActiveMap(itisedge, prop, mapname);
|
hegyi@96
|
189 |
}
|
hegyi@96
|
190 |
|
hegyi@96
|
191 |
sigc::signal<void, NoteBookTab *, bool> NoteBookTab::signal_newmap_needed()
|
hegyi@96
|
192 |
{
|
hegyi@96
|
193 |
return signal_newmap;
|
hegyi@96
|
194 |
}
|
hegyi@96
|
195 |
|
hegyi@121
|
196 |
void NoteBookTab::popupNewMapWin(bool itisedge)
|
hegyi@96
|
197 |
{
|
hegyi@96
|
198 |
signal_newmap.emit(this, itisedge);
|
hegyi@96
|
199 |
}
|
hegyi@96
|
200 |
|
hegyi@96
|
201 |
std::string NoteBookTab::getActiveEdgeMap(int prop)
|
hegyi@96
|
202 |
{
|
hegyi@194
|
203 |
return mapstorage->getActiveEdgeMap(prop);
|
hegyi@96
|
204 |
}
|
hegyi@96
|
205 |
|
hegyi@96
|
206 |
std::string NoteBookTab::getActiveNodeMap(int prop)
|
hegyi@96
|
207 |
{
|
hegyi@194
|
208 |
return mapstorage->getActiveNodeMap(prop);
|
hegyi@96
|
209 |
}
|
hegyi@96
|
210 |
|
hegyi@96
|
211 |
void NoteBookTab::registerNewEdgeMap(std::string mapname)
|
hegyi@96
|
212 |
{
|
hegyi@96
|
213 |
if(mapwinexists)
|
hegyi@96
|
214 |
{
|
hegyi@96
|
215 |
mapwin->registerNewEdgeMap(mapname);
|
hegyi@96
|
216 |
}
|
hegyi@96
|
217 |
}
|
hegyi@96
|
218 |
|
hegyi@96
|
219 |
void NoteBookTab::registerNewNodeMap(std::string mapname)
|
hegyi@96
|
220 |
{
|
hegyi@96
|
221 |
if(mapwinexists)
|
hegyi@96
|
222 |
{
|
hegyi@96
|
223 |
mapwin->registerNewNodeMap(mapname);
|
hegyi@96
|
224 |
}
|
hegyi@96
|
225 |
}
|
hegyi@96
|
226 |
|
hegyi@96
|
227 |
void NoteBookTab::createMapWin(std::string name)
|
hegyi@96
|
228 |
{
|
hegyi@96
|
229 |
if(!mapwinexists)
|
hegyi@96
|
230 |
{
|
hegyi@194
|
231 |
mapwin=new MapWin("Map Setup - "+name, mapstorage->getEdgeMapList(), mapstorage->getNodeMapList(), *this);
|
hegyi@194
|
232 |
mapst2mapwin=mapstorage->signal_map_win_ch().connect(sigc::mem_fun(*mapwin, &MapWin::changeEntry));
|
hegyi@96
|
233 |
mapwin->show();
|
hegyi@96
|
234 |
mapwinexists=true;
|
hegyi@96
|
235 |
}
|
hegyi@96
|
236 |
}
|
hegyi@96
|
237 |
|
hegyi@191
|
238 |
void NoteBookTab::createExportToEPSWin(std::string name)
|
hegyi@191
|
239 |
{
|
hegyi@191
|
240 |
if(!epswinexists)
|
hegyi@191
|
241 |
{
|
hegyi@191
|
242 |
epswin=new EpsWin("Export to EPS - "+name, *this);
|
hegyi@191
|
243 |
epswin->show();
|
hegyi@191
|
244 |
epswinexists=true;
|
hegyi@191
|
245 |
}
|
hegyi@191
|
246 |
}
|
hegyi@191
|
247 |
|
hegyi@191
|
248 |
|
hegyi@160
|
249 |
void NoteBookTab::createDesignWin(std::string name)
|
hegyi@160
|
250 |
{
|
hegyi@160
|
251 |
if(!designwinexists)
|
hegyi@160
|
252 |
{
|
hegyi@160
|
253 |
double attraction, propulsation;
|
hegyi@160
|
254 |
int iterations;
|
hegyi@194
|
255 |
mapstorage->get_design_data(attraction, propulsation, iterations);
|
hegyi@172
|
256 |
designwin=new DesignWin("Design Setup - "+name, attraction, propulsation, iterations, *this);
|
hegyi@160
|
257 |
|
hegyi@177
|
258 |
designwin->signal_attraction().connect(sigc::mem_fun(mapstorage, &MapStorage::set_attraction));
|
hegyi@177
|
259 |
designwin->signal_propulsation().connect(sigc::mem_fun(mapstorage, &MapStorage::set_propulsation));
|
hegyi@177
|
260 |
designwin->signal_iteration().connect(sigc::mem_fun(mapstorage, &MapStorage::set_iteration));
|
hegyi@160
|
261 |
designwin->close_run().connect(sigc::mem_fun(*gd_canvas, &GraphDisplayerCanvas::reDesignGraph));
|
hegyi@160
|
262 |
|
hegyi@160
|
263 |
designwin->signal_delete_event().connect(sigc::mem_fun(*this, &NoteBookTab::closeDesignWin));
|
hegyi@160
|
264 |
|
hegyi@194
|
265 |
mapst2designwin=mapstorage->signal_design_win_ch().connect(sigc::mem_fun(*designwin, &DesignWin::set_data));
|
hegyi@177
|
266 |
|
hegyi@160
|
267 |
designwin->show();
|
hegyi@160
|
268 |
designwinexists=true;
|
hegyi@160
|
269 |
}
|
hegyi@160
|
270 |
}
|
hegyi@160
|
271 |
|
hegyi@96
|
272 |
void NoteBookTab::closeMapWin()
|
hegyi@96
|
273 |
{
|
hegyi@172
|
274 |
mapst2mapwin.disconnect();
|
hegyi@96
|
275 |
mapwinexists=false;
|
hegyi@96
|
276 |
delete mapwin;
|
hegyi@96
|
277 |
}
|
hegyi@96
|
278 |
|
hegyi@191
|
279 |
void NoteBookTab::closeEpsWin()
|
hegyi@191
|
280 |
{
|
hegyi@191
|
281 |
epswinexists=false;
|
hegyi@191
|
282 |
delete epswin;
|
hegyi@191
|
283 |
}
|
hegyi@191
|
284 |
|
hegyi@160
|
285 |
bool NoteBookTab::closeDesignWin(GdkEventAny * e)
|
hegyi@160
|
286 |
{
|
hegyi@160
|
287 |
if(e->type==GDK_DELETE)
|
hegyi@160
|
288 |
{
|
hegyi@160
|
289 |
designwinexists=false;
|
hegyi@177
|
290 |
mapst2designwin.disconnect();
|
hegyi@160
|
291 |
delete designwin;
|
hegyi@160
|
292 |
}
|
hegyi@160
|
293 |
}
|
hegyi@160
|
294 |
|
hegyi@96
|
295 |
sigc::signal<void, std::string> NoteBookTab::signal_title_ch()
|
hegyi@96
|
296 |
{
|
hegyi@96
|
297 |
return signal_title;
|
hegyi@96
|
298 |
}
|
hegyi@96
|
299 |
|
hegyi@157
|
300 |
void NoteBookTab::setView(bool autoscale, bool zoomtrack, double width, double radius)
|
hegyi@154
|
301 |
{
|
hegyi@157
|
302 |
gd_canvas->setView(autoscale, zoomtrack, width, radius);
|
hegyi@154
|
303 |
}
|
hegyi@154
|
304 |
|
hegyi@157
|
305 |
void NoteBookTab::getView(bool & autoscale, bool & zoomtrack, double& width, double& radius)
|
hegyi@154
|
306 |
{
|
hegyi@157
|
307 |
gd_canvas->getView(autoscale, zoomtrack, width, radius);
|
hegyi@154
|
308 |
}
|
hegyi@160
|
309 |
|
hegyi@160
|
310 |
void NoteBookTab::reDesignGraph()
|
hegyi@160
|
311 |
{
|
hegyi@160
|
312 |
gd_canvas->reDesignGraph();
|
hegyi@160
|
313 |
}
|
hegyi@160
|
314 |
|
hegyi@172
|
315 |
void NoteBookTab::active_maps_needed()
|
hegyi@172
|
316 |
{
|
hegyi@194
|
317 |
mapstorage->broadcastActiveMaps();
|
hegyi@172
|
318 |
}
|
hegyi@191
|
319 |
|
hegyi@191
|
320 |
void NoteBookTab::exportGraphToEPS(std::vector<bool> options, std::string filename)
|
hegyi@191
|
321 |
{
|
hegyi@194
|
322 |
mapstorage->exportGraphToEPS(options, filename);
|
hegyi@191
|
323 |
}
|