[Lemon-commits] [lemon_svn] ladanyi: r2953 - glemon/trunk
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 21:51:27 CET 2006
Author: ladanyi
Date: Mon Sep 25 09:54:00 2006
New Revision: 2953
Modified:
glemon/trunk/gdc-broken_edge.cc
glemon/trunk/graph_displayer_canvas-event.cc
glemon/trunk/graph_displayer_canvas.cc
glemon/trunk/graph_displayer_canvas.h
glemon/trunk/mapstorage.cc
Log:
LoopEdge improvements.
Modified: glemon/trunk/gdc-broken_edge.cc
==============================================================================
--- glemon/trunk/gdc-broken_edge.cc (original)
+++ glemon/trunk/gdc-broken_edge.cc Mon Sep 25 09:54:00 2006
@@ -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;
}
Modified: glemon/trunk/graph_displayer_canvas-event.cc
==============================================================================
--- glemon/trunk/graph_displayer_canvas-event.cc (original)
+++ glemon/trunk/graph_displayer_canvas-event.cc Mon Sep 25 09:54:00 2006
@@ -409,39 +409,29 @@
//the clicked item is a node, the edge can be drawn
if(target_node!=INVALID)
{
- if(target_node!=active_node)
- {
- (mytab.mapstorage).modified = true;
-
- *(nodesmap[target_node]) <<
- Gnome::Canvas::Properties::fill_color("red");
+ (mytab.mapstorage).modified = true;
- //creating new edge
- active_edge=(mytab.mapstorage).graph.addEdge(active_node,
- target_node);
-
- // update maps
- for (std::map<std::string,
- Graph::EdgeMap<double>*>::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;
+ *(nodesmap[target_node]) <<
+ Gnome::Canvas::Properties::fill_color("red");
- 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));
+ //creating new edge
+ active_edge=(mytab.mapstorage).graph.addEdge(active_node,
+ target_node);
+
+ // update maps
+ for (std::map<std::string,
+ Graph::EdgeMap<double>*>::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)
+ {
// 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.
Modified: glemon/trunk/graph_displayer_canvas.cc
==============================================================================
--- glemon/trunk/graph_displayer_canvas.cc (original)
+++ glemon/trunk/graph_displayer_canvas.cc Mon Sep 25 09:54:00 2006
@@ -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];
Modified: glemon/trunk/graph_displayer_canvas.h
==============================================================================
--- glemon/trunk/graph_displayer_canvas.h (original)
+++ glemon/trunk/graph_displayer_canvas.h Mon Sep 25 09:54:00 2006
@@ -106,6 +106,8 @@
{
private:
Gnome::Canvas::Ellipse line;
+ bool edgeFormerEventHandler(GdkEvent* e);
+ bool isbutton;
public:
LoopEdge(Gnome::Canvas::Group&, Edge, GraphDisplayerCanvas&);
~LoopEdge();
Modified: glemon/trunk/mapstorage.cc
==============================================================================
--- glemon/trunk/mapstorage.cc (original)
+++ glemon/trunk/mapstorage.cc Mon Sep 25 09:54:00 2006
@@ -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;
}
More information about the Lemon-commits
mailing list