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