1.1 --- a/gui/graph_displayer_canvas-event.cc Fri Aug 19 12:09:21 2005 +0000
1.2 +++ b/gui/graph_displayer_canvas-event.cc Tue Aug 23 07:36:09 2005 +0000
1.3 @@ -214,13 +214,19 @@
1.4 bool GraphDisplayerCanvas::createNodeEventHandler(GdkEvent* e)
1.5 {
1.6 switch(e->type)
1.7 - {
1.8 + {
1.9 + //move the new node
1.10 + case GDK_MOTION_NOTIFY:
1.11 + {
1.12 + GdkEvent * generated=new GdkEvent();
1.13 + generated->motion.x=e->motion.x;
1.14 + generated->motion.y=e->motion.y;
1.15 + generated->type=GDK_MOTION_NOTIFY;
1.16 + moveEventHandler(generated);
1.17 + break;
1.18 + }
1.19
1.20 - //draw the new node in red at the clicked place
1.21 - case GDK_2BUTTON_PRESS:
1.22 - //std::cout << "double click" << std::endl;
1.23 - break;
1.24 - case GDK_BUTTON_PRESS:
1.25 + case GDK_BUTTON_RELEASE:
1.26 mapstorage.modified = true;
1.27
1.28 isbutton=1;
1.29 @@ -231,183 +237,188 @@
1.30
1.31 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.32
1.33 + // update coordinates
1.34 mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
1.35 +
1.36 + // update id map
1.37 (*mapstorage.nodemap_storage["id"])[active_node] =
1.38 mapstorage.graph.id(active_node);
1.39
1.40 + // update all other maps
1.41 + for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
1.42 + mapstorage.nodemap_storage.begin(); it !=
1.43 + mapstorage.nodemap_storage.end(); ++it)
1.44 + {
1.45 + if ((it->first != "id") &&
1.46 + (it->first != "coordinates_x") &&
1.47 + (it->first != "coordiantes_y"))
1.48 + {
1.49 + (*(it->second))[active_node] =
1.50 + mapstorage.nodemap_default[it->first];
1.51 + }
1.52 + }
1.53 +
1.54 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
1.55 - clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
1.56 + clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
1.57 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
1.58 - *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
1.59 - *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
1.60 + *(nodesmap[active_node]) <<
1.61 + Gnome::Canvas::Properties::fill_color("blue");
1.62 + *(nodesmap[active_node]) <<
1.63 + Gnome::Canvas::Properties::outline_color("black");
1.64 + active_item->raise_to_top();
1.65 +
1.66 (nodesmap[active_node])->show();
1.67
1.68 nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
1.69 - clicked_x+node_property_defaults[N_RADIUS]+5,
1.70 - clicked_y+node_property_defaults[N_RADIUS]+5, "");
1.71 + clicked_x+node_property_defaults[N_RADIUS]+5,
1.72 + clicked_y+node_property_defaults[N_RADIUS]+5, "");
1.73 nodetextmap[active_node]->property_fill_color().set_value("darkblue");
1.74 + nodetextmap[active_node]->raise_to_top();
1.75
1.76 mapwin.updateNode(active_node);
1.77
1.78 - break;
1.79 -
1.80 - //move the new node
1.81 - case GDK_MOTION_NOTIFY:
1.82 - {
1.83 - GdkEvent * generated=new GdkEvent();
1.84 - generated->motion.x=e->motion.x;
1.85 - generated->motion.y=e->motion.y;
1.86 - generated->type=GDK_MOTION_NOTIFY;
1.87 - moveEventHandler(generated);
1.88 - break;
1.89 - }
1.90 -
1.91 - //finalize the new node
1.92 - case GDK_BUTTON_RELEASE:
1.93 - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.94 -
1.95 - active_item->lower_to_bottom();
1.96 -
1.97 - target_item=NULL;
1.98 - target_item=get_item_at(clicked_x, clicked_y);
1.99 -
1.100 - active_item->raise_to_top();
1.101 -
1.102 isbutton=0;
1.103 - if(target_item==active_item)
1.104 - {
1.105 - //Its appropriate color is given by update.
1.106 - *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.107 - }
1.108 - else
1.109 - {
1.110 - //In this case the given color has to be overwritten, because the noe covers an other item.
1.111 - *active_item << Gnome::Canvas::Properties::fill_color("lightblue");
1.112 - }
1.113 target_item=NULL;
1.114 active_item=NULL;
1.115 active_node=INVALID;
1.116 +
1.117 break;
1.118 default:
1.119 break;
1.120 - }
1.121 + }
1.122 return false;
1.123 }
1.124
1.125 bool GraphDisplayerCanvas::createEdgeEventHandler(GdkEvent* e)
1.126 {
1.127 switch(e->type)
1.128 - {
1.129 + {
1.130 case GDK_BUTTON_PRESS:
1.131 //in edge creation right button has special meaning
1.132 if(e->button.button!=3)
1.133 - {
1.134 - //there is not yet selected node
1.135 - if(active_node==INVALID)
1.136 - {
1.137 - //we mark the location of the event to be able to calculate parameters of dragging
1.138 + {
1.139 + //there is not yet selected node
1.140 + if(active_node==INVALID)
1.141 + {
1.142 + //we mark the location of the event to be able to calculate parameters of dragging
1.143
1.144 - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.145 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.146
1.147 - active_item=(get_item_at(clicked_x, clicked_y));
1.148 - active_node=INVALID;
1.149 - for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.150 - {
1.151 - if(nodesmap[i]==active_item)
1.152 - {
1.153 - active_node=i;
1.154 - }
1.155 - }
1.156 - //the clicked item is really a node
1.157 - if(active_node!=INVALID)
1.158 - {
1.159 - *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
1.160 - isbutton=1;
1.161 - }
1.162 - //clicked item was not a node. It could be e.g. edge.
1.163 - else
1.164 - {
1.165 - active_item=NULL;
1.166 - }
1.167 - }
1.168 - //we only have to do sg. if the mouse button
1.169 - // is pressed already once AND the click was
1.170 - // on a node that was found in the set of
1.171 - //nodes, and now we only search for the second
1.172 - //node
1.173 - else
1.174 - {
1.175 - window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.176 - target_item=(get_item_at(clicked_x, clicked_y));
1.177 - Node target_node=INVALID;
1.178 - for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.179 - {
1.180 - if(nodesmap[i]==target_item)
1.181 - {
1.182 - target_node=i;
1.183 - }
1.184 - }
1.185 - //the clicked item is a node, the edge can be drawn
1.186 - if(target_node!=INVALID)
1.187 - {
1.188 - if(target_node!=active_node)
1.189 - {
1.190 - mapstorage.modified = true;
1.191 + active_item=(get_item_at(clicked_x, clicked_y));
1.192 + active_node=INVALID;
1.193 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.194 + {
1.195 + if(nodesmap[i]==active_item)
1.196 + {
1.197 + active_node=i;
1.198 + }
1.199 + }
1.200 + //the clicked item is really a node
1.201 + if(active_node!=INVALID)
1.202 + {
1.203 + *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
1.204 + isbutton=1;
1.205 + }
1.206 + //clicked item was not a node. It could be e.g. edge.
1.207 + else
1.208 + {
1.209 + active_item=NULL;
1.210 + }
1.211 + }
1.212 + //we only have to do sg. if the mouse button
1.213 + // is pressed already once AND the click was
1.214 + // on a node that was found in the set of
1.215 + //nodes, and now we only search for the second
1.216 + //node
1.217 + else
1.218 + {
1.219 + window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
1.220 + target_item=(get_item_at(clicked_x, clicked_y));
1.221 + Node target_node=INVALID;
1.222 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
1.223 + {
1.224 + if(nodesmap[i]==target_item)
1.225 + {
1.226 + target_node=i;
1.227 + }
1.228 + }
1.229 + //the clicked item is a node, the edge can be drawn
1.230 + if(target_node!=INVALID)
1.231 + {
1.232 + if(target_node!=active_node)
1.233 + {
1.234 + mapstorage.modified = true;
1.235
1.236 - *(nodesmap[target_node]) <<
1.237 - Gnome::Canvas::Properties::fill_color("red");
1.238 + *(nodesmap[target_node]) <<
1.239 + Gnome::Canvas::Properties::fill_color("red");
1.240
1.241 - //creating new edge
1.242 - active_edge=mapstorage.graph.addEdge(active_node,
1.243 - target_node);
1.244 + //creating new edge
1.245 + active_edge=mapstorage.graph.addEdge(active_node,
1.246 + target_node);
1.247
1.248 - //initiating values corresponding to new edge in maps
1.249 - mapstorage.initMapsForEdge(active_edge);
1.250 - (*mapstorage.edgemap_storage["id"])[active_edge] =
1.251 - mapstorage.graph.id(active_edge);
1.252 -
1.253 - //calculating coordinates of new edge
1.254 - Gnome::Canvas::Points coos;
1.255 - double x1, x2, y1, y2;
1.256 -
1.257 - active_item->get_bounds(x1, y1, x2, y2);
1.258 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.259 + // update id map
1.260 + (*mapstorage.edgemap_storage["id"])[active_edge] =
1.261 + mapstorage.graph.id(active_edge);
1.262 +
1.263 + // update all other maps
1.264 + for (std::map<std::string,
1.265 + Graph::EdgeMap<double>*>::const_iterator it =
1.266 + mapstorage.edgemap_storage.begin(); it !=
1.267 + mapstorage.edgemap_storage.end(); ++it)
1.268 + {
1.269 + if (it->first != "id")
1.270 + {
1.271 + (*(it->second))[active_edge] =
1.272 + mapstorage.edgemap_default[it->first];
1.273 + }
1.274 + }
1.275
1.276 - target_item->get_bounds(x1, y1, x2, y2);
1.277 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.278 + //calculating coordinates of new edge
1.279 + Gnome::Canvas::Points coos;
1.280 + double x1, x2, y1, y2;
1.281
1.282 - //drawing new edge
1.283 - edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
1.284 - *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
1.285 - edgesmap[active_edge]->property_width_pixels().set_value(10);
1.286 + active_item->get_bounds(x1, y1, x2, y2);
1.287 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.288
1.289 - //redraw nodes to blank terminations of the new edge
1.290 - target_item->raise_to_top();
1.291 - active_item->raise_to_top();
1.292 + target_item->get_bounds(x1, y1, x2, y2);
1.293 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
1.294
1.295 - //initializing edge-text as well, to empty string
1.296 - xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
1.297 - text_pos+=(xy<double>(10,10));
1.298 + //drawing new edge
1.299 + edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos,
1.300 + *this);
1.301 + *(edgesmap[active_edge]) <<
1.302 + Gnome::Canvas::Properties::fill_color("green");
1.303 + edgesmap[active_edge]->property_width_pixels().set_value(10);
1.304
1.305 - edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
1.306 - edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
1.307 + edgesmap[active_edge]->lower_to_bottom();
1.308
1.309 - //updating its properties
1.310 - mapwin.updateEdge(active_edge);
1.311 - }
1.312 - else
1.313 - {
1.314 - target_node=INVALID;
1.315 - std::cerr << "Loop edge is not yet implemented!" << std::endl;
1.316 - }
1.317 - }
1.318 - //clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
1.319 - else
1.320 - {
1.321 - target_item=NULL;
1.322 - }
1.323 - }
1.324 - }
1.325 + //initializing edge-text as well, to empty string
1.326 + xy<double> text_pos=edgesmap[active_edge]->getArrowPos();
1.327 + text_pos+=(xy<double>(10,10));
1.328 +
1.329 + edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph,
1.330 + text_pos.x, text_pos.y, "");
1.331 + edgetextmap[active_edge]->property_fill_color().set_value(
1.332 + "darkgreen");
1.333 + edgetextmap[active_edge]->raise_to_top();
1.334 +
1.335 + //updating its properties
1.336 + mapwin.updateEdge(active_edge);
1.337 + }
1.338 + else
1.339 + {
1.340 + target_node=INVALID;
1.341 + std::cerr << "Loop edge is not yet implemented!" << std::endl;
1.342 + }
1.343 + }
1.344 + //clicked item was not a node. it could be an e.g. edge. we do not
1.345 + //deal with it furthermore.
1.346 + else
1.347 + {
1.348 + target_item=NULL;
1.349 + }
1.350 + }
1.351 + }
1.352 break;
1.353 case GDK_BUTTON_RELEASE:
1.354 isbutton=0;
1.355 @@ -415,24 +426,24 @@
1.356 //1: the edge is ready (target_item has valid value)
1.357 //2: the edge creation is cancelled with right button
1.358 if((target_item)||(e->button.button==3))
1.359 - {
1.360 - if(active_item)
1.361 - {
1.362 - *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.363 - active_item=NULL;
1.364 - }
1.365 - if(target_item)
1.366 - {
1.367 - *target_item << Gnome::Canvas::Properties::fill_color("blue");
1.368 - target_item=NULL;
1.369 - }
1.370 - active_node=INVALID;
1.371 - active_edge=INVALID;
1.372 - }
1.373 + {
1.374 + if(active_item)
1.375 + {
1.376 + *active_item << Gnome::Canvas::Properties::fill_color("blue");
1.377 + active_item=NULL;
1.378 + }
1.379 + if(target_item)
1.380 + {
1.381 + *target_item << Gnome::Canvas::Properties::fill_color("blue");
1.382 + target_item=NULL;
1.383 + }
1.384 + active_node=INVALID;
1.385 + active_edge=INVALID;
1.386 + }
1.387 break;
1.388 default:
1.389 break;
1.390 - }
1.391 + }
1.392 return false;
1.393 }
1.394
1.395 @@ -588,6 +599,8 @@
1.396 //if it was really an edge...
1.397 if(clicked_edge!=INVALID)
1.398 {
1.399 + // the id map is not editable
1.400 + if (nodemap_to_edit == "id") return 0;
1.401 //If there is already edited edge, it has to be saved first
1.402 if(entrywidget.is_visible())
1.403 {
1.404 @@ -711,6 +724,8 @@
1.405 //if it was really an edge...
1.406 if(clicked_node!=INVALID)
1.407 {
1.408 + // the id map is not editable
1.409 + if (nodemap_to_edit == "id") return 0;
1.410 //If there is already edited edge, it has to be saved first
1.411 if(entrywidget.is_visible())
1.412 {
1.413 @@ -913,7 +928,7 @@
1.414
1.415 //if addition was not successful addEdgeMap returns one.
1.416 //cause can be that there is already a map named like the new one
1.417 - if(mapstorage.addEdgeMap(mapname,emptr))
1.418 + if(mapstorage.addEdgeMap(mapname,emptr, default_value))
1.419 {
1.420 return 1;
1.421 }
1.422 @@ -935,7 +950,7 @@
1.423
1.424 //if addition was not successful addNodeMap returns one.
1.425 //cause can be that there is already a map named like the new one
1.426 - if(mapstorage.addNodeMap(mapname,emptr))
1.427 + if(mapstorage.addNodeMap(mapname,emptr, default_value))
1.428 {
1.429 return 1;
1.430 }