# HG changeset patch # User hegyi # Date 1118404683 0 # Node ID 0bb1675306cb9ab00522d406f85598cda93e5839 # Parent abac0179a26ad467a06d2db32b5be21dc237fd8c Hopefully, node creation works well, after a small structural consideration. diff -r abac0179a26a -r 0bb1675306cb Makefile.am --- a/Makefile.am Mon Jun 06 17:01:12 2005 +0000 +++ b/Makefile.am Fri Jun 10 11:58:03 2005 +0000 @@ -13,7 +13,9 @@ mapstorage.cc \ mapstorage.h \ map_win.cc \ - map_win.h + map_win.h \ + edit_win.cc \ + edit_win.h gd_CXXFLAGS = $(GTK_CFLAGS) gd_LDFLAGS = $(GTK_LIBS) diff -r abac0179a26a -r 0bb1675306cb all_include.h --- a/all_include.h Mon Jun 06 17:01:12 2005 +0000 +++ b/all_include.h Fri Jun 10 11:58:03 2005 +0000 @@ -16,7 +16,8 @@ #include #include -enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties; +enum {WIDTH, COLOR, TEXT, PROPERTY_NUM}; // edge properties; +enum {MOVE, CREATE_NODE, CREATE_EDGE, TOOL_NUM}; // tools; #define RANGE 3 #define WIN_WIDTH 900 #define WIN_HEIGHT 600 diff -r abac0179a26a -r 0bb1675306cb graph_displayer_canvas.cc --- a/graph_displayer_canvas.cc Mon Jun 06 17:01:12 2005 +0000 +++ b/graph_displayer_canvas.cc Fri Jun 10 11:58:03 2005 +0000 @@ -3,6 +3,12 @@ GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL) { + Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20); + *origo << Gnome::Canvas::Properties::fill_color("black"); + *origo << Gnome::Canvas::Properties::outline_color("black"); + + actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false); + //set_center_scroll_region(true); //first edges are drawn, to hide joining with nodes later @@ -48,20 +54,9 @@ nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20); *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); - (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); + //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); } -/* - //setting zoom to be able to see the whole graph on the canvas - - double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80); - double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); - - set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2)); - std::cout<get_bounds(wx1, wy1, wx2, wy2); set_scroll_region(wx1, wy1, wx2, wy2); } + +void GraphDisplayerCanvas::changeEditorialTool(int newtool) +{ + actual_handler.disconnect(); + + switch(newtool) + { + case MOVE: + actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false); + break; + case CREATE_NODE: + actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false); + break; + case CREATE_EDGE: + actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false); + break; + default: + break; + } +} + +bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e) +{ + switch(e->type) + { + case GDK_BUTTON_PRESS: + //we mark the location of the event to be able to calculate parameters of dragging + clicked_x=e->button.x; + clicked_y=e->button.y; + active_item=(get_item_at(e->button.x, e->button.y)); + active_node=INVALID; + for (NodeIt i(g); i!=INVALID; ++i) + { + if(nodesmap[i]==active_item) + { + active_node=i; + } + } + isbutton=true; + break; + case GDK_BUTTON_RELEASE: + isbutton=false; + active_item=NULL; + updateScrollRegion(); + break; + case GDK_MOTION_NOTIFY: + //we only have to do sg. if the mouse button is pressed + if(isbutton) + { + //new coordinates will be the old values, + //because the item will be moved to the + //new coordinate therefore the new movement + //has to be calculated from here + + double dx=e->motion.x-clicked_x; + double dy=e->motion.y-clicked_y; + + active_item->move(dx, dy); + + clicked_x=e->motion.x; + clicked_y=e->motion.y; + + //all the edges connected to the moved point has to be redrawn + + EdgeIt e; + + g.firstOut(e,active_node); + + for(;e!=INVALID;g.nextOut(e)) + { + Gnome::Canvas::Points coos; + double x1, x2, y1, y2; + + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + edgesmap[e]->property_points().set_value(coos); + + edgesmap[e]->get_bounds(x1, y1, x2, y2); + + edgetextmap[e]->property_x().set_value((x1+x2)/2); + edgetextmap[e]->property_y().set_value((y1+y2)/2); + } + + g.firstIn(e,active_node); + for(;e!=INVALID;g.nextIn(e)) + { + Gnome::Canvas::Points coos; + double x1, x2, y1, y2; + + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + edgesmap[e]->property_points().set_value(coos); + + edgesmap[e]->get_bounds(x1, y1, x2, y2); + + edgetextmap[e]->property_x().set_value((x1+x2)/2); + edgetextmap[e]->property_y().set_value((y1+y2)/2); + } + } + default: break; + } + + return true; +} + +bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e) +{ + switch(e->type) + { + case GDK_BUTTON_PRESS: + isbutton=true; + + active_node=NodeIt(g,g.addNode()); + + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); + + nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, 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])->show(); + break; + case GDK_MOTION_NOTIFY: + { + double world_motion_x, world_motion_y; + GdkEvent * generated=new GdkEvent(); + window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y); + generated->motion.x=world_motion_x; + generated->motion.y=world_motion_y; + generated->type=GDK_MOTION_NOTIFY; + move_event_handler(generated); + break; + } + case GDK_BUTTON_RELEASE: + isbutton=false; + *active_item << Gnome::Canvas::Properties::fill_color("blue"); + active_item=NULL; + updateScrollRegion(); + break; + default: + break; + } + return false; +} + +bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e) +{ + e=e; + return false; +} + diff -r abac0179a26a -r 0bb1675306cb graph_displayer_canvas.h --- a/graph_displayer_canvas.h Mon Jun 06 17:01:12 2005 +0000 +++ b/graph_displayer_canvas.h Fri Jun 10 11:58:03 2005 +0000 @@ -40,6 +40,9 @@ ///Sets the scroll region of the convas to the bounding box of the graph. void updateScrollRegion(); + ///This function changes the tool in the graph-editor's hand + void changeEditorialTool(int); + protected: //maximizing, minimizing, restoring window, etc. @@ -52,6 +55,18 @@ ///of the canvas bool event_handler(GdkEvent* e, Node n); + ///actual event handler + /// + ///Actual event handler should be stored, to be able to disconnect it and later reconnect it. + sigc::connection actual_handler; + + ///event handler for the case when move-tool is active + bool move_event_handler(GdkEvent*); + ///event handler for the case when create_node-tool is active + bool create_node_event_handler(GdkEvent*); + ///event handler for the case when create_edge-tool is active + bool create_edge_event_handler(GdkEvent*); + ///The graph, on which we work Graph g; @@ -82,6 +97,7 @@ ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution Gnome::Canvas::Item * active_item; + Graph::NodeIt active_node; static const int zoom_step = 5; }; diff -r abac0179a26a -r 0bb1675306cb main_win.cc --- a/main_win.cc Mon Jun 06 17:01:12 2005 +0000 +++ b/main_win.cc Fri Jun 10 11:58:03 2005 +0000 @@ -1,7 +1,7 @@ #include MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, - MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms) + MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms) { set_title (title); set_default_size(WIN_WIDTH,WIN_HEIGHT); @@ -34,6 +34,8 @@ ag->add( Gtk::Action::create("ShowMenu", "_Show") ); ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps)); + ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"), + sigc::mem_fun(*this, &MainWin::showEditorials)); uim=Gtk::UIManager::create(); uim->insert_action_group(ag); @@ -60,6 +62,7 @@ " " " " " " + " " " " " " " " @@ -107,6 +110,11 @@ mapwin.show(); } +void MainWin::showEditorials() +{ + editwin.show(); +} + void MainWin::quit() { hide(); diff -r abac0179a26a -r 0bb1675306cb main_win.h --- a/main_win.h Mon Jun 06 17:01:12 2005 +0000 +++ b/main_win.h Fri Jun 10 11:58:03 2005 +0000 @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -25,6 +26,9 @@ ///Window of map-showing setup. Its type is \ref MapWin MapWin mapwin; + ///Window of editorial tools. Its type is \ref EditWin + EditWin editwin; + ///The graph will be drawn on this \ref GraphDisplayerCanvas GraphDisplayerCanvas gd_canvas; @@ -39,6 +43,8 @@ ///This function makes map-setup window popped up. virtual void showMaps(); + ///This function makes editorial window popped up. + virtual void showEditorials(); ///Callback for 'FileNew' action. virtual void newFile(); ///Callback for 'FileOpen' action.