[Lemon-commits] [lemon_svn] ladanyi: r2432 - hugo/trunk/gui

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:52:35 CET 2006


Author: ladanyi
Date: Sat Dec 17 21:55:41 2005
New Revision: 2432

Added:
   hugo/trunk/gui/gui_reader.cc
   hugo/trunk/gui/gui_reader.h
   hugo/trunk/gui/gui_writer.cc
   hugo/trunk/gui/gui_writer.h
Modified:
   hugo/trunk/gui/Makefile.am
   hugo/trunk/gui/all_include.h
   hugo/trunk/gui/gdc-broken_edge.cc
   hugo/trunk/gui/graph_displayer_canvas-event.cc
   hugo/trunk/gui/graph_displayer_canvas.cc
   hugo/trunk/gui/graph_displayer_canvas.h
   hugo/trunk/gui/mapstorage.cc
   hugo/trunk/gui/mapstorage.h
   hugo/trunk/gui/xymap.h

Log:
Save and load the coordinates of the arrows on the edges.

Modified: hugo/trunk/gui/Makefile.am
==============================================================================
--- hugo/trunk/gui/Makefile.am	(original)
+++ hugo/trunk/gui/Makefile.am	Sat Dec 17 21:55:41 2005
@@ -28,6 +28,10 @@
 	new_map_win.cc \
 	new_map_win.h \
 	xymap.h \
+	gui_reader.h \
+	gui_reader.cc \
+	gui_writer.h \
+	gui_writer.cc \
 	icons/guipixbufs.h
 
 

Modified: hugo/trunk/gui/all_include.h
==============================================================================
--- hugo/trunk/gui/all_include.h	(original)
+++ hugo/trunk/gui/all_include.h	Sat Dec 17 21:55:41 2005
@@ -37,9 +37,8 @@
 
 using namespace lemon;
 
-typedef xy<double> Coordinates;
+typedef xy<double> XY;
 typedef ListGraph Graph;
-typedef Graph::NodeMap<Coordinates> CoordinatesMap;
 typedef Graph::Node Node;
 typedef Graph::Edge Edge;
 typedef Graph::EdgeIt EdgeIt;

Modified: hugo/trunk/gui/gdc-broken_edge.cc
==============================================================================
--- hugo/trunk/gui/gdc-broken_edge.cc	(original)
+++ hugo/trunk/gui/gdc-broken_edge.cc	Sat Dec 17 21:55:41 2005
@@ -1,15 +1,13 @@
 #include "graph_displayer_canvas.h"
 #include <cmath>
 
-GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false)
+GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Edge _edge, GraphDisplayerCanvas & gc) : Line(g), edge(_edge), gdc(gc), isbutton(false)
 {
-  my_points=new Gnome::Art::Point[3];
-
   arrow=new Gnome::Canvas::Polygon(g);
   *arrow << Gnome::Canvas::Properties::fill_color("red");
   arrow->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler));
   arrow->lower_to_bottom();
-  setPoints(p);
+  draw();
 }
 
 GraphDisplayerCanvas::BrokenEdge::~BrokenEdge()
@@ -17,155 +15,71 @@
   if(arrow)delete(arrow);
 }
 
