Changeset 4:e099638ff236 in glemon-0.x
- Timestamp:
- 05/27/05 12:34:20 (19 years ago)
- Branch:
- gui
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk/gui@1915
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
graph-displayer.cc
r1 r4 13 13 int main(int argc, char *argv[]) 14 14 { 15 16 //initializing 17 15 18 property_strings=new std::string[PROPERTY_NUM]; 16 19 property_strings[WIDTH]="Width"; … … 35 38 CoordinatesMap cm(g); 36 39 Graph::EdgeMap<double> cap(g), map1(g), map2(g), map3(g), map4(g); 40 Graph::NodeMap<double> nodedata (g); 37 41 38 42 //we create one object to read x coordinates 39 43 //and one to read y coordinate of nodes and write them to cm NodeMap. 40 41 44 XMap <CoordinatesMap> xreader (cm); 42 45 YMap <CoordinatesMap> yreader (cm); 43 Graph::NodeMap<double> nodedata (g); 46 47 //reading in graph and its maps 44 48 45 49 std::ifstream is(argv[1]); … … 56 60 reader.run(); 57 61 62 //initializing MapStorage with the read data 63 58 64 MapStorage ms(g); 59 65 ms.addNodeMap("data",&nodedata); … … 63 69 ms.addEdgeMap("map3",&map3); 64 70 ms.addEdgeMap("map4",&map4); 71 72 //initializing GUI 65 73 66 74 Gnome::Canvas::init(); -
graph_displayer_canvas.cc
r1 r4 1 1 #include <graph_displayer_canvas.h> 2 #include <math.h> 2 3 3 4 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 5 { 5 6 7 //first edges are drawn, to hide joining with nodes later 8 6 9 for (EdgeIt i(g); i!=INVALID; ++i) 7 10 { 11 12 //drawing green lines, coordinates are from cm 13 8 14 Gnome::Canvas::Points coos; 9 15 coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); … … 12 18 edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos); 13 19 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); 14 edgesmap[i]->property_width_pixels().set_value(10); 20 edgesmap[i]->property_width_pixels().set_value(10); 15 21 16 22 //initializing edge-text as well, to empty string 23 17 24 double x1, x2, y1, y2; 18 25 edgesmap[i]->get_bounds(x1, y1, x2, y2); … … 22 29 } 23 30 31 //afterwards nodes come to be drawn 32 24 33 NodeIt i(g); 25 34 int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; … … 27 36 for (; i!=INVALID; ++i) 28 37 { 38 //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen) 39 29 40 if(cm[i].x>maxx)maxx=(int)cm[i].x; 30 41 if(cm[i].y>maxy)maxy=(int)cm[i].y; … … 32 43 if(cm[i].y<miny)miny=(int)cm[i].y; 33 44 45 //drawing bule nodes, with black line around them 46 34 47 nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20); 35 48 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); … … 38 51 } 39 52 53 //setting zoom to be able to see the whole graph on the canvas 54 40 55 double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80); 41 56 double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); … … 50 65 GraphDisplayerCanvas::~GraphDisplayerCanvas() 51 66 { 52 Graph::NodeMap <int> id(g); 53 Graph::NodeMap <double> xc(g); 54 Graph::NodeMap <double> yc(g); 55 56 int j=1; 57 58 for (NodeIt i(g); i!=INVALID; ++i) 59 { 60 double x1,y1,x2,y2; 61 nodesmap[i]->get_bounds(x1, y1, x2, y2); 62 63 id[i]=j++; 64 xc[i]=(x1+x2)/2; 65 yc[i]=(y1+y2)/2; 66 } 67 68 GraphWriter<Graph> writer(std::cout,g); 69 70 writer.writeNodeMap("id", id); 71 writer.writeNodeMap("coordinates_x", xc); 72 writer.writeNodeMap("coordinates_y", yc); 73 writer.run(); 67 68 //writing out the end state of the graph 69 //\todo all the maps has to be write out! 70 71 Graph::NodeMap <int> id(g); 72 Graph::NodeMap <double> xc(g); 73 Graph::NodeMap <double> yc(g); 74 75 int j=1; 76 77 for (NodeIt i(g); i!=INVALID; ++i) 78 { 79 double x1,y1,x2,y2; 80 nodesmap[i]->get_bounds(x1, y1, x2, y2); 81 82 id[i]=j++; 83 xc[i]=(x1+x2)/2; 84 yc[i]=(y1+y2)/2; 85 } 86 87 GraphWriter<Graph> writer(std::cout,g); 88 89 writer.writeNodeMap("id", id); 90 writer.writeNodeMap("coordinates_x", xc); 91 writer.writeNodeMap("coordinates_y", yc); 92 writer.run(); 74 93 } 75 94 … … 86 105 int GraphDisplayerCanvas::changeColor (std::string mapname) 87 106 { 107 108 //function maps the range of the maximum and 109 //the minimum of the nodemap to the range of 110 //green in RGB 111 88 112 for (EdgeIt i(g); i!=INVALID; ++i) 89 113 { … … 110 134 int GraphDisplayerCanvas::changeText (std::string mapname) 111 135 { 136 137 //the number in the map will be written on the edge 138 //EXCEPT when the name of the map is Text, because 139 //in that case empty string will be written, because 140 //that is the deleter map 141 //\todo isn't it a bit woodcutter? 142 112 143 for (EdgeIt i(g); i!=INVALID; ++i) 113 144 { … … 146 177 int GraphDisplayerCanvas::rezoom () 147 178 { 179 180 //searches for the minimum and the maximum 181 //value of the coordinates of the nodes to 182 //set the pixel rpo unit to a value to be 183 //able to see the whole graph in the canvas 184 //\todo does not work properly 185 148 186 double x1, x2, y1, y2; 149 187 int x,y; … … 178 216 179 217 180 ///This function moves only one node of displayed_graph,181 ///but recalculate the location of weight point,182 ///and also redraw the sides of the planefigure.183 218 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) 184 219 { … … 186 221 { 187 222 case GDK_BUTTON_PRESS: 223 //we mark the location of the event to be able to calculate parameters of dragging 188 224 clicked_x=e->button.x; 189 225 clicked_y=e->button.y; … … 196 232 break; 197 233 case GDK_MOTION_NOTIFY: 234 //we only have to do sg. if the mouse button is pressed 198 235 if(isbutton) 199 236 { 237 //new coordinates will be the old values, 238 //because the item will be moved to the 239 //new coordinate therefore the new movement 240 //has to be calculated from here 241 200 242 double dx=e->motion.x-clicked_x; 201 243 double dy=e->motion.y-clicked_y; … … 204 246 clicked_y=e->motion.y; 205 247 248 //all the edges connected to the moved point has to be redrawn 249 206 250 EdgeIt e; 207 208 251 g.firstOut(e,n); 209 252 for(;e!=INVALID;g.nextOut(e)) -
graph_displayer_canvas.h
r1 r4 9 9 #include <libgnomecanvasmm/polygon.h> 10 10 11 ///This class is the canvas, on which the graph can be drawn. 11 12 class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA 12 13 { … … 17 18 virtual ~GraphDisplayerCanvas(); 18 19 20 ///Changes the linewidth attribute according to the given map. 21 ///\param mapname is the name of the map which contains the new values 19 22 int changeLineWidth (std::string mapname); 23 24 ///Changes the linecolor attribute according to the given map. 25 ///\param mapname is the name of the map which contains the new values 20 26 int changeColor (std::string mapname); 27 28 ///Changes the text of line attribute according to the given map. 29 ///\param mapname is the name of the map which contains the new values 21 30 int changeText (std::string mapname); 31 32 ///Changes the dot-pro-pixel to be able to show the whole graph. 22 33 int rezoom(); 23 34 24 35 protected: 25 36 37 //maximizing, minimizing, restoring window, etc. 26 38 virtual bool on_expose_event(GdkEventExpose *); 27 39 28 40 private: 29 41 30 ///Event handler function that handles dragging nodes of displayed_graph 42 ///This function is responsible for the correct 43 ///reaction of any action happened in the territory 44 ///of the canvas 31 45 bool event_handler(GdkEvent* e, Node n); 32 46 33 47 ///The graph, on which we work 34 48 Graph g; 35 ///Map of nodes of planefigure 49 50 ///Map of nodes of graph 36 51 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; 37 ///Map of edges of planefigure 52 53 ///Map of edges of graph 38 54 Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap; 39 55 -
main_win.h
r1 r4 10 10 #include <libgnomecanvasmm/polygon.h> 11 11 12 ///This class is the main window of GUI. 13 ///It has menus, but the main part of it is the canvas. 12 14 class MainWin : public Gtk::Window 13 15 { 14 16 public: 17 ///Constructor of the \ref MainWin. It creates the menu and the \ref GraphDisplayerCanvas on which the graph will be drawn. 18 ///\param title is the title of the window 19 ///\param graph is the graph that will be drawn here. It will be given further to the \ref GraphDisplayerCanvas 20 ///\param cm stores the coordinates of the nodes of the graph 21 ///\param ms is the \ref MapStorage in which the different visualizable maps are stored 15 22 MainWin(const std::string& title, Graph &, CoordinatesMap &, MapStorage &); 16 23 17 24 protected: 18 // Window of map-showing setup25 ///Window of map-showing setup. Its type is \ref MapWin 19 26 MapWin mapwin; 20 27 21 // Member widgets:28 ///The graph will be drawn on this \ref GraphDisplayerCanvas 22 29 GraphDisplayerCanvas gd_canvas; 23 30 24 // ActionGroup for menu31 ///ActionGroup for menu 25 32 Glib::RefPtr<Gtk::ActionGroup> ag; 26 33 27 // UIManager for menu34 ///UIManager for menu 28 35 Glib::RefPtr<Gtk::UIManager> uim; 29 36 30 // Container37 ///Container 31 38 Gtk::VBox vbox; 32 39 33 // Pops up map-setup window40 ///This function makes map-setup window popped up. 34 41 virtual void showMaps(); 35 42 36 // Exit43 ///Exit 37 44 virtual void quit(); 38 45 39 // Refit screen46 ///Refit screen to be able to show the whole graph. 40 47 virtual void rezoom(); 41 48 -
map_win.cc
r1 r4 4 4 MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst) 5 5 { 6 7 //most nem kommentezem fel, mert ugyis valtozik 8 6 9 set_title(title); 7 10 set_default_size(400, 200); … … 89 92 void MapWin::radio_click(int prop, int actpos) 90 93 { 94 95 //most nem kommentezem fel, mert ugyis valtozik 96 91 97 if(rb_array[prop][actpos].get_active()) 92 98 { -
map_win.h
r1 r4 10 10 #include <libgnomecanvasmm/polygon.h> 11 11 12 ///This class is responsible for creating a window, 13 ///on which the visualization attributes can be 14 ///assigned to maps. 12 15 class MapWin : public Gtk::Window 13 16 { 14 17 protected: 18 ///The \ref GraphDisplayerCanvas on which the graph will be drawn. 19 ///It has to be known for this class, because 20 ///when a map assigned to a certain attribute 21 ///a function of the \ref GraphDisplayerCanvas will be called. 15 22 GraphDisplayerCanvas & gdc; 23 24 ///The \ref MapStorage in which the visualizable maps are stored 16 25 MapStorage & ms; 17 26 27 18 28 Gtk::HBox * radios; 19 29 Gtk::RadioButton ** rb_array; 20 30 21 31 Gtk::VBox vbox_b, * vbox_r1, * vbox_r2; 32 33 ///The notebook has different pages for each attribute. 22 34 Gtk::Notebook notebook; 35 23 36 Gtk::Label * labels; 24 37 25 38 public: 39 ///Constructor of MapWin creates the widgets shown in MapWin. 26 40 MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &); 41 42 ///If a radiobutton is clicked, this function determines 43 ///which button was that and after that calls the 44 ///appropriate function of the \ref GraphDisplayerCanvas 45 ///to change the visible values of that attribute. 27 46 virtual void radio_click(int, int); 28 47 }; -
mapstorage.cc
r1 r4 10 10 default_nodemaps.push_back(nmd); 11 11 } 12 13 //std::string defaultstr="Default ";14 12 for(int i=0;i<PROPERTY_NUM;i++) 15 13 { … … 28 26 return 0; 29 27 } 28 30 29 int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap) 31 30 { -
mapstorage.h
r1 r4 6 6 #include <all_include.h> 7 7 8 ///Class MapStorage is responsible for storing 9 ///NodeMaps and EdgeMaps that can be shown later 10 ///on GUI. Therefore maps can be added to it, 11 ///and datas over the added maps can be queried. 12 ///The maps will be stored in an std::map, 13 ///referenced with their names. Unfortunately at 14 ///the moment it works only with double type maps 15 /// 16 ///\todo too many things are public!! 8 17 class MapStorage 9 18 { 19 public: 10 20 11 public: ///!!!!!!!!12 21 Graph g; 22 23 ///Stores double type NodeMaps 13 24 std::map< std::string,Graph::NodeMap<double> * > nodemap_storage; 25 26 ///Stores double type EdgeMaps 14 27 std::map< std::string,Graph::EdgeMap<double> * > edgemap_storage; 15 28 29 //Stores the default values for the different visualization node attributes 16 30 std::vector<Graph::NodeMap<double> > default_nodemaps; 31 32 //Stores the default values for the different visualization edge attributes 17 33 std::vector<Graph::EdgeMap<double> > default_edgemaps; 18 34 19 35 public: 36 ///Constructor of MapStorage. Expects the Graph of 37 ///which maps will be stored in it. 38 ///Its all activity is initializing default values 39 ///for different visualization attributes 40 /// 41 ///\param graph is the graph for which the maps are stored in this object. 20 42 MapStorage(Graph &); 43 44 ///Adds given map to storage. A name and the map itself has to be provided. 45 ///\param name is the name of map 46 ///\nodemap is the pointer of the given nodemap 47 ///\todo map should be given by reference! 21 48 int addNodeMap(const std::string &,Graph::NodeMap<double> *); 49 50 ///Adds given map to storage. A name and the map itself has to be provided. 51 ///\param name is the name of map 52 ///\edgemap is the pointer of the given edgemap 53 ///\todo map should be given by reference! 22 54 int addEdgeMap(const std::string &,Graph::EdgeMap<double> *); 23 55 56 ///Returns how much nodemaps is stored in \ref MapStorage 24 57 int numOfNodeMaps() {return nodemap_storage.size();}; 58 59 ///Returns how much edgemaps is stored in \ref MapStorage 25 60 int numOfEdgeMaps() {return edgemap_storage.size();}; 26 61 62 ///Returns the maximum value of the given NodeMap. NodeMap has to be given by its name. 63 ///\param name is the name of map of which maximum is searched 27 64 double maxOfNodeMap(const std::string &); 65 66 ///Returns the maximum value of the given EdgeMap. EdgeMap has to be given by its name. 67 ///\param name is the name of map of which maximum is searched 28 68 double maxOfEdgeMap(const std::string &); 29 69 70 ///Returns the minimum value of the given NodeMap. NodeMap has to be given by its name. 71 ///\param name is the name of map of which minimum is searched 30 72 double minOfNodeMap(const std::string &); 73 74 ///Returns the minimum value of the given EdgeMap. EdgeMap has to be given by its name. 75 ///\param name is the name of map of which minimum is searched 31 76 double minOfEdgeMap(const std::string &); 32 77 78 ///To be able to iterate through each maps this function returns an iterator pointing to the first nodemap in the storage. 33 79 std::map< std::string,Graph::NodeMap<double> * >::iterator beginOfNodeMaps(){return nodemap_storage.begin();}; 80 81 ///To be able to iterate through each maps this function returns an iterator pointing to the first edgemap in the storage. 34 82 std::map< std::string,Graph::EdgeMap<double> * >::iterator beginOfEdgeMaps(){return edgemap_storage.begin();}; 35 83 };
Note: See TracChangeset
for help on using the changeset viewer.