1.1 --- a/gui/Makefile.am Thu Jul 28 19:09:39 2005 +0000
1.2 +++ b/gui/Makefile.am Fri Jul 29 12:01:37 2005 +0000
1.3 @@ -25,7 +25,8 @@
1.4 broken_edge.cc \
1.5 broken_edge.h \
1.6 new_map_win.cc \
1.7 - new_map_win.h
1.8 + new_map_win.h \
1.9 + xymap.h
1.10
1.11 gd_CXXFLAGS = $(GTK_CFLAGS)
1.12 gd_LDFLAGS = $(GTK_LIBS)
2.1 --- a/gui/broken_edge.cc Thu Jul 28 19:09:39 2005 +0000
2.2 +++ b/gui/broken_edge.cc Fri Jul 29 12:01:37 2005 +0000
2.3 @@ -1,4 +1,4 @@
2.4 -#include <broken_edge.h>
2.5 +#include "broken_edge.h"
2.6 #include <math.h>
2.7
2.8 BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false)
3.1 --- a/gui/broken_edge.h Thu Jul 28 19:09:39 2005 +0000
3.2 +++ b/gui/broken_edge.h Fri Jul 29 12:01:37 2005 +0000
3.3 @@ -5,10 +5,10 @@
3.4
3.5 class BrokenEdge;
3.6
3.7 -#include <all_include.h>
3.8 +#include "all_include.h"
3.9 #include <libgnomecanvasmm.h>
3.10 #include <libgnomecanvasmm/polygon.h>
3.11 -#include <graph_displayer_canvas.h>
3.12 +#include "graph_displayer_canvas.h"
3.13 #include <lemon/xy.h>
3.14
3.15 class BrokenEdge : public Gnome::Canvas::Line
4.1 --- a/gui/graph-displayer.cc Thu Jul 28 19:09:39 2005 +0000
4.2 +++ b/gui/graph-displayer.cc Fri Jul 29 12:01:37 2005 +0000
4.3 @@ -1,6 +1,6 @@
4.4 -#include <all_include.h>
4.5 -#include <mapstorage.h>
4.6 -#include <main_win.h>
4.7 +#include "all_include.h"
4.8 +#include "mapstorage.h"
4.9 +#include "main_win.h"
4.10 #include <libgnomecanvasmm.h>
4.11 #include <libgnomecanvasmm/polygon.h>
4.12
4.13 @@ -37,56 +37,12 @@
4.14 node_property_defaults[N_COLOR]=100;
4.15 node_property_defaults[N_TEXT]=0;
4.16
4.17 - if(argc<2)
4.18 - {
4.19 - std::cerr << "USAGE: gd <input filename.lgf>" << std::endl;
4.20 - return 0;
4.21 - }
4.22 -
4.23 - Coordinates coosvector;
4.24 -
4.25 - Graph g;
4.26 -
4.27 - CoordinatesMap cm(g);
4.28 - Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g);
4.29 - Graph::NodeMap<double> nodedata (g);
4.30 -
4.31 - //we create one object to read x coordinates
4.32 - //and one to read y coordinate of nodes and write them to cm NodeMap.
4.33 - XMap <CoordinatesMap> xreader (cm);
4.34 - YMap <CoordinatesMap> yreader (cm);
4.35 -
4.36 - //reading in graph and its maps
4.37 -
4.38 - std::ifstream is(argv[1]);
4.39 -
4.40 - GraphReader<Graph> reader(is, g);
4.41 - reader.readNodeMap("coordinates_x", xreader);
4.42 - reader.readNodeMap("coordinates_y", yreader);
4.43 - reader.readNodeMap("data", nodedata);
4.44 - reader.readEdgeMap("cap", cap);
4.45 - reader.readEdgeMap("map1", map1);
4.46 - reader.readEdgeMap("map2", map2);
4.47 - reader.readEdgeMap("map3", map3);
4.48 - reader.readEdgeMap("map4", map4);
4.49 - reader.run();
4.50 -
4.51 - //initializing MapStorage with the read data
4.52 -
4.53 - MapStorage ms(g);
4.54 - ms.addNodeMap("data",&nodedata);
4.55 - ms.addEdgeMap("cap",&cap);
4.56 - ms.addEdgeMap("map1",&map1);
4.57 - ms.addEdgeMap("map2",&map2);
4.58 - ms.addEdgeMap("map3",&map3);
4.59 - ms.addEdgeMap("map4",&map4);
4.60 -
4.61 //initializing GUI
4.62
4.63 Gnome::Canvas::init();
4.64 Gtk::Main app(argc, argv);
4.65
4.66 - MainWin mainwin("Displayed Graph", g, cm, ms);
4.67 + MainWin mainwin("Displayed Graph");
4.68 app.run(mainwin);
4.69
4.70 return 0;
5.1 --- a/gui/graph_displayer_canvas-edge.cc Thu Jul 28 19:09:39 2005 +0000
5.2 +++ b/gui/graph_displayer_canvas-edge.cc Fri Jul 29 12:01:37 2005 +0000
5.3 @@ -1,5 +1,5 @@
5.4 -#include <graph_displayer_canvas.h>
5.5 -#include <broken_edge.h>
5.6 +#include "graph_displayer_canvas.h"
5.7 +#include "broken_edge.h"
5.8 #include <math.h>
5.9
5.10
5.11 @@ -12,7 +12,7 @@
5.12 {
5.13 min=edge_property_defaults[E_WIDTH];
5.14 max=edge_property_defaults[E_WIDTH];
5.15 - actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
5.16 + actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
5.17 }
5.18 else
5.19 {
5.20 @@ -23,7 +23,7 @@
5.21
5.22 if(edge==INVALID)
5.23 {
5.24 - for (EdgeIt i(g); i!=INVALID; ++i)
5.25 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
5.26 {
5.27 double v=abs((*actual_map)[i]);
5.28 int w;
5.29 @@ -58,7 +58,7 @@
5.30 Graph::EdgeMap<double> * actual_map;
5.31 if(mapname=="Default")
5.32 {
5.33 - actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
5.34 + actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
5.35 }
5.36 else
5.37 {
5.38 @@ -80,7 +80,7 @@
5.39
5.40 if(edge==INVALID)
5.41 {
5.42 - for (EdgeIt i(g); i!=INVALID; ++i)
5.43 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
5.44 {
5.45 double w=(*actual_map)[i];
5.46
5.47 @@ -125,7 +125,7 @@
5.48
5.49 if(edge==INVALID)
5.50 {
5.51 - for (EdgeIt i(g); i!=INVALID; ++i)
5.52 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
5.53 {
5.54 if(mapname!="Default")
5.55 {
6.1 --- a/gui/graph_displayer_canvas-event.cc Thu Jul 28 19:09:39 2005 +0000
6.2 +++ b/gui/graph_displayer_canvas-event.cc Fri Jul 29 12:01:37 2005 +0000
6.3 @@ -1,5 +1,5 @@
6.4 -#include <graph_displayer_canvas.h>
6.5 -#include <broken_edge.h>
6.6 +#include "graph_displayer_canvas.h"
6.7 +#include "broken_edge.h"
6.8 #include <math.h>
6.9
6.10
6.11 @@ -99,7 +99,7 @@
6.12
6.13 active_item=(get_item_at(clicked_x, clicked_y));
6.14 active_node=INVALID;
6.15 - for (NodeIt i(g); i!=INVALID; ++i)
6.16 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
6.17 {
6.18 if(nodesmap[i]==active_item)
6.19 {
6.20 @@ -125,6 +125,8 @@
6.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
6.22 if(active_node!=INVALID)
6.23 {
6.24 + mapstorage.modified = true;
6.25 + mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
6.26 //new coordinates will be the old values,
6.27 //because the item will be moved to the
6.28 //new coordinate therefore the new movement
6.29 @@ -147,17 +149,17 @@
6.30 //all the edges connected to the moved point has to be redrawn
6.31 EdgeIt ei;
6.32
6.33 - g.firstOut(ei,active_node);
6.34 + mapstorage.graph.firstOut(ei,active_node);
6.35
6.36 - for(;ei!=INVALID;g.nextOut(ei))
6.37 + for(;ei!=INVALID;mapstorage.graph.nextOut(ei))
6.38 {
6.39 Gnome::Canvas::Points coos;
6.40 double x1, x2, y1, y2;
6.41
6.42 - nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
6.43 + nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
6.44 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
6.45
6.46 - nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
6.47 + nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
6.48 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
6.49
6.50 if(isbutton==3)
6.51 @@ -176,16 +178,16 @@
6.52 edgetextmap[ei]->property_y().set_value(text_pos.y);
6.53 }
6.54
6.55 - g.firstIn(ei,active_node);
6.56 - for(;ei!=INVALID;g.nextIn(ei))
6.57 + mapstorage.graph.firstIn(ei,active_node);
6.58 + for(;ei!=INVALID;mapstorage.graph.nextIn(ei))
6.59 {
6.60 Gnome::Canvas::Points coos;
6.61 double x1, x2, y1, y2;
6.62
6.63 - nodesmap[g.source(ei)]->get_bounds(x1, y1, x2, y2);
6.64 + nodesmap[mapstorage.graph.source(ei)]->get_bounds(x1, y1, x2, y2);
6.65 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
6.66
6.67 - nodesmap[g.target(ei)]->get_bounds(x1, y1, x2, y2);
6.68 + nodesmap[mapstorage.graph.target(ei)]->get_bounds(x1, y1, x2, y2);
6.69 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
6.70
6.71 if(isbutton==3)
6.72 @@ -219,24 +221,33 @@
6.73 //std::cout << "double click" << std::endl;
6.74 break;
6.75 case GDK_BUTTON_PRESS:
6.76 + mapstorage.modified = true;
6.77 +
6.78 isbutton=1;
6.79
6.80 - active_node=NodeIt(g,g.addNode());
6.81 + active_node=NodeIt(mapstorage.graph,mapstorage.graph.addNode());
6.82
6.83 //initiating values corresponding to new node in maps
6.84
6.85 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
6.86
6.87 - nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph, clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
6.88 + mapstorage.coords.set(active_node, xy<double>(clicked_x, clicked_y));
6.89 + (*mapstorage.nodemap_storage["id"])[active_node] =
6.90 + mapstorage.graph.id(active_node);
6.91 +
6.92 + nodesmap[active_node]=new Gnome::Canvas::Ellipse(displayed_graph,
6.93 + clicked_x-20, clicked_y-20, clicked_x+20, clicked_y+20);
6.94 active_item=(Gnome::Canvas::Item *)(nodesmap[active_node]);
6.95 *(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
6.96 *(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
6.97 (nodesmap[active_node])->show();
6.98
6.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, "");
6.100 + nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph,
6.101 + clicked_x+node_property_defaults[N_RADIUS]+5,
6.102 + clicked_y+node_property_defaults[N_RADIUS]+5, "");
6.103 nodetextmap[active_node]->property_fill_color().set_value("darkblue");
6.104
6.105 - mapwin->updateNode(active_node);
6.106 + mapwin.updateNode(active_node);
6.107
6.108 break;
6.109
6.110 @@ -300,7 +311,7 @@
6.111
6.112 active_item=(get_item_at(clicked_x, clicked_y));
6.113 active_node=INVALID;
6.114 - for (NodeIt i(g); i!=INVALID; ++i)
6.115 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
6.116 {
6.117 if(nodesmap[i]==active_item)
6.118 {
6.119 @@ -329,7 +340,7 @@
6.120 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
6.121 target_item=(get_item_at(clicked_x, clicked_y));
6.122 Graph::NodeIt target_node=INVALID;
6.123 - for (NodeIt i(g); i!=INVALID; ++i)
6.124 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
6.125 {
6.126 if(nodesmap[i]==target_item)
6.127 {
6.128 @@ -341,13 +352,16 @@
6.129 {
6.130 if(target_node!=active_node)
6.131 {
6.132 + mapstorage.modified = true;
6.133 +
6.134 *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
6.135
6.136 //creating new edge
6.137 - active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
6.138 + active_edge=EdgeIt(mapstorage.graph,mapstorage.graph.addEdge(active_node, target_node));
6.139
6.140 //initiating values corresponding to new edge in maps
6.141 mapstorage.initMapsForEdge(active_edge);
6.142 + (*mapstorage.edgemap_storage["id"])[active_edge] = mapstorage.graph.id(active_edge);
6.143
6.144 //calculating coordinates of new edge
6.145 Gnome::Canvas::Points coos;
6.146 @@ -376,7 +390,7 @@
6.147 edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
6.148
6.149 //updating its properties
6.150 - mapwin->updateEdge(active_edge);
6.151 + mapwin.updateEdge(active_edge);
6.152 }
6.153 else
6.154 {
6.155 @@ -429,9 +443,8 @@
6.156 active_item=(get_item_at(clicked_x, clicked_y));
6.157 active_node=INVALID;
6.158 active_edge=INVALID;
6.159 -
6.160 //was it a node?
6.161 - for (NodeIt i(g); i!=INVALID; ++i)
6.162 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
6.163 {
6.164 if(nodesmap[i]==active_item)
6.165 {
6.166 @@ -441,7 +454,7 @@
6.167 //or was it an edge?
6.168 if(active_node==INVALID)
6.169 {
6.170 - for (EdgeIt i(g); i!=INVALID; ++i)
6.171 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
6.172 {
6.173 if(edgesmap[i]==active_item)
6.174 {
6.175 @@ -467,19 +480,20 @@
6.176 //a node was found
6.177 if(active_node!=INVALID)
6.178 {
6.179 + mapstorage.modified = true;
6.180
6.181 //collecting edges to delete
6.182 EdgeIt e;
6.183 std::set<Graph::Edge> edges_to_delete;
6.184
6.185 - g.firstOut(e,active_node);
6.186 - for(;e!=INVALID;g.nextOut(e))
6.187 + mapstorage.graph.firstOut(e,active_node);
6.188 + for(;e!=INVALID;mapstorage.graph.nextOut(e))
6.189 {
6.190 edges_to_delete.insert(e);
6.191 }
6.192
6.193 - g.firstIn(e,active_node);
6.194 - for(;e!=INVALID;g.nextIn(e))
6.195 + mapstorage.graph.firstIn(e,active_node);
6.196 + for(;e!=INVALID;mapstorage.graph.nextIn(e))
6.197 {
6.198 edges_to_delete.insert(e);
6.199 }
6.200 @@ -545,7 +559,7 @@
6.201
6.202 //find the activated item between texts
6.203 active_item=(get_item_at(e->button.x, e->button.y));
6.204 - for (EdgeIt i(g); i!=INVALID; ++i)
6.205 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
6.206 {
6.207 if(edgetextmap[i]==active_item)
6.208 {
6.209 @@ -559,7 +573,7 @@
6.210 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
6.211 active_item=(get_item_at(clicked_x, clicked_y));
6.212
6.213 - for (EdgeIt i(g); i!=INVALID; ++i)
6.214 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
6.215 {
6.216 //at the same time only one can be active
6.217 if((edgesmap[i]==active_item)||(edgetextmap[i]==active_item))
6.218 @@ -663,7 +677,7 @@
6.219
6.220 //find the activated item between texts
6.221 active_item=(get_item_at(e->button.x, e->button.y));
6.222 - for (NodeIt i(g); i!=INVALID; ++i)
6.223 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
6.224 {
6.225 //at the same time only one can be active
6.226 if(nodetextmap[i]==active_item)
6.227 @@ -678,7 +692,7 @@
6.228 window_to_world (e->button.x, e->button.y, clicked_x, clicked_y);
6.229 active_item=(get_item_at(clicked_x, clicked_y));
6.230
6.231 - for (NodeIt i(g); i!=INVALID; ++i)
6.232 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
6.233 {
6.234 //at the same time only one can be active
6.235 if(nodesmap[i]==active_item)
6.236 @@ -803,12 +817,12 @@
6.237 case EDGE_MAP_EDIT:
6.238 edgetextmap[active_edge]->property_text().set_value(ostr.str());
6.239 (*(mapstorage.edgemap_storage)[edgemap_to_edit])[active_edge]=mapvalue_d;
6.240 - mapwin->updateEdge(active_edge);
6.241 + mapwin.updateEdge(active_edge);
6.242 break;
6.243 case NODE_MAP_EDIT:
6.244 nodetextmap[active_node]->property_text().set_value(ostr.str());
6.245 (*(mapstorage.nodemap_storage)[nodemap_to_edit])[active_node]=mapvalue_d;
6.246 - mapwin->updateNode(active_node);
6.247 + mapwin.updateNode(active_node);
6.248 break;
6.249 default:
6.250 break;
6.251 @@ -835,21 +849,21 @@
6.252 {
6.253 delete(nodetextmap[node_to_delete]);
6.254 delete(nodesmap[node_to_delete]);
6.255 - g.erase(node_to_delete);
6.256 + mapstorage.graph.erase(node_to_delete);
6.257 }
6.258
6.259 void GraphDisplayerCanvas::deleteItem(EdgeIt edge_to_delete)
6.260 {
6.261 delete(edgetextmap[edge_to_delete]);
6.262 delete(edgesmap[edge_to_delete]);
6.263 - g.erase(edge_to_delete);
6.264 + mapstorage.graph.erase(edge_to_delete);
6.265 }
6.266
6.267 void GraphDisplayerCanvas::deleteItem(Graph::Edge edge_to_delete)
6.268 {
6.269 delete(edgetextmap[edge_to_delete]);
6.270 delete(edgesmap[edge_to_delete]);
6.271 - g.erase(edge_to_delete);
6.272 + mapstorage.graph.erase(edge_to_delete);
6.273 }
6.274
6.275 void GraphDisplayerCanvas::textReposition(xy<double> new_place)
6.276 @@ -869,7 +883,7 @@
6.277 }
6.278 else
6.279 {
6.280 - for (EdgeIt i(g); i!=INVALID; ++i)
6.281 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
6.282 {
6.283 if(edgesmap[i]==active_bre)
6.284 {
6.285 @@ -895,7 +909,7 @@
6.286 int GraphDisplayerCanvas::addNewEdgeMap(double default_value, std::string mapname)
6.287 {
6.288 //create the new map
6.289 - Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (g,default_value);
6.290 + Graph::EdgeMap<double> * emptr=new Graph::EdgeMap<double> (mapstorage.graph, default_value);
6.291
6.292 //if addition was not successful addEdgeMap returns one.
6.293 //cause can be that there is already a map named like the new one
6.294 @@ -906,7 +920,7 @@
6.295
6.296
6.297 //add it to the list of the displayable maps
6.298 - mapwin->registerNewEdgeMap(mapname);
6.299 + mapwin.registerNewEdgeMap(mapname);
6.300
6.301 //display it
6.302 changeEdgeText(mapname);
6.303 @@ -917,7 +931,7 @@
6.304 int GraphDisplayerCanvas::addNewNodeMap(double default_value, std::string mapname)
6.305 {
6.306 //create the new map
6.307 - Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (g,default_value);
6.308 + Graph::NodeMap<double> * emptr=new Graph::NodeMap<double> (mapstorage.graph,default_value);
6.309
6.310 //if addition was not successful addNodeMap returns one.
6.311 //cause can be that there is already a map named like the new one
6.312 @@ -927,7 +941,7 @@
6.313 }
6.314
6.315 //add it to the list of the displayable maps
6.316 - mapwin->registerNewNodeMap(mapname);
6.317 + mapwin.registerNewNodeMap(mapname);
6.318
6.319 //display it
6.320 changeNodeText(mapname);
7.1 --- a/gui/graph_displayer_canvas-node.cc Thu Jul 28 19:09:39 2005 +0000
7.2 +++ b/gui/graph_displayer_canvas-node.cc Fri Jul 29 12:01:37 2005 +0000
7.3 @@ -1,5 +1,5 @@
7.4 -#include <graph_displayer_canvas.h>
7.5 -#include <broken_edge.h>
7.6 +#include "graph_displayer_canvas.h"
7.7 +#include "broken_edge.h"
7.8 #include <math.h>
7.9
7.10
7.11 @@ -11,7 +11,7 @@
7.12 {
7.13 min=node_property_defaults[N_RADIUS];
7.14 max=node_property_defaults[N_RADIUS];
7.15 - actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
7.16 + actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
7.17 }
7.18 else
7.19 {
7.20 @@ -22,7 +22,7 @@
7.21
7.22 if(node==INVALID)
7.23 {
7.24 - for (NodeIt i(g); i!=INVALID; ++i)
7.25 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
7.26 {
7.27 double v=abs((*actual_map)[i]);
7.28 int w;
7.29 @@ -79,7 +79,7 @@
7.30 Graph::NodeMap<double> * actual_map;
7.31 if(mapname=="Default")
7.32 {
7.33 - actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
7.34 + actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
7.35 }
7.36 else
7.37 {
7.38 @@ -103,7 +103,7 @@
7.39 if(node==INVALID)
7.40 {
7.41
7.42 - for (NodeIt i(g); i!=INVALID; ++i)
7.43 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
7.44 {
7.45 Gdk::Color color;
7.46
7.47 @@ -157,7 +157,7 @@
7.48
7.49 if(node==INVALID)
7.50 {
7.51 - for (NodeIt i(g); i!=INVALID; ++i)
7.52 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
7.53 {
7.54 if(mapname!="Default")
7.55 {
8.1 --- a/gui/graph_displayer_canvas-zoom.cc Thu Jul 28 19:09:39 2005 +0000
8.2 +++ b/gui/graph_displayer_canvas-zoom.cc Fri Jul 29 12:01:37 2005 +0000
8.3 @@ -1,5 +1,5 @@
8.4 -#include <graph_displayer_canvas.h>
8.5 -#include <broken_edge.h>
8.6 +#include "graph_displayer_canvas.h"
8.7 +#include "broken_edge.h"
8.8 #include <math.h>
8.9
8.10 void GraphDisplayerCanvas::zoomIn()
9.1 --- a/gui/graph_displayer_canvas.cc Thu Jul 28 19:09:39 2005 +0000
9.2 +++ b/gui/graph_displayer_canvas.cc Fri Jul 29 12:01:37 2005 +0000
9.3 @@ -1,34 +1,61 @@
9.4 -#include <graph_displayer_canvas.h>
9.5 -#include <broken_edge.h>
9.6 +#include "graph_displayer_canvas.h"
9.7 +#include "broken_edge.h"
9.8 #include <math.h>
9.9
9.10 -GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),canvasentrywidget(NULL),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),nodemap_to_edit(""),edgemap_to_edit(""),mapwin(mw)
9.11 +GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) :
9.12 + nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
9.13 + nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
9.14 + canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
9.15 + target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
9.16 {
9.17 -
9.18 - //Initializing values.
9.19 - active_node=INVALID;
9.20 - active_edge=INVALID;
9.21 - forming_edge=INVALID;
9.22 + //base event handler is move tool
9.23 + actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
9.24 + actual_tool=MOVE;
9.25
9.26 //setting event handler for the editor widget
9.27 entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
9.28
9.29 - //base event handler is move tool
9.30 - actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
9.31 - actual_tool=MOVE;
9.32 + active_node=INVALID;
9.33 + active_edge=INVALID;
9.34 + forming_edge=INVALID;
9.35 +}
9.36
9.37 - //set_center_scroll_region(true);
9.38 +GraphDisplayerCanvas::~GraphDisplayerCanvas()
9.39 +{
9.40 + for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
9.41 + {
9.42 + delete nodesmap[n];
9.43 + delete nodetextmap[n];
9.44 + }
9.45
9.46 + for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
9.47 + {
9.48 + delete edgesmap[e];
9.49 + delete edgetextmap[e];
9.50 + }
9.51 +
9.52 + if(canvasentrywidget)
9.53 + {
9.54 + delete(canvasentrywidget);
9.55 + }
9.56 +}
9.57 +
9.58 +void GraphDisplayerCanvas::drawGraph()
9.59 +{
9.60 //first edges are drawn, to hide joining with nodes later
9.61
9.62 - for (EdgeIt i(g); i!=INVALID; ++i)
9.63 + for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
9.64 {
9.65
9.66 - //drawing green lines, coordinates are from cm
9.67 + //drawing green lines, coordinates are from mapstorage.coords
9.68
9.69 Gnome::Canvas::Points coos;
9.70 - coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
9.71 - coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
9.72 + coos.push_back(Gnome::Art::Point(
9.73 + mapstorage.coords[mapstorage.graph.source(i)].x,
9.74 + mapstorage.coords[mapstorage.graph.source(i)].y));
9.75 + coos.push_back(Gnome::Art::Point(
9.76 + mapstorage.coords[mapstorage.graph.target(i)].x,
9.77 + mapstorage.coords[mapstorage.graph.target(i)].y));
9.78
9.79 edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
9.80 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
9.81 @@ -46,29 +73,27 @@
9.82
9.83 //afterwards nodes come to be drawn
9.84
9.85 - NodeIt i(g);
9.86 - int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
9.87 -
9.88 - for (; i!=INVALID; ++i)
9.89 + for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
9.90 {
9.91 - //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
9.92 -
9.93 - if(cm[i].x>maxx)maxx=(int)cm[i].x;
9.94 - if(cm[i].y>maxy)maxy=(int)cm[i].y;
9.95 - if(cm[i].x<minx)minx=(int)cm[i].x;
9.96 - if(cm[i].y<miny)miny=(int)cm[i].y;
9.97 -
9.98 //drawing bule nodes, with black line around them
9.99
9.100 - nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
9.101 + nodesmap[i]=new Gnome::Canvas::Ellipse(
9.102 + displayed_graph,
9.103 + mapstorage.coords[i].x-20,
9.104 + mapstorage.coords[i].y-20,
9.105 + mapstorage.coords[i].x+20,
9.106 + mapstorage.coords[i].y+20);
9.107 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
9.108 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
9.109
9.110 //initializing edge-text as well, to empty string
9.111
9.112 - xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
9.113 + xy<double> text_pos(
9.114 + (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
9.115 + (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
9.116
9.117 - nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
9.118 + nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
9.119 + text_pos.x, text_pos.y, "");
9.120 nodetextmap[i]->property_fill_color().set_value("darkblue");
9.121 nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
9.122 }
9.123 @@ -76,36 +101,21 @@
9.124 updateScrollRegion();
9.125 }
9.126
9.127 -GraphDisplayerCanvas::~GraphDisplayerCanvas()
9.128 +void GraphDisplayerCanvas::clear()
9.129 {
9.130 - if(canvasentrywidget)
9.131 - {
9.132 - delete(canvasentrywidget);
9.133 - }
9.134 + active_node=INVALID;
9.135 + active_edge=INVALID;
9.136 + forming_edge=INVALID;
9.137
9.138 - //writing out the end state of the graph
9.139 - //\todo all the maps has to be write out!
9.140 -
9.141 - Graph::NodeMap <int> id(g);
9.142 - Graph::NodeMap <double> xc(g);
9.143 - Graph::NodeMap <double> yc(g);
9.144 -
9.145 - int j=1;
9.146 -
9.147 - for (NodeIt i(g); i!=INVALID; ++i)
9.148 + for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
9.149 {
9.150 - double x1,y1,x2,y2;
9.151 - nodesmap[i]->get_bounds(x1, y1, x2, y2);
9.152 -
9.153 - id[i]=j++;
9.154 - xc[i]=(x1+x2)/2;
9.155 - yc[i]=(y1+y2)/2;
9.156 + delete nodesmap[n];
9.157 + delete nodetextmap[n];
9.158 }
9.159
9.160 - GraphWriter<Graph> writer(std::cout,g);
9.161 -
9.162 - writer.writeNodeMap("id", id);
9.163 - writer.writeNodeMap("coordinates_x", xc);
9.164 - writer.writeNodeMap("coordinates_y", yc);
9.165 - writer.run();
9.166 + for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
9.167 + {
9.168 + delete edgesmap[e];
9.169 + delete edgetextmap[e];
9.170 + }
9.171 }
10.1 --- a/gui/graph_displayer_canvas.h Thu Jul 28 19:09:39 2005 +0000
10.2 +++ b/gui/graph_displayer_canvas.h Fri Jul 29 12:01:37 2005 +0000
10.3 @@ -5,10 +5,10 @@
10.4
10.5 class GraphDisplayerCanvas;
10.6
10.7 -#include <all_include.h>
10.8 -#include <map_win.h>
10.9 -#include <mapstorage.h>
10.10 -#include <broken_edge.h>
10.11 +#include "all_include.h"
10.12 +#include "mapstorage.h"
10.13 +#include "broken_edge.h"
10.14 +#include "map_win.h"
10.15 #include <libgnomecanvasmm.h>
10.16 #include <libgnomecanvasmm/polygon.h>
10.17
10.18 @@ -18,7 +18,7 @@
10.19 typedef Gnome::Canvas::CanvasAA Parent;
10.20
10.21 public:
10.22 - GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &, MapWin *);
10.23 + GraphDisplayerCanvas(MapStorage &, MapWin &);
10.24 virtual ~GraphDisplayerCanvas();
10.25
10.26 ///Changes the linewidth attribute according to the given map.
10.27 @@ -109,6 +109,9 @@
10.28 ///\return the actual tool in hand
10.29 int getActualTool();
10.30
10.31 + void drawGraph();
10.32 + void clear();
10.33 +
10.34 ///creates a new Nodemap
10.35 int addNewNodeMap(double,std::string);
10.36 ///creates a new Edgemap
10.37 @@ -124,9 +127,6 @@
10.38
10.39 private:
10.40
10.41 - ///The graph, on which we work
10.42 - Graph & g;
10.43 -
10.44 ///Map of nodes of graph
10.45 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
10.46
10.47 @@ -175,7 +175,7 @@
10.48 static const int zoom_step = 5;
10.49
10.50 ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
10.51 - MapWin * mapwin;
10.52 + MapWin & mapwin;
10.53
10.54 };
10.55
11.1 --- a/gui/main_win.cc Thu Jul 28 19:09:39 2005 +0000
11.2 +++ b/gui/main_win.cc Fri Jul 29 12:01:37 2005 +0000
11.3 @@ -1,7 +1,8 @@
11.4 -#include <main_win.h>
11.5 +#include "main_win.h"
11.6
11.7 -MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
11.8 - MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),newmapwin("Creating new map",gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
11.9 +MainWin::MainWin(const std::string& title) :
11.10 + mapwin("Map Setup", mapstorage, gd_canvas),
11.11 + newmapwin("Creating new map", gd_canvas), gd_canvas(mapstorage, mapwin)
11.12 {
11.13
11.14 set_title (title);
11.15 @@ -19,7 +20,9 @@
11.16 sigc::mem_fun(*this, &MainWin::saveFile));
11.17 ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
11.18 sigc::mem_fun(*this, &MainWin::saveFileAs));
11.19 - ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
11.20 + ag->add( Gtk::Action::create("Close", Gtk::Stock::CLOSE),
11.21 + sigc::mem_fun(*this, &MainWin::close));
11.22 + ag->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT),
11.23 sigc::mem_fun(*this, &MainWin::hide));
11.24
11.25 ag->add( Gtk::Action::create("ViewMenu", "_View") );
11.26 @@ -36,14 +39,15 @@
11.27 ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
11.28 sigc::mem_fun(this->mapwin, &MapWin::show));
11.29
11.30 - ag->add( Gtk::Action::create("CreateNode", Gtk::Stock::NO),
11.31 + Gtk::RadioAction::Group tool_group;
11.32 + ag->add( Gtk::RadioAction::create(tool_group, "MoveItem", Gtk::Stock::CONVERT, "Move"),
11.33 + sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
11.34 + ag->add( Gtk::RadioAction::create(tool_group, "CreateNode", Gtk::Stock::NO, "Create node"),
11.35 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 1) );
11.36 - ag->add( Gtk::Action::create("CreateEdge", Gtk::Stock::REMOVE),
11.37 + ag->add( Gtk::RadioAction::create(tool_group, "CreateEdge", Gtk::Stock::REMOVE, "Create edge"),
11.38 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 2) );
11.39 - ag->add( Gtk::Action::create("EraseItem", Gtk::Stock::DELETE),
11.40 + ag->add( Gtk::RadioAction::create(tool_group, "EraseItem", Gtk::Stock::DELETE, "Delete"),
11.41 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 3) );
11.42 - ag->add( Gtk::Action::create("MoveItem", Gtk::Stock::CONVERT),
11.43 - sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 0) );
11.44 ag->add( Gtk::Action::create("EditEdgeMap", Gtk::Stock::PROPERTIES),
11.45 sigc::bind( sigc::mem_fun ( this->gd_canvas, &GraphDisplayerCanvas::changeEditorialTool ), 4) );
11.46 ag->add( Gtk::Action::create("EditNodeMap", Gtk::Stock::PREFERENCES),
11.47 @@ -66,7 +70,8 @@
11.48 " <menuitem action='FileOpen'/>"
11.49 " <menuitem action='FileSave'/>"
11.50 " <menuitem action='FileSaveAs'/>"
11.51 - " <menuitem action='FileQuit'/>"
11.52 + " <menuitem action='Close'/>"
11.53 + " <menuitem action='Quit'/>"
11.54 " </menu>"
11.55 " <menu action='ViewMenu'>"
11.56 " <menuitem action='ViewZoomIn' />"
11.57 @@ -82,16 +87,17 @@
11.58 " <toolitem action='FileNew' />"
11.59 " <toolitem action='FileOpen' />"
11.60 " <toolitem action='FileSave' />"
11.61 + " <toolitem action='Close' />"
11.62 " <separator />"
11.63 " <toolitem action='ViewZoomIn' />"
11.64 " <toolitem action='ViewZoomOut' />"
11.65 " <toolitem action='ViewZoomFit' />"
11.66 " <toolitem action='ViewZoom100' />"
11.67 " <separator />"
11.68 + " <toolitem action='MoveItem' />"
11.69 " <toolitem action='CreateNode' />"
11.70 " <toolitem action='CreateEdge' />"
11.71 " <toolitem action='EraseItem' />"
11.72 - " <toolitem action='MoveItem' />"
11.73 " <toolitem action='EditEdgeMap' />"
11.74 " <toolitem action='EditNodeMap' />"
11.75 " <toolitem action='AddMap' />"
11.76 @@ -130,20 +136,115 @@
11.77
11.78 void MainWin::newFile()
11.79 {
11.80 - std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
11.81 + if (mapstorage.modified)
11.82 + {
11.83 + Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
11.84 + Gtk::BUTTONS_NONE);
11.85 + mdialog.set_message("<b>Save changes before closing?</b>", true);
11.86 + mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
11.87 + mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
11.88 + mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
11.89 + switch (mdialog.run())
11.90 + {
11.91 + case Gtk::RESPONSE_CANCEL:
11.92 + return;
11.93 + case Gtk::RESPONSE_REJECT:
11.94 + break;
11.95 + case Gtk::RESPONSE_ACCEPT:
11.96 + saveFile();
11.97 + break;
11.98 + }
11.99 + }
11.100 + gd_canvas.clear();
11.101 + mapstorage.clear();
11.102 + mapwin.update();
11.103 }
11.104
11.105 void MainWin::openFile()
11.106 {
11.107 - std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
11.108 + if (mapstorage.modified)
11.109 + {
11.110 + Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
11.111 + Gtk::BUTTONS_NONE);
11.112 + mdialog.set_message("<b>Save changes before closing?</b>", true);
11.113 + mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
11.114 + mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
11.115 + mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
11.116 + switch (mdialog.run())
11.117 + {
11.118 + case Gtk::RESPONSE_CANCEL:
11.119 + return;
11.120 + case Gtk::RESPONSE_REJECT:
11.121 + break;
11.122 + case Gtk::RESPONSE_ACCEPT:
11.123 + saveFile();
11.124 + break;
11.125 + }
11.126 + }
11.127 + gd_canvas.clear();
11.128 + mapstorage.clear();
11.129 + Gtk::FileChooserDialog fcdialog("Open File");
11.130 + fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
11.131 + fcdialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
11.132 + if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
11.133 + {
11.134 + Glib::ustring filename = fcdialog.get_filename();
11.135 + mapstorage.readFromFile(filename);
11.136 + mapstorage.file_name = filename;
11.137 + mapstorage.modified = false;
11.138 + gd_canvas.drawGraph();
11.139 + mapwin.update();
11.140 + }
11.141 }
11.142
11.143 void MainWin::saveFile()
11.144 {
11.145 - std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
11.146 + if (mapstorage.file_name == "") {
11.147 + saveFileAs();
11.148 + }
11.149 + else
11.150 + {
11.151 + mapstorage.writeToFile(mapstorage.file_name);
11.152 + mapstorage.modified = false;
11.153 + }
11.154 }
11.155
11.156 void MainWin::saveFileAs()
11.157 {
11.158 - std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
11.159 + Gtk::FileChooserDialog fcdialog("Save File", Gtk::FILE_CHOOSER_ACTION_SAVE);
11.160 + fcdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
11.161 + fcdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
11.162 + if (fcdialog.run() == Gtk::RESPONSE_ACCEPT)
11.163 + {
11.164 + Glib::ustring filename = fcdialog.get_filename();
11.165 + mapstorage.file_name = filename;
11.166 + mapstorage.writeToFile(filename);
11.167 + mapstorage.modified = false;
11.168 + }
11.169 }
11.170 +
11.171 +void MainWin::close()
11.172 +{
11.173 + if (mapstorage.modified)
11.174 + {
11.175 + Gtk::MessageDialog mdialog("", false, Gtk::MESSAGE_WARNING,
11.176 + Gtk::BUTTONS_NONE);
11.177 + mdialog.set_message("<b>Save changes before closing?</b>", true);
11.178 + mdialog.add_button("Close _without Saving", Gtk::RESPONSE_REJECT);
11.179 + mdialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
11.180 + mdialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_ACCEPT);
11.181 + switch (mdialog.run())
11.182 + {
11.183 + case Gtk::RESPONSE_CANCEL:
11.184 + return;
11.185 + case Gtk::RESPONSE_REJECT:
11.186 + break;
11.187 + case Gtk::RESPONSE_ACCEPT:
11.188 + saveFile();
11.189 + break;
11.190 + }
11.191 + }
11.192 + gd_canvas.clear();
11.193 + mapstorage.clear();
11.194 + mapwin.update();
11.195 +}
12.1 --- a/gui/main_win.h Thu Jul 28 19:09:39 2005 +0000
12.2 +++ b/gui/main_win.h Fri Jul 29 12:01:37 2005 +0000
12.3 @@ -3,10 +3,12 @@
12.4 #ifndef MAIN_WIN_H
12.5 #define MAIN_WIN_H
12.6
12.7 -#include <all_include.h>
12.8 -#include <mapstorage.h>
12.9 -#include <map_win.h>
12.10 -#include <new_map_win.h>
12.11 +#include "all_include.h"
12.12 +#include "mapstorage.h"
12.13 +#include "map_win.h"
12.14 +#include "new_map_win.h"
12.15 +#include "edit_win.h"
12.16 +#include "graph_displayer_canvas.h"
12.17 #include <libgnomecanvasmm.h>
12.18 #include <libgnomecanvasmm/polygon.h>
12.19
12.20 @@ -17,10 +19,9 @@
12.21 public:
12.22 ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
12.23 ///\param title is the title of the window
12.24 - ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
12.25 - ///\param cm stores the coordinates of the nodes of the graph
12.26 - ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
12.27 - MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
12.28 + MainWin(const std::string& title);
12.29 +
12.30 + MapStorage mapstorage;
12.31
12.32 protected:
12.33 ///Window of map-showing setup. Its type is \ref MapWin
12.34 @@ -52,6 +53,8 @@
12.35 virtual void saveFile();
12.36 ///Callback for 'FileSaveAs' action.
12.37 virtual void saveFileAs();
12.38 + ///Callback for 'Close' action.
12.39 + virtual void close();
12.40 };
12.41
12.42 #endif //MAIN_WIN_H
13.1 --- a/gui/map_win.cc Thu Jul 28 19:09:39 2005 +0000
13.2 +++ b/gui/map_win.cc Fri Jul 29 12:01:37 2005 +0000
13.3 @@ -1,4 +1,4 @@
13.4 -#include <map_win.h>
13.5 +#include "map_win.h"
13.6 #include <set>
13.7
13.8 bool MapWin::closeIfEscapeIsPressed(GdkEventKey* e)
13.9 @@ -120,6 +120,41 @@
13.10
13.11 }
13.12
13.13 +void MapWin::update()
13.14 +{
13.15 + for(int i=0;i<EDGE_PROPERTY_NUM;i++)
13.16 + {
13.17 + //filling in combo box with choices
13.18 + std::list<Glib::ustring> listStrings;
13.19 +
13.20 + listStrings.push_back("Default");
13.21 +
13.22 + std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
13.23 + for(;emsi!=ms.endOfEdgeMaps();emsi++)
13.24 + {
13.25 + listStrings.push_back(emsi->first);
13.26 + }
13.27 +
13.28 + e_combo_array[i].set_popdown_strings(listStrings);
13.29 + }
13.30 + for(int i=0;i<NODE_PROPERTY_NUM;i++)
13.31 + {
13.32 + //filling in combo box with choices
13.33 + std::list<Glib::ustring> listStrings;
13.34 +
13.35 + listStrings.push_back("Default");
13.36 +
13.37 + std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
13.38 +
13.39 + for(;emsi!=ms.endOfNodeMaps();emsi++)
13.40 + {
13.41 + listStrings.push_back(emsi->first);
13.42 + }
13.43 +
13.44 + n_combo_array[i].set_popdown_strings(listStrings);
13.45 + }
13.46 +}
13.47 +
13.48 void MapWin::eComboChanged(int prop)
13.49 {
13.50
14.1 --- a/gui/map_win.h Thu Jul 28 19:09:39 2005 +0000
14.2 +++ b/gui/map_win.h Fri Jul 29 12:01:37 2005 +0000
14.3 @@ -5,9 +5,9 @@
14.4
14.5 class MapWin;
14.6
14.7 -#include <all_include.h>
14.8 -#include <mapstorage.h>
14.9 -#include <graph_displayer_canvas.h>
14.10 +#include "all_include.h"
14.11 +#include "graph_displayer_canvas.h"
14.12 +#include "mapstorage.h"
14.13 #include <libgnomecanvasmm.h>
14.14 #include <libgnomecanvasmm/polygon.h>
14.15
14.16 @@ -63,6 +63,7 @@
14.17
14.18 virtual bool closeIfEscapeIsPressed(GdkEventKey*);
14.19
14.20 + void update();
14.21 };
14.22
14.23 #endif //MAP_WIN_H
15.1 --- a/gui/mapstorage.cc Thu Jul 28 19:09:39 2005 +0000
15.2 +++ b/gui/mapstorage.cc Fri Jul 29 12:01:37 2005 +0000
15.3 @@ -1,8 +1,29 @@
15.4 -#include <mapstorage.h>
15.5 +#include "mapstorage.h"
15.6
15.7 -MapStorage::MapStorage(Graph & graph):g(graph)
15.8 +MapStorage::MapStorage() : modified(false), file_name("")
15.9 {
15.10 -};
15.11 + nodemap_storage["coordinates_x"] = new Graph::NodeMap<double>(graph);
15.12 + coords.setXMap(*nodemap_storage["coordinates_x"]);
15.13 + nodemap_storage["coordinates_y"] = new Graph::NodeMap<double>(graph);
15.14 + coords.setYMap(*nodemap_storage["coordinates_y"]);
15.15 +
15.16 + nodemap_storage["id"] = new Graph::NodeMap<double>(graph);
15.17 + edgemap_storage["id"] = new Graph::EdgeMap<double>(graph);
15.18 +}
15.19 +
15.20 +MapStorage::~MapStorage()
15.21 +{
15.22 + for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
15.23 + nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
15.24 + {
15.25 + delete it->second;
15.26 + }
15.27 + for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
15.28 + edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
15.29 + {
15.30 + delete it->second;
15.31 + }
15.32 +}
15.33
15.34 int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
15.35 {
15.36 @@ -27,7 +48,7 @@
15.37 double MapStorage::maxOfNodeMap(const std::string & name)
15.38 {
15.39 double max=0;
15.40 - for (NodeIt j(g); j!=INVALID; ++j)
15.41 + for (NodeIt j(graph); j!=INVALID; ++j)
15.42 {
15.43 if( (*nodemap_storage[name])[j]>max )
15.44 {
15.45 @@ -40,7 +61,7 @@
15.46 double MapStorage::maxOfEdgeMap(const std::string & name)
15.47 {
15.48 double max=0;
15.49 - for (EdgeIt j(g); j!=INVALID; ++j)
15.50 + for (EdgeIt j(graph); j!=INVALID; ++j)
15.51 {
15.52 if( (*edgemap_storage[name])[j]>max )
15.53 {
15.54 @@ -52,7 +73,7 @@
15.55
15.56 double MapStorage::minOfNodeMap(const std::string & name)
15.57 {
15.58 - NodeIt j(g);
15.59 + NodeIt j(graph);
15.60 double min=(*nodemap_storage[name])[j];
15.61 for (; j!=INVALID; ++j)
15.62 {
15.63 @@ -66,9 +87,9 @@
15.64
15.65 double MapStorage::minOfEdgeMap(const std::string & name)
15.66 {
15.67 - EdgeIt j(g);
15.68 + EdgeIt j(graph);
15.69 double min=(*edgemap_storage[name])[j];
15.70 - for (EdgeIt j(g); j!=INVALID; ++j)
15.71 + for (EdgeIt j(graph); j!=INVALID; ++j)
15.72 {
15.73 if( (*edgemap_storage[name])[j]<min )
15.74 {
15.75 @@ -86,3 +107,131 @@
15.76 (*((*ems_it).second))[e]=5;
15.77 }
15.78 }
15.79 +
15.80 +void MapStorage::readFromFile(const std::string &filename)
15.81 +{
15.82 + bool read_x = false;
15.83 + bool read_y = false;
15.84 +
15.85 + try {
15.86 + LemonReader lreader(filename);
15.87 + ContentReader content(lreader);
15.88 + lreader.run();
15.89 +
15.90 + const std::vector<std::string>& nodeMapNames = content.nodeSetMaps(0);
15.91 + const std::vector<std::string>& edgeMapNames = content.edgeSetMaps(0);
15.92 +
15.93 + GraphReader<Graph> greader(filename, graph);
15.94 + for (std::vector<std::string>::const_iterator it = nodeMapNames.begin();
15.95 + it != nodeMapNames.end(); ++it)
15.96 + {
15.97 + if (*it == "coordinates_x")
15.98 + {
15.99 + read_x = true;
15.100 + //std::cout << "read X nodemap" << std::endl;
15.101 + }
15.102 + else if (*it == "coordinates_y")
15.103 + {
15.104 + read_y = true;
15.105 + //std::cout << "read Y nodemap" << std::endl;
15.106 + }
15.107 + else if (*it == "id")
15.108 + {
15.109 + //std::cout << "read id nodemap" << std::endl;
15.110 + }
15.111 + else
15.112 + {
15.113 + nodemap_storage[*it] = new Graph::NodeMap<double>(graph);
15.114 + //std::cout << "read " << *it << " nodemap" << std::endl;
15.115 + }
15.116 + greader.readNodeMap(*it, *nodemap_storage[*it]);
15.117 + }
15.118 + for (std::vector<std::string>::const_iterator it = edgeMapNames.begin();
15.119 + it != edgeMapNames.end(); ++it)
15.120 + {
15.121 + if (*it == "id")
15.122 + {
15.123 + //std::cout << "read id edgemap" << std::endl;
15.124 + }
15.125 + else
15.126 + {
15.127 + edgemap_storage[*it] = new Graph::EdgeMap<double>(graph);
15.128 + //std::cout << "read " << *it << " edgemap" << std::endl;
15.129 + }
15.130 + greader.readEdgeMap(*it, *edgemap_storage[*it]);
15.131 + }
15.132 + greader.run();
15.133 + } catch (DataFormatError& error) {
15.134 + /*
15.135 + Gtk::MessageDialog mdialog("Read Error");
15.136 + mdialog.set_message(error.what());
15.137 + mdialog.run();
15.138 + */
15.139 + // reset graph and mapstorage ?
15.140 + return;
15.141 + }
15.142 +
15.143 + if (!read_x || !read_y)
15.144 + {
15.145 + int node_num = 0;
15.146 + for (NodeIt n(graph); n != INVALID; ++n)
15.147 + {
15.148 + node_num++;
15.149 + }
15.150 + const double pi = 3.142;
15.151 + double step = 2 * pi / (double) node_num;
15.152 + int i = 0;
15.153 + for (NodeIt n(graph); n != INVALID; ++n)
15.154 + {
15.155 + nodemap_storage["coordinates_x"]->set(n, 250.0 * cos(i * step));
15.156 + nodemap_storage["coordinates_y"]->set(n, 250.0 * sin(i * step));
15.157 + i++;
15.158 + }
15.159 + }
15.160 +}
15.161 +
15.162 +void MapStorage::writeToFile(const std::string &filename)
15.163 +{
15.164 + GraphWriter<Graph> gwriter(filename, graph);
15.165 +
15.166 + for (std::map<std::string, Graph::NodeMap<double>*>::const_iterator it =
15.167 + nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
15.168 + {
15.169 + gwriter.writeNodeMap(it->first, *(it->second));
15.170 + //std::cout << "wrote " << it->first << " nodemap" << std::endl;
15.171 + }
15.172 + for (std::map<std::string, Graph::EdgeMap<double>*>::const_iterator it =
15.173 + edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
15.174 + {
15.175 + gwriter.writeEdgeMap(it->first, *(it->second));
15.176 + //std::cout << "wrote " << it->first << " edgemap" << std::endl;
15.177 + }
15.178 + gwriter.run();
15.179 +}
15.180 +
15.181 +void MapStorage::clear()
15.182 +{
15.183 + for (std::map<std::string, Graph::NodeMap<double>*>::iterator it =
15.184 + nodemap_storage.begin(); it != nodemap_storage.end(); ++it)
15.185 + {
15.186 + if ((it->first != "coordinates_x") &&
15.187 + (it->first != "coordinates_y") &&
15.188 + (it->first != "id"))
15.189 + {
15.190 + delete it->second;
15.191 + nodemap_storage.erase(it);
15.192 + }
15.193 + }
15.194 + for (std::map<std::string, Graph::EdgeMap<double>*>::iterator it =
15.195 + edgemap_storage.begin(); it != edgemap_storage.end(); ++it)
15.196 + {
15.197 + if (it->first != "id")
15.198 + {
15.199 + delete it->second;
15.200 + edgemap_storage.erase(it);
15.201 + }
15.202 + }
15.203 + graph.clear();
15.204 + file_name = "";
15.205 + modified = false;
15.206 +}
16.1 --- a/gui/mapstorage.h Thu Jul 28 19:09:39 2005 +0000
16.2 +++ b/gui/mapstorage.h Fri Jul 29 12:01:37 2005 +0000
16.3 @@ -3,7 +3,8 @@
16.4 #ifndef MAPSTORAGE_H
16.5 #define MAPSTORAGE_H
16.6
16.7 -#include <all_include.h>
16.8 +#include "all_include.h"
16.9 +#include "xymap.h"
16.10
16.11 ///Class MapStorage is responsible for storing
16.12 ///NodeMaps and EdgeMaps that can be shown later
16.13 @@ -18,7 +19,11 @@
16.14 {
16.15 public:
16.16
16.17 - Graph &g;
16.18 + Graph graph;
16.19 + XYMap<Graph::NodeMap<double> > coords;
16.20 +
16.21 + bool modified;
16.22 + std::string file_name;
16.23
16.24 ///Stores double type NodeMaps
16.25 std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
16.26 @@ -39,7 +44,9 @@
16.27 ///for different visualization attributes
16.28 ///
16.29 ///\param graph is the graph for which the maps are stored in this object.
16.30 - MapStorage(Graph &);
16.31 + MapStorage();
16.32 +
16.33 + ~MapStorage();
16.34
16.35 ///Adds given map to storage. A name and the map itself has to be provided.
16.36 ///\param name is the name of map
16.37 @@ -92,6 +99,11 @@
16.38
16.39 ///This function sets a default base value for the newly created node
16.40 void initMapsForEdge(Graph::Edge);
16.41 +
16.42 + void readFromFile(const std::string &);
16.43 + void writeToFile(const std::string &);
16.44 +
16.45 + void clear();
16.46 };
16.47
16.48 #endif //MAPSTORAGE_H
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/gui/xymap.h Fri Jul 29 12:01:37 2005 +0000
17.3 @@ -0,0 +1,35 @@
17.4 +#ifndef XYMAP_H
17.5 +#define XYMAP_H
17.6 +
17.7 +#include <lemon/list_graph.h>
17.8 +#include <lemon/xy.h>
17.9 +
17.10 +using lemon::ListGraph;
17.11 +using lemon::xy;
17.12 +
17.13 +template<class M>
17.14 +class XYMap
17.15 +{
17.16 + private:
17.17 + M *xmap, *ymap;
17.18 +
17.19 + public:
17.20 + typedef typename M::Key Key;
17.21 + typedef xy<typename M::Value> Value;
17.22 + XYMap() {}
17.23 + XYMap(M &_xmap, M &_ymap) : xmap(&_xmap), ymap(&_ymap) {}
17.24 + void setXMap(M &_xmap) { xmap = &_xmap; }
17.25 + void setYMap(M &_ymap) { ymap = &_ymap; }
17.26 + Value operator[](Key k) const
17.27 + {
17.28 + Value v(xmap->operator[](k), ymap->operator[](k));
17.29 + return v;
17.30 + }
17.31 + void set(Key k, Value v)
17.32 + {
17.33 + xmap->set(k, v.x);
17.34 + ymap->set(k, v.y);
17.35 + }
17.36 +};
17.37 +
17.38 +#endif