-void GraphDisplayerCanvas::BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move)
+void GraphDisplayerCanvas::BrokenEdge::draw()
 {
-  bool set_arrow=false;
-  //red arrow losts its position-right button
-  if(!move)
-    {
-      if(p.size()==2)
-	{
-	  set_arrow=true;
-	  Gnome::Canvas::Points points_with_center;
-	  points_with_center.push_back(my_points[0]=p[0]);
-	  points_with_center.push_back(my_points[1]=Gnome::Art::Point( (p[0].get_x()+p[1].get_x())/2+0 , (p[0].get_y()+p[1].get_y())/2 )+0 );
-	  points_with_center.push_back(my_points[2]=p[1]);
-	  property_points().set_value(points_with_center);
-	}  
-      if(p.size()==3)
-	{
-	  set_arrow=true;
-	  property_points().set_value(p);
-	  for(int i=0;i<3;i++)
-	    {
-	      my_points[i]=p[i];
-	    }
-	}
-    }
-  else
-    {
-      //arrow keeps its position-left button
+  MapStorage& ms = gdc.mytab.mapstorage;
 
-//       if(p.size()==2)
-//       	{
-//       	  Gnome::Canvas::Points points;
-//       	  my_points[0]=p[0];
-//       	  my_points[2]=p[1];
-//       	  for(int i=0;i<3;i++)
-//       	    {
-//       	      points.push_back(my_points[i]);
-//       	    }
-//       	  property_points().set_value(points);
-//       	}
-      set_arrow=true;
-
-      //////////////////////////////////////////////////////////////////////////////////////////////////////
-      /////////// keeps shape-with scalar multiplication - version 2.
-      //////////////////////////////////////////////////////////////////////////////////////////////////////
-
-      if(p.size()==2)
-      	{
-	  //old vector from one to the other node - a
-	  xy<double> a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y());
-	  //new vector from one to the other node - b
-	  xy<double> b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y());
-
-	  double absa=sqrt(a_v.normSquare());
-	  double absb=sqrt(b_v.normSquare());
-
-	  if((absa!=0)&&(absb!=0))
-	    {
-	      //old vector from one node to the breakpoint - c
-	      xy<double> c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y());
-
-	      //unit vector with the same direction to a_v
-	      xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
-
-	      //normal vector of unit vector with the same direction to a_v
-	      xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
-
-	      //unit vector with the same direction to b_v
-	      xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
-
-	      //normal vector of unit vector with the same direction to b_v
-	      xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
-
-	      //vector c in a_v_u and a_v_u_n co-ordinate system
-	      xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
-
-	      //new vector from one node to the breakpoint - d - we have to calculate this one
-	      xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
-
-	      my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y());
-
-	      my_points[0]=p[0];
-	      my_points[2]=p[1];
-	  
-	      Gnome::Canvas::Points points;
-	      for(int i=0;i<3;i++)
-		{
-		  points.push_back(my_points[i]);
-		}
-	      property_points().set_value(points);
-	    }
-	  else
-	    {
-	      //if distance is 0, segmentation would be occured
-	      //in calculations, because of division by zero
-	      //But we have luck: the edge cannot be seen in
-	      //this case, so no update needed
-	      set_arrow=false;
-	    }
-	}
+  // update the edge
+  {
+    Gnome::Canvas::Points points;
+    Node source = ms.graph.source(edge);
+    Node target = ms.graph.target(edge);
+    points.push_back(Gnome::Art::Point(ms.coords[source].x,
+          ms.coords[source].y));
+    points.push_back(Gnome::Art::Point(ms.arrow_pos[edge].x,
+          ms.arrow_pos[edge].y));
+    points.push_back(Gnome::Art::Point(ms.coords[target].x,
+          ms.coords[target].y));
+    property_points().set_value(points);
+  }
+
+  // update the arrow
+  {
+    //calculating coordinates of the direction indicator arrow
+    XY target(ms.coords[ms.graph.target(edge)]);
+    XY center(ms.arrow_pos[edge]);
+
+    XY unit_vector_in_dir(target-center);
+    double length=sqrt( unit_vector_in_dir.normSquare() );
+
+    //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
+    unit_vector_in_dir/=length;
+    //       std::cout << " = " << unit_vector_in_dir << std::endl;
+
+    XY unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
+    //       std::cout << unit_norm_vector << std::endl;
+
+    {      
+      //       /\       // top
+      //      /  \      //
+      //      -  -      // c(enter)l(eft), ccl, ccr, cr
+      //       ||       //
+      //       ||       // b(ottom)l, br
     }
-  if(set_arrow)
-    {
-      //calculating coordinates of the direction indicator arrow
 
-      xy<gdouble> target( my_points[2].get_x(), my_points[2].get_y() );
-      xy<gdouble> center( my_points[1].get_x(), my_points[1].get_y() );
+    double size=3;
 
-      xy<gdouble> unit_vector_in_dir(target-center);
-      double length=sqrt( unit_vector_in_dir.normSquare() );
+    XY bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
+    XY br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
+    XY ccl(center + unit_vector_in_dir *  size + unit_norm_vector * size );
+    XY ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
+    XY cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
+    XY cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
+    XY top(center + unit_vector_in_dir * 3 * size);
+
+    //std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
+
+    Gnome::Canvas::Points arrow_points;
+    arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
+    arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
+    arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
+    arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y  ) );
+    arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
+    arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y  ) );
+    arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
 
