ladanyi@1606
|
1 |
#include "graph_displayer_canvas.h"
|
ladanyi@1606
|
2 |
#include "broken_edge.h"
|
alpar@1632
|
3 |
#include <cmath>
|
hegyi@1510
|
4 |
|
hegyi@1510
|
5 |
|
hegyi@1510
|
6 |
bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
|
hegyi@1510
|
7 |
{
|
hegyi@1510
|
8 |
Gnome::Canvas::CanvasAA::on_expose_event(event);
|
hegyi@1510
|
9 |
//usleep(10000);
|
hegyi@1510
|
10 |
//rezoom();
|
hegyi@1510
|
11 |
return true;
|
hegyi@1510
|
12 |
}
|
hegyi@1510
|
13 |
|
hegyi@1510
|
14 |
void GraphDisplayerCanvas::changeEditorialTool(int newtool)
|
hegyi@1510
|
15 |
{
|
hegyi@1562
|
16 |
if(actual_tool!=newtool)
|
hegyi@1562
|
17 |
{
|
hegyi@1510
|
18 |
|
hegyi@1562
|
19 |
actual_handler.disconnect();
|
hegyi@1510
|
20 |
|
hegyi@1562
|
21 |
switch(actual_tool)
|
hegyi@1562
|
22 |
{
|
hegyi@1562
|
23 |
case CREATE_EDGE:
|
hegyi@1562
|
24 |
{
|
hegyi@1562
|
25 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1562
|
26 |
generated->type=GDK_BUTTON_RELEASE;
|
hegyi@1562
|
27 |
generated->button.button=3;
|
hegyi@1562
|
28 |
createEdgeEventHandler(generated);
|
hegyi@1562
|
29 |
break;
|
hegyi@1562
|
30 |
}
|
hegyi@1562
|
31 |
case EDGE_MAP_EDIT:
|
hegyi@1579
|
32 |
//has to do the same thing as in the case of NODE_MAP_EDIT
|
hegyi@1579
|
33 |
case NODE_MAP_EDIT:
|
hegyi@1579
|
34 |
{
|
hegyi@1579
|
35 |
break;
|
hegyi@1579
|
36 |
}
|
hegyi@1562
|
37 |
default:
|
hegyi@1562
|
38 |
break;
|
hegyi@1562
|
39 |
}
|
hegyi@1510
|
40 |
|
hegyi@1562
|
41 |
active_item=NULL;
|
hegyi@1562
|
42 |
target_item=NULL;
|
hegyi@1562
|
43 |
active_edge=INVALID;
|
hegyi@1562
|
44 |
active_node=INVALID;
|
hegyi@1551
|
45 |
|
hegyi@1510
|
46 |
|
hegyi@1562
|
47 |
actual_tool=newtool;
|
hegyi@1562
|
48 |
|
hegyi@1562
|
49 |
switch(newtool)
|
hegyi@1562
|
50 |
{
|
hegyi@1562
|
51 |
case MOVE:
|
hegyi@1562
|
52 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
|
hegyi@1562
|
53 |
break;
|
hegyi@1510
|
54 |
|
hegyi@1562
|
55 |
case CREATE_NODE:
|
hegyi@1562
|
56 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
|
hegyi@1562
|
57 |
break;
|
hegyi@1510
|
58 |
|
hegyi@1562
|
59 |
case CREATE_EDGE:
|
hegyi@1562
|
60 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
|
hegyi@1562
|
61 |
break;
|
hegyi@1510
|
62 |
|
hegyi@1562
|
63 |
case ERASER:
|
hegyi@1562
|
64 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
|
hegyi@1562
|
65 |
break;
|
hegyi@1550
|
66 |
|
hegyi@1562
|
67 |
case EDGE_MAP_EDIT:
|
hegyi@1562
|
68 |
grab_focus();
|
hegyi@1562
|
69 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
|
hegyi@1562
|
70 |
break;
|
hegyi@1550
|
71 |
|
hegyi@1562
|
72 |
case NODE_MAP_EDIT:
|
hegyi@1562
|
73 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
|
hegyi@1562
|
74 |
break;
|
hegyi@1562
|
75 |
|
hegyi@1562
|
76 |
default:
|
hegyi@1562
|
77 |
break;
|
hegyi@1562
|
78 |
}
|
hegyi@1510
|
79 |
}
|
hegyi@1510
|
80 |
}
|
hegyi@1510
|
81 |
|
hegyi@1524
|
82 |
int GraphDisplayerCanvas::getActualTool()
|
hegyi@1510
|
83 |
{
|
hegyi@1510
|
84 |
return actual_tool;
|
hegyi@1510
|
85 |
}
|
hegyi@1510
|
86 |
|
hegyi@1524
|
87 |
bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
|
hegyi@1510
|
88 |
{
|
hegyi@1510
|
89 |
switch(e->type)
|
hegyi@1510
|
90 |
{
|
hegyi@1510
|
91 |
case GDK_BUTTON_PRESS:
|
hegyi@1510
|
92 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@1525
|
93 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
94 |
|
hegyi@1525
|
95 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
96 |
active_node=INVALID;
|
ladanyi@1606
|
97 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
98 |
{
|
hegyi@1510
|
99 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
100 |
{
|
hegyi@1510
|
101 |
active_node=i;
|
hegyi@1510
|
102 |
}
|
hegyi@1510
|
103 |
}
|
hegyi@1510
|
104 |
switch(e->button.button)
|
hegyi@1510
|
105 |
{
|
hegyi@1510
|
106 |
case 3:
|
hegyi@1510
|
107 |
isbutton=3;
|
hegyi@1510
|
108 |
break;
|
hegyi@1510
|
109 |
default:
|
hegyi@1510
|
110 |
isbutton=1;
|
hegyi@1510
|
111 |
break;
|
hegyi@1510
|
112 |
}
|
hegyi@1510
|
113 |
break;
|
hegyi@1510
|
114 |
case GDK_BUTTON_RELEASE:
|
hegyi@1510
|
115 |
isbutton=0;
|
hegyi@1510
|
116 |
active_item=NULL;
|
hegyi@1510
|
117 |
active_node=INVALID;
|
hegyi@1510
|
118 |
break;
|
hegyi@1510
|
119 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
120 |
//we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes
|
hegyi@1510
|
121 |
if(active_node!=INVALID)
|
hegyi@1510
|
122 |
{
|
ladanyi@1606
|
123 |
mapstorage.modified = true;
|
ladanyi@1606
|
124 |
mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
|
hegyi@1510
|
125 |
//new coordinates will be the old values,
|
hegyi@1510
|
126 |
//because the item will be moved to the
|
hegyi@1510
|
127 |
//new coordinate therefore the new movement
|
hegyi@1510
|
128 |
//has to be calculated from here
|
hegyi@1510
|
129 |
|
hegyi@1525
|
130 |
double new_x, new_y;
|
hegyi@1525
|
131 |
|
hegyi@1525
|
132 |
window_to_world (e->motion.x, e->motion.y, new_x, new_y);
|
hegyi@1525
|
133 |
|
hegyi@1525
|
134 |
double dx=new_x-clicked_x;
|
hegyi@1525
|
135 |
double dy=new_y-clicked_y;
|
hegyi@1510
|
136 |
|
hegyi@1512
|
137 |
//repositioning node and its text
|
hegyi@1510
|
138 |
active_item->move(dx, dy);
|
hegyi@1512
|
139 |
nodetextmap[active_node]->move(dx, dy);
|
hegyi@1510
|
140 |
|
hegyi@1525
|
141 |
clicked_x=new_x;
|
hegyi@1525
|
142 |
clicked_y=new_y;
|
hegyi@1510
|
143 |
|
hegyi@1510
|
144 |
|
alpar@1651
|
145 |
for(OutEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
|
hegyi@1510
|
146 |
{
|
hegyi@1510
|
147 |
Gnome::Canvas::Points coos;
|
hegyi@1510
|
148 |
double x1, x2, y1, y2;
|
hegyi@1510
|
149 |
|
ladanyi@1606
|
150 |
nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
151 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
152 |
|
ladanyi@1606
|
153 |
nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
154 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
155 |
|
hegyi@1510
|
156 |
if(isbutton==3)
|
hegyi@1510
|
157 |
{
|
hegyi@1524
|
158 |
edgesmap[ei]->setPoints(coos);
|
hegyi@1510
|
159 |
}
|
hegyi@1510
|
160 |
else
|
hegyi@1510
|
161 |
{
|
hegyi@1524
|
162 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@1510
|
163 |
}
|
hegyi@1510
|
164 |
|
hegyi@1512
|
165 |
//reposition of edgetext
|
hegyi@1524
|
166 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@1510
|
167 |
text_pos+=(xy<double>(10,10));
|
hegyi@1510
|
168 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@1510
|
169 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@1510
|
170 |
}
|
hegyi@1510
|
171 |
|
alpar@1651
|
172 |
for(InEdgeIt ei(mapstorage.graph,active_node);ei!=INVALID;++ei)
|
hegyi@1510
|
173 |
{
|
hegyi@1510
|
174 |
Gnome::Canvas::Points coos;
|
hegyi@1510
|
175 |
double x1, x2, y1, y2;
|
hegyi@1510
|
176 |
|
ladanyi@1606
|
177 |
nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
178 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
179 |
|
ladanyi@1606
|
180 |
nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
181 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
182 |
|
hegyi@1510
|
183 |
if(isbutton==3)
|
hegyi@1510
|
184 |
{
|
hegyi@1524
|
185 |
edgesmap[ei]->setPoints(coos);
|
hegyi@1510
|
186 |
}
|
hegyi@1510
|
187 |
else
|
hegyi@1510
|
188 |
{
|
hegyi@1524
|
189 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@1510
|
190 |
}
|
hegyi@1510
|
191 |
|
hegyi@1524
|
192 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@1510
|
193 |
text_pos+=(xy<double>(10,10));
|
hegyi@1510
|
194 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@1510
|
195 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@1510
|
196 |
}
|
hegyi@1510
|
197 |
}
|
hegyi@1510
|
198 |
default: break;
|
hegyi@1510
|
199 |
}
|
hegyi@1510
|
200 |
|
hegyi@1525
|
201 |
return false;
|
hegyi@1510
|
202 |
}
|
hegyi@1510
|
203 |
|
hegyi@1524
|
204 |
bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
|
hegyi@1510
|
205 |
{
|
hegyi@1510
|
206 |
switch(e->type)
|
ladanyi@1645
|
207 |
{
|
ladanyi@1645
|
208 |
//move the new node
|
ladanyi@1645
|
209 |
case GDK_MOTION_NOTIFY:
|
ladanyi@1645
|
210 |
{
|
ladanyi@1645
|
211 |
GdkEvent * generated=new GdkEvent();
|
ladanyi@1645
|
212 |
generated->motion.x=e->motion.x;
|
ladanyi@1645
|
213 |
generated->motion.y=e->motion.y;
|
ladanyi@1645
|
214 |
generated->type=GDK_MOTION_NOTIFY;
|
ladanyi@1645
|
215 |
moveEventHandler(generated);
|
ladanyi@1645
|
216 |
break;
|
ladanyi@1645
|
217 |
}
|
hegyi@1510
|
218 |
|
ladanyi@1645
|
219 |
case GDK_BUTTON_RELEASE:
|
ladanyi@1606
|
220 |
mapstorage.modified = true;
|
ladanyi@1606
|
221 |
|
hegyi@1510
|
222 |
isbutton=1;
|
hegyi@1510
|
223 |
|
alpar@1643
|
224 |
active_node=mapstorage.graph.addNode();
|
hegyi@1510
|
225 |
|
hegyi@1510
|
226 |
//initiating values corresponding to new node in maps
|
hegyi@1510
|
227 |
|
hegyi@1510
|
228 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1510
|
229 |
|
ladanyi@1645
|
230 |
// update coordinates
|
ladanyi@1606
|
231 |
mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
|
ladanyi@1645
|
232 |
|
ladanyi@1645
|
233 |
// update all other maps
|
ladanyi@1645
|
234 |
for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
|
ladanyi@1645
|
235 |
mapstorage.nodemap_storage.begin(); it !=
|
ladanyi@1645
|
236 |
mapstorage.nodemap_storage.end(); ++it)
|
ladanyi@1645
|
237 |
{
|
ladanyi@1646
|
238 |
if ((it->first != "coordinates_x") &&
|
ladanyi@1646
|
239 |
(it->first != "coordinates_y"))
|
ladanyi@1645
|
240 |
{
|
ladanyi@1645
|
241 |
(*(it->second))[active_node] =
|
ladanyi@1645
|
242 |
mapstorage.nodemap_default[it->first];
|
ladanyi@1645
|
243 |
}
|
ladanyi@1645
|
244 |
}
|
ladanyi@1646
|
245 |
// increment the id map's default value
|
ladanyi@1646
|
246 |
mapstorage.nodemap_default["id"] += 1.0;
|
ladanyi@1645
|
247 |
|
ladanyi@1606
|
248 |
nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
|
ladanyi@1645
|
249 |
clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
|
hegyi@1510
|
250 |
active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
|
ladanyi@1645
|
251 |
*(nodesmap[active_node]) <<
|
ladanyi@1645
|
252 |
Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@1645
|
253 |
*(nodesmap[active_node]) <<
|
ladanyi@1645
|
254 |
Gnome::Canvas::Properties::outline_color("black");
|
ladanyi@1645
|
255 |
active_item->raise_to_top();
|
ladanyi@1645
|
256 |
|
hegyi@1510
|
257 |
(nodesmap[active_node])->show();
|
hegyi@1512
|
258 |
|
ladanyi@1606
|
259 |
nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@1645
|
260 |
clicked_x+node_property_defaults[N_RADIUS]+5,
|
ladanyi@1645
|
261 |
clicked_y+node_property_defaults[N_RADIUS]+5, "");
|
hegyi@1512
|
262 |
nodetextmap[active_node]->property_fill_color().set_value("darkblue");
|
ladanyi@1645
|
263 |
nodetextmap[active_node]->raise_to_top();
|
hegyi@1512
|
264 |
|
ladanyi@1606
|
265 |
mapwin.updateNode(active_node);
|
hegyi@1512
|
266 |
|
hegyi@1510
|
267 |
isbutton=0;
|
hegyi@1525
|
268 |
target_item=NULL;
|
hegyi@1510
|
269 |
active_item=NULL;
|
hegyi@1510
|
270 |
active_node=INVALID;
|
ladanyi@1645
|
271 |
|
hegyi@1510
|
272 |
break;
|
hegyi@1510
|
273 |
default:
|
hegyi@1510
|
274 |
break;
|
ladanyi@1645
|
275 |
}
|
hegyi@1510
|
276 |
return false;
|
hegyi@1510
|
277 |
}
|
hegyi@1510
|
278 |
|
hegyi@1524
|
279 |
bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
|
hegyi@1510
|
280 |
{
|
hegyi@1510
|
281 |
switch(e->type)
|
ladanyi@1645
|
282 |
{
|
hegyi@1510
|
283 |
case GDK_BUTTON_PRESS:
|
hegyi@1510
|
284 |
//in edge creation right button has special meaning
|
hegyi@1510
|
285 |
if(e->button.button!=3)
|
ladanyi@1645
|
286 |
{
|
ladanyi@1645
|
287 |
//there is not yet selected node
|
ladanyi@1645
|
288 |
if(active_node==INVALID)
|
ladanyi@1645
|
289 |
{
|
ladanyi@1645
|
290 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@1525
|
291 |
|
ladanyi@1645
|
292 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
293 |
|
ladanyi@1645
|
294 |
active_item=(get_item_at(clicked_x, clicked_y));
|
ladanyi@1645
|
295 |
active_node=INVALID;
|
ladanyi@1645
|
296 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1645
|
297 |
{
|
ladanyi@1645
|
298 |
if(nodesmap[i]==active_item)
|
ladanyi@1645
|
299 |
{
|
ladanyi@1645
|
300 |
active_node=i;
|
ladanyi@1645
|
301 |
}
|
ladanyi@1645
|
302 |
}
|
ladanyi@1645
|
303 |
//the clicked item is really a node
|
ladanyi@1645
|
304 |
if(active_node!=INVALID)
|
ladanyi@1645
|
305 |
{
|
ladanyi@1645
|
306 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
|
ladanyi@1645
|
307 |
isbutton=1;
|
ladanyi@1645
|
308 |
}
|
ladanyi@1645
|
309 |
//clicked item was not a node. It could be e.g. edge.
|
ladanyi@1645
|
310 |
else
|
ladanyi@1645
|
311 |
{
|
ladanyi@1645
|
312 |
active_item=NULL;
|
ladanyi@1645
|
313 |
}
|
ladanyi@1645
|
314 |
}
|
ladanyi@1645
|
315 |
//we only have to do sg. if the mouse button
|
ladanyi@1645
|
316 |
// is pressed already once AND the click was
|
ladanyi@1645
|
317 |
// on a node that was found in the set of
|
ladanyi@1645
|
318 |
//nodes, and now we only search for the second
|
ladanyi@1645
|
319 |
//node
|
ladanyi@1645
|
320 |
else
|
ladanyi@1645
|
321 |
{
|
ladanyi@1645
|
322 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
ladanyi@1645
|
323 |
target_item=(get_item_at(clicked_x, clicked_y));
|
ladanyi@1645
|
324 |
Node target_node=INVALID;
|
ladanyi@1645
|
325 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1645
|
326 |
{
|
ladanyi@1645
|
327 |
if(nodesmap[i]==target_item)
|
ladanyi@1645
|
328 |
{
|
ladanyi@1645
|
329 |
target_node=i;
|
ladanyi@1645
|
330 |
}
|
ladanyi@1645
|
331 |
}
|
ladanyi@1645
|
332 |
//the clicked item is a node, the edge can be drawn
|
ladanyi@1645
|
333 |
if(target_node!=INVALID)
|
ladanyi@1645
|
334 |
{
|
ladanyi@1645
|
335 |
if(target_node!=active_node)
|
ladanyi@1645
|
336 |
{
|
ladanyi@1645
|
337 |
mapstorage.modified = true;
|
ladanyi@1606
|
338 |
|
ladanyi@1645
|
339 |
*(nodesmap[target_node]) <<
|
ladanyi@1645
|
340 |
Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1510
|
341 |
|
ladanyi@1645
|
342 |
//creating new edge
|
ladanyi@1645
|
343 |
active_edge=mapstorage.graph.addEdge(active_node,
|
ladanyi@1645
|
344 |
target_node);
|
hegyi@1510
|
345 |
|
ladanyi@1646
|
346 |
// update maps
|
ladanyi@1645
|
347 |
for (std::map<std::string,
|
ladanyi@1645
|
348 |
Graph::EdgeMap<double>*>::const_iterator it =
|
ladanyi@1645
|
349 |
mapstorage.edgemap_storage.begin(); it !=
|
ladanyi@1645
|
350 |
mapstorage.edgemap_storage.end(); ++it)
|
ladanyi@1645
|
351 |
{
|
ladanyi@1646
|
352 |
(*(it->second))[active_edge] =
|
ladanyi@1646
|
353 |
mapstorage.edgemap_default[it->first];
|
ladanyi@1645
|
354 |
}
|
ladanyi@1646
|
355 |
// increment the id map's default value
|
ladanyi@1646
|
356 |
mapstorage.edgemap_default["id"] += 1.0;
|
hegyi@1510
|
357 |
|
ladanyi@1645
|
358 |
//calculating coordinates of new edge
|
ladanyi@1645
|
359 |
Gnome::Canvas::Points coos;
|
ladanyi@1645
|
360 |
double x1, x2, y1, y2;
|
hegyi@1510
|
361 |
|
ladanyi@1645
|
362 |
active_item->get_bounds(x1, y1, x2, y2);
|
ladanyi@1645
|
363 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
364 |
|
ladanyi@1645
|
365 |
target_item->get_bounds(x1, y1, x2, y2);
|
ladanyi@1645
|
366 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
367 |
|
ladanyi@1645
|
368 |
//drawing new edge
|
ladanyi@1645
|
369 |
edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,
|
ladanyi@1645
|
370 |
*this);
|
ladanyi@1645
|
371 |
*(edgesmap[active_edge]) <<
|
ladanyi@1645
|
372 |
Gnome::Canvas::Properties::fill_color("green");
|
ladanyi@1645
|
373 |
edgesmap[active_edge]->property_width_pixels().set_value(10);
|
hegyi@1510
|
374 |
|
ladanyi@1645
|
375 |
edgesmap[active_edge]->lower_to_bottom();
|
hegyi@1512
|
376 |
|
ladanyi@1645
|
377 |
//initializing edge-text as well, to empty string
|
ladanyi@1645
|
378 |
xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
|
ladanyi@1645
|
379 |
text_pos+=(xy<double>(10,10));
|
ladanyi@1645
|
380 |
|
ladanyi@1645
|
381 |
edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@1645
|
382 |
text_pos.x, text_pos.y, "");
|
ladanyi@1645
|
383 |
edgetextmap[active_edge]->property_fill_color().set_value(
|
ladanyi@1645
|
384 |
"darkgreen");
|
ladanyi@1645
|
385 |
edgetextmap[active_edge]->raise_to_top();
|
ladanyi@1645
|
386 |
|
ladanyi@1645
|
387 |
//updating its properties
|
ladanyi@1645
|
388 |
mapwin.updateEdge(active_edge);
|
ladanyi@1645
|
389 |
}
|
ladanyi@1645
|
390 |
else
|
ladanyi@1645
|
391 |
{
|
ladanyi@1645
|
392 |
target_node=INVALID;
|
ladanyi@1645
|
393 |
std::cerr << "Loop edge is not yet implemented!" << std::endl;
|
ladanyi@1645
|
394 |
}
|
ladanyi@1645
|
395 |
}
|
ladanyi@1645
|
396 |
//clicked item was not a node. it could be an e.g. edge. we do not
|
ladanyi@1645
|
397 |
//deal with it furthermore.
|
ladanyi@1645
|
398 |
else
|
ladanyi@1645
|
399 |
{
|
ladanyi@1645
|
400 |
target_item=NULL;
|
ladanyi@1645
|
401 |
}
|
ladanyi@1645
|
402 |
}
|
ladanyi@1645
|
403 |
}
|
hegyi@1510
|
404 |
break;
|
hegyi@1510
|
405 |
case GDK_BUTTON_RELEASE:
|
hegyi@1510
|
406 |
isbutton=0;
|
hegyi@1510
|
407 |
//we clear settings in two cases
|
hegyi@1510
|
408 |
//1: the edge is ready (target_item has valid value)
|
hegyi@1510
|
409 |
//2: the edge creation is cancelled with right button
|
hegyi@1510
|
410 |
if((target_item)||(e->button.button==3))
|
ladanyi@1645
|
411 |
{
|
ladanyi@1645
|
412 |
if(active_item)
|
ladanyi@1645
|
413 |
{
|
ladanyi@1645
|
414 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@1645
|
415 |
active_item=NULL;
|
ladanyi@1645
|
416 |
}
|
ladanyi@1645
|
417 |
if(target_item)
|
ladanyi@1645
|
418 |
{
|
ladanyi@1645
|
419 |
*target_item << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@1645
|
420 |
target_item=NULL;
|
ladanyi@1645
|
421 |
}
|
ladanyi@1645
|
422 |
active_node=INVALID;
|
ladanyi@1645
|
423 |
active_edge=INVALID;
|
ladanyi@1645
|
424 |
}
|
hegyi@1510
|
425 |
break;
|
hegyi@1510
|
426 |
default:
|
hegyi@1510
|
427 |
break;
|
ladanyi@1645
|
428 |
}
|
hegyi@1510
|
429 |
return false;
|
hegyi@1510
|
430 |
}
|
hegyi@1510
|
431 |
|
hegyi@1524
|
432 |
bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
|
hegyi@1510
|
433 |
{
|
hegyi@1510
|
434 |
switch(e->type)
|
hegyi@1510
|
435 |
{
|
hegyi@1510
|
436 |
case GDK_BUTTON_PRESS:
|
hegyi@1594
|
437 |
//finding the clicked items
|
hegyi@1525
|
438 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
439 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
440 |
active_node=INVALID;
|
hegyi@1510
|
441 |
active_edge=INVALID;
|
hegyi@1594
|
442 |
//was it a node?
|
ladanyi@1606
|
443 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
444 |
{
|
hegyi@1510
|
445 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
446 |
{
|
hegyi@1510
|
447 |
active_node=i;
|
hegyi@1510
|
448 |
}
|
hegyi@1510
|
449 |
}
|
hegyi@1594
|
450 |
//or was it an edge?
|
hegyi@1510
|
451 |
if(active_node==INVALID)
|
hegyi@1510
|
452 |
{
|
ladanyi@1606
|
453 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
454 |
{
|
hegyi@1510
|
455 |
if(edgesmap[i]==active_item)
|
hegyi@1510
|
456 |
{
|
hegyi@1510
|
457 |
active_edge=i;
|
hegyi@1510
|
458 |
}
|
hegyi@1510
|
459 |
}
|
hegyi@1510
|
460 |
}
|
hegyi@1594
|
461 |
|
hegyi@1594
|
462 |
//recolor activated item
|
hegyi@1525
|
463 |
if(active_item)
|
hegyi@1525
|
464 |
{
|
hegyi@1525
|
465 |
*active_item << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1525
|
466 |
}
|
hegyi@1510
|
467 |
break;
|
hegyi@1510
|
468 |
|
hegyi@1510
|
469 |
case GDK_BUTTON_RELEASE:
|
hegyi@1525
|
470 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
471 |
if(active_item)
|
hegyi@1510
|
472 |
{
|
hegyi@1594
|
473 |
//the cursor was not moved since pressing it
|
hegyi@1525
|
474 |
if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
|
hegyi@1510
|
475 |
{
|
hegyi@1594
|
476 |
//a node was found
|
hegyi@1525
|
477 |
if(active_node!=INVALID)
|
hegyi@1525
|
478 |
{
|
ladanyi@1606
|
479 |
mapstorage.modified = true;
|
hegyi@1510
|
480 |
|
hegyi@1525
|
481 |
std::set<Graph::Edge> edges_to_delete;
|
hegyi@1510
|
482 |
|
alpar@1651
|
483 |
for(OutEdgeIt e(mapstorage.graph,active_node);e!=INVALID;++e)
|
hegyi@1525
|
484 |
{
|
hegyi@1525
|
485 |
edges_to_delete.insert(e);
|
hegyi@1525
|
486 |
}
|
alpar@1651
|
487 |
|
alpar@1651
|
488 |
for(InEdgeIt e(mapstorage.graph,active_node);e!=INVALID;++e)
|
hegyi@1525
|
489 |
{
|
hegyi@1525
|
490 |
edges_to_delete.insert(e);
|
hegyi@1525
|
491 |
}
|
alpar@1651
|
492 |
|
hegyi@1525
|
493 |
//deleting collected edges
|
alpar@1651
|
494 |
for(std::set<Graph::Edge>::iterator
|
alpar@1651
|
495 |
edge_set_it=edges_to_delete.begin();
|
alpar@1651
|
496 |
edge_set_it!=edges_to_delete.end();
|
alpar@1651
|
497 |
++edge_set_it)
|
hegyi@1525
|
498 |
{
|
hegyi@1525
|
499 |
deleteItem(*edge_set_it);
|
hegyi@1525
|
500 |
}
|
hegyi@1525
|
501 |
deleteItem(active_node);
|
hegyi@1525
|
502 |
}
|
hegyi@1525
|
503 |
//a simple edge was chosen
|
hegyi@1525
|
504 |
else
|
hegyi@1510
|
505 |
{
|
hegyi@1525
|
506 |
deleteItem(active_edge);
|
hegyi@1510
|
507 |
}
|
hegyi@1510
|
508 |
}
|
hegyi@1525
|
509 |
//pointer was moved, deletion is cancelled
|
hegyi@1510
|
510 |
else
|
hegyi@1510
|
511 |
{
|
hegyi@1525
|
512 |
if(active_node!=INVALID)
|
hegyi@1525
|
513 |
{
|
hegyi@1525
|
514 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1525
|
515 |
}
|
hegyi@1525
|
516 |
else
|
hegyi@1525
|
517 |
{
|
hegyi@1525
|
518 |
*active_item << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@1525
|
519 |
}
|
hegyi@1510
|
520 |
}
|
hegyi@1510
|
521 |
}
|
hegyi@1510
|
522 |
//reseting datas
|
hegyi@1510
|
523 |
active_item=NULL;
|
hegyi@1510
|
524 |
active_edge=INVALID;
|
hegyi@1510
|
525 |
active_node=INVALID;
|
hegyi@1510
|
526 |
break;
|
hegyi@1510
|
527 |
|
hegyi@1510
|
528 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
529 |
break;
|
hegyi@1510
|
530 |
|
hegyi@1510
|
531 |
default:
|
hegyi@1510
|
532 |
break;
|
hegyi@1510
|
533 |
}
|
hegyi@1525
|
534 |
return false;
|
hegyi@1510
|
535 |
}
|
hegyi@1510
|
536 |
|
hegyi@1550
|
537 |
bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
538 |
{
|
hegyi@1599
|
539 |
if(actual_tool==EDGE_MAP_EDIT)
|
ladanyi@1648
|
540 |
{
|
ladanyi@1648
|
541 |
switch(e->type)
|
hegyi@1550
|
542 |
{
|
ladanyi@1648
|
543 |
case GDK_BUTTON_PRESS:
|
ladanyi@1648
|
544 |
{
|
ladanyi@1648
|
545 |
//for determine, whether it was an edge
|
ladanyi@1648
|
546 |
Edge clicked_edge=INVALID;
|
hegyi@1594
|
547 |
|
ladanyi@1648
|
548 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
ladanyi@1648
|
549 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1599
|
550 |
|
ladanyi@1648
|
551 |
//find the activated item between texts
|
ladanyi@1648
|
552 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1648
|
553 |
{
|
ladanyi@1648
|
554 |
//at the same time only one can be active
|
ladanyi@1648
|
555 |
if(edgetextmap[i]==active_item)
|
ladanyi@1648
|
556 |
{
|
ladanyi@1648
|
557 |
clicked_edge=i;
|
ladanyi@1648
|
558 |
}
|
ladanyi@1648
|
559 |
}
|
ladanyi@1647
|
560 |
|
ladanyi@1648
|
561 |
//if it was not between texts, search for it between edges
|
ladanyi@1648
|
562 |
if(clicked_edge==INVALID)
|
ladanyi@1648
|
563 |
{
|
ladanyi@1648
|
564 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1648
|
565 |
{
|
ladanyi@1648
|
566 |
//at the same time only one can be active
|
ladanyi@1648
|
567 |
if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
|
ladanyi@1648
|
568 |
{
|
ladanyi@1648
|
569 |
clicked_edge=i;
|
ladanyi@1648
|
570 |
}
|
ladanyi@1648
|
571 |
}
|
ladanyi@1648
|
572 |
}
|
ladanyi@1648
|
573 |
|
ladanyi@1648
|
574 |
//if it was really an edge...
|
ladanyi@1648
|
575 |
if(clicked_edge!=INVALID)
|
ladanyi@1648
|
576 |
{
|
ladanyi@1648
|
577 |
// the id map is not editable
|
ladanyi@1648
|
578 |
if (edgemap_to_edit == "id") return 0;
|
hegyi@1599
|
579 |
|
ladanyi@1648
|
580 |
//and there is activated map
|
ladanyi@1648
|
581 |
if(edgetextmap[clicked_edge]->property_text().get_value()!="")
|
ladanyi@1648
|
582 |
{
|
ladanyi@1648
|
583 |
//activate the general variable for it
|
ladanyi@1648
|
584 |
active_edge=clicked_edge;
|
hegyi@1599
|
585 |
|
ladanyi@1648
|
586 |
//create a dialog
|
ladanyi@1648
|
587 |
Gtk::Dialog dialog("Edit value", *parentwin, true);
|
ladanyi@1648
|
588 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
ladanyi@1648
|
589 |
dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
|
ladanyi@1648
|
590 |
Gtk::VBox* vbox = dialog.get_vbox();
|
ladanyi@1648
|
591 |
Gtk::Adjustment adj(
|
ladanyi@1648
|
592 |
(*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge],
|
ladanyi@1648
|
593 |
-1000000.0,
|
ladanyi@1648
|
594 |
1000000.0,
|
ladanyi@1648
|
595 |
1.0, 5.0, 0.0);
|
ladanyi@1648
|
596 |
//TODO: find out why doesn't it work with
|
ladanyi@1648
|
597 |
//numeric_limits<double>::min/max
|
ladanyi@1648
|
598 |
Gtk::SpinButton spin(adj);
|
ladanyi@1648
|
599 |
spin.set_numeric(true);
|
ladanyi@1648
|
600 |
spin.set_digits(4);
|
ladanyi@1648
|
601 |
vbox->add(spin);
|
ladanyi@1648
|
602 |
spin.show();
|
ladanyi@1648
|
603 |
switch (dialog.run())
|
ladanyi@1648
|
604 |
{
|
ladanyi@1648
|
605 |
case Gtk::RESPONSE_NONE:
|
ladanyi@1648
|
606 |
case Gtk::RESPONSE_CANCEL:
|
ladanyi@1648
|
607 |
break;
|
ladanyi@1648
|
608 |
case Gtk::RESPONSE_ACCEPT:
|
ladanyi@1648
|
609 |
double new_value = spin.get_value();
|
ladanyi@1648
|
610 |
(*mapstorage.edgemap_storage[edgemap_to_edit])[active_edge] =
|
ladanyi@1648
|
611 |
new_value;
|
ladanyi@1648
|
612 |
std::ostringstream ostr;
|
ladanyi@1648
|
613 |
ostr << new_value;
|
ladanyi@1648
|
614 |
edgetextmap[active_edge]->property_text().set_value(
|
ladanyi@1648
|
615 |
ostr.str());
|
ladanyi@1648
|
616 |
//mapwin.updateEdge(active_edge);
|
ladanyi@1648
|
617 |
mapwin.updateEdge(Edge(INVALID));
|
ladanyi@1648
|
618 |
}
|
ladanyi@1648
|
619 |
}
|
ladanyi@1648
|
620 |
}
|
ladanyi@1648
|
621 |
break;
|
ladanyi@1648
|
622 |
}
|
ladanyi@1648
|
623 |
default:
|
ladanyi@1648
|
624 |
break;
|
hegyi@1550
|
625 |
}
|
ladanyi@1648
|
626 |
}
|
hegyi@1550
|
627 |
return false;
|
hegyi@1550
|
628 |
}
|
hegyi@1550
|
629 |
|
hegyi@1550
|
630 |
bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
631 |
{
|
hegyi@1599
|
632 |
if(actual_tool==NODE_MAP_EDIT)
|
ladanyi@1648
|
633 |
{
|
ladanyi@1648
|
634 |
switch(e->type)
|
hegyi@1579
|
635 |
{
|
ladanyi@1648
|
636 |
case GDK_BUTTON_PRESS:
|
ladanyi@1648
|
637 |
{
|
ladanyi@1648
|
638 |
//for determine, whether it was a node
|
ladanyi@1648
|
639 |
Node clicked_node=INVALID;
|
hegyi@1594
|
640 |
|
ladanyi@1648
|
641 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
ladanyi@1648
|
642 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1594
|
643 |
|
ladanyi@1648
|
644 |
//find the activated item between texts
|
ladanyi@1648
|
645 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1648
|
646 |
{
|
ladanyi@1648
|
647 |
//at the same time only one can be active
|
ladanyi@1648
|
648 |
if(nodetextmap[i]==active_item)
|
ladanyi@1648
|
649 |
{
|
ladanyi@1648
|
650 |
clicked_node=i;
|
ladanyi@1648
|
651 |
}
|
ladanyi@1648
|
652 |
}
|
hegyi@1599
|
653 |
|
ladanyi@1648
|
654 |
//if there was not, search for it between nodes
|
ladanyi@1648
|
655 |
if(clicked_node==INVALID)
|
ladanyi@1648
|
656 |
{
|
ladanyi@1648
|
657 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1648
|
658 |
{
|
ladanyi@1648
|
659 |
//at the same time only one can be active
|
ladanyi@1648
|
660 |
if(nodesmap[i]==active_item)
|
ladanyi@1648
|
661 |
{
|
ladanyi@1648
|
662 |
clicked_node=i;
|
ladanyi@1648
|
663 |
}
|
ladanyi@1648
|
664 |
}
|
ladanyi@1648
|
665 |
}
|
hegyi@1599
|
666 |
|
ladanyi@1648
|
667 |
//if it was really a node...
|
ladanyi@1648
|
668 |
if(clicked_node!=INVALID)
|
ladanyi@1648
|
669 |
{
|
ladanyi@1648
|
670 |
// the id map is not editable
|
ladanyi@1648
|
671 |
if (nodemap_to_edit == "id") return 0;
|
hegyi@1599
|
672 |
|
ladanyi@1648
|
673 |
//and there is activated map
|
ladanyi@1648
|
674 |
if(nodetextmap[clicked_node]->property_text().get_value()!="")
|
ladanyi@1648
|
675 |
{
|
ladanyi@1648
|
676 |
//activate the general variable for it
|
ladanyi@1648
|
677 |
active_node=clicked_node;
|
hegyi@1599
|
678 |
|
ladanyi@1648
|
679 |
//create a dialog
|
ladanyi@1648
|
680 |
Gtk::Dialog dialog("Edit value", *parentwin, true);
|
ladanyi@1648
|
681 |
dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
ladanyi@1648
|
682 |
dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
|
ladanyi@1648
|
683 |
Gtk::VBox* vbox = dialog.get_vbox();
|
ladanyi@1648
|
684 |
Gtk::Adjustment adj(
|
ladanyi@1648
|
685 |
(*mapstorage.nodemap_storage[nodemap_to_edit])[active_node],
|
ladanyi@1648
|
686 |
-1000000.0,
|
ladanyi@1648
|
687 |
1000000.0,
|
ladanyi@1648
|
688 |
1.0, 5.0, 0.0);
|
ladanyi@1648
|
689 |
//TODO: find out why doesn't it work with
|
ladanyi@1648
|
690 |
//numeric_limits<double>::min/max
|
ladanyi@1648
|
691 |
Gtk::SpinButton spin(adj);
|
ladanyi@1648
|
692 |
spin.set_numeric(true);
|
ladanyi@1648
|
693 |
spin.set_digits(4);
|
ladanyi@1648
|
694 |
vbox->add(spin);
|
ladanyi@1648
|
695 |
spin.show();
|
ladanyi@1648
|
696 |
switch (dialog.run())
|
ladanyi@1648
|
697 |
{
|
ladanyi@1648
|
698 |
case Gtk::RESPONSE_NONE:
|
ladanyi@1648
|
699 |
case Gtk::RESPONSE_CANCEL:
|
ladanyi@1648
|
700 |
break;
|
ladanyi@1648
|
701 |
case Gtk::RESPONSE_ACCEPT:
|
ladanyi@1648
|
702 |
double new_value = spin.get_value();
|
ladanyi@1648
|
703 |
(*mapstorage.nodemap_storage[nodemap_to_edit])[active_node] =
|
ladanyi@1648
|
704 |
new_value;
|
ladanyi@1648
|
705 |
std::ostringstream ostr;
|
ladanyi@1648
|
706 |
ostr << new_value;
|
ladanyi@1648
|
707 |
nodetextmap[active_node]->property_text().set_value(
|
ladanyi@1648
|
708 |
ostr.str());
|
ladanyi@1648
|
709 |
//mapwin.updateNode(active_node);
|
ladanyi@1648
|
710 |
mapwin.updateNode(Node(INVALID));
|
ladanyi@1648
|
711 |
}
|
ladanyi@1648
|
712 |
}
|
ladanyi@1648
|
713 |
}
|
ladanyi@1648
|
714 |
break;
|
ladanyi@1648
|
715 |
}
|
ladanyi@1648
|
716 |
default:
|
ladanyi@1648
|
717 |
break;
|
hegyi@1579
|
718 |
}
|
ladanyi@1648
|
719 |
}
|
hegyi@1579
|
720 |
return false;
|
hegyi@1550
|
721 |
}
|
hegyi@1550
|
722 |
|
alpar@1643
|
723 |
void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
|
hegyi@1510
|
724 |
{
|
hegyi@1512
|
725 |
delete(nodetextmap[node_to_delete]);
|
hegyi@1510
|
726 |
delete(nodesmap[node_to_delete]);
|
ladanyi@1606
|
727 |
mapstorage.graph.erase(node_to_delete);
|
hegyi@1510
|
728 |
}
|
hegyi@1510
|
729 |
|
alpar@1643
|
730 |
void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete)
|
hegyi@1510
|
731 |
{
|
hegyi@1512
|
732 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@1510
|
733 |
delete(edgesmap[edge_to_delete]);
|
ladanyi@1606
|
734 |
mapstorage.graph.erase(edge_to_delete);
|
hegyi@1510
|
735 |
}
|
hegyi@1510
|
736 |
|
hegyi@1524
|
737 |
void GraphDisplayerCanvas::textReposition(xy<double> new_place)
|
hegyi@1510
|
738 |
{
|
hegyi@1510
|
739 |
new_place+=(xy<double>(10,10));
|
hegyi@1579
|
740 |
edgetextmap[forming_edge]->property_x().set_value(new_place.x);
|
hegyi@1579
|
741 |
edgetextmap[forming_edge]->property_y().set_value(new_place.y);
|
hegyi@1510
|
742 |
}
|
hegyi@1510
|
743 |
|
hegyi@1524
|
744 |
void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
|
hegyi@1510
|
745 |
{
|
hegyi@1510
|
746 |
if(on)
|
hegyi@1510
|
747 |
{
|
hegyi@1579
|
748 |
if(forming_edge!=INVALID)
|
hegyi@1510
|
749 |
{
|
hegyi@1599
|
750 |
std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
|
hegyi@1510
|
751 |
}
|
hegyi@1510
|
752 |
else
|
hegyi@1510
|
753 |
{
|
ladanyi@1606
|
754 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
755 |
{
|
hegyi@1510
|
756 |
if(edgesmap[i]==active_bre)
|
hegyi@1510
|
757 |
{
|
hegyi@1579
|
758 |
forming_edge=i;
|
hegyi@1510
|
759 |
}
|
hegyi@1510
|
760 |
}
|
hegyi@1510
|
761 |
}
|
hegyi@1510
|
762 |
}
|
hegyi@1510
|
763 |
else
|
hegyi@1510
|
764 |
{
|
hegyi@1579
|
765 |
if(forming_edge!=INVALID)
|
hegyi@1510
|
766 |
{
|
hegyi@1579
|
767 |
forming_edge=INVALID;
|
hegyi@1510
|
768 |
}
|
hegyi@1510
|
769 |
else
|
hegyi@1510
|
770 |
{
|
hegyi@1599
|
771 |
std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
|
hegyi@1510
|
772 |
}
|
hegyi@1510
|
773 |
}
|
hegyi@1510
|
774 |
|
hegyi@1510
|
775 |
}
|
hegyi@1550
|
776 |
|
hegyi@1597
|
777 |
int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
|
hegyi@1585
|
778 |
{
|
hegyi@1594
|
779 |
//create the new map
|
ladanyi@1606
|
780 |
Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
|
hegyi@1597
|
781 |
|
hegyi@1597
|
782 |
//if addition was not successful addEdgeMap returns one.
|
hegyi@1597
|
783 |
//cause can be that there is already a map named like the new one
|
ladanyi@1645
|
784 |
if(mapstorage.addEdgeMap(mapname,emptr, default_value))
|
hegyi@1597
|
785 |
{
|
hegyi@1597
|
786 |
return 1;
|
hegyi@1597
|
787 |
}
|
hegyi@1597
|
788 |
|
hegyi@1594
|
789 |
|
hegyi@1594
|
790 |
//add it to the list of the displayable maps
|
ladanyi@1606
|
791 |
mapwin.registerNewEdgeMap(mapname);
|
hegyi@1594
|
792 |
|
hegyi@1594
|
793 |
//display it
|
hegyi@1592
|
794 |
changeEdgeText(mapname);
|
hegyi@1597
|
795 |
|
hegyi@1597
|
796 |
return 0;
|
hegyi@1585
|
797 |
}
|
hegyi@1585
|
798 |
|
hegyi@1597
|
799 |
int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
|
hegyi@1585
|
800 |
{
|
hegyi@1594
|
801 |
//create the new map
|
ladanyi@1606
|
802 |
Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
|
hegyi@1597
|
803 |
|
hegyi@1597
|
804 |
//if addition was not successful addNodeMap returns one.
|
hegyi@1597
|
805 |
//cause can be that there is already a map named like the new one
|
ladanyi@1645
|
806 |
if(mapstorage.addNodeMap(mapname,emptr, default_value))
|
hegyi@1597
|
807 |
{
|
hegyi@1597
|
808 |
return 1;
|
hegyi@1597
|
809 |
}
|
hegyi@1594
|
810 |
|
hegyi@1594
|
811 |
//add it to the list of the displayable maps
|
ladanyi@1606
|
812 |
mapwin.registerNewNodeMap(mapname);
|
hegyi@1594
|
813 |
|
hegyi@1594
|
814 |
//display it
|
hegyi@1592
|
815 |
changeNodeText(mapname);
|
hegyi@1597
|
816 |
|
hegyi@1597
|
817 |
return 0;
|
hegyi@1585
|
818 |
}
|
hegyi@1585
|
819 |
|