# HG changeset patch # User ladanyi # Date 1124782569 0 # Node ID 4a04bb856ac704a0fc665c9c8738a410d2a7945e # Parent 62548b317e6584dd69962ab6087cfe7fbd2a4ca8 - id maps are not editable - handle exceptions thrown by the file reader - texts are always above the edges - store a default value for all maps, so that edges and nodes created after adding a new map receive the default value too - create node on button release, not on click (fixes a few oddities) diff -r 62548b317e65 -r 4a04bb856ac7 gui/broken_edge.cc --- a/gui/broken_edge.cc Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/broken_edge.cc Tue Aug 23 07:36:09 2005 +0000 @@ -8,6 +8,7 @@ arrow=new Gnome::Canvas::Polygon(g); *arrow << Gnome::Canvas::Properties::fill_color("red"); arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edgeFormerEventHandler)); + arrow->lower_to_bottom(); setPoints(p); } diff -r 62548b317e65 -r 4a04bb856ac7 gui/graph_displayer_canvas-edge.cc --- a/gui/graph_displayer_canvas-edge.cc Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/graph_displayer_canvas-edge.cc Tue Aug 23 07:36:09 2005 +0000 @@ -122,7 +122,7 @@ //EXCEPT when the name of the map is Default, because //in that case empty string will be written, because //that is the deleter map - + if(edge==INVALID) { for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) diff -r 62548b317e65 -r 4a04bb856ac7 gui/graph_displayer_canvas-event.cc --- a/gui/graph_displayer_canvas-event.cc Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/graph_displayer_canvas-event.cc Tue Aug 23 07:36:09 2005 +0000 @@ -214,13 +214,19 @@ bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e) { switch(e->type) - { + { + //move the new node + case GDK_MOTION_NOTIFY: + { + GdkEvent * generated=new GdkEvent(); + generated->motion.x=e->motion.x; + generated->motion.y=e->motion.y; + generated->type=GDK_MOTION_NOTIFY; + moveEventHandler(generated); + break; + } - //draw the new node in red at the clicked place - case GDK_2BUTTON_PRESS: - //std::cout << "double click" << std::endl; - break; - case GDK_BUTTON_PRESS: + case GDK_BUTTON_RELEASE: mapstorage.modified = true; isbutton=1; @@ -231,183 +237,188 @@ window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); + // update coordinates mapstorage.coords.set(active_node, xy(clicked_x, clicked_y)); + + // update id map (*mapstorage.nodemap_storage["id"])[active_node] = mapstorage.graph.id(active_node); + // update all other maps + for (std::map*>::const_iterator it = + mapstorage.nodemap_storage.begin(); it != + mapstorage.nodemap_storage.end(); ++it) + { + if ((it->first != "id") && + (it->first != "coordinates_x") && + (it->first != "coordiantes_y")) + { + (*(it->second))[active_node] = + mapstorage.nodemap_default[it->first]; + } + } + nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, - clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); + clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); - *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); - *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black"); + *(nodesmap[active_node]) << + Gnome::Canvas::Properties::fill_color("blue"); + *(nodesmap[active_node]) << + Gnome::Canvas::Properties::outline_color("black"); + active_item->raise_to_top(); + (nodesmap[active_node])->show(); nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, - clicked_x+node_property_defaults[N_RADIUS]+5, - clicked_y+node_property_defaults[N_RADIUS]+5, ""); + clicked_x+node_property_defaults[N_RADIUS]+5, + clicked_y+node_property_defaults[N_RADIUS]+5, ""); nodetextmap[active_node]->property_fill_color().set_value("darkblue"); + nodetextmap[active_node]->raise_to_top(); mapwin.updateNode(active_node); - break; - - //move the new node - case GDK_MOTION_NOTIFY: - { - GdkEvent * generated=new GdkEvent(); - generated->motion.x=e->motion.x; - generated->motion.y=e->motion.y; - generated->type=GDK_MOTION_NOTIFY; - moveEventHandler(generated); - break; - } - - //finalize the new node - case GDK_BUTTON_RELEASE: - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - - active_item->lower_to_bottom(); - - target_item=NULL; - target_item=get_item_at(clicked_x, clicked_y); - - active_item->raise_to_top(); - isbutton=0; - if(target_item==active_item) - { - //Its appropriate color is given by update. - *active_item << Gnome::Canvas::Properties::fill_color("blue"); - } - else - { - //In this case the given color has to be overwritten, because the noe covers an other item. - *active_item << Gnome::Canvas::Properties::fill_color("lightblue"); - } target_item=NULL; active_item=NULL; active_node=INVALID; + break; default: break; - } + } return false; } bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e) { switch(e->type) - { + { case GDK_BUTTON_PRESS: //in edge creation right button has special meaning if(e->button.button!=3) - { - //there is not yet selected node - if(active_node==INVALID) - { - //we mark the location of the event to be able to calculate parameters of dragging + { + //there is not yet selected node + if(active_node==INVALID) + { + //we mark the location of the event to be able to calculate parameters of dragging - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - active_item=(get_item_at(clicked_x, clicked_y)); - active_node=INVALID; - for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) - { - if(nodesmap[i]==active_item) - { - active_node=i; - } - } - //the clicked item is really a node - if(active_node!=INVALID) - { - *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); - isbutton=1; - } - //clicked item was not a node. It could be e.g. edge. - else - { - active_item=NULL; - } - } - //we only have to do sg. if the mouse button - // is pressed already once AND the click was - // on a node that was found in the set of - //nodes, and now we only search for the second - //node - else - { - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); - target_item=(get_item_at(clicked_x, clicked_y)); - Node target_node=INVALID; - for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) - { - if(nodesmap[i]==target_item) - { - target_node=i; - } - } - //the clicked item is a node, the edge can be drawn - if(target_node!=INVALID) - { - if(target_node!=active_node) - { - mapstorage.modified = true; + active_item=(get_item_at(clicked_x, clicked_y)); + active_node=INVALID; + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) + { + if(nodesmap[i]==active_item) + { + active_node=i; + } + } + //the clicked item is really a node + if(active_node!=INVALID) + { + *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red"); + isbutton=1; + } + //clicked item was not a node. It could be e.g. edge. + else + { + active_item=NULL; + } + } + //we only have to do sg. if the mouse button + // is pressed already once AND the click was + // on a node that was found in the set of + //nodes, and now we only search for the second + //node + else + { + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); + target_item=(get_item_at(clicked_x, clicked_y)); + Node target_node=INVALID; + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) + { + if(nodesmap[i]==target_item) + { + target_node=i; + } + } + //the clicked item is a node, the edge can be drawn + if(target_node!=INVALID) + { + if(target_node!=active_node) + { + mapstorage.modified = true; - *(nodesmap[target_node]) << - Gnome::Canvas::Properties::fill_color("red"); + *(nodesmap[target_node]) << + Gnome::Canvas::Properties::fill_color("red"); - //creating new edge - active_edge=mapstorage.graph.addEdge(active_node, - target_node); + //creating new edge + active_edge=mapstorage.graph.addEdge(active_node, + target_node); - //initiating values corresponding to new edge in maps - mapstorage.initMapsForEdge(active_edge); - (*mapstorage.edgemap_storage["id"])[active_edge] = - mapstorage.graph.id(active_edge); - - //calculating coordinates of new edge - Gnome::Canvas::Points coos; - double x1, x2, y1, y2; - - active_item->get_bounds(x1, y1, x2, y2); - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + // update id map + (*mapstorage.edgemap_storage["id"])[active_edge] = + mapstorage.graph.id(active_edge); + + // update all other maps + for (std::map*>::const_iterator it = + mapstorage.edgemap_storage.begin(); it != + mapstorage.edgemap_storage.end(); ++it) + { + if (it->first != "id") + { + (*(it->second))[active_edge] = + mapstorage.edgemap_default[it->first]; + } + } - target_item->get_bounds(x1, y1, x2, y2); - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + //calculating coordinates of new edge + Gnome::Canvas::Points coos; + double x1, x2, y1, y2; - //drawing new edge - edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this); - *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green"); - edgesmap[active_edge]->property_width_pixels().set_value(10); + active_item->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - //redraw nodes to blank terminations of the new edge - target_item->raise_to_top(); - active_item->raise_to_top(); + target_item->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); - //initializing edge-text as well, to empty string - xy text_pos=edgesmap[active_edge]->getArrowPos(); - text_pos+=(xy(10,10)); + //drawing new edge + edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, + *this); + *(edgesmap[active_edge]) << + Gnome::Canvas::Properties::fill_color("green"); + edgesmap[active_edge]->property_width_pixels().set_value(10); - edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); - edgetextmap[active_edge]->property_fill_color().set_value("darkgreen"); + edgesmap[active_edge]->lower_to_bottom(); - //updating its properties - mapwin.updateEdge(active_edge); - } - else - { - target_node=INVALID; - std::cerr << "Loop edge is not yet implemented!" << std::endl; - } - } - //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore. - else - { - target_item=NULL; - } - } - } + //initializing edge-text as well, to empty string + xy text_pos=edgesmap[active_edge]->getArrowPos(); + text_pos+=(xy(10,10)); + + edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, + text_pos.x, text_pos.y, ""); + edgetextmap[active_edge]->property_fill_color().set_value( + "darkgreen"); + edgetextmap[active_edge]->raise_to_top(); + + //updating its properties + mapwin.updateEdge(active_edge); + } + else + { + target_node=INVALID; + std::cerr << "Loop edge is not yet implemented!" << std::endl; + } + } + //clicked item was not a node. it could be an e.g. edge. we do not + //deal with it furthermore. + else + { + target_item=NULL; + } + } + } break; case GDK_BUTTON_RELEASE: isbutton=0; @@ -415,24 +426,24 @@ //1: the edge is ready (target_item has valid value) //2: the edge creation is cancelled with right button if((target_item)||(e->button.button==3)) - { - if(active_item) - { - *active_item << Gnome::Canvas::Properties::fill_color("blue"); - active_item=NULL; - } - if(target_item) - { - *target_item << Gnome::Canvas::Properties::fill_color("blue"); - target_item=NULL; - } - active_node=INVALID; - active_edge=INVALID; - } + { + if(active_item) + { + *active_item << Gnome::Canvas::Properties::fill_color("blue"); + active_item=NULL; + } + if(target_item) + { + *target_item << Gnome::Canvas::Properties::fill_color("blue"); + target_item=NULL; + } + active_node=INVALID; + active_edge=INVALID; + } break; default: break; - } + } return false; } @@ -588,6 +599,8 @@ //if it was really an edge... if(clicked_edge!=INVALID) { + // the id map is not editable + if (nodemap_to_edit == "id") return 0; //If there is already edited edge, it has to be saved first if(entrywidget.is_visible()) { @@ -711,6 +724,8 @@ //if it was really an edge... if(clicked_node!=INVALID) { + // the id map is not editable + if (nodemap_to_edit == "id") return 0; //If there is already edited edge, it has to be saved first if(entrywidget.is_visible()) { @@ -913,7 +928,7 @@ //if addition was not successful addEdgeMap returns one. //cause can be that there is already a map named like the new one - if(mapstorage.addEdgeMap(mapname,emptr)) + if(mapstorage.addEdgeMap(mapname,emptr, default_value)) { return 1; } @@ -935,7 +950,7 @@ //if addition was not successful addNodeMap returns one. //cause can be that there is already a map named like the new one - if(mapstorage.addNodeMap(mapname,emptr)) + if(mapstorage.addNodeMap(mapname,emptr, default_value)) { return 1; } diff -r 62548b317e65 -r 4a04bb856ac7 gui/graph_displayer_canvas.cc --- a/gui/graph_displayer_canvas.cc Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/graph_displayer_canvas.cc Tue Aug 23 07:36:09 2005 +0000 @@ -62,6 +62,7 @@ edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this); *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); edgesmap[i]->property_width_units().set_value(10); + edgesmap[i]->lower_to_bottom(); //initializing edge-text as well, to empty string @@ -71,6 +72,7 @@ edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); edgetextmap[i]->property_fill_color().set_value("darkgreen"); edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false); + edgetextmap[i]->raise_to_top(); } //afterwards nodes come to be drawn @@ -87,6 +89,7 @@ mapstorage.coords[i].y+20); *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); + nodesmap[i]->raise_to_top(); //initializing edge-text as well, to empty string @@ -98,6 +101,7 @@ text_pos.x, text_pos.y, ""); nodetextmap[i]->property_fill_color().set_value("darkblue"); nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); + nodetextmap[i]->raise_to_top(); } updateScrollRegion(); diff -r 62548b317e65 -r 4a04bb856ac7 gui/main_win.cc --- a/gui/main_win.cc Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/main_win.cc Tue Aug 23 07:36:09 2005 +0000 @@ -264,11 +264,13 @@ if (fcdialog.run() == Gtk::RESPONSE_ACCEPT) { Glib::ustring filename = fcdialog.get_filename(); - mapstorage.readFromFile(filename); - mapstorage.file_name = filename; - mapstorage.modified = false; - gd_canvas.drawGraph(); - mapwin.update(); + if (!mapstorage.readFromFile(filename)) + { + mapstorage.file_name = filename; + mapstorage.modified = false; + gd_canvas.drawGraph(); + mapwin.update(); + } } } diff -r 62548b317e65 -r 4a04bb856ac7 gui/mapstorage.cc --- a/gui/mapstorage.cc Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/mapstorage.cc Tue Aug 23 07:36:09 2005 +0000 @@ -1,4 +1,5 @@ #include "mapstorage.h" +#include #include MapStorage::MapStorage() : modified(false), file_name("") @@ -26,21 +27,25 @@ } } -int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap) +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap *nodemap, double default_value = 0.0) { if( nodemap_storage.find(name) == nodemap_storage.end() ) { nodemap_storage[name]=nodemap; + // set the maps default value + nodemap_default[name] = default_value; return 0; } return 1; } -int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap) +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap *edgemap, double default_value = 0.0) { if( edgemap_storage.find(name) == edgemap_storage.end() ) { edgemap_storage[name]=edgemap; + // set the maps default value + edgemap_default[name] = default_value; return 0; } return 1; @@ -116,16 +121,7 @@ return min; } -void MapStorage::initMapsForEdge(Edge e) -{ - std::map< std::string,Graph::EdgeMap * >::iterator ems_it; - for(ems_it=edgemap_storage.begin();ems_it!=edgemap_storage.end();ems_it++) - { - (*((*ems_it).second))[e]=5; - } -} - -void MapStorage::readFromFile(const std::string &filename) +int MapStorage::readFromFile(const std::string &filename) { bool read_x = false; bool read_y = false; @@ -179,13 +175,11 @@ } greader.run(); } catch (DataFormatError& error) { - /* Gtk::MessageDialog mdialog("Read Error"); mdialog.set_message(error.what()); mdialog.run(); - */ - // reset graph and mapstorage ? - return; + clear(); + return 1; } if (!read_x || !read_y) @@ -205,6 +199,28 @@ i++; } } + + // fill in the default values for the maps + for (std::map*>::const_iterator it = + nodemap_storage.begin(); it != nodemap_storage.end(); ++it) + { + if ((it->first != "id") && + (it->first != "coordiantes_x") && + (it->first != "coordinates_y")) + { + nodemap_default[it->first] = 0.0; + } + } + for (std::map*>::const_iterator it = + edgemap_storage.begin(); it != edgemap_storage.end(); ++it) + { + if (it->first != "id") + { + edgemap_default[it->first] = 0.0; + } + } + + return 0; } void MapStorage::writeToFile(const std::string &filename) @@ -248,6 +264,16 @@ edgemap_storage.erase(it); } } + for (std::map::iterator it = + nodemap_default.begin(); it != nodemap_default.end(); ++it) + { + nodemap_default.erase(it); + } + for (std::map::iterator it = + edgemap_default.begin(); it != edgemap_default.end(); ++it) + { + edgemap_default.erase(it); + } graph.clear(); file_name = ""; modified = false; diff -r 62548b317e65 -r 4a04bb856ac7 gui/mapstorage.h --- a/gui/mapstorage.h Fri Aug 19 12:09:21 2005 +0000 +++ b/gui/mapstorage.h Tue Aug 23 07:36:09 2005 +0000 @@ -37,6 +37,12 @@ //Stores the default values for the different visualization edge attributes std::vector > default_edgemaps; + // Default values for the maps + std::map< std::string, double > nodemap_default; + + // Default values for the maps + std::map< std::string, double > edgemap_default; + public: ///Constructor of MapStorage. Expects the Graph of ///which maps will be stored in it. @@ -52,13 +58,13 @@ ///\param name is the name of map ///\nodemap is the pointer of the given nodemap ///\todo map should be given by reference! - int addNodeMap(const std::string &,Graph::NodeMap *); + int addNodeMap(const std::string &,Graph::NodeMap *, double); ///Adds given map to storage. A name and the map itself has to be provided. ///\param name is the name of map ///\edgemap is the pointer of the given edgemap ///\todo map should be given by reference! - int addEdgeMap(const std::string &,Graph::EdgeMap *); + int addEdgeMap(const std::string &,Graph::EdgeMap *, double); ///Returns how much nodemaps is stored in \ref MapStorage int numOfNodeMaps() {return nodemap_storage.size();}; @@ -94,13 +100,7 @@ ///To be able to iterate through each maps this function returns an iterator pointing to the last edgemap in the storage. std::map< std::string,Graph::EdgeMap * >::iterator endOfEdgeMaps(){return edgemap_storage.end();}; - ///This function sets a default base value for the newly created node - void initMapsForNode(NodeIt); - - ///This function sets a default base value for the newly created node - void initMapsForEdge(Graph::Edge); - - void readFromFile(const std::string &); + int readFromFile(const std::string &); void writeToFile(const std::string &); void clear();