-      //       std::cout << target << " - " << center << " = " << unit_vector_in_dir << "    / " <<unit_vector_in_dir.normSquare() ;
-      unit_vector_in_dir/=length;
-      //       std::cout << " = " << unit_vector_in_dir << std::endl;
-
-      xy<gdouble> unit_norm_vector(0-unit_vector_in_dir.y, unit_vector_in_dir.x);
-      //       std::cout << unit_norm_vector << std::endl;
-
-      {      
-	//       /\       // top
-	//      /  \      //
-	//      -  -      // c(enter)l(eft), ccl, ccr, cr
-	//       ||       //
-	//       ||       // b(ottom)l, br
-      }
-
-      double size=3;
-
-      xy<gdouble> bl (center - unit_vector_in_dir * 3 * size + unit_norm_vector * size );
-      xy<gdouble> br (center - unit_vector_in_dir * 3 * size - unit_norm_vector * size );
-      xy<gdouble> ccl(center + unit_vector_in_dir *  size + unit_norm_vector * size );
-      xy<gdouble> ccr(center + unit_vector_in_dir *  size - unit_norm_vector * size );
-      xy<gdouble> cl (center + unit_vector_in_dir *  size + unit_norm_vector * 2 * size );
-      xy<gdouble> cr (center + unit_vector_in_dir *  size - unit_norm_vector * 2 * size );
-      xy<gdouble> top(center + unit_vector_in_dir * 3 * size);
-	 
-      //std::cout << bl << " " << br << " " << ccl << " "  << ccr << " " << cl << " " << cr << " " << top << std::endl;
-
-      Gnome::Canvas::Points arrow_points;
-      arrow_points.push_back(Gnome::Art::Point( bl.x , bl.y  ) );
-      arrow_points.push_back(Gnome::Art::Point( br.x , br.y  ) );
-      arrow_points.push_back(Gnome::Art::Point( ccr.x, ccr.y ) );
-      arrow_points.push_back(Gnome::Art::Point( cr.x , cr.y  ) );
-      arrow_points.push_back(Gnome::Art::Point( top.x, top.y ) );
-      arrow_points.push_back(Gnome::Art::Point( cl.x , cl.y  ) );
-      arrow_points.push_back(Gnome::Art::Point( ccl.x, ccl.y ) );
-
-      arrow->property_points().set_value(arrow_points);
-    }
+    arrow->property_points().set_value(arrow_points);
+  }
 }
 
 bool GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler(GdkEvent* e)
@@ -203,12 +117,10 @@
 
 	  Gnome::Canvas::Points points_new;
 
-	  points_new.push_back(my_points[0]);
-	  points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy));
-	  points_new.push_back(my_points[2]);
+          gdc.mytab.mapstorage.arrow_pos.set(edge, gdc.mytab.mapstorage.arrow_pos[edge] + XY(dx, dy));
 
-	  setPoints(points_new);
-	  gdc.textReposition(xy<double>(my_points[1].get_x(),my_points[1].get_y()));
+	  draw();
+	  gdc.textReposition(gdc.mytab.mapstorage.arrow_pos[edge]);
 
 	  clicked_x=e->motion.x;
 	  clicked_y=e->motion.y;
@@ -219,9 +131,3 @@
 
   return true;
 }
-
-xy<double> GraphDisplayerCanvas::BrokenEdge::getArrowPos()
-{
-  xy<double> ret_val(my_points[1].get_x(),my_points[1].get_y());
-  return ret_val;
-}

Modified: hugo/trunk/gui/graph_displayer_canvas-event.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas-event.cc	(original)
+++ hugo/trunk/gui/graph_displayer_canvas-event.cc	Sat Dec 17 21:55:41 2005
@@ -147,12 +147,12 @@
         double coord_x = new_x - (clicked_x - (mytab.mapstorage).coords[active_node].x);
         double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y);
 
