1.1 --- a/graph_displayer_canvas-event.cc Mon Oct 09 08:06:31 2006 +0000
1.2 +++ b/graph_displayer_canvas-event.cc Thu Oct 12 11:39:29 2006 +0000
1.3 @@ -81,11 +81,11 @@
1.4 {
1.5 static Gnome::Canvas::Text *coord_text = 0;
1.6 switch(e->type)
1.7 - {
1.8 + {
1.9 case GDK_BUTTON_PRESS:
1.10 //we mark the location of the event to be able to calculate parameters of dragging
1.11 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.12 -
1.13 +
1.14 active_item=(get_item_at(clicked_x, clicked_y));
1.15 active_node=INVALID;
1.16 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
1.17 @@ -99,10 +99,10 @@
1.18 break;
1.19 case GDK_BUTTON_RELEASE:
1.20 if (coord_text)
1.21 - {
1.22 - delete coord_text;
1.23 - coord_text = 0;
1.24 - }
1.25 + {
1.26 + delete coord_text;
1.27 + coord_text = 0;
1.28 + }
1.29 isbutton=0;
1.30 active_item=NULL;
1.31 active_node=INVALID;
1.32 @@ -110,122 +110,59 @@
1.33 case GDK_MOTION_NOTIFY:
1.34 //we only have to do sg. if the mouse button is pressed AND the click was on a node that was found in the set of nodes
1.35 if(active_node!=INVALID)
1.36 - {
1.37 - (mytab.mapstorage).modified = true;
1.38 + {
1.39 + (mytab.mapstorage).modified = true;
1.40 +
1.41 + //new coordinates will be the old values,
1.42 + //because the item will be moved to the
1.43 + //new coordinate therefore the new movement
1.44 + //has to be calculated from here
1.45 +
1.46 + double new_x, new_y;
1.47 +
1.48 + window_to_world (e->motion.x, e->motion.y, new_x, new_y);
1.49 +
1.50 + double dx=new_x-clicked_x;
1.51 + double dy=new_y-clicked_y;
1.52 +
1.53 + moveNode(dx, dy);
1.54
1.55 - //new coordinates will be the old values,
1.56 - //because the item will be moved to the
1.57 - //new coordinate therefore the new movement
1.58 - //has to be calculated from here
1.59 + clicked_x=new_x;
1.60 + clicked_y=new_y;
1.61
1.62 - double new_x, new_y;
1.63 + // reposition the coordinates text
1.64 + std::ostringstream ostr;
1.65 + ostr << "(" <<
1.66 + (mytab.mapstorage).coords[active_node].x << ", " <<
1.67 + (mytab.mapstorage).coords[active_node].y << ")";
1.68 + double radius =
1.69 + (nodesmap[active_node]->property_x2().get_value() -
1.70 + nodesmap[active_node]->property_x1().get_value()) / 2.0;
1.71 + if (coord_text)
1.72 + {
1.73 + coord_text->property_text().set_value(ostr.str());
1.74 + coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x +
1.75 + radius);
1.76 + coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y -
1.77 + radius);
1.78 + }
1.79 + else
1.80 + {
1.81 + coord_text = new Gnome::Canvas::Text(
1.82 + displayed_graph,
1.83 + (mytab.mapstorage).coords[active_node].x + radius,
1.84 + (mytab.mapstorage).coords[active_node].y - radius,
1.85 + ostr.str());
1.86 + coord_text->property_fill_color().set_value("black");
1.87 + coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
1.88 + }
1.89
1.90 - window_to_world (e->motion.x, e->motion.y, new_x, new_y);
1.91
1.92 - double dx=new_x-clicked_x;
1.93 - double dy=new_y-clicked_y;
1.94 + }
1.95 + default: break;
1.96 + }
1.97
1.98 - //repositioning node and its text
1.99 - active_item->move(dx, dy);
1.100 - nodetextmap[active_node]->move(dx, dy);
1.101 -
1.102 - // the new coordinates of the centre of the node
1.103 - double coord_x = new_x - (clicked_x - (mytab.mapstorage).coords[active_node].x);
1.104 - double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y);
1.105 -
1.106 - // write back the new coordinates to the coords map
1.107 - (mytab.mapstorage).coords.set(active_node, XY(coord_x, coord_y));
1.108 -
1.109 - clicked_x=new_x;
1.110 - clicked_y=new_y;
1.111 -
1.112 - // reposition the coordinates text
1.113 - std::ostringstream ostr;
1.114 - ostr << "(" <<
1.115 - (mytab.mapstorage).coords[active_node].x << ", " <<
1.116 - (mytab.mapstorage).coords[active_node].y << ")";
1.117 - double radius =
1.118 - (nodesmap[active_node]->property_x2().get_value() -
1.119 - nodesmap[active_node]->property_x1().get_value()) / 2.0;
1.120 - if (coord_text)
1.121 - {
1.122 - coord_text->property_text().set_value(ostr.str());
1.123 - coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x +
1.124 - radius);
1.125 - coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y -
1.126 - radius);
1.127 - }
1.128 - else
1.129 - {
1.130 - coord_text = new Gnome::Canvas::Text(
1.131 - displayed_graph,
1.132 - (mytab.mapstorage).coords[active_node].x + radius,
1.133 - (mytab.mapstorage).coords[active_node].y - radius,
1.134 - ostr.str());
1.135 - coord_text->property_fill_color().set_value("black");
1.136 - coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST);
1.137 - }
1.138 -
1.139 - //all the edges connected to the moved point has to be redrawn
1.140 - for(OutEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
1.141 - {
1.142 - XY arrow_pos;
1.143 -
1.144 - if (mytab.mapstorage.graph.source(ei) == mytab.mapstorage.graph.target(ei))
1.145 - {
1.146 - arrow_pos = mytab.mapstorage.arrow_pos[ei] + XY(dx, dy);
1.147 - }
1.148 - else
1.149 - {
1.150 - XY moved_node_1(coord_x - dx, coord_y - dy);
1.151 - XY moved_node_2(coord_x, coord_y);
1.152 - Node target = mytab.mapstorage.graph.target(ei);
1.153 - XY fix_node(mytab.mapstorage.coords[target].x,
1.154 - mytab.mapstorage.coords[target].y);
1.155 - XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
1.156 -
1.157 - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
1.158 - }
1.159 -
1.160 - mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
1.161 - edgesmap[ei]->draw();
1.162 -
1.163 - //reposition of edgetext
1.164 - XY text_pos=mytab.mapstorage.arrow_pos[ei];
1.165 - text_pos+=(XY(10,10));
1.166 - edgetextmap[ei]->property_x().set_value(text_pos.x);
1.167 - edgetextmap[ei]->property_y().set_value(text_pos.y);
1.168 - }
1.169 -
1.170 - for(InEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei)
1.171 - {
1.172 - if (mytab.mapstorage.graph.source(ei) != mytab.mapstorage.graph.target(ei))
1.173 - {
1.174 - XY moved_node_1(coord_x - dx, coord_y - dy);
1.175 - XY moved_node_2(coord_x, coord_y);
1.176 - Node source = mytab.mapstorage.graph.source(ei);
1.177 - XY fix_node(mytab.mapstorage.coords[source].x,
1.178 - mytab.mapstorage.coords[source].y);
1.179 - XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
1.180 -
1.181 - XY arrow_pos;
1.182 - arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
1.183 -
1.184 - mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
1.185 - edgesmap[ei]->draw();
1.186 -
1.187 - //reposition of edgetext
1.188 - XY text_pos=mytab.mapstorage.arrow_pos[ei];
1.189 - text_pos+=(XY(10,10));
1.190 - edgetextmap[ei]->property_x().set_value(text_pos.x);
1.191 - edgetextmap[ei]->property_y().set_value(text_pos.y);
1.192 - }
1.193 - }
1.194 - }
1.195 - default: break;
1.196 - }
1.197 -
1.198 - return false;
1.199 +return false;
1.200 }
1.201
1.202 XY GraphDisplayerCanvas::calcArrowPos(XY moved_node_1, XY moved_node_2, XY fix_node, XY old_arrow_pos, int move_code)
1.203 @@ -823,14 +760,97 @@
1.204 }
1.205 }
1.206 else
1.207 - {
1.208 - if(forming_edge!=INVALID)
1.209 {
1.210 - forming_edge=INVALID;
1.211 + if(forming_edge!=INVALID)
1.212 + {
1.213 + forming_edge=INVALID;
1.214 + }
1.215 + else
1.216 + {
1.217 + std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
1.218 + }
1.219 }
1.220 - else
1.221 +}
1.222 +
1.223 +void GraphDisplayerCanvas::moveNode(double dx, double dy, Gnome::Canvas::Item * item, Node node)
1.224 +{
1.225 + Gnome::Canvas::Item * moved_item=item;
1.226 + Node moved_node=node;
1.227 +
1.228 + if(item==NULL && node==INVALID)
1.229 {
1.230 - std::cerr << "ERROR!!!! Invalid edge found!" << std::endl;
1.231 + moved_item=active_item;
1.232 + moved_node=active_node;
1.233 }
1.234 - }
1.235 + else
1.236 + {
1.237 + isbutton=1;
1.238 + }
1.239 +
1.240 + //repositioning node and its text
1.241 + moved_item->move(dx, dy);
1.242 + nodetextmap[moved_node]->move(dx, dy);
1.243 +
1.244 + // the new coordinates of the centre of the node
1.245 + double coord_x = dx + (mytab.mapstorage).coords[moved_node].x;
1.246 + double coord_y = dy + (mytab.mapstorage).coords[moved_node].y;
1.247 +
1.248 + // write back the new coordinates to the coords map
1.249 + (mytab.mapstorage).coords.set(moved_node, XY(coord_x, coord_y));
1.250 +
1.251 + //all the edges connected to the moved point has to be redrawn
1.252 + for(OutEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei)
1.253 + {
1.254 + XY arrow_pos;
1.255 +
1.256 + if (mytab.mapstorage.graph.source(ei) == mytab.mapstorage.graph.target(ei))
1.257 + {
1.258 + arrow_pos = mytab.mapstorage.arrow_pos[ei] + XY(dx, dy);
1.259 + }
1.260 + else
1.261 + {
1.262 + XY moved_node_1(coord_x - dx, coord_y - dy);
1.263 + XY moved_node_2(coord_x, coord_y);
1.264 + Node target = mytab.mapstorage.graph.target(ei);
1.265 + XY fix_node(mytab.mapstorage.coords[target].x,
1.266 + mytab.mapstorage.coords[target].y);
1.267 + XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
1.268 +
1.269 + arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
1.270 + }
1.271 +
1.272 + mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
1.273 + edgesmap[ei]->draw();
1.274 +
1.275 + //reposition of edgetext
1.276 + XY text_pos=mytab.mapstorage.arrow_pos[ei];
1.277 + text_pos+=(XY(10,10));
1.278 + edgetextmap[ei]->property_x().set_value(text_pos.x);
1.279 + edgetextmap[ei]->property_y().set_value(text_pos.y);
1.280 + }
1.281 +
1.282 + for(InEdgeIt ei((mytab.mapstorage).graph,moved_node);ei!=INVALID;++ei)
1.283 + {
1.284 + if (mytab.mapstorage.graph.source(ei) != mytab.mapstorage.graph.target(ei))
1.285 + {
1.286 + XY moved_node_1(coord_x - dx, coord_y - dy);
1.287 + XY moved_node_2(coord_x, coord_y);
1.288 + Node source = mytab.mapstorage.graph.source(ei);
1.289 + XY fix_node(mytab.mapstorage.coords[source].x,
1.290 + mytab.mapstorage.coords[source].y);
1.291 + XY old_arrow_pos(mytab.mapstorage.arrow_pos[ei]);
1.292 +
1.293 + XY arrow_pos;
1.294 + arrow_pos = calcArrowPos(moved_node_1, moved_node_2, fix_node, old_arrow_pos, isbutton);
1.295 +
1.296 + mytab.mapstorage.arrow_pos.set(ei, arrow_pos);
1.297 + edgesmap[ei]->draw();
1.298 +
1.299 + //reposition of edgetext
1.300 + XY text_pos=mytab.mapstorage.arrow_pos[ei];
1.301 + text_pos+=(XY(10,10));
1.302 + edgetextmap[ei]->property_x().set_value(text_pos.x);
1.303 + edgetextmap[ei]->property_y().set_value(text_pos.y);
1.304 + }
1.305 + }
1.306 }