1.1 --- a/Makefile.am Thu May 05 15:34:43 2005 +0000
1.2 +++ b/Makefile.am Wed May 11 16:55:18 2005 +0000
1.3 @@ -1,1 +1,19 @@
1.4 -SUBDIRS = src
1.5 +AM_CPPFLAGS = -I$(top_srcdir)/src
1.6 +LDADD = $(top_builddir)/src/lemon/libemon.la
1.7 +
1.8 +bin_PROGRAMS = gd
1.9 +
1.10 +gd_SOURCES = \
1.11 + all_include.h \
1.12 + graph_displayer_canvas.cc \
1.13 + graph_displayer_canvas.h \
1.14 + graph-displayer.cc \
1.15 + main_win.cc \
1.16 + main_win.h \
1.17 + mapstorage.cc \
1.18 + mapstorage.h \
1.19 + map_win.cc \
1.20 + map_win.h
1.21 +
1.22 +gd_CXXFLAGS = $(GTK_CFLAGS)
1.23 +gd_LDFLAGS = $(GTK_LIBS)
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/all_include.h Wed May 11 16:55:18 2005 +0000
2.3 @@ -0,0 +1,39 @@
2.4 +// -*- C++ -*- //
2.5 +
2.6 +#ifndef ALL_INCLUDE_H
2.7 +#define ALL_INCLUDE_H
2.8 +
2.9 +#include <fstream>
2.10 +#include <iostream>
2.11 +
2.12 +#include <vector>
2.13 +
2.14 +#include <lemon/list_graph.h>
2.15 +#include <lemon/graph_reader.h>
2.16 +#include <lemon/graph_writer.h>
2.17 +#include <lemon/graph_utils.h>
2.18 +#include <lemon/maps.h>
2.19 +#include <lemon/error.h>
2.20 +#include <lemon/xy.h>
2.21 +
2.22 +enum {WIDTH, COLOR, TEXT, PROPERTY_NUM};// properties;
2.23 +#define RANGE 3
2.24 +#define WIN_WIDTH 900
2.25 +#define WIN_HEIGHT 600
2.26 +
2.27 +
2.28 +#ifndef MAIN_PART
2.29 +extern std::string * property_strings;
2.30 +extern double * property_defaults;
2.31 +#endif //MAIN_PART
2.32 +
2.33 +using namespace lemon;
2.34 +
2.35 +typedef xy<double> Coordinates;
2.36 +typedef ListGraph Graph;
2.37 +typedef Graph::NodeMap<Coordinates> CoordinatesMap;
2.38 +typedef Graph::Node Node;
2.39 +typedef Graph::EdgeIt EdgeIt;
2.40 +typedef Graph::NodeIt NodeIt;
2.41 +
2.42 +#endif // ALL_INCLUDE_H
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/graph-displayer.cc Wed May 11 16:55:18 2005 +0000
3.3 @@ -0,0 +1,73 @@
3.4 +#include <all_include.h>
3.5 +#include <mapstorage.h>
3.6 +#include <main_win.h>
3.7 +#include <libgnomecanvasmm.h>
3.8 +#include <libgnomecanvasmm/polygon.h>
3.9 +
3.10 +#define MAIN_PART
3.11 +
3.12 +std::string * property_strings;
3.13 +double * property_defaults;
3.14 +
3.15 +
3.16 +int main(int argc, char *argv[])
3.17 +{
3.18 + property_strings=new std::string[PROPERTY_NUM];
3.19 + property_strings[WIDTH]="Width";
3.20 + property_strings[COLOR]="Color";
3.21 + property_strings[TEXT]="Text";
3.22 +
3.23 + property_defaults=new double[PROPERTY_NUM];
3.24 + property_defaults[WIDTH]=10.0;
3.25 + property_defaults[COLOR]=100;
3.26 + property_defaults[TEXT]=0;
3.27 +
3.28 + if(argc<2)
3.29 + {
3.30 + std::cerr << "USAGE: gd <input filename.lgf>" << std::endl;
3.31 + return 0;
3.32 + }
3.33 +
3.34 + Coordinates coosvector;
3.35 +
3.36 + Graph g;
3.37 +
3.38 + CoordinatesMap cm(g);
3.39 + Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g);
3.40 +
3.41 + //we create one object to read x coordinates
3.42 + //and one to read y coordinate of nodes and write them to cm NodeMap.
3.43 +
3.44 + XMap <CoordinatesMap> xreader (cm);
3.45 + YMap <CoordinatesMap> yreader (cm);
3.46 + Graph::NodeMap<double> nodedata (g);
3.47 +
3.48 + std::ifstream is(argv[1]);
3.49 +
3.50 + GraphReader<Graph> reader(is, g);
3.51 + reader.readNodeMap("coordinates_x", xreader);
3.52 + reader.readNodeMap("coordinates_y", yreader);
3.53 + reader.readNodeMap("data", nodedata);
3.54 + reader.readEdgeMap("cap", cap);
3.55 + reader.readEdgeMap("map1", map1);
3.56 + reader.readEdgeMap("map2", map2);
3.57 + reader.readEdgeMap("map3", map3);
3.58 + reader.readEdgeMap("map4", map4);
3.59 + reader.run();
3.60 +
3.61 + MapStorage ms(g);
3.62 + ms.addNodeMap("data",&nodedata);
3.63 + ms.addEdgeMap("cap",&cap);
3.64 + ms.addEdgeMap("map1",&map1);
3.65 + ms.addEdgeMap("map2",&map2);
3.66 + ms.addEdgeMap("map3",&map3);
3.67 + ms.addEdgeMap("map4",&map4);
3.68 +
3.69 + Gnome::Canvas::init();
3.70 + Gtk::Main app(argc, argv);
3.71 +
3.72 + MainWin mainwin("Displayed Graph", g, cm, ms);
3.73 + app.run(mainwin);
3.74 +
3.75 + return 0;
3.76 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/graph_displayer_canvas.cc Wed May 11 16:55:18 2005 +0000
4.3 @@ -0,0 +1,259 @@
4.4 +#include <graph_displayer_canvas.h>
4.5 +
4.6 +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)
4.7 +{
4.8 +
4.9 + for (EdgeIt i(g); i!=INVALID; ++i)
4.10 + {
4.11 + Gnome::Canvas::Points coos;
4.12 + coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
4.13 + coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
4.14 +
4.15 + edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
4.16 + *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
4.17 + edgesmap[i]->property_width_pixels().set_value(10);
4.18 +
4.19 +
4.20 + double x1, x2, y1, y2;
4.21 + edgesmap[i]->get_bounds(x1, y1, x2, y2);
4.22 +
4.23 + edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, "");
4.24 + edgetextmap[i]->property_fill_color().set_value("black");
4.25 + }
4.26 +
4.27 + NodeIt i(g);
4.28 + int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
4.29 +
4.30 + for (; i!=INVALID; ++i)
4.31 + {
4.32 + if(cm[i].x>maxx)maxx=(int)cm[i].x;
4.33 + if(cm[i].y>maxy)maxy=(int)cm[i].y;
4.34 + if(cm[i].x<minx)minx=(int)cm[i].x;
4.35 + if(cm[i].y<miny)miny=(int)cm[i].y;
4.36 +
4.37 + nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20);
4.38 + *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
4.39 + *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
4.40 + (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
4.41 + }
4.42 +
4.43 + double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
4.44 + double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
4.45 +
4.46 + set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
4.47 + std::cout<<abs(maxx)<<" "<<abs(minx)<<" big x "<<biggest_x<<" "<<abs(maxy)<<" "<<abs(miny)<<" big y "<<biggest_y<<std::endl;
4.48 + std::cout<<maxx<<" "<<minx<<" big x "<<biggest_x<<" "<<maxy<<" "<<miny<<" big y "<<biggest_y<<std::endl;
4.49 + std::cout<<"dx "<<(maxx-minx)<<" dy "<<(maxy-miny)<<" xrate "<<((maxx-minx)/WIN_WIDTH)<<" yrate "<<((maxy-miny)/WIN_HEIGHT)<<std::endl;
4.50 +
4.51 +}
4.52 +
4.53 +GraphDisplayerCanvas::~GraphDisplayerCanvas()
4.54 +{
4.55 + Graph::NodeMap <int> id(g);
4.56 + Graph::NodeMap <double> xc(g);
4.57 + Graph::NodeMap <double> yc(g);
4.58 +
4.59 + int j=1;
4.60 +
4.61 + for (NodeIt i(g); i!=INVALID; ++i)
4.62 + {
4.63 + double x1,y1,x2,y2;
4.64 + nodesmap[i]->get_bounds(x1, y1, x2, y2);
4.65 +
4.66 + id[i]=j++;
4.67 + xc[i]=(x1+x2)/2;
4.68 + yc[i]=(y1+y2)/2;
4.69 + }
4.70 +
4.71 + GraphWriter<Graph> writer(std::cout,g);
4.72 +
4.73 + writer.writeNodeMap("id", id);
4.74 + writer.writeNodeMap("coordinates_x", xc);
4.75 + writer.writeNodeMap("coordinates_y", yc);
4.76 + writer.run();
4.77 +}
4.78 +
4.79 +int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
4.80 +{
4.81 + for (EdgeIt i(g); i!=INVALID; ++i)
4.82 + {
4.83 + int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
4.84 + edgesmap[i]->property_width_pixels().set_value(w);
4.85 + }
4.86 + return 0;
4.87 +};
4.88 +
4.89 +int GraphDisplayerCanvas::changeColor (std::string mapname)
4.90 +{
4.91 + for (EdgeIt i(g); i!=INVALID; ++i)
4.92 + {
4.93 + double w=(*(mapstorage.edgemap_storage)[mapname])[i];
4.94 + double max=mapstorage.maxOfEdgeMap(mapname);
4.95 + double min=mapstorage.minOfEdgeMap(mapname);
4.96 +
4.97 + //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
4.98 + Gdk::Color color;
4.99 + if(max!=min)
4.100 + {
4.101 + color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
4.102 + }
4.103 + else
4.104 + {
4.105 + color.set_rgb_p (0, 100, 0);
4.106 + }
4.107 +
4.108 + edgesmap[i]->property_fill_color_gdk().set_value(color);
4.109 + }
4.110 + return 0;
4.111 +};
4.112 +
4.113 +int GraphDisplayerCanvas::changeText (std::string mapname)
4.114 +{
4.115 + for (EdgeIt i(g); i!=INVALID; ++i)
4.116 + {
4.117 + if(mapname!="Text")
4.118 + {
4.119 + double number=(*(mapstorage.edgemap_storage)[mapname])[i];
4.120 + int length=(int)(floor(log(number)/log(10)))+1;
4.121 + int maxpos=(int)(pow(10,length-1));
4.122 + int strl=length+1+RANGE;
4.123 + char * str=new char[strl];
4.124 + str[length]='.';
4.125 + str[strl]='\0';
4.126 +
4.127 + for(int j=0;j<strl;j++)
4.128 + {
4.129 + if(j!=length)
4.130 + {
4.131 + int digit=(int)(number/maxpos);
4.132 + str[j]=(digit+'0');
4.133 + number-=digit*maxpos;
4.134 + number*=10;
4.135 + }
4.136 + }
4.137 +
4.138 + edgetextmap[i]->property_text().set_value(str);
4.139 + }
4.140 + else
4.141 + {
4.142 + edgetextmap[i]->property_text().set_value("");
4.143 + }
4.144 + }
4.145 + return 0;
4.146 +};
4.147 +
4.148 +
4.149 +int GraphDisplayerCanvas::rezoom ()
4.150 +{
4.151 + double x1, x2, y1, y2;
4.152 + int x,y;
4.153 +
4.154 + NodeIt i(g);
4.155 + nodesmap[i]->get_bounds(x1, y1, x2, y2);
4.156 +
4.157 + x=(int)((x1+x2)/2);
4.158 + y=(int)((y1+y2)/2);
4.159 +
4.160 + int maxx=0, maxy=0, minx=(int)x, miny=(int)y;
4.161 +
4.162 + for (; i!=INVALID; ++i)
4.163 + {
4.164 + nodesmap[i]->get_bounds(x1, y1, x2, y2);
4.165 +
4.166 + x=(int)((x1+x2)/2);
4.167 + y=(int)((y1+y2)/2);
4.168 +
4.169 + if(x>maxx)maxx=x;
4.170 + if(y>maxy)maxy=y;
4.171 + if(x<minx)minx=x;
4.172 + if(y<miny)miny=y;
4.173 + }
4.174 +
4.175 + double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80);
4.176 + double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80);
4.177 +
4.178 + set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2));
4.179 + return 0;
4.180 +};
4.181 +
4.182 +
4.183 +///This function moves only one node of displayed_graph,
4.184 +///but recalculate the location of weight point,
4.185 +///and also redraw the sides of the planefigure.
4.186 +bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
4.187 +{
4.188 + switch(e->type)
4.189 + {
4.190 + case GDK_BUTTON_PRESS:
4.191 + clicked_x=e->button.x;
4.192 + clicked_y=e->button.y;
4.193 + active_item=(get_item_at(e->button.x, e->button.y));
4.194 + isbutton=true;
4.195 + break;
4.196 + case GDK_BUTTON_RELEASE:
4.197 + isbutton=false;
4.198 + active_item=NULL;
4.199 + break;
4.200 + case GDK_MOTION_NOTIFY:
4.201 + if(isbutton)
4.202 + {
4.203 + double dx=e->motion.x-clicked_x;
4.204 + double dy=e->motion.y-clicked_y;
4.205 + active_item->move(dx, dy);
4.206 + clicked_x=e->motion.x;
4.207 + clicked_y=e->motion.y;
4.208 +
4.209 + EdgeIt e;
4.210 +
4.211 + g.firstOut(e,n);
4.212 + for(;e!=INVALID;g.nextOut(e))
4.213 + {
4.214 + Gnome::Canvas::Points coos;
4.215 + double x1, x2, y1, y2;
4.216 +
4.217 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
4.218 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
4.219 +
4.220 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
4.221 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
4.222 +
4.223 + edgesmap[e]->property_points().set_value(coos);
4.224 +
4.225 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
4.226 +
4.227 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
4.228 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
4.229 + }
4.230 +
4.231 + g.firstIn(e,n);
4.232 + for(;e!=INVALID;g.nextIn(e))
4.233 + {
4.234 + Gnome::Canvas::Points coos;
4.235 + double x1, x2, y1, y2;
4.236 +
4.237 + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2);
4.238 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
4.239 +
4.240 + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2);
4.241 + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
4.242 +
4.243 + edgesmap[e]->property_points().set_value(coos);
4.244 +
4.245 + edgesmap[e]->get_bounds(x1, y1, x2, y2);
4.246 +
4.247 + edgetextmap[e]->property_x().set_value((x1+x2)/2);
4.248 + edgetextmap[e]->property_y().set_value((y1+y2)/2);
4.249 + }
4.250 + }
4.251 + default: break;
4.252 + }
4.253 + return true;
4.254 +}
4.255 +
4.256 +bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event)
4.257 +{
4.258 + Gnome::Canvas::CanvasAA::on_expose_event(event);
4.259 + //usleep(10000);
4.260 + //rezoom();
4.261 + return true;
4.262 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/graph_displayer_canvas.h Wed May 11 16:55:18 2005 +0000
5.3 @@ -0,0 +1,65 @@
5.4 +// -*- C++ -*- //
5.5 +
5.6 +#ifndef GRAPH_DISPLAYER_CANVAS_H
5.7 +#define GRAPH_DISPLAYER_CANVAS_H
5.8 +
5.9 +#include <all_include.h>
5.10 +#include <mapstorage.h>
5.11 +#include <libgnomecanvasmm.h>
5.12 +#include <libgnomecanvasmm/polygon.h>
5.13 +
5.14 +class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
5.15 +{
5.16 + typedef Gnome::Canvas::CanvasAA Parent;
5.17 +
5.18 +public:
5.19 + GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
5.20 + virtual ~GraphDisplayerCanvas();
5.21 +
5.22 + int changeLineWidth (std::string mapname);
5.23 + int changeColor (std::string mapname);
5.24 + int changeText (std::string mapname);
5.25 + int rezoom();
5.26 +
5.27 +protected:
5.28 +
5.29 + virtual bool on_expose_event(GdkEventExpose *);
5.30 +
5.31 +private:
5.32 +
5.33 + ///Event handler function that handles dragging nodes of displayed_graph
5.34 + bool event_handler(GdkEvent* e, Node n);
5.35 +
5.36 + ///The graph, on which we work
5.37 + Graph g;
5.38 + ///Map of nodes of planefigure
5.39 + Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
5.40 + ///Map of edges of planefigure
5.41 + Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
5.42 +
5.43 + ///Map of texts to write on edges
5.44 + Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
5.45 +
5.46 + ///Group of graphical elements of displayed_graph
5.47 + Gnome::Canvas::Group displayed_graph;
5.48 +
5.49 + ///Here we store the maps that can be displayed through properties.
5.50 + MapStorage mapstorage;
5.51 +
5.52 + ///Indicates whether the button of mouse is pressed or not
5.53 + bool isbutton;
5.54 +
5.55 + ///At this location was the mousebutton pressed.
5.56 + ///It helps to calculate the distance of dragging.
5.57 + double clicked_x, clicked_y;
5.58 +
5.59 + ///Remembers which Gnome::Canvas::Item was pressed.
5.60 + ///this variable is needed, because
5.61 + ///1. we cannot query the item at he cursor as fast as it could not cause a Segmentation Fault
5.62 + ///2. we would like to handle only ony item per movement, therefore quering it is not a working solution
5.63 + Gnome::Canvas::Item * active_item;
5.64 +
5.65 +
5.66 +};
5.67 +
5.68 +#endif //GRAPH_DISPLAYER_CANVAS_H
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/graphocska.lgf Wed May 11 16:55:18 2005 +0000
6.3 @@ -0,0 +1,39 @@
6.4 +@nodeset
6.5 +id coordinates_x coordinates_y data
6.6 +1 230 -80 1
6.7 +2 230 100 3
6.8 +3 120 -80 5
6.9 +4 120 100 7
6.10 +5 20 100 9
6.11 +6 20 -80 11
6.12 +7 -40 10 13
6.13 +8 -100 100 15
6.14 +9 -100 10 17
6.15 +10 -100 -80 19
6.16 +11 -200 -80 21
6.17 +12 -200 10 23
6.18 +13 -200 100 25
6.19 +14 -300 100 27
6.20 +15 -300 -80 29
6.21 +
6.22 +@edgeset
6.23 + cap map1 map2 map3 map4
6.24 +15 14 1 21 111 231 3
6.25 +14 13 2 22 112 232 6
6.26 +13 12 3 23 113 233 9
6.27 +13 8 4 24 114 234 12
6.28 +12 11 5 25 115 235 15
6.29 +12 9 6 26 116 236 18
6.30 +11 10 7 27 117 237 21
6.31 +10 9 8 28 118 238 24
6.32 +10 7 9 29 119 239 27
6.33 +9 8 10 30 120 230 30
6.34 +7 6 11 31 121 241 33
6.35 +6 5 12 32 122 242 36
6.36 +6 3 13 33 123 243 39
6.37 +5 4 14 34 124 244 42
6.38 +4 3 15 35 125 245 45
6.39 +3 2 16 36 126 246 48
6.40 +2 1 17 37 127 247 51
6.41 +
6.42 +@end
6.43 \ No newline at end of file
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/main_win.cc Wed May 11 16:55:18 2005 +0000
7.3 @@ -0,0 +1,69 @@
7.4 +#include <main_win.h>
7.5 +
7.6 +MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm, MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),gd_canvas(graph, cm, ms)
7.7 +{
7.8 + set_title (title);
7.9 + set_default_size(WIN_WIDTH,WIN_HEIGHT);
7.10 + add(vbox);
7.11 +
7.12 + ag=Gtk::ActionGroup::create();
7.13 + ag->add( Gtk::Action::create("ShowMenu", "_Show") );
7.14 + ag->add( Gtk::Action::create("ShowMaps", "_Maps"), sigc::mem_fun(*this, &MainWin::showMaps));
7.15 + ag->add( Gtk::Action::create("FileMenu", "_File") );
7.16 + ag->add( Gtk::Action::create("FileQuit", "_Quit"), sigc::mem_fun(*this, &MainWin::quit));
7.17 + ag->add( Gtk::Action::create("ZoomMenu", "_Zoom") );
7.18 + ag->add( Gtk::Action::create("ZoomRezoom", "_Rezoom"), sigc::mem_fun(*this, &MainWin::rezoom)); //!!!!!!
7.19 +
7.20 + uim=Gtk::UIManager::create();
7.21 + uim->insert_action_group(ag);
7.22 + add_accel_group(uim->get_accel_group());
7.23 +
7.24 + try
7.25 + {
7.26 +
7.27 + Glib::ustring ui_info =
7.28 + "<ui>"
7.29 + " <menubar name='MenuBar'>"
7.30 + " <menu action='FileMenu'>"
7.31 + " <menuitem action='FileQuit'/>"
7.32 + " </menu>"
7.33 + " <menu action='ShowMenu'>"
7.34 + " <menuitem action='ShowMaps'/>"
7.35 + " </menu>"
7.36 + " <menu action='ZoomMenu'>"
7.37 + " <menuitem action='ZoomRezoom'/>"
7.38 + " </menu>"
7.39 + " </menubar>"
7.40 + "</ui>";
7.41 +
7.42 + uim->add_ui_from_string(ui_info);
7.43 +
7.44 + }
7.45 + catch(const Glib::Error& ex)
7.46 + {
7.47 + std::cerr << "building menus failed: " << ex.what();
7.48 + }
7.49 +
7.50 + Gtk::Widget* menubar = uim->get_widget("/MenuBar");
7.51 + if(menubar)vbox.pack_start(*menubar, Gtk::PACK_SHRINK);
7.52 +
7.53 + vbox.pack_start(gd_canvas);
7.54 +
7.55 + show_all_children();
7.56 +}
7.57 +
7.58 +void MainWin::showMaps()
7.59 +{
7.60 + mapwin.show();
7.61 +}
7.62 +
7.63 +void MainWin::quit()
7.64 +{
7.65 + hide();
7.66 +}
7.67 +
7.68 +void MainWin::rezoom()
7.69 +{
7.70 + gd_canvas.rezoom();
7.71 +}
7.72 +
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/main_win.h Wed May 11 16:55:18 2005 +0000
8.3 @@ -0,0 +1,44 @@
8.4 +// -*- C++ -*- //
8.5 +
8.6 +#ifndef MAIN_WIN_H
8.7 +#define MAIN_WIN_H
8.8 +
8.9 +#include <all_include.h>
8.10 +#include <mapstorage.h>
8.11 +#include <map_win.h>
8.12 +#include <libgnomecanvasmm.h>
8.13 +#include <libgnomecanvasmm/polygon.h>
8.14 +
8.15 +class MainWin : public Gtk::Window
8.16 +{
8.17 +public:
8.18 + MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
8.19 +
8.20 +protected:
8.21 + //Window of map-showing setup
8.22 + MapWin mapwin;
8.23 +
8.24 + //Member widgets:
8.25 + GraphDisplayerCanvas gd_canvas;
8.26 +
8.27 + //ActionGroup for menu
8.28 + Glib::RefPtr<Gtk::ActionGroup> ag;
8.29 +
8.30 + //UIManager for menu
8.31 + Glib::RefPtr<Gtk::UIManager> uim;
8.32 +
8.33 + //Container
8.34 + Gtk::VBox vbox;
8.35 +
8.36 + //Pops up map-setup window
8.37 + virtual void showMaps();
8.38 +
8.39 + //Exit
8.40 + virtual void quit();
8.41 +
8.42 + //Refit screen
8.43 + virtual void rezoom();
8.44 +
8.45 +};
8.46 +
8.47 +#endif //MAIN_WIN_H
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/map_win.cc Wed May 11 16:55:18 2005 +0000
9.3 @@ -0,0 +1,116 @@
9.4 +#include <map_win.h>
9.5 +#include <set>
9.6 +
9.7 +MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
9.8 +{
9.9 + set_title(title);
9.10 + set_default_size(400, 200);
9.11 +
9.12 + rb_array=new Gtk::RadioButton * [PROPERTY_NUM];
9.13 + vbox_r1=new Gtk::VBox[PROPERTY_NUM];
9.14 + vbox_r2=new Gtk::VBox[PROPERTY_NUM];
9.15 + radios=new Gtk::HBox[PROPERTY_NUM];
9.16 + for(int i=0;i<PROPERTY_NUM;i++)
9.17 + {
9.18 + rb_array[i]=new Gtk::RadioButton[ms.numOfEdgeMaps()+1];
9.19 +
9.20 + Gtk::RadioButton::Group group;
9.21 +
9.22 + std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
9.23 + std::set<int> props;
9.24 +
9.25 + int actprop;
9.26 + for(int j=0;j<ms.numOfEdgeMaps();j++)
9.27 + {
9.28 +
9.29 + if(emsi->second==&(ms.default_edgemaps[i]))
9.30 + {
9.31 + actprop=j;
9.32 + }
9.33 + for(int k=0;k<PROPERTY_NUM;k++)
9.34 + {
9.35 + if(emsi->second==&(ms.default_edgemaps[k]))
9.36 + {
9.37 + props.insert(j);
9.38 + }
9.39 + }
9.40 + emsi++;
9.41 + }
9.42 +
9.43 + rb_array[i][0].set_group(group);
9.44 + rb_array[i][0].set_label("Default");
9.45 + rb_array[i][0].signal_clicked().connect( sigc::bind( sigc::bind( sigc::mem_fun(*this, &MapWin::radio_click), 0), i) );
9.46 + vbox_r1[i].pack_start(rb_array[i][0]);
9.47 +
9.48 +
9.49 + emsi=ms.beginOfEdgeMaps();
9.50 + int actpos=1;
9.51 + for(int j=0;j<ms.numOfEdgeMaps();j++)
9.52 + {
9.53 + if( ( props.find(j) )==( props.end() ) )
9.54 + {
9.55 + rb_array[i][actpos].set_group(group);
9.56 + rb_array[i][actpos].set_label(emsi->first);
9.57 + rb_array[i][actpos].signal_clicked().connect
9.58 + (
9.59 + sigc::bind(
9.60 + sigc::bind(
9.61 + sigc::mem_fun(*this, &MapWin::radio_click),
9.62 + actpos
9.63 + ),
9.64 + i
9.65 + )
9.66 + );
9.67 +
9.68 + if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
9.69 + {
9.70 + vbox_r1[i].pack_start(rb_array[i][actpos]);
9.71 + }
9.72 + else
9.73 + {
9.74 + vbox_r2[i].pack_start(rb_array[i][actpos]);
9.75 + }
9.76 + actpos++;
9.77 + }
9.78 + emsi++;
9.79 + }
9.80 + radios[i].pack_start(vbox_r1[i]);
9.81 + radios[i].pack_start(vbox_r2[i]);
9.82 + notebook.append_page(radios[i], property_strings[i]);
9.83 + }
9.84 +
9.85 + add(vbox_b);
9.86 + vbox_b.pack_start(notebook);
9.87 +
9.88 + show_all_children();
9.89 +
9.90 +}
9.91 +
9.92 +void MapWin::radio_click(int prop, int actpos)
9.93 +{
9.94 + if(rb_array[prop][actpos].get_active())
9.95 + {
9.96 +
9.97 + std::string mapname=rb_array[prop][actpos].get_label();
9.98 +
9.99 + if(mapname=="Default")
9.100 + {
9.101 + mapname=property_strings[prop];
9.102 + }
9.103 +
9.104 + switch(prop)
9.105 + {
9.106 + case WIDTH:
9.107 + gdc.changeLineWidth(mapname);
9.108 + break;
9.109 + case COLOR:
9.110 + gdc.changeColor(mapname);
9.111 + break;
9.112 + case TEXT:
9.113 + gdc.changeText(mapname);
9.114 + break;
9.115 + default:
9.116 + std::cout<<"Error\n";
9.117 + }
9.118 + }
9.119 +};
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/map_win.h Wed May 11 16:55:18 2005 +0000
10.3 @@ -0,0 +1,30 @@
10.4 +// -*- C++ -*- //
10.5 +
10.6 +#ifndef MAP_WIN_H
10.7 +#define MAP_WIN_H
10.8 +
10.9 +#include <all_include.h>
10.10 +#include <mapstorage.h>
10.11 +#include <graph_displayer_canvas.h>
10.12 +#include <libgnomecanvasmm.h>
10.13 +#include <libgnomecanvasmm/polygon.h>
10.14 +
10.15 +class MapWin : public Gtk::Window
10.16 +{
10.17 +protected:
10.18 + GraphDisplayerCanvas & gdc;
10.19 + MapStorage & ms;
10.20 +
10.21 + Gtk::HBox * radios;
10.22 + Gtk::RadioButton ** rb_array;
10.23 +
10.24 + Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
10.25 + Gtk::Notebook notebook;
10.26 + Gtk::Label * labels;
10.27 +
10.28 +public:
10.29 + MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
10.30 + virtual void radio_click(int, int);
10.31 +};
10.32 +
10.33 +#endif //MAP_WIN_H
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/mapstorage.cc Wed May 11 16:55:18 2005 +0000
11.3 @@ -0,0 +1,89 @@
11.4 +#include <mapstorage.h>
11.5 +
11.6 +MapStorage::MapStorage(Graph & graph):g(graph)
11.7 +{
11.8 + for(int i=0;i<PROPERTY_NUM;i++)
11.9 + {
11.10 + Graph::EdgeMap<double> emd(g);
11.11 + default_edgemaps.push_back(emd);
11.12 + Graph::NodeMap<double> nmd(g);
11.13 + default_nodemaps.push_back(nmd);
11.14 + }
11.15 +
11.16 + //std::string defaultstr="Default ";
11.17 + for(int i=0;i<PROPERTY_NUM;i++)
11.18 + {
11.19 + for (EdgeIt j(g); j!=INVALID; ++j)
11.20 + {
11.21 + (default_edgemaps[i])[j]=property_defaults[i];
11.22 + }
11.23 + addEdgeMap(property_strings[i],&(default_edgemaps[i]));
11.24 + }
11.25 +
11.26 +};
11.27 +
11.28 +int MapStorage::addNodeMap(const std::string & name, Graph::NodeMap<double> *nodemap)
11.29 +{
11.30 + nodemap_storage[name]=nodemap;
11.31 + return 0;
11.32 +}
11.33 +int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
11.34 +{
11.35 + edgemap_storage[name]=edgemap;
11.36 + return 0;
11.37 +}
11.38 +
11.39 +double MapStorage::maxOfNodeMap(const std::string & name)
11.40 +{
11.41 + double max=0;
11.42 + for (NodeIt j(g); j!=INVALID; ++j)
11.43 + {
11.44 + if( (*nodemap_storage[name])[j]>max )
11.45 + {
11.46 + max=(*nodemap_storage[name])[j];
11.47 + }
11.48 + }
11.49 + return max;
11.50 +}
11.51 +
11.52 +double MapStorage::maxOfEdgeMap(const std::string & name)
11.53 +{
11.54 + double max=0;
11.55 + for (EdgeIt j(g); j!=INVALID; ++j)
11.56 + {
11.57 + if( (*edgemap_storage[name])[j]>max )
11.58 + {
11.59 + max=(*edgemap_storage[name])[j];
11.60 + }
11.61 + }
11.62 + return max;
11.63 +}
11.64 +
11.65 +double MapStorage::minOfNodeMap(const std::string & name)
11.66 +{
11.67 + NodeIt j(g);
11.68 + double min=(*nodemap_storage[name])[j];
11.69 + for (; j!=INVALID; ++j)
11.70 + {
11.71 + if( (*nodemap_storage[name])[j]<min )
11.72 + {
11.73 + min=(*nodemap_storage[name])[j];
11.74 + }
11.75 + }
11.76 + return min;
11.77 +}
11.78 +
11.79 +double MapStorage::minOfEdgeMap(const std::string & name)
11.80 +{
11.81 + EdgeIt j(g);
11.82 + double min=(*edgemap_storage[name])[j];
11.83 + for (EdgeIt j(g); j!=INVALID; ++j)
11.84 + {
11.85 + if( (*edgemap_storage[name])[j]<min )
11.86 + {
11.87 + min=(*edgemap_storage[name])[j];
11.88 + }
11.89 + }
11.90 + return min;
11.91 +}
11.92 +
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/mapstorage.h Wed May 11 16:55:18 2005 +0000
12.3 @@ -0,0 +1,37 @@
12.4 +// -*- C++ -*- //
12.5 +
12.6 +#ifndef MAPSTORAGE_H
12.7 +#define MAPSTORAGE_H
12.8 +
12.9 +#include <all_include.h>
12.10 +
12.11 +class MapStorage
12.12 +{
12.13 +
12.14 +public: ///!!!!!!!!
12.15 + Graph g;
12.16 + std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
12.17 + std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
12.18 +
12.19 + std::vector<Graph::NodeMap<double> > default_nodemaps;
12.20 + std::vector<Graph::EdgeMap<double> > default_edgemaps;
12.21 +
12.22 +public:
12.23 + MapStorage(Graph &);
12.24 + int addNodeMap(const std::string &,Graph::NodeMap<double> *);
12.25 + int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
12.26 +
12.27 + int numOfNodeMaps() {return nodemap_storage.size();};
12.28 + int numOfEdgeMaps() {return edgemap_storage.size();};
12.29 +
12.30 + double maxOfNodeMap(const std::string &);
12.31 + double maxOfEdgeMap(const std::string &);
12.32 +
12.33 + double minOfNodeMap(const std::string &);
12.34 + double minOfEdgeMap(const std::string &);
12.35 +
12.36 + std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
12.37 + std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
12.38 +};
12.39 +
12.40 +#endif //MAPSTORAGE_H
13.1 --- a/src/Makefile.am Thu May 05 15:34:43 2005 +0000
13.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
13.3 @@ -1,6 +0,0 @@
13.4 -AM_CPPFLAGS = -I$(top_srcdir)/src
13.5 -LDADD = $(top_builddir)/src/lemon/libemon.la
13.6 -
13.7 -bin_PROGRAMS = gui
13.8 -
13.9 -gui_SOURCES = main.cc
14.1 --- a/src/main.cc Thu May 05 15:34:43 2005 +0000
14.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
14.3 @@ -1,10 +0,0 @@
14.4 -#ifdef HAVE_CONFIG_H
14.5 -#include <config.h>
14.6 -#endif
14.7 -
14.8 -#include <iostream>
14.9 -
14.10 -int main()
14.11 -{
14.12 - std::cout << "Hello World!" << std::endl;
14.13 -}