LoopEdge improvements.
1.1 --- a/gdc-broken_edge.cc Thu Sep 21 10:29:29 2006 +0000
1.2 +++ b/gdc-broken_edge.cc Mon Sep 25 07:54:00 2006 +0000
1.3 @@ -155,10 +155,12 @@
1.4
1.5 GraphDisplayerCanvas::LoopEdge::LoopEdge(Gnome::Canvas::Group& _group,
1.6 Edge _edge, GraphDisplayerCanvas& _canvas) :
1.7 - EdgeBase(_group, _edge, _canvas), line(*this)
1.8 + EdgeBase(_group, _edge, _canvas), line(*this), isbutton(false)
1.9 {
1.10 - line.property_fill_color().set_value("green");
1.11 - line.property_width_units().set_value(10);
1.12 + arrow.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::LoopEdge::edgeFormerEventHandler));
1.13 +
1.14 + line.property_outline_color().set_value("green");
1.15 + line.property_width_units().set_value(10);
1.16 line.lower_to_bottom();
1.17
1.18 draw();
1.19 @@ -199,5 +201,36 @@
1.20
1.21 void GraphDisplayerCanvas::LoopEdge::setFillColor(Gdk::Color c)
1.22 {
1.23 - line.property_fill_color_gdk().set_value(c);
1.24 + line.property_outline_color_gdk().set_value(c);
1.25 }
1.26 +
1.27 +bool GraphDisplayerCanvas::LoopEdge::edgeFormerEventHandler(GdkEvent* e)
1.28 +{
1.29 + switch(e->type)
1.30 + {
1.31 + case GDK_BUTTON_PRESS:
1.32 + if(canvas.getActualTool()!=CREATE_NODE)
1.33 + {
1.34 + canvas.toggleEdgeActivity(this, true);
1.35 + isbutton=true;
1.36 + }
1.37 + break;
1.38 + case GDK_BUTTON_RELEASE:
1.39 + if(canvas.getActualTool()!=CREATE_NODE)
1.40 + {
1.41 + canvas.toggleEdgeActivity(this, false);
1.42 + isbutton=false;
1.43 + }
1.44 + break;
1.45 + case GDK_MOTION_NOTIFY:
1.46 + if(isbutton)
1.47 + {
1.48 + canvas.mytab.mapstorage.arrow_pos.set(edge, XY(e->motion.x, e->motion.y));
1.49 +
1.50 + draw();
1.51 + canvas.textReposition(canvas.mytab.mapstorage.arrow_pos[edge]);
1.52 + }
1.53 + default: break;
1.54 + }
1.55 + return true;
1.56 +}
2.1 --- a/graph_displayer_canvas-event.cc Thu Sep 21 10:29:29 2006 +0000
2.2 +++ b/graph_displayer_canvas-event.cc Mon Sep 25 07:54:00 2006 +0000
2.3 @@ -409,39 +409,29 @@
2.4 //the clicked item is a node, the edge can be drawn
2.5 if(target_node!=INVALID)
2.6 {
2.7 + (mytab.mapstorage).modified = true;
2.8 +
2.9 + *(nodesmap[target_node]) <<
2.10 + Gnome::Canvas::Properties::fill_color("red");
2.11 +
2.12 + //creating new edge
2.13 + active_edge=(mytab.mapstorage).graph.addEdge(active_node,
2.14 + target_node);
2.15 +
2.16 + // update maps
2.17 + for (std::map<std::string,
2.18 + Graph::EdgeMap<double>*>::const_iterator it =
2.19 + (mytab.mapstorage).edgemap_storage.begin(); it !=
2.20 + (mytab.mapstorage).edgemap_storage.end(); ++it)
2.21 + {
2.22 + (*(it->second))[active_edge] =
2.23 + (mytab.mapstorage).edgemap_default[it->first];
2.24 + }
2.25 + // increment the id map's default value
2.26 + (mytab.mapstorage).edgemap_default["label"] += 1.0;
2.27 +
2.28 if(target_node!=active_node)
2.29 {
2.30 - (mytab.mapstorage).modified = true;
2.31 -
2.32 - *(nodesmap[target_node]) <<
2.33 - Gnome::Canvas::Properties::fill_color("red");
2.34 -
2.35 - //creating new edge
2.36 - active_edge=(mytab.mapstorage).graph.addEdge(active_node,
2.37 - target_node);
2.38 -
2.39 - // update maps
2.40 - for (std::map<std::string,
2.41 - Graph::EdgeMap<double>*>::const_iterator it =
2.42 - (mytab.mapstorage).edgemap_storage.begin(); it !=
2.43 - (mytab.mapstorage).edgemap_storage.end(); ++it)
2.44 - {
2.45 - (*(it->second))[active_edge] =
2.46 - (mytab.mapstorage).edgemap_default[it->first];
2.47 - }
2.48 - // increment the id map's default value
2.49 - (mytab.mapstorage).edgemap_default["label"] += 1.0;
2.50 -
2.51 - //calculating coordinates of new edge
2.52 - Gnome::Canvas::Points coos;
2.53 - double x1, x2, y1, y2;
2.54 -
2.55 - active_item->get_bounds(x1, y1, x2, y2);
2.56 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.57 -
2.58 - target_item->get_bounds(x1, y1, x2, y2);
2.59 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.60 -
2.61 // set the coordinates of the arrow on the new edge
2.62 MapStorage& ms = mytab.mapstorage;
2.63 ms.arrow_pos.set(active_edge,
2.64 @@ -451,26 +441,31 @@
2.65 //drawing new edge
2.66 edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
2.67 *this);
2.68 -
2.69 - //initializing edge-text as well, to empty string
2.70 - XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
2.71 - text_pos+=(XY(10,10));
2.72 -
2.73 - edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
2.74 - text_pos.x, text_pos.y, "");
2.75 - edgetextmap[active_edge]->property_fill_color().set_value(
2.76 - "darkgreen");
2.77 - edgetextmap[active_edge]->raise_to_top();
2.78 -
2.79 - //updating its properties
2.80 -// mapwin.updateEdge(active_edge);
2.81 - propertyUpdate(active_edge);
2.82 }
2.83 else
2.84 {
2.85 - target_node=INVALID;
2.86 - std::cerr << "Loop edge is not yet implemented!" << std::endl;
2.87 + // set the coordinates of the arrow on the new edge
2.88 + MapStorage& ms = mytab.mapstorage;
2.89 + ms.arrow_pos.set(active_edge,
2.90 + (ms.coords[ms.graph.source(active_edge)] +
2.91 + XY(0.0, 80.0)));
2.92 +
2.93 + //drawing new edge
2.94 + edgesmap[active_edge]=new LoopEdge(displayed_graph, active_edge,
2.95 + *this);
2.96 }
2.97 +
2.98 + //initializing edge-text as well, to empty string
2.99 + XY text_pos=mytab.mapstorage.arrow_pos[active_edge];
2.100 + text_pos+=(XY(10,10));
2.101 +
2.102 + edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
2.103 + text_pos.x, text_pos.y, "");
2.104 + edgetextmap[active_edge]->property_fill_color().set_value(
2.105 + "darkgreen");
2.106 + edgetextmap[active_edge]->raise_to_top();
2.107 +
2.108 + propertyUpdate(active_edge);
2.109 }
2.110 //clicked item was not a node. it could be an e.g. edge. we do not
2.111 //deal with it furthermore.
3.1 --- a/graph_displayer_canvas.cc Thu Sep 21 10:29:29 2006 +0000
3.2 +++ b/graph_displayer_canvas.cc Mon Sep 25 07:54:00 2006 +0000
3.3 @@ -157,19 +157,14 @@
3.4
3.5 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
3.6 {
3.7 -
3.8 - //drawing green lines, coordinates are from mapstorage.coords
3.9 -
3.10 - Gnome::Canvas::Points coos;
3.11 - coos.push_back(Gnome::Art::Point(
3.12 - (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].x,
3.13 - (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].y));
3.14 - coos.push_back(Gnome::Art::Point(
3.15 - (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].x,
3.16 - (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y));
3.17 -
3.18 - edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
3.19 -
3.20 + if (mytab.mapstorage.graph.source(i) == mytab.mapstorage.graph.target(i))
3.21 + {
3.22 + edgesmap[i]=new LoopEdge(displayed_graph, i, *this);
3.23 + }
3.24 + else
3.25 + {
3.26 + edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
3.27 + }
3.28 //initializing edge-text as well, to empty string
3.29
3.30 XY text_pos=mytab.mapstorage.arrow_pos[i];
4.1 --- a/graph_displayer_canvas.h Thu Sep 21 10:29:29 2006 +0000
4.2 +++ b/graph_displayer_canvas.h Mon Sep 25 07:54:00 2006 +0000
4.3 @@ -106,6 +106,8 @@
4.4 {
4.5 private:
4.6 Gnome::Canvas::Ellipse line;
4.7 + bool edgeFormerEventHandler(GdkEvent* e);
4.8 + bool isbutton;
4.9 public:
4.10 LoopEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
4.11 ~LoopEdge();
5.1 --- a/mapstorage.cc Thu Sep 21 10:29:29 2006 +0000
5.2 +++ b/mapstorage.cc Mon Sep 25 07:54:00 2006 +0000
5.3 @@ -319,7 +319,14 @@
5.4 arrow_pos_read_ok = false;
5.5 for (EdgeIt e(graph); e != INVALID; ++e)
5.6 {
5.7 - arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
5.8 + if (graph.source(e) == graph.target(e))
5.9 + {
5.10 + arrow_pos.set(e, coords[graph.source(e)] + XY(0.0, 80.0));
5.11 + }
5.12 + else
5.13 + {
5.14 + arrow_pos.set(e, (coords[graph.source(e)] + coords[graph.target(e)]) / 2.0);
5.15 + }
5.16 }
5.17 }
5.18
5.19 @@ -367,20 +374,6 @@
5.20 }
5.21 }
5.22
5.23 - // filter loop edges
5.24 - for (EdgeIt e(graph); e != INVALID; ++e)
5.25 - {
5.26 - if (graph.source(e) == graph.target(e))
5.27 - {
5.28 - std::cerr << "Removed loop edge " << (*edgemap_storage["label"])[e]
5.29 - << " (from " << (*nodemap_storage["label"])[graph.source(e)]
5.30 - << ", to " << (*nodemap_storage["label"])[graph.target(e)] << ")."
5.31 - << std::endl;
5.32 -
5.33 - graph.erase(e);
5.34 - }
5.35 - }
5.36 -
5.37 return 0;
5.38 }
5.39