1.1 --- a/graph_displayer_canvas.cc Wed May 02 20:33:58 2007 +0000
1.2 +++ b/graph_displayer_canvas.cc Wed Jan 02 21:03:09 2008 +0000
1.3 @@ -117,46 +117,57 @@
1.4 std::string mapname=mytab.getActiveNodeMap(prop);
1.5
1.6 if(is_drawn)
1.7 + {
1.8 + if(mapname!="")
1.9 {
1.10 - if(mapname!="")
1.11 - {
1.12 - if( ( ((mytab.mapstorage)->nodemap_storage).find(mapname) != ((mytab.mapstorage)->nodemap_storage).end() ) )
1.13 - {
1.14 - switch(prop)
1.15 - {
1.16 - case N_RADIUS:
1.17 - changeNodeRadius(mapname, node);
1.18 - break;
1.19 - case N_COLOR:
1.20 - changeNodeColor(mapname, node);
1.21 - break;
1.22 - case N_TEXT:
1.23 - changeNodeText(mapname, node);
1.24 - break;
1.25 - default:
1.26 - std::cerr<<"Error\n";
1.27 - }
1.28 - }
1.29 - }
1.30 - else //mapname==""
1.31 - {
1.32 - Node node=INVALID;
1.33 - switch(prop)
1.34 - {
1.35 - case N_RADIUS:
1.36 - resetNodeRadius(node);
1.37 - break;
1.38 - case N_COLOR:
1.39 - resetNodeColor(node);
1.40 - break;
1.41 - case N_TEXT:
1.42 - resetNodeText(node);
1.43 - break;
1.44 - default:
1.45 - std::cerr<<"Error\n";
1.46 - }
1.47 - }
1.48 + std::vector<std::string> nodemaps = mytab.mapstorage->getNodeMapList();
1.49 + bool found = false;
1.50 + for (std::vector<std::string>::const_iterator it = nodemaps.begin();
1.51 + it != nodemaps.end(); ++it)
1.52 + {
1.53 + if (*it == mapname)
1.54 + {
1.55 + found = true;
1.56 + break;
1.57 + }
1.58 + }
1.59 + if (found)
1.60 + {
1.61 + switch(prop)
1.62 + {
1.63 + case N_RADIUS:
1.64 + changeNodeRadius(mapname, node);
1.65 + break;
1.66 + case N_COLOR:
1.67 + changeNodeColor(mapname, node);
1.68 + break;
1.69 + case N_TEXT:
1.70 + changeNodeText(mapname, node);
1.71 + break;
1.72 + default:
1.73 + std::cerr<<"Error\n";
1.74 + }
1.75 + }
1.76 }
1.77 + else //mapname==""
1.78 + {
1.79 + Node node=INVALID;
1.80 + switch(prop)
1.81 + {
1.82 + case N_RADIUS:
1.83 + resetNodeRadius(node);
1.84 + break;
1.85 + case N_COLOR:
1.86 + resetNodeColor(node);
1.87 + break;
1.88 + case N_TEXT:
1.89 + resetNodeText(node);
1.90 + break;
1.91 + default:
1.92 + std::cerr<<"Error\n";
1.93 + }
1.94 + }
1.95 + }
1.96 }
1.97
1.98 void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
1.99 @@ -164,45 +175,56 @@
1.100 std::string mapname=mytab.getActiveEdgeMap(prop);
1.101
1.102 if(is_drawn)
1.103 + {
1.104 + if(mapname!="")
1.105 {
1.106 - if(mapname!="")
1.107 - {
1.108 - if( ( ((mytab.mapstorage)->edgemap_storage).find(mapname) != ((mytab.mapstorage)->edgemap_storage).end() ) )
1.109 - {
1.110 - switch(prop)
1.111 - {
1.112 - case E_WIDTH:
1.113 - changeEdgeWidth(mapname, edge);
1.114 - break;
1.115 - case E_COLOR:
1.116 - changeEdgeColor(mapname, edge);
1.117 - break;
1.118 - case E_TEXT:
1.119 - changeEdgeText(mapname, edge);
1.120 - break;
1.121 - default:
1.122 - std::cerr<<"Error\n";
1.123 - }
1.124 - }
1.125 - }
1.126 - else //mapname==""
1.127 - {
1.128 - switch(prop)
1.129 - {
1.130 - case E_WIDTH:
1.131 - resetEdgeWidth(edge);
1.132 - break;
1.133 - case E_COLOR:
1.134 - resetEdgeColor(edge);
1.135 - break;
1.136 - case E_TEXT:
1.137 - resetEdgeText(edge);
1.138 - break;
1.139 - default:
1.140 - std::cerr<<"Error\n";
1.141 - }
1.142 - }
1.143 + std::vector<std::string> edgemaps = mytab.mapstorage->getEdgeMapList();
1.144 + bool found = false;
1.145 + for (std::vector<std::string>::const_iterator it = edgemaps.begin();
1.146 + it != edgemaps.end(); ++it)
1.147 + {
1.148 + if (*it == mapname)
1.149 + {
1.150 + found = true;
1.151 + break;
1.152 + }
1.153 + }
1.154 + if (found)
1.155 + {
1.156 + switch(prop)
1.157 + {
1.158 + case E_WIDTH:
1.159 + changeEdgeWidth(mapname, edge);
1.160 + break;
1.161 + case E_COLOR:
1.162 + changeEdgeColor(mapname, edge);
1.163 + break;
1.164 + case E_TEXT:
1.165 + changeEdgeText(mapname, edge);
1.166 + break;
1.167 + default:
1.168 + std::cerr<<"Error\n";
1.169 + }
1.170 + }
1.171 }
1.172 + else //mapname==""
1.173 + {
1.174 + switch(prop)
1.175 + {
1.176 + case E_WIDTH:
1.177 + resetEdgeWidth(edge);
1.178 + break;
1.179 + case E_COLOR:
1.180 + resetEdgeColor(edge);
1.181 + break;
1.182 + case E_TEXT:
1.183 + resetEdgeText(edge);
1.184 + break;
1.185 + default:
1.186 + std::cerr<<"Error\n";
1.187 + }
1.188 + }
1.189 + }
1.190 }
1.191
1.192 void GraphDisplayerCanvas::drawGraph()
1.193 @@ -221,7 +243,7 @@
1.194 }
1.195 //initializing edge-text as well, to empty string
1.196
1.197 - XY text_pos=mytab.mapstorage->arrow_pos[i];
1.198 + XY text_pos=mytab.mapstorage->getArrowCoords(i);
1.199 text_pos+=(XY(10,10));
1.200
1.201 edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
1.202 @@ -238,10 +260,10 @@
1.203
1.204 nodesmap[i]=new Gnome::Canvas::Ellipse(
1.205 displayed_graph,
1.206 - (mytab.mapstorage)->coords[i].x-20,
1.207 - (mytab.mapstorage)->coords[i].y-20,
1.208 - (mytab.mapstorage)->coords[i].x+20,
1.209 - (mytab.mapstorage)->coords[i].y+20);
1.210 + mytab.mapstorage->getNodeCoords(i).x-20,
1.211 + mytab.mapstorage->getNodeCoords(i).y-20,
1.212 + mytab.mapstorage->getNodeCoords(i).x+20,
1.213 + mytab.mapstorage->getNodeCoords(i).y+20);
1.214 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
1.215 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
1.216 nodesmap[i]->raise_to_top();
1.217 @@ -249,8 +271,8 @@
1.218 //initializing edge-text as well, to empty string
1.219
1.220 XY text_pos(
1.221 - ((mytab.mapstorage)->coords[i].x+node_property_defaults[N_RADIUS]+5),
1.222 - ((mytab.mapstorage)->coords[i].y+node_property_defaults[N_RADIUS]+5));
1.223 + (mytab.mapstorage->getNodeCoords(i).x+node_property_defaults[N_RADIUS]+5),
1.224 + (mytab.mapstorage->getNodeCoords(i).y+node_property_defaults[N_RADIUS]+5));
1.225
1.226 nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
1.227 text_pos.x, text_pos.y, "");
1.228 @@ -325,7 +347,8 @@
1.229
1.230 void GraphDisplayerCanvas::reDesignGraph()
1.231 {
1.232 - NodeIt firstnode((mytab.mapstorage)->graph);
1.233 + MapStorage& ms = *mytab.mapstorage;
1.234 + NodeIt firstnode(ms.graph);
1.235 //is it not an empty graph?
1.236 if(firstnode!=INVALID)
1.237 {
1.238 @@ -335,7 +358,7 @@
1.239
1.240 if(!was_redesigned)
1.241 {
1.242 - NodeIt i((mytab.mapstorage)->graph);
1.243 + NodeIt i(ms.graph);
1.244
1.245 dim2::Point<double> init(init_vector_length*rnd(),
1.246 init_vector_length*rnd());
1.247 @@ -347,28 +370,28 @@
1.248 double propulsation;
1.249 int iterations;
1.250
1.251 - (mytab.mapstorage)->get_design_data(attraction, propulsation, iterations);
1.252 + ms.get_design_data(attraction, propulsation, iterations);
1.253
1.254 //iteration counter
1.255 for(int l=0;l<iterations;l++)
1.256 {
1.257 - Graph::NodeMap<double> x(mytab.mapstorage->graph);
1.258 - Graph::NodeMap<double> y(mytab.mapstorage->graph);
1.259 + Graph::NodeMap<double> x(ms.graph);
1.260 + Graph::NodeMap<double> y(ms.graph);
1.261 XYMap<Graph::NodeMap<double> > actual_forces;
1.262 actual_forces.setXMap(x);
1.263 actual_forces.setYMap(y);
1.264
1.265 //count actual force for each nodes
1.266 - for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
1.267 + for (NodeIt i(ms.graph); i!=INVALID; ++i)
1.268 {
1.269 //propulsation of nodes
1.270 - for (NodeIt j((mytab.mapstorage)->graph); j!=INVALID; ++j)
1.271 + for (NodeIt j(ms.graph); j!=INVALID; ++j)
1.272 {
1.273 if(i!=j)
1.274 {
1.275 lemon::dim2::Point<double> delta =
1.276 - ((mytab.mapstorage)->coords[i]-
1.277 - (mytab.mapstorage)->coords[j]);
1.278 + (ms.getNodeCoords(i)-
1.279 + ms.getNodeCoords(j));
1.280
1.281 const double length_sqr=std::max(delta.normSquare(),min_dist);
1.282
1.283 @@ -382,55 +405,53 @@
1.284 actual_forces.set(i,(actual_forces[i]+delta));
1.285 }
1.286 }
1.287 - //attraction of nodes, to which actual node is bound
1.288 - for(OutEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)
1.289 + //attraction of nodes, to which actual node is bound
1.290 + for(OutEdgeIt ei(ms.graph,i);ei!=INVALID;++ei)
1.291 + {
1.292 + lemon::dim2::Point<double> delta =
1.293 + (ms.getNodeCoords(i)-
1.294 + ms.getNodeCoords(ms.graph.target(ei)));
1.295 +
1.296 + //calculating attraction strength
1.297 + //greater distance means greater strength
1.298 + delta*=attraction;
1.299 +
1.300 + actual_forces.set(i,actual_forces[i]-delta);
1.301 + }
1.302 + for(InEdgeIt ei(ms.graph,i);ei!=INVALID;++ei)
1.303 + {
1.304 + lemon::dim2::Point<double> delta =
1.305 + (ms.getNodeCoords(i)-
1.306 + ms.getNodeCoords(ms.graph.source(ei)));
1.307 +
1.308 + //calculating attraction strength
1.309 + //greater distance means greater strength
1.310 + delta*=attraction;
1.311 +
1.312 + actual_forces.set(i,actual_forces[i]-delta);
1.313 + }
1.314 + }
1.315 + for (NodeIt i(ms.graph); i!=INVALID; ++i)
1.316 + {
1.317 + if((ms.getNodeCoords(i).x)+actual_forces[i].x>max_coord)
1.318 {
1.319 - lemon::dim2::Point<double> delta =
1.320 - ((mytab.mapstorage)->coords[i]-
1.321 - (mytab.mapstorage)->coords[mytab.mapstorage->
1.322 - graph.target(ei)]);
1.323 -
1.324 - //calculating attraction strength
1.325 - //greater distance means greater strength
1.326 - delta*=attraction;
1.327 -
1.328 - actual_forces.set(i,actual_forces[i]-delta);
1.329 + actual_forces[i].x=max_coord-(ms.getNodeCoords(i).x);
1.330 + std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl;
1.331 }
1.332 - for(InEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)
1.333 + else if((ms.getNodeCoords(i).x)+actual_forces[i].x<(0-max_coord))
1.334 {
1.335 - lemon::dim2::Point<double> delta =
1.336 - ((mytab.mapstorage)->coords[i]-
1.337 - (mytab.mapstorage)->coords[mytab.mapstorage->
1.338 - graph.source(ei)]);
1.339 -
1.340 - //calculating attraction strength
1.341 - //greater distance means greater strength
1.342 - delta*=attraction;
1.343 -
1.344 - actual_forces.set(i,actual_forces[i]-delta);
1.345 + actual_forces[i].x=0-max_coord-(ms.getNodeCoords(i).x);
1.346 + std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl;
1.347 }
1.348 - }
1.349 - for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
1.350 - {
1.351 - if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x>max_coord)
1.352 + if((ms.getNodeCoords(i).y)+actual_forces[i].y>max_coord)
1.353 {
1.354 - actual_forces[i].x=max_coord-((mytab.mapstorage)->coords[i].x);
1.355 - std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;
1.356 + actual_forces[i].y=max_coord-(ms.getNodeCoords(i).y);
1.357 + std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl;
1.358 }
1.359 - else if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x<(0-max_coord))
1.360 + else if((ms.getNodeCoords(i).y)+actual_forces[i].y<(0-max_coord))
1.361 {
1.362 - actual_forces[i].x=0-max_coord-((mytab.mapstorage)->coords[i].x);
1.363 - std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;
1.364 - }
1.365 - if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y>max_coord)
1.366 - {
1.367 - actual_forces[i].y=max_coord-((mytab.mapstorage)->coords[i].y);
1.368 - std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl;
1.369 - }
1.370 - else if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y<(0-max_coord))
1.371 - {
1.372 - actual_forces[i].y=0-max_coord-((mytab.mapstorage)->coords[i].y);
1.373 - std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl;
1.374 + actual_forces[i].y=0-max_coord-(ms.getNodeCoords(i).y);
1.375 + std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl;
1.376 }
1.377 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
1.378 }