graph_displayer_canvas.cc
branchgui
changeset 94 adfdc2f70548
parent 89 4042761b21e3
child 96 e664d8aa3f72
     1.1 --- a/graph_displayer_canvas.cc	Wed Nov 23 16:24:59 2005 +0000
     1.2 +++ b/graph_displayer_canvas.cc	Tue Nov 29 19:31:58 2005 +0000
     1.3 @@ -1,14 +1,12 @@
     1.4  #include "graph_displayer_canvas.h"
     1.5  #include <cmath>
     1.6  
     1.7 -GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
     1.8 -  nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
     1.9 -  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), mapstorage(ms),
    1.10 +GraphDisplayerCanvas::GraphDisplayerCanvas(MainWin & mainw) :
    1.11 +  nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
    1.12 +  nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
    1.13    isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
    1.14 -  edgemap_to_edit(""), mapwin(mw)
    1.15 +  edgemap_to_edit(""), mainwin(mainw)
    1.16  {
    1.17 -  parentwin=mainwin;
    1.18 -
    1.19    //base event handler is move tool
    1.20    actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
    1.21    actual_tool=MOVE;
    1.22 @@ -20,35 +18,155 @@
    1.23  
    1.24  GraphDisplayerCanvas::~GraphDisplayerCanvas()
    1.25  {
    1.26 -  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
    1.27 -  {
    1.28 -    delete nodesmap[n];
    1.29 -    delete nodetextmap[n];
    1.30 -  }
    1.31 +  for (NodeIt n((mainwin.mapstorage).graph); n != INVALID; ++n)
    1.32 +    {
    1.33 +      delete nodesmap[n];
    1.34 +      delete nodetextmap[n];
    1.35 +    }
    1.36 +  
    1.37 +  for (EdgeIt e((mainwin.mapstorage).graph); e != INVALID; ++e)
    1.38 +    {
    1.39 +      delete edgesmap[e];
    1.40 +      delete edgetextmap[e];
    1.41 +    }
    1.42 +}
    1.43  
    1.44 -  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
    1.45 -  {
    1.46 -    delete edgesmap[e];
    1.47 -    delete edgetextmap[e];
    1.48 -  }
    1.49 +void GraphDisplayerCanvas::propertyChange(bool itisedge, int prop)
    1.50 +{
    1.51 +  if(itisedge)
    1.52 +    {
    1.53 +      propertyUpdate(Edge(INVALID), prop);
    1.54 +    }
    1.55 +  else
    1.56 +    {
    1.57 +      propertyUpdate(Node(INVALID), prop);
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +void GraphDisplayerCanvas::propertyUpdate(Edge edge)
    1.62 +{
    1.63 +  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
    1.64 +    {
    1.65 +      propertyUpdate(edge, i);
    1.66 +    }
    1.67 +}
    1.68 +
    1.69 +void GraphDisplayerCanvas::propertyUpdate(Node node)
    1.70 +{
    1.71 +  for(int i=0;i<NODE_PROPERTY_NUM;i++)
    1.72 +    {
    1.73 +      propertyUpdate(node, i);
    1.74 +    }
    1.75 +}
    1.76 +
    1.77 +void GraphDisplayerCanvas::propertyUpdate(Node node, int prop, int dummy)
    1.78 +{
    1.79 +  dummy=dummy;
    1.80 +
    1.81 +  std::string mapname=mainwin.getActiveNodeMap(prop);
    1.82 +
    1.83 +  if(mapname!="")
    1.84 +    {
    1.85 +      if( ( ((mainwin.mapstorage).nodemap_storage).find(mapname) != ((mainwin.mapstorage).nodemap_storage).end() ) )
    1.86 +	{
    1.87 +	  switch(prop)
    1.88 +	    {
    1.89 +	    case N_RADIUS:
    1.90 +	      changeNodeRadius(mapname, node);
    1.91 +	      break;
    1.92 +	    case N_COLOR:
    1.93 +	      changeNodeColor(mapname, node);
    1.94 +	      break;
    1.95 +	    case N_TEXT:
    1.96 +	      changeNodeText(mapname, node);
    1.97 +	      break;
    1.98 +	    default:
    1.99 +	      std::cerr<<"Error\n";
   1.100 +	    }
   1.101 +	}
   1.102 +    }
   1.103 +  else //mapname==""
   1.104 +    {
   1.105 +      Node node=INVALID;	
   1.106 +      switch(prop)
   1.107 +	{
   1.108 +	case N_RADIUS:
   1.109 +	  resetNodeRadius(node);
   1.110 +	  break;
   1.111 +	case N_COLOR:
   1.112 +	  resetNodeColor(node);
   1.113 +	  break;
   1.114 +	case N_TEXT:
   1.115 +	  resetNodeText(node);
   1.116 +	  break;
   1.117 +	default:
   1.118 +	  std::cerr<<"Error\n";
   1.119 +	}
   1.120 +    }
   1.121 +
   1.122 +}
   1.123 +
   1.124 +void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop, int dummy)
   1.125 +{
   1.126 +  dummy=dummy;
   1.127 +
   1.128 +  std::string mapname=mainwin.getActiveEdgeMap(prop);
   1.129 +
   1.130 +  if(mapname!="")
   1.131 +    {
   1.132 +      if( ( ((mainwin.mapstorage).edgemap_storage).find(mapname) != ((mainwin.mapstorage).edgemap_storage).end() ) )
   1.133 +	{
   1.134 +	  switch(prop)
   1.135 +	    {
   1.136 +	    case E_WIDTH:
   1.137 +	      changeEdgeWidth(mapname, edge);
   1.138 +	      break;
   1.139 +	    case E_COLOR:
   1.140 +	      changeEdgeColor(mapname, edge);
   1.141 +	      break;
   1.142 +	    case E_TEXT:
   1.143 +	      changeEdgeText(mapname, edge);
   1.144 +	      break;
   1.145 +	    default:
   1.146 +	      std::cerr<<"Error\n";
   1.147 +	    }
   1.148 +	}
   1.149 +    }
   1.150 +  else //mapname==""
   1.151 +    {
   1.152 +      switch(prop)
   1.153 +	{
   1.154 +	case E_WIDTH:
   1.155 +	  resetEdgeWidth(edge);
   1.156 +	  break;
   1.157 +	case E_COLOR:
   1.158 +	  resetEdgeColor(edge);
   1.159 +	  break;
   1.160 +	case E_TEXT:
   1.161 +	  resetEdgeText(edge);
   1.162 +	  break;
   1.163 +	default:
   1.164 +	  std::cerr<<"Error\n";
   1.165 +	}
   1.166 +    }
   1.167  }
   1.168  
   1.169  void GraphDisplayerCanvas::drawGraph()
   1.170  {
   1.171    //first edges are drawn, to hide joining with nodes later
   1.172  
   1.173 -  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   1.174 +  for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.175    {
   1.176  
   1.177      //drawing green lines, coordinates are from mapstorage.coords
   1.178  
   1.179      Gnome::Canvas::Points coos;
   1.180      coos.push_back(Gnome::Art::Point(
   1.181 -          mapstorage.coords[mapstorage.graph.source(i)].x,
   1.182 -          mapstorage.coords[mapstorage.graph.source(i)].y));
   1.183 +          (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.source(i)].x,
   1.184 +          (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.source(i)].y));
   1.185      coos.push_back(Gnome::Art::Point(
   1.186 -          mapstorage.coords[mapstorage.graph.target(i)].x,
   1.187 -          mapstorage.coords[mapstorage.graph.target(i)].y));
   1.188 +          (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.target(i)].x,
   1.189 +          (mainwin.mapstorage).coords[(mainwin.mapstorage).graph.target(i)].y));
   1.190      
   1.191      edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
   1.192      *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
   1.193 @@ -68,16 +186,16 @@
   1.194  
   1.195    //afterwards nodes come to be drawn
   1.196  
   1.197 -  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   1.198 +  for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i)
   1.199    {
   1.200      //drawing bule nodes, with black line around them
   1.201  
   1.202      nodesmap[i]=new Gnome::Canvas::Ellipse(
   1.203          displayed_graph,
   1.204 -        mapstorage.coords[i].x-20,
   1.205 -        mapstorage.coords[i].y-20,
   1.206 -        mapstorage.coords[i].x+20,
   1.207 -        mapstorage.coords[i].y+20);
   1.208 +        (mainwin.mapstorage).coords[i].x-20,
   1.209 +        (mainwin.mapstorage).coords[i].y-20,
   1.210 +        (mainwin.mapstorage).coords[i].x+20,
   1.211 +        (mainwin.mapstorage).coords[i].y+20);
   1.212      *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
   1.213      *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
   1.214      nodesmap[i]->raise_to_top();
   1.215 @@ -85,8 +203,8 @@
   1.216      //initializing edge-text as well, to empty string
   1.217  
   1.218      xy<double> text_pos(
   1.219 -        (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
   1.220 -        (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
   1.221 +        ((mainwin.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
   1.222 +        ((mainwin.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
   1.223  
   1.224      nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
   1.225          text_pos.x, text_pos.y, "");
   1.226 @@ -104,13 +222,13 @@
   1.227    active_edge=INVALID;
   1.228    forming_edge=INVALID;
   1.229  
   1.230 -  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
   1.231 +  for (NodeIt n((mainwin.mapstorage).graph); n != INVALID; ++n)
   1.232    {
   1.233      delete nodesmap[n];
   1.234      delete nodetextmap[n];
   1.235    }
   1.236  
   1.237 -  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
   1.238 +  for (EdgeIt e((mainwin.mapstorage).graph); e != INVALID; ++e)
   1.239    {
   1.240      delete edgesmap[e];
   1.241      delete edgetextmap[e];