-        clicked_x=new_x;
-        clicked_y=new_y;
-
         // write back the new coordinates to the coords map
         (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y));
 
+        clicked_x=new_x;
+        clicked_y=new_y;
+
         // reposition the coordinates text
         std::ostringstream ostr;
         ostr << "(" <<
@@ -183,53 +183,50 @@
 	//all the edges connected to the moved point has to be redrawn
         for(OutEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
         {
-            Gnome::Canvas::Points coos;
-            double x1, x2, y1, y2;
-
-            nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
-            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
-
-            nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
-            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+            XY moved_node_1(coord_x - dx, coord_y - dy);
+            XY moved_node_2(coord_x, coord_y);
+            Node target = mytab.mapstorage.graph.target(ei);
+            XY fix_node(mytab.mapstorage.coords[target].x,
+                        mytab.mapstorage.coords[target].y);
+            XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
 
+            XY arrow_pos;
 	    if(isbutton==3)
-	      {
-		edgesmap[ei]->setPoints(coos);
-	      }
+              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
 	    else
-	      {
-		edgesmap[ei]->setPoints(coos,true);
-	      }
+              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
+
+            mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
+            edgesmap[ei]->draw();
 
 	    //reposition of edgetext
-	    xy<double> text_pos=edgesmap[ei]->getArrowPos();
-	    text_pos+=(xy<double>(10,10));
+	    XY text_pos=mytab.mapstorage.arrow_pos[ei];
+	    text_pos+=(XY(10,10));
 	    edgetextmap[ei]->property_x().set_value(text_pos.x);
 	    edgetextmap[ei]->property_y().set_value(text_pos.y);
         }
 
         for(InEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
         {
-            Gnome::Canvas::Points coos;
-            double x1, x2, y1, y2;
-
-            nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2);
-            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
-
-            nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2);
-            coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+            XY moved_node_1(coord_x - dx, coord_y - dy);
+            XY moved_node_2(coord_x, coord_y);
+            Node source = mytab.mapstorage.graph.source(ei);
+            XY fix_node(mytab.mapstorage.coords[source].x,
+                        mytab.mapstorage.coords[source].y);
+            XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
 
+            XY arrow_pos;
 	    if(isbutton==3)
-	      {
-		edgesmap[ei]->setPoints(coos);
-	      }
+              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, false);
 	    else
-	      {
-		edgesmap[ei]->setPoints(coos,true);
-	      }
+              arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, true);
 
-	    xy<double> text_pos=edgesmap[ei]->getArrowPos();
-	    text_pos+=(xy<double>(10,10));
+            mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
+            edgesmap[ei]->draw();
+
+	    //reposition of edgetext
+	    XY text_pos=mytab.mapstorage.arrow_pos[ei];
+	    text_pos+=(XY(10,10));
 	    edgetextmap[ei]->property_x().set_value(text_pos.x);
 	    edgetextmap[ei]->property_y().set_value(text_pos.y);
         }
@@ -240,6 +237,58 @@
   return false;
 }
 
+XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, bool move)
+{
+  if(!move)
+  {
+    return XY((moved_node_2.x + fix_node.x) / 2.0, (moved_node_2.y + fix_node.y) / 2.0);
+  }
+  else
+  {
+    //////////////////////////////////////////////////////////////////////////////////////////////////////
+    /////////// keeps shape-with scalar multiplication - version 2.
+    //////////////////////////////////////////////////////////////////////////////////////////////////////
+
+    //old vector from one to the other node - a
+    xy<double> a_v(moved_node_1.x-fix_node.x,moved_node_1.y-fix_node.y);
+    //new vector from one to the other node - b
+    xy<double> b_v(moved_node_2.x-fix_node.x,moved_node_2.y-fix_node.y);
+
+    double absa=sqrt(a_v.normSquare());
+    double absb=sqrt(b_v.normSquare());
+
+    if ((absa == 0.0) || (absb == 0.0))
+    {
+      return old_arrow_pos;
+    }
+    else
+    {
+      //old vector from one node to the breakpoint - c
+      xy<double> c_v(old_arrow_pos.x-fix_node.x,old_arrow_pos.y-fix_node.y);
+
+      //unit vector with the same direction to a_v
+      xy<double> a_v_u(a_v.x/absa,a_v.y/absa);
+
+      //normal vector of unit vector with the same direction to a_v
+      xy<double> a_v_u_n(((-1)*a_v_u.y),a_v_u.x);
+
+      //unit vector with the same direction to b_v
+      xy<double> b_v_u(b_v.x/absb,b_v.y/absb);
+
+      //normal vector of unit vector with the same direction to b_v
+      xy<double> b_v_u_n(((-1)*b_v_u.y),b_v_u.x);
+
+      //vector c in a_v_u and a_v_u_n co-ordinate system
+      xy<double> c_a(c_v*a_v_u,c_v*a_v_u_n);
+
+      //new vector from one node to the breakpoint - d - we have to calculate this one
+      xy<double> d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n);
+
+      return XY(d_v.x+fix_node.x,d_v.y+fix_node.y);
+    }
+  }
+}
+
 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
 {
   switch(e->type)
@@ -405,7 +454,7 @@
               coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
 
               //drawing new edge
-              edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,
+              edgesmap[active_edge]=new BrokenEdge(displayed_graph, active_edge,
                   *this);
               *(edgesmap[active_edge]) <<
                 Gnome::Canvas::Properties::fill_color("green");
@@ -414,8 +463,8 @@
               edgesmap[active_edge]->lower_to_bottom();
 
               //initializing edge-text as well, to empty string
-              xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
-              text_pos+=(xy<double>(10,10));
+              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, "");

Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc	(original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc	Sat Dec 17 21:55:41 2005
@@ -168,15 +168,15 @@
           (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].x,
           (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y));
     
-    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
+    edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
     *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
     edgesmap[i]->property_width_units().set_value(10);    
     edgesmap[i]->lower_to_bottom();
     
     //initializing edge-text as well, to empty string
 
-    xy<double> text_pos=edgesmap[i]->getArrowPos();
-    text_pos+=(xy<double>(10,10));
+    XY text_pos=mytab.mapstorage.arrow_pos[i];
+    text_pos+=(XY(10,10));
 
     edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
     edgetextmap[i]->property_fill_color().set_value("darkgreen");

Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h	(original)
+++ hugo/trunk/gui/graph_displayer_canvas.h	Sat Dec 17 21:55:41 2005
@@ -14,12 +14,13 @@
 ///This class is the canvas, on which the graph can be drawn.
 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
 {
+  friend class BrokenEdge;
+
   class BrokenEdge : public Gnome::Canvas::Line
   {
+    Edge edge;
     GraphDisplayerCanvas & gdc;
     Gnome::Canvas::Polygon * arrow;
-    Gnome::Art::Point * my_points;
-
 
     ///Indicates whether the button of mouse is pressed or not
     bool isbutton;
@@ -31,10 +32,9 @@
     ///event handler for forming edges
     bool edgeFormerEventHandler(GdkEvent*);
   public:
-    BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &);
+    BrokenEdge(Gnome::Canvas::Group &, Edge, GraphDisplayerCanvas &);
     ~BrokenEdge();
-    void setPoints(Gnome::Canvas::Points, bool move=false);
-    xy<double> getArrowPos();
+    void draw();
   };
   typedef Gnome::Canvas::CanvasAA Parent;
 
@@ -200,6 +200,7 @@
   ///reference to the parent window
   NoteBookTab & mytab;
 
+  XY GraphDisplayerCanvas::calcArrowPos(XY, XY, XY, XY, bool);
 };
 
 #endif //GRAPH_DISPLAYER_CANVAS_H

