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; }