# HG changeset patch # User ladanyi # Date 1159170840 0 # Node ID 72f1c33f89d41a613d0c8e970ef07381702173d3 # Parent 86273bfe0e4d9b29e24341b8eb51dba4abddb44f LoopEdge improvements. diff -r 86273bfe0e4d -r 72f1c33f89d4 gdc-broken_edge.cc --- a/gdc-broken_edge.cc Thu Sep 21 10:29:29 2006 +0000 +++ b/gdc-broken_edge.cc Mon Sep 25 07:54:00 2006 +0000 @@ -155,10 +155,12 @@ GraphDisplayerCanvas::LoopEdge::LoopEdge(Gnome::Canvas::Group& _group, Edge _edge, GraphDisplayerCanvas& _canvas) : - EdgeBase(_group, _edge, _canvas), line(*this) + EdgeBase(_group, _edge, _canvas), line(*this), isbutton(false) { - line.property_fill_color().set_value("green"); - line.property_width_units().set_value(10); + arrow.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::LoopEdge::edgeFormerEventHandler)); + + line.property_outline_color().set_value("green"); + line.property_width_units().set_value(10); line.lower_to_bottom(); draw(); @@ -199,5 +201,36 @@ void GraphDisplayerCanvas::LoopEdge::setFillColor(Gdk::Color c) { - line.property_fill_color_gdk().set_value(c); + line.property_outline_color_gdk().set_value(c); } + +bool GraphDisplayerCanvas::LoopEdge::edgeFormerEventHandler(GdkEvent* e) +{ + switch(e->type) + { + case GDK_BUTTON_PRESS: + if(canvas.getActualTool()!=CREATE_NODE) + { + canvas.toggleEdgeActivity(this, true); + isbutton=true; + } + break; + case GDK_BUTTON_RELEASE: + if(canvas.getActualTool()!=CREATE_NODE) + { + canvas.toggleEdgeActivity(this, false); + isbutton=false; + } + break; + case GDK_MOTION_NOTIFY: + if(isbutton) + { + canvas.mytab.mapstorage.arrow_pos.set(edge, XY(e->motion.x, e->motion.y)); + + draw(); + canvas.textReposition(canvas.mytab.mapstorage.arrow_pos[edge]); + } + default: break; + } + return true; +} diff -r 86273bfe0e4d -r 72f1c33f89d4 graph_displayer_canvas-event.cc --- a/graph_displayer_canvas-event.cc Thu Sep 21 10:29:29 2006 +0000 +++ b/graph_displayer_canvas-event.cc Mon Sep 25 07:54:00 2006 +0000 @@ -409,39 +409,29 @@ //the clicked item is a node, the edge can be drawn if(target_node!=INVALID) { + (mytab.mapstorage).modified = true; + + *(nodesmap[target_node]) << + Gnome::Canvas::Properties::fill_color("red"); + + //creating new edge + active_edge=(mytab.mapstorage).graph.addEdge(active_node, + target_node); + + // update maps + for (std::map*>::const_iterator it = + (mytab.mapstorage).edgemap_storage.begin(); it != + (mytab.mapstorage).edgemap_storage.end(); ++it) + { + (*(it->second))[active_edge] = + (mytab.mapstorage).edgemap_default[it->first]; + } + // increment the id map's default value + (mytab.mapstorage).edgemap_default["label"] += 1.0; + if(target_node!=active_node) { - (mytab.mapstorage).modified = true; - - *(nodesmap[target_node]) << - Gnome::Canvas::Properties::fill_color("red"); - - //creating new edge - active_edge=(mytab.mapstorage).graph.addEdge(active_node, - target_node); - - // update maps - for (std::map*>::const_iterator it = - (mytab.mapstorage).edgemap_storage.begin(); it != - (mytab.mapstorage).edgemap_storage.end(); ++it) - { - (*(it->second))[active_edge] = - (mytab.mapstorage).edgemap_default[it->first]; - } - // increment the id map's default value - (mytab.mapstorage).edgemap_default["label"] += 1.0; - - //calculating coordinates of new edge - Gnome::Canvas::Points coos; - double x1, x2, y1, y2; - - active_item->get_bounds(x1, y1, x2, y2); - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - - target_item->get_bounds(x1, y1, x2, y2); - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - // set the coordinates of the arrow on the new edge MapStorage& ms = mytab.mapstorage; ms.arrow_pos.set(active_edge, @@ -451,26 +441,31 @@ //drawing new edge edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge, *this); - - //initializing edge-text as well, to empty string - XY text_pos=mytab.mapstorage.arrow_pos[active_edge]; - text_pos+=(XY(10,10)); - - edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, - text_pos.x, text_pos.y, ""); - edgetextmap[active_edge]->property_fill_color().set_value( - "darkgreen"); - edgetextmap[active_edge]->raise_to_top(); - - //updating its properties -// mapwin.updateEdge(active_edge); - propertyUpdate(active_edge); } else { - target_node=INVALID; - std::cerr << "Loop edge is not yet implemented!" << std::endl; + // set the coordinates of the arrow on the new edge + MapStorage& ms = mytab.mapstorage; + ms.arrow_pos.set(active_edge, + (ms.coords[ms.graph.source(active_edge)] + + XY(0.0, 80.0))); + + //drawing new edge + edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge, + *this); } + + //initializing edge-text as well, to empty string + XY text_pos=mytab.mapstorage.arrow_pos[active_edge]; + text_pos+=(XY(10,10)); + + edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, + text_pos.x, text_pos.y, ""); + edgetextmap[active_edge]->property_fill_color().set_value( + "darkgreen"); + edgetextmap[active_edge]->raise_to_top(); + + propertyUpdate(active_edge); } //clicked item was not a node. it could be an e.g. edge. we do not //deal with it furthermore. diff -r 86273bfe0e4d -r 72f1c33f89d4 graph_displayer_canvas.cc --- a/graph_displayer_canvas.cc Thu Sep 21 10:29:29 2006 +0000 +++ b/graph_displayer_canvas.cc Mon Sep 25 07:54:00 2006 +0000 @@ -157,19 +157,14 @@ for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) { - - //drawing green lines, coordinates are from mapstorage.coords - - Gnome::Canvas::Points coos; - coos.push_back(Gnome::Art::Point( - (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].x, - (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].y)); - coos.push_back(Gnome::Art::Point( - (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].x, - (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y)); - - edgesmap[i]=new BrokenEdge(displayed_graph, i, *this); - + if (mytab.mapstorage.graph.source(i) == mytab.mapstorage.graph.target(i)) + { + edgesmap[i]=new LoopEdge(displayed_graph, i, *this); + } + else + { + edgesmap[i]=new BrokenEdge(displayed_graph, i, *this); + } //initializing edge-text as well, to empty string XY text_pos=mytab.mapstorage.arrow_pos[i]; diff -r 86273bfe0e4d -r 72f1c33f89d4 graph_displayer_canvas.h --- a/graph_displayer_canvas.h Thu Sep 21 10:29:29 2006 +0000 +++ b/graph_displayer_canvas.h Mon Sep 25 07:54:00 2006 +0000 @@ -106,6 +106,8 @@ { private: Gnome::Canvas::Ellipse line; + bool edgeFormerEventHandler(GdkEvent* e); + bool isbutton; public: LoopEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&); ~LoopEdge(); diff -r 86273bfe0e4d -r 72f1c33f89d4 mapstorage.cc --- a/mapstorage.cc Thu Sep 21 10:29:29 2006 +0000 +++ b/mapstorage.cc Mon Sep 25 07:54:00 2006 +0000 @@ -319,7 +319,14 @@ arrow_pos_read_ok = false; for (EdgeIt e(graph); e != INVALID; ++e) { - arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0); + if (graph.source(e) == graph.target(e)) + { + arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0)); + } + else + { + arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0); + } } } @@ -367,20 +374,6 @@ } } - // filter loop edges - for (EdgeIt e(graph); e != INVALID; ++e) - { - if (graph.source(e) == graph.target(e)) - { - std::cerr << "Removed loop edge " << (*edgemap_storage["label"])[e] - << " (from " << (*nodemap_storage["label"])[graph.source(e)] - << ", to " << (*nodemap_storage["label"])[graph.target(e)] << ")." - << std::endl; - - graph.erase(e); - } - } - return 0; }