1.1 --- a/gui/graph_displayer_canvas.cc Thu Jun 09 21:49:48 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas.cc Fri Jun 10 11:58:03 2005 +0000
1.3 @@ -3,6 +3,12 @@
1.4
1.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)
1.6 {
1.7 + Gnome::Canvas::Ellipse * origo=new Gnome::Canvas::Ellipse(displayed_graph, 0-20, 0-20, 0+20, 0+20);
1.8 + *origo << Gnome::Canvas::Properties::fill_color("black");
1.9 + *origo << Gnome::Canvas::Properties::outline_color("black");
1.10 +
1.11 + actual_handler=/*displayed_graph.*/signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
1.12 +
1.13 //set_center_scroll_region(true);
1.14
1.15 //first edges are drawn, to hide joining with nodes later
1.16 @@ -48,20 +54,9 @@
1.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);
1.18 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
1.19 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
1.20 - (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
1.21 + //!!!!!!! (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
1.22 }
1.23
1.24 -/*
1.25 - //setting zoom to be able to see the whole graph on the canvas
1.26 -
1.27 - double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
1.28 - double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
1.29 -
1.30 - set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
1.31 - std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
1.32 - std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
1.33 - std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
1.34 -*/
1.35 updateScrollRegion();
1.36 }
1.37
1.38 @@ -308,3 +303,162 @@
1.39 pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
1.40 set_scroll_region(wx1, wy1, wx2, wy2);
1.41 }
1.42 +
1.43 +void GraphDisplayerCanvas::changeEditorialTool(int newtool)
1.44 +{
1.45 + actual_handler.disconnect();
1.46 +
1.47 + switch(newtool)
1.48 + {
1.49 + case MOVE:
1.50 + actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::move_event_handler), false);
1.51 + break;
1.52 + case CREATE_NODE:
1.53 + actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
1.54 + break;
1.55 + case CREATE_EDGE:
1.56 + actual_handler=displayed_graph.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_edge_event_handler), false);
1.57 + break;
1.58 + default:
1.59 + break;
1.60 + }
1.61 +}
1.62 +
1.63 +bool GraphDisplayerCanvas::move_event_handler(GdkEvent* e)
1.64 +{
1.65 + switch(e->type)
1.66 + {
1.67 + case GDK_BUTTON_PRESS:
1.68 + //we mark the location of the event to be able to calculate parameters of dragging
1.69 + clicked_x=e->button.x;
1.70 + clicked_y=e->button.y;
1.71 + active_item=(get_item_at(e->button.x, e->button.y));
1.72 + active_node=INVALID;
1.73 + for (NodeIt i(g); i!=INVALID; ++i)
1.74 + {
1.75 + if(nodesmap[i]==active_item)
1.76 + {
1.77 + active_node=i;
1.78 + }
1.79 + }
1.80 + isbutton=true;
1.81 + break;
1.82 + case GDK_BUTTON_RELEASE:
1.83 + isbutton=false;
1.84 + active_item=NULL;
1.85 + updateScrollRegion();
1.86 + break;
1.87 + case GDK_MOTION_NOTIFY:
1.88 + //we only have to do sg. if the mouse button is pressed
1.89 + if(isbutton)
1.90 + {
1.91 + //new coordinates will be the old values,
1.92 + //because the item will be moved to the
1.93 + //new coordinate therefore the new movement
1.94 + //has to be calculated from here
1.95 +
1.96 + double dx=e->motion.x-clicked_x;
1.97 + double dy=e->motion.y-clicked_y;
1.98 +
1.99 + active_item->move(dx, dy);
1.100 +
1.101 + clicked_x=e->motion.x;
1.102 + clicked_y=e->motion.y;
1.103 +
1.104 + //all the edges connected to the moved point has to be redrawn
1.105 +
1.106 + EdgeIt e;
1.107 +
1.108 + g.firstOut(e,active_node);
1.109 +
1.110 + for(;e!=INVALID;g.nextOut(e))
1.111 + {
1.112 + Gnome::Canvas::Points coos;
1.113 + double x1, x2, y1, y2;
1.114 +
1.115 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
1.116 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.117 +
1.118 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
1.119 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.120 +
1.121 + edgesmap[e]->property_points().set_value(coos);
1.122 +
1.123 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
1.124 +
1.125 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
1.126 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
1.127 + }
1.128 +
1.129 + g.firstIn(e,active_node);
1.130 + for(;e!=INVALID;g.nextIn(e))
1.131 + {
1.132 + Gnome::Canvas::Points coos;
1.133 + double x1, x2, y1, y2;
1.134 +
1.135 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
1.136 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.137 +
1.138 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
1.139 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.140 +
1.141 + edgesmap[e]->property_points().set_value(coos);
1.142 +
1.143 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
1.144 +
1.145 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
1.146 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
1.147 + }
1.148 + }
1.149 + default: break;
1.150 + }
1.151 +
1.152 + return true;
1.153 +}
1.154 +
1.155 +bool GraphDisplayerCanvas::create_node_event_handler(GdkEvent* e)
1.156 +{
1.157 + switch(e->type)
1.158 + {
1.159 + case GDK_BUTTON_PRESS:
1.160 + isbutton=true;
1.161 +
1.162 + active_node=NodeIt(g,g.addNode());
1.163 +
1.164 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.165 +
1.166 + nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
1.167 + active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
1.168 + *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
1.169 + *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
1.170 + (nodesmap[active_node])->show();
1.171 + break;
1.172 + case GDK_MOTION_NOTIFY:
1.173 + {
1.174 + double world_motion_x, world_motion_y;
1.175 + GdkEvent * generated=new GdkEvent();
1.176 + window_to_world (e->motion.x, e->motion.y, world_motion_x, world_motion_y);
1.177 + generated->motion.x=world_motion_x;
1.178 + generated->motion.y=world_motion_y;
1.179 + generated->type=GDK_MOTION_NOTIFY;
1.180 + move_event_handler(generated);
1.181 + break;
1.182 + }
1.183 + case GDK_BUTTON_RELEASE:
1.184 + isbutton=false;
1.185 + *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.186 + active_item=NULL;
1.187 + updateScrollRegion();
1.188 + break;
1.189 + default:
1.190 + break;
1.191 + }
1.192 + return false;
1.193 +}
1.194 +
1.195 +bool GraphDisplayerCanvas::create_edge_event_handler(GdkEvent* e)
1.196 +{
1.197 + e=e;
1.198 + return false;
1.199 +}
1.200 +