1.1 --- a/gui/all_include.h Wed Jun 01 23:30:13 2005 +0000
1.2 +++ b/gui/all_include.h Wed Jun 01 23:33:26 2005 +0000
1.3 @@ -1,39 +1,39 @@
1.4 -// -*- C++ -*- //
1.5 -
1.6 -#ifndef ALL_INCLUDE_H
1.7 -#define ALL_INCLUDE_H
1.8 -
1.9 -#include <fstream>
1.10 -#include <iostream>
1.11 -
1.12 -#include <vector>
1.13 -
1.14 -#include <lemon/list_graph.h>
1.15 -#include <lemon/graph_reader.h>
1.16 -#include <lemon/graph_writer.h>
1.17 -#include <lemon/graph_utils.h>
1.18 -#include <lemon/maps.h>
1.19 -#include <lemon/error.h>
1.20 -#include <lemon/xy.h>
1.21 -
1.22 -enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
1.23 -#define RANGE 3
1.24 -#define WIN_WIDTH 900
1.25 -#define WIN_HEIGHT 600
1.26 -
1.27 -
1.28 -#ifndef MAIN_PART
1.29 -extern std::string * property_strings;
1.30 -extern double * property_defaults;
1.31 -#endif //MAIN_PART
1.32 -
1.33 -using namespace lemon;
1.34 -
1.35 -typedef xy<double> Coordinates;
1.36 -typedef ListGraph Graph;
1.37 -typedef Graph::NodeMap<Coordinates> CoordinatesMap;
1.38 -typedef Graph::Node Node;
1.39 -typedef Graph::EdgeIt EdgeIt;
1.40 -typedef Graph::NodeIt NodeIt;
1.41 -
1.42 -#endif // ALL_INCLUDE_H
1.43 +// -*- C++ -*- //
1.44 +
1.45 +#ifndef ALL_INCLUDE_H
1.46 +#define ALL_INCLUDE_H
1.47 +
1.48 +#include <fstream>
1.49 +#include <iostream>
1.50 +
1.51 +#include <vector>
1.52 +
1.53 +#include <lemon/list_graph.h>
1.54 +#include <lemon/graph_reader.h>
1.55 +#include <lemon/graph_writer.h>
1.56 +#include <lemon/graph_utils.h>
1.57 +#include <lemon/maps.h>
1.58 +#include <lemon/error.h>
1.59 +#include <lemon/xy.h>
1.60 +
1.61 +enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
1.62 +#define RANGE 3
1.63 +#define WIN_WIDTH 900
1.64 +#define WIN_HEIGHT 600
1.65 +
1.66 +
1.67 +#ifndef MAIN_PART
1.68 +extern std::string * property_strings;
1.69 +extern double * property_defaults;
1.70 +#endif //MAIN_PART
1.71 +
1.72 +using namespace lemon;
1.73 +
1.74 +typedef xy<double> Coordinates;
1.75 +typedef ListGraph Graph;
1.76 +typedef Graph::NodeMap<Coordinates> CoordinatesMap;
1.77 +typedef Graph::Node Node;
1.78 +typedef Graph::EdgeIt EdgeIt;
1.79 +typedef Graph::NodeIt NodeIt;
1.80 +
1.81 +#endif // ALL_INCLUDE_H
2.1 --- a/gui/graph_displayer_canvas.cc Wed Jun 01 23:30:13 2005 +0000
2.2 +++ b/gui/graph_displayer_canvas.cc Wed Jun 01 23:33:26 2005 +0000
2.3 @@ -1,321 +1,321 @@
2.4 -#include <graph_displayer_canvas.h>
2.5 -#include <math.h>
2.6 -
2.7 -GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
2.8 -{
2.9 - //set_center_scroll_region(true);
2.10 -
2.11 - //first edges are drawn, to hide joining with nodes later
2.12 -
2.13 - for (EdgeIt i(g); i!=INVALID; ++i)
2.14 - {
2.15 -
2.16 - //drawing green lines, coordinates are from cm
2.17 -
2.18 - Gnome::Canvas::Points coos;
2.19 - coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
2.20 - coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
2.21 -
2.22 - edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
2.23 - *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
2.24 - edgesmap[i]->property_width_pixels().set_value(10);
2.25 -
2.26 - //initializing edge-text as well, to empty string
2.27 -
2.28 - double x1, x2, y1, y2;
2.29 - edgesmap[i]->get_bounds(x1, y1, x2, y2);
2.30 -
2.31 - edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
2.32 - edgetextmap[i]->property_fill_color().set_value("black");
2.33 - }
2.34 -
2.35 - //afterwards nodes come to be drawn
2.36 -
2.37 - NodeIt i(g);
2.38 - int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
2.39 -
2.40 - for (; i!=INVALID; ++i)
2.41 - {
2.42 - //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
2.43 -
2.44 - if(cm[i].x>maxx)maxx=(int)cm[i].x;
2.45 - if(cm[i].y>maxy)maxy=(int)cm[i].y;
2.46 - if(cm[i].x<minx)minx=(int)cm[i].x;
2.47 - if(cm[i].y<miny)miny=(int)cm[i].y;
2.48 -
2.49 - //drawing bule nodes, with black line around them
2.50 -
2.51 - nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
2.52 - *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
2.53 - *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
2.54 - (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
2.55 - }
2.56 -
2.57 -/*
2.58 - //setting zoom to be able to see the whole graph on the canvas
2.59 -
2.60 - double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
2.61 - double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
2.62 -
2.63 - set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
2.64 - std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
2.65 - std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
2.66 - std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
2.67 -*/
2.68 - updateScrollRegion();
2.69 -}
2.70 -
2.71 -GraphDisplayerCanvas::~GraphDisplayerCanvas()
2.72 -{
2.73 -
2.74 - //writing out the end state of the graph
2.75 - //\todo all the maps has to be write out!
2.76 -
2.77 - Graph::NodeMap <int> id(g);
2.78 - Graph::NodeMap <double> xc(g);
2.79 - Graph::NodeMap <double> yc(g);
2.80 -
2.81 - int j=1;
2.82 -
2.83 - for (NodeIt i(g); i!=INVALID; ++i)
2.84 - {
2.85 - double x1,y1,x2,y2;
2.86 - nodesmap[i]->get_bounds(x1, y1, x2, y2);
2.87 -
2.88 - id[i]=j++;
2.89 - xc[i]=(x1+x2)/2;
2.90 - yc[i]=(y1+y2)/2;
2.91 - }
2.92 -
2.93 - GraphWriter<Graph> writer(std::cout,g);
2.94 -
2.95 - writer.writeNodeMap("id", id);
2.96 - writer.writeNodeMap("coordinates_x", xc);
2.97 - writer.writeNodeMap("coordinates_y", yc);
2.98 - writer.run();
2.99 -}
2.100 -
2.101 -int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
2.102 -{
2.103 - for (EdgeIt i(g); i!=INVALID; ++i)
2.104 - {
2.105 - int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
2.106 - edgesmap[i]->property_width_pixels().set_value(w);
2.107 - }
2.108 - return 0;
2.109 -};
2.110 -
2.111 -int GraphDisplayerCanvas::changeColor (std::string mapname)
2.112 -{
2.113 -
2.114 - //function maps the range of the maximum and
2.115 - //the minimum of the nodemap to the range of
2.116 - //green in RGB
2.117 -
2.118 - for (EdgeIt i(g); i!=INVALID; ++i)
2.119 - {
2.120 - double w=(*(mapstorage.edgemap_storage)[mapname])[i];
2.121 - double max=mapstorage.maxOfEdgeMap(mapname);
2.122 - double min=mapstorage.minOfEdgeMap(mapname);
2.123 -
2.124 - //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
2.125 - Gdk::Color color;
2.126 - if(max!=min)
2.127 - {
2.128 - color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
2.129 - }
2.130 - else
2.131 - {
2.132 - color.set_rgb_p (0, 100, 0);
2.133 - }
2.134 -
2.135 - edgesmap[i]->property_fill_color_gdk().set_value(color);
2.136 - }
2.137 - return 0;
2.138 -};
2.139 -
2.140 -int GraphDisplayerCanvas::changeText (std::string mapname)
2.141 -{
2.142 -
2.143 - //the number in the map will be written on the edge
2.144 - //EXCEPT when the name of the map is Text, because
2.145 - //in that case empty string will be written, because
2.146 - //that is the deleter map
2.147 - //\todo isn't it a bit woodcutter?
2.148 -
2.149 - for (EdgeIt i(g); i!=INVALID; ++i)
2.150 - {
2.151 - if(mapname!="Text")
2.152 - {
2.153 - double number=(*(mapstorage.edgemap_storage)[mapname])[i];
2.154 - int length=(int)(floor(log(number)/log(10)))+1;
2.155 - int maxpos=(int)(pow(10,length-1));
2.156 - int strl=length+1+RANGE;
2.157 - char * str=new char[strl];
2.158 - str[length]='.';
2.159 - str[strl]='\0';
2.160 -
2.161 - for(int j=0;j<strl;j++)
2.162 - {
2.163 - if(j!=length)
2.164 - {
2.165 - int digit=(int)(number/maxpos);
2.166 - str[j]=(digit+'0');
2.167 - number-=digit*maxpos;
2.168 - number*=10;
2.169 - }
2.170 - }
2.171 -
2.172 - edgetextmap[i]->property_text().set_value(str);
2.173 - }
2.174 - else
2.175 - {
2.176 - edgetextmap[i]->property_text().set_value("");
2.177 - }
2.178 - }
2.179 - return 0;
2.180 -};
2.181 -
2.182 -bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
2.183 -{
2.184 - switch(e->type)
2.185 - {
2.186 - case GDK_BUTTON_PRESS:
2.187 - //we mark the location of the event to be able to calculate parameters of dragging
2.188 - clicked_x=e->button.x;
2.189 - clicked_y=e->button.y;
2.190 - active_item=(get_item_at(e->button.x, e->button.y));
2.191 - isbutton=true;
2.192 - break;
2.193 - case GDK_BUTTON_RELEASE:
2.194 - isbutton=false;
2.195 - active_item=NULL;
2.196 - break;
2.197 - case GDK_MOTION_NOTIFY:
2.198 - //we only have to do sg. if the mouse button is pressed
2.199 - if(isbutton)
2.200 - {
2.201 - //new coordinates will be the old values,
2.202 - //because the item will be moved to the
2.203 - //new coordinate therefore the new movement
2.204 - //has to be calculated from here
2.205 -
2.206 - double dx=e->motion.x-clicked_x;
2.207 - double dy=e->motion.y-clicked_y;
2.208 - active_item->move(dx, dy);
2.209 - clicked_x=e->motion.x;
2.210 - clicked_y=e->motion.y;
2.211 -
2.212 - //all the edges connected to the moved point has to be redrawn
2.213 -
2.214 - EdgeIt e;
2.215 - g.firstOut(e,n);
2.216 - for(;e!=INVALID;g.nextOut(e))
2.217 - {
2.218 - Gnome::Canvas::Points coos;
2.219 - double x1, x2, y1, y2;
2.220 -
2.221 - nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
2.222 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.223 -
2.224 - nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
2.225 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.226 -
2.227 - edgesmap[e]->property_points().set_value(coos);
2.228 -
2.229 - edgesmap[e]->get_bounds(x1, y1, x2, y2);
2.230 -
2.231 - edgetextmap[e]->property_x().set_value((x1+x2)/2);
2.232 - edgetextmap[e]->property_y().set_value((y1+y2)/2);
2.233 - }
2.234 -
2.235 - g.firstIn(e,n);
2.236 - for(;e!=INVALID;g.nextIn(e))
2.237 - {
2.238 - Gnome::Canvas::Points coos;
2.239 - double x1, x2, y1, y2;
2.240 -
2.241 - nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
2.242 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.243 -
2.244 - nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
2.245 - coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.246 -
2.247 - edgesmap[e]->property_points().set_value(coos);
2.248 -
2.249 - edgesmap[e]->get_bounds(x1, y1, x2, y2);
2.250 -
2.251 - edgetextmap[e]->property_x().set_value((x1+x2)/2);
2.252 - edgetextmap[e]->property_y().set_value((y1+y2)/2);
2.253 - }
2.254 - }
2.255 - default: break;
2.256 - }
2.257 - return true;
2.258 -}
2.259 -
2.260 -bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
2.261 -{
2.262 - Gnome::Canvas::CanvasAA::on_expose_event(event);
2.263 - //usleep(10000);
2.264 - //rezoom();
2.265 - return true;
2.266 -}
2.267 -
2.268 -void GraphDisplayerCanvas::zoomIn()
2.269 -{
2.270 - set_pixels_per_unit(
2.271 - (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
2.272 -}
2.273 -
2.274 -void GraphDisplayerCanvas::zoomOut()
2.275 -{
2.276 - set_pixels_per_unit(
2.277 - (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
2.278 -}
2.279 -
2.280 -void GraphDisplayerCanvas::zoomFit()
2.281 -{
2.282 - // get the height and width of the canvas
2.283 - Gtk::Allocation a = get_allocation();
2.284 - int aw = a.get_width();
2.285 - int ah = a.get_height();
2.286 - // add some space
2.287 - aw -= 5; if (aw < 0) aw = 0;
2.288 - ah -= 5; if (ah < 0) ah = 0;
2.289 - //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
2.290 -
2.291 - // get the bounding box of the graph
2.292 - set_pixels_per_unit(1.0); // I don't really understand why this is necessary
2.293 - double wx1, wy1, wx2, wy2;
2.294 - double cx1, cy1, cx2, cy2;
2.295 - Gnome::Canvas::Item* pCanvasItem = root();
2.296 - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
2.297 - //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
2.298 - w2c(wx1, wy1, cx1, cy1);
2.299 - w2c(wx2, wy2, cx2, cy2);
2.300 - //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
2.301 - //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
2.302 -
2.303 - // fit the graph to the window
2.304 - double ppu1 = (double) aw / fabs(cx2 - cx1);
2.305 - double ppu2 = (double) ah / fabs(cy2 - cy1);
2.306 - //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
2.307 - (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
2.308 -}
2.309 -
2.310 -void GraphDisplayerCanvas::zoom100()
2.311 -{
2.312 - set_pixels_per_unit(1.0);
2.313 -}
2.314 -
2.315 -void GraphDisplayerCanvas::updateScrollRegion()
2.316 -{
2.317 - double wx1, wy1, wx2, wy2;
2.318 - int cx1, cy1, cx2, cy2;
2.319 - Gnome::Canvas::Item* pCanvasItem = root();
2.320 - pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
2.321 - w2c(wx1, wy1, cx1, cy1);
2.322 - w2c(wx2, wy2, cx2, cy2);
2.323 - set_scroll_region(cx1, cy1, cx2, cy2);
2.324 -}
2.325 +#include <graph_displayer_canvas.h>
2.326 +#include <math.h>
2.327 +
2.328 +GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL)
2.329 +{
2.330 + //set_center_scroll_region(true);
2.331 +
2.332 + //first edges are drawn, to hide joining with nodes later
2.333 +
2.334 + for (EdgeIt i(g); i!=INVALID; ++i)
2.335 + {
2.336 +
2.337 + //drawing green lines, coordinates are from cm
2.338 +
2.339 + Gnome::Canvas::Points coos;
2.340 + coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
2.341 + coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
2.342 +
2.343 + edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
2.344 + *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
2.345 + edgesmap[i]->property_width_pixels().set_value(10);
2.346 +
2.347 + //initializing edge-text as well, to empty string
2.348 +
2.349 + double x1, x2, y1, y2;
2.350 + edgesmap[i]->get_bounds(x1, y1, x2, y2);
2.351 +
2.352 + edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
2.353 + edgetextmap[i]->property_fill_color().set_value("black");
2.354 + }
2.355 +
2.356 + //afterwards nodes come to be drawn
2.357 +
2.358 + NodeIt i(g);
2.359 + int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
2.360 +
2.361 + for (; i!=INVALID; ++i)
2.362 + {
2.363 + //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
2.364 +
2.365 + if(cm[i].x>maxx)maxx=(int)cm[i].x;
2.366 + if(cm[i].y>maxy)maxy=(int)cm[i].y;
2.367 + if(cm[i].x<minx)minx=(int)cm[i].x;
2.368 + if(cm[i].y<miny)miny=(int)cm[i].y;
2.369 +
2.370 + //drawing bule nodes, with black line around them
2.371 +
2.372 + nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
2.373 + *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
2.374 + *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
2.375 + (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
2.376 + }
2.377 +
2.378 +/*
2.379 + //setting zoom to be able to see the whole graph on the canvas
2.380 +
2.381 + double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
2.382 + double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
2.383 +
2.384 + set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
2.385 + std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
2.386 + std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
2.387 + std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
2.388 +*/
2.389 + updateScrollRegion();
2.390 +}
2.391 +
2.392 +GraphDisplayerCanvas::~GraphDisplayerCanvas()
2.393 +{
2.394 +
2.395 + //writing out the end state of the graph
2.396 + //\todo all the maps has to be write out!
2.397 +
2.398 + Graph::NodeMap <int> id(g);
2.399 + Graph::NodeMap <double> xc(g);
2.400 + Graph::NodeMap <double> yc(g);
2.401 +
2.402 + int j=1;
2.403 +
2.404 + for (NodeIt i(g); i!=INVALID; ++i)
2.405 + {
2.406 + double x1,y1,x2,y2;
2.407 + nodesmap[i]->get_bounds(x1, y1, x2, y2);
2.408 +
2.409 + id[i]=j++;
2.410 + xc[i]=(x1+x2)/2;
2.411 + yc[i]=(y1+y2)/2;
2.412 + }
2.413 +
2.414 + GraphWriter<Graph> writer(std::cout,g);
2.415 +
2.416 + writer.writeNodeMap("id", id);
2.417 + writer.writeNodeMap("coordinates_x", xc);
2.418 + writer.writeNodeMap("coordinates_y", yc);
2.419 + writer.run();
2.420 +}
2.421 +
2.422 +int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
2.423 +{
2.424 + for (EdgeIt i(g); i!=INVALID; ++i)
2.425 + {
2.426 + int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
2.427 + edgesmap[i]->property_width_pixels().set_value(w);
2.428 + }
2.429 + return 0;
2.430 +};
2.431 +
2.432 +int GraphDisplayerCanvas::changeColor (std::string mapname)
2.433 +{
2.434 +
2.435 + //function maps the range of the maximum and
2.436 + //the minimum of the nodemap to the range of
2.437 + //green in RGB
2.438 +
2.439 + for (EdgeIt i(g); i!=INVALID; ++i)
2.440 + {
2.441 + double w=(*(mapstorage.edgemap_storage)[mapname])[i];
2.442 + double max=mapstorage.maxOfEdgeMap(mapname);
2.443 + double min=mapstorage.minOfEdgeMap(mapname);
2.444 +
2.445 + //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
2.446 + Gdk::Color color;
2.447 + if(max!=min)
2.448 + {
2.449 + color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
2.450 + }
2.451 + else
2.452 + {
2.453 + color.set_rgb_p (0, 100, 0);
2.454 + }
2.455 +
2.456 + edgesmap[i]->property_fill_color_gdk().set_value(color);
2.457 + }
2.458 + return 0;
2.459 +};
2.460 +
2.461 +int GraphDisplayerCanvas::changeText (std::string mapname)
2.462 +{
2.463 +
2.464 + //the number in the map will be written on the edge
2.465 + //EXCEPT when the name of the map is Text, because
2.466 + //in that case empty string will be written, because
2.467 + //that is the deleter map
2.468 + //\todo isn't it a bit woodcutter?
2.469 +
2.470 + for (EdgeIt i(g); i!=INVALID; ++i)
2.471 + {
2.472 + if(mapname!="Text")
2.473 + {
2.474 + double number=(*(mapstorage.edgemap_storage)[mapname])[i];
2.475 + int length=(int)(floor(log(number)/log(10)))+1;
2.476 + int maxpos=(int)(pow(10,length-1));
2.477 + int strl=length+1+RANGE;
2.478 + char * str=new char[strl];
2.479 + str[length]='.';
2.480 + str[strl]='\0';
2.481 +
2.482 + for(int j=0;j<strl;j++)
2.483 + {
2.484 + if(j!=length)
2.485 + {
2.486 + int digit=(int)(number/maxpos);
2.487 + str[j]=(digit+'0');
2.488 + number-=digit*maxpos;
2.489 + number*=10;
2.490 + }
2.491 + }
2.492 +
2.493 + edgetextmap[i]->property_text().set_value(str);
2.494 + }
2.495 + else
2.496 + {
2.497 + edgetextmap[i]->property_text().set_value("");
2.498 + }
2.499 + }
2.500 + return 0;
2.501 +};
2.502 +
2.503 +bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
2.504 +{
2.505 + switch(e->type)
2.506 + {
2.507 + case GDK_BUTTON_PRESS:
2.508 + //we mark the location of the event to be able to calculate parameters of dragging
2.509 + clicked_x=e->button.x;
2.510 + clicked_y=e->button.y;
2.511 + active_item=(get_item_at(e->button.x, e->button.y));
2.512 + isbutton=true;
2.513 + break;
2.514 + case GDK_BUTTON_RELEASE:
2.515 + isbutton=false;
2.516 + active_item=NULL;
2.517 + break;
2.518 + case GDK_MOTION_NOTIFY:
2.519 + //we only have to do sg. if the mouse button is pressed
2.520 + if(isbutton)
2.521 + {
2.522 + //new coordinates will be the old values,
2.523 + //because the item will be moved to the
2.524 + //new coordinate therefore the new movement
2.525 + //has to be calculated from here
2.526 +
2.527 + double dx=e->motion.x-clicked_x;
2.528 + double dy=e->motion.y-clicked_y;
2.529 + active_item->move(dx, dy);
2.530 + clicked_x=e->motion.x;
2.531 + clicked_y=e->motion.y;
2.532 +
2.533 + //all the edges connected to the moved point has to be redrawn
2.534 +
2.535 + EdgeIt e;
2.536 + g.firstOut(e,n);
2.537 + for(;e!=INVALID;g.nextOut(e))
2.538 + {
2.539 + Gnome::Canvas::Points coos;
2.540 + double x1, x2, y1, y2;
2.541 +
2.542 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
2.543 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.544 +
2.545 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
2.546 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.547 +
2.548 + edgesmap[e]->property_points().set_value(coos);
2.549 +
2.550 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
2.551 +
2.552 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
2.553 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
2.554 + }
2.555 +
2.556 + g.firstIn(e,n);
2.557 + for(;e!=INVALID;g.nextIn(e))
2.558 + {
2.559 + Gnome::Canvas::Points coos;
2.560 + double x1, x2, y1, y2;
2.561 +
2.562 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
2.563 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.564 +
2.565 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
2.566 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
2.567 +
2.568 + edgesmap[e]->property_points().set_value(coos);
2.569 +
2.570 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
2.571 +
2.572 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
2.573 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
2.574 + }
2.575 + }
2.576 + default: break;
2.577 + }
2.578 + return true;
2.579 +}
2.580 +
2.581 +bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
2.582 +{
2.583 + Gnome::Canvas::CanvasAA::on_expose_event(event);
2.584 + //usleep(10000);
2.585 + //rezoom();
2.586 + return true;
2.587 +}
2.588 +
2.589 +void GraphDisplayerCanvas::zoomIn()
2.590 +{
2.591 + set_pixels_per_unit(
2.592 + (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
2.593 +}
2.594 +
2.595 +void GraphDisplayerCanvas::zoomOut()
2.596 +{
2.597 + set_pixels_per_unit(
2.598 + (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
2.599 +}
2.600 +
2.601 +void GraphDisplayerCanvas::zoomFit()
2.602 +{
2.603 + // get the height and width of the canvas
2.604 + Gtk::Allocation a = get_allocation();
2.605 + int aw = a.get_width();
2.606 + int ah = a.get_height();
2.607 + // add some space
2.608 + aw -= 5; if (aw < 0) aw = 0;
2.609 + ah -= 5; if (ah < 0) ah = 0;
2.610 + //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
2.611 +
2.612 + // get the bounding box of the graph
2.613 + set_pixels_per_unit(1.0); // I don't really understand why this is necessary
2.614 + double wx1, wy1, wx2, wy2;
2.615 + double cx1, cy1, cx2, cy2;
2.616 + Gnome::Canvas::Item* pCanvasItem = root();
2.617 + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
2.618 + //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
2.619 + w2c(wx1, wy1, cx1, cy1);
2.620 + w2c(wx2, wy2, cx2, cy2);
2.621 + //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
2.622 + //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
2.623 +
2.624 + // fit the graph to the window
2.625 + double ppu1 = (double) aw / fabs(cx2 - cx1);
2.626 + double ppu2 = (double) ah / fabs(cy2 - cy1);
2.627 + //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
2.628 + (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
2.629 +}
2.630 +
2.631 +void GraphDisplayerCanvas::zoom100()
2.632 +{
2.633 + set_pixels_per_unit(1.0);
2.634 +}
2.635 +
2.636 +void GraphDisplayerCanvas::updateScrollRegion()
2.637 +{
2.638 + double wx1, wy1, wx2, wy2;
2.639 + int cx1, cy1, cx2, cy2;
2.640 + Gnome::Canvas::Item* pCanvasItem = root();
2.641 + pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
2.642 + w2c(wx1, wy1, cx1, cy1);
2.643 + w2c(wx2, wy2, cx2, cy2);
2.644 + set_scroll_region(cx1, cy1, cx2, cy2);
2.645 +}
3.1 --- a/gui/graph_displayer_canvas.h Wed Jun 01 23:30:13 2005 +0000
3.2 +++ b/gui/graph_displayer_canvas.h Wed Jun 01 23:33:26 2005 +0000
3.3 @@ -1,89 +1,89 @@
3.4 -// -*- C++ -*- //
3.5 -
3.6 -#ifndef GRAPH_DISPLAYER_CANVAS_H
3.7 -#define GRAPH_DISPLAYER_CANVAS_H
3.8 -
3.9 -#include <all_include.h>
3.10 -#include <mapstorage.h>
3.11 -#include <libgnomecanvasmm.h>
3.12 -#include <libgnomecanvasmm/polygon.h>
3.13 -
3.14 -///This class is the canvas, on which the graph can be drawn.
3.15 -class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
3.16 -{
3.17 - typedef Gnome::Canvas::CanvasAA Parent;
3.18 -
3.19 -public:
3.20 - GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
3.21 - virtual ~GraphDisplayerCanvas();
3.22 -
3.23 - ///Changes the linewidth attribute according to the given map.
3.24 - ///\param mapname is the name of the map which contains the new values
3.25 - int changeLineWidth (std::string mapname);
3.26 -
3.27 - ///Changes the linecolor attribute according to the given map.
3.28 - ///\param mapname is the name of the map which contains the new values
3.29 - int changeColor (std::string mapname);
3.30 -
3.31 - ///Changes the text of line attribute according to the given map.
3.32 - ///\param mapname is the name of the map which contains the new values
3.33 - int changeText (std::string mapname);
3.34 -
3.35 - ///Callback for 'ViewZoomIn' action.
3.36 - virtual void zoomIn();
3.37 - ///Callback for 'ViewZoomOut' action.
3.38 - virtual void zoomOut();
3.39 - ///Callback for 'ViewZoomFit' action.
3.40 - virtual void zoomFit();
3.41 - ///Callback for 'ViewZoom100' action.
3.42 - virtual void zoom100();
3.43 - ///Sets the scroll region of the convas to the bounding box of the graph.
3.44 - void updateScrollRegion();
3.45 -
3.46 -protected:
3.47 -
3.48 - //maximizing, minimizing, restoring window, etc.
3.49 - virtual bool on_expose_event(GdkEventExpose *);
3.50 -
3.51 -private:
3.52 -
3.53 - ///This function is responsible for the correct
3.54 - ///reaction of any action happened in the territory
3.55 - ///of the canvas
3.56 - bool event_handler(GdkEvent* e, Node n);
3.57 -
3.58 - ///The graph, on which we work
3.59 - Graph g;
3.60 -
3.61 - ///Map of nodes of graph
3.62 - Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
3.63 -
3.64 - ///Map of edges of graph
3.65 - Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
3.66 -
3.67 - ///Map of texts to write on edges
3.68 - Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
3.69 -
3.70 - ///Group of graphical elements of displayed_graph
3.71 - Gnome::Canvas::Group displayed_graph;
3.72 -
3.73 - ///Here we store the maps that can be displayed through properties.
3.74 - MapStorage mapstorage;
3.75 -
3.76 - ///Indicates whether the button of mouse is pressed or not
3.77 - bool isbutton;
3.78 -
3.79 - ///At this location was the mousebutton pressed.
3.80 - ///It helps to calculate the distance of dragging.
3.81 - double clicked_x, clicked_y;
3.82 -
3.83 - ///Remembers which Gnome::Canvas::Item was pressed.
3.84 - ///this variable is needed, because
3.85 - ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
3.86 - ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
3.87 - Gnome::Canvas::Item * active_item;
3.88 -
3.89 - static const int zoom_step = 5;
3.90 -};
3.91 -
3.92 -#endif //GRAPH_DISPLAYER_CANVAS_H
3.93 +// -*- C++ -*- //
3.94 +
3.95 +#ifndef GRAPH_DISPLAYER_CANVAS_H
3.96 +#define GRAPH_DISPLAYER_CANVAS_H
3.97 +
3.98 +#include <all_include.h>
3.99 +#include <mapstorage.h>
3.100 +#include <libgnomecanvasmm.h>
3.101 +#include <libgnomecanvasmm/polygon.h>
3.102 +
3.103 +///This class is the canvas, on which the graph can be drawn.
3.104 +class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
3.105 +{
3.106 + typedef Gnome::Canvas::CanvasAA Parent;
3.107 +
3.108 +public:
3.109 + GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
3.110 + virtual ~GraphDisplayerCanvas();
3.111 +
3.112 + ///Changes the linewidth attribute according to the given map.
3.113 + ///\param mapname is the name of the map which contains the new values
3.114 + int changeLineWidth (std::string mapname);
3.115 +
3.116 + ///Changes the linecolor attribute according to the given map.
3.117 + ///\param mapname is the name of the map which contains the new values
3.118 + int changeColor (std::string mapname);
3.119 +
3.120 + ///Changes the text of line attribute according to the given map.
3.121 + ///\param mapname is the name of the map which contains the new values
3.122 + int changeText (std::string mapname);
3.123 +
3.124 + ///Callback for 'ViewZoomIn' action.
3.125 + virtual void zoomIn();
3.126 + ///Callback for 'ViewZoomOut' action.
3.127 + virtual void zoomOut();
3.128 + ///Callback for 'ViewZoomFit' action.
3.129 + virtual void zoomFit();
3.130 + ///Callback for 'ViewZoom100' action.
3.131 + virtual void zoom100();
3.132 + ///Sets the scroll region of the convas to the bounding box of the graph.
3.133 + void updateScrollRegion();
3.134 +
3.135 +protected:
3.136 +
3.137 + //maximizing, minimizing, restoring window, etc.
3.138 + virtual bool on_expose_event(GdkEventExpose *);
3.139 +
3.140 +private:
3.141 +
3.142 + ///This function is responsible for the correct
3.143 + ///reaction of any action happened in the territory
3.144 + ///of the canvas
3.145 + bool event_handler(GdkEvent* e, Node n);
3.146 +
3.147 + ///The graph, on which we work
3.148 + Graph g;
3.149 +
3.150 + ///Map of nodes of graph
3.151 + Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
3.152 +
3.153 + ///Map of edges of graph
3.154 + Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
3.155 +
3.156 + ///Map of texts to write on edges
3.157 + Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
3.158 +
3.159 + ///Group of graphical elements of displayed_graph
3.160 + Gnome::Canvas::Group displayed_graph;
3.161 +
3.162 + ///Here we store the maps that can be displayed through properties.
3.163 + MapStorage mapstorage;
3.164 +
3.165 + ///Indicates whether the button of mouse is pressed or not
3.166 + bool isbutton;
3.167 +
3.168 + ///At this location was the mousebutton pressed.
3.169 + ///It helps to calculate the distance of dragging.
3.170 + double clicked_x, clicked_y;
3.171 +
3.172 + ///Remembers which Gnome::Canvas::Item was pressed.
3.173 + ///this variable is needed, because
3.174 + ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
3.175 + ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
3.176 + Gnome::Canvas::Item * active_item;
3.177 +
3.178 + static const int zoom_step = 5;
3.179 +};
3.180 +
3.181 +#endif //GRAPH_DISPLAYER_CANVAS_H
4.1 --- a/gui/main_win.cc Wed Jun 01 23:30:13 2005 +0000
4.2 +++ b/gui/main_win.cc Wed Jun 01 23:33:26 2005 +0000
4.3 @@ -1,133 +1,133 @@
4.4 -#include <main_win.h>
4.5 -
4.6 -MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
4.7 - MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
4.8 -{
4.9 - set_title (title);
4.10 - set_default_size(WIN_WIDTH,WIN_HEIGHT);
4.11 - add(vbox);
4.12 -
4.13 - ag=Gtk::ActionGroup::create();
4.14 -
4.15 - ag->add( Gtk::Action::create("FileMenu", "_File") );
4.16 - ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
4.17 - sigc::mem_fun(*this, &MainWin::newFile));
4.18 - ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
4.19 - sigc::mem_fun(*this, &MainWin::openFile));
4.20 - ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
4.21 - sigc::mem_fun(*this, &MainWin::saveFile));
4.22 - ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
4.23 - sigc::mem_fun(*this, &MainWin::saveFileAs));
4.24 - ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
4.25 - sigc::mem_fun(*this, &MainWin::quit));
4.26 -
4.27 - ag->add( Gtk::Action::create("ViewMenu", "_View") );
4.28 - ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
4.29 - sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
4.30 - ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
4.31 - sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
4.32 - ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
4.33 - sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
4.34 - ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
4.35 - sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
4.36 -
4.37 - ag->add( Gtk::Action::create("ShowMenu", "_Show") );
4.38 - ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
4.39 - sigc::mem_fun(*this, &MainWin::showMaps));
4.40 -
4.41 - uim=Gtk::UIManager::create();
4.42 - uim->insert_action_group(ag);
4.43 - add_accel_group(uim->get_accel_group());
4.44 -
4.45 - try
4.46 - {
4.47 -
4.48 - Glib::ustring ui_info =
4.49 - "<ui>"
4.50 - " <menubar name='MenuBar'>"
4.51 - " <menu action='FileMenu'>"
4.52 - " <menuitem action='FileNew'/>"
4.53 - " <menuitem action='FileOpen'/>"
4.54 - " <menuitem action='FileSave'/>"
4.55 - " <menuitem action='FileSaveAs'/>"
4.56 - " <menuitem action='FileQuit'/>"
4.57 - " </menu>"
4.58 - " <menu action='ViewMenu'>"
4.59 - " <menuitem action='ViewZoomIn' />"
4.60 - " <menuitem action='ViewZoomOut' />"
4.61 - " <menuitem action='ViewZoomFit' />"
4.62 - " <menuitem action='ViewZoom100' />"
4.63 - " </menu>"
4.64 - " <menu action='ShowMenu'>"
4.65 - " <menuitem action='ShowMaps'/>"
4.66 - " </menu>"
4.67 - " </menubar>"
4.68 - " <toolbar name='ToolBar'>"
4.69 - " <toolitem action='FileNew' />"
4.70 - " <toolitem action='FileOpen' />"
4.71 - " <toolitem action='FileSave' />"
4.72 - " <separator />"
4.73 - " <toolitem action='ViewZoomIn' />"
4.74 - " <toolitem action='ViewZoomOut' />"
4.75 - " <toolitem action='ViewZoomFit' />"
4.76 - " <toolitem action='ViewZoom100' />"
4.77 - " </toolbar>"
4.78 - "</ui>";
4.79 -
4.80 - uim->add_ui_from_string(ui_info);
4.81 -
4.82 - }
4.83 - catch(const Glib::Error& ex)
4.84 - {
4.85 - std::cerr << "building menus failed: " << ex.what();
4.86 - }
4.87 -
4.88 - Gtk::Widget* menubar = uim->get_widget("/MenuBar");
4.89 - if (menubar){
4.90 - vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
4.91 - }
4.92 -
4.93 - Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
4.94 - if (toolbar)
4.95 - {
4.96 - static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
4.97 - vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
4.98 - }
4.99 -
4.100 - Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
4.101 - pScrolledWindow->add(gd_canvas);
4.102 - vbox.pack_start(*pScrolledWindow);
4.103 - //vbox.pack_start(gd_canvas);
4.104 -
4.105 - show_all_children();
4.106 -}
4.107 -
4.108 -void MainWin::showMaps()
4.109 -{
4.110 - mapwin.show();
4.111 -}
4.112 -
4.113 -void MainWin::quit()
4.114 -{
4.115 - hide();
4.116 -}
4.117 -
4.118 -void MainWin::newFile()
4.119 -{
4.120 - std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
4.121 -}
4.122 -
4.123 -void MainWin::openFile()
4.124 -{
4.125 - std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
4.126 -}
4.127 -
4.128 -void MainWin::saveFile()
4.129 -{
4.130 - std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
4.131 -}
4.132 -
4.133 -void MainWin::saveFileAs()
4.134 -{
4.135 - std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
4.136 -}
4.137 +#include <main_win.h>
4.138 +
4.139 +MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
4.140 + MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
4.141 +{
4.142 + set_title (title);
4.143 + set_default_size(WIN_WIDTH,WIN_HEIGHT);
4.144 + add(vbox);
4.145 +
4.146 + ag=Gtk::ActionGroup::create();
4.147 +
4.148 + ag->add( Gtk::Action::create("FileMenu", "_File") );
4.149 + ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
4.150 + sigc::mem_fun(*this, &MainWin::newFile));
4.151 + ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
4.152 + sigc::mem_fun(*this, &MainWin::openFile));
4.153 + ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
4.154 + sigc::mem_fun(*this, &MainWin::saveFile));
4.155 + ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
4.156 + sigc::mem_fun(*this, &MainWin::saveFileAs));
4.157 + ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
4.158 + sigc::mem_fun(*this, &MainWin::quit));
4.159 +
4.160 + ag->add( Gtk::Action::create("ViewMenu", "_View") );
4.161 + ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
4.162 + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
4.163 + ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
4.164 + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
4.165 + ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
4.166 + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
4.167 + ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
4.168 + sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
4.169 +
4.170 + ag->add( Gtk::Action::create("ShowMenu", "_Show") );
4.171 + ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
4.172 + sigc::mem_fun(*this, &MainWin::showMaps));
4.173 +
4.174 + uim=Gtk::UIManager::create();
4.175 + uim->insert_action_group(ag);
4.176 + add_accel_group(uim->get_accel_group());
4.177 +
4.178 + try
4.179 + {
4.180 +
4.181 + Glib::ustring ui_info =
4.182 + "<ui>"
4.183 + " <menubar name='MenuBar'>"
4.184 + " <menu action='FileMenu'>"
4.185 + " <menuitem action='FileNew'/>"
4.186 + " <menuitem action='FileOpen'/>"
4.187 + " <menuitem action='FileSave'/>"
4.188 + " <menuitem action='FileSaveAs'/>"
4.189 + " <menuitem action='FileQuit'/>"
4.190 + " </menu>"
4.191 + " <menu action='ViewMenu'>"
4.192 + " <menuitem action='ViewZoomIn' />"
4.193 + " <menuitem action='ViewZoomOut' />"
4.194 + " <menuitem action='ViewZoomFit' />"
4.195 + " <menuitem action='ViewZoom100' />"
4.196 + " </menu>"
4.197 + " <menu action='ShowMenu'>"
4.198 + " <menuitem action='ShowMaps'/>"
4.199 + " </menu>"
4.200 + " </menubar>"
4.201 + " <toolbar name='ToolBar'>"
4.202 + " <toolitem action='FileNew' />"
4.203 + " <toolitem action='FileOpen' />"
4.204 + " <toolitem action='FileSave' />"
4.205 + " <separator />"
4.206 + " <toolitem action='ViewZoomIn' />"
4.207 + " <toolitem action='ViewZoomOut' />"
4.208 + " <toolitem action='ViewZoomFit' />"
4.209 + " <toolitem action='ViewZoom100' />"
4.210 + " </toolbar>"
4.211 + "</ui>";
4.212 +
4.213 + uim->add_ui_from_string(ui_info);
4.214 +
4.215 + }
4.216 + catch(const Glib::Error& ex)
4.217 + {
4.218 + std::cerr << "building menus failed: " << ex.what();
4.219 + }
4.220 +
4.221 + Gtk::Widget* menubar = uim->get_widget("/MenuBar");
4.222 + if (menubar){
4.223 + vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
4.224 + }
4.225 +
4.226 + Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
4.227 + if (toolbar)
4.228 + {
4.229 + static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
4.230 + vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
4.231 + }
4.232 +
4.233 + Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
4.234 + pScrolledWindow->add(gd_canvas);
4.235 + vbox.pack_start(*pScrolledWindow);
4.236 + //vbox.pack_start(gd_canvas);
4.237 +
4.238 + show_all_children();
4.239 +}
4.240 +
4.241 +void MainWin::showMaps()
4.242 +{
4.243 + mapwin.show();
4.244 +}
4.245 +
4.246 +void MainWin::quit()
4.247 +{
4.248 + hide();
4.249 +}
4.250 +
4.251 +void MainWin::newFile()
4.252 +{
4.253 + std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
4.254 +}
4.255 +
4.256 +void MainWin::openFile()
4.257 +{
4.258 + std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
4.259 +}
4.260 +
4.261 +void MainWin::saveFile()
4.262 +{
4.263 + std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
4.264 +}
4.265 +
4.266 +void MainWin::saveFileAs()
4.267 +{
4.268 + std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
4.269 +}
5.1 --- a/gui/main_win.h Wed Jun 01 23:30:13 2005 +0000
5.2 +++ b/gui/main_win.h Wed Jun 01 23:33:26 2005 +0000
5.3 @@ -1,54 +1,54 @@
5.4 -// -*- C++ -*- //
5.5 -
5.6 -#ifndef MAIN_WIN_H
5.7 -#define MAIN_WIN_H
5.8 -
5.9 -#include <all_include.h>
5.10 -#include <mapstorage.h>
5.11 -#include <map_win.h>
5.12 -#include <libgnomecanvasmm.h>
5.13 -#include <libgnomecanvasmm/polygon.h>
5.14 -
5.15 -///This class is the main window of GUI.
5.16 -///It has menus, but the main part of it is the canvas.
5.17 -class MainWin : public Gtk::Window
5.18 -{
5.19 -public:
5.20 - ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
5.21 - ///\param title is the title of the window
5.22 - ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
5.23 - ///\param cm stores the coordinates of the nodes of the graph
5.24 - ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
5.25 - MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
5.26 -
5.27 -protected:
5.28 - ///Window of map-showing setup. Its type is \ref MapWin
5.29 - MapWin mapwin;
5.30 -
5.31 - ///The graph will be drawn on this \ref GraphDisplayerCanvas
5.32 - GraphDisplayerCanvas gd_canvas;
5.33 -
5.34 - ///ActionGroup for menu
5.35 - Glib::RefPtr<Gtk::ActionGroup> ag;
5.36 -
5.37 - ///UIManager for menu
5.38 - Glib::RefPtr<Gtk::UIManager> uim;
5.39 -
5.40 - ///Container
5.41 - Gtk::VBox vbox;
5.42 -
5.43 - ///This function makes map-setup window popped up.
5.44 - virtual void showMaps();
5.45 - ///Callback for 'FileNew' action.
5.46 - virtual void newFile();
5.47 - ///Callback for 'FileOpen' action.
5.48 - virtual void openFile();
5.49 - ///Callback for 'FileSave' action.
5.50 - virtual void saveFile();
5.51 - ///Callback for 'FileSaveAs' action.
5.52 - virtual void saveFileAs();
5.53 - ///Callback for 'Quit' action.
5.54 - virtual void quit();
5.55 -};
5.56 -
5.57 -#endif //MAIN_WIN_H
5.58 +// -*- C++ -*- //
5.59 +
5.60 +#ifndef MAIN_WIN_H
5.61 +#define MAIN_WIN_H
5.62 +
5.63 +#include <all_include.h>
5.64 +#include <mapstorage.h>
5.65 +#include <map_win.h>
5.66 +#include <libgnomecanvasmm.h>
5.67 +#include <libgnomecanvasmm/polygon.h>
5.68 +
5.69 +///This class is the main window of GUI.
5.70 +///It has menus, but the main part of it is the canvas.
5.71 +class MainWin : public Gtk::Window
5.72 +{
5.73 +public:
5.74 + ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
5.75 + ///\param title is the title of the window
5.76 + ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
5.77 + ///\param cm stores the coordinates of the nodes of the graph
5.78 + ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
5.79 + MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
5.80 +
5.81 +protected:
5.82 + ///Window of map-showing setup. Its type is \ref MapWin
5.83 + MapWin mapwin;
5.84 +
5.85 + ///The graph will be drawn on this \ref GraphDisplayerCanvas
5.86 + GraphDisplayerCanvas gd_canvas;
5.87 +
5.88 + ///ActionGroup for menu
5.89 + Glib::RefPtr<Gtk::ActionGroup> ag;
5.90 +
5.91 + ///UIManager for menu
5.92 + Glib::RefPtr<Gtk::UIManager> uim;
5.93 +
5.94 + ///Container
5.95 + Gtk::VBox vbox;
5.96 +
5.97 + ///This function makes map-setup window popped up.
5.98 + virtual void showMaps();
5.99 + ///Callback for 'FileNew' action.
5.100 + virtual void newFile();
5.101 + ///Callback for 'FileOpen' action.
5.102 + virtual void openFile();
5.103 + ///Callback for 'FileSave' action.
5.104 + virtual void saveFile();
5.105 + ///Callback for 'FileSaveAs' action.
5.106 + virtual void saveFileAs();
5.107 + ///Callback for 'Quit' action.
5.108 + virtual void quit();
5.109 +};
5.110 +
5.111 +#endif //MAIN_WIN_H
6.1 --- a/gui/map_win.cc Wed Jun 01 23:30:13 2005 +0000
6.2 +++ b/gui/map_win.cc Wed Jun 01 23:33:26 2005 +0000
6.3 @@ -1,122 +1,122 @@
6.4 -#include <map_win.h>
6.5 -#include <set>
6.6 -
6.7 -MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
6.8 -{
6.9 -
6.10 - //most nem kommentezem fel, mert ugyis valtozik
6.11 -
6.12 - set_title(title);
6.13 - set_default_size(400, 200);
6.14 -
6.15 - rb_array=new Gtk::RadioButton * [PROPERTY_NUM];
6.16 - vbox_r1=new Gtk::VBox[PROPERTY_NUM];
6.17 - vbox_r2=new Gtk::VBox[PROPERTY_NUM];
6.18 - radios=new Gtk::HBox[PROPERTY_NUM];
6.19 - for(int i=0;i<PROPERTY_NUM;i++)
6.20 - {
6.21 - rb_array[i]=new Gtk::RadioButton[ms.numOfEdgeMaps()+1];
6.22 -
6.23 - Gtk::RadioButton::Group group;
6.24 -
6.25 - std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
6.26 - std::set<int> props;
6.27 -
6.28 - int actprop;
6.29 - for(int j=0;j<ms.numOfEdgeMaps();j++)
6.30 - {
6.31 -
6.32 - if(emsi->second==&(ms.default_edgemaps[i]))
6.33 - {
6.34 - actprop=j;
6.35 - }
6.36 - for(int k=0;k<PROPERTY_NUM;k++)
6.37 - {
6.38 - if(emsi->second==&(ms.default_edgemaps[k]))
6.39 - {
6.40 - props.insert(j);
6.41 - }
6.42 - }
6.43 - emsi++;
6.44 - }
6.45 -
6.46 - rb_array[i][0].set_group(group);
6.47 - rb_array[i][0].set_label("Default");
6.48 - rb_array[i][0].signal_clicked().connect( sigc::bind( sigc::bind( sigc::mem_fun(*this, &MapWin::radio_click), 0), i) );
6.49 - vbox_r1[i].pack_start(rb_array[i][0]);
6.50 -
6.51 -
6.52 - emsi=ms.beginOfEdgeMaps();
6.53 - int actpos=1;
6.54 - for(int j=0;j<ms.numOfEdgeMaps();j++)
6.55 - {
6.56 - if( ( props.find(j) )==( props.end() ) )
6.57 - {
6.58 - rb_array[i][actpos].set_group(group);
6.59 - rb_array[i][actpos].set_label(emsi->first);
6.60 - rb_array[i][actpos].signal_clicked().connect
6.61 - (
6.62 - sigc::bind(
6.63 - sigc::bind(
6.64 - sigc::mem_fun(*this, &MapWin::radio_click),
6.65 - actpos
6.66 - ),
6.67 - i
6.68 - )
6.69 - );
6.70 -
6.71 - if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
6.72 - {
6.73 - vbox_r1[i].pack_start(rb_array[i][actpos]);
6.74 - }
6.75 - else
6.76 - {
6.77 - vbox_r2[i].pack_start(rb_array[i][actpos]);
6.78 - }
6.79 - actpos++;
6.80 - }
6.81 - emsi++;
6.82 - }
6.83 - radios[i].pack_start(vbox_r1[i]);
6.84 - radios[i].pack_start(vbox_r2[i]);
6.85 - notebook.append_page(radios[i], property_strings[i]);
6.86 - }
6.87 -
6.88 - add(vbox_b);
6.89 - vbox_b.pack_start(notebook);
6.90 -
6.91 - show_all_children();
6.92 -
6.93 -}
6.94 -
6.95 -void MapWin::radio_click(int prop, int actpos)
6.96 -{
6.97 -
6.98 - //most nem kommentezem fel, mert ugyis valtozik
6.99 -
6.100 - if(rb_array[prop][actpos].get_active())
6.101 - {
6.102 -
6.103 - std::string mapname=rb_array[prop][actpos].get_label();
6.104 -
6.105 - if(mapname=="Default")
6.106 - {
6.107 - mapname=property_strings[prop];
6.108 - }
6.109 -
6.110 - switch(prop)
6.111 - {
6.112 - case WIDTH:
6.113 - gdc.changeLineWidth(mapname);
6.114 - break;
6.115 - case COLOR:
6.116 - gdc.changeColor(mapname);
6.117 - break;
6.118 - case TEXT:
6.119 - gdc.changeText(mapname);
6.120 - break;
6.121 - default:
6.122 - std::cout<<"Error\n";
6.123 - }
6.124 - }
6.125 -};
6.126 +#include <map_win.h>
6.127 +#include <set>
6.128 +
6.129 +MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
6.130 +{
6.131 +
6.132 + //most nem kommentezem fel, mert ugyis valtozik
6.133 +
6.134 + set_title(title);
6.135 + set_default_size(400, 200);
6.136 +
6.137 + rb_array=new Gtk::RadioButton * [PROPERTY_NUM];
6.138 + vbox_r1=new Gtk::VBox[PROPERTY_NUM];
6.139 + vbox_r2=new Gtk::VBox[PROPERTY_NUM];
6.140 + radios=new Gtk::HBox[PROPERTY_NUM];
6.141 + for(int i=0;i<PROPERTY_NUM;i++)
6.142 + {
6.143 + rb_array[i]=new Gtk::RadioButton[ms.numOfEdgeMaps()+1];
6.144 +
6.145 + Gtk::RadioButton::Group group;
6.146 +
6.147 + std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
6.148 + std::set<int> props;
6.149 +
6.150 + int actprop;
6.151 + for(int j=0;j<ms.numOfEdgeMaps();j++)
6.152 + {
6.153 +
6.154 + if(emsi->second==&(ms.default_edgemaps[i]))
6.155 + {
6.156 + actprop=j;
6.157 + }
6.158 + for(int k=0;k<PROPERTY_NUM;k++)
6.159 + {
6.160 + if(emsi->second==&(ms.default_edgemaps[k]))
6.161 + {
6.162 + props.insert(j);
6.163 + }
6.164 + }
6.165 + emsi++;
6.166 + }
6.167 +
6.168 + rb_array[i][0].set_group(group);
6.169 + rb_array[i][0].set_label("Default");
6.170 + rb_array[i][0].signal_clicked().connect( sigc::bind( sigc::bind( sigc::mem_fun(*this, &MapWin::radio_click), 0), i) );
6.171 + vbox_r1[i].pack_start(rb_array[i][0]);
6.172 +
6.173 +
6.174 + emsi=ms.beginOfEdgeMaps();
6.175 + int actpos=1;
6.176 + for(int j=0;j<ms.numOfEdgeMaps();j++)
6.177 + {
6.178 + if( ( props.find(j) )==( props.end() ) )
6.179 + {
6.180 + rb_array[i][actpos].set_group(group);
6.181 + rb_array[i][actpos].set_label(emsi->first);
6.182 + rb_array[i][actpos].signal_clicked().connect
6.183 + (
6.184 + sigc::bind(
6.185 + sigc::bind(
6.186 + sigc::mem_fun(*this, &MapWin::radio_click),
6.187 + actpos
6.188 + ),
6.189 + i
6.190 + )
6.191 + );
6.192 +
6.193 + if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
6.194 + {
6.195 + vbox_r1[i].pack_start(rb_array[i][actpos]);
6.196 + }
6.197 + else
6.198 + {
6.199 + vbox_r2[i].pack_start(rb_array[i][actpos]);
6.200 + }
6.201 + actpos++;
6.202 + }
6.203 + emsi++;
6.204 + }
6.205 + radios[i].pack_start(vbox_r1[i]);
6.206 + radios[i].pack_start(vbox_r2[i]);
6.207 + notebook.append_page(radios[i], property_strings[i]);
6.208 + }
6.209 +
6.210 + add(vbox_b);
6.211 + vbox_b.pack_start(notebook);
6.212 +
6.213 + show_all_children();
6.214 +
6.215 +}
6.216 +
6.217 +void MapWin::radio_click(int prop, int actpos)
6.218 +{
6.219 +
6.220 + //most nem kommentezem fel, mert ugyis valtozik
6.221 +
6.222 + if(rb_array[prop][actpos].get_active())
6.223 + {
6.224 +
6.225 + std::string mapname=rb_array[prop][actpos].get_label();
6.226 +
6.227 + if(mapname=="Default")
6.228 + {
6.229 + mapname=property_strings[prop];
6.230 + }
6.231 +
6.232 + switch(prop)
6.233 + {
6.234 + case WIDTH:
6.235 + gdc.changeLineWidth(mapname);
6.236 + break;
6.237 + case COLOR:
6.238 + gdc.changeColor(mapname);
6.239 + break;
6.240 + case TEXT:
6.241 + gdc.changeText(mapname);
6.242 + break;
6.243 + default:
6.244 + std::cout<<"Error\n";
6.245 + }
6.246 + }
6.247 +};
7.1 --- a/gui/map_win.h Wed Jun 01 23:30:13 2005 +0000
7.2 +++ b/gui/map_win.h Wed Jun 01 23:33:26 2005 +0000
7.3 @@ -1,49 +1,49 @@
7.4 -// -*- C++ -*- //
7.5 -
7.6 -#ifndef MAP_WIN_H
7.7 -#define MAP_WIN_H
7.8 -
7.9 -#include <all_include.h>
7.10 -#include <mapstorage.h>
7.11 -#include <graph_displayer_canvas.h>
7.12 -#include <libgnomecanvasmm.h>
7.13 -#include <libgnomecanvasmm/polygon.h>
7.14 -
7.15 -///This class is responsible for creating a window,
7.16 -///on which the visualization attributes can be
7.17 -///assigned to maps.
7.18 -class MapWin : public Gtk::Window
7.19 -{
7.20 -protected:
7.21 - ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
7.22 - ///It has to be known for this class, because
7.23 - ///when a map assigned to a certain attribute
7.24 - ///a function of the \ref GraphDisplayerCanvas will be called.
7.25 - GraphDisplayerCanvas & gdc;
7.26 -
7.27 - ///The \ref MapStorage in which the visualizable maps are stored
7.28 - MapStorage & ms;
7.29 -
7.30 -
7.31 - Gtk::HBox * radios;
7.32 - Gtk::RadioButton ** rb_array;
7.33 -
7.34 - Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
7.35 -
7.36 - ///The notebook has different pages for each attribute.
7.37 - Gtk::Notebook notebook;
7.38 -
7.39 - Gtk::Label * labels;
7.40 -
7.41 -public:
7.42 - ///Constructor of MapWin creates the widgets shown in MapWin.
7.43 - MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
7.44 -
7.45 - ///If a radiobutton is clicked, this function determines
7.46 - ///which button was that and after that calls the
7.47 - ///appropriate function of the \ref GraphDisplayerCanvas
7.48 - ///to change the visible values of that attribute.
7.49 - virtual void radio_click(int, int);
7.50 -};
7.51 -
7.52 -#endif //MAP_WIN_H
7.53 +// -*- C++ -*- //
7.54 +
7.55 +#ifndef MAP_WIN_H
7.56 +#define MAP_WIN_H
7.57 +
7.58 +#include <all_include.h>
7.59 +#include <mapstorage.h>
7.60 +#include <graph_displayer_canvas.h>
7.61 +#include <libgnomecanvasmm.h>
7.62 +#include <libgnomecanvasmm/polygon.h>
7.63 +
7.64 +///This class is responsible for creating a window,
7.65 +///on which the visualization attributes can be
7.66 +///assigned to maps.
7.67 +class MapWin : public Gtk::Window
7.68 +{
7.69 +protected:
7.70 + ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
7.71 + ///It has to be known for this class, because
7.72 + ///when a map assigned to a certain attribute
7.73 + ///a function of the \ref GraphDisplayerCanvas will be called.
7.74 + GraphDisplayerCanvas & gdc;
7.75 +
7.76 + ///The \ref MapStorage in which the visualizable maps are stored
7.77 + MapStorage & ms;
7.78 +
7.79 +
7.80 + Gtk::HBox * radios;
7.81 + Gtk::RadioButton ** rb_array;
7.82 +
7.83 + Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
7.84 +
7.85 + ///The notebook has different pages for each attribute.
7.86 + Gtk::Notebook notebook;
7.87 +
7.88 + Gtk::Label * labels;
7.89 +
7.90 +public:
7.91 + ///Constructor of MapWin creates the widgets shown in MapWin.
7.92 + MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
7.93 +
7.94 + ///If a radiobutton is clicked, this function determines
7.95 + ///which button was that and after that calls the
7.96 + ///appropriate function of the \ref GraphDisplayerCanvas
7.97 + ///to change the visible values of that attribute.
7.98 + virtual void radio_click(int, int);
7.99 +};
7.100 +
7.101 +#endif //MAP_WIN_H
8.1 --- a/gui/mapstorage.cc Wed Jun 01 23:30:13 2005 +0000
8.2 +++ b/gui/mapstorage.cc Wed Jun 01 23:33:26 2005 +0000
8.3 @@ -1,88 +1,88 @@
8.4 -#include <mapstorage.h>
8.5 -
8.6 -MapStorage::MapStorage(Graph & graph):g(graph)
8.7 -{
8.8 - for(int i=0;i<PROPERTY_NUM;i++)
8.9 - {
8.10 - Graph::EdgeMap<double> emd(g);
8.11 - default_edgemaps.push_back(emd);
8.12 - Graph::NodeMap<double> nmd(g);
8.13 - default_nodemaps.push_back(nmd);
8.14 - }
8.15 - for(int i=0;i<PROPERTY_NUM;i++)
8.16 - {
8.17 - for (EdgeIt j(g); j!=INVALID; ++j)
8.18 - {
8.19 - (default_edgemaps[i])[j]=property_defaults[i];
8.20 - }
8.21 - addEdgeMap(property_strings[i],&(default_edgemaps[i]));
8.22 - }
8.23 -
8.24 -};
8.25 -
8.26 -int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
8.27 -{
8.28 - nodemap_storage[name]=nodemap;
8.29 - return 0;
8.30 -}
8.31 -
8.32 -int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
8.33 -{
8.34 - edgemap_storage[name]=edgemap;
8.35 - return 0;
8.36 -}
8.37 -
8.38 -double MapStorage::maxOfNodeMap(const std::string & name)
8.39 -{
8.40 - double max=0;
8.41 - for (NodeIt j(g); j!=INVALID; ++j)
8.42 - {
8.43 - if( (*nodemap_storage[name])[j]>max )
8.44 - {
8.45 - max=(*nodemap_storage[name])[j];
8.46 - }
8.47 - }
8.48 - return max;
8.49 -}
8.50 -
8.51 -double MapStorage::maxOfEdgeMap(const std::string & name)
8.52 -{
8.53 - double max=0;
8.54 - for (EdgeIt j(g); j!=INVALID; ++j)
8.55 - {
8.56 - if( (*edgemap_storage[name])[j]>max )
8.57 - {
8.58 - max=(*edgemap_storage[name])[j];
8.59 - }
8.60 - }
8.61 - return max;
8.62 -}
8.63 -
8.64 -double MapStorage::minOfNodeMap(const std::string & name)
8.65 -{
8.66 - NodeIt j(g);
8.67 - double min=(*nodemap_storage[name])[j];
8.68 - for (; j!=INVALID; ++j)
8.69 - {
8.70 - if( (*nodemap_storage[name])[j]<min )
8.71 - {
8.72 - min=(*nodemap_storage[name])[j];
8.73 - }
8.74 - }
8.75 - return min;
8.76 -}
8.77 -
8.78 -double MapStorage::minOfEdgeMap(const std::string & name)
8.79 -{
8.80 - EdgeIt j(g);
8.81 - double min=(*edgemap_storage[name])[j];
8.82 - for (EdgeIt j(g); j!=INVALID; ++j)
8.83 - {
8.84 - if( (*edgemap_storage[name])[j]<min )
8.85 - {
8.86 - min=(*edgemap_storage[name])[j];
8.87 - }
8.88 - }
8.89 - return min;
8.90 -}
8.91 -
8.92 +#include <mapstorage.h>
8.93 +
8.94 +MapStorage::MapStorage(Graph & graph):g(graph)
8.95 +{
8.96 + for(int i=0;i<PROPERTY_NUM;i++)
8.97 + {
8.98 + Graph::EdgeMap<double> emd(g);
8.99 + default_edgemaps.push_back(emd);
8.100 + Graph::NodeMap<double> nmd(g);
8.101 + default_nodemaps.push_back(nmd);
8.102 + }
8.103 + for(int i=0;i<PROPERTY_NUM;i++)
8.104 + {
8.105 + for (EdgeIt j(g); j!=INVALID; ++j)
8.106 + {
8.107 + (default_edgemaps[i])[j]=property_defaults[i];
8.108 + }
8.109 + addEdgeMap(property_strings[i],&(default_edgemaps[i]));
8.110 + }
8.111 +
8.112 +};
8.113 +
8.114 +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
8.115 +{
8.116 + nodemap_storage[name]=nodemap;
8.117 + return 0;
8.118 +}
8.119 +
8.120 +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
8.121 +{
8.122 + edgemap_storage[name]=edgemap;
8.123 + return 0;
8.124 +}
8.125 +
8.126 +double MapStorage::maxOfNodeMap(const std::string & name)
8.127 +{
8.128 + double max=0;
8.129 + for (NodeIt j(g); j!=INVALID; ++j)
8.130 + {
8.131 + if( (*nodemap_storage[name])[j]>max )
8.132 + {
8.133 + max=(*nodemap_storage[name])[j];
8.134 + }
8.135 + }
8.136 + return max;
8.137 +}
8.138 +
8.139 +double MapStorage::maxOfEdgeMap(const std::string & name)
8.140 +{
8.141 + double max=0;
8.142 + for (EdgeIt j(g); j!=INVALID; ++j)
8.143 + {
8.144 + if( (*edgemap_storage[name])[j]>max )
8.145 + {
8.146 + max=(*edgemap_storage[name])[j];
8.147 + }
8.148 + }
8.149 + return max;
8.150 +}
8.151 +
8.152 +double MapStorage::minOfNodeMap(const std::string & name)
8.153 +{
8.154 + NodeIt j(g);
8.155 + double min=(*nodemap_storage[name])[j];
8.156 + for (; j!=INVALID; ++j)
8.157 + {
8.158 + if( (*nodemap_storage[name])[j]<min )
8.159 + {
8.160 + min=(*nodemap_storage[name])[j];
8.161 + }
8.162 + }
8.163 + return min;
8.164 +}
8.165 +
8.166 +double MapStorage::minOfEdgeMap(const std::string & name)
8.167 +{
8.168 + EdgeIt j(g);
8.169 + double min=(*edgemap_storage[name])[j];
8.170 + for (EdgeIt j(g); j!=INVALID; ++j)
8.171 + {
8.172 + if( (*edgemap_storage[name])[j]<min )
8.173 + {
8.174 + min=(*edgemap_storage[name])[j];
8.175 + }
8.176 + }
8.177 + return min;
8.178 +}
8.179 +
9.1 --- a/gui/mapstorage.h Wed Jun 01 23:30:13 2005 +0000
9.2 +++ b/gui/mapstorage.h Wed Jun 01 23:33:26 2005 +0000
9.3 @@ -1,85 +1,85 @@
9.4 -// -*- C++ -*- //
9.5 -
9.6 -#ifndef MAPSTORAGE_H
9.7 -#define MAPSTORAGE_H
9.8 -
9.9 -#include <all_include.h>
9.10 -
9.11 -///Class MapStorage is responsible for storing
9.12 -///NodeMaps and EdgeMaps that can be shown later
9.13 -///on GUI. Therefore maps can be added to it,
9.14 -///and datas over the added maps can be queried.
9.15 -///The maps will be stored in an std::map,
9.16 -///referenced with their names. Unfortunately at
9.17 -///the moment it works only with double type maps
9.18 -///
9.19 -///\todo too many things are public!!
9.20 -class MapStorage
9.21 -{
9.22 -public:
9.23 -
9.24 - Graph g;
9.25 -
9.26 - ///Stores double type NodeMaps
9.27 - std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
9.28 -
9.29 - ///Stores double type EdgeMaps
9.30 - std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
9.31 -
9.32 - //Stores the default values for the different visualization node attributes
9.33 - std::vector<Graph::NodeMap<double> > default_nodemaps;
9.34 -
9.35 - //Stores the default values for the different visualization edge attributes
9.36 - std::vector<Graph::EdgeMap<double> > default_edgemaps;
9.37 -
9.38 -public:
9.39 - ///Constructor of MapStorage. Expects the Graph of
9.40 - ///which maps will be stored in it.
9.41 - ///Its all activity is initializing default values
9.42 - ///for different visualization attributes
9.43 - ///
9.44 - ///\param graph is the graph for which the maps are stored in this object.
9.45 - MapStorage(Graph &);
9.46 -
9.47 - ///Adds given map to storage. A name and the map itself has to be provided.
9.48 - ///\param name is the name of map
9.49 - ///\nodemap is the pointer of the given nodemap
9.50 - ///\todo map should be given by reference!
9.51 - int addNodeMap(const std::string &,Graph::NodeMap<double> *);
9.52 -
9.53 - ///Adds given map to storage. A name and the map itself has to be provided.
9.54 - ///\param name is the name of map
9.55 - ///\edgemap is the pointer of the given edgemap
9.56 - ///\todo map should be given by reference!
9.57 - int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
9.58 -
9.59 - ///Returns how much nodemaps is stored in \ref MapStorage
9.60 - int numOfNodeMaps() {return nodemap_storage.size();};
9.61 -
9.62 - ///Returns how much edgemaps is stored in \ref MapStorage
9.63 - int numOfEdgeMaps() {return edgemap_storage.size();};
9.64 -
9.65 - ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
9.66 - ///\param name is the name of map of which maximum is searched
9.67 - double maxOfNodeMap(const std::string &);
9.68 -
9.69 - ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
9.70 - ///\param name is the name of map of which maximum is searched
9.71 - double maxOfEdgeMap(const std::string &);
9.72 -
9.73 - ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
9.74 - ///\param name is the name of map of which minimum is searched
9.75 - double minOfNodeMap(const std::string &);
9.76 -
9.77 - ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
9.78 - ///\param name is the name of map of which minimum is searched
9.79 - double minOfEdgeMap(const std::string &);
9.80 -
9.81 - ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
9.82 - std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
9.83 -
9.84 - ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
9.85 - std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
9.86 -};
9.87 -
9.88 -#endif //MAPSTORAGE_H
9.89 +// -*- C++ -*- //
9.90 +
9.91 +#ifndef MAPSTORAGE_H
9.92 +#define MAPSTORAGE_H
9.93 +
9.94 +#include <all_include.h>
9.95 +
9.96 +///Class MapStorage is responsible for storing
9.97 +///NodeMaps and EdgeMaps that can be shown later
9.98 +///on GUI. Therefore maps can be added to it,
9.99 +///and datas over the added maps can be queried.
9.100 +///The maps will be stored in an std::map,
9.101 +///referenced with their names. Unfortunately at
9.102 +///the moment it works only with double type maps
9.103 +///
9.104 +///\todo too many things are public!!
9.105 +class MapStorage
9.106 +{
9.107 +public:
9.108 +
9.109 + Graph g;
9.110 +
9.111 + ///Stores double type NodeMaps
9.112 + std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
9.113 +
9.114 + ///Stores double type EdgeMaps
9.115 + std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
9.116 +
9.117 + //Stores the default values for the different visualization node attributes
9.118 + std::vector<Graph::NodeMap<double> > default_nodemaps;
9.119 +
9.120 + //Stores the default values for the different visualization edge attributes
9.121 + std::vector<Graph::EdgeMap<double> > default_edgemaps;
9.122 +
9.123 +public:
9.124 + ///Constructor of MapStorage. Expects the Graph of
9.125 + ///which maps will be stored in it.
9.126 + ///Its all activity is initializing default values
9.127 + ///for different visualization attributes
9.128 + ///
9.129 + ///\param graph is the graph for which the maps are stored in this object.
9.130 + MapStorage(Graph &);
9.131 +
9.132 + ///Adds given map to storage. A name and the map itself has to be provided.
9.133 + ///\param name is the name of map
9.134 + ///\nodemap is the pointer of the given nodemap
9.135 + ///\todo map should be given by reference!
9.136 + int addNodeMap(const std::string &,Graph::NodeMap<double> *);
9.137 +
9.138 + ///Adds given map to storage. A name and the map itself has to be provided.
9.139 + ///\param name is the name of map
9.140 + ///\edgemap is the pointer of the given edgemap
9.141 + ///\todo map should be given by reference!
9.142 + int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
9.143 +
9.144 + ///Returns how much nodemaps is stored in \ref MapStorage
9.145 + int numOfNodeMaps() {return nodemap_storage.size();};
9.146 +
9.147 + ///Returns how much edgemaps is stored in \ref MapStorage
9.148 + int numOfEdgeMaps() {return edgemap_storage.size();};
9.149 +
9.150 + ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
9.151 + ///\param name is the name of map of which maximum is searched
9.152 + double maxOfNodeMap(const std::string &);
9.153 +
9.154 + ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
9.155 + ///\param name is the name of map of which maximum is searched
9.156 + double maxOfEdgeMap(const std::string &);
9.157 +
9.158 + ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
9.159 + ///\param name is the name of map of which minimum is searched
9.160 + double minOfNodeMap(const std::string &);
9.161 +
9.162 + ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
9.163 + ///\param name is the name of map of which minimum is searched
9.164 + double minOfEdgeMap(const std::string &);
9.165 +
9.166 + ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
9.167 + std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
9.168 +
9.169 + ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
9.170 + std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
9.171 +};
9.172 +
9.173 +#endif //MAPSTORAGE_H