Added: hugo/trunk/gui/gui_reader.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/gui/gui_reader.cc	Sat Dec 17 21:55:41 2005
@@ -0,0 +1,33 @@
+#include "gui_reader.h"
+#include "xml.h"
+#include "mapstorage.h"
+#include <lemon/xy.h>
+#include <vector>
+
+bool GuiReader::header(const std::string& line)
+{
+  std::istringstream ls(line);
+  std::string head;
+  ls >> head;
+  return head == "@gui";
+}
+
+void GuiReader::read(std::istream& is)
+{
+  XmlIo x(is);
+  std::map<int, xy<double> > m;
+  x("arrow_pos", m);
+
+  if ((int)m.size() != countEdges(mapstorage->graph)) return;
+
+  for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
+  {
+    int edgeid = (int)(*mapstorage->edgemap_storage["id"])[e];
+    mapstorage->arrow_pos.set(e, m[edgeid]);
+  }
+  mapstorage->ArrowPosReadOK();
+}
+
+GuiReader::GuiReader(LemonReader& reader, MapStorage* ms) : Parent(reader), mapstorage(ms)
+{
+}

Added: hugo/trunk/gui/gui_reader.h
==============================================================================
--- (empty file)
+++ hugo/trunk/gui/gui_reader.h	Sat Dec 17 21:55:41 2005
@@ -0,0 +1,21 @@
+#ifndef GUI_READER_H
+#define GUI_READER_H
+
+#include "mapstorage.h"
+#include <lemon/lemon_reader.h>
+
+using lemon::LemonReader;
+
+class GuiReader : public LemonReader::SectionReader
+{
+  private:
+    MapStorage* mapstorage;
+  protected:
+    virtual bool header(const std::string&);
+    virtual void read(std::istream&);
+  public:
+    typedef LemonReader::SectionReader Parent;
+    GuiReader(LemonReader&, MapStorage*);
+};
+
+#endif

Added: hugo/trunk/gui/gui_writer.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/gui/gui_writer.cc	Sat Dec 17 21:55:41 2005
@@ -0,0 +1,26 @@
+#include "gui_writer.h"
+#include "xml.h"
+#include "mapstorage.h"
+#include <lemon/xy.h>
+#include <vector>
+
+std::string GuiWriter::header()
+{
+  return "@gui";
+}
+
+void GuiWriter::write(std::ostream& os)
+{
+  XmlIo x(os);
+  std::map<int, xy<double> > m;
+  for (EdgeIt e(mapstorage->graph); e != INVALID; ++e)
+  {
+    int edgeid = (int)(*(mapstorage->edgemap_storage["id"]))[e];
+    m[edgeid] = mapstorage->arrow_pos[e];
+  }
+  x("arrow_pos", m);
+}
+
+GuiWriter::GuiWriter(LemonWriter& writer, MapStorage* ms) : Parent(writer), mapstorage(ms)
+{
+}

Added: hugo/trunk/gui/gui_writer.h
==============================================================================
--- (empty file)
+++ hugo/trunk/gui/gui_writer.h	Sat Dec 17 21:55:41 2005
@@ -0,0 +1,21 @@
+#ifndef GUI_WRITER_H
+#define GUI_WRITER_H
+
+#include "mapstorage.h"
+#include <lemon/lemon_writer.h>
+
+using lemon::LemonWriter;
+
+class GuiWriter : public LemonWriter::SectionWriter
+{
+  private:
+    MapStorage* mapstorage;
+  protected:
+    virtual std::string header();
+    virtual void write(std::ostream&);
+  public:
+    typedef LemonWriter::SectionWriter Parent;
+    GuiWriter(LemonWriter&, MapStorage*);
+};
+
+#endif

Modified: hugo/trunk/gui/mapstorage.cc
==============================================================================
--- hugo/trunk/gui/mapstorage.cc	(original)
+++ hugo/trunk/gui/mapstorage.cc	Sat Dec 17 21:55:41 2005
@@ -1,16 +1,23 @@
 #include "mapstorage.h"
+#include "gui_writer.h"
+#include "gui_reader.h"
 #include <gtkmm.h>
 #include <cmath>
 
 #include <cmath>
 
