136 return handled; |
136 return handled; |
137 } |
137 } |
138 |
138 |
139 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e) |
139 bool GraphDisplayerCanvas::moveEventHandler(GdkEvent* e) |
140 { |
140 { |
|
141 MapStorage& ms = *mytab.mapstorage; |
|
142 |
141 static Gnome::Canvas::Text *coord_text = 0; |
143 static Gnome::Canvas::Text *coord_text = 0; |
142 switch(e->type) |
144 switch(e->type) |
143 { |
145 { |
144 case GDK_BUTTON_PRESS: |
146 case GDK_BUTTON_PRESS: |
145 //we mark the location of the event to be able to calculate parameters of dragging |
147 //we mark the location of the event to be able to calculate parameters of dragging |
146 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
148 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
147 |
149 |
148 active_item=(get_item_at(clicked_x, clicked_y)); |
150 active_item=(get_item_at(clicked_x, clicked_y)); |
149 active_node=INVALID; |
151 active_node=INVALID; |
150 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
152 for (NodeIt i(ms.graph); i!=INVALID; ++i) |
151 { |
153 { |
152 if(nodesmap[i]==active_item) |
154 if(nodesmap[i]==active_item) |
153 { |
155 { |
154 active_node=i; |
156 active_node=i; |
155 } |
157 } |
156 } |
158 } |
157 isbutton=e->button.button; |
159 isbutton=e->button.button; |
158 break; |
160 break; |
159 case GDK_BUTTON_RELEASE: |
161 case GDK_BUTTON_RELEASE: |
160 if (coord_text) |
162 if (coord_text) |
161 { |
163 { |
162 delete coord_text; |
164 delete coord_text; |
163 coord_text = 0; |
165 coord_text = 0; |
164 } |
166 } |
165 isbutton=0; |
167 isbutton=0; |
166 active_item=NULL; |
168 active_item=NULL; |
167 active_node=INVALID; |
169 active_node=INVALID; |
168 break; |
170 break; |
169 case GDK_MOTION_NOTIFY: |
171 case GDK_MOTION_NOTIFY: |
170 //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 |
172 //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 |
171 if(active_node!=INVALID) |
173 if(active_node!=INVALID) |
172 { |
174 { |
173 (mytab.mapstorage)->modified = true; |
175 ms.setModified(); |
174 |
176 |
175 //new coordinates will be the old values, |
177 //new coordinates will be the old values, |
176 //because the item will be moved to the |
178 //because the item will be moved to the |
177 //new coordinate therefore the new movement |
179 //new coordinate therefore the new movement |
178 //has to be calculated from here |
180 //has to be calculated from here |
179 |
181 |
180 double new_x, new_y; |
182 double new_x, new_y; |
181 |
183 |
182 window_to_world (e->motion.x, e->motion.y, new_x, new_y); |
184 window_to_world (e->motion.x, e->motion.y, new_x, new_y); |
183 |
185 |
184 double dx=new_x-clicked_x; |
186 double dx=new_x-clicked_x; |
185 double dy=new_y-clicked_y; |
187 double dy=new_y-clicked_y; |
186 |
188 |
187 moveNode(dx, dy); |
189 moveNode(dx, dy); |
188 |
190 |
189 clicked_x=new_x; |
191 clicked_x=new_x; |
190 clicked_y=new_y; |
192 clicked_y=new_y; |
191 |
193 |
192 // reposition the coordinates text |
194 // reposition the coordinates text |
193 std::ostringstream ostr; |
195 std::ostringstream ostr; |
194 ostr << "(" << |
196 ostr << "(" << |
195 (mytab.mapstorage)->coords[active_node].x << ", " << |
197 ms.getNodeCoords(active_node).x << ", " << |
196 (mytab.mapstorage)->coords[active_node].y << ")"; |
198 ms.getNodeCoords(active_node).y << ")"; |
197 double radius = |
199 double radius = |
198 (nodesmap[active_node]->property_x2().get_value() - |
200 (nodesmap[active_node]->property_x2().get_value() - |
199 nodesmap[active_node]->property_x1().get_value()) / 2.0; |
201 nodesmap[active_node]->property_x1().get_value()) / 2.0; |
200 if (coord_text) |
202 if (coord_text) |
201 { |
203 { |
202 coord_text->property_text().set_value(ostr.str()); |
204 coord_text->property_text().set_value(ostr.str()); |
203 coord_text->property_x().set_value((mytab.mapstorage)->coords[active_node].x + |
205 coord_text->property_x().set_value( |
204 radius); |
206 ms.getNodeCoords(active_node).x + radius); |
205 coord_text->property_y().set_value((mytab.mapstorage)->coords[active_node].y - |
207 coord_text->property_y().set_value( |
206 radius); |
208 ms.getNodeCoords(active_node).y - radius); |
207 } |
209 } |
208 else |
210 else |
209 { |
211 { |
210 coord_text = new Gnome::Canvas::Text( |
212 coord_text = new Gnome::Canvas::Text( |
211 displayed_graph, |
213 displayed_graph, |
212 (mytab.mapstorage)->coords[active_node].x + radius, |
214 ms.getNodeCoords(active_node).x + radius, |
213 (mytab.mapstorage)->coords[active_node].y - radius, |
215 ms.getNodeCoords(active_node).y - radius, |
214 ostr.str()); |
216 ostr.str()); |
215 coord_text->property_fill_color().set_value("black"); |
217 coord_text->property_fill_color().set_value("black"); |
216 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); |
218 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); |
217 } |
219 } |
218 |
220 |
219 |
221 |
220 } |
222 } |
221 default: break; |
223 default: break; |
222 } |
224 } |
223 |
225 |
224 return false; |
226 return false; |
225 } |
227 } |
226 |
228 |
227 XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code) |
229 XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code) |
228 { |
230 { |
229 switch(move_code) |
231 switch(move_code) |
230 { |
232 { |
231 case 1: |
233 case 1: |
232 return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); |
234 return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0); |
233 break; |
235 break; |
234 case 2: |
236 case 2: |
235 return old_arrow_pos; |
237 return old_arrow_pos; |
236 break; |
238 break; |
237 case 3: |
239 case 3: |
238 { |
240 { |
239 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
241 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
240 /////////// keeps shape-with scalar multiplication - version 2. |
242 /////////// keeps shape-with scalar multiplication - version 2. |
241 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
243 ////////////////////////////////////////////////////////////////////////////////////////////////////// |
242 |
244 |
243 //old vector from one to the other node - a |
245 //old vector from one to the other node - a |
244 XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); |
246 XY a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y); |
245 //new vector from one to the other node - b |
247 //new vector from one to the other node - b |
246 XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); |
248 XY b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y); |
247 |
249 |
248 double absa=sqrt(a_v.normSquare()); |
250 double absa=sqrt(a_v.normSquare()); |
249 double absb=sqrt(b_v.normSquare()); |
251 double absb=sqrt(b_v.normSquare()); |
250 |
252 |
251 if ((absa == 0.0) || (absb == 0.0)) |
253 if ((absa == 0.0) || (absb == 0.0)) |
252 { |
254 { |
253 return old_arrow_pos; |
255 return old_arrow_pos; |
254 } |
256 } |
255 else |
257 else |
256 { |
258 { |
257 //old vector from one node to the breakpoint - c |
259 //old vector from one node to the breakpoint - c |
258 XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); |
260 XY c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y); |
259 |
261 |
260 //unit vector with the same direction to a_v |
262 //unit vector with the same direction to a_v |
261 XY a_v_u(a_v.x/absa,a_v.y/absa); |
263 XY a_v_u(a_v.x/absa,a_v.y/absa); |
262 |
264 |
263 //normal vector of unit vector with the same direction to a_v |
265 //normal vector of unit vector with the same direction to a_v |
264 XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x); |
266 XY a_v_u_n(((-1)*a_v_u.y),a_v_u.x); |
265 |
267 |
266 //unit vector with the same direction to b_v |
268 //unit vector with the same direction to b_v |
267 XY b_v_u(b_v.x/absb,b_v.y/absb); |
269 XY b_v_u(b_v.x/absb,b_v.y/absb); |
268 |
270 |
269 //normal vector of unit vector with the same direction to b_v |
271 //normal vector of unit vector with the same direction to b_v |
270 XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x); |
272 XY b_v_u_n(((-1)*b_v_u.y),b_v_u.x); |
271 |
273 |
272 //vector c in a_v_u and a_v_u_n co-ordinate system |
274 //vector c in a_v_u and a_v_u_n co-ordinate system |
273 XY c_a(c_v*a_v_u,c_v*a_v_u_n); |
275 XY c_a(c_v*a_v_u,c_v*a_v_u_n); |
274 |
276 |
275 //new vector from one node to the breakpoint - d - we have to calculate this one |
277 //new vector from one node to the breakpoint - d - we have to calculate this one |
276 XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); |
278 XY d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); |
277 |
279 |
278 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); |
280 return XY(d_v.x+fix_node.x,d_v.y+fix_node.y); |
279 } |
281 } |
280 break; |
282 break; |
281 } |
283 } |
282 default: |
284 default: |
283 break; |
285 break; |
284 } |
286 } |
285 } |
287 } |
286 |
288 |
287 |
289 |
288 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) |
290 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) |
289 { |
291 { |
|
292 MapStorage& ms = *mytab.mapstorage; |
|
293 |
290 switch(e->type) |
294 switch(e->type) |
291 { |
295 { |
292 //move the new node |
296 //move the new node |
293 case GDK_MOTION_NOTIFY: |
297 case GDK_MOTION_NOTIFY: |
294 { |
298 { |
406 else |
392 else |
407 { |
393 { |
408 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
394 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
409 target_item=(get_item_at(clicked_x, clicked_y)); |
395 target_item=(get_item_at(clicked_x, clicked_y)); |
410 Node target_node=INVALID; |
396 Node target_node=INVALID; |
411 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
397 for (NodeIt i(ms.graph); i!=INVALID; ++i) |
412 { |
398 { |
413 if(nodesmap[i]==target_item) |
399 if(nodesmap[i]==target_item) |
414 { |
400 { |
415 target_node=i; |
401 target_node=i; |
416 } |
402 } |
417 } |
403 } |
418 //the clicked item is a node, the edge can be drawn |
404 //the clicked item is a node, the edge can be drawn |
419 if(target_node!=INVALID) |
405 if(target_node!=INVALID) |
420 { |
406 { |
421 (mytab.mapstorage)->modified = true; |
407 ms.setModified(); |
422 |
408 |
423 *(nodesmap[target_node]) << |
409 *(nodesmap[target_node]) << |
424 Gnome::Canvas::Properties::fill_color("red"); |
410 Gnome::Canvas::Properties::fill_color("red"); |
425 |
411 |
426 //creating new edge |
412 active_edge = ms.addEdge(active_node, target_node); |
427 active_edge=(mytab.mapstorage)->graph.addEdge(active_node, |
|
428 target_node); |
|
429 |
|
430 // update maps |
|
431 for (std::map<std::string, |
|
432 Graph::EdgeMap<double>*>::const_iterator it = |
|
433 (mytab.mapstorage)->edgemap_storage.begin(); it != |
|
434 (mytab.mapstorage)->edgemap_storage.end(); ++it) |
|
435 { |
|
436 (*(it->second))[active_edge] = |
|
437 (mytab.mapstorage)->edgemap_default[it->first]; |
|
438 } |
|
439 // increment the id map's default value |
|
440 (mytab.mapstorage)->edgemap_default["label"] += 1.0; |
|
441 |
413 |
442 if(target_node!=active_node) |
414 if(target_node!=active_node) |
443 { |
415 { |
444 // set the coordinates of the arrow on the new edge |
416 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, *this); |
445 MapStorage& ms = *mytab.mapstorage; |
|
446 ms.arrow_pos.set(active_edge, |
|
447 (ms.coords[ms.graph.source(active_edge)] + |
|
448 ms.coords[ms.graph.target(active_edge)])/ 2.0); |
|
449 |
|
450 //drawing new edge |
|
451 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, |
|
452 *this); |
|
453 } |
417 } |
454 else |
418 else |
455 { |
419 { |
456 // set the coordinates of the arrow on the new edge |
420 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, *this); |
457 MapStorage& ms = *mytab.mapstorage; |
|
458 ms.arrow_pos.set(active_edge, |
|
459 (ms.coords[ms.graph.source(active_edge)] + |
|
460 XY(0.0, 80.0))); |
|
461 |
|
462 //drawing new edge |
|
463 edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, |
|
464 *this); |
|
465 } |
421 } |
466 |
422 |
467 //initializing edge-text as well, to empty string |
423 //initializing edge-text as well, to empty string |
468 XY text_pos=mytab.mapstorage->arrow_pos[active_edge]; |
424 XY text_pos=ms.getArrowCoords(active_edge); |
469 text_pos+=(XY(10,10)); |
425 text_pos+=(XY(10,10)); |
470 |
426 |
471 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, |
427 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, |
472 text_pos.x, text_pos.y, ""); |
428 text_pos.x, text_pos.y, ""); |
473 edgetextmap[active_edge]->property_fill_color().set_value( |
429 edgetextmap[active_edge]->property_fill_color().set_value( |
512 return false; |
468 return false; |
513 } |
469 } |
514 |
470 |
515 bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) |
471 bool GraphDisplayerCanvas::eraserEventHandler(GdkEvent* e) |
516 { |
472 { |
|
473 MapStorage& ms = *mytab.mapstorage; |
|
474 |
517 switch(e->type) |
475 switch(e->type) |
518 { |
476 { |
519 case GDK_BUTTON_PRESS: |
477 case GDK_BUTTON_PRESS: |
520 //finding the clicked items |
478 //finding the clicked items |
521 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
479 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
522 active_item=(get_item_at(clicked_x, clicked_y)); |
480 active_item=(get_item_at(clicked_x, clicked_y)); |
523 active_node=INVALID; |
481 active_node=INVALID; |
524 active_edge=INVALID; |
482 active_edge=INVALID; |
525 //was it a node? |
483 //was it a node? |
526 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
484 for (NodeIt i(ms.graph); i!=INVALID; ++i) |
527 { |
485 { |
528 if(nodesmap[i]==active_item) |
486 if(nodesmap[i]==active_item) |
529 { |
487 { |
530 active_node=i; |
488 active_node=i; |
531 } |
489 } |
532 } |
490 } |
533 //or was it an edge? |
491 //or was it an edge? |
534 if(active_node==INVALID) |
492 if(active_node==INVALID) |
535 { |
493 { |
536 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
494 for (EdgeIt i(ms.graph); i!=INVALID; ++i) |
537 { |
495 { |
538 if(edgesmap[i]->getLine()==active_item) |
496 if(edgesmap[i]->getLine()==active_item) |
539 { |
497 { |
540 active_edge=i; |
498 active_edge=i; |
541 } |
499 } |
542 } |
500 } |
543 } |
501 } |
544 |
502 |
545 // return if the clicked object is neither an edge nor a node |
503 // return if the clicked object is neither an edge nor a node |
546 if (active_edge == INVALID) return false; |
504 if (active_edge == INVALID) return false; |
547 |
505 |
548 //recolor activated item |
506 //recolor activated item |
549 if(active_item) |
507 if(active_item) |
550 { |
508 { |
551 *active_item << Gnome::Canvas::Properties::fill_color("red"); |
509 *active_item << Gnome::Canvas::Properties::fill_color("red"); |
552 } |
510 } |
553 break; |
511 break; |
554 |
512 |
555 case GDK_BUTTON_RELEASE: |
513 case GDK_BUTTON_RELEASE: |
556 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
514 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
557 if(active_item) |
515 if(active_item) |
558 { |
516 { |
559 //the cursor was not moved since pressing it |
517 //the cursor was not moved since pressing it |
560 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) |
518 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) |
561 { |
519 { |
562 //a node was found |
520 //a node was found |
563 if(active_node!=INVALID) |
521 if(active_node!=INVALID) |
564 { |
522 { |
565 (mytab.mapstorage)->modified = true; |
523 ms.setModified(); |
566 |
524 |
567 std::set<Graph::Edge> edges_to_delete; |
525 std::set<Graph::Edge> edges_to_delete; |
568 |
526 |
569 for(OutEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e) |
527 for(OutEdgeIt e(ms.graph,active_node);e!=INVALID;++e) |
570 { |
528 { |
571 edges_to_delete.insert(e); |
529 edges_to_delete.insert(e); |
572 } |
530 } |
573 |
531 |
574 for(InEdgeIt e((mytab.mapstorage)->graph,active_node);e!=INVALID;++e) |
532 for(InEdgeIt e(ms.graph,active_node);e!=INVALID;++e) |
575 { |
533 { |
576 edges_to_delete.insert(e); |
534 edges_to_delete.insert(e); |
577 } |
535 } |
578 |
536 |
579 //deleting collected edges |
537 //deleting collected edges |
580 for(std::set<Graph::Edge>::iterator |
538 for(std::set<Graph::Edge>::iterator |
581 edge_set_it=edges_to_delete.begin(); |
539 edge_set_it=edges_to_delete.begin(); |
582 edge_set_it!=edges_to_delete.end(); |
540 edge_set_it!=edges_to_delete.end(); |
583 ++edge_set_it) |
541 ++edge_set_it) |
584 { |
542 { |
585 deleteItem(*edge_set_it); |
543 deleteItem(*edge_set_it); |
586 } |
544 } |
587 deleteItem(active_node); |
545 deleteItem(active_node); |
588 } |
546 } |
589 //a simple edge was chosen |
547 //a simple edge was chosen |
590 else if (active_edge != INVALID) |
548 else if (active_edge != INVALID) |
591 { |
549 { |
592 deleteItem(active_edge); |
550 deleteItem(active_edge); |
593 } |
551 } |
594 } |
552 } |
595 //pointer was moved, deletion is cancelled |
553 //pointer was moved, deletion is cancelled |
596 else |
554 else |
597 { |
555 { |
598 if(active_node!=INVALID) |
556 if(active_node!=INVALID) |
599 { |
557 { |
600 *active_item << Gnome::Canvas::Properties::fill_color("blue"); |
558 *active_item << Gnome::Canvas::Properties::fill_color("blue"); |
601 } |
559 } |
602 else if (active_edge != INVALID) |
560 else if (active_edge != INVALID) |
603 { |
561 { |
604 *active_item << Gnome::Canvas::Properties::fill_color("green"); |
562 *active_item << Gnome::Canvas::Properties::fill_color("green"); |
605 } |
563 } |
606 } |
564 } |
607 } |
565 } |
608 //reseting datas |
566 //reseting datas |
609 active_item=NULL; |
567 active_item=NULL; |
610 active_edge=INVALID; |
568 active_edge=INVALID; |
611 active_node=INVALID; |
569 active_node=INVALID; |
612 break; |
570 break; |
614 case GDK_MOTION_NOTIFY: |
572 case GDK_MOTION_NOTIFY: |
615 break; |
573 break; |
616 |
574 |
617 default: |
575 default: |
618 break; |
576 break; |
619 } |
577 } |
620 return false; |
578 return false; |
621 } |
579 } |
622 |
580 |
623 bool GraphDisplayerCanvas::mapEditEventHandler(GdkEvent* e) |
581 bool GraphDisplayerCanvas::mapEditEventHandler(GdkEvent* e) |
624 { |
582 { |
|
583 MapStorage& ms = *mytab.mapstorage; |
|
584 |
625 if(actual_tool==MAP_EDIT) |
585 if(actual_tool==MAP_EDIT) |
626 { |
586 { |
627 switch(e->type) |
587 switch(e->type) |
628 { |
588 { |
629 case GDK_BUTTON_PRESS: |
589 case GDK_BUTTON_PRESS: |
630 { |
590 { |
631 //for determine, whether it was an edge |
591 //for determine, whether it was an edge |
632 Edge clicked_edge=INVALID; |
592 Edge clicked_edge=INVALID; |
633 //for determine, whether it was a node |
593 //for determine, whether it was a node |
634 Node clicked_node=INVALID; |
594 Node clicked_node=INVALID; |
635 |
595 |
636 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
596 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
637 active_item=(get_item_at(clicked_x, clicked_y)); |
597 active_item=(get_item_at(clicked_x, clicked_y)); |
638 |
598 |
639 //find the activated item between text of nodes |
599 //find the activated item between text of nodes |
640 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
600 for (NodeIt i(ms.graph); i!=INVALID; ++i) |
641 { |
601 { |
642 //at the same time only one can be active |
602 //at the same time only one can be active |
643 if(nodetextmap[i]==active_item) |
603 if(nodetextmap[i]==active_item) |
644 { |
604 { |
645 clicked_node=i; |
605 clicked_node=i; |
646 } |
606 } |
647 } |
607 } |
648 |
608 |
649 //if there was not, search for it between nodes |
609 //if there was not, search for it between nodes |
650 if(clicked_node==INVALID) |
610 if(clicked_node==INVALID) |
651 { |
611 { |
652 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
612 for (NodeIt i(ms.graph); i!=INVALID; ++i) |
653 { |
613 { |
654 //at the same time only one can be active |
614 //at the same time only one can be active |
655 if(nodesmap[i]==active_item) |
615 if(nodesmap[i]==active_item) |
656 { |
616 { |
657 clicked_node=i; |
617 clicked_node=i; |
658 } |
618 } |
659 } |
619 } |
660 } |
620 } |
661 |
621 |
662 if(clicked_node==INVALID) |
622 if(clicked_node==INVALID) |
663 { |
623 { |
664 //find the activated item between texts |
624 //find the activated item between texts |
665 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
625 for (EdgeIt i(ms.graph); i!=INVALID; ++i) |
666 { |
626 { |
667 //at the same time only one can be active |
627 //at the same time only one can be active |
668 if(edgetextmap[i]==active_item) |
628 if(edgetextmap[i]==active_item) |
669 { |
629 { |
670 clicked_edge=i; |
630 clicked_edge=i; |
671 } |
631 } |
672 } |
632 } |
673 |
633 |
674 //if it was not between texts, search for it between edges |
634 //if it was not between texts, search for it between edges |
675 if(clicked_edge==INVALID) |
635 if(clicked_edge==INVALID) |
676 { |
636 { |
677 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
637 for (EdgeIt i(ms.graph); i!=INVALID; ++i) |
678 { |
638 { |
679 //at the same time only one can be active |
639 //at the same time only one can be active |
680 if((edgesmap[i]->getLine())==active_item) |
640 if((edgesmap[i]->getLine())==active_item) |
681 { |
641 { |
682 clicked_edge=i; |
642 clicked_edge=i; |
683 } |
643 } |
684 } |
644 } |
685 } |
645 } |
686 } |
646 } |
687 |
647 |
688 //if it was really a node... |
648 //if it was really a node... |
689 if(clicked_node!=INVALID) |
649 if(clicked_node!=INVALID) |
690 { |
650 { |
691 // the id map is not editable |
651 // the id map is not editable |
692 if (nodemap_to_edit == "label") return 0; |
652 if (nodemap_to_edit == "label") return 0; |
693 |
653 |
694 //and there is activated map |
654 //and there is activated map |
695 if(nodetextmap[clicked_node]->property_text().get_value()!="") |
655 if(nodetextmap[clicked_node]->property_text().get_value()!="") |
696 { |
656 { |
697 //activate the general variable for it |
657 //activate the general variable for it |
698 active_node=clicked_node; |
658 active_node=clicked_node; |
699 |
659 |
700 //create a dialog |
660 //create a dialog |
701 Gtk::Dialog dialog("Edit value", true); |
661 Gtk::Dialog dialog("Edit value", true); |
702 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
662 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
703 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
663 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
704 Gtk::VBox* vbox = dialog.get_vbox(); |
664 Gtk::VBox* vbox = dialog.get_vbox(); |
705 Gtk::SpinButton spin(0.0, 4); |
665 |
706 spin.set_increments(1.0, 10.0); |
666 /* |
707 spin.set_range(-1000000.0, 1000000.0); |
667 Gtk::SpinButton spin(0.0, 4); |
708 spin.set_numeric(true); |
668 spin.set_increments(1.0, 10.0); |
709 spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str())); |
669 spin.set_range(-1000000.0, 1000000.0); |
710 vbox->add(spin); |
670 spin.set_numeric(true); |
711 spin.show(); |
671 spin.set_value(atof(nodetextmap[active_node]->property_text().get_value().c_str())); |
712 switch (dialog.run()) |
672 vbox->add(spin); |
713 { |
673 spin.show(); |
714 case Gtk::RESPONSE_NONE: |
674 */ |
715 case Gtk::RESPONSE_CANCEL: |
675 Gtk::Entry entry; |
716 break; |
676 entry.set_text(nodetextmap[active_node]->property_text().get_value()); |
717 case Gtk::RESPONSE_ACCEPT: |
677 vbox->add(entry); |
718 double new_value = spin.get_value(); |
678 entry.show(); |
719 (*(mytab.mapstorage)->nodemap_storage[nodemap_to_edit])[active_node] = |
679 |
720 new_value; |
680 switch (dialog.run()) |
721 std::ostringstream ostr; |
681 { |
722 ostr << new_value; |
682 case Gtk::RESPONSE_NONE: |
723 nodetextmap[active_node]->property_text().set_value(ostr.str()); |
683 case Gtk::RESPONSE_CANCEL: |
724 //mapwin.updateNode(active_node); |
684 break; |
725 //mapwin.updateNode(Node(INVALID)); |
685 case Gtk::RESPONSE_ACCEPT: |
726 propertyUpdate(Node(INVALID)); |
686 switch (ms.getNodeMapElementType(nodemap_to_edit)) |
727 } |
687 { |
728 } |
688 case MapValue::NUMERIC: |
729 } |
689 ms.set(nodemap_to_edit, active_node, |
730 else |
690 atof(entry.get_text().c_str())); |
731 //if it was really an edge... |
691 break; |
732 if(clicked_edge!=INVALID) |
692 case MapValue::STRING: |
733 { |
693 ms.set(nodemap_to_edit, active_node, |
734 // the id map is not editable |
694 static_cast<std::string>(entry.get_text())); |
735 if (edgemap_to_edit == "label") return 0; |
695 break; |
736 |
696 } |
737 //and there is activated map |
697 nodetextmap[active_node]->property_text().set_value( |
738 if(edgetextmap[clicked_edge]->property_text().get_value()!="") |
698 static_cast<std::string>(ms.get(nodemap_to_edit, active_node))); |
739 { |
699 |
740 //activate the general variable for it |
700 //mapwin.updateNode(active_node); |
741 active_edge=clicked_edge; |
701 //mapwin.updateNode(Node(INVALID)); |
742 |
702 propertyUpdate(Node(INVALID)); |
743 //create a dialog |
703 } |
744 Gtk::Dialog dialog("Edit value", true); |
704 } |
745 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
705 } |
746 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
706 else |
747 Gtk::VBox* vbox = dialog.get_vbox(); |
707 //if it was really an edge... |
748 Gtk::SpinButton spin(0.0, 4); |
708 if(clicked_edge!=INVALID) |
749 spin.set_increments(1.0, 10.0); |
709 { |
750 spin.set_range(-1000000.0, 1000000.0); |
710 // the id map is not editable |
751 spin.set_numeric(true); |
711 if (edgemap_to_edit == "label") return 0; |
752 spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str())); |
712 |
753 vbox->add(spin); |
713 //and there is activated map |
754 spin.show(); |
714 if(edgetextmap[clicked_edge]->property_text().get_value()!="") |
755 switch (dialog.run()) |
715 { |
756 { |
716 //activate the general variable for it |
757 case Gtk::RESPONSE_NONE: |
717 active_edge=clicked_edge; |
758 case Gtk::RESPONSE_CANCEL: |
718 |
759 break; |
719 //create a dialog |
760 case Gtk::RESPONSE_ACCEPT: |
720 Gtk::Dialog dialog("Edit value", true); |
761 double new_value = spin.get_value(); |
721 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
762 (*(mytab.mapstorage)->edgemap_storage[edgemap_to_edit])[active_edge] = |
722 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
763 new_value; |
723 Gtk::VBox* vbox = dialog.get_vbox(); |
764 std::ostringstream ostr; |
724 |
765 ostr << new_value; |
725 /* |
766 edgetextmap[active_edge]->property_text().set_value( |
726 Gtk::SpinButton spin(0.0, 4); |
767 ostr.str()); |
727 spin.set_increments(1.0, 10.0); |
768 //mapwin.updateEdge(active_edge); |
728 spin.set_range(-1000000.0, 1000000.0); |
769 // mapwin.updateEdge(Edge(INVALID)); |
729 spin.set_numeric(true); |
770 propertyUpdate(Edge(INVALID)); |
730 spin.set_value(atof(edgetextmap[active_edge]->property_text().get_value().c_str())); |
771 } |
731 vbox->add(spin); |
772 } |
732 spin.show(); |
773 } |
733 */ |
774 break; |
734 Gtk::Entry entry; |
775 } |
735 entry.set_text(edgetextmap[active_edge]->property_text().get_value()); |
776 default: |
736 vbox->add(entry); |
777 break; |
737 entry.show(); |
778 } |
738 |
779 } |
739 std::cout << edgemap_to_edit << std::endl; |
|
740 switch (dialog.run()) |
|
741 { |
|
742 case Gtk::RESPONSE_NONE: |
|
743 case Gtk::RESPONSE_CANCEL: |
|
744 break; |
|
745 case Gtk::RESPONSE_ACCEPT: |
|
746 switch (ms.getEdgeMapElementType(edgemap_to_edit)) |
|
747 { |
|
748 case MapValue::NUMERIC: |
|
749 ms.set(edgemap_to_edit, active_edge, |
|
750 atof(entry.get_text().c_str())); |
|
751 break; |
|
752 case MapValue::STRING: |
|
753 ms.set(edgemap_to_edit, active_edge, |
|
754 static_cast<std::string>(entry.get_text())); |
|
755 break; |
|
756 } |
|
757 edgetextmap[active_edge]->property_text().set_value( |
|
758 static_cast<std::string>(ms.get(edgemap_to_edit, active_edge))); |
|
759 |
|
760 //mapwin.updateEdge(active_edge); |
|
761 // mapwin.updateEdge(Edge(INVALID)); |
|
762 propertyUpdate(Edge(INVALID)); |
|
763 } |
|
764 } |
|
765 } |
|
766 break; |
|
767 } |
|
768 default: |
|
769 break; |
|
770 } |
|
771 } |
780 return false; |
772 return false; |
781 } |
773 } |
782 |
774 |
783 void GraphDisplayerCanvas::deleteItem(Node node_to_delete) |
775 void GraphDisplayerCanvas::deleteItem(Node node_to_delete) |
784 { |
776 { |
785 delete(nodetextmap[node_to_delete]); |
777 delete(nodetextmap[node_to_delete]); |
786 delete(nodesmap[node_to_delete]); |
778 delete(nodesmap[node_to_delete]); |
787 (mytab.mapstorage)->graph.erase(node_to_delete); |
779 mytab.mapstorage->graph.erase(node_to_delete); |
788 } |
780 } |
789 |
781 |
790 void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete) |
782 void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete) |
791 { |
783 { |
792 delete(edgetextmap[edge_to_delete]); |
784 delete(edgetextmap[edge_to_delete]); |
793 delete(edgesmap[edge_to_delete]); |
785 delete(edgesmap[edge_to_delete]); |
794 (mytab.mapstorage)->graph.erase(edge_to_delete); |
786 mytab.mapstorage->graph.erase(edge_to_delete); |
795 } |
787 } |
796 |
788 |
797 void GraphDisplayerCanvas::textReposition(XY new_place) |
789 void GraphDisplayerCanvas::textReposition(XY new_place) |
798 { |
790 { |
799 new_place+=(XY(10,10)); |
791 new_place+=(XY(10,10)); |
809 { |
801 { |
810 std::cerr << "ERROR!!!! Valid edge found!" << std::endl; |
802 std::cerr << "ERROR!!!! Valid edge found!" << std::endl; |
811 } |
803 } |
812 else |
804 else |
813 { |
805 { |
814 for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) |
806 for (EdgeIt i(mytab.mapstorage->graph); i!=INVALID; ++i) |
815 { |
807 { |
816 if(edgesmap[i]==active_bre) |
808 if(edgesmap[i]==active_bre) |
817 { |
809 { |
818 forming_edge=i; |
810 forming_edge=i; |
819 } |
811 } |
820 } |
812 } |
821 } |
813 } |
822 } |
814 } |
823 else |
815 else |
824 { |
816 { |
825 if(forming_edge!=INVALID) |
817 if(forming_edge!=INVALID) |
826 { |
818 { |
827 forming_edge=INVALID; |
819 forming_edge=INVALID; |
828 } |
820 } |
829 else |
821 else |
830 { |
822 { |
831 std::cerr << "ERROR!!!! Invalid edge found!" << std::endl; |
823 std::cerr << "ERROR!!!! Invalid edge found!" << std::endl; |
832 } |
824 } |
833 } |
825 } |
834 } |
826 } |
835 |
827 |
836 void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node) |
828 void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node) |
837 { |
829 { |
|
830 MapStorage& ms = *mytab.mapstorage; |
|
831 |
838 Gnome::Canvas::Item * moved_item=item; |
832 Gnome::Canvas::Item * moved_item=item; |
839 Node moved_node=node; |
833 Node moved_node=node; |
840 |
834 |
841 if(item==NULL && node==INVALID) |
835 if(item==NULL && node==INVALID) |
842 { |
836 { |
843 moved_item=active_item; |
837 moved_item=active_item; |
844 moved_node=active_node; |
838 moved_node=active_node; |
845 } |
839 } |
846 else |
840 else |
847 { |
841 { |
848 isbutton=1; |
842 isbutton=1; |
849 } |
843 } |
850 |
844 |
851 //repositioning node and its text |
845 //repositioning node and its text |
852 moved_item->move(dx, dy); |
846 moved_item->move(dx, dy); |
853 nodetextmap[moved_node]->move(dx, dy); |
847 nodetextmap[moved_node]->move(dx, dy); |
854 |
848 |
855 // the new coordinates of the centre of the node |
849 // the new coordinates of the centre of the node |
856 double coord_x = dx + (mytab.mapstorage)->coords[moved_node].x; |
850 double coord_x = dx + ms.getNodeCoords(moved_node).x; |
857 double coord_y = dy + (mytab.mapstorage)->coords[moved_node].y; |
851 double coord_y = dy + ms.getNodeCoords(moved_node).y; |
858 |
852 |
859 // write back the new coordinates to the coords map |
853 // write back the new coordinates to the coords map |
860 (mytab.mapstorage)->coords.set(moved_node, XY(coord_x, coord_y)); |
854 ms.setNodeCoords(moved_node, XY(coord_x, coord_y)); |
861 |
855 |
862 //all the edges connected to the moved point has to be redrawn |
856 //all the edges connected to the moved point has to be redrawn |
863 for(OutEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) |
857 for(OutEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei) |
864 { |
858 { |
|
859 XY arrow_pos; |
|
860 |
|
861 if (ms.graph.source(ei) == ms.graph.target(ei)) |
|
862 { |
|
863 arrow_pos = ms.getArrowCoords(ei) + XY(dx, dy); |
|
864 } |
|
865 else |
|
866 { |
|
867 XY moved_node_1(coord_x - dx, coord_y - dy); |
|
868 XY moved_node_2(coord_x, coord_y); |
|
869 Node target = ms.graph.target(ei); |
|
870 XY fix_node = ms.getNodeCoords(target); |
|
871 XY old_arrow_pos(ms.getArrowCoords(ei)); |
|
872 |
|
873 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
|
874 } |
|
875 |
|
876 ms.setArrowCoords(ei, arrow_pos); |
|
877 edgesmap[ei]->draw(); |
|
878 |
|
879 //reposition of edgetext |
|
880 XY text_pos=ms.getArrowCoords(ei); |
|
881 text_pos+=(XY(10,10)); |
|
882 edgetextmap[ei]->property_x().set_value(text_pos.x); |
|
883 edgetextmap[ei]->property_y().set_value(text_pos.y); |
|
884 } |
|
885 |
|
886 for(InEdgeIt ei(ms.graph,moved_node);ei!=INVALID;++ei) |
|
887 { |
|
888 if (ms.graph.source(ei) != ms.graph.target(ei)) |
|
889 { |
|
890 XY moved_node_1(coord_x - dx, coord_y - dy); |
|
891 XY moved_node_2(coord_x, coord_y); |
|
892 Node source = ms.graph.source(ei); |
|
893 XY fix_node = ms.getNodeCoords(source); |
|
894 XY old_arrow_pos(ms.getArrowCoords(ei)); |
|
895 |
865 XY arrow_pos; |
896 XY arrow_pos; |
866 |
897 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
867 if (mytab.mapstorage->graph.source(ei) == mytab.mapstorage->graph.target(ei)) |
898 |
868 { |
899 ms.setArrowCoords(ei, arrow_pos); |
869 arrow_pos = mytab.mapstorage->arrow_pos[ei] + XY(dx, dy); |
|
870 } |
|
871 else |
|
872 { |
|
873 XY moved_node_1(coord_x - dx, coord_y - dy); |
|
874 XY moved_node_2(coord_x, coord_y); |
|
875 Node target = mytab.mapstorage->graph.target(ei); |
|
876 XY fix_node(mytab.mapstorage->coords[target].x, |
|
877 mytab.mapstorage->coords[target].y); |
|
878 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); |
|
879 |
|
880 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
|
881 } |
|
882 |
|
883 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); |
|
884 edgesmap[ei]->draw(); |
900 edgesmap[ei]->draw(); |
885 |
901 |
886 //reposition of edgetext |
902 //reposition of edgetext |
887 XY text_pos=mytab.mapstorage->arrow_pos[ei]; |
903 XY text_pos=ms.getArrowCoords(ei); |
888 text_pos+=(XY(10,10)); |
904 text_pos+=(XY(10,10)); |
889 edgetextmap[ei]->property_x().set_value(text_pos.x); |
905 edgetextmap[ei]->property_x().set_value(text_pos.x); |
890 edgetextmap[ei]->property_y().set_value(text_pos.y); |
906 edgetextmap[ei]->property_y().set_value(text_pos.y); |
891 } |
907 } |
892 |
908 } |
893 for(InEdgeIt ei((mytab.mapstorage)->graph,moved_node);ei!=INVALID;++ei) |
|
894 { |
|
895 if (mytab.mapstorage->graph.source(ei) != mytab.mapstorage->graph.target(ei)) |
|
896 { |
|
897 XY moved_node_1(coord_x - dx, coord_y - dy); |
|
898 XY moved_node_2(coord_x, coord_y); |
|
899 Node source = mytab.mapstorage->graph.source(ei); |
|
900 XY fix_node(mytab.mapstorage->coords[source].x, |
|
901 mytab.mapstorage->coords[source].y); |
|
902 XY old_arrow_pos(mytab.mapstorage->arrow_pos[ei]); |
|
903 |
|
904 XY arrow_pos; |
|
905 arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton); |
|
906 |
|
907 mytab.mapstorage->arrow_pos.set(ei, arrow_pos); |
|
908 edgesmap[ei]->draw(); |
|
909 |
|
910 //reposition of edgetext |
|
911 XY text_pos=mytab.mapstorage->arrow_pos[ei]; |
|
912 text_pos+=(XY(10,10)); |
|
913 edgetextmap[ei]->property_x().set_value(text_pos.x); |
|
914 edgetextmap[ei]->property_y().set_value(text_pos.y); |
|
915 } |
|
916 } |
|
917 } |
909 } |
918 |
910 |
919 Gdk::Color GraphDisplayerCanvas::rainbowColorCounter(double min, double max, double w) |
911 Gdk::Color GraphDisplayerCanvas::rainbowColorCounter(double min, double max, double w) |
920 { |
912 { |
921 Gdk::Color color; |
913 Gdk::Color color; |
926 //rainbow transitions contain 6 phase |
918 //rainbow transitions contain 6 phase |
927 //in each phase only one color is changed |
919 //in each phase only one color is changed |
928 //first we determine the phase, in which |
920 //first we determine the phase, in which |
929 //the actual value belongs to |
921 //the actual value belongs to |
930 for (int i=0;i<=5;i++) |
922 for (int i=0;i<=5;i++) |
931 { |
923 { |
932 if(((double)i/6<pos)&&(pos<=(double(i+1)/6))) |
924 if(((double)i/6<pos)&&(pos<=(double(i+1)/6))) |
933 { |
925 { |
934 phase=i; |
926 phase=i; |
935 } |
927 } |
936 } |
928 } |
937 if(phase<6) |
929 if(phase<6) |
938 { |
930 { |
939 //within its 1/6 long phase the relativ position |
931 //within its 1/6 long phase the relativ position |
940 //determines the power of the color changed in |
932 //determines the power of the color changed in |
941 //that phase |
933 //that phase |
942 //we normalize that to one, to be able to give percentage |
934 //we normalize that to one, to be able to give percentage |
943 //value for the function |
935 //value for the function |
944 double rel_pos=(pos-(phase/6.0))*6.0; |
936 double rel_pos=(pos-(phase/6.0))*6.0; |
945 |
937 |
946 switch(phase) |
938 switch(phase) |
947 { |
939 { |
948 case 0: |
940 case 0: |
949 color.set_rgb_p (1, 0, 1-rel_pos); |
941 color.set_rgb_p (1, 0, 1-rel_pos); |
950 break; |
942 break; |
951 case 1: |
943 case 1: |
952 color.set_rgb_p (1, rel_pos, 0); |
944 color.set_rgb_p (1, rel_pos, 0); |
953 break; |
945 break; |
954 case 2: |
946 case 2: |
955 color.set_rgb_p (1-rel_pos, 1, 0); |
947 color.set_rgb_p (1-rel_pos, 1, 0); |
956 break; |
948 break; |
957 case 3: |
949 case 3: |
958 color.set_rgb_p (0, 1, rel_pos); |
950 color.set_rgb_p (0, 1, rel_pos); |
959 break; |
951 break; |
960 case 4: |
952 case 4: |
961 color.set_rgb_p (0, 1-rel_pos, 1); |
953 color.set_rgb_p (0, 1-rel_pos, 1); |
962 break; |
954 break; |
963 case 5: |
955 case 5: |
964 color.set_rgb_p ((rel_pos/3.0), 0, 1); |
956 color.set_rgb_p ((rel_pos/3.0), 0, 1); |
965 break; |
957 break; |
966 default: |
958 default: |
967 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; |
959 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; |
968 } |
960 } |
969 } |
961 } |
970 else |
962 else |
971 { |
963 { |
972 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; |
964 std::cout << "Wrong phase: " << phase << " " << pos << std::endl; |
973 } |
965 } |
974 return color; |
966 return color; |
975 } |
967 } |