[Lemon-commits] [lemon_svn] ladanyi: r1918 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:48:47 CET 2006
Author: ladanyi
Date: Thu Jun 2 01:33:26 2005
New Revision: 1918
Modified:
hugo/trunk/gui/all_include.h
hugo/trunk/gui/graph_displayer_canvas.cc
hugo/trunk/gui/graph_displayer_canvas.h
hugo/trunk/gui/main_win.cc
hugo/trunk/gui/main_win.h
hugo/trunk/gui/map_win.cc
hugo/trunk/gui/map_win.h
hugo/trunk/gui/mapstorage.cc
hugo/trunk/gui/mapstorage.h
Log:
dos2unix
Modified: hugo/trunk/gui/all_include.h
==============================================================================
--- hugo/trunk/gui/all_include.h (original)
+++ hugo/trunk/gui/all_include.h Thu Jun 2 01:33:26 2005
@@ -1,39 +1,39 @@
-// -*- C++ -*- //
-
-#ifndef ALL_INCLUDE_H
-#define ALL_INCLUDE_H
-
-#include <fstream>
-#include <iostream>
-
-#include <vector>
-
-#include <lemon/list_graph.h>
-#include <lemon/graph_reader.h>
-#include <lemon/graph_writer.h>
-#include <lemon/graph_utils.h>
-#include <lemon/maps.h>
-#include <lemon/error.h>
-#include <lemon/xy.h>
-
-enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
-#define RANGE 3
-#define WIN_WIDTH 900
-#define WIN_HEIGHT 600
-
-
-#ifndef MAIN_PART
-extern std::string * property_strings;
-extern double * property_defaults;
-#endif //MAIN_PART
-
-using namespace lemon;
-
-typedef xy<double> Coordinates;
-typedef ListGraph Graph;
-typedef Graph::NodeMap<Coordinates> CoordinatesMap;
-typedef Graph::Node Node;
-typedef Graph::EdgeIt EdgeIt;
-typedef Graph::NodeIt NodeIt;
-
-#endif // ALL_INCLUDE_H
+// -*- C++ -*- //
+
+#ifndef ALL_INCLUDE_H
+#define ALL_INCLUDE_H
+
+#include <fstream>
+#include <iostream>
+
+#include <vector>
+
+#include <lemon/list_graph.h>
+#include <lemon/graph_reader.h>
+#include <lemon/graph_writer.h>
+#include <lemon/graph_utils.h>
+#include <lemon/maps.h>
+#include <lemon/error.h>
+#include <lemon/xy.h>
+
+enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
+#define RANGE 3
+#define WIN_WIDTH 900
+#define WIN_HEIGHT 600
+
+
+#ifndef MAIN_PART
+extern std::string * property_strings;
+extern double * property_defaults;
+#endif //MAIN_PART
+
+using namespace lemon;
+
+typedef xy<double> Coordinates;
+typedef ListGraph Graph;
+typedef Graph::NodeMap<Coordinates> CoordinatesMap;
+typedef Graph::Node Node;
+typedef Graph::EdgeIt EdgeIt;
+typedef Graph::NodeIt NodeIt;
+
+#endif // ALL_INCLUDE_H
Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc Thu Jun 2 01:33:26 2005
@@ -1,321 +1,321 @@
-#include <graph_displayer_canvas.h>
-#include <math.h>
-
-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)
-{
- //set_center_scroll_region(true);
-
- //first edges are drawn, to hide joining with nodes later
-
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
-
- //drawing green lines, coordinates are from cm
-
- Gnome::Canvas::Points coos;
- coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
- coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
-
- edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
- *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
- edgesmap[i]->property_width_pixels().set_value(10);
-
- //initializing edge-text as well, to empty string
-
- double x1, x2, y1, y2;
- edgesmap[i]->get_bounds(x1, y1, x2, y2);
-
- edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
- edgetextmap[i]->property_fill_color().set_value("black");
- }
-
- //afterwards nodes come to be drawn
-
- NodeIt i(g);
- int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
-
- for (; i!=INVALID; ++i)
- {
- //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
-
- if(cm[i].x>maxx)maxx=(int)cm[i].x;
- if(cm[i].y>maxy)maxy=(int)cm[i].y;
- if(cm[i].x<minx)minx=(int)cm[i].x;
- if(cm[i].y<miny)miny=(int)cm[i].y;
-
- //drawing bule nodes, with black line around them
-
- nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
- *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
- *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
- (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
- }
-
-/*
- //setting zoom to be able to see the whole graph on the canvas
-
- double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
- double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
-
- set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
- std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
- std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
- std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
-*/
- updateScrollRegion();
-}
-
-GraphDisplayerCanvas::~GraphDisplayerCanvas()
-{
-
- //writing out the end state of the graph
- //\todo all the maps has to be write out!
-
- Graph::NodeMap <int> id(g);
- Graph::NodeMap <double> xc(g);
- Graph::NodeMap <double> yc(g);
-
- int j=1;
-
- for (NodeIt i(g); i!=INVALID; ++i)
- {
- double x1,y1,x2,y2;
- nodesmap[i]->get_bounds(x1, y1, x2, y2);
-
- id[i]=j++;
- xc[i]=(x1+x2)/2;
- yc[i]=(y1+y2)/2;
- }
-
- GraphWriter<Graph> writer(std::cout,g);
-
- writer.writeNodeMap("id", id);
- writer.writeNodeMap("coordinates_x", xc);
- writer.writeNodeMap("coordinates_y", yc);
- writer.run();
-}
-
-int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
-{
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
- int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
- edgesmap[i]->property_width_pixels().set_value(w);
- }
- return 0;
-};
-
-int GraphDisplayerCanvas::changeColor (std::string mapname)
-{
-
- //function maps the range of the maximum and
- //the minimum of the nodemap to the range of
- //green in RGB
-
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
- double w=(*(mapstorage.edgemap_storage)[mapname])[i];
- double max=mapstorage.maxOfEdgeMap(mapname);
- double min=mapstorage.minOfEdgeMap(mapname);
-
- //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
- Gdk::Color color;
- if(max!=min)
- {
- color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
- }
- else
- {
- color.set_rgb_p (0, 100, 0);
- }
-
- edgesmap[i]->property_fill_color_gdk().set_value(color);
- }
- return 0;
-};
-
-int GraphDisplayerCanvas::changeText (std::string mapname)
-{
-
- //the number in the map will be written on the edge
- //EXCEPT when the name of the map is Text, because
- //in that case empty string will be written, because
- //that is the deleter map
- //\todo isn't it a bit woodcutter?
-
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
- if(mapname!="Text")
- {
- double number=(*(mapstorage.edgemap_storage)[mapname])[i];
- int length=(int)(floor(log(number)/log(10)))+1;
- int maxpos=(int)(pow(10,length-1));
- int strl=length+1+RANGE;
- char * str=new char[strl];
- str[length]='.';
- str[strl]='\0';
-
- for(int j=0;j<strl;j++)
- {
- if(j!=length)
- {
- int digit=(int)(number/maxpos);
- str[j]=(digit+'0');
- number-=digit*maxpos;
- number*=10;
- }
- }
-
- edgetextmap[i]->property_text().set_value(str);
- }
- else
- {
- edgetextmap[i]->property_text().set_value("");
- }
- }
- return 0;
-};
-
-bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
-{
- switch(e->type)
- {
- case GDK_BUTTON_PRESS:
- //we mark the location of the event to be able to calculate parameters of dragging
- clicked_x=e->button.x;
- clicked_y=e->button.y;
- active_item=(get_item_at(e->button.x, e->button.y));
- isbutton=true;
- break;
- case GDK_BUTTON_RELEASE:
- isbutton=false;
- active_item=NULL;
- break;
- case GDK_MOTION_NOTIFY:
- //we only have to do sg. if the mouse button is pressed
- if(isbutton)
- {
- //new coordinates will be the old values,
- //because the item will be moved to the
- //new coordinate therefore the new movement
- //has to be calculated from here
-
- double dx=e->motion.x-clicked_x;
- double dy=e->motion.y-clicked_y;
- active_item->move(dx, dy);
- clicked_x=e->motion.x;
- clicked_y=e->motion.y;
-
- //all the edges connected to the moved point has to be redrawn
-
- EdgeIt e;
- g.firstOut(e,n);
- for(;e!=INVALID;g.nextOut(e))
- {
- Gnome::Canvas::Points coos;
- double x1, x2, y1, y2;
-
- nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
- coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
-
- nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
- coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
-
- edgesmap[e]->property_points().set_value(coos);
-
- edgesmap[e]->get_bounds(x1, y1, x2, y2);
-
- edgetextmap[e]->property_x().set_value((x1+x2)/2);
- edgetextmap[e]->property_y().set_value((y1+y2)/2);
- }
-
- g.firstIn(e,n);
- for(;e!=INVALID;g.nextIn(e))
- {
- Gnome::Canvas::Points coos;
- double x1, x2, y1, y2;
-
- nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
- coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
-
- nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
- coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
-
- edgesmap[e]->property_points().set_value(coos);
-
- edgesmap[e]->get_bounds(x1, y1, x2, y2);
-
- edgetextmap[e]->property_x().set_value((x1+x2)/2);
- edgetextmap[e]->property_y().set_value((y1+y2)/2);
- }
- }
- default: break;
- }
- return true;
-}
-
-bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
-{
- Gnome::Canvas::CanvasAA::on_expose_event(event);
- //usleep(10000);
- //rezoom();
- return true;
-}
-
-void GraphDisplayerCanvas::zoomIn()
-{
- set_pixels_per_unit(
- (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
-}
-
-void GraphDisplayerCanvas::zoomOut()
-{
- set_pixels_per_unit(
- (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
-}
-
-void GraphDisplayerCanvas::zoomFit()
-{
- // get the height and width of the canvas
- Gtk::Allocation a = get_allocation();
- int aw = a.get_width();
- int ah = a.get_height();
- // add some space
- aw -= 5; if (aw < 0) aw = 0;
- ah -= 5; if (ah < 0) ah = 0;
- //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
-
- // get the bounding box of the graph
- set_pixels_per_unit(1.0); // I don't really understand why this is necessary
- double wx1, wy1, wx2, wy2;
- double cx1, cy1, cx2, cy2;
- Gnome::Canvas::Item* pCanvasItem = root();
- pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
- //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
- w2c(wx1, wy1, cx1, cy1);
- w2c(wx2, wy2, cx2, cy2);
- //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
- //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
-
- // fit the graph to the window
- double ppu1 = (double) aw / fabs(cx2 - cx1);
- double ppu2 = (double) ah / fabs(cy2 - cy1);
- //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
- (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
-}
-
-void GraphDisplayerCanvas::zoom100()
-{
- set_pixels_per_unit(1.0);
-}
-
-void GraphDisplayerCanvas::updateScrollRegion()
-{
- double wx1, wy1, wx2, wy2;
- int cx1, cy1, cx2, cy2;
- Gnome::Canvas::Item* pCanvasItem = root();
- pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
- w2c(wx1, wy1, cx1, cy1);
- w2c(wx2, wy2, cx2, cy2);
- set_scroll_region(cx1, cy1, cx2, cy2);
-}
+#include <graph_displayer_canvas.h>
+#include <math.h>
+
+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)
+{
+ //set_center_scroll_region(true);
+
+ //first edges are drawn, to hide joining with nodes later
+
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+
+ //drawing green lines, coordinates are from cm
+
+ Gnome::Canvas::Points coos;
+ coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
+ coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
+
+ edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
+ *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
+ edgesmap[i]->property_width_pixels().set_value(10);
+
+ //initializing edge-text as well, to empty string
+
+ double x1, x2, y1, y2;
+ edgesmap[i]->get_bounds(x1, y1, x2, y2);
+
+ edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
+ edgetextmap[i]->property_fill_color().set_value("black");
+ }
+
+ //afterwards nodes come to be drawn
+
+ NodeIt i(g);
+ int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
+
+ for (; i!=INVALID; ++i)
+ {
+ //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
+
+ if(cm[i].x>maxx)maxx=(int)cm[i].x;
+ if(cm[i].y>maxy)maxy=(int)cm[i].y;
+ if(cm[i].x<minx)minx=(int)cm[i].x;
+ if(cm[i].y<miny)miny=(int)cm[i].y;
+
+ //drawing bule nodes, with black line around them
+
+ nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
+ *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
+ *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
+ (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
+ }
+
+/*
+ //setting zoom to be able to see the whole graph on the canvas
+
+ double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
+ double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
+
+ set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
+ std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
+ std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
+ std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
+*/
+ updateScrollRegion();
+}
+
+GraphDisplayerCanvas::~GraphDisplayerCanvas()
+{
+
+ //writing out the end state of the graph
+ //\todo all the maps has to be write out!
+
+ Graph::NodeMap <int> id(g);
+ Graph::NodeMap <double> xc(g);
+ Graph::NodeMap <double> yc(g);
+
+ int j=1;
+
+ for (NodeIt i(g); i!=INVALID; ++i)
+ {
+ double x1,y1,x2,y2;
+ nodesmap[i]->get_bounds(x1, y1, x2, y2);
+
+ id[i]=j++;
+ xc[i]=(x1+x2)/2;
+ yc[i]=(y1+y2)/2;
+ }
+
+ GraphWriter<Graph> writer(std::cout,g);
+
+ writer.writeNodeMap("id", id);
+ writer.writeNodeMap("coordinates_x", xc);
+ writer.writeNodeMap("coordinates_y", yc);
+ writer.run();
+}
+
+int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
+{
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
+ edgesmap[i]->property_width_pixels().set_value(w);
+ }
+ return 0;
+};
+
+int GraphDisplayerCanvas::changeColor (std::string mapname)
+{
+
+ //function maps the range of the maximum and
+ //the minimum of the nodemap to the range of
+ //green in RGB
+
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ double w=(*(mapstorage.edgemap_storage)[mapname])[i];
+ double max=mapstorage.maxOfEdgeMap(mapname);
+ double min=mapstorage.minOfEdgeMap(mapname);
+
+ //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
+ Gdk::Color color;
+ if(max!=min)
+ {
+ color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
+ }
+ else
+ {
+ color.set_rgb_p (0, 100, 0);
+ }
+
+ edgesmap[i]->property_fill_color_gdk().set_value(color);
+ }
+ return 0;
+};
+
+int GraphDisplayerCanvas::changeText (std::string mapname)
+{
+
+ //the number in the map will be written on the edge
+ //EXCEPT when the name of the map is Text, because
+ //in that case empty string will be written, because
+ //that is the deleter map
+ //\todo isn't it a bit woodcutter?
+
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ if(mapname!="Text")
+ {
+ double number=(*(mapstorage.edgemap_storage)[mapname])[i];
+ int length=(int)(floor(log(number)/log(10)))+1;
+ int maxpos=(int)(pow(10,length-1));
+ int strl=length+1+RANGE;
+ char * str=new char[strl];
+ str[length]='.';
+ str[strl]='\0';
+
+ for(int j=0;j<strl;j++)
+ {
+ if(j!=length)
+ {
+ int digit=(int)(number/maxpos);
+ str[j]=(digit+'0');
+ number-=digit*maxpos;
+ number*=10;
+ }
+ }
+
+ edgetextmap[i]->property_text().set_value(str);
+ }
+ else
+ {
+ edgetextmap[i]->property_text().set_value("");
+ }
+ }
+ return 0;
+};
+
+bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
+{
+ switch(e->type)
+ {
+ case GDK_BUTTON_PRESS:
+ //we mark the location of the event to be able to calculate parameters of dragging
+ clicked_x=e->button.x;
+ clicked_y=e->button.y;
+ active_item=(get_item_at(e->button.x, e->button.y));
+ isbutton=true;
+ break;
+ case GDK_BUTTON_RELEASE:
+ isbutton=false;
+ active_item=NULL;
+ break;
+ case GDK_MOTION_NOTIFY:
+ //we only have to do sg. if the mouse button is pressed
+ if(isbutton)
+ {
+ //new coordinates will be the old values,
+ //because the item will be moved to the
+ //new coordinate therefore the new movement
+ //has to be calculated from here
+
+ double dx=e->motion.x-clicked_x;
+ double dy=e->motion.y-clicked_y;
+ active_item->move(dx, dy);
+ clicked_x=e->motion.x;
+ clicked_y=e->motion.y;
+
+ //all the edges connected to the moved point has to be redrawn
+
+ EdgeIt e;
+ g.firstOut(e,n);
+ for(;e!=INVALID;g.nextOut(e))
+ {
+ Gnome::Canvas::Points coos;
+ double x1, x2, y1, y2;
+
+ nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ edgesmap[e]->property_points().set_value(coos);
+
+ edgesmap[e]->get_bounds(x1, y1, x2, y2);
+
+ edgetextmap[e]->property_x().set_value((x1+x2)/2);
+ edgetextmap[e]->property_y().set_value((y1+y2)/2);
+ }
+
+ g.firstIn(e,n);
+ for(;e!=INVALID;g.nextIn(e))
+ {
+ Gnome::Canvas::Points coos;
+ double x1, x2, y1, y2;
+
+ nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+
+ edgesmap[e]->property_points().set_value(coos);
+
+ edgesmap[e]->get_bounds(x1, y1, x2, y2);
+
+ edgetextmap[e]->property_x().set_value((x1+x2)/2);
+ edgetextmap[e]->property_y().set_value((y1+y2)/2);
+ }
+ }
+ default: break;
+ }
+ return true;
+}
+
+bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
+{
+ Gnome::Canvas::CanvasAA::on_expose_event(event);
+ //usleep(10000);
+ //rezoom();
+ return true;
+}
+
+void GraphDisplayerCanvas::zoomIn()
+{
+ set_pixels_per_unit(
+ (1.0 + (double) zoom_step / 100.0) * get_pixels_per_unit());
+}
+
+void GraphDisplayerCanvas::zoomOut()
+{
+ set_pixels_per_unit(
+ (1.0 - (double) zoom_step / 100.0) * get_pixels_per_unit());
+}
+
+void GraphDisplayerCanvas::zoomFit()
+{
+ // get the height and width of the canvas
+ Gtk::Allocation a = get_allocation();
+ int aw = a.get_width();
+ int ah = a.get_height();
+ // add some space
+ aw -= 5; if (aw < 0) aw = 0;
+ ah -= 5; if (ah < 0) ah = 0;
+ //std::cout << "aw=" << aw << " ah=" << ah << std::endl;
+
+ // get the bounding box of the graph
+ set_pixels_per_unit(1.0); // I don't really understand why this is necessary
+ double wx1, wy1, wx2, wy2;
+ double cx1, cy1, cx2, cy2;
+ Gnome::Canvas::Item* pCanvasItem = root();
+ pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
+ //std::cout << "root bounds: " << wx1 << " " << wy1 << " " << wx2 << " " << wy2 << std::endl;
+ w2c(wx1, wy1, cx1, cy1);
+ w2c(wx2, wy2, cx2, cy2);
+ //std::cout << "root bounds (c): " << cx1 << " " << cy1 << " " << cx2 << " " << cy2 << std::endl;
+ //std::cout << "cx2 - cx1=" << fabs(cx2 - cx1) << " cy2 - cy1=" << fabs(cy2 - cy1) << std::endl;
+
+ // fit the graph to the window
+ double ppu1 = (double) aw / fabs(cx2 - cx1);
+ double ppu2 = (double) ah / fabs(cy2 - cy1);
+ //std::cout << "ppu1=" << ppu1 << " ppu2=" << ppu2 << std::endl;
+ (ppu1 < ppu2) ? set_pixels_per_unit(ppu1) : set_pixels_per_unit(ppu2);
+}
+
+void GraphDisplayerCanvas::zoom100()
+{
+ set_pixels_per_unit(1.0);
+}
+
+void GraphDisplayerCanvas::updateScrollRegion()
+{
+ double wx1, wy1, wx2, wy2;
+ int cx1, cy1, cx2, cy2;
+ Gnome::Canvas::Item* pCanvasItem = root();
+ pCanvasItem->get_bounds(wx1, wy1, wx2, wy2);
+ w2c(wx1, wy1, cx1, cy1);
+ w2c(wx2, wy2, cx2, cy2);
+ set_scroll_region(cx1, cy1, cx2, cy2);
+}
Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h (original)
+++ hugo/trunk/gui/graph_displayer_canvas.h Thu Jun 2 01:33:26 2005
@@ -1,89 +1,89 @@
-// -*- C++ -*- //
-
-#ifndef GRAPH_DISPLAYER_CANVAS_H
-#define GRAPH_DISPLAYER_CANVAS_H
-
-#include <all_include.h>
-#include <mapstorage.h>
-#include <libgnomecanvasmm.h>
-#include <libgnomecanvasmm/polygon.h>
-
-///This class is the canvas, on which the graph can be drawn.
-class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
-{
- typedef Gnome::Canvas::CanvasAA Parent;
-
-public:
- GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
- virtual ~GraphDisplayerCanvas();
-
- ///Changes the linewidth attribute according to the given map.
- ///\param mapname is the name of the map which contains the new values
- int changeLineWidth (std::string mapname);
-
- ///Changes the linecolor attribute according to the given map.
- ///\param mapname is the name of the map which contains the new values
- int changeColor (std::string mapname);
-
- ///Changes the text of line attribute according to the given map.
- ///\param mapname is the name of the map which contains the new values
- int changeText (std::string mapname);
-
- ///Callback for 'ViewZoomIn' action.
- virtual void zoomIn();
- ///Callback for 'ViewZoomOut' action.
- virtual void zoomOut();
- ///Callback for 'ViewZoomFit' action.
- virtual void zoomFit();
- ///Callback for 'ViewZoom100' action.
- virtual void zoom100();
- ///Sets the scroll region of the convas to the bounding box of the graph.
- void updateScrollRegion();
-
-protected:
-
- //maximizing, minimizing, restoring window, etc.
- virtual bool on_expose_event(GdkEventExpose *);
-
-private:
-
- ///This function is responsible for the correct
- ///reaction of any action happened in the territory
- ///of the canvas
- bool event_handler(GdkEvent* e, Node n);
-
- ///The graph, on which we work
- Graph g;
-
- ///Map of nodes of graph
- Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
-
- ///Map of edges of graph
- Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
-
- ///Map of texts to write on edges
- Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
-
- ///Group of graphical elements of displayed_graph
- Gnome::Canvas::Group displayed_graph;
-
- ///Here we store the maps that can be displayed through properties.
- MapStorage mapstorage;
-
- ///Indicates whether the button of mouse is pressed or not
- bool isbutton;
-
- ///At this location was the mousebutton pressed.
- ///It helps to calculate the distance of dragging.
- double clicked_x, clicked_y;
-
- ///Remembers which Gnome::Canvas::Item was pressed.
- ///this variable is needed, because
- ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
- ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
- Gnome::Canvas::Item * active_item;
-
- static const int zoom_step = 5;
-};
-
-#endif //GRAPH_DISPLAYER_CANVAS_H
+// -*- C++ -*- //
+
+#ifndef GRAPH_DISPLAYER_CANVAS_H
+#define GRAPH_DISPLAYER_CANVAS_H
+
+#include <all_include.h>
+#include <mapstorage.h>
+#include <libgnomecanvasmm.h>
+#include <libgnomecanvasmm/polygon.h>
+
+///This class is the canvas, on which the graph can be drawn.
+class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
+{
+ typedef Gnome::Canvas::CanvasAA Parent;
+
+public:
+ GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
+ virtual ~GraphDisplayerCanvas();
+
+ ///Changes the linewidth attribute according to the given map.
+ ///\param mapname is the name of the map which contains the new values
+ int changeLineWidth (std::string mapname);
+
+ ///Changes the linecolor attribute according to the given map.
+ ///\param mapname is the name of the map which contains the new values
+ int changeColor (std::string mapname);
+
+ ///Changes the text of line attribute according to the given map.
+ ///\param mapname is the name of the map which contains the new values
+ int changeText (std::string mapname);
+
+ ///Callback for 'ViewZoomIn' action.
+ virtual void zoomIn();
+ ///Callback for 'ViewZoomOut' action.
+ virtual void zoomOut();
+ ///Callback for 'ViewZoomFit' action.
+ virtual void zoomFit();
+ ///Callback for 'ViewZoom100' action.
+ virtual void zoom100();
+ ///Sets the scroll region of the convas to the bounding box of the graph.
+ void updateScrollRegion();
+
+protected:
+
+ //maximizing, minimizing, restoring window, etc.
+ virtual bool on_expose_event(GdkEventExpose *);
+
+private:
+
+ ///This function is responsible for the correct
+ ///reaction of any action happened in the territory
+ ///of the canvas
+ bool event_handler(GdkEvent* e, Node n);
+
+ ///The graph, on which we work
+ Graph g;
+
+ ///Map of nodes of graph
+ Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
+
+ ///Map of edges of graph
+ Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
+
+ ///Map of texts to write on edges
+ Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
+
+ ///Group of graphical elements of displayed_graph
+ Gnome::Canvas::Group displayed_graph;
+
+ ///Here we store the maps that can be displayed through properties.
+ MapStorage mapstorage;
+
+ ///Indicates whether the button of mouse is pressed or not
+ bool isbutton;
+
+ ///At this location was the mousebutton pressed.
+ ///It helps to calculate the distance of dragging.
+ double clicked_x, clicked_y;
+
+ ///Remembers which Gnome::Canvas::Item was pressed.
+ ///this variable is needed, because
+ ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
+ ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
+ Gnome::Canvas::Item * active_item;
+
+ static const int zoom_step = 5;
+};
+
+#endif //GRAPH_DISPLAYER_CANVAS_H
Modified: hugo/trunk/gui/main_win.cc
==============================================================================
--- hugo/trunk/gui/main_win.cc (original)
+++ hugo/trunk/gui/main_win.cc Thu Jun 2 01:33:26 2005
@@ -1,133 +1,133 @@
-#include <main_win.h>
-
-MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
- MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
-{
- set_title (title);
- set_default_size(WIN_WIDTH,WIN_HEIGHT);
- add(vbox);
-
- ag=Gtk::ActionGroup::create();
-
- ag->add( Gtk::Action::create("FileMenu", "_File") );
- ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
- sigc::mem_fun(*this, &MainWin::newFile));
- ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
- sigc::mem_fun(*this, &MainWin::openFile));
- ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
- sigc::mem_fun(*this, &MainWin::saveFile));
- ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
- sigc::mem_fun(*this, &MainWin::saveFileAs));
- ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
- sigc::mem_fun(*this, &MainWin::quit));
-
- ag->add( Gtk::Action::create("ViewMenu", "_View") );
- ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
- sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
- ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
- sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
- ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
- sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
- ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
- sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
-
- ag->add( Gtk::Action::create("ShowMenu", "_Show") );
- ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
- sigc::mem_fun(*this, &MainWin::showMaps));
-
- uim=Gtk::UIManager::create();
- uim->insert_action_group(ag);
- add_accel_group(uim->get_accel_group());
-
- try
- {
-
- Glib::ustring ui_info =
- "<ui>"
- " <menubar name='MenuBar'>"
- " <menu action='FileMenu'>"
- " <menuitem action='FileNew'/>"
- " <menuitem action='FileOpen'/>"
- " <menuitem action='FileSave'/>"
- " <menuitem action='FileSaveAs'/>"
- " <menuitem action='FileQuit'/>"
- " </menu>"
- " <menu action='ViewMenu'>"
- " <menuitem action='ViewZoomIn' />"
- " <menuitem action='ViewZoomOut' />"
- " <menuitem action='ViewZoomFit' />"
- " <menuitem action='ViewZoom100' />"
- " </menu>"
- " <menu action='ShowMenu'>"
- " <menuitem action='ShowMaps'/>"
- " </menu>"
- " </menubar>"
- " <toolbar name='ToolBar'>"
- " <toolitem action='FileNew' />"
- " <toolitem action='FileOpen' />"
- " <toolitem action='FileSave' />"
- " <separator />"
- " <toolitem action='ViewZoomIn' />"
- " <toolitem action='ViewZoomOut' />"
- " <toolitem action='ViewZoomFit' />"
- " <toolitem action='ViewZoom100' />"
- " </toolbar>"
- "</ui>";
-
- uim->add_ui_from_string(ui_info);
-
- }
- catch(const Glib::Error& ex)
- {
- std::cerr << "building menus failed: " << ex.what();
- }
-
- Gtk::Widget* menubar = uim->get_widget("/MenuBar");
- if (menubar){
- vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
- }
-
- Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
- if (toolbar)
- {
- static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
- vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
- }
-
- Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
- pScrolledWindow->add(gd_canvas);
- vbox.pack_start(*pScrolledWindow);
- //vbox.pack_start(gd_canvas);
-
- show_all_children();
-}
-
-void MainWin::showMaps()
-{
- mapwin.show();
-}
-
-void MainWin::quit()
-{
- hide();
-}
-
-void MainWin::newFile()
-{
- std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
-}
-
-void MainWin::openFile()
-{
- std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
-}
-
-void MainWin::saveFile()
-{
- std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
-}
-
-void MainWin::saveFileAs()
-{
- std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
-}
+#include <main_win.h>
+
+MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
+ MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
+{
+ set_title (title);
+ set_default_size(WIN_WIDTH,WIN_HEIGHT);
+ add(vbox);
+
+ ag=Gtk::ActionGroup::create();
+
+ ag->add( Gtk::Action::create("FileMenu", "_File") );
+ ag->add( Gtk::Action::create("FileNew", Gtk::Stock::NEW),
+ sigc::mem_fun(*this, &MainWin::newFile));
+ ag->add( Gtk::Action::create("FileOpen", Gtk::Stock::OPEN),
+ sigc::mem_fun(*this, &MainWin::openFile));
+ ag->add( Gtk::Action::create("FileSave", Gtk::Stock::SAVE),
+ sigc::mem_fun(*this, &MainWin::saveFile));
+ ag->add( Gtk::Action::create("FileSaveAs", Gtk::Stock::SAVE_AS),
+ sigc::mem_fun(*this, &MainWin::saveFileAs));
+ ag->add( Gtk::Action::create("FileQuit", Gtk::Stock::QUIT),
+ sigc::mem_fun(*this, &MainWin::quit));
+
+ ag->add( Gtk::Action::create("ViewMenu", "_View") );
+ ag->add( Gtk::Action::create("ViewZoomIn", Gtk::Stock::ZOOM_IN),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomIn));
+ ag->add( Gtk::Action::create("ViewZoomOut", Gtk::Stock::ZOOM_OUT),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomOut));
+ ag->add( Gtk::Action::create("ViewZoomFit", Gtk::Stock::ZOOM_FIT),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoomFit));
+ ag->add( Gtk::Action::create("ViewZoom100", Gtk::Stock::ZOOM_100),
+ sigc::mem_fun(this->gd_canvas, &GraphDisplayerCanvas::zoom100));
+
+ ag->add( Gtk::Action::create("ShowMenu", "_Show") );
+ ag->add( Gtk::Action::create("ShowMaps", "_Maps"),
+ sigc::mem_fun(*this, &MainWin::showMaps));
+
+ uim=Gtk::UIManager::create();
+ uim->insert_action_group(ag);
+ add_accel_group(uim->get_accel_group());
+
+ try
+ {
+
+ Glib::ustring ui_info =
+ "<ui>"
+ " <menubar name='MenuBar'>"
+ " <menu action='FileMenu'>"
+ " <menuitem action='FileNew'/>"
+ " <menuitem action='FileOpen'/>"
+ " <menuitem action='FileSave'/>"
+ " <menuitem action='FileSaveAs'/>"
+ " <menuitem action='FileQuit'/>"
+ " </menu>"
+ " <menu action='ViewMenu'>"
+ " <menuitem action='ViewZoomIn' />"
+ " <menuitem action='ViewZoomOut' />"
+ " <menuitem action='ViewZoomFit' />"
+ " <menuitem action='ViewZoom100' />"
+ " </menu>"
+ " <menu action='ShowMenu'>"
+ " <menuitem action='ShowMaps'/>"
+ " </menu>"
+ " </menubar>"
+ " <toolbar name='ToolBar'>"
+ " <toolitem action='FileNew' />"
+ " <toolitem action='FileOpen' />"
+ " <toolitem action='FileSave' />"
+ " <separator />"
+ " <toolitem action='ViewZoomIn' />"
+ " <toolitem action='ViewZoomOut' />"
+ " <toolitem action='ViewZoomFit' />"
+ " <toolitem action='ViewZoom100' />"
+ " </toolbar>"
+ "</ui>";
+
+ uim->add_ui_from_string(ui_info);
+
+ }
+ catch(const Glib::Error& ex)
+ {
+ std::cerr << "building menus failed: " << ex.what();
+ }
+
+ Gtk::Widget* menubar = uim->get_widget("/MenuBar");
+ if (menubar){
+ vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
+ }
+
+ Gtk::Widget* toolbar = uim->get_widget("/ToolBar");
+ if (toolbar)
+ {
+ static_cast<Gtk::Toolbar*>(toolbar)->set_toolbar_style(Gtk::TOOLBAR_ICONS);
+ vbox.pack_start(*toolbar, Gtk::PACK_SHRINK);
+ }
+
+ Gtk::ScrolledWindow* pScrolledWindow = manage(new Gtk::ScrolledWindow());
+ pScrolledWindow->add(gd_canvas);
+ vbox.pack_start(*pScrolledWindow);
+ //vbox.pack_start(gd_canvas);
+
+ show_all_children();
+}
+
+void MainWin::showMaps()
+{
+ mapwin.show();
+}
+
+void MainWin::quit()
+{
+ hide();
+}
+
+void MainWin::newFile()
+{
+ std::cerr << "MainWin::newFile(): not yet implemented" << std::endl;
+}
+
+void MainWin::openFile()
+{
+ std::cerr << "MainWin::openFile(): not yet implemented" << std::endl;
+}
+
+void MainWin::saveFile()
+{
+ std::cerr << "MainWin::saveFile(): not yet implemented" << std::endl;
+}
+
+void MainWin::saveFileAs()
+{
+ std::cerr << "MainWin::saveFileAs(): not yet implemented" << std::endl;
+}
Modified: hugo/trunk/gui/main_win.h
==============================================================================
--- hugo/trunk/gui/main_win.h (original)
+++ hugo/trunk/gui/main_win.h Thu Jun 2 01:33:26 2005
@@ -1,54 +1,54 @@
-// -*- C++ -*- //
-
-#ifndef MAIN_WIN_H
-#define MAIN_WIN_H
-
-#include <all_include.h>
-#include <mapstorage.h>
-#include <map_win.h>
-#include <libgnomecanvasmm.h>
-#include <libgnomecanvasmm/polygon.h>
-
-///This class is the main window of GUI.
-///It has menus, but the main part of it is the canvas.
-class MainWin : public Gtk::Window
-{
-public:
- ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
- ///\param title is the title of the window
- ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
- ///\param cm stores the coordinates of the nodes of the graph
- ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
- MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
-
-protected:
- ///Window of map-showing setup. Its type is \ref MapWin
- MapWin mapwin;
-
- ///The graph will be drawn on this \ref GraphDisplayerCanvas
- GraphDisplayerCanvas gd_canvas;
-
- ///ActionGroup for menu
- Glib::RefPtr<Gtk::ActionGroup> ag;
-
- ///UIManager for menu
- Glib::RefPtr<Gtk::UIManager> uim;
-
- ///Container
- Gtk::VBox vbox;
-
- ///This function makes map-setup window popped up.
- virtual void showMaps();
- ///Callback for 'FileNew' action.
- virtual void newFile();
- ///Callback for 'FileOpen' action.
- virtual void openFile();
- ///Callback for 'FileSave' action.
- virtual void saveFile();
- ///Callback for 'FileSaveAs' action.
- virtual void saveFileAs();
- ///Callback for 'Quit' action.
- virtual void quit();
-};
-
-#endif //MAIN_WIN_H
+// -*- C++ -*- //
+
+#ifndef MAIN_WIN_H
+#define MAIN_WIN_H
+
+#include <all_include.h>
+#include <mapstorage.h>
+#include <map_win.h>
+#include <libgnomecanvasmm.h>
+#include <libgnomecanvasmm/polygon.h>
+
+///This class is the main window of GUI.
+///It has menus, but the main part of it is the canvas.
+class MainWin : public Gtk::Window
+{
+public:
+ ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
+ ///\param title is the title of the window
+ ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
+ ///\param cm stores the coordinates of the nodes of the graph
+ ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
+ MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
+
+protected:
+ ///Window of map-showing setup. Its type is \ref MapWin
+ MapWin mapwin;
+
+ ///The graph will be drawn on this \ref GraphDisplayerCanvas
+ GraphDisplayerCanvas gd_canvas;
+
+ ///ActionGroup for menu
+ Glib::RefPtr<Gtk::ActionGroup> ag;
+
+ ///UIManager for menu
+ Glib::RefPtr<Gtk::UIManager> uim;
+
+ ///Container
+ Gtk::VBox vbox;
+
+ ///This function makes map-setup window popped up.
+ virtual void showMaps();
+ ///Callback for 'FileNew' action.
+ virtual void newFile();
+ ///Callback for 'FileOpen' action.
+ virtual void openFile();
+ ///Callback for 'FileSave' action.
+ virtual void saveFile();
+ ///Callback for 'FileSaveAs' action.
+ virtual void saveFileAs();
+ ///Callback for 'Quit' action.
+ virtual void quit();
+};
+
+#endif //MAIN_WIN_H
Modified: hugo/trunk/gui/map_win.cc
==============================================================================
--- hugo/trunk/gui/map_win.cc (original)
+++ hugo/trunk/gui/map_win.cc Thu Jun 2 01:33:26 2005
@@ -1,122 +1,122 @@
-#include <map_win.h>
-#include <set>
-
-MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
-{
-
- //most nem kommentezem fel, mert ugyis valtozik
-
- set_title(title);
- set_default_size(400, 200);
-
- rb_array=new Gtk::RadioButton * [PROPERTY_NUM];
- vbox_r1=new Gtk::VBox[PROPERTY_NUM];
- vbox_r2=new Gtk::VBox[PROPERTY_NUM];
- radios=new Gtk::HBox[PROPERTY_NUM];
- for(int i=0;i<PROPERTY_NUM;i++)
- {
- rb_array[i]=new Gtk::RadioButton[ms.numOfEdgeMaps()+1];
-
- Gtk::RadioButton::Group group;
-
- std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
- std::set<int> props;
-
- int actprop;
- for(int j=0;j<ms.numOfEdgeMaps();j++)
- {
-
- if(emsi->second==&(ms.default_edgemaps[i]))
- {
- actprop=j;
- }
- for(int k=0;k<PROPERTY_NUM;k++)
- {
- if(emsi->second==&(ms.default_edgemaps[k]))
- {
- props.insert(j);
- }
- }
- emsi++;
- }
-
- rb_array[i][0].set_group(group);
- rb_array[i][0].set_label("Default");
- rb_array[i][0].signal_clicked().connect( sigc::bind( sigc::bind( sigc::mem_fun(*this, &MapWin::radio_click), 0), i) );
- vbox_r1[i].pack_start(rb_array[i][0]);
-
-
- emsi=ms.beginOfEdgeMaps();
- int actpos=1;
- for(int j=0;j<ms.numOfEdgeMaps();j++)
- {
- if( ( props.find(j) )==( props.end() ) )
- {
- rb_array[i][actpos].set_group(group);
- rb_array[i][actpos].set_label(emsi->first);
- rb_array[i][actpos].signal_clicked().connect
- (
- sigc::bind(
- sigc::bind(
- sigc::mem_fun(*this, &MapWin::radio_click),
- actpos
- ),
- i
- )
- );
-
- if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
- {
- vbox_r1[i].pack_start(rb_array[i][actpos]);
- }
- else
- {
- vbox_r2[i].pack_start(rb_array[i][actpos]);
- }
- actpos++;
- }
- emsi++;
- }
- radios[i].pack_start(vbox_r1[i]);
- radios[i].pack_start(vbox_r2[i]);
- notebook.append_page(radios[i], property_strings[i]);
- }
-
- add(vbox_b);
- vbox_b.pack_start(notebook);
-
- show_all_children();
-
-}
-
-void MapWin::radio_click(int prop, int actpos)
-{
-
- //most nem kommentezem fel, mert ugyis valtozik
-
- if(rb_array[prop][actpos].get_active())
- {
-
- std::string mapname=rb_array[prop][actpos].get_label();
-
- if(mapname=="Default")
- {
- mapname=property_strings[prop];
- }
-
- switch(prop)
- {
- case WIDTH:
- gdc.changeLineWidth(mapname);
- break;
- case COLOR:
- gdc.changeColor(mapname);
- break;
- case TEXT:
- gdc.changeText(mapname);
- break;
- default:
- std::cout<<"Error\n";
- }
- }
-};
+#include <map_win.h>
+#include <set>
+
+MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
+{
+
+ //most nem kommentezem fel, mert ugyis valtozik
+
+ set_title(title);
+ set_default_size(400, 200);
+
+ rb_array=new Gtk::RadioButton * [PROPERTY_NUM];
+ vbox_r1=new Gtk::VBox[PROPERTY_NUM];
+ vbox_r2=new Gtk::VBox[PROPERTY_NUM];
+ radios=new Gtk::HBox[PROPERTY_NUM];
+ for(int i=0;i<PROPERTY_NUM;i++)
+ {
+ rb_array[i]=new Gtk::RadioButton[ms.numOfEdgeMaps()+1];
+
+ Gtk::RadioButton::Group group;
+
+ std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
+ std::set<int> props;
+
+ int actprop;
+ for(int j=0;j<ms.numOfEdgeMaps();j++)
+ {
+
+ if(emsi->second==&(ms.default_edgemaps[i]))
+ {
+ actprop=j;
+ }
+ for(int k=0;k<PROPERTY_NUM;k++)
+ {
+ if(emsi->second==&(ms.default_edgemaps[k]))
+ {
+ props.insert(j);
+ }
+ }
+ emsi++;
+ }
+
+ rb_array[i][0].set_group(group);
+ rb_array[i][0].set_label("Default");
+ rb_array[i][0].signal_clicked().connect( sigc::bind( sigc::bind( sigc::mem_fun(*this, &MapWin::radio_click), 0), i) );
+ vbox_r1[i].pack_start(rb_array[i][0]);
+
+
+ emsi=ms.beginOfEdgeMaps();
+ int actpos=1;
+ for(int j=0;j<ms.numOfEdgeMaps();j++)
+ {
+ if( ( props.find(j) )==( props.end() ) )
+ {
+ rb_array[i][actpos].set_group(group);
+ rb_array[i][actpos].set_label(emsi->first);
+ rb_array[i][actpos].signal_clicked().connect
+ (
+ sigc::bind(
+ sigc::bind(
+ sigc::mem_fun(*this, &MapWin::radio_click),
+ actpos
+ ),
+ i
+ )
+ );
+
+ if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
+ {
+ vbox_r1[i].pack_start(rb_array[i][actpos]);
+ }
+ else
+ {
+ vbox_r2[i].pack_start(rb_array[i][actpos]);
+ }
+ actpos++;
+ }
+ emsi++;
+ }
+ radios[i].pack_start(vbox_r1[i]);
+ radios[i].pack_start(vbox_r2[i]);
+ notebook.append_page(radios[i], property_strings[i]);
+ }
+
+ add(vbox_b);
+ vbox_b.pack_start(notebook);
+
+ show_all_children();
+
+}
+
+void MapWin::radio_click(int prop, int actpos)
+{
+
+ //most nem kommentezem fel, mert ugyis valtozik
+
+ if(rb_array[prop][actpos].get_active())
+ {
+
+ std::string mapname=rb_array[prop][actpos].get_label();
+
+ if(mapname=="Default")
+ {
+ mapname=property_strings[prop];
+ }
+
+ switch(prop)
+ {
+ case WIDTH:
+ gdc.changeLineWidth(mapname);
+ break;
+ case COLOR:
+ gdc.changeColor(mapname);
+ break;
+ case TEXT:
+ gdc.changeText(mapname);
+ break;
+ default:
+ std::cout<<"Error\n";
+ }
+ }
+};
Modified: hugo/trunk/gui/map_win.h
==============================================================================
--- hugo/trunk/gui/map_win.h (original)
+++ hugo/trunk/gui/map_win.h Thu Jun 2 01:33:26 2005
@@ -1,49 +1,49 @@
-// -*- C++ -*- //
-
-#ifndef MAP_WIN_H
-#define MAP_WIN_H
-
-#include <all_include.h>
-#include <mapstorage.h>
-#include <graph_displayer_canvas.h>
-#include <libgnomecanvasmm.h>
-#include <libgnomecanvasmm/polygon.h>
-
-///This class is responsible for creating a window,
-///on which the visualization attributes can be
-///assigned to maps.
-class MapWin : public Gtk::Window
-{
-protected:
- ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
- ///It has to be known for this class, because
- ///when a map assigned to a certain attribute
- ///a function of the \ref GraphDisplayerCanvas will be called.
- GraphDisplayerCanvas & gdc;
-
- ///The \ref MapStorage in which the visualizable maps are stored
- MapStorage & ms;
-
-
- Gtk::HBox * radios;
- Gtk::RadioButton ** rb_array;
-
- Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
-
- ///The notebook has different pages for each attribute.
- Gtk::Notebook notebook;
-
- Gtk::Label * labels;
-
-public:
- ///Constructor of MapWin creates the widgets shown in MapWin.
- MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
-
- ///If a radiobutton is clicked, this function determines
- ///which button was that and after that calls the
- ///appropriate function of the \ref GraphDisplayerCanvas
- ///to change the visible values of that attribute.
- virtual void radio_click(int, int);
-};
-
-#endif //MAP_WIN_H
+// -*- C++ -*- //
+
+#ifndef MAP_WIN_H
+#define MAP_WIN_H
+
+#include <all_include.h>
+#include <mapstorage.h>
+#include <graph_displayer_canvas.h>
+#include <libgnomecanvasmm.h>
+#include <libgnomecanvasmm/polygon.h>
+
+///This class is responsible for creating a window,
+///on which the visualization attributes can be
+///assigned to maps.
+class MapWin : public Gtk::Window
+{
+protected:
+ ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
+ ///It has to be known for this class, because
+ ///when a map assigned to a certain attribute
+ ///a function of the \ref GraphDisplayerCanvas will be called.
+ GraphDisplayerCanvas & gdc;
+
+ ///The \ref MapStorage in which the visualizable maps are stored
+ MapStorage & ms;
+
+
+ Gtk::HBox * radios;
+ Gtk::RadioButton ** rb_array;
+
+ Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
+
+ ///The notebook has different pages for each attribute.
+ Gtk::Notebook notebook;
+
+ Gtk::Label * labels;
+
+public:
+ ///Constructor of MapWin creates the widgets shown in MapWin.
+ MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
+
+ ///If a radiobutton is clicked, this function determines
+ ///which button was that and after that calls the
+ ///appropriate function of the \ref GraphDisplayerCanvas
+ ///to change the visible values of that attribute.
+ virtual void radio_click(int, int);
+};
+
+#endif //MAP_WIN_H
Modified: hugo/trunk/gui/mapstorage.cc
==============================================================================
--- hugo/trunk/gui/mapstorage.cc (original)
+++ hugo/trunk/gui/mapstorage.cc Thu Jun 2 01:33:26 2005
@@ -1,88 +1,88 @@
-#include <mapstorage.h>
-
-MapStorage::MapStorage(Graph & graph):g(graph)
-{
- for(int i=0;i<PROPERTY_NUM;i++)
- {
- Graph::EdgeMap<double> emd(g);
- default_edgemaps.push_back(emd);
- Graph::NodeMap<double> nmd(g);
- default_nodemaps.push_back(nmd);
- }
- for(int i=0;i<PROPERTY_NUM;i++)
- {
- for (EdgeIt j(g); j!=INVALID; ++j)
- {
- (default_edgemaps[i])[j]=property_defaults[i];
- }
- addEdgeMap(property_strings[i],&(default_edgemaps[i]));
- }
-
-};
-
-int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
-{
- nodemap_storage[name]=nodemap;
- return 0;
-}
-
-int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
-{
- edgemap_storage[name]=edgemap;
- return 0;
-}
-
-double MapStorage::maxOfNodeMap(const std::string & name)
-{
- double max=0;
- for (NodeIt j(g); j!=INVALID; ++j)
- {
- if( (*nodemap_storage[name])[j]>max )
- {
- max=(*nodemap_storage[name])[j];
- }
- }
- return max;
-}
-
-double MapStorage::maxOfEdgeMap(const std::string & name)
-{
- double max=0;
- for (EdgeIt j(g); j!=INVALID; ++j)
- {
- if( (*edgemap_storage[name])[j]>max )
- {
- max=(*edgemap_storage[name])[j];
- }
- }
- return max;
-}
-
-double MapStorage::minOfNodeMap(const std::string & name)
-{
- NodeIt j(g);
- double min=(*nodemap_storage[name])[j];
- for (; j!=INVALID; ++j)
- {
- if( (*nodemap_storage[name])[j]<min )
- {
- min=(*nodemap_storage[name])[j];
- }
- }
- return min;
-}
-
-double MapStorage::minOfEdgeMap(const std::string & name)
-{
- EdgeIt j(g);
- double min=(*edgemap_storage[name])[j];
- for (EdgeIt j(g); j!=INVALID; ++j)
- {
- if( (*edgemap_storage[name])[j]<min )
- {
- min=(*edgemap_storage[name])[j];
- }
- }
- return min;
-}
-
+#include <mapstorage.h>
+
+MapStorage::MapStorage(Graph & graph):g(graph)
+{
+ for(int i=0;i<PROPERTY_NUM;i++)
+ {
+ Graph::EdgeMap<double> emd(g);
+ default_edgemaps.push_back(emd);
+ Graph::NodeMap<double> nmd(g);
+ default_nodemaps.push_back(nmd);
+ }
+ for(int i=0;i<PROPERTY_NUM;i++)
+ {
+ for (EdgeIt j(g); j!=INVALID; ++j)
+ {
+ (default_edgemaps[i])[j]=property_defaults[i];
+ }
+ addEdgeMap(property_strings[i],&(default_edgemaps[i]));
+ }
+
+};
+
+int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
+{
+ nodemap_storage[name]=nodemap;
+ return 0;
+}
+
+int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
+{
+ edgemap_storage[name]=edgemap;
+ return 0;
+}
+
+double MapStorage::maxOfNodeMap(const std::string & name)
+{
+ double max=0;
+ for (NodeIt j(g); j!=INVALID; ++j)
+ {
+ if( (*nodemap_storage[name])[j]>max )
+ {
+ max=(*nodemap_storage[name])[j];
+ }
+ }
+ return max;
+}
+
+double MapStorage::maxOfEdgeMap(const std::string & name)
+{
+ double max=0;
+ for (EdgeIt j(g); j!=INVALID; ++j)
+ {
+ if( (*edgemap_storage[name])[j]>max )
+ {
+ max=(*edgemap_storage[name])[j];
+ }
+ }
+ return max;
+}
+
+double MapStorage::minOfNodeMap(const std::string & name)
+{
+ NodeIt j(g);
+ double min=(*nodemap_storage[name])[j];
+ for (; j!=INVALID; ++j)
+ {
+ if( (*nodemap_storage[name])[j]<min )
+ {
+ min=(*nodemap_storage[name])[j];
+ }
+ }
+ return min;
+}
+
+double MapStorage::minOfEdgeMap(const std::string & name)
+{
+ EdgeIt j(g);
+ double min=(*edgemap_storage[name])[j];
+ for (EdgeIt j(g); j!=INVALID; ++j)
+ {
+ if( (*edgemap_storage[name])[j]<min )
+ {
+ min=(*edgemap_storage[name])[j];
+ }
+ }
+ return min;
+}
+
Modified: hugo/trunk/gui/mapstorage.h
==============================================================================
--- hugo/trunk/gui/mapstorage.h (original)
+++ hugo/trunk/gui/mapstorage.h Thu Jun 2 01:33:26 2005
@@ -1,85 +1,85 @@
-// -*- C++ -*- //
-
-#ifndef MAPSTORAGE_H
-#define MAPSTORAGE_H
-
-#include <all_include.h>
-
-///Class MapStorage is responsible for storing
-///NodeMaps and EdgeMaps that can be shown later
-///on GUI. Therefore maps can be added to it,
-///and datas over the added maps can be queried.
-///The maps will be stored in an std::map,
-///referenced with their names. Unfortunately at
-///the moment it works only with double type maps
-///
-///\todo too many things are public!!
-class MapStorage
-{
-public:
-
- Graph g;
-
- ///Stores double type NodeMaps
- std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
-
- ///Stores double type EdgeMaps
- std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
-
- //Stores the default values for the different visualization node attributes
- std::vector<Graph::NodeMap<double> > default_nodemaps;
-
- //Stores the default values for the different visualization edge attributes
- std::vector<Graph::EdgeMap<double> > default_edgemaps;
-
-public:
- ///Constructor of MapStorage. Expects the Graph of
- ///which maps will be stored in it.
- ///Its all activity is initializing default values
- ///for different visualization attributes
- ///
- ///\param graph is the graph for which the maps are stored in this object.
- MapStorage(Graph &);
-
- ///Adds given map to storage. A name and the map itself has to be provided.
- ///\param name is the name of map
- ///\nodemap is the pointer of the given nodemap
- ///\todo map should be given by reference!
- int addNodeMap(const std::string &,Graph::NodeMap<double> *);
-
- ///Adds given map to storage. A name and the map itself has to be provided.
- ///\param name is the name of map
- ///\edgemap is the pointer of the given edgemap
- ///\todo map should be given by reference!
- int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
-
- ///Returns how much nodemaps is stored in \ref MapStorage
- int numOfNodeMaps() {return nodemap_storage.size();};
-
- ///Returns how much edgemaps is stored in \ref MapStorage
- int numOfEdgeMaps() {return edgemap_storage.size();};
-
- ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
- ///\param name is the name of map of which maximum is searched
- double maxOfNodeMap(const std::string &);
-
- ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
- ///\param name is the name of map of which maximum is searched
- double maxOfEdgeMap(const std::string &);
-
- ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
- ///\param name is the name of map of which minimum is searched
- double minOfNodeMap(const std::string &);
-
- ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
- ///\param name is the name of map of which minimum is searched
- double minOfEdgeMap(const std::string &);
-
- ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
- std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
-
- ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
- std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
-};
-
-#endif //MAPSTORAGE_H
+// -*- C++ -*- //
+
+#ifndef MAPSTORAGE_H
+#define MAPSTORAGE_H
+
+#include <all_include.h>
+
+///Class MapStorage is responsible for storing
+///NodeMaps and EdgeMaps that can be shown later
+///on GUI. Therefore maps can be added to it,
+///and datas over the added maps can be queried.
+///The maps will be stored in an std::map,
+///referenced with their names. Unfortunately at
+///the moment it works only with double type maps
+///
+///\todo too many things are public!!
+class MapStorage
+{
+public:
+
+ Graph g;
+
+ ///Stores double type NodeMaps
+ std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
+
+ ///Stores double type EdgeMaps
+ std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
+
+ //Stores the default values for the different visualization node attributes
+ std::vector<Graph::NodeMap<double> > default_nodemaps;
+
+ //Stores the default values for the different visualization edge attributes
+ std::vector<Graph::EdgeMap<double> > default_edgemaps;
+
+public:
+ ///Constructor of MapStorage. Expects the Graph of
+ ///which maps will be stored in it.
+ ///Its all activity is initializing default values
+ ///for different visualization attributes
+ ///
+ ///\param graph is the graph for which the maps are stored in this object.
+ MapStorage(Graph &);
+
+ ///Adds given map to storage. A name and the map itself has to be provided.
+ ///\param name is the name of map
+ ///\nodemap is the pointer of the given nodemap
+ ///\todo map should be given by reference!
+ int addNodeMap(const std::string &,Graph::NodeMap<double> *);
+
+ ///Adds given map to storage. A name and the map itself has to be provided.
+ ///\param name is the name of map
+ ///\edgemap is the pointer of the given edgemap
+ ///\todo map should be given by reference!
+ int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
+
+ ///Returns how much nodemaps is stored in \ref MapStorage
+ int numOfNodeMaps() {return nodemap_storage.size();};
+
+ ///Returns how much edgemaps is stored in \ref MapStorage
+ int numOfEdgeMaps() {return edgemap_storage.size();};
+
+ ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
+ ///\param name is the name of map of which maximum is searched
+ double maxOfNodeMap(const std::string &);
+
+ ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
+ ///\param name is the name of map of which maximum is searched
+ double maxOfEdgeMap(const std::string &);
+
+ ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
+ ///\param name is the name of map of which minimum is searched
+ double minOfNodeMap(const std::string &);
+
+ ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
+ ///\param name is the name of map of which minimum is searched
+ double minOfEdgeMap(const std::string &);
+
+ ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
+ std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
+
+ ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
+ std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
+};
+
+#endif //MAPSTORAGE_H
More information about the Lemon-commits
mailing list