123 break; |
123 break; |
124 case GDK_MOTION_NOTIFY: |
124 case GDK_MOTION_NOTIFY: |
125 //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 |
125 //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 |
126 if(active_node!=INVALID) |
126 if(active_node!=INVALID) |
127 { |
127 { |
128 (mainwin.mapstorage).modified = true; |
128 (mytab.mapstorage).modified = true; |
129 |
129 |
130 //new coordinates will be the old values, |
130 //new coordinates will be the old values, |
131 //because the item will be moved to the |
131 //because the item will be moved to the |
132 //new coordinate therefore the new movement |
132 //new coordinate therefore the new movement |
133 //has to be calculated from here |
133 //has to be calculated from here |
142 //repositioning node and its text |
142 //repositioning node and its text |
143 active_item->move(dx, dy); |
143 active_item->move(dx, dy); |
144 nodetextmap[active_node]->move(dx, dy); |
144 nodetextmap[active_node]->move(dx, dy); |
145 |
145 |
146 // the new coordinates of the centre of the node |
146 // the new coordinates of the centre of the node |
147 double coord_x = new_x - (clicked_x - (mainwin.mapstorage).coords[active_node].x); |
147 double coord_x = new_x - (clicked_x - (mytab.mapstorage).coords[active_node].x); |
148 double coord_y = new_y - (clicked_y - (mainwin.mapstorage).coords[active_node].y); |
148 double coord_y = new_y - (clicked_y - (mytab.mapstorage).coords[active_node].y); |
149 |
149 |
150 clicked_x=new_x; |
150 clicked_x=new_x; |
151 clicked_y=new_y; |
151 clicked_y=new_y; |
152 |
152 |
153 // write back the new coordinates to the coords map |
153 // write back the new coordinates to the coords map |
154 (mainwin.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y)); |
154 (mytab.mapstorage).coords.set(active_node, xy<double>(coord_x, coord_y)); |
155 |
155 |
156 // reposition the coordinates text |
156 // reposition the coordinates text |
157 std::ostringstream ostr; |
157 std::ostringstream ostr; |
158 ostr << "(" << |
158 ostr << "(" << |
159 (mainwin.mapstorage).coords[active_node].x << ", " << |
159 (mytab.mapstorage).coords[active_node].x << ", " << |
160 (mainwin.mapstorage).coords[active_node].y << ")"; |
160 (mytab.mapstorage).coords[active_node].y << ")"; |
161 double radius = |
161 double radius = |
162 (nodesmap[active_node]->property_x2().get_value() - |
162 (nodesmap[active_node]->property_x2().get_value() - |
163 nodesmap[active_node]->property_x1().get_value()) / 2.0; |
163 nodesmap[active_node]->property_x1().get_value()) / 2.0; |
164 if (coord_text) |
164 if (coord_text) |
165 { |
165 { |
166 coord_text->property_text().set_value(ostr.str()); |
166 coord_text->property_text().set_value(ostr.str()); |
167 coord_text->property_x().set_value((mainwin.mapstorage).coords[active_node].x + |
167 coord_text->property_x().set_value((mytab.mapstorage).coords[active_node].x + |
168 radius); |
168 radius); |
169 coord_text->property_y().set_value((mainwin.mapstorage).coords[active_node].y - |
169 coord_text->property_y().set_value((mytab.mapstorage).coords[active_node].y - |
170 radius); |
170 radius); |
171 } |
171 } |
172 else |
172 else |
173 { |
173 { |
174 coord_text = new Gnome::Canvas::Text( |
174 coord_text = new Gnome::Canvas::Text( |
175 displayed_graph, |
175 displayed_graph, |
176 (mainwin.mapstorage).coords[active_node].x + radius, |
176 (mytab.mapstorage).coords[active_node].x + radius, |
177 (mainwin.mapstorage).coords[active_node].y - radius, |
177 (mytab.mapstorage).coords[active_node].y - radius, |
178 ostr.str()); |
178 ostr.str()); |
179 coord_text->property_fill_color().set_value("black"); |
179 coord_text->property_fill_color().set_value("black"); |
180 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); |
180 coord_text->property_anchor().set_value(Gtk::ANCHOR_SOUTH_WEST); |
181 } |
181 } |
182 |
182 |
183 //all the edges connected to the moved point has to be redrawn |
183 //all the edges connected to the moved point has to be redrawn |
184 for(OutEdgeIt ei((mainwin.mapstorage).graph,active_node);ei!=INVALID;++ei) |
184 for(OutEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei) |
185 { |
185 { |
186 Gnome::Canvas::Points coos; |
186 Gnome::Canvas::Points coos; |
187 double x1, x2, y1, y2; |
187 double x1, x2, y1, y2; |
188 |
188 |
189 nodesmap[(mainwin.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2); |
189 nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2); |
190 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
190 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
191 |
191 |
192 nodesmap[(mainwin.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2); |
192 nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2); |
193 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
193 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
194 |
194 |
195 if(isbutton==3) |
195 if(isbutton==3) |
196 { |
196 { |
197 edgesmap[ei]->setPoints(coos); |
197 edgesmap[ei]->setPoints(coos); |
206 text_pos+=(xy<double>(10,10)); |
206 text_pos+=(xy<double>(10,10)); |
207 edgetextmap[ei]->property_x().set_value(text_pos.x); |
207 edgetextmap[ei]->property_x().set_value(text_pos.x); |
208 edgetextmap[ei]->property_y().set_value(text_pos.y); |
208 edgetextmap[ei]->property_y().set_value(text_pos.y); |
209 } |
209 } |
210 |
210 |
211 for(InEdgeIt ei((mainwin.mapstorage).graph,active_node);ei!=INVALID;++ei) |
211 for(InEdgeIt ei((mytab.mapstorage).graph,active_node);ei!=INVALID;++ei) |
212 { |
212 { |
213 Gnome::Canvas::Points coos; |
213 Gnome::Canvas::Points coos; |
214 double x1, x2, y1, y2; |
214 double x1, x2, y1, y2; |
215 |
215 |
216 nodesmap[(mainwin.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2); |
216 nodesmap[(mytab.mapstorage).graph.source(ei)]->get_bounds(x1, y1, x2, y2); |
217 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
217 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
218 |
218 |
219 nodesmap[(mainwin.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2); |
219 nodesmap[(mytab.mapstorage).graph.target(ei)]->get_bounds(x1, y1, x2, y2); |
220 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
220 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); |
221 |
221 |
222 if(isbutton==3) |
222 if(isbutton==3) |
223 { |
223 { |
224 edgesmap[ei]->setPoints(coos); |
224 edgesmap[ei]->setPoints(coos); |
254 moveEventHandler(generated); |
254 moveEventHandler(generated); |
255 break; |
255 break; |
256 } |
256 } |
257 |
257 |
258 case GDK_BUTTON_RELEASE: |
258 case GDK_BUTTON_RELEASE: |
259 (mainwin.mapstorage).modified = true; |
259 (mytab.mapstorage).modified = true; |
260 |
260 |
261 isbutton=1; |
261 isbutton=1; |
262 |
262 |
263 active_node=(mainwin.mapstorage).graph.addNode(); |
263 active_node=(mytab.mapstorage).graph.addNode(); |
264 |
264 |
265 //initiating values corresponding to new node in maps |
265 //initiating values corresponding to new node in maps |
266 |
266 |
267 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
267 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
268 |
268 |
269 // update coordinates |
269 // update coordinates |
270 (mainwin.mapstorage).coords.set(active_node, xy<double>(clicked_x, clicked_y)); |
270 (mytab.mapstorage).coords.set(active_node, xy<double>(clicked_x, clicked_y)); |
271 |
271 |
272 // update all other maps |
272 // update all other maps |
273 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
273 for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it = |
274 (mainwin.mapstorage).nodemap_storage.begin(); it != |
274 (mytab.mapstorage).nodemap_storage.begin(); it != |
275 (mainwin.mapstorage).nodemap_storage.end(); ++it) |
275 (mytab.mapstorage).nodemap_storage.end(); ++it) |
276 { |
276 { |
277 if ((it->first != "coordinates_x") && |
277 if ((it->first != "coordinates_x") && |
278 (it->first != "coordinates_y")) |
278 (it->first != "coordinates_y")) |
279 { |
279 { |
280 (*(it->second))[active_node] = |
280 (*(it->second))[active_node] = |
281 (mainwin.mapstorage).nodemap_default[it->first]; |
281 (mytab.mapstorage).nodemap_default[it->first]; |
282 } |
282 } |
283 } |
283 } |
284 // increment the id map's default value |
284 // increment the id map's default value |
285 (mainwin.mapstorage).nodemap_default["id"] += 1.0; |
285 (mytab.mapstorage).nodemap_default["id"] += 1.0; |
286 |
286 |
287 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, |
287 nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, |
288 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
288 clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20); |
289 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
289 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]); |
290 *(nodesmap[active_node]) << |
290 *(nodesmap[active_node]) << |
371 //the clicked item is a node, the edge can be drawn |
371 //the clicked item is a node, the edge can be drawn |
372 if(target_node!=INVALID) |
372 if(target_node!=INVALID) |
373 { |
373 { |
374 if(target_node!=active_node) |
374 if(target_node!=active_node) |
375 { |
375 { |
376 (mainwin.mapstorage).modified = true; |
376 (mytab.mapstorage).modified = true; |
377 |
377 |
378 *(nodesmap[target_node]) << |
378 *(nodesmap[target_node]) << |
379 Gnome::Canvas::Properties::fill_color("red"); |
379 Gnome::Canvas::Properties::fill_color("red"); |
380 |
380 |
381 //creating new edge |
381 //creating new edge |
382 active_edge=(mainwin.mapstorage).graph.addEdge(active_node, |
382 active_edge=(mytab.mapstorage).graph.addEdge(active_node, |
383 target_node); |
383 target_node); |
384 |
384 |
385 // update maps |
385 // update maps |
386 for (std::map<std::string, |
386 for (std::map<std::string, |
387 Graph::EdgeMap<double>*>::const_iterator it = |
387 Graph::EdgeMap<double>*>::const_iterator it = |
388 (mainwin.mapstorage).edgemap_storage.begin(); it != |
388 (mytab.mapstorage).edgemap_storage.begin(); it != |
389 (mainwin.mapstorage).edgemap_storage.end(); ++it) |
389 (mytab.mapstorage).edgemap_storage.end(); ++it) |
390 { |
390 { |
391 (*(it->second))[active_edge] = |
391 (*(it->second))[active_edge] = |
392 (mainwin.mapstorage).edgemap_default[it->first]; |
392 (mytab.mapstorage).edgemap_default[it->first]; |
393 } |
393 } |
394 // increment the id map's default value |
394 // increment the id map's default value |
395 (mainwin.mapstorage).edgemap_default["id"] += 1.0; |
395 (mytab.mapstorage).edgemap_default["id"] += 1.0; |
396 |
396 |
397 //calculating coordinates of new edge |
397 //calculating coordinates of new edge |
398 Gnome::Canvas::Points coos; |
398 Gnome::Canvas::Points coos; |
399 double x1, x2, y1, y2; |
399 double x1, x2, y1, y2; |
400 |
400 |
478 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
478 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y); |
479 active_item=(get_item_at(clicked_x, clicked_y)); |
479 active_item=(get_item_at(clicked_x, clicked_y)); |
480 active_node=INVALID; |
480 active_node=INVALID; |
481 active_edge=INVALID; |
481 active_edge=INVALID; |
482 //was it a node? |
482 //was it a node? |
483 for (NodeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i) |
483 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
484 { |
484 { |
485 if(nodesmap[i]==active_item) |
485 if(nodesmap[i]==active_item) |
486 { |
486 { |
487 active_node=i; |
487 active_node=i; |
488 } |
488 } |
489 } |
489 } |
490 //or was it an edge? |
490 //or was it an edge? |
491 if(active_node==INVALID) |
491 if(active_node==INVALID) |
492 { |
492 { |
493 for (EdgeIt i((mainwin.mapstorage).graph); i!=INVALID; ++i) |
493 for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) |
494 { |
494 { |
495 if(edgesmap[i]==active_item) |
495 if(edgesmap[i]==active_item) |
496 { |
496 { |
497 active_edge=i; |
497 active_edge=i; |
498 } |
498 } |
514 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) |
514 if( active_item == ( get_item_at (clicked_x, clicked_y) ) ) |
515 { |
515 { |
516 //a node was found |
516 //a node was found |
517 if(active_node!=INVALID) |
517 if(active_node!=INVALID) |
518 { |
518 { |
519 (mainwin.mapstorage).modified = true; |
519 (mytab.mapstorage).modified = true; |
520 |
520 |
521 std::set<Graph::Edge> edges_to_delete; |
521 std::set<Graph::Edge> edges_to_delete; |
522 |
522 |
523 for(OutEdgeIt e((mainwin.mapstorage).graph,active_node);e!=INVALID;++e) |
523 for(OutEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e) |
524 { |
524 { |
525 edges_to_delete.insert(e); |
525 edges_to_delete.insert(e); |
526 } |
526 } |
527 |
527 |
528 for(InEdgeIt e((mainwin.mapstorage).graph,active_node);e!=INVALID;++e) |
528 for(InEdgeIt e((mytab.mapstorage).graph,active_node);e!=INVALID;++e) |
529 { |
529 { |
530 edges_to_delete.insert(e); |
530 edges_to_delete.insert(e); |
531 } |
531 } |
532 |
532 |
533 //deleting collected edges |
533 //deleting collected edges |
622 { |
622 { |
623 //activate the general variable for it |
623 //activate the general variable for it |
624 active_edge=clicked_edge; |
624 active_edge=clicked_edge; |
625 |
625 |
626 //create a dialog |
626 //create a dialog |
627 Gtk::Dialog dialog("Edit value", mainwin, true); |
627 Gtk::Dialog dialog("Edit value", true); |
628 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
628 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
629 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
629 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
630 Gtk::VBox* vbox = dialog.get_vbox(); |
630 Gtk::VBox* vbox = dialog.get_vbox(); |
631 Gtk::SpinButton spin(0.0, 4); |
631 Gtk::SpinButton spin(0.0, 4); |
632 spin.set_increments(1.0, 10.0); |
632 spin.set_increments(1.0, 10.0); |
710 { |
710 { |
711 //activate the general variable for it |
711 //activate the general variable for it |
712 active_node=clicked_node; |
712 active_node=clicked_node; |
713 |
713 |
714 //create a dialog |
714 //create a dialog |
715 Gtk::Dialog dialog("Edit value", mainwin, true); |
715 Gtk::Dialog dialog("Edit value", true); |
716 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
716 dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); |
717 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
717 dialog.add_button(Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT); |
718 Gtk::VBox* vbox = dialog.get_vbox(); |
718 Gtk::VBox* vbox = dialog.get_vbox(); |
719 Gtk::SpinButton spin(0.0, 4); |
719 Gtk::SpinButton spin(0.0, 4); |
720 spin.set_increments(1.0, 10.0); |
720 spin.set_increments(1.0, 10.0); |
752 |
752 |
753 void GraphDisplayerCanvas::deleteItem(Node node_to_delete) |
753 void GraphDisplayerCanvas::deleteItem(Node node_to_delete) |
754 { |
754 { |
755 delete(nodetextmap[node_to_delete]); |
755 delete(nodetextmap[node_to_delete]); |
756 delete(nodesmap[node_to_delete]); |
756 delete(nodesmap[node_to_delete]); |
757 (mainwin.mapstorage).graph.erase(node_to_delete); |
757 (mytab.mapstorage).graph.erase(node_to_delete); |
758 } |
758 } |
759 |
759 |
760 void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete) |
760 void GraphDisplayerCanvas::deleteItem(Edge edge_to_delete) |
761 { |
761 { |
762 delete(edgetextmap[edge_to_delete]); |
762 delete(edgetextmap[edge_to_delete]); |
763 delete(edgesmap[edge_to_delete]); |
763 delete(edgesmap[edge_to_delete]); |
764 (mainwin.mapstorage).graph.erase(edge_to_delete); |
764 (mytab.mapstorage).graph.erase(edge_to_delete); |
765 } |
765 } |
766 |
766 |
767 void GraphDisplayerCanvas::textReposition(xy<double> new_place) |
767 void GraphDisplayerCanvas::textReposition(xy<double> new_place) |
768 { |
768 { |
769 new_place+=(xy<double>(10,10)); |
769 new_place+=(xy<double>(10,10)); |
805 } |
805 } |
806 |
806 |
807 int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) |
807 int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname) |
808 { |
808 { |
809 //create the new map |
809 //create the new map |
810 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ((mainwin.mapstorage).graph, default_value); |
810 Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> ((mytab.mapstorage).graph, default_value); |
811 |
811 |
812 //if addition was not successful addEdgeMap returns one. |
812 //if addition was not successful addEdgeMap returns one. |
813 //cause can be that there is already a map named like the new one |
813 //cause can be that there is already a map named like the new one |
814 if((mainwin.mapstorage).addEdgeMap(mapname,emptr, default_value)) |
814 if((mytab.mapstorage).addEdgeMap(mapname,emptr, default_value)) |
815 { |
815 { |
816 return 1; |
816 return 1; |
817 } |
817 } |
818 |
818 |
819 |
819 |
820 //add it to the list of the displayable maps |
820 //add it to the list of the displayable maps |
821 mainwin.registerNewEdgeMap(mapname); |
821 mytab.registerNewEdgeMap(mapname); |
822 |
822 |
823 //display it |
823 //display it |
824 changeEdgeText(mapname); |
824 changeEdgeText(mapname); |
825 |
825 |
826 return 0; |
826 return 0; |
827 } |
827 } |
828 |
828 |
829 int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) |
829 int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname) |
830 { |
830 { |
831 //create the new map |
831 //create the new map |
832 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ((mainwin.mapstorage).graph,default_value); |
832 Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> ((mytab.mapstorage).graph,default_value); |
833 |
833 |
834 //if addition was not successful addNodeMap returns one. |
834 //if addition was not successful addNodeMap returns one. |
835 //cause can be that there is already a map named like the new one |
835 //cause can be that there is already a map named like the new one |
836 if((mainwin.mapstorage).addNodeMap(mapname,emptr, default_value)) |
836 if((mytab.mapstorage).addNodeMap(mapname,emptr, default_value)) |
837 { |
837 { |
838 return 1; |
838 return 1; |
839 } |
839 } |
840 |
840 |
841 //add it to the list of the displayable maps |
841 //add it to the list of the displayable maps |
842 mainwin.registerNewNodeMap(mapname); |
842 mytab.registerNewNodeMap(mapname); |
843 |
843 |
844 //display it |
844 //display it |
845 changeNodeText(mapname); |
845 changeNodeText(mapname); |
846 |
846 |
847 return 0; |
847 return 0; |