Changeset 201:879e47e5b731 in glemon-0.x for graph_displayer_canvas.cc
- Timestamp:
- 01/02/08 22:03:09 (16 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/glemon/trunk@3431
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
graph_displayer_canvas.cc
r194 r201 118 118 119 119 if(is_drawn) 120 { 121 if(mapname!="") 122 { 123 if( ( ((mytab.mapstorage)->nodemap_storage).find(mapname) != ((mytab.mapstorage)->nodemap_storage).end() ) ) 124 { 125 switch(prop) 126 { 127 case N_RADIUS: 128 changeNodeRadius(mapname, node); 129 break; 130 case N_COLOR: 131 changeNodeColor(mapname, node); 132 break; 133 case N_TEXT: 134 changeNodeText(mapname, node); 135 break; 136 default: 137 std::cerr<<"Error\n"; 138 } 139 } 140 } 141 else //mapname=="" 142 { 143 Node node=INVALID; 144 switch(prop) 145 { 146 case N_RADIUS: 147 resetNodeRadius(node); 148 break; 149 case N_COLOR: 150 resetNodeColor(node); 151 break; 152 case N_TEXT: 153 resetNodeText(node); 154 break; 155 default: 156 std::cerr<<"Error\n"; 157 } 158 } 159 } 120 { 121 if(mapname!="") 122 { 123 std::vector<std::string> nodemaps = mytab.mapstorage->getNodeMapList(); 124 bool found = false; 125 for (std::vector<std::string>::const_iterator it = nodemaps.begin(); 126 it != nodemaps.end(); ++it) 127 { 128 if (*it == mapname) 129 { 130 found = true; 131 break; 132 } 133 } 134 if (found) 135 { 136 switch(prop) 137 { 138 case N_RADIUS: 139 changeNodeRadius(mapname, node); 140 break; 141 case N_COLOR: 142 changeNodeColor(mapname, node); 143 break; 144 case N_TEXT: 145 changeNodeText(mapname, node); 146 break; 147 default: 148 std::cerr<<"Error\n"; 149 } 150 } 151 } 152 else //mapname=="" 153 { 154 Node node=INVALID; 155 switch(prop) 156 { 157 case N_RADIUS: 158 resetNodeRadius(node); 159 break; 160 case N_COLOR: 161 resetNodeColor(node); 162 break; 163 case N_TEXT: 164 resetNodeText(node); 165 break; 166 default: 167 std::cerr<<"Error\n"; 168 } 169 } 170 } 160 171 } 161 172 … … 165 176 166 177 if(is_drawn) 167 { 168 if(mapname!="") 169 { 170 if( ( ((mytab.mapstorage)->edgemap_storage).find(mapname) != ((mytab.mapstorage)->edgemap_storage).end() ) ) 171 { 172 switch(prop) 173 { 174 case E_WIDTH: 175 changeEdgeWidth(mapname, edge); 176 break; 177 case E_COLOR: 178 changeEdgeColor(mapname, edge); 179 break; 180 case E_TEXT: 181 changeEdgeText(mapname, edge); 182 break; 183 default: 184 std::cerr<<"Error\n"; 185 } 186 } 187 } 188 else //mapname=="" 189 { 190 switch(prop) 191 { 192 case E_WIDTH: 193 resetEdgeWidth(edge); 194 break; 195 case E_COLOR: 196 resetEdgeColor(edge); 197 break; 198 case E_TEXT: 199 resetEdgeText(edge); 200 break; 201 default: 202 std::cerr<<"Error\n"; 203 } 204 } 205 } 178 { 179 if(mapname!="") 180 { 181 std::vector<std::string> edgemaps = mytab.mapstorage->getEdgeMapList(); 182 bool found = false; 183 for (std::vector<std::string>::const_iterator it = edgemaps.begin(); 184 it != edgemaps.end(); ++it) 185 { 186 if (*it == mapname) 187 { 188 found = true; 189 break; 190 } 191 } 192 if (found) 193 { 194 switch(prop) 195 { 196 case E_WIDTH: 197 changeEdgeWidth(mapname, edge); 198 break; 199 case E_COLOR: 200 changeEdgeColor(mapname, edge); 201 break; 202 case E_TEXT: 203 changeEdgeText(mapname, edge); 204 break; 205 default: 206 std::cerr<<"Error\n"; 207 } 208 } 209 } 210 else //mapname=="" 211 { 212 switch(prop) 213 { 214 case E_WIDTH: 215 resetEdgeWidth(edge); 216 break; 217 case E_COLOR: 218 resetEdgeColor(edge); 219 break; 220 case E_TEXT: 221 resetEdgeText(edge); 222 break; 223 default: 224 std::cerr<<"Error\n"; 225 } 226 } 227 } 206 228 } 207 229 … … 222 244 //initializing edge-text as well, to empty string 223 245 224 XY text_pos=mytab.mapstorage-> arrow_pos[i];246 XY text_pos=mytab.mapstorage->getArrowCoords(i); 225 247 text_pos+=(XY(10,10)); 226 248 … … 239 261 nodesmap[i]=new Gnome::Canvas::Ellipse( 240 262 displayed_graph, 241 (mytab.mapstorage)->coords[i].x-20,242 (mytab.mapstorage)->coords[i].y-20,243 (mytab.mapstorage)->coords[i].x+20,244 (mytab.mapstorage)->coords[i].y+20);263 mytab.mapstorage->getNodeCoords(i).x-20, 264 mytab.mapstorage->getNodeCoords(i).y-20, 265 mytab.mapstorage->getNodeCoords(i).x+20, 266 mytab.mapstorage->getNodeCoords(i).y+20); 245 267 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); 246 268 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); … … 250 272 251 273 XY text_pos( 252 ( (mytab.mapstorage)->coords[i].x+node_property_defaults[N_RADIUS]+5),253 ( (mytab.mapstorage)->coords[i].y+node_property_defaults[N_RADIUS]+5));274 (mytab.mapstorage->getNodeCoords(i).x+node_property_defaults[N_RADIUS]+5), 275 (mytab.mapstorage->getNodeCoords(i).y+node_property_defaults[N_RADIUS]+5)); 254 276 255 277 nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, … … 326 348 void GraphDisplayerCanvas::reDesignGraph() 327 349 { 328 NodeIt firstnode((mytab.mapstorage)->graph); 350 MapStorage& ms = *mytab.mapstorage; 351 NodeIt firstnode(ms.graph); 329 352 //is it not an empty graph? 330 353 if(firstnode!=INVALID) … … 336 359 if(!was_redesigned) 337 360 { 338 NodeIt i( (mytab.mapstorage)->graph);361 NodeIt i(ms.graph); 339 362 340 363 dim2::Point<double> init(init_vector_length*rnd(), … … 348 371 int iterations; 349 372 350 (mytab.mapstorage)->get_design_data(attraction, propulsation, iterations);373 ms.get_design_data(attraction, propulsation, iterations); 351 374 352 375 //iteration counter 353 376 for(int l=0;l<iterations;l++) 354 377 { 355 Graph::NodeMap<double> x(m ytab.mapstorage->graph);356 Graph::NodeMap<double> y(m ytab.mapstorage->graph);378 Graph::NodeMap<double> x(ms.graph); 379 Graph::NodeMap<double> y(ms.graph); 357 380 XYMap<Graph::NodeMap<double> > actual_forces; 358 381 actual_forces.setXMap(x); … … 360 383 361 384 //count actual force for each nodes 362 for (NodeIt i( (mytab.mapstorage)->graph); i!=INVALID; ++i)385 for (NodeIt i(ms.graph); i!=INVALID; ++i) 363 386 { 364 387 //propulsation of nodes 365 for (NodeIt j( (mytab.mapstorage)->graph); j!=INVALID; ++j)388 for (NodeIt j(ms.graph); j!=INVALID; ++j) 366 389 { 367 390 if(i!=j) 368 391 { 369 392 lemon::dim2::Point<double> delta = 370 ( (mytab.mapstorage)->coords[i]-371 (mytab.mapstorage)->coords[j]);393 (ms.getNodeCoords(i)- 394 ms.getNodeCoords(j)); 372 395 373 396 const double length_sqr=std::max(delta.normSquare(),min_dist); … … 383 406 } 384 407 } 385 //attraction of nodes, to which actual node is bound 386 for(OutEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei) 408 //attraction of nodes, to which actual node is bound 409 for(OutEdgeIt ei(ms.graph,i);ei!=INVALID;++ei) 410 { 411 lemon::dim2::Point<double> delta = 412 (ms.getNodeCoords(i)- 413 ms.getNodeCoords(ms.graph.target(ei))); 414 415 //calculating attraction strength 416 //greater distance means greater strength 417 delta*=attraction; 418 419 actual_forces.set(i,actual_forces[i]-delta); 420 } 421 for(InEdgeIt ei(ms.graph,i);ei!=INVALID;++ei) 422 { 423 lemon::dim2::Point<double> delta = 424 (ms.getNodeCoords(i)- 425 ms.getNodeCoords(ms.graph.source(ei))); 426 427 //calculating attraction strength 428 //greater distance means greater strength 429 delta*=attraction; 430 431 actual_forces.set(i,actual_forces[i]-delta); 432 } 433 } 434 for (NodeIt i(ms.graph); i!=INVALID; ++i) 435 { 436 if((ms.getNodeCoords(i).x)+actual_forces[i].x>max_coord) 387 437 { 388 lemon::dim2::Point<double> delta = 389 ((mytab.mapstorage)->coords[i]- 390 (mytab.mapstorage)->coords[mytab.mapstorage-> 391 graph.target(ei)]); 392 393 //calculating attraction strength 394 //greater distance means greater strength 395 delta*=attraction; 396 397 actual_forces.set(i,actual_forces[i]-delta); 438 actual_forces[i].x=max_coord-(ms.getNodeCoords(i).x); 439 std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl; 398 440 } 399 for(InEdgeIt ei((mytab.mapstorage)->graph,i);ei!=INVALID;++ei)441 else if((ms.getNodeCoords(i).x)+actual_forces[i].x<(0-max_coord)) 400 442 { 401 lemon::dim2::Point<double> delta = 402 ((mytab.mapstorage)->coords[i]- 403 (mytab.mapstorage)->coords[mytab.mapstorage-> 404 graph.source(ei)]); 405 406 //calculating attraction strength 407 //greater distance means greater strength 408 delta*=attraction; 409 410 actual_forces.set(i,actual_forces[i]-delta); 443 actual_forces[i].x=0-max_coord-(ms.getNodeCoords(i).x); 444 std::cout << "Correction! " << ((ms.getNodeCoords(i).x)+actual_forces[i].x) << std::endl; 411 445 } 412 } 413 for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i) 414 { 415 if(((mytab.mapstorage)->coords[i].x)+actual_forces[i].x>max_coord) 446 if((ms.getNodeCoords(i).y)+actual_forces[i].y>max_coord) 416 447 { 417 actual_forces[i]. x=max_coord-((mytab.mapstorage)->coords[i].x);418 std::cout << "Correction! " << (( (mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl;448 actual_forces[i].y=max_coord-(ms.getNodeCoords(i).y); 449 std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl; 419 450 } 420 else if(( (mytab.mapstorage)->coords[i].x)+actual_forces[i].x<(0-max_coord))451 else if((ms.getNodeCoords(i).y)+actual_forces[i].y<(0-max_coord)) 421 452 { 422 actual_forces[i].x=0-max_coord-((mytab.mapstorage)->coords[i].x); 423 std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].x)+actual_forces[i].x) << std::endl; 424 } 425 if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y>max_coord) 426 { 427 actual_forces[i].y=max_coord-((mytab.mapstorage)->coords[i].y); 428 std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl; 429 } 430 else if(((mytab.mapstorage)->coords[i].y)+actual_forces[i].y<(0-max_coord)) 431 { 432 actual_forces[i].y=0-max_coord-((mytab.mapstorage)->coords[i].y); 433 std::cout << "Correction! " << (((mytab.mapstorage)->coords[i].y)+actual_forces[i].y) << std::endl; 453 actual_forces[i].y=0-max_coord-(ms.getNodeCoords(i).y); 454 std::cout << "Correction! " << ((ms.getNodeCoords(i).y)+actual_forces[i].y) << std::endl; 434 455 } 435 456 moveNode(actual_forces[i].x, actual_forces[i].y, nodesmap[i], i);
Note: See TracChangeset
for help on using the changeset viewer.