# HG changeset patch # User hegyi # Date 1117190060 0 # Node ID e099638ff23648eab2e147ba8847a026e06e0c40 # Parent bd60a2909c533533a9a48acb98c4cee3651b665d Small documentation is added to GUI diff -r bd60a2909c53 -r e099638ff236 graph-displayer.cc --- a/graph-displayer.cc Mon May 23 04:48:14 2005 +0000 +++ b/graph-displayer.cc Fri May 27 10:34:20 2005 +0000 @@ -12,6 +12,9 @@ int main(int argc, char *argv[]) { + + //initializing + property_strings=new std::string[PROPERTY_NUM]; property_strings[WIDTH]="Width"; property_strings[COLOR]="Color"; @@ -34,13 +37,14 @@ CoordinatesMap cm(g); Graph::EdgeMap cap(g), map1(g), map2(g), map3(g), map4(g); + Graph::NodeMap nodedata (g); //we create one object to read x coordinates //and one to read y coordinate of nodes and write them to cm NodeMap. - XMap xreader (cm); YMap yreader (cm); - Graph::NodeMap nodedata (g); + + //reading in graph and its maps std::ifstream is(argv[1]); @@ -55,6 +59,8 @@ reader.readEdgeMap("map4", map4); reader.run(); + //initializing MapStorage with the read data + MapStorage ms(g); ms.addNodeMap("data",&nodedata); ms.addEdgeMap("cap",&cap); @@ -63,6 +69,8 @@ ms.addEdgeMap("map3",&map3); ms.addEdgeMap("map4",&map4); + //initializing GUI + Gnome::Canvas::init(); Gtk::Main app(argc, argv); diff -r bd60a2909c53 -r e099638ff236 graph_displayer_canvas.cc --- a/graph_displayer_canvas.cc Mon May 23 04:48:14 2005 +0000 +++ b/graph_displayer_canvas.cc Fri May 27 10:34:20 2005 +0000 @@ -1,19 +1,26 @@ #include +#include 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) { + //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); + 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); @@ -21,22 +28,30 @@ 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].xsignal_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); @@ -49,28 +64,32 @@ GraphDisplayerCanvas::~GraphDisplayerCanvas() { - Graph::NodeMap id(g); - Graph::NodeMap xc(g); - Graph::NodeMap yc(g); - int j=1; + //writing out the end state of the graph + //\todo all the maps has to be write out! - for (NodeIt i(g); i!=INVALID; ++i) - { - double x1,y1,x2,y2; - nodesmap[i]->get_bounds(x1, y1, x2, y2); + Graph::NodeMap id(g); + Graph::NodeMap xc(g); + Graph::NodeMap 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; + } - id[i]=j++; - xc[i]=(x1+x2)/2; - yc[i]=(y1+y2)/2; - } - - GraphWriter writer(std::cout,g); - - writer.writeNodeMap("id", id); - writer.writeNodeMap("coordinates_x", xc); - writer.writeNodeMap("coordinates_y", yc); - writer.run(); + GraphWriter 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) @@ -85,6 +104,11 @@ 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]; @@ -109,6 +133,13 @@ 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") @@ -145,6 +176,13 @@ int GraphDisplayerCanvas::rezoom () { + + //searches for the minimum and the maximum + //value of the coordinates of the nodes to + //set the pixel rpo unit to a value to be + //able to see the whole graph in the canvas + //\todo does not work properly + double x1, x2, y1, y2; int x,y; @@ -177,14 +215,12 @@ }; -///This function moves only one node of displayed_graph, -///but recalculate the location of weight point, -///and also redraw the sides of the planefigure. 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)); @@ -195,16 +231,23 @@ 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)) { diff -r bd60a2909c53 -r e099638ff236 graph_displayer_canvas.h --- a/graph_displayer_canvas.h Mon May 23 04:48:14 2005 +0000 +++ b/graph_displayer_canvas.h Fri May 27 10:34:20 2005 +0000 @@ -8,6 +8,7 @@ #include #include +///This class is the canvas, on which the graph can be drawn. class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA { typedef Gnome::Canvas::CanvasAA Parent; @@ -16,25 +17,40 @@ 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); + + ///Changes the dot-pro-pixel to be able to show the whole graph. int rezoom(); protected: + //maximizing, minimizing, restoring window, etc. virtual bool on_expose_event(GdkEventExpose *); private: - ///Event handler function that handles dragging nodes of displayed_graph + ///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 planefigure + + ///Map of nodes of graph Graph::NodeMap nodesmap; - ///Map of edges of planefigure + + ///Map of edges of graph Graph::EdgeMap edgesmap; ///Map of texts to write on edges diff -r bd60a2909c53 -r e099638ff236 main_win.h --- a/main_win.h Mon May 23 04:48:14 2005 +0000 +++ b/main_win.h Fri May 27 10:34:20 2005 +0000 @@ -9,34 +9,41 @@ #include #include +///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 + ///Window of map-showing setup. Its type is \ref MapWin MapWin mapwin; - //Member widgets: + ///The graph will be drawn on this \ref GraphDisplayerCanvas GraphDisplayerCanvas gd_canvas; - //ActionGroup for menu + ///ActionGroup for menu Glib::RefPtr ag; - //UIManager for menu + ///UIManager for menu Glib::RefPtr uim; - //Container + ///Container Gtk::VBox vbox; - //Pops up map-setup window + ///This function makes map-setup window popped up. virtual void showMaps(); - //Exit + ///Exit virtual void quit(); - //Refit screen + ///Refit screen to be able to show the whole graph. virtual void rezoom(); }; diff -r bd60a2909c53 -r e099638ff236 map_win.cc --- a/map_win.cc Mon May 23 04:48:14 2005 +0000 +++ b/map_win.cc Fri May 27 10:34:20 2005 +0000 @@ -3,6 +3,9 @@ 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); @@ -88,6 +91,9 @@ void MapWin::radio_click(int prop, int actpos) { + + //most nem kommentezem fel, mert ugyis valtozik + if(rb_array[prop][actpos].get_active()) { diff -r bd60a2909c53 -r e099638ff236 map_win.h --- a/map_win.h Mon May 23 04:48:14 2005 +0000 +++ b/map_win.h Fri May 27 10:34:20 2005 +0000 @@ -9,21 +9,40 @@ #include #include +///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); }; diff -r bd60a2909c53 -r e099638ff236 mapstorage.cc --- a/mapstorage.cc Mon May 23 04:48:14 2005 +0000 +++ b/mapstorage.cc Fri May 27 10:34:20 2005 +0000 @@ -9,8 +9,6 @@ Graph::NodeMap nmd(g); default_nodemaps.push_back(nmd); } - - //std::string defaultstr="Default "; for(int i=0;i *edgemap) { edgemap_storage[name]=edgemap; diff -r bd60a2909c53 -r e099638ff236 mapstorage.h --- a/mapstorage.h Mon May 23 04:48:14 2005 +0000 +++ b/mapstorage.h Fri May 27 10:34:20 2005 +0000 @@ -5,32 +5,80 @@ #include +///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: -public: ///!!!!!!!! Graph g; + + ///Stores double type NodeMaps std::map< std::string,Graph::NodeMap * > nodemap_storage; + + ///Stores double type EdgeMaps std::map< std::string,Graph::EdgeMap * > edgemap_storage; + //Stores the default values for the different visualization node attributes std::vector > default_nodemaps; + + //Stores the default values for the different visualization edge attributes std::vector > 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 *); + + ///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 *); + ///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 * >::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 * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();}; };