Changeset 1645:4a04bb856ac7 in lemon-0.x
- Timestamp:
- 08/23/05 09:36:09 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2158
- Location:
- gui
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
gui/broken_edge.cc
r1632 r1645 9 9 *arrow << Gnome::Canvas::Properties::fill_color("red"); 10 10 arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edgeFormerEventHandler)); 11 arrow->lower_to_bottom(); 11 12 setPoints(p); 12 13 } -
gui/graph_displayer_canvas-edge.cc
r1643 r1645 123 123 //in that case empty string will be written, because 124 124 //that is the deleter map 125 125 126 126 if(edge==INVALID) 127 127 { -
gui/graph_displayer_canvas-event.cc
r1643 r1645 215 215 { 216 216 switch(e->type) 217 { 218 219 //draw the new node in red at the clicked place 220 case GDK_2BUTTON_PRESS: 221 //std::cout << "double click" << std::endl; 222 break; 223 case GDK_BUTTON_PRESS: 217 { 218 //move the new node 219 case GDK_MOTION_NOTIFY: 220 { 221 GdkEvent * generated=new GdkEvent(); 222 generated->motion.x=e->motion.x; 223 generated->motion.y=e->motion.y; 224 generated->type=GDK_MOTION_NOTIFY; 225 moveEventHandler(generated); 226 break; 227 } 228 229 case GDK_BUTTON_RELEASE: 224 230 mapstorage.modified = true; 225 231 … … 232 238 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 233 239 240 // update coordinates 234 241 mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y)); 242 243 // update id map 235 244 (*mapstorage.nodemap_storage["id"])[active_node] = 236 245 mapstorage.graph.id(active_node); 237 246 247 // update all other maps 248 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 249 mapstorage.nodemap_storage.begin(); it != 250 mapstorage.nodemap_storage.end(); ++it) 251 { 252 if ((it->first != "id") && 253 (it->first != "coordinates_x") && 254 (it->first != "coordiantes_y")) 255 { 256 (*(it->second))[active_node] = 257 mapstorage.nodemap_default[it->first]; 258 } 259 } 260 238 261 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, 239 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);262 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); 240 263 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); 241 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 242 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); 264 *(nodesmap[active_node]) << 265 Gnome::Canvas::Properties::fill_color("blue"); 266 *(nodesmap[active_node]) << 267 Gnome::Canvas::Properties::outline_color("black"); 268 active_item->raise_to_top(); 269 243 270 (nodesmap[active_node])->show(); 244 271 245 272 nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, 246 clicked_x+node_property_defaults[N_RADIUS]+5,247 clicked_y+node_property_defaults[N_RADIUS]+5, "");273 clicked_x+node_property_defaults[N_RADIUS]+5, 274 clicked_y+node_property_defaults[N_RADIUS]+5, ""); 248 275 nodetextmap[active_node]->property_fill_color().set_value("darkblue"); 276 nodetextmap[active_node]->raise_to_top(); 249 277 250 278 mapwin.updateNode(active_node); 251 279 252 break;253 254 //move the new node255 case GDK_MOTION_NOTIFY:256 {257 GdkEvent * generated=new GdkEvent();258 generated->motion.x=e->motion.x;259 generated->motion.y=e->motion.y;260 generated->type=GDK_MOTION_NOTIFY;261 moveEventHandler(generated);262 break;263 }264 265 //finalize the new node266 case GDK_BUTTON_RELEASE:267 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);268 269 active_item->lower_to_bottom();270 271 target_item=NULL;272 target_item=get_item_at(clicked_x, clicked_y);273 274 active_item->raise_to_top();275 276 280 isbutton=0; 277 if(target_item==active_item)278 {279 //Its appropriate color is given by update.280 *active_item << Gnome::Canvas::Properties::fill_color("blue");281 }282 else283 {284 //In this case the given color has to be overwritten, because the noe covers an other item.285 *active_item << Gnome::Canvas::Properties::fill_color("lightblue");286 }287 281 target_item=NULL; 288 282 active_item=NULL; 289 283 active_node=INVALID; 284 290 285 break; 291 286 default: 292 287 break; 293 288 } 294 289 return false; 295 290 } … … 298 293 { 299 294 switch(e->type) 300 295 { 301 296 case GDK_BUTTON_PRESS: 302 297 //in edge creation right button has special meaning 303 298 if(e->button.button!=3) 304 { 305 //there is not yet selected node 306 if(active_node==INVALID) 307 { 308 //we mark the location of the event to be able to calculate parameters of dragging 309 310 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 311 312 active_item=(get_item_at(clicked_x, clicked_y)); 313 active_node=INVALID; 314 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 315 { 316 if(nodesmap[i]==active_item) 317 { 318 active_node=i; 319 } 320 } 321 //the clicked item is really a node 322 if(active_node!=INVALID) 323 { 324 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 325 isbutton=1; 326 } 327 //clicked item was not a node. It could be e.g. edge. 328 else 329 { 330 active_item=NULL; 331 } 332 } 333 //we only have to do sg. if the mouse button 334 // is pressed already once AND the click was 335 // on a node that was found in the set of 336 //nodes, and now we only search for the second 337 //node 338 else 339 { 340 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 341 target_item=(get_item_at(clicked_x, clicked_y)); 342 Node target_node=INVALID; 343 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 344 { 345 if(nodesmap[i]==target_item) 346 { 347 target_node=i; 348 } 349 } 350 //the clicked item is a node, the edge can be drawn 351 if(target_node!=INVALID) 352 { 353 if(target_node!=active_node) 354 { 355 mapstorage.modified = true; 356 357 *(nodesmap[target_node]) << 358 Gnome::Canvas::Properties::fill_color("red"); 359 360 //creating new edge 361 active_edge=mapstorage.graph.addEdge(active_node, 362 target_node); 363 364 //initiating values corresponding to new edge in maps 365 mapstorage.initMapsForEdge(active_edge); 366 (*mapstorage.edgemap_storage["id"])[active_edge] = 367 mapstorage.graph.id(active_edge); 368 369 //calculating coordinates of new edge 370 Gnome::Canvas::Points coos; 371 double x1, x2, y1, y2; 372 373 active_item->get_bounds(x1, y1, x2, y2); 374 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 375 376 target_item->get_bounds(x1, y1, x2, y2); 377 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 378 379 //drawing new edge 380 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this); 381 *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green"); 382 edgesmap[active_edge]->property_width_pixels().set_value(10); 383 384 //redraw nodes to blank terminations of the new edge 385 target_item->raise_to_top(); 386 active_item->raise_to_top(); 387 388 //initializing edge-text as well, to empty string 389 xy<double> text_pos=edgesmap[active_edge]->getArrowPos(); 390 text_pos+=(xy<double>(10,10)); 391 392 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); 393 edgetextmap[active_edge]->property_fill_color().set_value("darkgreen"); 394 395 //updating its properties 396 mapwin.updateEdge(active_edge); 397 } 398 else 399 { 400 target_node=INVALID; 401 std::cerr << "Loop edge is not yet implemented!" << std::endl; 402 } 403 } 404 //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore. 405 else 406 { 407 target_item=NULL; 408 } 409 } 410 } 299 { 300 //there is not yet selected node 301 if(active_node==INVALID) 302 { 303 //we mark the location of the event to be able to calculate parameters of dragging 304 305 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 306 307 active_item=(get_item_at(clicked_x, clicked_y)); 308 active_node=INVALID; 309 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 310 { 311 if(nodesmap[i]==active_item) 312 { 313 active_node=i; 314 } 315 } 316 //the clicked item is really a node 317 if(active_node!=INVALID) 318 { 319 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); 320 isbutton=1; 321 } 322 //clicked item was not a node. It could be e.g. edge. 323 else 324 { 325 active_item=NULL; 326 } 327 } 328 //we only have to do sg. if the mouse button 329 // is pressed already once AND the click was 330 // on a node that was found in the set of 331 //nodes, and now we only search for the second 332 //node 333 else 334 { 335 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); 336 target_item=(get_item_at(clicked_x, clicked_y)); 337 Node target_node=INVALID; 338 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) 339 { 340 if(nodesmap[i]==target_item) 341 { 342 target_node=i; 343 } 344 } 345 //the clicked item is a node, the edge can be drawn 346 if(target_node!=INVALID) 347 { 348 if(target_node!=active_node) 349 { 350 mapstorage.modified = true; 351 352 *(nodesmap[target_node]) << 353 Gnome::Canvas::Properties::fill_color("red"); 354 355 //creating new edge 356 active_edge=mapstorage.graph.addEdge(active_node, 357 target_node); 358 359 // update id map 360 (*mapstorage.edgemap_storage["id"])[active_edge] = 361 mapstorage.graph.id(active_edge); 362 363 // update all other maps 364 for (std::map<std::string, 365 Graph::EdgeMap<double>*>::const_iterator it = 366 mapstorage.edgemap_storage.begin(); it != 367 mapstorage.edgemap_storage.end(); ++it) 368 { 369 if (it->first != "id") 370 { 371 (*(it->second))[active_edge] = 372 mapstorage.edgemap_default[it->first]; 373 } 374 } 375 376 //calculating coordinates of new edge 377 Gnome::Canvas::Points coos; 378 double x1, x2, y1, y2; 379 380 active_item->get_bounds(x1, y1, x2, y2); 381 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 382 383 target_item->get_bounds(x1, y1, x2, y2); 384 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 385 386 //drawing new edge 387 edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, 388 *this); 389 *(edgesmap[active_edge]) << 390 Gnome::Canvas::Properties::fill_color("green"); 391 edgesmap[active_edge]->property_width_pixels().set_value(10); 392 393 edgesmap[active_edge]->lower_to_bottom(); 394 395 //initializing edge-text as well, to empty string 396 xy<double> text_pos=edgesmap[active_edge]->getArrowPos(); 397 text_pos+=(xy<double>(10,10)); 398 399 edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, 400 text_pos.x, text_pos.y, ""); 401 edgetextmap[active_edge]->property_fill_color().set_value( 402 "darkgreen"); 403 edgetextmap[active_edge]->raise_to_top(); 404 405 //updating its properties 406 mapwin.updateEdge(active_edge); 407 } 408 else 409 { 410 target_node=INVALID; 411 std::cerr << "Loop edge is not yet implemented!" << std::endl; 412 } 413 } 414 //clicked item was not a node. it could be an e.g. edge. we do not 415 //deal with it furthermore. 416 else 417 { 418 target_item=NULL; 419 } 420 } 421 } 411 422 break; 412 423 case GDK_BUTTON_RELEASE: … … 416 427 //2: the edge creation is cancelled with right button 417 428 if((target_item)||(e->button.button==3)) 418 419 420 421 422 423 424 425 426 427 428 429 430 431 429 { 430 if(active_item) 431 { 432 *active_item << Gnome::Canvas::Properties::fill_color("blue"); 433 active_item=NULL; 434 } 435 if(target_item) 436 { 437 *target_item << Gnome::Canvas::Properties::fill_color("blue"); 438 target_item=NULL; 439 } 440 active_node=INVALID; 441 active_edge=INVALID; 442 } 432 443 break; 433 444 default: 434 445 break; 435 446 } 436 447 return false; 437 448 } … … 589 600 if(clicked_edge!=INVALID) 590 601 { 602 // the id map is not editable 603 if (nodemap_to_edit == "id") return 0; 591 604 //If there is already edited edge, it has to be saved first 592 605 if(entrywidget.is_visible()) … … 712 725 if(clicked_node!=INVALID) 713 726 { 727 // the id map is not editable 728 if (nodemap_to_edit == "id") return 0; 714 729 //If there is already edited edge, it has to be saved first 715 730 if(entrywidget.is_visible()) … … 914 929 //if addition was not successful addEdgeMap returns one. 915 930 //cause can be that there is already a map named like the new one 916 if(mapstorage.addEdgeMap(mapname,emptr ))931 if(mapstorage.addEdgeMap(mapname,emptr, default_value)) 917 932 { 918 933 return 1; … … 936 951 //if addition was not successful addNodeMap returns one. 937 952 //cause can be that there is already a map named like the new one 938 if(mapstorage.addNodeMap(mapname,emptr ))953 if(mapstorage.addNodeMap(mapname,emptr, default_value)) 939 954 { 940 955 return 1; -
gui/graph_displayer_canvas.cc
r1632 r1645 63 63 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); 64 64 edgesmap[i]->property_width_units().set_value(10); 65 edgesmap[i]->lower_to_bottom(); 65 66 66 67 //initializing edge-text as well, to empty string … … 72 73 edgetextmap[i]->property_fill_color().set_value("darkgreen"); 73 74 edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false); 75 edgetextmap[i]->raise_to_top(); 74 76 } 75 77 … … 88 90 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); 89 91 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); 92 nodesmap[i]->raise_to_top(); 90 93 91 94 //initializing edge-text as well, to empty string … … 99 102 nodetextmap[i]->property_fill_color().set_value("darkblue"); 100 103 nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); 104 nodetextmap[i]->raise_to_top(); 101 105 } 102 106 -
gui/main_win.cc
r1635 r1645 265 265 { 266 266 Glib::ustring filename = fcdialog.get_filename(); 267 mapstorage.readFromFile(filename); 268 mapstorage.file_name = filename; 269 mapstorage.modified = false; 270 gd_canvas.drawGraph(); 271 mapwin.update(); 267 if (!mapstorage.readFromFile(filename)) 268 { 269 mapstorage.file_name = filename; 270 mapstorage.modified = false; 271 gd_canvas.drawGraph(); 272 mapwin.update(); 273 } 272 274 } 273 275 } -
gui/mapstorage.cc
r1643 r1645 1 1 #include "mapstorage.h" 2 #include <gtkmm.h> 2 3 #include <cmath> 3 4 … … 27 28 } 28 29 29 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap )30 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap, double default_value = 0.0) 30 31 { 31 32 if( nodemap_storage.find(name) == nodemap_storage.end() ) 32 33 { 33 34 nodemap_storage[name]=nodemap; 35 // set the maps default value 36 nodemap_default[name] = default_value; 34 37 return 0; 35 38 } … … 37 40 } 38 41 39 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap )42 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap, double default_value = 0.0) 40 43 { 41 44 if( edgemap_storage.find(name) == edgemap_storage.end() ) 42 45 { 43 46 edgemap_storage[name]=edgemap; 47 // set the maps default value 48 edgemap_default[name] = default_value; 44 49 return 0; 45 50 } … … 117 122 } 118 123 119 void MapStorage::initMapsForEdge(Edge e) 120 { 121 std::map< std::string,Graph::EdgeMap<double> * >::iterator ems_it; 122 for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++) 123 { 124 (*((*ems_it).second))[e]=5; 125 } 126 } 127 128 void MapStorage::readFromFile(const std::string &filename) 124 int MapStorage::readFromFile(const std::string &filename) 129 125 { 130 126 bool read_x = false; … … 180 176 greader.run(); 181 177 } catch (DataFormatError& error) { 182 /*183 178 Gtk::MessageDialog mdialog("Read Error"); 184 179 mdialog.set_message(error.what()); 185 180 mdialog.run(); 186 */ 187 // reset graph and mapstorage ? 188 return; 181 clear(); 182 return 1; 189 183 } 190 184 … … 206 200 } 207 201 } 202 203 // fill in the default values for the maps 204 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = 205 nodemap_storage.begin(); it != nodemap_storage.end(); ++it) 206 { 207 if ((it->first != "id") && 208 (it->first != "coordiantes_x") && 209 (it->first != "coordinates_y")) 210 { 211 nodemap_default[it->first] = 0.0; 212 } 213 } 214 for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it = 215 edgemap_storage.begin(); it != edgemap_storage.end(); ++it) 216 { 217 if (it->first != "id") 218 { 219 edgemap_default[it->first] = 0.0; 220 } 221 } 222 223 return 0; 208 224 } 209 225 … … 249 265 } 250 266 } 267 for (std::map<std::string, double>::iterator it = 268 nodemap_default.begin(); it != nodemap_default.end(); ++it) 269 { 270 nodemap_default.erase(it); 271 } 272 for (std::map<std::string, double>::iterator it = 273 edgemap_default.begin(); it != edgemap_default.end(); ++it) 274 { 275 edgemap_default.erase(it); 276 } 251 277 graph.clear(); 252 278 file_name = ""; -
gui/mapstorage.h
r1606 r1645 38 38 std::vector<Graph::EdgeMap<double> > default_edgemaps; 39 39 40 // Default values for the maps 41 std::map< std::string, double > nodemap_default; 42 43 // Default values for the maps 44 std::map< std::string, double > edgemap_default; 45 40 46 public: 41 47 ///Constructor of MapStorage. Expects the Graph of … … 53 59 ///\nodemap is the pointer of the given nodemap 54 60 ///\todo map should be given by reference! 55 int addNodeMap(const std::string &,Graph::NodeMap<double> * );61 int addNodeMap(const std::string &,Graph::NodeMap<double> *, double); 56 62 57 63 ///Adds given map to storage. A name and the map itself has to be provided. … … 59 65 ///\edgemap is the pointer of the given edgemap 60 66 ///\todo map should be given by reference! 61 int addEdgeMap(const std::string &,Graph::EdgeMap<double> * );67 int addEdgeMap(const std::string &,Graph::EdgeMap<double> *, double); 62 68 63 69 ///Returns how much nodemaps is stored in \ref MapStorage … … 95 101 std::map< std::string,Graph::EdgeMap<double> * >::iterator endOfEdgeMaps(){return edgemap_storage.end();}; 96 102 97 ///This function sets a default base value for the newly created node 98 void initMapsForNode(NodeIt); 99 100 ///This function sets a default base value for the newly created node 101 void initMapsForEdge(Graph::Edge); 102 103 void readFromFile(const std::string &); 103 int readFromFile(const std::string &); 104 104 void writeToFile(const std::string &); 105 105
Note: See TracChangeset
for help on using the changeset viewer.