1.1 --- a/gui/graph_displayer_canvas-event.cc Thu Jul 28 19:09:39 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas-event.cc Fri Jul 29 12:01:37 2005 +0000
1.3 @@ -1,5 +1,5 @@
1.4 -#include <graph_displayer_canvas.h>
1.5 -#include <broken_edge.h>
1.6 +#include "graph_displayer_canvas.h"
1.7 +#include "broken_edge.h"
1.8 #include <math.h>
1.9
1.10
1.11 @@ -99,7 +99,7 @@
1.12
1.13 active_item=(get_item_at(clicked_x, clicked_y));
1.14 active_node=INVALID;
1.15 - for (NodeIt i(g); i!=INVALID; ++i)
1.16 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.17 {
1.18 if(nodesmap[i]==active_item)
1.19 {
1.20 @@ -125,6 +125,8 @@
1.21 //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.22 if(active_node!=INVALID)
1.23 {
1.24 + mapstorage.modified = true;
1.25 + mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
1.26 //new coordinates will be the old values,
1.27 //because the item will be moved to the
1.28 //new coordinate therefore the new movement
1.29 @@ -147,17 +149,17 @@
1.30 //all the edges connected to the moved point has to be redrawn
1.31 EdgeIt ei;
1.32
1.33 - g.firstOut(ei,active_node);
1.34 + mapstorage.graph.firstOut(ei,active_node);
1.35
1.36 - for(;ei!=INVALID;g.nextOut(ei))
1.37 + for(;ei!=INVALID;mapstorage.graph.nextOut(ei))
1.38 {
1.39 Gnome::Canvas::Points coos;
1.40 double x1, x2, y1, y2;
1.41
1.42 - nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
1.43 + nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
1.44 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.45
1.46 - nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
1.47 + nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
1.48 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.49
1.50 if(isbutton==3)
1.51 @@ -176,16 +178,16 @@
1.52 edgetextmap[ei]->property_y().set_value(text_pos.y);
1.53 }
1.54
1.55 - g.firstIn(ei,active_node);
1.56 - for(;ei!=INVALID;g.nextIn(ei))
1.57 + mapstorage.graph.firstIn(ei,active_node);
1.58 + for(;ei!=INVALID;mapstorage.graph.nextIn(ei))
1.59 {
1.60 Gnome::Canvas::Points coos;
1.61 double x1, x2, y1, y2;
1.62
1.63 - nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
1.64 + nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
1.65 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.66
1.67 - nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
1.68 + nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
1.69 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.70
1.71 if(isbutton==3)
1.72 @@ -219,24 +221,33 @@
1.73 //std::cout << "double click" << std::endl;
1.74 break;
1.75 case GDK_BUTTON_PRESS:
1.76 + mapstorage.modified = true;
1.77 +
1.78 isbutton=1;
1.79
1.80 - active_node=NodeIt(g,g.addNode());
1.81 + active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode());
1.82
1.83 //initiating values corresponding to new node in maps
1.84
1.85 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.86
1.87 - nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
1.88 + mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
1.89 + (*mapstorage.nodemap_storage["id"])[active_node] =
1.90 + mapstorage.graph.id(active_node);
1.91 +
1.92 + nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
1.93 + clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
1.94 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
1.95 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
1.96 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
1.97 (nodesmap[active_node])->show();
1.98
1.99 - 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, "");
1.100 + nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
1.101 + clicked_x+node_property_defaults[N_RADIUS]+5,
1.102 + clicked_y+node_property_defaults[N_RADIUS]+5, "");
1.103 nodetextmap[active_node]->property_fill_color().set_value("darkblue");
1.104
1.105 - mapwin->updateNode(active_node);
1.106 + mapwin.updateNode(active_node);
1.107
1.108 break;
1.109
1.110 @@ -300,7 +311,7 @@
1.111
1.112 active_item=(get_item_at(clicked_x, clicked_y));
1.113 active_node=INVALID;
1.114 - for (NodeIt i(g); i!=INVALID; ++i)
1.115 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.116 {
1.117 if(nodesmap[i]==active_item)
1.118 {
1.119 @@ -329,7 +340,7 @@
1.120 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.121 target_item=(get_item_at(clicked_x, clicked_y));
1.122 Graph::NodeIt target_node=INVALID;
1.123 - for (NodeIt i(g); i!=INVALID; ++i)
1.124 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.125 {
1.126 if(nodesmap[i]==target_item)
1.127 {
1.128 @@ -341,13 +352,16 @@
1.129 {
1.130 if(target_node!=active_node)
1.131 {
1.132 + mapstorage.modified = true;
1.133 +
1.134 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
1.135
1.136 //creating new edge
1.137 - active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
1.138 + active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node));
1.139
1.140 //initiating values corresponding to new edge in maps
1.141 mapstorage.initMapsForEdge(active_edge);
1.142 + (*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge);
1.143
1.144 //calculating coordinates of new edge
1.145 Gnome::Canvas::Points coos;
1.146 @@ -376,7 +390,7 @@
1.147 edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
1.148
1.149 //updating its properties
1.150 - mapwin->updateEdge(active_edge);
1.151 + mapwin.updateEdge(active_edge);
1.152 }
1.153 else
1.154 {
1.155 @@ -429,9 +443,8 @@
1.156 active_item=(get_item_at(clicked_x, clicked_y));
1.157 active_node=INVALID;
1.158 active_edge=INVALID;
1.159 -
1.160 //was it a node?
1.161 - for (NodeIt i(g); i!=INVALID; ++i)
1.162 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.163 {
1.164 if(nodesmap[i]==active_item)
1.165 {
1.166 @@ -441,7 +454,7 @@
1.167 //or was it an edge?
1.168 if(active_node==INVALID)
1.169 {
1.170 - for (EdgeIt i(g); i!=INVALID; ++i)
1.171 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
1.172 {
1.173 if(edgesmap[i]==active_item)
1.174 {
1.175 @@ -467,19 +480,20 @@
1.176 //a node was found
1.177 if(active_node!=INVALID)
1.178 {
1.179 + mapstorage.modified = true;
1.180
1.181 //collecting edges to delete
1.182 EdgeIt e;
1.183 std::set<Graph::Edge> edges_to_delete;
1.184
1.185 - g.firstOut(e,active_node);
1.186 - for(;e!=INVALID;g.nextOut(e))
1.187 + mapstorage.graph.firstOut(e,active_node);
1.188 + for(;e!=INVALID;mapstorage.graph.nextOut(e))
1.189 {
1.190 edges_to_delete.insert(e);
1.191 }
1.192
1.193 - g.firstIn(e,active_node);
1.194 - for(;e!=INVALID;g.nextIn(e))
1.195 + mapstorage.graph.firstIn(e,active_node);
1.196 + for(;e!=INVALID;mapstorage.graph.nextIn(e))
1.197 {
1.198 edges_to_delete.insert(e);
1.199 }
1.200 @@ -545,7 +559,7 @@
1.201
1.202 //find the activated item between texts
1.203 active_item=(get_item_at(e->button.x, e->button.y));
1.204 - for (EdgeIt i(g); i!=INVALID; ++i)
1.205 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
1.206 {
1.207 if(edgetextmap[i]==active_item)
1.208 {
1.209 @@ -559,7 +573,7 @@
1.210 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.211 active_item=(get_item_at(clicked_x, clicked_y));
1.212
1.213 - for (EdgeIt i(g); i!=INVALID; ++i)
1.214 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
1.215 {
1.216 //at the same time only one can be active
1.217 if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
1.218 @@ -663,7 +677,7 @@
1.219
1.220 //find the activated item between texts
1.221 active_item=(get_item_at(e->button.x, e->button.y));
1.222 - for (NodeIt i(g); i!=INVALID; ++i)
1.223 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.224 {
1.225 //at the same time only one can be active
1.226 if(nodetextmap[i]==active_item)
1.227 @@ -678,7 +692,7 @@
1.228 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.229 active_item=(get_item_at(clicked_x, clicked_y));
1.230
1.231 - for (NodeIt i(g); i!=INVALID; ++i)
1.232 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.233 {
1.234 //at the same time only one can be active
1.235 if(nodesmap[i]==active_item)
1.236 @@ -803,12 +817,12 @@
1.237 case EDGE_MAP_EDIT:
1.238 edgetextmap[active_edge]->property_text().set_value(ostr.str());
1.239 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
1.240 - mapwin->updateEdge(active_edge);
1.241 + mapwin.updateEdge(active_edge);
1.242 break;
1.243 case NODE_MAP_EDIT:
1.244 nodetextmap[active_node]->property_text().set_value(ostr.str());
1.245 (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
1.246 - mapwin->updateNode(active_node);
1.247 + mapwin.updateNode(active_node);
1.248 break;
1.249 default:
1.250 break;
1.251 @@ -835,21 +849,21 @@
1.252 {
1.253 delete(nodetextmap[node_to_delete]);
1.254 delete(nodesmap[node_to_delete]);
1.255 - g.erase(node_to_delete);
1.256 + mapstorage.graph.erase(node_to_delete);
1.257 }
1.258
1.259 void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
1.260 {
1.261 delete(edgetextmap[edge_to_delete]);
1.262 delete(edgesmap[edge_to_delete]);
1.263 - g.erase(edge_to_delete);
1.264 + mapstorage.graph.erase(edge_to_delete);
1.265 }
1.266
1.267 void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
1.268 {
1.269 delete(edgetextmap[edge_to_delete]);
1.270 delete(edgesmap[edge_to_delete]);
1.271 - g.erase(edge_to_delete);
1.272 + mapstorage.graph.erase(edge_to_delete);
1.273 }
1.274
1.275 void GraphDisplayerCanvas::textReposition(xy<double> new_place)
1.276 @@ -869,7 +883,7 @@
1.277 }
1.278 else
1.279 {
1.280 - for (EdgeIt i(g); i!=INVALID; ++i)
1.281 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
1.282 {
1.283 if(edgesmap[i]==active_bre)
1.284 {
1.285 @@ -895,7 +909,7 @@
1.286 int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
1.287 {
1.288 //create the new map
1.289 - Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
1.290 + Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
1.291
1.292 //if addition was not successful addEdgeMap returns one.
1.293 //cause can be that there is already a map named like the new one
1.294 @@ -906,7 +920,7 @@
1.295
1.296
1.297 //add it to the list of the displayable maps
1.298 - mapwin->registerNewEdgeMap(mapname);
1.299 + mapwin.registerNewEdgeMap(mapname);
1.300
1.301 //display it
1.302 changeEdgeText(mapname);
1.303 @@ -917,7 +931,7 @@
1.304 int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
1.305 {
1.306 //create the new map
1.307 - Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
1.308 + Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
1.309
1.310 //if addition was not successful addNodeMap returns one.
1.311 //cause can be that there is already a map named like the new one
1.312 @@ -927,7 +941,7 @@
1.313 }
1.314
1.315 //add it to the list of the displayable maps
1.316 - mapwin->registerNewNodeMap(mapname);
1.317 + mapwin.registerNewNodeMap(mapname);
1.318
1.319 //display it
1.320 changeNodeText(mapname);