18 if(actual_tool==CREATE_EDGE) |
18 if(actual_tool==CREATE_EDGE) |
19 { |
19 { |
20 GdkEvent * generated=new GdkEvent(); |
20 GdkEvent * generated=new GdkEvent(); |
21 generated->type=GDK_BUTTON_RELEASE; |
21 generated->type=GDK_BUTTON_RELEASE; |
22 generated->button.button=3; |
22 generated->button.button=3; |
23 create_edge_event_handler(generated); |
23 createEdgeEventHandler(generated); |
24 } |
24 } |
25 |
25 |
26 actual_tool=newtool; |
26 actual_tool=newtool; |
27 |
27 |
28 switch(newtool) |
28 switch(newtool) |
29 { |
29 { |
30 case MOVE: |
30 case MOVE: |
31 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false); |
31 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); |
32 break; |
32 break; |
33 |
33 |
34 //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group |
34 //it has to assigned to canvas, because all the canvas has to be monitored, not only the elements of the already drawn group |
35 case CREATE_NODE: |
35 case CREATE_NODE: |
36 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false); |
36 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createNodeEventHandler), false); |
37 break; |
37 break; |
38 |
38 |
39 case CREATE_EDGE: |
39 case CREATE_EDGE: |
40 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false); |
40 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::createEdgeEventHandler), false); |
41 break; |
41 break; |
42 |
42 |
43 case ERASER: |
43 case ERASER: |
44 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraser_event_handler), false); |
44 actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::eraserEventHandler), false); |
45 break; |
45 break; |
46 |
46 |
47 default: |
47 default: |
48 break; |
48 break; |
49 } |
49 } |
50 } |
50 } |
51 |
51 |
52 int GraphDisplayerCanvas::get_actual_tool() |
52 int GraphDisplayerCanvas::getActualTool() |
53 { |
53 { |
54 return actual_tool; |
54 return actual_tool; |
55 } |
55 } |
56 |
56 |
57 bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e) |
57 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e) |
58 { |
58 { |
59 switch(e->type) |
59 switch(e->type) |
60 { |
60 { |
61 case GDK_BUTTON_PRESS: |
61 case GDK_BUTTON_PRESS: |
62 //we mark the location of the event to be able to calculate parameters of dragging |
62 //we mark the location of the event to be able to calculate parameters of dragging |
122 nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); |
122 nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); |
123 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
123 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
124 |
124 |
125 if(isbutton==3) |
125 if(isbutton==3) |
126 { |
126 { |
127 edgesmap[ei]->set_points(coos); |
127 edgesmap[ei]->setPoints(coos); |
128 } |
128 } |
129 else |
129 else |
130 { |
130 { |
131 edgesmap[ei]->set_points(coos,true); |
131 edgesmap[ei]->setPoints(coos,true); |
132 } |
132 } |
133 |
133 |
134 //reposition of edgetext |
134 //reposition of edgetext |
135 xy<double> text_pos=edgesmap[ei]->get_arrow_pos(); |
135 xy<double> text_pos=edgesmap[ei]->getArrowPos(); |
136 text_pos+=(xy<double>(10,10)); |
136 text_pos+=(xy<double>(10,10)); |
137 edgetextmap[ei]->property_x().set_value(text_pos.x); |
137 edgetextmap[ei]->property_x().set_value(text_pos.x); |
138 edgetextmap[ei]->property_y().set_value(text_pos.y); |
138 edgetextmap[ei]->property_y().set_value(text_pos.y); |
139 } |
139 } |
140 |
140 |
150 nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); |
150 nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2); |
151 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
151 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
152 |
152 |
153 if(isbutton==3) |
153 if(isbutton==3) |
154 { |
154 { |
155 edgesmap[ei]->set_points(coos); |
155 edgesmap[ei]->setPoints(coos); |
156 } |
156 } |
157 else |
157 else |
158 { |
158 { |
159 edgesmap[ei]->set_points(coos,true); |
159 edgesmap[ei]->setPoints(coos,true); |
160 } |
160 } |
161 |
161 |
162 xy<double> text_pos=edgesmap[ei]->get_arrow_pos(); |
162 xy<double> text_pos=edgesmap[ei]->getArrowPos(); |
163 text_pos+=(xy<double>(10,10)); |
163 text_pos+=(xy<double>(10,10)); |
164 edgetextmap[ei]->property_x().set_value(text_pos.x); |
164 edgetextmap[ei]->property_x().set_value(text_pos.x); |
165 edgetextmap[ei]->property_y().set_value(text_pos.y); |
165 edgetextmap[ei]->property_y().set_value(text_pos.y); |
166 } |
166 } |
167 } |
167 } |
194 (nodesmap[active_node])->show(); |
194 (nodesmap[active_node])->show(); |
195 |
195 |
196 nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, clicked_x+node_property_defaults[N_RADIUS]+5, clicked_y+node_property_defaults[N_RADIUS]+5, ""); |
196 nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, clicked_x+node_property_defaults[N_RADIUS]+5, clicked_y+node_property_defaults[N_RADIUS]+5, ""); |
197 nodetextmap[active_node]->property_fill_color().set_value("darkblue"); |
197 nodetextmap[active_node]->property_fill_color().set_value("darkblue"); |
198 |
198 |
199 mapwin->update_node(active_node); |
199 mapwin->updateNode(active_node); |
200 |
200 |
201 break; |
201 break; |
202 |
202 |
203 //move the new node |
203 //move the new node |
204 case GDK_MOTION_NOTIFY: |
204 case GDK_MOTION_NOTIFY: |
207 GdkEvent * generated=new GdkEvent(); |
207 GdkEvent * generated=new GdkEvent(); |
208 window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y); |
208 window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y); |
209 generated->motion.x=world_motion_x; |
209 generated->motion.x=world_motion_x; |
210 generated->motion.y=world_motion_y; |
210 generated->motion.y=world_motion_y; |
211 generated->type=GDK_MOTION_NOTIFY; |
211 generated->type=GDK_MOTION_NOTIFY; |
212 move_event_handler(generated); |
212 moveEventHandler(generated); |
213 break; |
213 break; |
214 } |
214 } |
215 |
215 |
216 //finalize the new node |
216 //finalize the new node |
217 case GDK_BUTTON_RELEASE: |
217 case GDK_BUTTON_RELEASE: |
287 |
287 |
288 //creating new edge |
288 //creating new edge |
289 active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); |
289 active_edge=EdgeIt(g,g.addEdge(active_node, target_node)); |
290 |
290 |
291 //initiating values corresponding to new edge in maps |
291 //initiating values corresponding to new edge in maps |
292 mapstorage.init_maps_for_edge(active_edge); |
292 mapstorage.initMapsForEdge(active_edge); |
293 |
293 |
294 //calculating coordinates of new edge |
294 //calculating coordinates of new edge |
295 Gnome::Canvas::Points coos; |
295 Gnome::Canvas::Points coos; |
296 double x1, x2, y1, y2; |
296 double x1, x2, y1, y2; |
297 |
297 |
309 //redraw nodes to blank terminations of the new edge |
309 //redraw nodes to blank terminations of the new edge |
310 target_item->raise_to_top(); |
310 target_item->raise_to_top(); |
311 active_item->raise_to_top(); |
311 active_item->raise_to_top(); |
312 |
312 |
313 //initializing edge-text as well, to empty string |
313 //initializing edge-text as well, to empty string |
314 xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos(); |
314 xy<double> text_pos=edgesmap[active_edge]->getArrowPos(); |
315 text_pos+=(xy<double>(10,10)); |
315 text_pos+=(xy<double>(10,10)); |
316 |
316 |
317 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); |
317 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); |
318 edgetextmap[active_edge]->property_fill_color().set_value("darkgreen"); |
318 edgetextmap[active_edge]->property_fill_color().set_value("darkgreen"); |
319 |
319 |
320 //updating its properties |
320 //updating its properties |
321 mapwin->update_edge(active_edge); |
321 mapwin->updateEdge(active_edge); |
322 } |
322 } |
323 else |
323 else |
324 { |
324 { |
325 target_node=INVALID; |
325 target_node=INVALID; |
326 std::cout << "Loop edge is not yet implemented!" << std::endl; |
326 std::cout << "Loop edge is not yet implemented!" << std::endl; |
412 } |
412 } |
413 |
413 |
414 //deleting collected edges |
414 //deleting collected edges |
415 for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++) |
415 for(std::set<Graph::Edge>::iterator edge_set_it=edges_to_delete.begin();edge_set_it!=edges_to_delete.end();edge_set_it++) |
416 { |
416 { |
417 delete_item(*edge_set_it); |
417 deleteItem(*edge_set_it); |
418 } |
418 } |
419 delete_item(active_node); |
419 deleteItem(active_node); |
420 } |
420 } |
421 //a simple edge was chosen |
421 //a simple edge was chosen |
422 else |
422 else |
423 { |
423 { |
424 delete_item(active_edge); |
424 deleteItem(active_edge); |
425 } |
425 } |
426 |
426 |
427 |
427 |
428 } |
428 } |
429 //pointer was moved, deletion is cancelled |
429 //pointer was moved, deletion is cancelled |
451 break; |
451 break; |
452 } |
452 } |
453 return true; |
453 return true; |
454 } |
454 } |
455 |
455 |
456 void GraphDisplayerCanvas::delete_item(NodeIt node_to_delete) |
456 void GraphDisplayerCanvas::deleteItem(NodeIt node_to_delete) |
457 { |
457 { |
458 delete(nodetextmap[node_to_delete]); |
458 delete(nodetextmap[node_to_delete]); |
459 delete(nodesmap[node_to_delete]); |
459 delete(nodesmap[node_to_delete]); |
460 g.erase(node_to_delete); |
460 g.erase(node_to_delete); |
461 } |
461 } |
462 |
462 |
463 void GraphDisplayerCanvas::delete_item(EdgeIt edge_to_delete) |
463 void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete) |
464 { |
464 { |
465 delete(edgetextmap[edge_to_delete]); |
465 delete(edgetextmap[edge_to_delete]); |
466 delete(edgesmap[edge_to_delete]); |
466 delete(edgesmap[edge_to_delete]); |
467 g.erase(edge_to_delete); |
467 g.erase(edge_to_delete); |
468 } |
468 } |
469 |
469 |
470 void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete) |
470 void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete) |
471 { |
471 { |
472 delete(edgetextmap[edge_to_delete]); |
472 delete(edgetextmap[edge_to_delete]); |
473 delete(edgesmap[edge_to_delete]); |
473 delete(edgesmap[edge_to_delete]); |
474 g.erase(edge_to_delete); |
474 g.erase(edge_to_delete); |
475 } |
475 } |
476 |
476 |
477 void GraphDisplayerCanvas::text_reposition(xy<double> new_place) |
477 void GraphDisplayerCanvas::textReposition(xy<double> new_place) |
478 { |
478 { |
479 new_place+=(xy<double>(10,10)); |
479 new_place+=(xy<double>(10,10)); |
480 edgetextmap[active_edge]->property_x().set_value(new_place.x); |
480 edgetextmap[active_edge]->property_x().set_value(new_place.x); |
481 edgetextmap[active_edge]->property_y().set_value(new_place.y); |
481 edgetextmap[active_edge]->property_y().set_value(new_place.y); |
482 } |
482 } |
483 |
483 |
484 void GraphDisplayerCanvas::toggle_edge_activity(BrokenEdge* active_bre, bool on) |
484 void GraphDisplayerCanvas::toggleEdgeActivity(BrokenEdge* active_bre, bool on) |
485 { |
485 { |
486 if(on) |
486 if(on) |
487 { |
487 { |
488 if(active_edge!=INVALID) |
488 if(active_edge!=INVALID) |
489 { |
489 { |