-MapStorage::MapStorage() : modified(false), file_name("")
+MapStorage::MapStorage() : modified(false), file_name(""), arrow_pos_read_ok(false)
 {
   nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
   coords.setXMap(*nodemap_storage["coordinates_x"]);
   nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
   coords.setYMap(*nodemap_storage["coordinates_y"]);
 
+  edgemap_storage["arrow_pos_x"] = new Graph::EdgeMap<double>(graph);
+  arrow_pos.setXMap(*edgemap_storage["arrow_pos_x"]);
+  edgemap_storage["arrow_pos_y"] = new Graph::EdgeMap<double>(graph);
+  arrow_pos.setYMap(*edgemap_storage["arrow_pos_y"]);
+
   nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
   edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
 
@@ -247,6 +254,7 @@
       }
       greader.readEdgeMap(*it, *edgemap_storage[*it]);
     }
+    GuiReader gui_reader(greader, this);
     greader.run();
   } catch (DataFormatError& error) {
     Gtk::MessageDialog mdialog(error.what());
@@ -283,6 +291,15 @@
     }
   }
 
+  if (!arrow_pos_read_ok)
+  {
+    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);
+    }
+  }
+
   // fill in the default values for the maps
   for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
@@ -338,14 +355,19 @@
       nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
   {
     gwriter.writeNodeMap(it->first, *(it->second));
-    //std::cout << "wrote " << it->first << " nodemap" << std::endl;
   }
   for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   {
-    gwriter.writeEdgeMap(it->first, *(it->second));
-    //std::cout << "wrote " << it->first << " edgemap" << std::endl;
+    if ((it->first != "arrow_pos_x") &&
+        (it->first != "arrow_pos_y"))
+    {
+      gwriter.writeEdgeMap(it->first, *(it->second));
+    }
   }
+
+  GuiWriter gui_writer(gwriter, this);
+
   gwriter.run();
 }
 
@@ -365,7 +387,9 @@
   for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
       edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
   {
-    if (it->first != "id")
+    if ((it->first != "id") &&
+        (it->first != "arrow_pos_x") &&
+        (it->first != "arrow_pos_y"))
     {
       delete it->second;
       edgemap_storage.erase(it);
@@ -387,3 +411,8 @@
   file_name = "";
   modified = false;
 }
+
+void MapStorage::ArrowPosReadOK()
+{
+  arrow_pos_read_ok = true;
+}

Modified: hugo/trunk/gui/mapstorage.h
==============================================================================
--- hugo/trunk/gui/mapstorage.h	(original)
+++ hugo/trunk/gui/mapstorage.h	Sat Dec 17 21:55:41 2005
@@ -23,7 +23,10 @@
 public:
 
   Graph graph;
+  /// the coordinates of the nodes
   XYMap<Graph::NodeMap<double> > coords;
+  /// the coordinates of the arrows on the edges
+  XYMap<Graph::EdgeMap<double> > arrow_pos;
 
   bool modified;
   std::string file_name;
@@ -52,6 +55,8 @@
   // Default values for the maps
   std::map< std::string, double > edgemap_default;
 
+  bool arrow_pos_read_ok;
+
 protected:
   typedef sigc::signal<void, bool, int> Signal_Prop;
   Signal_Prop signal_prop;
@@ -127,6 +132,8 @@
   void writeToFile(const std::string &);
 
   void clear();
+
+  void ArrowPosReadOK();
 };
 
 #endif //MAPSTORAGE_H

Modified: hugo/trunk/gui/xymap.h
==============================================================================
--- hugo/trunk/gui/xymap.h	(original)
+++ hugo/trunk/gui/xymap.h	Sat Dec 17 21:55:41 2005
@@ -4,9 +4,6 @@
 #include <lemon/list_graph.h>
 #include <lemon/xy.h>
 
-using lemon::ListGraph;
-using lemon::xy;
-
 template<class M>
 class XYMap
 {
@@ -15,7 +12,7 @@
 
   public:
     typedef typename M::Key Key;
-    typedef xy<typename M::Value> Value;
+    typedef lemon::xy<typename M::Value> Value;
     XYMap() {}
     XYMap(M &_xmap, M &_ymap) : xmap(&_xmap), ymap(&_ymap) {}
     void setXMap(M &_xmap) { xmap = &_xmap; }



More information about the Lemon-commits mailing list