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