[Lemon-commits] [lemon_svn] hegyi: r1915 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:48:45 CET 2006
Author: hegyi
Date: Fri May 27 12:34:20 2005
New Revision: 1915
Modified:
hugo/trunk/gui/graph-displayer.cc
hugo/trunk/gui/graph_displayer_canvas.cc
hugo/trunk/gui/graph_displayer_canvas.h
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:
Small documentation is added to GUI
Modified: hugo/trunk/gui/graph-displayer.cc
==============================================================================
--- hugo/trunk/gui/graph-displayer.cc (original)
+++ hugo/trunk/gui/graph-displayer.cc Fri May 27 12:34:20 2005
@@ -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<double> cap(g), map1(g), map2(g), map3(g), map4(g);
+ Graph::NodeMap<double> 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 <CoordinatesMap> xreader (cm);
YMap <CoordinatesMap> yreader (cm);
- Graph::NodeMap<double> 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);
Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc Fri May 27 12:34:20 2005
@@ -1,19 +1,26 @@
#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)
{
+ //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].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);
@@ -49,28 +64,32 @@
GraphDisplayerCanvas::~GraphDisplayerCanvas()
{
- 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);
+ //writing out the end state of the graph
+ //\todo all the maps has to be write out!
- id[i]=j++;
- xc[i]=(x1+x2)/2;
- yc[i]=(y1+y2)/2;
- }
-
- GraphWriter<Graph> writer(std::cout,g);
+ 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;
+ }
- writer.writeNodeMap("id", id);
- writer.writeNodeMap("coordinates_x", xc);
- writer.writeNodeMap("coordinates_y", yc);
- writer.run();
+ 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)
@@ -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;
- EdgeIt e;
+ //all the edges connected to the moved point has to be redrawn
+ EdgeIt e;
g.firstOut(e,n);
for(;e!=INVALID;g.nextOut(e))
{
Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h (original)
+++ hugo/trunk/gui/graph_displayer_canvas.h Fri May 27 12:34:20 2005
@@ -8,6 +8,7 @@
#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;
@@ -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<Gnome::Canvas::Ellipse *> nodesmap;
- ///Map of edges of planefigure
+
+ ///Map of edges of graph
Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap;
///Map of texts to write on edges
Modified: hugo/trunk/gui/main_win.h
==============================================================================
--- hugo/trunk/gui/main_win.h (original)
+++ hugo/trunk/gui/main_win.h Fri May 27 12:34:20 2005
@@ -9,34 +9,41 @@
#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
+ ///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<Gtk::ActionGroup> ag;
- //UIManager for menu
+ ///UIManager for menu
Glib::RefPtr<Gtk::UIManager> 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();
};
Modified: hugo/trunk/gui/map_win.cc
==============================================================================
--- hugo/trunk/gui/map_win.cc (original)
+++ hugo/trunk/gui/map_win.cc Fri May 27 12:34:20 2005
@@ -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())
{
Modified: hugo/trunk/gui/map_win.h
==============================================================================
--- hugo/trunk/gui/map_win.h (original)
+++ hugo/trunk/gui/map_win.h Fri May 27 12:34:20 2005
@@ -9,21 +9,40 @@
#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);
};
Modified: hugo/trunk/gui/mapstorage.cc
==============================================================================
--- hugo/trunk/gui/mapstorage.cc (original)
+++ hugo/trunk/gui/mapstorage.cc Fri May 27 12:34:20 2005
@@ -9,8 +9,6 @@
Graph::NodeMap<double> nmd(g);
default_nodemaps.push_back(nmd);
}
-
- //std::string defaultstr="Default ";
for(int i=0;i<PROPERTY_NUM;i++)
{
for (EdgeIt j(g); j!=INVALID; ++j)
@@ -27,6 +25,7 @@
nodemap_storage[name]=nodemap;
return 0;
}
+
int MapStorage::addEdgeMap(const std::string & name, Graph::EdgeMap<double> *edgemap)
{
edgemap_storage[name]=edgemap;
Modified: hugo/trunk/gui/mapstorage.h
==============================================================================
--- hugo/trunk/gui/mapstorage.h (original)
+++ hugo/trunk/gui/mapstorage.h Fri May 27 12:34:20 2005
@@ -5,32 +5,80 @@
#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:
-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();};
};
More information about the Lemon-commits
mailing list