graph_displayer_canvas.cc
changeset 194 6b2b718420eb
parent 190 2cac5b936a2b
child 201 879e47e5b731
     1.1 --- a/graph_displayer_canvas.cc	Wed Feb 28 15:19:20 2007 +0000
     1.2 +++ b/graph_displayer_canvas.cc	Wed Feb 28 18:20:28 2007 +0000
     1.3 @@ -16,13 +16,15 @@
     1.4   *
     1.5   */
     1.6  
     1.7 -#include "graph_displayer_canvas.h"
     1.8 +#include <mapstorage.h>
     1.9 +#include <nbtab.h>
    1.10 +#include <graph_displayer_canvas.h>
    1.11  #include <lemon/random.h>
    1.12  #include <cmath>
    1.13  
    1.14  GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) :
    1.15 -  nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
    1.16 -  nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
    1.17 +  nodesmap(mainw.mapstorage->graph), edgesmap(mainw.mapstorage->graph), edgetextmap(mainw.mapstorage->graph),
    1.18 +  nodetextmap(mainw.mapstorage->graph), displayed_graph(*(root()), 0, 0),
    1.19    isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
    1.20    edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10),
    1.21    was_redesigned(false), is_drawn(false), mytab(mainw),
    1.22 @@ -49,11 +51,11 @@
    1.23    {
    1.24      delete background;
    1.25    }
    1.26 -  if (mytab.mapstorage.isBackgroundSet())
    1.27 +  if (mytab.mapstorage->isBackgroundSet())
    1.28    {
    1.29      background_set = true;
    1.30      refBackground = Gdk::Pixbuf::create_from_file(
    1.31 -      mytab.mapstorage.getBackgroundFilename());
    1.32 +      mytab.mapstorage->getBackgroundFilename());
    1.33      background = new Gnome::Canvas::Pixbuf(
    1.34          *(root()),
    1.35          0.0 - refBackground->get_width() / 2.0,
    1.36 @@ -69,13 +71,13 @@
    1.37  
    1.38  GraphDisplayerCanvas::~GraphDisplayerCanvas()
    1.39  {
    1.40 -  for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
    1.41 +  for (NodeIt n((mytab.mapstorage)->graph); n != INVALID; ++n)
    1.42      {
    1.43        delete nodesmap[n];
    1.44        delete nodetextmap[n];
    1.45      }
    1.46    
    1.47 -  for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
    1.48 +  for (EdgeIt e((mytab.mapstorage)->graph); e != INVALID; ++e)
    1.49      {
    1.50        delete edgesmap[e];
    1.51        delete edgetextmap[e];
    1.52 @@ -118,7 +120,7 @@
    1.53      {
    1.54        if(mapname!="")
    1.55  	{
    1.56 -	  if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
    1.57 +	  if( ( ((mytab.mapstorage)->nodemap_storage).find(mapname) != ((mytab.mapstorage)->nodemap_storage).end() ) )
    1.58  	    {
    1.59  	      switch(prop)
    1.60  		{
    1.61 @@ -165,7 +167,7 @@
    1.62      {
    1.63        if(mapname!="")
    1.64  	{
    1.65 -	  if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
    1.66 +	  if( ( ((mytab.mapstorage)->edgemap_storage).find(mapname) != ((mytab.mapstorage)->edgemap_storage).end() ) )
    1.67  	    {
    1.68  	      switch(prop)
    1.69  		{
    1.70 @@ -207,9 +209,9 @@
    1.71  {
    1.72    //first edges are drawn, to hide joining with nodes later
    1.73  
    1.74 -  for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    1.75 +  for (EdgeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    1.76    {
    1.77 -    if (mytab.mapstorage.graph.source(i) == mytab.mapstorage.graph.target(i))
    1.78 +    if (mytab.mapstorage->graph.source(i) == mytab.mapstorage->graph.target(i))
    1.79      {
    1.80        edgesmap[i]=new LoopEdge(displayed_graph, i, *this);
    1.81      }
    1.82 @@ -219,7 +221,7 @@
    1.83      }
    1.84      //initializing edge-text as well, to empty string
    1.85  
    1.86 -    XY text_pos=mytab.mapstorage.arrow_pos[i];
    1.87 +    XY text_pos=mytab.mapstorage->arrow_pos[i];
    1.88      text_pos+=(XY(10,10));
    1.89  
    1.90      edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
    1.91 @@ -230,16 +232,16 @@
    1.92  
    1.93    //afterwards nodes come to be drawn
    1.94  
    1.95 -  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    1.96 +  for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    1.97    {
    1.98      //drawing bule nodes, with black line around them
    1.99  
   1.100      nodesmap[i]=new Gnome::Canvas::Ellipse(
   1.101          displayed_graph,
   1.102 -        (mytab.mapstorage).coords[i].x-20,
   1.103 -        (mytab.mapstorage).coords[i].y-20,
   1.104 -        (mytab.mapstorage).coords[i].x+20,
   1.105 -        (mytab.mapstorage).coords[i].y+20);
   1.106 +        (mytab.mapstorage)->coords[i].x-20,
   1.107 +        (mytab.mapstorage)->coords[i].y-20,
   1.108 +        (mytab.mapstorage)->coords[i].x+20,
   1.109 +        (mytab.mapstorage)->coords[i].y+20);
   1.110      *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
   1.111      *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
   1.112      nodesmap[i]->raise_to_top();
   1.113 @@ -247,8 +249,8 @@
   1.114      //initializing edge-text as well, to empty string
   1.115  
   1.116      XY text_pos(
   1.117 -        ((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
   1.118 -        ((mytab.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
   1.119 +        ((mytab.mapstorage)->coords[i].x+node_property_defaults[N_RADIUS]+5),
   1.120 +        ((mytab.mapstorage)->coords[i].y+node_property_defaults[N_RADIUS]+5));
   1.121  
   1.122      nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
   1.123          text_pos.x, text_pos.y, "");
   1.124 @@ -281,13 +283,13 @@
   1.125    active_edge=INVALID;
   1.126    forming_edge=INVALID;
   1.127  
   1.128 -  for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
   1.129 +  for (NodeIt n((mytab.mapstorage)->graph); n != INVALID; ++n)
   1.130    {
   1.131      delete nodesmap[n];
   1.132      delete nodetextmap[n];
   1.133    }
   1.134  
   1.135 -  for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
   1.136 +  for (EdgeIt e((mytab.mapstorage)->graph); e != INVALID; ++e)
   1.137    {
   1.138      delete edgesmap[e];
   1.139      delete edgetextmap[e];
   1.140 @@ -323,7 +325,7 @@
   1.141  
   1.142  void GraphDisplayerCanvas::reDesignGraph()
   1.143  {
   1.144 -  NodeIt firstnode((mytab.mapstorage).graph);
   1.145 +  NodeIt firstnode((mytab.mapstorage)->graph);
   1.146    //is it not an empty graph?
   1.147    if(firstnode!=INVALID)
   1.148      {
   1.149 @@ -333,7 +335,7 @@
   1.150  
   1.151        if(!was_redesigned)
   1.152  	{
   1.153 -	  NodeIt i((mytab.mapstorage).graph);
   1.154 +	  NodeIt i((mytab.mapstorage)->graph);
   1.155  
   1.156  	  dim2::Point<double> init(init_vector_length*rnd(),
   1.157  				   init_vector_length*rnd());
   1.158 @@ -345,28 +347,28 @@
   1.159        double propulsation;
   1.160        int iterations;
   1.161  
   1.162 -      (mytab.mapstorage).get_design_data(attraction, propulsation, iterations);
   1.163 +      (mytab.mapstorage)->get_design_data(attraction, propulsation, iterations);
   1.164  
   1.165        //iteration counter
   1.166        for(int l=0;l<iterations;l++)
   1.167  	{
   1.168 -	  Graph::NodeMap<double> x(mytab.mapstorage.graph);
   1.169 -	  Graph::NodeMap<double> y(mytab.mapstorage.graph);
   1.170 +	  Graph::NodeMap<double> x(mytab.mapstorage->graph);
   1.171 +	  Graph::NodeMap<double> y(mytab.mapstorage->graph);
   1.172  	  XYMap<Graph::NodeMap<double> > actual_forces;
   1.173  	  actual_forces.setXMap(x);
   1.174  	  actual_forces.setYMap(y);
   1.175  
   1.176  	  //count actual force for each nodes
   1.177 -	  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.178 +	  for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
   1.179  	    {
   1.180  	      //propulsation of nodes
   1.181 -	      for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j)
   1.182 +	      for (NodeIt j((mytab.mapstorage)->graph); j!=INVALID; ++j)
   1.183  		{
   1.184  		  if(i!=j)
   1.185  		    {
   1.186  		      lemon::dim2::Point<double> delta =
   1.187 -			((mytab.mapstorage).coords[i]-
   1.188 -			 (mytab.mapstorage).coords[j]);
   1.189 +			((mytab.mapstorage)->coords[i]-
   1.190 +			 (mytab.mapstorage)->coords[j]);
   1.191  
   1.192  		      const double length_sqr=std::max(delta.normSquare(),min_dist);
   1.193  
   1.194 @@ -381,11 +383,11 @@
   1.195  		    }
   1.196  		}
   1.197  	      //attraction of nodes, to which actual node is bound
   1.198 -	      for(OutEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.199 +	      for(OutEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)
   1.200  		{
   1.201  		  lemon::dim2::Point<double> delta =
   1.202 -		    ((mytab.mapstorage).coords[i]-
   1.203 -		     (mytab.mapstorage).coords[mytab.mapstorage.
   1.204 +		    ((mytab.mapstorage)->coords[i]-
   1.205 +		     (mytab.mapstorage)->coords[mytab.mapstorage->
   1.206  					       graph.target(ei)]);
   1.207  		
   1.208  		  //calculating attraction strength
   1.209 @@ -394,11 +396,11 @@
   1.210  		
   1.211  		  actual_forces.set(i,actual_forces[i]-delta);
   1.212  		}
   1.213 -	      for(InEdgeIt ei((mytab.mapstorage).graph,i);ei!=INVALID;++ei)
   1.214 +	      for(InEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)
   1.215  		{
   1.216  		  lemon::dim2::Point<double> delta =
   1.217 -		    ((mytab.mapstorage).coords[i]-
   1.218 -		     (mytab.mapstorage).coords[mytab.mapstorage.
   1.219 +		    ((mytab.mapstorage)->coords[i]-
   1.220 +		     (mytab.mapstorage)->coords[mytab.mapstorage->
   1.221  					       graph.source(ei)]);
   1.222  		
   1.223  		  //calculating attraction strength
   1.224 @@ -408,27 +410,27 @@
   1.225  		  actual_forces.set(i,actual_forces[i]-delta);
   1.226  		}
   1.227  	    }
   1.228 -	  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   1.229 +	  for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
   1.230  	    {
   1.231 -	      if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x>max_coord)
   1.232 +	      if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x>max_coord)
   1.233  		{
   1.234 -		  actual_forces[i].x=max_coord-((mytab.mapstorage).coords[i].x);
   1.235 -		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.236 +		  actual_forces[i].x=max_coord-((mytab.mapstorage)->coords[i].x);
   1.237 +		  std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;
   1.238  		}
   1.239 -	      else if(((mytab.mapstorage).coords[i].x)+actual_forces[i].x<(0-max_coord))
   1.240 +	      else if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x<(0-max_coord))
   1.241  		{
   1.242 -		  actual_forces[i].x=0-max_coord-((mytab.mapstorage).coords[i].x);
   1.243 -		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].x)+actual_forces[i].x) << std::endl;
   1.244 +		  actual_forces[i].x=0-max_coord-((mytab.mapstorage)->coords[i].x);
   1.245 +		  std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;
   1.246  		}
   1.247 -	      if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y>max_coord)
   1.248 +	      if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y>max_coord)
   1.249  		{
   1.250 -		  actual_forces[i].y=max_coord-((mytab.mapstorage).coords[i].y);
   1.251 -		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.252 +		  actual_forces[i].y=max_coord-((mytab.mapstorage)->coords[i].y);
   1.253 +		  std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl;
   1.254  		}
   1.255 -	      else if(((mytab.mapstorage).coords[i].y)+actual_forces[i].y<(0-max_coord))
   1.256 +	      else if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y<(0-max_coord))
   1.257  		{
   1.258 -		  actual_forces[i].y=0-max_coord-((mytab.mapstorage).coords[i].y);
   1.259 -		  std::cout << "Correction! " << (((mytab.mapstorage).coords[i].y)+actual_forces[i].y) << std::endl;
   1.260 +		  actual_forces[i].y=0-max_coord-((mytab.mapstorage)->coords[i].y);
   1.261 +		  std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl;
   1.262  		}
   1.263  	      moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
   1.264  	    }