Hopefully, node creation works well, after a small structural consideration.
1.1 --- a/Makefile.am Mon Jun 06 17:01:12 2005 +0000
1.2 +++ b/Makefile.am Fri Jun 10 11:58:03 2005 +0000
1.3 @@ -13,7 +13,9 @@
1.4 mapstorage.cc \
1.5 mapstorage.h \
1.6 map_win.cc \
1.7 - map_win.h
1.8 + map_win.h \
1.9 + edit_win.cc \
1.10 + edit_win.h
1.11
1.12 gd_CXXFLAGS = $(GTK_CFLAGS)
1.13 gd_LDFLAGS = $(GTK_LIBS)
2.1 --- a/all_include.h Mon Jun 06 17:01:12 2005 +0000
2.2 +++ b/all_include.h Fri Jun 10 11:58:03 2005 +0000
2.3 @@ -16,7 +16,8 @@
2.4 #include <lemon/error.h>
2.5 #include <lemon/xy.h>
2.6
2.7 -enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
2.8 +enum {WIDTH, COLOR, TEXT, PROPERTY_NUM}; // edge properties;
2.9 +enum {MOVE, CREATE_NODE, CREATE_EDGE, TOOL_NUM}; // tools;
2.10 #define RANGE 3
2.11 #define WIN_WIDTH 900
2.12 #define WIN_HEIGHT 600
3.1 --- a/graph_displayer_canvas.cc Mon Jun 06 17:01:12 2005 +0000
3.2 +++ b/graph_displayer_canvas.cc Fri Jun 10 11:58:03 2005 +0000
3.3 @@ -3,6 +3,12 @@
3.4
3.5 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)
3.6 {
3.7 + Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
3.8 + *origo << Gnome::Canvas::Properties::fill_color("black");
3.9 + *origo << Gnome::Canvas::Properties::outline_color("black");
3.10 +
3.11 + actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
3.12 +
3.13 //set_center_scroll_region(true);
3.14
3.15 //first edges are drawn, to hide joining with nodes later
3.16 @@ -48,20 +54,9 @@
3.17 nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
3.18 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
3.19 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
3.20 - (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
3.21 + //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
3.22 }
3.23
3.24 -/*
3.25 - //setting zoom to be able to see the whole graph on the canvas
3.26 -
3.27 - double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
3.28 - double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
3.29 -
3.30 - set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
3.31 - std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
3.32 - std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
3.33 - std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
3.34 -*/
3.35 updateScrollRegion();
3.36 }
3.37
3.38 @@ -308,3 +303,162 @@
3.39 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
3.40 set_scroll_region(wx1, wy1, wx2, wy2);
3.41 }
3.42 +
3.43 +void GraphDisplayerCanvas::changeEditorialTool(int newtool)
3.44 +{
3.45 + actual_handler.disconnect();
3.46 +
3.47 + switch(newtool)
3.48 + {
3.49 + case MOVE:
3.50 + actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
3.51 + break;
3.52 + case CREATE_NODE:
3.53 + actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
3.54 + break;
3.55 + case CREATE_EDGE:
3.56 + actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
3.57 + break;
3.58 + default:
3.59 + break;
3.60 + }
3.61 +}
3.62 +
3.63 +bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
3.64 +{
3.65 + switch(e->type)
3.66 + {
3.67 + case GDK_BUTTON_PRESS:
3.68 + //we mark the location of the event to be able to calculate parameters of dragging
3.69 + clicked_x=e->button.x;
3.70 + clicked_y=e->button.y;
3.71 + active_item=(get_item_at(e->button.x, e->button.y));
3.72 + active_node=INVALID;
3.73 + for (NodeIt i(g); i!=INVALID; ++i)
3.74 + {
3.75 + if(nodesmap[i]==active_item)
3.76 + {
3.77 + active_node=i;
3.78 + }
3.79 + }
3.80 + isbutton=true;
3.81 + break;
3.82 + case GDK_BUTTON_RELEASE:
3.83 + isbutton=false;
3.84 + active_item=NULL;
3.85 + updateScrollRegion();
3.86 + break;
3.87 + case GDK_MOTION_NOTIFY:
3.88 + //we only have to do sg. if the mouse button is pressed
3.89 + if(isbutton)
3.90 + {
3.91 + //new coordinates will be the old values,
3.92 + //because the item will be moved to the
3.93 + //new coordinate therefore the new movement
3.94 + //has to be calculated from here
3.95 +
3.96 + double dx=e->motion.x-clicked_x;
3.97 + double dy=e->motion.y-clicked_y;
3.98 +
3.99 + active_item->move(dx, dy);
3.100 +
3.101 + clicked_x=e->motion.x;
3.102 + clicked_y=e->motion.y;
3.103 +
3.104 + //all the edges connected to the moved point has to be redrawn
3.105 +
3.106 + EdgeIt e;
3.107 +
3.108 + g.firstOut(e,active_node);
3.109 +
3.110 + for(;e!=INVALID;g.nextOut(e))
3.111 + {
3.112 + Gnome::Canvas::Points coos;
3.113 + double x1, x2, y1, y2;
3.114 +
3.115 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
3.116 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
3.117 +
3.118 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
3.119 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
3.120 +
3.121 + edgesmap[e]->property_points().set_value(coos);
3.122 +
3.123 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
3.124 +
3.125 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
3.126 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
3.127 + }
3.128 +
3.129 + g.firstIn(e,active_node);
3.130 + for(;e!=INVALID;g.nextIn(e))
3.131 + {
3.132 + Gnome::Canvas::Points coos;
3.133 + double x1, x2, y1, y2;
3.134 +
3.135 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
3.136 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
3.137 +
3.138 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
3.139 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
3.140 +
3.141 + edgesmap[e]->property_points().set_value(coos);
3.142 +
3.143 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
3.144 +
3.145 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
3.146 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
3.147 + }
3.148 + }
3.149 + default: break;
3.150 + }
3.151 +
3.152 + return true;
3.153 +}
3.154 +
3.155 +bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
3.156 +{
3.157 + switch(e->type)
3.158 + {
3.159 + case GDK_BUTTON_PRESS:
3.160 + isbutton=true;
3.161 +
3.162 + active_node=NodeIt(g,g.addNode());
3.163 +
3.164 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
3.165 +
3.166 + nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
3.167 + active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
3.168 + *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
3.169 + *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
3.170 + (nodesmap[active_node])->show();
3.171 + break;
3.172 + case GDK_MOTION_NOTIFY:
3.173 + {
3.174 + double world_motion_x, world_motion_y;
3.175 + GdkEvent * generated=new GdkEvent();
3.176 + window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
3.177 + generated->motion.x=world_motion_x;
3.178 + generated->motion.y=world_motion_y;
3.179 + generated->type=GDK_MOTION_NOTIFY;
3.180 + move_event_handler(generated);
3.181 + break;
3.182 + }
3.183 + case GDK_BUTTON_RELEASE:
3.184 + isbutton=false;
3.185 + *active_item << Gnome::Canvas::Properties::fill_color("blue");
3.186 + active_item=NULL;
3.187 + updateScrollRegion();
3.188 + break;
3.189 + default:
3.190 + break;
3.191 + }
3.192 + return false;
3.193 +}
3.194 +
3.195 +bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
3.196 +{
3.197 + e=e;
3.198 + return false;
3.199 +}
3.200 +
4.1 --- a/graph_displayer_canvas.h Mon Jun 06 17:01:12 2005 +0000
4.2 +++ b/graph_displayer_canvas.h Fri Jun 10 11:58:03 2005 +0000
4.3 @@ -40,6 +40,9 @@
4.4 ///Sets the scroll region of the convas to the bounding box of the graph.
4.5 void updateScrollRegion();
4.6
4.7 + ///This function changes the tool in the graph-editor's hand
4.8 + void changeEditorialTool(int);
4.9 +
4.10 protected:
4.11
4.12 //maximizing, minimizing, restoring window, etc.
4.13 @@ -52,6 +55,18 @@
4.14 ///of the canvas
4.15 bool event_handler(GdkEvent* e, Node n);
4.16
4.17 + ///actual event handler
4.18 + ///
4.19 + ///Actual event handler should be stored, to be able to disconnect it and later reconnect it.
4.20 + sigc::connection actual_handler;
4.21 +
4.22 + ///event handler for the case when move-tool is active
4.23 + bool move_event_handler(GdkEvent*);
4.24 + ///event handler for the case when create_node-tool is active
4.25 + bool create_node_event_handler(GdkEvent*);
4.26 + ///event handler for the case when create_edge-tool is active
4.27 + bool create_edge_event_handler(GdkEvent*);
4.28 +
4.29 ///The graph, on which we work
4.30 Graph g;
4.31
4.32 @@ -82,6 +97,7 @@
4.33 ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
4.34 ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
4.35 Gnome::Canvas::Item * active_item;
4.36 + Graph::NodeIt active_node;
4.37
4.38 static const int zoom_step = 5;
4.39 };
5.1 --- a/main_win.cc Mon Jun 06 17:01:12 2005 +0000
5.2 +++ b/main_win.cc Fri Jun 10 11:58:03 2005 +0000
5.3 @@ -1,7 +1,7 @@
5.4 #include <main_win.h>
5.5
5.6 MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
5.7 - MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
5.8 + MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms)
5.9 {
5.10 set_title (title);
5.11 set_default_size(WIN_WIDTH,WIN_HEIGHT);
5.12 @@ -34,6 +34,8 @@
5.13 ag->add( Gtk::Action::create("ShowMenu", "_Show") );
5.14 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
5.15 sigc::mem_fun(*this, &MainWin::showMaps));
5.16 + ag->add( Gtk::Action::create("ShowEditorials", "_Editorials"),
5.17 + sigc::mem_fun(*this, &MainWin::showEditorials));
5.18
5.19 uim=Gtk::UIManager::create();
5.20 uim->insert_action_group(ag);
5.21 @@ -60,6 +62,7 @@
5.22 " </menu>"
5.23 " <menu action='ShowMenu'>"
5.24 " <menuitem action='ShowMaps'/>"
5.25 + " <menuitem action='ShowEditorials'/>"
5.26 " </menu>"
5.27 " </menubar>"
5.28 " <toolbar name='ToolBar'>"
5.29 @@ -107,6 +110,11 @@
5.30 mapwin.show();
5.31 }
5.32
5.33 +void MainWin::showEditorials()
5.34 +{
5.35 + editwin.show();
5.36 +}
5.37 +
5.38 void MainWin::quit()
5.39 {
5.40 hide();
6.1 --- a/main_win.h Mon Jun 06 17:01:12 2005 +0000
6.2 +++ b/main_win.h Fri Jun 10 11:58:03 2005 +0000
6.3 @@ -6,6 +6,7 @@
6.4 #include <all_include.h>
6.5 #include <mapstorage.h>
6.6 #include <map_win.h>
6.7 +#include <edit_win.h>
6.8 #include <libgnomecanvasmm.h>
6.9 #include <libgnomecanvasmm/polygon.h>
6.10
6.11 @@ -25,6 +26,9 @@
6.12 ///Window of map-showing setup. Its type is \ref MapWin
6.13 MapWin mapwin;
6.14
6.15 + ///Window of editorial tools. Its type is \ref EditWin
6.16 + EditWin editwin;
6.17 +
6.18 ///The graph will be drawn on this \ref GraphDisplayerCanvas
6.19 GraphDisplayerCanvas gd_canvas;
6.20
6.21 @@ -39,6 +43,8 @@
6.22
6.23 ///This function makes map-setup window popped up.
6.24 virtual void showMaps();
6.25 + ///This function makes editorial window popped up.
6.26 + virtual void showEditorials();
6.27 ///Callback for 'FileNew' action.
6.28 virtual void newFile();
6.29 ///Callback for 'FileOpen' action.