1.1 --- a/gui/graph-displayer.cc Thu May 26 16:32:26 2005 +0000
1.2 +++ b/gui/graph-displayer.cc Fri May 27 10:34:20 2005 +0000
1.3 @@ -12,6 +12,9 @@
1.4
1.5 int main(int argc, char *argv[])
1.6 {
1.7 +
1.8 + //initializing
1.9 +
1.10 property_strings=new std::string[PROPERTY_NUM];
1.11 property_strings[WIDTH]="Width";
1.12 property_strings[COLOR]="Color";
1.13 @@ -34,13 +37,14 @@
1.14
1.15 CoordinatesMap cm(g);
1.16 Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g);
1.17 + Graph::NodeMap<double> nodedata (g);
1.18
1.19 //we create one object to read x coordinates
1.20 //and one to read y coordinate of nodes and write them to cm NodeMap.
1.21 -
1.22 XMap <CoordinatesMap> xreader (cm);
1.23 YMap <CoordinatesMap> yreader (cm);
1.24 - Graph::NodeMap<double> nodedata (g);
1.25 +
1.26 + //reading in graph and its maps
1.27
1.28 std::ifstream is(argv[1]);
1.29
1.30 @@ -55,6 +59,8 @@
1.31 reader.readEdgeMap("map4", map4);
1.32 reader.run();
1.33
1.34 + //initializing MapStorage with the read data
1.35 +
1.36 MapStorage ms(g);
1.37 ms.addNodeMap("data",&nodedata);
1.38 ms.addEdgeMap("cap",&cap);
1.39 @@ -63,6 +69,8 @@
1.40 ms.addEdgeMap("map3",&map3);
1.41 ms.addEdgeMap("map4",&map4);
1.42
1.43 + //initializing GUI
1.44 +
1.45 Gnome::Canvas::init();
1.46 Gtk::Main app(argc, argv);
1.47
2.1 --- a/gui/graph_displayer_canvas.cc Thu May 26 16:32:26 2005 +0000
2.2 +++ b/gui/graph_displayer_canvas.cc Fri May 27 10:34:20 2005 +0000
2.3 @@ -1,19 +1,26 @@
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
2.10 + //first edges are drawn, to hide joining with nodes later
2.11 +
2.12 for (EdgeIt i(g); i!=INVALID; ++i)
2.13 {
2.14 +
2.15 + //drawing green lines, coordinates are from cm
2.16 +
2.17 Gnome::Canvas::Points coos;
2.18 coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y));
2.19 coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y));
2.20
2.21 edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos);
2.22 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
2.23 - edgesmap[i]->property_width_pixels().set_value(10);
2.24 + edgesmap[i]->property_width_pixels().set_value(10);
2.25
2.26 -
2.27 + //initializing edge-text as well, to empty string
2.28 +
2.29 double x1, x2, y1, y2;
2.30 edgesmap[i]->get_bounds(x1, y1, x2, y2);
2.31
2.32 @@ -21,22 +28,30 @@
2.33 edgetextmap[i]->property_fill_color().set_value("black");
2.34 }
2.35
2.36 + //afterwards nodes come to be drawn
2.37 +
2.38 NodeIt i(g);
2.39 int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y;
2.40
2.41 for (; i!=INVALID; ++i)
2.42 {
2.43 + //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen)
2.44 +
2.45 if(cm[i].x>maxx)maxx=(int)cm[i].x;
2.46 if(cm[i].y>maxy)maxy=(int)cm[i].y;
2.47 if(cm[i].x<minx)minx=(int)cm[i].x;
2.48 if(cm[i].y<miny)miny=(int)cm[i].y;
2.49
2.50 + //drawing bule nodes, with black line around them
2.51 +
2.52 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.53 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
2.54 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
2.55 (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i));
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 @@ -49,28 +64,32 @@
2.64
2.65 GraphDisplayerCanvas::~GraphDisplayerCanvas()
2.66 {
2.67 - Graph::NodeMap <int> id(g);
2.68 - Graph::NodeMap <double> xc(g);
2.69 - Graph::NodeMap <double> yc(g);
2.70
2.71 - int j=1;
2.72 + //writing out the end state of the graph
2.73 + //\todo all the maps has to be write out!
2.74
2.75 - for (NodeIt i(g); i!=INVALID; ++i)
2.76 - {
2.77 - double x1,y1,x2,y2;
2.78 - nodesmap[i]->get_bounds(x1, y1, x2, y2);
2.79 + Graph::NodeMap <int> id(g);
2.80 + Graph::NodeMap <double> xc(g);
2.81 + Graph::NodeMap <double> yc(g);
2.82 +
2.83 + int j=1;
2.84 +
2.85 + for (NodeIt i(g); i!=INVALID; ++i)
2.86 + {
2.87 + double x1,y1,x2,y2;
2.88 + nodesmap[i]->get_bounds(x1, y1, x2, y2);
2.89 +
2.90 + id[i]=j++;
2.91 + xc[i]=(x1+x2)/2;
2.92 + yc[i]=(y1+y2)/2;
2.93 + }
2.94
2.95 - id[i]=j++;
2.96 - xc[i]=(x1+x2)/2;
2.97 - yc[i]=(y1+y2)/2;
2.98 - }
2.99 -
2.100 - GraphWriter<Graph> writer(std::cout,g);
2.101 -
2.102 - writer.writeNodeMap("id", id);
2.103 - writer.writeNodeMap("coordinates_x", xc);
2.104 - writer.writeNodeMap("coordinates_y", yc);
2.105 - writer.run();
2.106 + GraphWriter<Graph> writer(std::cout,g);
2.107 +
2.108 + writer.writeNodeMap("id", id);
2.109 + writer.writeNodeMap("coordinates_x", xc);
2.110 + writer.writeNodeMap("coordinates_y", yc);
2.111 + writer.run();
2.112 }
2.113
2.114 int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
2.115 @@ -85,6 +104,11 @@
2.116
2.117 int GraphDisplayerCanvas::changeColor (std::string mapname)
2.118 {
2.119 +
2.120 + //function maps the range of the maximum and
2.121 + //the minimum of the nodemap to the range of
2.122 + //green in RGB
2.123 +
2.124 for (EdgeIt i(g); i!=INVALID; ++i)
2.125 {
2.126 double w=(*(mapstorage.edgemap_storage)[mapname])[i];
2.127 @@ -109,6 +133,13 @@
2.128
2.129 int GraphDisplayerCanvas::changeText (std::string mapname)
2.130 {
2.131 +
2.132 + //the number in the map will be written on the edge
2.133 + //EXCEPT when the name of the map is Text, because
2.134 + //in that case empty string will be written, because
2.135 + //that is the deleter map
2.136 + //\todo isn't it a bit woodcutter?
2.137 +
2.138 for (EdgeIt i(g); i!=INVALID; ++i)
2.139 {
2.140 if(mapname!="Text")
2.141 @@ -145,6 +176,13 @@
2.142
2.143 int GraphDisplayerCanvas::rezoom ()
2.144 {
2.145 +
2.146 + //searches for the minimum and the maximum
2.147 + //value of the coordinates of the nodes to
2.148 + //set the pixel rpo unit to a value to be
2.149 + //able to see the whole graph in the canvas
2.150 + //\todo does not work properly
2.151 +
2.152 double x1, x2, y1, y2;
2.153 int x,y;
2.154
2.155 @@ -177,14 +215,12 @@
2.156 };
2.157
2.158
2.159 -///This function moves only one node of displayed_graph,
2.160 -///but recalculate the location of weight point,
2.161 -///and also redraw the sides of the planefigure.
2.162 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n)
2.163 {
2.164 switch(e->type)
2.165 {
2.166 case GDK_BUTTON_PRESS:
2.167 + //we mark the location of the event to be able to calculate parameters of dragging
2.168 clicked_x=e->button.x;
2.169 clicked_y=e->button.y;
2.170 active_item=(get_item_at(e->button.x, e->button.y));
2.171 @@ -195,16 +231,23 @@
2.172 active_item=NULL;
2.173 break;
2.174 case GDK_MOTION_NOTIFY:
2.175 + //we only have to do sg. if the mouse button is pressed
2.176 if(isbutton)
2.177 {
2.178 + //new coordinates will be the old values,
2.179 + //because the item will be moved to the
2.180 + //new coordinate therefore the new movement
2.181 + //has to be calculated from here
2.182 +
2.183 double dx=e->motion.x-clicked_x;
2.184 double dy=e->motion.y-clicked_y;
2.185 active_item->move(dx, dy);
2.186 clicked_x=e->motion.x;
2.187 clicked_y=e->motion.y;
2.188
2.189 + //all the edges connected to the moved point has to be redrawn
2.190 +
2.191 EdgeIt e;
2.192 -
2.193 g.firstOut(e,n);
2.194 for(;e!=INVALID;g.nextOut(e))
2.195 {
3.1 --- a/gui/graph_displayer_canvas.h Thu May 26 16:32:26 2005 +0000
3.2 +++ b/gui/graph_displayer_canvas.h Fri May 27 10:34:20 2005 +0000
3.3 @@ -8,6 +8,7 @@
3.4 #include <libgnomecanvasmm.h>
3.5 #include <libgnomecanvasmm/polygon.h>
3.6
3.7 +///This class is the canvas, on which the graph can be drawn.
3.8 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA
3.9 {
3.10 typedef Gnome::Canvas::CanvasAA Parent;
3.11 @@ -16,25 +17,40 @@
3.12 GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
3.13 virtual ~GraphDisplayerCanvas();
3.14
3.15 + ///Changes the linewidth attribute according to the given map.
3.16 + ///\param mapname is the name of the map which contains the new values
3.17 int changeLineWidth (std::string mapname);
3.18 +
3.19 + ///Changes the linecolor attribute according to the given map.
3.20 + ///\param mapname is the name of the map which contains the new values
3.21 int changeColor (std::string mapname);
3.22 +
3.23 + ///Changes the text of line attribute according to the given map.
3.24 + ///\param mapname is the name of the map which contains the new values
3.25 int changeText (std::string mapname);
3.26 +
3.27 + ///Changes the dot-pro-pixel to be able to show the whole graph.
3.28 int rezoom();
3.29
3.30 protected:
3.31
3.32 + //maximizing, minimizing, restoring window, etc.
3.33 virtual bool on_expose_event(GdkEventExpose *);
3.34
3.35 private:
3.36
3.37 - ///Event handler function that handles dragging nodes of displayed_graph
3.38 + ///This function is responsible for the correct
3.39 + ///reaction of any action happened in the territory
3.40 + ///of the canvas
3.41 bool event_handler(GdkEvent* e, Node n);
3.42
3.43 ///The graph, on which we work
3.44 Graph g;
3.45 - ///Map of nodes of planefigure
3.46 +
3.47 + ///Map of nodes of graph
3.48 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap;
3.49 - ///Map of edges of planefigure
3.50 +
3.51 + ///Map of edges of graph
3.52 Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
3.53
3.54 ///Map of texts to write on edges
4.1 --- a/gui/main_win.h Thu May 26 16:32:26 2005 +0000
4.2 +++ b/gui/main_win.h Fri May 27 10:34:20 2005 +0000
4.3 @@ -9,34 +9,41 @@
4.4 #include <libgnomecanvasmm.h>
4.5 #include <libgnomecanvasmm/polygon.h>
4.6
4.7 +///This class is the main window of GUI.
4.8 +///It has menus, but the main part of it is the canvas.
4.9 class MainWin : public Gtk::Window
4.10 {
4.11 public:
4.12 + ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn.
4.13 + ///\param title is the title of the window
4.14 + ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas
4.15 + ///\param cm stores the coordinates of the nodes of the graph
4.16 + ///\param ms is the \ref MapStorage in which the different visualizable maps are stored
4.17 MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &);
4.18
4.19 protected:
4.20 - //Window of map-showing setup
4.21 + ///Window of map-showing setup. Its type is \ref MapWin
4.22 MapWin mapwin;
4.23
4.24 - //Member widgets:
4.25 + ///The graph will be drawn on this \ref GraphDisplayerCanvas
4.26 GraphDisplayerCanvas gd_canvas;
4.27
4.28 - //ActionGroup for menu
4.29 + ///ActionGroup for menu
4.30 Glib::RefPtr<Gtk::ActionGroup> ag;
4.31
4.32 - //UIManager for menu
4.33 + ///UIManager for menu
4.34 Glib::RefPtr<Gtk::UIManager> uim;
4.35
4.36 - //Container
4.37 + ///Container
4.38 Gtk::VBox vbox;
4.39
4.40 - //Pops up map-setup window
4.41 + ///This function makes map-setup window popped up.
4.42 virtual void showMaps();
4.43
4.44 - //Exit
4.45 + ///Exit
4.46 virtual void quit();
4.47
4.48 - //Refit screen
4.49 + ///Refit screen to be able to show the whole graph.
4.50 virtual void rezoom();
4.51
4.52 };
5.1 --- a/gui/map_win.cc Thu May 26 16:32:26 2005 +0000
5.2 +++ b/gui/map_win.cc Fri May 27 10:34:20 2005 +0000
5.3 @@ -3,6 +3,9 @@
5.4
5.5 MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
5.6 {
5.7 +
5.8 + //most nem kommentezem fel, mert ugyis valtozik
5.9 +
5.10 set_title(title);
5.11 set_default_size(400, 200);
5.12
5.13 @@ -88,6 +91,9 @@
5.14
5.15 void MapWin::radio_click(int prop, int actpos)
5.16 {
5.17 +
5.18 + //most nem kommentezem fel, mert ugyis valtozik
5.19 +
5.20 if(rb_array[prop][actpos].get_active())
5.21 {
5.22
6.1 --- a/gui/map_win.h Thu May 26 16:32:26 2005 +0000
6.2 +++ b/gui/map_win.h Fri May 27 10:34:20 2005 +0000
6.3 @@ -9,21 +9,40 @@
6.4 #include <libgnomecanvasmm.h>
6.5 #include <libgnomecanvasmm/polygon.h>
6.6
6.7 +///This class is responsible for creating a window,
6.8 +///on which the visualization attributes can be
6.9 +///assigned to maps.
6.10 class MapWin : public Gtk::Window
6.11 {
6.12 protected:
6.13 + ///The \ref GraphDisplayerCanvas on which the graph will be drawn.
6.14 + ///It has to be known for this class, because
6.15 + ///when a map assigned to a certain attribute
6.16 + ///a function of the \ref GraphDisplayerCanvas will be called.
6.17 GraphDisplayerCanvas & gdc;
6.18 +
6.19 + ///The \ref MapStorage in which the visualizable maps are stored
6.20 MapStorage & ms;
6.21
6.22 +
6.23 Gtk::HBox * radios;
6.24 Gtk::RadioButton ** rb_array;
6.25
6.26 Gtk::VBox vbox_b, * vbox_r1, * vbox_r2;
6.27 +
6.28 + ///The notebook has different pages for each attribute.
6.29 Gtk::Notebook notebook;
6.30 +
6.31 Gtk::Label * labels;
6.32
6.33 public:
6.34 + ///Constructor of MapWin creates the widgets shown in MapWin.
6.35 MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
6.36 +
6.37 + ///If a radiobutton is clicked, this function determines
6.38 + ///which button was that and after that calls the
6.39 + ///appropriate function of the \ref GraphDisplayerCanvas
6.40 + ///to change the visible values of that attribute.
6.41 virtual void radio_click(int, int);
6.42 };
6.43
7.1 --- a/gui/mapstorage.cc Thu May 26 16:32:26 2005 +0000
7.2 +++ b/gui/mapstorage.cc Fri May 27 10:34:20 2005 +0000
7.3 @@ -9,8 +9,6 @@
7.4 Graph::NodeMap<double> nmd(g);
7.5 default_nodemaps.push_back(nmd);
7.6 }
7.7 -
7.8 - //std::string defaultstr="Default ";
7.9 for(int i=0;i<PROPERTY_NUM;i++)
7.10 {
7.11 for (EdgeIt j(g); j!=INVALID; ++j)
7.12 @@ -27,6 +25,7 @@
7.13 nodemap_storage[name]=nodemap;
7.14 return 0;
7.15 }
7.16 +
7.17 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
7.18 {
7.19 edgemap_storage[name]=edgemap;
8.1 --- a/gui/mapstorage.h Thu May 26 16:32:26 2005 +0000
8.2 +++ b/gui/mapstorage.h Fri May 27 10:34:20 2005 +0000
8.3 @@ -5,32 +5,80 @@
8.4
8.5 #include <all_include.h>
8.6
8.7 +///Class MapStorage is responsible for storing
8.8 +///NodeMaps and EdgeMaps that can be shown later
8.9 +///on GUI. Therefore maps can be added to it,
8.10 +///and datas over the added maps can be queried.
8.11 +///The maps will be stored in an std::map,
8.12 +///referenced with their names. Unfortunately at
8.13 +///the moment it works only with double type maps
8.14 +///
8.15 +///\todo too many things are public!!
8.16 class MapStorage
8.17 {
8.18 +public:
8.19
8.20 -public: ///!!!!!!!!
8.21 Graph g;
8.22 +
8.23 + ///Stores double type NodeMaps
8.24 std::map< std::string,Graph::NodeMap<double> * > nodemap_storage;
8.25 +
8.26 + ///Stores double type EdgeMaps
8.27 std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage;
8.28
8.29 + //Stores the default values for the different visualization node attributes
8.30 std::vector<Graph::NodeMap<double> > default_nodemaps;
8.31 +
8.32 + //Stores the default values for the different visualization edge attributes
8.33 std::vector<Graph::EdgeMap<double> > default_edgemaps;
8.34
8.35 public:
8.36 + ///Constructor of MapStorage. Expects the Graph of
8.37 + ///which maps will be stored in it.
8.38 + ///Its all activity is initializing default values
8.39 + ///for different visualization attributes
8.40 + ///
8.41 + ///\param graph is the graph for which the maps are stored in this object.
8.42 MapStorage(Graph &);
8.43 +
8.44 + ///Adds given map to storage. A name and the map itself has to be provided.
8.45 + ///\param name is the name of map
8.46 + ///\nodemap is the pointer of the given nodemap
8.47 + ///\todo map should be given by reference!
8.48 int addNodeMap(const std::string &,Graph::NodeMap<double> *);
8.49 +
8.50 + ///Adds given map to storage. A name and the map itself has to be provided.
8.51 + ///\param name is the name of map
8.52 + ///\edgemap is the pointer of the given edgemap
8.53 + ///\todo map should be given by reference!
8.54 int addEdgeMap(const std::string &,Graph::EdgeMap<double> *);
8.55
8.56 + ///Returns how much nodemaps is stored in \ref MapStorage
8.57 int numOfNodeMaps() {return nodemap_storage.size();};
8.58 +
8.59 + ///Returns how much edgemaps is stored in \ref MapStorage
8.60 int numOfEdgeMaps() {return edgemap_storage.size();};
8.61
8.62 + ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name.
8.63 + ///\param name is the name of map of which maximum is searched
8.64 double maxOfNodeMap(const std::string &);
8.65 +
8.66 + ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name.
8.67 + ///\param name is the name of map of which maximum is searched
8.68 double maxOfEdgeMap(const std::string &);
8.69
8.70 + ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name.
8.71 + ///\param name is the name of map of which minimum is searched
8.72 double minOfNodeMap(const std::string &);
8.73 +
8.74 + ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name.
8.75 + ///\param name is the name of map of which minimum is searched
8.76 double minOfEdgeMap(const std::string &);
8.77
8.78 + ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage.
8.79 std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();};
8.80 +
8.81 + ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage.
8.82 std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();};
8.83 };
8.84