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 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1579
|
36 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1579
|
37 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1579
|
38 |
entryWidgetChangeHandler(generated);
|
hegyi@1579
|
39 |
entrywidget.hide();
|
hegyi@1579
|
40 |
break;
|
hegyi@1579
|
41 |
}
|
hegyi@1562
|
42 |
default:
|
hegyi@1562
|
43 |
break;
|
hegyi@1562
|
44 |
}
|
hegyi@1510
|
45 |
|
hegyi@1562
|
46 |
active_item=NULL;
|
hegyi@1562
|
47 |
target_item=NULL;
|
hegyi@1562
|
48 |
active_edge=INVALID;
|
hegyi@1562
|
49 |
active_node=INVALID;
|
hegyi@1551
|
50 |
|
hegyi@1510
|
51 |
|
hegyi@1562
|
52 |
actual_tool=newtool;
|
hegyi@1562
|
53 |
|
hegyi@1562
|
54 |
switch(newtool)
|
hegyi@1562
|
55 |
{
|
hegyi@1562
|
56 |
case MOVE:
|
hegyi@1562
|
57 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
|
hegyi@1562
|
58 |
break;
|
hegyi@1510
|
59 |
|
hegyi@1562
|
60 |
case CREATE_NODE:
|
hegyi@1562
|
61 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false);
|
hegyi@1562
|
62 |
break;
|
hegyi@1510
|
63 |
|
hegyi@1562
|
64 |
case CREATE_EDGE:
|
hegyi@1562
|
65 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false);
|
hegyi@1562
|
66 |
break;
|
hegyi@1510
|
67 |
|
hegyi@1562
|
68 |
case ERASER:
|
hegyi@1562
|
69 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false);
|
hegyi@1562
|
70 |
break;
|
hegyi@1550
|
71 |
|
hegyi@1562
|
72 |
case EDGE_MAP_EDIT:
|
hegyi@1562
|
73 |
grab_focus();
|
hegyi@1562
|
74 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
|
hegyi@1562
|
75 |
break;
|
hegyi@1550
|
76 |
|
hegyi@1562
|
77 |
case NODE_MAP_EDIT:
|
hegyi@1562
|
78 |
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
|
hegyi@1562
|
79 |
break;
|
hegyi@1562
|
80 |
|
hegyi@1562
|
81 |
default:
|
hegyi@1562
|
82 |
break;
|
hegyi@1562
|
83 |
}
|
hegyi@1510
|
84 |
}
|
hegyi@1510
|
85 |
}
|
hegyi@1510
|
86 |
|
hegyi@1524
|
87 |
int GraphDisplayerCanvas::getActualTool()
|
hegyi@1510
|
88 |
{
|
hegyi@1510
|
89 |
return actual_tool;
|
hegyi@1510
|
90 |
}
|
hegyi@1510
|
91 |
|
hegyi@1524
|
92 |
bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e)
|
hegyi@1510
|
93 |
{
|
hegyi@1510
|
94 |
switch(e->type)
|
hegyi@1510
|
95 |
{
|
hegyi@1510
|
96 |
case GDK_BUTTON_PRESS:
|
hegyi@1510
|
97 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@1525
|
98 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
99 |
|
hegyi@1525
|
100 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
101 |
active_node=INVALID;
|
ladanyi@1606
|
102 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
103 |
{
|
hegyi@1510
|
104 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
105 |
{
|
hegyi@1510
|
106 |
active_node=i;
|
hegyi@1510
|
107 |
}
|
hegyi@1510
|
108 |
}
|
hegyi@1510
|
109 |
switch(e->button.button)
|
hegyi@1510
|
110 |
{
|
hegyi@1510
|
111 |
case 3:
|
hegyi@1510
|
112 |
isbutton=3;
|
hegyi@1510
|
113 |
break;
|
hegyi@1510
|
114 |
default:
|
hegyi@1510
|
115 |
isbutton=1;
|
hegyi@1510
|
116 |
break;
|
hegyi@1510
|
117 |
}
|
hegyi@1510
|
118 |
break;
|
hegyi@1510
|
119 |
case GDK_BUTTON_RELEASE:
|
hegyi@1510
|
120 |
isbutton=0;
|
hegyi@1510
|
121 |
active_item=NULL;
|
hegyi@1510
|
122 |
active_node=INVALID;
|
hegyi@1510
|
123 |
break;
|
hegyi@1510
|
124 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
125 |
//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
|
126 |
if(active_node!=INVALID)
|
hegyi@1510
|
127 |
{
|
ladanyi@1606
|
128 |
mapstorage.modified = true;
|
ladanyi@1606
|
129 |
mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
|
hegyi@1510
|
130 |
//new coordinates will be the old values,
|
hegyi@1510
|
131 |
//because the item will be moved to the
|
hegyi@1510
|
132 |
//new coordinate therefore the new movement
|
hegyi@1510
|
133 |
//has to be calculated from here
|
hegyi@1510
|
134 |
|
hegyi@1525
|
135 |
double new_x, new_y;
|
hegyi@1525
|
136 |
|
hegyi@1525
|
137 |
window_to_world (e->motion.x, e->motion.y, new_x, new_y);
|
hegyi@1525
|
138 |
|
hegyi@1525
|
139 |
double dx=new_x-clicked_x;
|
hegyi@1525
|
140 |
double dy=new_y-clicked_y;
|
hegyi@1510
|
141 |
|
hegyi@1512
|
142 |
//repositioning node and its text
|
hegyi@1510
|
143 |
active_item->move(dx, dy);
|
hegyi@1512
|
144 |
nodetextmap[active_node]->move(dx, dy);
|
hegyi@1510
|
145 |
|
hegyi@1525
|
146 |
clicked_x=new_x;
|
hegyi@1525
|
147 |
clicked_y=new_y;
|
hegyi@1510
|
148 |
|
hegyi@1510
|
149 |
//all the edges connected to the moved point has to be redrawn
|
hegyi@1510
|
150 |
EdgeIt ei;
|
hegyi@1510
|
151 |
|
ladanyi@1606
|
152 |
mapstorage.graph.firstOut(ei,active_node);
|
hegyi@1510
|
153 |
|
ladanyi@1606
|
154 |
for(;ei!=INVALID;mapstorage.graph.nextOut(ei))
|
hegyi@1510
|
155 |
{
|
hegyi@1510
|
156 |
Gnome::Canvas::Points coos;
|
hegyi@1510
|
157 |
double x1, x2, y1, y2;
|
hegyi@1510
|
158 |
|
ladanyi@1606
|
159 |
nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
160 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
161 |
|
ladanyi@1606
|
162 |
nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
163 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
164 |
|
hegyi@1510
|
165 |
if(isbutton==3)
|
hegyi@1510
|
166 |
{
|
hegyi@1524
|
167 |
edgesmap[ei]->setPoints(coos);
|
hegyi@1510
|
168 |
}
|
hegyi@1510
|
169 |
else
|
hegyi@1510
|
170 |
{
|
hegyi@1524
|
171 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@1510
|
172 |
}
|
hegyi@1510
|
173 |
|
hegyi@1512
|
174 |
//reposition of edgetext
|
hegyi@1524
|
175 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@1510
|
176 |
text_pos+=(xy<double>(10,10));
|
hegyi@1510
|
177 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@1510
|
178 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@1510
|
179 |
}
|
hegyi@1510
|
180 |
|
ladanyi@1606
|
181 |
mapstorage.graph.firstIn(ei,active_node);
|
ladanyi@1606
|
182 |
for(;ei!=INVALID;mapstorage.graph.nextIn(ei))
|
hegyi@1510
|
183 |
{
|
hegyi@1510
|
184 |
Gnome::Canvas::Points coos;
|
hegyi@1510
|
185 |
double x1, x2, y1, y2;
|
hegyi@1510
|
186 |
|
ladanyi@1606
|
187 |
nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
188 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
189 |
|
ladanyi@1606
|
190 |
nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
|
hegyi@1510
|
191 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
192 |
|
hegyi@1510
|
193 |
if(isbutton==3)
|
hegyi@1510
|
194 |
{
|
hegyi@1524
|
195 |
edgesmap[ei]->setPoints(coos);
|
hegyi@1510
|
196 |
}
|
hegyi@1510
|
197 |
else
|
hegyi@1510
|
198 |
{
|
hegyi@1524
|
199 |
edgesmap[ei]->setPoints(coos,true);
|
hegyi@1510
|
200 |
}
|
hegyi@1510
|
201 |
|
hegyi@1524
|
202 |
xy<double> text_pos=edgesmap[ei]->getArrowPos();
|
hegyi@1510
|
203 |
text_pos+=(xy<double>(10,10));
|
hegyi@1510
|
204 |
edgetextmap[ei]->property_x().set_value(text_pos.x);
|
hegyi@1510
|
205 |
edgetextmap[ei]->property_y().set_value(text_pos.y);
|
hegyi@1510
|
206 |
}
|
hegyi@1510
|
207 |
}
|
hegyi@1510
|
208 |
default: break;
|
hegyi@1510
|
209 |
}
|
hegyi@1510
|
210 |
|
hegyi@1525
|
211 |
return false;
|
hegyi@1510
|
212 |
}
|
hegyi@1510
|
213 |
|
hegyi@1524
|
214 |
bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
|
hegyi@1510
|
215 |
{
|
hegyi@1510
|
216 |
switch(e->type)
|
ladanyi@1645
|
217 |
{
|
ladanyi@1645
|
218 |
//move the new node
|
ladanyi@1645
|
219 |
case GDK_MOTION_NOTIFY:
|
ladanyi@1645
|
220 |
{
|
ladanyi@1645
|
221 |
GdkEvent * generated=new GdkEvent();
|
ladanyi@1645
|
222 |
generated->motion.x=e->motion.x;
|
ladanyi@1645
|
223 |
generated->motion.y=e->motion.y;
|
ladanyi@1645
|
224 |
generated->type=GDK_MOTION_NOTIFY;
|
ladanyi@1645
|
225 |
moveEventHandler(generated);
|
ladanyi@1645
|
226 |
break;
|
ladanyi@1645
|
227 |
}
|
hegyi@1510
|
228 |
|
ladanyi@1645
|
229 |
case GDK_BUTTON_RELEASE:
|
ladanyi@1606
|
230 |
mapstorage.modified = true;
|
ladanyi@1606
|
231 |
|
hegyi@1510
|
232 |
isbutton=1;
|
hegyi@1510
|
233 |
|
alpar@1643
|
234 |
active_node=mapstorage.graph.addNode();
|
hegyi@1510
|
235 |
|
hegyi@1510
|
236 |
//initiating values corresponding to new node in maps
|
hegyi@1510
|
237 |
|
hegyi@1510
|
238 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1510
|
239 |
|
ladanyi@1645
|
240 |
// update coordinates
|
ladanyi@1606
|
241 |
mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
|
ladanyi@1645
|
242 |
|
ladanyi@1645
|
243 |
// update all other maps
|
ladanyi@1645
|
244 |
for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
|
ladanyi@1645
|
245 |
mapstorage.nodemap_storage.begin(); it !=
|
ladanyi@1645
|
246 |
mapstorage.nodemap_storage.end(); ++it)
|
ladanyi@1645
|
247 |
{
|
ladanyi@1646
|
248 |
if ((it->first != "coordinates_x") &&
|
ladanyi@1646
|
249 |
(it->first != "coordinates_y"))
|
ladanyi@1645
|
250 |
{
|
ladanyi@1645
|
251 |
(*(it->second))[active_node] =
|
ladanyi@1645
|
252 |
mapstorage.nodemap_default[it->first];
|
ladanyi@1645
|
253 |
}
|
ladanyi@1645
|
254 |
}
|
ladanyi@1646
|
255 |
// increment the id map's default value
|
ladanyi@1646
|
256 |
mapstorage.nodemap_default["id"] += 1.0;
|
ladanyi@1645
|
257 |
|
ladanyi@1606
|
258 |
nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
|
ladanyi@1645
|
259 |
clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
|
hegyi@1510
|
260 |
active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
|
ladanyi@1645
|
261 |
*(nodesmap[active_node]) <<
|
ladanyi@1645
|
262 |
Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@1645
|
263 |
*(nodesmap[active_node]) <<
|
ladanyi@1645
|
264 |
Gnome::Canvas::Properties::outline_color("black");
|
ladanyi@1645
|
265 |
active_item->raise_to_top();
|
ladanyi@1645
|
266 |
|
hegyi@1510
|
267 |
(nodesmap[active_node])->show();
|
hegyi@1512
|
268 |
|
ladanyi@1606
|
269 |
nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@1645
|
270 |
clicked_x+node_property_defaults[N_RADIUS]+5,
|
ladanyi@1645
|
271 |
clicked_y+node_property_defaults[N_RADIUS]+5, "");
|
hegyi@1512
|
272 |
nodetextmap[active_node]->property_fill_color().set_value("darkblue");
|
ladanyi@1645
|
273 |
nodetextmap[active_node]->raise_to_top();
|
hegyi@1512
|
274 |
|
ladanyi@1606
|
275 |
mapwin.updateNode(active_node);
|
hegyi@1512
|
276 |
|
hegyi@1510
|
277 |
isbutton=0;
|
hegyi@1525
|
278 |
target_item=NULL;
|
hegyi@1510
|
279 |
active_item=NULL;
|
hegyi@1510
|
280 |
active_node=INVALID;
|
ladanyi@1645
|
281 |
|
hegyi@1510
|
282 |
break;
|
hegyi@1510
|
283 |
default:
|
hegyi@1510
|
284 |
break;
|
ladanyi@1645
|
285 |
}
|
hegyi@1510
|
286 |
return false;
|
hegyi@1510
|
287 |
}
|
hegyi@1510
|
288 |
|
hegyi@1524
|
289 |
bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
|
hegyi@1510
|
290 |
{
|
hegyi@1510
|
291 |
switch(e->type)
|
ladanyi@1645
|
292 |
{
|
hegyi@1510
|
293 |
case GDK_BUTTON_PRESS:
|
hegyi@1510
|
294 |
//in edge creation right button has special meaning
|
hegyi@1510
|
295 |
if(e->button.button!=3)
|
ladanyi@1645
|
296 |
{
|
ladanyi@1645
|
297 |
//there is not yet selected node
|
ladanyi@1645
|
298 |
if(active_node==INVALID)
|
ladanyi@1645
|
299 |
{
|
ladanyi@1645
|
300 |
//we mark the location of the event to be able to calculate parameters of dragging
|
hegyi@1525
|
301 |
|
ladanyi@1645
|
302 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
303 |
|
ladanyi@1645
|
304 |
active_item=(get_item_at(clicked_x, clicked_y));
|
ladanyi@1645
|
305 |
active_node=INVALID;
|
ladanyi@1645
|
306 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1645
|
307 |
{
|
ladanyi@1645
|
308 |
if(nodesmap[i]==active_item)
|
ladanyi@1645
|
309 |
{
|
ladanyi@1645
|
310 |
active_node=i;
|
ladanyi@1645
|
311 |
}
|
ladanyi@1645
|
312 |
}
|
ladanyi@1645
|
313 |
//the clicked item is really a node
|
ladanyi@1645
|
314 |
if(active_node!=INVALID)
|
ladanyi@1645
|
315 |
{
|
ladanyi@1645
|
316 |
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
|
ladanyi@1645
|
317 |
isbutton=1;
|
ladanyi@1645
|
318 |
}
|
ladanyi@1645
|
319 |
//clicked item was not a node. It could be e.g. edge.
|
ladanyi@1645
|
320 |
else
|
ladanyi@1645
|
321 |
{
|
ladanyi@1645
|
322 |
active_item=NULL;
|
ladanyi@1645
|
323 |
}
|
ladanyi@1645
|
324 |
}
|
ladanyi@1645
|
325 |
//we only have to do sg. if the mouse button
|
ladanyi@1645
|
326 |
// is pressed already once AND the click was
|
ladanyi@1645
|
327 |
// on a node that was found in the set of
|
ladanyi@1645
|
328 |
//nodes, and now we only search for the second
|
ladanyi@1645
|
329 |
//node
|
ladanyi@1645
|
330 |
else
|
ladanyi@1645
|
331 |
{
|
ladanyi@1645
|
332 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
ladanyi@1645
|
333 |
target_item=(get_item_at(clicked_x, clicked_y));
|
ladanyi@1645
|
334 |
Node target_node=INVALID;
|
ladanyi@1645
|
335 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
ladanyi@1645
|
336 |
{
|
ladanyi@1645
|
337 |
if(nodesmap[i]==target_item)
|
ladanyi@1645
|
338 |
{
|
ladanyi@1645
|
339 |
target_node=i;
|
ladanyi@1645
|
340 |
}
|
ladanyi@1645
|
341 |
}
|
ladanyi@1645
|
342 |
//the clicked item is a node, the edge can be drawn
|
ladanyi@1645
|
343 |
if(target_node!=INVALID)
|
ladanyi@1645
|
344 |
{
|
ladanyi@1645
|
345 |
if(target_node!=active_node)
|
ladanyi@1645
|
346 |
{
|
ladanyi@1645
|
347 |
mapstorage.modified = true;
|
ladanyi@1606
|
348 |
|
ladanyi@1645
|
349 |
*(nodesmap[target_node]) <<
|
ladanyi@1645
|
350 |
Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1510
|
351 |
|
ladanyi@1645
|
352 |
//creating new edge
|
ladanyi@1645
|
353 |
active_edge=mapstorage.graph.addEdge(active_node,
|
ladanyi@1645
|
354 |
target_node);
|
hegyi@1510
|
355 |
|
ladanyi@1646
|
356 |
// update maps
|
ladanyi@1645
|
357 |
for (std::map<std::string,
|
ladanyi@1645
|
358 |
Graph::EdgeMap<double>*>::const_iterator it =
|
ladanyi@1645
|
359 |
mapstorage.edgemap_storage.begin(); it !=
|
ladanyi@1645
|
360 |
mapstorage.edgemap_storage.end(); ++it)
|
ladanyi@1645
|
361 |
{
|
ladanyi@1646
|
362 |
(*(it->second))[active_edge] =
|
ladanyi@1646
|
363 |
mapstorage.edgemap_default[it->first];
|
ladanyi@1645
|
364 |
}
|
ladanyi@1646
|
365 |
// increment the id map's default value
|
ladanyi@1646
|
366 |
mapstorage.edgemap_default["id"] += 1.0;
|
hegyi@1510
|
367 |
|
ladanyi@1645
|
368 |
//calculating coordinates of new edge
|
ladanyi@1645
|
369 |
Gnome::Canvas::Points coos;
|
ladanyi@1645
|
370 |
double x1, x2, y1, y2;
|
hegyi@1510
|
371 |
|
ladanyi@1645
|
372 |
active_item->get_bounds(x1, y1, x2, y2);
|
ladanyi@1645
|
373 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
374 |
|
ladanyi@1645
|
375 |
target_item->get_bounds(x1, y1, x2, y2);
|
ladanyi@1645
|
376 |
coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
|
hegyi@1510
|
377 |
|
ladanyi@1645
|
378 |
//drawing new edge
|
ladanyi@1645
|
379 |
edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,
|
ladanyi@1645
|
380 |
*this);
|
ladanyi@1645
|
381 |
*(edgesmap[active_edge]) <<
|
ladanyi@1645
|
382 |
Gnome::Canvas::Properties::fill_color("green");
|
ladanyi@1645
|
383 |
edgesmap[active_edge]->property_width_pixels().set_value(10);
|
hegyi@1510
|
384 |
|
ladanyi@1645
|
385 |
edgesmap[active_edge]->lower_to_bottom();
|
hegyi@1512
|
386 |
|
ladanyi@1645
|
387 |
//initializing edge-text as well, to empty string
|
ladanyi@1645
|
388 |
xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
|
ladanyi@1645
|
389 |
text_pos+=(xy<double>(10,10));
|
ladanyi@1645
|
390 |
|
ladanyi@1645
|
391 |
edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
|
ladanyi@1645
|
392 |
text_pos.x, text_pos.y, "");
|
ladanyi@1645
|
393 |
edgetextmap[active_edge]->property_fill_color().set_value(
|
ladanyi@1645
|
394 |
"darkgreen");
|
ladanyi@1645
|
395 |
edgetextmap[active_edge]->raise_to_top();
|
ladanyi@1645
|
396 |
|
ladanyi@1645
|
397 |
//updating its properties
|
ladanyi@1645
|
398 |
mapwin.updateEdge(active_edge);
|
ladanyi@1645
|
399 |
}
|
ladanyi@1645
|
400 |
else
|
ladanyi@1645
|
401 |
{
|
ladanyi@1645
|
402 |
target_node=INVALID;
|
ladanyi@1645
|
403 |
std::cerr << "Loop edge is not yet implemented!" << std::endl;
|
ladanyi@1645
|
404 |
}
|
ladanyi@1645
|
405 |
}
|
ladanyi@1645
|
406 |
//clicked item was not a node. it could be an e.g. edge. we do not
|
ladanyi@1645
|
407 |
//deal with it furthermore.
|
ladanyi@1645
|
408 |
else
|
ladanyi@1645
|
409 |
{
|
ladanyi@1645
|
410 |
target_item=NULL;
|
ladanyi@1645
|
411 |
}
|
ladanyi@1645
|
412 |
}
|
ladanyi@1645
|
413 |
}
|
hegyi@1510
|
414 |
break;
|
hegyi@1510
|
415 |
case GDK_BUTTON_RELEASE:
|
hegyi@1510
|
416 |
isbutton=0;
|
hegyi@1510
|
417 |
//we clear settings in two cases
|
hegyi@1510
|
418 |
//1: the edge is ready (target_item has valid value)
|
hegyi@1510
|
419 |
//2: the edge creation is cancelled with right button
|
hegyi@1510
|
420 |
if((target_item)||(e->button.button==3))
|
ladanyi@1645
|
421 |
{
|
ladanyi@1645
|
422 |
if(active_item)
|
ladanyi@1645
|
423 |
{
|
ladanyi@1645
|
424 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@1645
|
425 |
active_item=NULL;
|
ladanyi@1645
|
426 |
}
|
ladanyi@1645
|
427 |
if(target_item)
|
ladanyi@1645
|
428 |
{
|
ladanyi@1645
|
429 |
*target_item << Gnome::Canvas::Properties::fill_color("blue");
|
ladanyi@1645
|
430 |
target_item=NULL;
|
ladanyi@1645
|
431 |
}
|
ladanyi@1645
|
432 |
active_node=INVALID;
|
ladanyi@1645
|
433 |
active_edge=INVALID;
|
ladanyi@1645
|
434 |
}
|
hegyi@1510
|
435 |
break;
|
hegyi@1510
|
436 |
default:
|
hegyi@1510
|
437 |
break;
|
ladanyi@1645
|
438 |
}
|
hegyi@1510
|
439 |
return false;
|
hegyi@1510
|
440 |
}
|
hegyi@1510
|
441 |
|
hegyi@1524
|
442 |
bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e)
|
hegyi@1510
|
443 |
{
|
hegyi@1510
|
444 |
switch(e->type)
|
hegyi@1510
|
445 |
{
|
hegyi@1510
|
446 |
case GDK_BUTTON_PRESS:
|
hegyi@1594
|
447 |
//finding the clicked items
|
hegyi@1525
|
448 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
449 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1510
|
450 |
active_node=INVALID;
|
hegyi@1510
|
451 |
active_edge=INVALID;
|
hegyi@1594
|
452 |
//was it a node?
|
ladanyi@1606
|
453 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
454 |
{
|
hegyi@1510
|
455 |
if(nodesmap[i]==active_item)
|
hegyi@1510
|
456 |
{
|
hegyi@1510
|
457 |
active_node=i;
|
hegyi@1510
|
458 |
}
|
hegyi@1510
|
459 |
}
|
hegyi@1594
|
460 |
//or was it an edge?
|
hegyi@1510
|
461 |
if(active_node==INVALID)
|
hegyi@1510
|
462 |
{
|
ladanyi@1606
|
463 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
464 |
{
|
hegyi@1510
|
465 |
if(edgesmap[i]==active_item)
|
hegyi@1510
|
466 |
{
|
hegyi@1510
|
467 |
active_edge=i;
|
hegyi@1510
|
468 |
}
|
hegyi@1510
|
469 |
}
|
hegyi@1510
|
470 |
}
|
hegyi@1594
|
471 |
|
hegyi@1594
|
472 |
//recolor activated item
|
hegyi@1525
|
473 |
if(active_item)
|
hegyi@1525
|
474 |
{
|
hegyi@1525
|
475 |
*active_item << Gnome::Canvas::Properties::fill_color("red");
|
hegyi@1525
|
476 |
}
|
hegyi@1510
|
477 |
break;
|
hegyi@1510
|
478 |
|
hegyi@1510
|
479 |
case GDK_BUTTON_RELEASE:
|
hegyi@1525
|
480 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1525
|
481 |
if(active_item)
|
hegyi@1510
|
482 |
{
|
hegyi@1594
|
483 |
//the cursor was not moved since pressing it
|
hegyi@1525
|
484 |
if( active_item == ( get_item_at (clicked_x, clicked_y) ) )
|
hegyi@1510
|
485 |
{
|
hegyi@1594
|
486 |
//a node was found
|
hegyi@1525
|
487 |
if(active_node!=INVALID)
|
hegyi@1525
|
488 |
{
|
ladanyi@1606
|
489 |
mapstorage.modified = true;
|
hegyi@1510
|
490 |
|
hegyi@1525
|
491 |
//collecting edges to delete
|
hegyi@1525
|
492 |
EdgeIt e;
|
hegyi@1525
|
493 |
std::set<Graph::Edge> edges_to_delete;
|
hegyi@1510
|
494 |
|
ladanyi@1606
|
495 |
mapstorage.graph.firstOut(e,active_node);
|
ladanyi@1606
|
496 |
for(;e!=INVALID;mapstorage.graph.nextOut(e))
|
hegyi@1525
|
497 |
{
|
hegyi@1525
|
498 |
edges_to_delete.insert(e);
|
hegyi@1525
|
499 |
}
|
hegyi@1525
|
500 |
|
ladanyi@1606
|
501 |
mapstorage.graph.firstIn(e,active_node);
|
ladanyi@1606
|
502 |
for(;e!=INVALID;mapstorage.graph.nextIn(e))
|
hegyi@1525
|
503 |
{
|
hegyi@1525
|
504 |
edges_to_delete.insert(e);
|
hegyi@1525
|
505 |
}
|
hegyi@1525
|
506 |
|
hegyi@1525
|
507 |
//deleting collected edges
|
hegyi@1525
|
508 |
for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++)
|
hegyi@1525
|
509 |
{
|
hegyi@1525
|
510 |
deleteItem(*edge_set_it);
|
hegyi@1525
|
511 |
}
|
hegyi@1525
|
512 |
deleteItem(active_node);
|
hegyi@1525
|
513 |
}
|
hegyi@1525
|
514 |
//a simple edge was chosen
|
hegyi@1525
|
515 |
else
|
hegyi@1510
|
516 |
{
|
hegyi@1525
|
517 |
deleteItem(active_edge);
|
hegyi@1510
|
518 |
}
|
hegyi@1510
|
519 |
}
|
hegyi@1525
|
520 |
//pointer was moved, deletion is cancelled
|
hegyi@1510
|
521 |
else
|
hegyi@1510
|
522 |
{
|
hegyi@1525
|
523 |
if(active_node!=INVALID)
|
hegyi@1525
|
524 |
{
|
hegyi@1525
|
525 |
*active_item << Gnome::Canvas::Properties::fill_color("blue");
|
hegyi@1525
|
526 |
}
|
hegyi@1525
|
527 |
else
|
hegyi@1525
|
528 |
{
|
hegyi@1525
|
529 |
*active_item << Gnome::Canvas::Properties::fill_color("green");
|
hegyi@1525
|
530 |
}
|
hegyi@1510
|
531 |
}
|
hegyi@1510
|
532 |
}
|
hegyi@1510
|
533 |
//reseting datas
|
hegyi@1510
|
534 |
active_item=NULL;
|
hegyi@1510
|
535 |
active_edge=INVALID;
|
hegyi@1510
|
536 |
active_node=INVALID;
|
hegyi@1510
|
537 |
break;
|
hegyi@1510
|
538 |
|
hegyi@1510
|
539 |
case GDK_MOTION_NOTIFY:
|
hegyi@1510
|
540 |
break;
|
hegyi@1510
|
541 |
|
hegyi@1510
|
542 |
default:
|
hegyi@1510
|
543 |
break;
|
hegyi@1510
|
544 |
}
|
hegyi@1525
|
545 |
return false;
|
hegyi@1510
|
546 |
}
|
hegyi@1510
|
547 |
|
hegyi@1550
|
548 |
bool GraphDisplayerCanvas::edgeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
549 |
{
|
hegyi@1599
|
550 |
if(actual_tool==EDGE_MAP_EDIT)
|
hegyi@1550
|
551 |
{
|
hegyi@1599
|
552 |
switch(e->type)
|
hegyi@1599
|
553 |
{
|
hegyi@1599
|
554 |
case GDK_KEY_PRESS:
|
hegyi@1599
|
555 |
//for Escape or Enter hide the displayed widget
|
hegyi@1599
|
556 |
{
|
hegyi@1599
|
557 |
nodeMapEditEventHandler(e);
|
hegyi@1599
|
558 |
break;
|
hegyi@1599
|
559 |
}
|
hegyi@1599
|
560 |
case GDK_BUTTON_PRESS:
|
hegyi@1599
|
561 |
//If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
|
hegyi@1599
|
562 |
{
|
hegyi@1599
|
563 |
//for determine, whether it was an edge
|
alpar@1643
|
564 |
Edge clicked_edge=INVALID;
|
hegyi@1594
|
565 |
|
hegyi@1599
|
566 |
//find the activated item between texts
|
hegyi@1599
|
567 |
active_item=(get_item_at(e->button.x, e->button.y));
|
ladanyi@1606
|
568 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1562
|
569 |
{
|
hegyi@1599
|
570 |
if(edgetextmap[i]==active_item)
|
hegyi@1599
|
571 |
{
|
hegyi@1599
|
572 |
clicked_edge=i;
|
hegyi@1599
|
573 |
}
|
hegyi@1562
|
574 |
}
|
hegyi@1599
|
575 |
|
hegyi@1599
|
576 |
//if it was not between texts, search for it between edges
|
hegyi@1599
|
577 |
if(clicked_edge==INVALID)
|
hegyi@1562
|
578 |
{
|
hegyi@1599
|
579 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1599
|
580 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1599
|
581 |
|
ladanyi@1606
|
582 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1599
|
583 |
{
|
hegyi@1599
|
584 |
//at the same time only one can be active
|
hegyi@1599
|
585 |
if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
|
hegyi@1599
|
586 |
{
|
hegyi@1599
|
587 |
clicked_edge=i;
|
hegyi@1599
|
588 |
}
|
hegyi@1599
|
589 |
}
|
hegyi@1599
|
590 |
}
|
hegyi@1599
|
591 |
//if it was really an edge...
|
hegyi@1599
|
592 |
if(clicked_edge!=INVALID)
|
hegyi@1599
|
593 |
{
|
ladanyi@1645
|
594 |
// the id map is not editable
|
ladanyi@1645
|
595 |
if (nodemap_to_edit == "id") return 0;
|
hegyi@1599
|
596 |
//If there is already edited edge, it has to be saved first
|
hegyi@1599
|
597 |
if(entrywidget.is_visible())
|
hegyi@1599
|
598 |
{
|
hegyi@1599
|
599 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1599
|
600 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1599
|
601 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1599
|
602 |
entryWidgetChangeHandler(generated);
|
hegyi@1599
|
603 |
}
|
hegyi@1599
|
604 |
//If the previous value could be saved, we can go further, otherwise not
|
hegyi@1599
|
605 |
if(!entrywidget.is_visible())
|
hegyi@1599
|
606 |
{
|
hegyi@1599
|
607 |
//and there is activated map
|
hegyi@1599
|
608 |
if(edgetextmap[clicked_edge]->property_text().get_value()!="")
|
hegyi@1599
|
609 |
{
|
hegyi@1599
|
610 |
//activate the general variable for it
|
hegyi@1599
|
611 |
active_edge=clicked_edge;
|
hegyi@1599
|
612 |
//delete visible widget if there is
|
hegyi@1599
|
613 |
if(canvasentrywidget)
|
hegyi@1599
|
614 |
{
|
hegyi@1599
|
615 |
delete(canvasentrywidget);
|
hegyi@1599
|
616 |
}
|
hegyi@1599
|
617 |
|
hegyi@1599
|
618 |
//initialize the entry
|
hegyi@1599
|
619 |
entrywidget.show();
|
hegyi@1599
|
620 |
|
hegyi@1599
|
621 |
//fill in the correct value
|
hegyi@1599
|
622 |
entrywidget.set_text(edgetextmap[active_edge]->property_text().get_value());
|
hegyi@1599
|
623 |
|
hegyi@1599
|
624 |
//replace and resize the entry to the activated edge and put it in a Canvas::Widget to be able to display it on gdc
|
hegyi@1599
|
625 |
xy<double> entry_coos;
|
hegyi@1599
|
626 |
entry_coos.x=(edgetextmap[active_edge])->property_x().get_value();
|
hegyi@1599
|
627 |
entry_coos.x-=edgetextmap[active_edge]->property_text_width().get_value()/2;
|
hegyi@1599
|
628 |
entry_coos.y=(edgetextmap[active_edge])->property_y().get_value();
|
hegyi@1599
|
629 |
entry_coos.y-=edgetextmap[active_edge]->property_text_height().get_value()*1.5/2;
|
hegyi@1599
|
630 |
canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
|
hegyi@1599
|
631 |
canvasentrywidget->property_width().set_value(edgetextmap[active_edge]->property_text_width().get_value()*4);
|
hegyi@1599
|
632 |
canvasentrywidget->property_height().set_value(edgetextmap[active_edge]->property_text_height().get_value()*1.5);
|
hegyi@1614
|
633 |
|
hegyi@1614
|
634 |
//setting the focus to newly created widget
|
hegyi@1614
|
635 |
parentwin->set_focus(entrywidget);
|
hegyi@1614
|
636 |
parentwin->activate_focus();
|
hegyi@1599
|
637 |
}
|
hegyi@1599
|
638 |
}
|
hegyi@1599
|
639 |
}
|
hegyi@1599
|
640 |
//if it was not an edge...
|
hegyi@1599
|
641 |
else
|
hegyi@1599
|
642 |
{
|
hegyi@1599
|
643 |
//In this case the click did not happen on an edge
|
hegyi@1599
|
644 |
//if there is visible entry we save the value in it
|
hegyi@1599
|
645 |
//we pretend like an Enter was presse din the Entry widget
|
hegyi@1594
|
646 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1594
|
647 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1594
|
648 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1594
|
649 |
entryWidgetChangeHandler(generated);
|
hegyi@1594
|
650 |
}
|
hegyi@1599
|
651 |
break;
|
hegyi@1562
|
652 |
}
|
hegyi@1599
|
653 |
default:
|
hegyi@1599
|
654 |
break;
|
hegyi@1599
|
655 |
}
|
hegyi@1550
|
656 |
}
|
hegyi@1550
|
657 |
return false;
|
hegyi@1550
|
658 |
}
|
hegyi@1550
|
659 |
|
hegyi@1550
|
660 |
bool GraphDisplayerCanvas::nodeMapEditEventHandler(GdkEvent* e)
|
hegyi@1550
|
661 |
{
|
hegyi@1599
|
662 |
if(actual_tool==NODE_MAP_EDIT)
|
hegyi@1579
|
663 |
{
|
hegyi@1599
|
664 |
switch(e->type)
|
hegyi@1599
|
665 |
{
|
hegyi@1599
|
666 |
case GDK_KEY_PRESS:
|
hegyi@1599
|
667 |
//for Escape or Enter hide the displayed widget
|
hegyi@1579
|
668 |
{
|
hegyi@1599
|
669 |
switch(((GdkEventKey*)e)->keyval)
|
hegyi@1599
|
670 |
{
|
hegyi@1599
|
671 |
case GDK_Escape:
|
hegyi@1599
|
672 |
entrywidget.hide();
|
hegyi@1599
|
673 |
break;
|
hegyi@1599
|
674 |
case GDK_Return:
|
hegyi@1599
|
675 |
case GDK_KP_Enter:
|
hegyi@1599
|
676 |
entrywidget.hide();
|
hegyi@1599
|
677 |
break;
|
hegyi@1599
|
678 |
default:
|
hegyi@1599
|
679 |
break;
|
hegyi@1599
|
680 |
}
|
hegyi@1599
|
681 |
|
hegyi@1579
|
682 |
break;
|
hegyi@1579
|
683 |
}
|
hegyi@1599
|
684 |
case GDK_BUTTON_PRESS:
|
hegyi@1599
|
685 |
//If the click happened on an edge we place the entrywidget there and fill in the value of the activated map at that edge.
|
hegyi@1599
|
686 |
{
|
hegyi@1599
|
687 |
//for determine, whether it was a node
|
alpar@1643
|
688 |
Node clicked_node=INVALID;
|
hegyi@1594
|
689 |
|
hegyi@1599
|
690 |
//find the activated item between texts
|
hegyi@1599
|
691 |
active_item=(get_item_at(e->button.x, e->button.y));
|
ladanyi@1606
|
692 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1579
|
693 |
{
|
hegyi@1599
|
694 |
//at the same time only one can be active
|
hegyi@1599
|
695 |
if(nodetextmap[i]==active_item)
|
hegyi@1599
|
696 |
{
|
hegyi@1599
|
697 |
clicked_node=i;
|
hegyi@1599
|
698 |
}
|
hegyi@1579
|
699 |
}
|
hegyi@1594
|
700 |
|
hegyi@1599
|
701 |
//if there was not, search for it between nodes
|
hegyi@1599
|
702 |
if(clicked_node==INVALID)
|
hegyi@1579
|
703 |
{
|
hegyi@1599
|
704 |
window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
|
hegyi@1599
|
705 |
active_item=(get_item_at(clicked_x, clicked_y));
|
hegyi@1599
|
706 |
|
ladanyi@1606
|
707 |
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1599
|
708 |
{
|
hegyi@1599
|
709 |
//at the same time only one can be active
|
hegyi@1599
|
710 |
if(nodesmap[i]==active_item)
|
hegyi@1599
|
711 |
{
|
hegyi@1599
|
712 |
clicked_node=i;
|
hegyi@1599
|
713 |
}
|
hegyi@1599
|
714 |
}
|
hegyi@1599
|
715 |
}
|
hegyi@1599
|
716 |
//if it was really an edge...
|
hegyi@1599
|
717 |
if(clicked_node!=INVALID)
|
hegyi@1599
|
718 |
{
|
ladanyi@1645
|
719 |
// the id map is not editable
|
ladanyi@1645
|
720 |
if (nodemap_to_edit == "id") return 0;
|
hegyi@1599
|
721 |
//If there is already edited edge, it has to be saved first
|
hegyi@1599
|
722 |
if(entrywidget.is_visible())
|
hegyi@1599
|
723 |
{
|
hegyi@1599
|
724 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1599
|
725 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1599
|
726 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1599
|
727 |
entryWidgetChangeHandler(generated);
|
hegyi@1599
|
728 |
}
|
hegyi@1599
|
729 |
//If the previous value could be saved, we can go further, otherwise not
|
hegyi@1599
|
730 |
if(!entrywidget.is_visible())
|
hegyi@1599
|
731 |
{
|
hegyi@1599
|
732 |
//and there is activated map
|
hegyi@1599
|
733 |
if(nodetextmap[clicked_node]->property_text().get_value()!="")
|
hegyi@1599
|
734 |
{
|
hegyi@1599
|
735 |
//activate the general variable for it
|
hegyi@1599
|
736 |
active_node=clicked_node;
|
hegyi@1599
|
737 |
//delete visible widget if there is
|
hegyi@1599
|
738 |
if(canvasentrywidget)
|
hegyi@1599
|
739 |
{
|
hegyi@1599
|
740 |
delete(canvasentrywidget);
|
hegyi@1599
|
741 |
}
|
hegyi@1599
|
742 |
|
hegyi@1599
|
743 |
//initialize the entry
|
hegyi@1599
|
744 |
entrywidget.show();
|
hegyi@1599
|
745 |
|
hegyi@1599
|
746 |
//fill in the correct value
|
hegyi@1599
|
747 |
entrywidget.set_text(nodetextmap[active_node]->property_text().get_value());
|
hegyi@1599
|
748 |
|
hegyi@1599
|
749 |
//replace and resize the entry to the activated node and put it in a Canvas::Widget to be able to display it on gdc
|
hegyi@1599
|
750 |
xy<double> entry_coos;
|
hegyi@1599
|
751 |
entry_coos.x=(nodetextmap[active_node])->property_x().get_value();
|
hegyi@1599
|
752 |
entry_coos.x-=nodetextmap[active_node]->property_text_width().get_value()/2;
|
hegyi@1599
|
753 |
entry_coos.y=(nodetextmap[active_node])->property_y().get_value();
|
hegyi@1599
|
754 |
entry_coos.y-=nodetextmap[active_node]->property_text_height().get_value()*1.5/2;
|
hegyi@1599
|
755 |
canvasentrywidget=new Gnome::Canvas::Widget(displayed_graph, entry_coos.x, entry_coos.y, entrywidget);
|
hegyi@1599
|
756 |
canvasentrywidget->property_width().set_value(nodetextmap[active_node]->property_text_width().get_value()*4);
|
hegyi@1599
|
757 |
canvasentrywidget->property_height().set_value(nodetextmap[active_node]->property_text_height().get_value()*1.5);
|
hegyi@1599
|
758 |
}
|
hegyi@1599
|
759 |
}
|
hegyi@1599
|
760 |
}
|
hegyi@1599
|
761 |
//if it was not an edge...
|
hegyi@1599
|
762 |
else
|
hegyi@1599
|
763 |
{
|
hegyi@1599
|
764 |
//In this case the click did not happen on an edge
|
hegyi@1599
|
765 |
//if there is visible entry we save the value in it
|
hegyi@1599
|
766 |
//we pretend like an Enter was presse din the Entry widget
|
hegyi@1579
|
767 |
GdkEvent * generated=new GdkEvent();
|
hegyi@1579
|
768 |
generated->type=GDK_KEY_PRESS;
|
hegyi@1579
|
769 |
((GdkEventKey*)generated)->keyval=GDK_KP_Enter;
|
hegyi@1579
|
770 |
entryWidgetChangeHandler(generated);
|
hegyi@1579
|
771 |
}
|
hegyi@1599
|
772 |
break;
|
hegyi@1579
|
773 |
}
|
hegyi@1599
|
774 |
default:
|
hegyi@1599
|
775 |
break;
|
hegyi@1599
|
776 |
}
|
hegyi@1579
|
777 |
}
|
hegyi@1579
|
778 |
return false;
|
hegyi@1550
|
779 |
}
|
hegyi@1550
|
780 |
|
hegyi@1562
|
781 |
bool GraphDisplayerCanvas::entryWidgetChangeHandler(GdkEvent* e)
|
hegyi@1562
|
782 |
{
|
hegyi@1579
|
783 |
if(entrywidget.is_visible())
|
hegyi@1579
|
784 |
{
|
hegyi@1579
|
785 |
if(e->type==GDK_KEY_PRESS)
|
hegyi@1579
|
786 |
{
|
hegyi@1579
|
787 |
switch(((GdkEventKey*)e)->keyval)
|
hegyi@1579
|
788 |
{
|
hegyi@1579
|
789 |
case GDK_Escape:
|
hegyi@1579
|
790 |
entrywidget.hide();
|
hegyi@1579
|
791 |
break;
|
hegyi@1579
|
792 |
case GDK_KP_Enter:
|
hegyi@1579
|
793 |
case GDK_Return:
|
hegyi@1579
|
794 |
{
|
hegyi@1594
|
795 |
//these variables check whether the text in the entry is valid
|
hegyi@1592
|
796 |
bool valid_double=true;
|
hegyi@1592
|
797 |
int point_num=0;
|
hegyi@1594
|
798 |
|
hegyi@1594
|
799 |
//getting the value from the entry and converting it to double
|
hegyi@1592
|
800 |
Glib::ustring mapvalue_str = entrywidget.get_text();
|
hegyi@1579
|
801 |
|
hegyi@1592
|
802 |
char * mapvalue_ch=new char [mapvalue_str.length()];
|
hegyi@1592
|
803 |
for(int i=0;i<(int)(mapvalue_str.length());i++)
|
hegyi@1579
|
804 |
{
|
hegyi@1592
|
805 |
if(((mapvalue_str[i]<'0')||(mapvalue_str[i]>'9'))&&(mapvalue_str[i]!='.'))
|
hegyi@1579
|
806 |
{
|
hegyi@1592
|
807 |
valid_double=false;
|
hegyi@1579
|
808 |
}
|
hegyi@1579
|
809 |
else
|
hegyi@1579
|
810 |
{
|
hegyi@1592
|
811 |
if(mapvalue_str[i]=='.')
|
hegyi@1592
|
812 |
{
|
hegyi@1592
|
813 |
point_num++;
|
hegyi@1592
|
814 |
}
|
hegyi@1579
|
815 |
}
|
hegyi@1592
|
816 |
mapvalue_ch[i]=mapvalue_str[i];
|
hegyi@1579
|
817 |
}
|
hegyi@1596
|
818 |
|
hegyi@1594
|
819 |
//if the text in the entry was correct
|
hegyi@1592
|
820 |
if((point_num<=1)&&(valid_double))
|
hegyi@1579
|
821 |
{
|
hegyi@1596
|
822 |
double mapvalue_d=atof(mapvalue_ch);
|
hegyi@1596
|
823 |
|
hegyi@1596
|
824 |
//reconvert the double to string for the correct format
|
hegyi@1596
|
825 |
std::ostringstream ostr;
|
hegyi@1596
|
826 |
ostr << mapvalue_d;
|
hegyi@1596
|
827 |
|
hegyi@1594
|
828 |
//save the value to the correct place
|
hegyi@1579
|
829 |
switch(actual_tool)
|
hegyi@1579
|
830 |
{
|
hegyi@1579
|
831 |
case EDGE_MAP_EDIT:
|
hegyi@1596
|
832 |
edgetextmap[active_edge]->property_text().set_value(ostr.str());
|
hegyi@1592
|
833 |
(*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
|
ladanyi@1606
|
834 |
mapwin.updateEdge(active_edge);
|
hegyi@1579
|
835 |
break;
|
hegyi@1579
|
836 |
case NODE_MAP_EDIT:
|
hegyi@1596
|
837 |
nodetextmap[active_node]->property_text().set_value(ostr.str());
|
hegyi@1592
|
838 |
(*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
|
ladanyi@1606
|
839 |
mapwin.updateNode(active_node);
|
hegyi@1579
|
840 |
break;
|
hegyi@1579
|
841 |
default:
|
hegyi@1579
|
842 |
break;
|
hegyi@1579
|
843 |
}
|
hegyi@1579
|
844 |
entrywidget.hide();
|
hegyi@1579
|
845 |
}
|
hegyi@1594
|
846 |
//the text in the entry was not correct for a double
|
hegyi@1579
|
847 |
else
|
hegyi@1579
|
848 |
{
|
hegyi@1599
|
849 |
std::cerr << "ERROR: only handling of double values is implemented yet!" << std::endl;
|
hegyi@1579
|
850 |
}
|
hegyi@1579
|
851 |
|
hegyi@1579
|
852 |
break;
|
hegyi@1579
|
853 |
}
|
hegyi@1579
|
854 |
default:
|
hegyi@1579
|
855 |
break;
|
hegyi@1579
|
856 |
}
|
hegyi@1579
|
857 |
}
|
hegyi@1579
|
858 |
}
|
hegyi@1562
|
859 |
return false;
|
hegyi@1562
|
860 |
}
|
hegyi@1562
|
861 |
|
alpar@1643
|
862 |
void GraphDisplayerCanvas::deleteItem(Node node_to_delete)
|
hegyi@1510
|
863 |
{
|
hegyi@1512
|
864 |
delete(nodetextmap[node_to_delete]);
|
hegyi@1510
|
865 |
delete(nodesmap[node_to_delete]);
|
ladanyi@1606
|
866 |
mapstorage.graph.erase(node_to_delete);
|
hegyi@1510
|
867 |
}
|
hegyi@1510
|
868 |
|
alpar@1643
|
869 |
void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete)
|
hegyi@1510
|
870 |
{
|
hegyi@1512
|
871 |
delete(edgetextmap[edge_to_delete]);
|
hegyi@1510
|
872 |
delete(edgesmap[edge_to_delete]);
|
ladanyi@1606
|
873 |
mapstorage.graph.erase(edge_to_delete);
|
hegyi@1510
|
874 |
}
|
hegyi@1510
|
875 |
|
hegyi@1524
|
876 |
void GraphDisplayerCanvas::textReposition(xy<double> new_place)
|
hegyi@1510
|
877 |
{
|
hegyi@1510
|
878 |
new_place+=(xy<double>(10,10));
|
hegyi@1579
|
879 |
edgetextmap[forming_edge]->property_x().set_value(new_place.x);
|
hegyi@1579
|
880 |
edgetextmap[forming_edge]->property_y().set_value(new_place.y);
|
hegyi@1510
|
881 |
}
|
hegyi@1510
|
882 |
|
hegyi@1524
|
883 |
void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on)
|
hegyi@1510
|
884 |
{
|
hegyi@1510
|
885 |
if(on)
|
hegyi@1510
|
886 |
{
|
hegyi@1579
|
887 |
if(forming_edge!=INVALID)
|
hegyi@1510
|
888 |
{
|
hegyi@1599
|
889 |
std::cerr << "ERROR!!!! Valid edge found!" << std::endl;
|
hegyi@1510
|
890 |
}
|
hegyi@1510
|
891 |
else
|
hegyi@1510
|
892 |
{
|
ladanyi@1606
|
893 |
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
|
hegyi@1510
|
894 |
{
|
hegyi@1510
|
895 |
if(edgesmap[i]==active_bre)
|
hegyi@1510
|
896 |
{
|
hegyi@1579
|
897 |
forming_edge=i;
|
hegyi@1510
|
898 |
}
|
hegyi@1510
|
899 |
}
|
hegyi@1510
|
900 |
}
|
hegyi@1510
|
901 |
}
|
hegyi@1510
|
902 |
else
|
hegyi@1510
|
903 |
{
|
hegyi@1579
|
904 |
if(forming_edge!=INVALID)
|
hegyi@1510
|
905 |
{
|
hegyi@1579
|
906 |
forming_edge=INVALID;
|
hegyi@1510
|
907 |
}
|
hegyi@1510
|
908 |
else
|
hegyi@1510
|
909 |
{
|
hegyi@1599
|
910 |
std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
|
hegyi@1510
|
911 |
}
|
hegyi@1510
|
912 |
}
|
hegyi@1510
|
913 |
|
hegyi@1510
|
914 |
}
|
hegyi@1550
|
915 |
|
hegyi@1597
|
916 |
int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
|
hegyi@1585
|
917 |
{
|
hegyi@1594
|
918 |
//create the new map
|
ladanyi@1606
|
919 |
Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
|
hegyi@1597
|
920 |
|
hegyi@1597
|
921 |
//if addition was not successful addEdgeMap returns one.
|
hegyi@1597
|
922 |
//cause can be that there is already a map named like the new one
|
ladanyi@1645
|
923 |
if(mapstorage.addEdgeMap(mapname,emptr, default_value))
|
hegyi@1597
|
924 |
{
|
hegyi@1597
|
925 |
return 1;
|
hegyi@1597
|
926 |
}
|
hegyi@1597
|
927 |
|
hegyi@1594
|
928 |
|
hegyi@1594
|
929 |
//add it to the list of the displayable maps
|
ladanyi@1606
|
930 |
mapwin.registerNewEdgeMap(mapname);
|
hegyi@1594
|
931 |
|
hegyi@1594
|
932 |
//display it
|
hegyi@1592
|
933 |
changeEdgeText(mapname);
|
hegyi@1597
|
934 |
|
hegyi@1597
|
935 |
return 0;
|
hegyi@1585
|
936 |
}
|
hegyi@1585
|
937 |
|
hegyi@1597
|
938 |
int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
|
hegyi@1585
|
939 |
{
|
hegyi@1594
|
940 |
//create the new map
|
ladanyi@1606
|
941 |
Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
|
hegyi@1597
|
942 |
|
hegyi@1597
|
943 |
//if addition was not successful addNodeMap returns one.
|
hegyi@1597
|
944 |
//cause can be that there is already a map named like the new one
|
ladanyi@1645
|
945 |
if(mapstorage.addNodeMap(mapname,emptr, default_value))
|
hegyi@1597
|
946 |
{
|
hegyi@1597
|
947 |
return 1;
|
hegyi@1597
|
948 |
}
|
hegyi@1594
|
949 |
|
hegyi@1594
|
950 |
//add it to the list of the displayable maps
|
ladanyi@1606
|
951 |
mapwin.registerNewNodeMap(mapname);
|
hegyi@1594
|
952 |
|
hegyi@1594
|
953 |
//display it
|
hegyi@1592
|
954 |
changeNodeText(mapname);
|
hegyi@1597
|
955 |
|
hegyi@1597
|
956 |
return 0;
|
hegyi@1585
|
957 |
}
|
hegyi@1585
|
958 |
|