[Lemon-commits] [lemon_svn] hegyi: r1996 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:49:22 CET 2006
Author: hegyi
Date: Fri Jun 24 20:16:12 2005
New Revision: 1996
Added:
hugo/trunk/gui/graph_displayer_canvas-node.cc (contents, props changed)
Modified:
hugo/trunk/gui/Makefile.am
hugo/trunk/gui/all_include.h
hugo/trunk/gui/graph-displayer.cc
hugo/trunk/gui/graph_displayer_canvas-edge.cc
hugo/trunk/gui/graph_displayer_canvas-event.cc
hugo/trunk/gui/graph_displayer_canvas.cc
hugo/trunk/gui/graph_displayer_canvas.h
hugo/trunk/gui/main_win.cc
hugo/trunk/gui/map_win.cc
hugo/trunk/gui/map_win.h
hugo/trunk/gui/mapstorage.cc
Log:
NodeMap values are now visualizable. Todo: default map-values
Modified: hugo/trunk/gui/Makefile.am
==============================================================================
--- hugo/trunk/gui/Makefile.am (original)
+++ hugo/trunk/gui/Makefile.am Fri Jun 24 20:16:12 2005
@@ -7,6 +7,7 @@
all_include.h \
graph_displayer_canvas.cc \
graph_displayer_canvas-edge.cc \
+ graph_displayer_canvas-node.cc \
graph_displayer_canvas-event.cc \
graph_displayer_canvas-zoom.cc \
graph_displayer_canvas.h \
Modified: hugo/trunk/gui/all_include.h
==============================================================================
--- hugo/trunk/gui/all_include.h (original)
+++ hugo/trunk/gui/all_include.h Fri Jun 24 20:16:12 2005
@@ -16,7 +16,8 @@
#include <lemon/error.h>
#include <lemon/xy.h>
-enum {WIDTH, COLOR, TEXT, PROPERTY_NUM}; // edge properties;
+enum {E_WIDTH, E_COLOR, E_TEXT, EDGE_PROPERTY_NUM}; // edge properties;
+enum {N_RADIUS, N_COLOR, N_TEXT, NODE_PROPERTY_NUM}; // node properties;
enum {MOVE, CREATE_NODE, CREATE_EDGE, ERASER, EDGE_MAP_EDIT, TOOL_NUM}; // tools;
#define RANGE 3
#define WIN_WIDTH 900
@@ -24,8 +25,10 @@
#ifndef MAIN_PART
-extern std::vector <std::string> property_strings;
-extern std::vector <double> property_defaults;
+extern std::vector <std::string> edge_property_strings;
+extern std::vector <double> edge_property_defaults;
+extern std::vector <std::string> node_property_strings;
+extern std::vector <double> node_property_defaults;
#endif //MAIN_PART
using namespace lemon;
Modified: hugo/trunk/gui/graph-displayer.cc
==============================================================================
--- hugo/trunk/gui/graph-displayer.cc (original)
+++ hugo/trunk/gui/graph-displayer.cc Fri Jun 24 20:16:12 2005
@@ -6,8 +6,10 @@
#define MAIN_PART
-std::vector <std::string> property_strings;
-std::vector <double> property_defaults;
+std::vector <std::string> edge_property_strings;
+std::vector <double> edge_property_defaults;
+std::vector <std::string> node_property_strings;
+std::vector <double> node_property_defaults;
int main(int argc, char *argv[])
@@ -15,15 +17,25 @@
//initializing
- property_strings.resize(PROPERTY_NUM);
- property_strings[WIDTH]="Width";
- property_strings[COLOR]="Color";
- property_strings[TEXT]="Text";
-
- property_defaults.resize(PROPERTY_NUM);
- property_defaults[WIDTH]=10.0;
- property_defaults[COLOR]=100;
- property_defaults[TEXT]=0;
+ edge_property_strings.resize(EDGE_PROPERTY_NUM);
+ edge_property_strings[E_WIDTH]="Edge Width";
+ edge_property_strings[E_COLOR]="Edge Color";
+ edge_property_strings[E_TEXT]="Edge Text";
+
+ edge_property_defaults.resize(EDGE_PROPERTY_NUM);
+ edge_property_defaults[E_WIDTH]=10.0;
+ edge_property_defaults[E_COLOR]=100;
+ edge_property_defaults[E_TEXT]=0;
+
+ node_property_strings.resize(NODE_PROPERTY_NUM);
+ node_property_strings[N_RADIUS]="Node Radius";
+ node_property_strings[N_COLOR]="Node Color";
+ node_property_strings[N_TEXT]="Node Text";
+
+ node_property_defaults.resize(NODE_PROPERTY_NUM);
+ node_property_defaults[N_RADIUS]=20.0;
+ node_property_defaults[N_COLOR]=100;
+ node_property_defaults[N_TEXT]=0;
if(argc<2)
{
Modified: hugo/trunk/gui/graph_displayer_canvas-edge.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas-edge.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas-edge.cc Fri Jun 24 20:16:12 2005
@@ -3,49 +3,82 @@
#include <math.h>
-int GraphDisplayerCanvas::changeLineWidth (std::string mapname)
+int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
{
- for (EdgeIt i(g); i!=INVALID; ++i)
+ if(edge==INVALID)
{
- int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i];
+ if(w>=0)
+ {
+ edgesmap[i]->property_width_pixels().set_value(w);
+ }
+ }
+ }
+ else
+ {
+ int w=(int)(*(mapstorage.edgemap_storage)[mapname])[edge];
if(w>=0)
{
- edgesmap[i]->property_width_pixels().set_value(w);
+ edgesmap[edge]->property_width_pixels().set_value(w);
}
}
return 0;
};
-int GraphDisplayerCanvas::changeColor (std::string mapname)
+int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
{
//function maps the range of the maximum and
//the minimum of the nodemap to the range of
//green in RGB
+ if(edge==INVALID)
+ {
- for (EdgeIt i(g); i!=INVALID; ++i)
- {
- double w=(*(mapstorage.edgemap_storage)[mapname])[i];
- double max=mapstorage.maxOfEdgeMap(mapname);
- double min=mapstorage.minOfEdgeMap(mapname);
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ double w=(*(mapstorage.edgemap_storage)[mapname])[i];
+ double max=mapstorage.maxOfEdgeMap(mapname);
+ double min=mapstorage.minOfEdgeMap(mapname);
- //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
- Gdk::Color color;
- if(max!=min)
- {
- color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
+ //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
+ Gdk::Color color;
+ if(max!=min)
+ {
+ color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
+ }
+ else
+ {
+ color.set_rgb_p (0, 100, 0);
+ }
+
+ edgesmap[i]->property_fill_color_gdk().set_value(color);
+ }
}
- else
+ else
{
- color.set_rgb_p (0, 100, 0);
- }
+ double w=(*(mapstorage.edgemap_storage)[mapname])[edge];
+ double max=mapstorage.maxOfEdgeMap(mapname);
+ double min=mapstorage.minOfEdgeMap(mapname);
+
+ //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
+ Gdk::Color color;
+ if(max!=min)
+ {
+ color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
+ }
+ else
+ {
+ color.set_rgb_p (0, 100, 0);
+ }
- edgesmap[i]->property_fill_color_gdk().set_value(color);
- }
+ edgesmap[edge]->property_fill_color_gdk().set_value(color);
+ }
return 0;
};
-int GraphDisplayerCanvas::changeText (std::string mapname)
+int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
{
//the number in the map will be written on the edge
@@ -54,11 +87,50 @@
//that is the deleter map
//\todo isn't it a bit woodcutter?
- for (EdgeIt i(g); i!=INVALID; ++i)
+ if(edge==INVALID)
+ {
+ for (EdgeIt i(g); i!=INVALID; ++i)
+ {
+ if(mapname!=edge_property_strings[E_TEXT])
+ {
+ double number=(*(mapstorage.edgemap_storage)[mapname])[i];
+ int length=1;
+ //if number is smaller than one, length would be negative, or invalid
+ if(number>=1)
+ {
+ length=(int)(floor(log(number)/log(10)))+1;
+ }
+ int maxpos=(int)(pow(10,length-1));
+ int strl=length+1+RANGE;
+ char * str=new char[strl];
+ str[length]='.';
+ str[strl]='\0';
+
+ for(int j=0;j<strl;j++)
+ {
+ if(j!=length)
+ {
+ int digit=(int)(number/maxpos);
+ str[j]=(digit+'0');
+ number-=digit*maxpos;
+ number*=10;
+ }
+ }
+
+ edgetextmap[i]->property_text().set_value(str);
+ }
+ else
+ {
+ edgetextmap[i]->property_text().set_value("");
+ }
+ }
+
+ }
+ else
{
- if(mapname!="Text")
+ if(mapname!=edge_property_strings[E_TEXT])
{
- double number=(*(mapstorage.edgemap_storage)[mapname])[i];
+ double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
int length=1;
//if number is smaller than one, length would be negative, or invalid
if(number>=1)
@@ -82,12 +154,15 @@
}
}
- edgetextmap[i]->property_text().set_value(str);
+ edgetextmap[edge]->property_text().set_value(str);
}
else
{
- edgetextmap[i]->property_text().set_value("");
+ edgetextmap[edge]->property_text().set_value("");
}
+
}
+
return 0;
+
};
Modified: hugo/trunk/gui/graph_displayer_canvas-event.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas-event.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas-event.cc Fri Jun 24 20:16:12 2005
@@ -99,7 +99,9 @@
double dx=e->motion.x-clicked_x;
double dy=e->motion.y-clicked_y;
+ //repositioning node and its text
active_item->move(dx, dy);
+ nodetextmap[active_node]->move(dx, dy);
clicked_x=e->motion.x;
clicked_y=e->motion.y;
@@ -129,6 +131,7 @@
edgesmap[ei]->set_points(coos,true);
}
+ //reposition of edgetext
xy<double> text_pos=edgesmap[ei]->get_arrow_pos();
text_pos+=(xy<double>(10,10));
edgetextmap[ei]->property_x().set_value(text_pos.x);
@@ -189,6 +192,12 @@
*(nodesmap[active_node]) << Gnome::Canvas::Properties::fill_color("red");
*(nodesmap[active_node]) << Gnome::Canvas::Properties::outline_color("black");
(nodesmap[active_node])->show();
+
+ nodetextmap[active_node]=new Gnome::Canvas::Text(displayed_graph, clicked_x+node_property_defaults[N_RADIUS]+5, clicked_y+node_property_defaults[N_RADIUS]+5, "");
+ nodetextmap[active_node]->property_fill_color().set_value("darkblue");
+
+ mapwin->update_node(active_node);
+
break;
//move the new node
@@ -272,39 +281,50 @@
//the clicked item is a node, the edge can be drawn
if(target_node!=INVALID)
{
- *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
+ if(target_node!=active_node)
+ {
+ *(nodesmap[target_node]) << Gnome::Canvas::Properties::fill_color("red");
- //creating new edge
- active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
+ //creating new edge
+ active_edge=EdgeIt(g,g.addEdge(active_node, target_node));
- //initiating values corresponding to new edge in maps
- mapstorage.init_maps_for_edge(active_edge);
+ //initiating values corresponding to new edge in maps
+ mapstorage.init_maps_for_edge(active_edge);
- //calculating coordinates of new edge
- Gnome::Canvas::Points coos;
- double x1, x2, y1, y2;
+ //calculating coordinates of new edge
+ Gnome::Canvas::Points coos;
+ double x1, x2, y1, y2;
- active_item->get_bounds(x1, y1, x2, y2);
- coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+ active_item->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
- target_item->get_bounds(x1, y1, x2, y2);
- coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
+ target_item->get_bounds(x1, y1, x2, y2);
+ coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2));
- //drawing new edge
- edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
- *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
- edgesmap[active_edge]->property_width_pixels().set_value(10);
-
- //redraw nodes to blank terminations of the new edge
- target_item->raise_to_top();
- active_item->raise_to_top();
-
- //initializing edge-text as well, to empty string
- xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos();
- text_pos+=(xy<double>(10,10));
+ //drawing new edge
+ edgesmap[active_edge]=new BrokenEdge(displayed_graph, coos, *this);
+ *(edgesmap[active_edge]) << Gnome::Canvas::Properties::fill_color("green");
+ edgesmap[active_edge]->property_width_pixels().set_value(10);
+
+ //redraw nodes to blank terminations of the new edge
+ target_item->raise_to_top();
+ active_item->raise_to_top();
+
+ //initializing edge-text as well, to empty string
+ xy<double> text_pos=edgesmap[active_edge]->get_arrow_pos();
+ text_pos+=(xy<double>(10,10));
- edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
- edgetextmap[active_edge]->property_fill_color().set_value("black");
+ edgetextmap[active_edge]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
+ edgetextmap[active_edge]->property_fill_color().set_value("darkgreen");
+
+ //updating its properties
+ mapwin->update_edge(active_edge);
+ }
+ else
+ {
+ target_node=INVALID;
+ std::cout << "Loop edge is not yet implemented!" << std::endl;
+ }
}
//clicked item was not a node. it could be an e.g. edge. we do not deal with it furthermore.
else
@@ -435,18 +455,21 @@
void GraphDisplayerCanvas::delete_item(NodeIt node_to_delete)
{
+ delete(nodetextmap[node_to_delete]);
delete(nodesmap[node_to_delete]);
g.erase(node_to_delete);
}
void GraphDisplayerCanvas::delete_item(EdgeIt edge_to_delete)
{
+ delete(edgetextmap[edge_to_delete]);
delete(edgesmap[edge_to_delete]);
g.erase(edge_to_delete);
}
void GraphDisplayerCanvas::delete_item(Graph::Edge edge_to_delete)
{
+ delete(edgetextmap[edge_to_delete]);
delete(edgesmap[edge_to_delete]);
g.erase(edge_to_delete);
}
Added: hugo/trunk/gui/graph_displayer_canvas-node.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/gui/graph_displayer_canvas-node.cc Fri Jun 24 20:16:12 2005
@@ -0,0 +1,175 @@
+#include <graph_displayer_canvas.h>
+#include <broken_edge.h>
+#include <math.h>
+
+
+int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
+{
+ if(node==INVALID)
+ {
+ for (NodeIt i(g); i!=INVALID; ++i)
+ {
+ int w=(int)(*(mapstorage.nodemap_storage)[mapname])[i];
+ if(w>=0)
+ {
+ double x1, y1, x2, y2;
+ nodesmap[i]->get_bounds(x1, y1, x2, y2);
+ nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
+ nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
+ nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
+ nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
+ }
+ }
+ }
+ else
+ {
+ int w=(int)(*(mapstorage.nodemap_storage)[mapname])[node];
+ if(w>=0)
+ {
+ double x1, y1, x2, y2;
+ nodesmap[node]->get_bounds(x1, y1, x2, y2);
+ nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
+ nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
+ nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
+ nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
+ }
+ }
+ return 0;
+};
+
+int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
+{
+
+ //function maps the range of the maximum and
+ //the minimum of the nodemap to the range of
+ //green in RGB
+
+ if(node==INVALID)
+ {
+
+ for (NodeIt i(g); i!=INVALID; ++i)
+ {
+ double w=(*(mapstorage.nodemap_storage)[mapname])[i];
+ double max=mapstorage.maxOfNodeMap(mapname);
+ double min=mapstorage.minOfNodeMap(mapname);
+
+ //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
+ Gdk::Color color;
+ if(max!=min)
+ {
+ color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
+ }
+ else
+ {
+ color.set_rgb_p (0, 0, 100);
+ }
+
+ nodesmap[i]->property_fill_color_gdk().set_value(color);
+ }
+ }
+ else
+ {
+ double w=(*(mapstorage.nodemap_storage)[mapname])[node];
+ double max=mapstorage.maxOfNodeMap(mapname);
+ double min=mapstorage.minOfNodeMap(mapname);
+
+ //std::cout<<w<<" "<<max<<" "<<min<<" "<<100*(w-min)/(max-min)<<std::endl;
+ Gdk::Color color;
+ if(max!=min)
+ {
+ color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
+ }
+ else
+ {
+ color.set_rgb_p (0, 0, 100);
+ }
+
+ nodesmap[node]->property_fill_color_gdk().set_value(color);
+ }
+ return 0;
+};
+
+int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
+{
+
+ //the number in the map will be written on the node
+ //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?
+
+ if(node==INVALID)
+ {
+ for (NodeIt i(g); i!=INVALID; ++i)
+ {
+ if(mapname!=node_property_strings[N_TEXT])
+ {
+ double number=(*(mapstorage.nodemap_storage)[mapname])[i];
+ int length=1;
+ //if number is smaller than one, length would be negative, or invalid
+ if(number>=1)
+ {
+ length=(int)(floor(log(number)/log(10)))+1;
+ }
+ int maxpos=(int)(pow(10,length-1));
+ int strl=length+1+RANGE;
+ char * str=new char[strl];
+ str[length]='.';
+ str[strl]='\0';
+
+ for(int j=0;j<strl;j++)
+ {
+ if(j!=length)
+ {
+ int digit=(int)(number/maxpos);
+ str[j]=(digit+'0');
+ number-=digit*maxpos;
+ number*=10;
+ }
+ }
+
+ nodetextmap[i]->property_text().set_value(str);
+ }
+ else
+ {
+ nodetextmap[i]->property_text().set_value("");
+ }
+ }
+ }
+ else
+ {
+ if(mapname!=node_property_strings[N_TEXT])
+ {
+ double number=(*(mapstorage.nodemap_storage)[mapname])[node];
+ int length=1;
+ //if number is smaller than one, length would be negative, or invalid
+ if(number>=1)
+ {
+ length=(int)(floor(log(number)/log(10)))+1;
+ }
+ int maxpos=(int)(pow(10,length-1));
+ int strl=length+1+RANGE;
+ char * str=new char[strl];
+ str[length]='.';
+ str[strl]='\0';
+
+ for(int j=0;j<strl;j++)
+ {
+ if(j!=length)
+ {
+ int digit=(int)(number/maxpos);
+ str[j]=(digit+'0');
+ number-=digit*maxpos;
+ number*=10;
+ }
+ }
+
+ nodetextmap[node]->property_text().set_value(str);
+ }
+ else
+ {
+ nodetextmap[node]->property_text().set_value("");
+ }
+ }
+ return 0;
+};
Modified: hugo/trunk/gui/graph_displayer_canvas.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas.cc Fri Jun 24 20:16:12 2005
@@ -2,7 +2,7 @@
#include <broken_edge.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(0),active_item(NULL),target_item(NULL)
+GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),mapwin(mw)
{
actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false);
@@ -34,7 +34,7 @@
text_pos+=(xy<double>(10,10));
edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
- edgetextmap[i]->property_fill_color().set_value("black");
+ edgetextmap[i]->property_fill_color().set_value("darkgreen");
}
//afterwards nodes come to be drawn
@@ -56,7 +56,13 @@
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));
+
+ //initializing edge-text as well, to empty string
+
+ xy<double> text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5));
+
+ nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
+ nodetextmap[i]->property_fill_color().set_value("darkblue");
}
updateScrollRegion();
Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h (original)
+++ hugo/trunk/gui/graph_displayer_canvas.h Fri Jun 24 20:16:12 2005
@@ -6,6 +6,7 @@
class GraphDisplayerCanvas;
#include <all_include.h>
+#include <map_win.h>
#include <mapstorage.h>
#include <broken_edge.h>
#include <libgnomecanvasmm.h>
@@ -17,20 +18,32 @@
typedef Gnome::Canvas::CanvasAA Parent;
public:
- GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &);
+ GraphDisplayerCanvas(Graph &, CoordinatesMap &, MapStorage &, MapWin *);
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);
+ int changeEdgeWidth (std::string mapname, Graph::Edge new_item=INVALID);
///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);
+ int changeEdgeColor (std::string mapname, Graph::Edge new_item=INVALID);
///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);
+ int changeEdgeText (std::string mapname, Graph::Edge new_item=INVALID);
+
+ ///Changes the linewidth attribute according to the given map.
+ ///\param mapname is the name of the map which contains the new values
+ int changeNodeRadius (std::string mapname, Graph::Node new_item=INVALID);
+
+ ///Changes the linecolor attribute according to the given map.
+ ///\param mapname is the name of the map which contains the new values
+ int changeNodeColor (std::string mapname, Graph::Node new_item=INVALID);
+
+ ///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 changeNodeText (std::string mapname, Graph::Node new_item=INVALID);
///Callback for 'ViewZoomIn' action.
virtual void zoomIn();
@@ -107,6 +120,9 @@
///Map of texts to write on edges
Graph::EdgeMap<Gnome::Canvas::Text *> edgetextmap;
+ ///Map of texts to write on nodes
+ Graph::NodeMap<Gnome::Canvas::Text *> nodetextmap;
+
///Group of graphical elements of displayed_graph
Gnome::Canvas::Group displayed_graph;
@@ -133,6 +149,9 @@
static const int zoom_step = 5;
+ ///We need to store mapwin, to be able to ask the appropriate values for properties of new items.
+ MapWin * mapwin;
+
};
#endif //GRAPH_DISPLAYER_CANVAS_H
Modified: hugo/trunk/gui/main_win.cc
==============================================================================
--- hugo/trunk/gui/main_win.cc (original)
+++ hugo/trunk/gui/main_win.cc Fri Jun 24 20:16:12 2005
@@ -1,7 +1,7 @@
#include <main_win.h>
MainWin::MainWin(const std::string& title, Graph & graph, CoordinatesMap & cm,
- MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms)
+ MapStorage & ms):mapwin("Map Setup", ms, gd_canvas),editwin("Editorial Window", gd_canvas),gd_canvas(graph, cm, ms, &mapwin)
{
set_title (title);
set_default_size(WIN_WIDTH,WIN_HEIGHT);
Modified: hugo/trunk/gui/map_win.cc
==============================================================================
--- hugo/trunk/gui/map_win.cc (original)
+++ hugo/trunk/gui/map_win.cc Fri Jun 24 20:16:12 2005
@@ -10,16 +10,18 @@
return true;
}
-MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst),table(PROPERTY_NUM, 2, false)
+MapWin::MapWin(const std::string& title, MapStorage & mapst, GraphDisplayerCanvas & grdispc):gdc(grdispc),ms(mapst)
{
set_title(title);
set_default_size(200, 50);
signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::close_if_escape_is_pressed));
- combo_array=new Gtk::Combo [PROPERTY_NUM];
+ e_combo_array=new Gtk::Combo [EDGE_PROPERTY_NUM];
- for(int i=0;i<PROPERTY_NUM;i++)
+ table=new Gtk::Table(EDGE_PROPERTY_NUM, 2, false);
+
+ for(int i=0;i<EDGE_PROPERTY_NUM;i++)
{
std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
@@ -35,8 +37,8 @@
{
actprop=j;
}
- //this is the other maps to show for this property
- for(int k=0;k<PROPERTY_NUM;k++)
+ //these are the maps NOT to show for this property
+ for(int k=0;k<EDGE_PROPERTY_NUM;k++)
{
if(emsi->second==&(ms.default_edgemaps[k]))
{
@@ -46,8 +48,6 @@
emsi++;
}
- //combo_array[i].set_group(group);
-
//filling in combo box with choices
std::list<Glib::ustring> listStrings;
@@ -64,17 +64,17 @@
emsi++;
}
- combo_array[i].set_popdown_strings(listStrings);
+ e_combo_array[i].set_popdown_strings(listStrings);
//Restrict it to these choices only:
- combo_array[i].set_value_in_list();
+ e_combo_array[i].set_value_in_list();
- //binding signal to thew actual entry
- combo_array[i].get_entry()->signal_changed().connect
+ //binding signal to the actual entry
+ e_combo_array[i].get_entry()->signal_changed().connect
(
sigc::bind
(
- sigc::mem_fun(*this, &MapWin::combo_changed),
+ sigc::mem_fun(*this, &MapWin::e_combo_changed),
i
)
);
@@ -82,44 +82,106 @@
//placing actual entry in the right place
label=new Gtk::Label;
- label->set_text(property_strings[i]);
-
- // labelpluscombo=new Gtk::HBox;
- // labelpluscombo->pack_start(*label);
- // labelpluscombo->pack_start(combo_array[i]);
+ label->set_text(edge_property_strings[i]);
- table.attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
- table.attach(combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
+ (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
+ (*table).attach(e_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
+
+
+ }
+
+ vbox.pack_start(*(new Gtk::Label("Edge properties")));
+
+ vbox.pack_start(*table);
+
+ vbox.pack_start(*(new Gtk::HSeparator));
+
+ n_combo_array=new Gtk::Combo [NODE_PROPERTY_NUM];
+
+ table=new Gtk::Table(NODE_PROPERTY_NUM, 2, false);
- /*
- if(actpos<(ms.numOfEdgeMaps()-PROPERTY_NUM+1)/2)
+ for(int i=0;i<NODE_PROPERTY_NUM;i++)
+ {
+
+ std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
+ std::set<int> props;
+
+ int actprop;
+
+ //here we find out, which map is the default in MapStorage for this property, which are not
+ for(int j=0;j<ms.numOfNodeMaps();j++)
{
- vbox_r1.pack_start(*labelpluscombo);
+ //these are the maps NOT to show for this property
+ if(emsi->second==&(ms.default_nodemaps[i]))
+ {
+ actprop=j;
+ }
+ //this is the other maps to show for this property
+ for(int k=0;k<NODE_PROPERTY_NUM;k++)
+ {
+ if(emsi->second==&(ms.default_nodemaps[k]))
+ {
+ props.insert(j);
+ }
+ }
+ emsi++;
}
- else
+
+ //filling in combo box with choices
+ std::list<Glib::ustring> listStrings;
+
+ listStrings.push_back("Default");
+
+ emsi=ms.beginOfNodeMaps();
+
+ for(int j=0;j<ms.numOfNodeMaps();j++)
{
- vbox_r2.pack_start(*labelpluscombo);
+ if( ( props.find(j) )==( props.end() ) )
+ {
+ listStrings.push_back(emsi->first);
+ }
+ emsi++;
}
- actpos++;
- //*/
+
+ n_combo_array[i].set_popdown_strings(listStrings);
+
+ //Restrict it to these choices only:
+ n_combo_array[i].set_value_in_list();
+
+ //binding signal to thew actual entry
+ n_combo_array[i].get_entry()->signal_changed().connect
+ (
+ sigc::bind
+ (
+ sigc::mem_fun(*this, &MapWin::n_combo_changed),
+ i
+ )
+ );
+
+ //placing actual entry in the right place
+
+ label=new Gtk::Label;
+ label->set_text(node_property_strings[i]);
+
+ (*table).attach(*label,0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
+ (*table).attach(n_combo_array[i],1,2,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
+
}
- combos.pack_start(vbox_r1);
- combos.pack_start(vbox_r2);
+ add(vbox);
- //add(combos);
- add(table);
+ vbox.pack_start(*(new Gtk::Label("Node properties")));
+
+ vbox.pack_start(*table);
show_all_children();
}
-void MapWin::combo_changed(int prop)
+void MapWin::e_combo_changed(int prop)
{
-
- //most nem kommentezem fel, mert ugyis valtozik
- Gtk::Entry* entry = combo_array[prop].get_entry();
+ Gtk::Entry* entry = e_combo_array[prop].get_entry();
if(entry)
{
@@ -128,21 +190,57 @@
{
if(mapname=="Default")
{
- mapname=property_strings[prop];
+ mapname=edge_property_strings[prop];
}
if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() )
{
switch(prop)
{
- case WIDTH:
- gdc.changeLineWidth(mapname);
+ case E_WIDTH:
+ gdc.changeEdgeWidth(mapname);
+ break;
+ case E_COLOR:
+ gdc.changeEdgeColor(mapname);
+ break;
+ case E_TEXT:
+ gdc.changeEdgeText(mapname);
+ break;
+ default:
+ std::cout<<"Error\n";
+ }
+ }
+ }
+ }
+};
+
+void MapWin::n_combo_changed(int prop)
+{
+
+ Gtk::Entry* entry = n_combo_array[prop].get_entry();
+
+ if(entry)
+ {
+ Glib::ustring mapname = entry->get_text();
+ if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
+ {
+ if(mapname=="Default")
+ {
+ mapname=node_property_strings[prop];
+ }
+
+ if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() )
+ {
+ switch(prop)
+ {
+ case N_RADIUS:
+ gdc.changeNodeRadius(mapname);
break;
- case COLOR:
- gdc.changeColor(mapname);
+ case N_COLOR:
+ gdc.changeNodeColor(mapname);
break;
- case TEXT:
- gdc.changeText(mapname);
+ case N_TEXT:
+ gdc.changeNodeText(mapname);
break;
default:
std::cout<<"Error\n";
@@ -151,3 +249,82 @@
}
}
};
+
+void MapWin::update_node(Graph::Node node)
+{
+ for(int i=0;i<NODE_PROPERTY_NUM;i++)
+ {
+ Gtk::Entry* entry = n_combo_array[i].get_entry();
+
+ if(entry)
+ {
+ Glib::ustring mapname = entry->get_text();
+ if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
+ {
+ if(mapname=="Default")
+ {
+ mapname=node_property_strings[i];
+ }
+
+ if( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() )
+ {
+ switch(i)
+ {
+ case N_RADIUS:
+ //gdc.changeNodeRadius(mapname, node);
+ std::cout << "If default map-value problem is solved, uncomment line in MapWin::node_update!" << std::endl;
+ break;
+ case N_COLOR:
+ gdc.changeNodeColor(mapname, node);
+ break;
+ case N_TEXT:
+ gdc.changeNodeText(mapname, node);
+ break;
+ default:
+ std::cout<<"Error\n";
+ }
+ }
+ }
+ }
+ }
+}
+
+void MapWin::update_edge(Graph::Edge edge)
+{
+ for(int i=0;i<EDGE_PROPERTY_NUM;i++)
+ {
+
+ Gtk::Entry* entry = e_combo_array[i].get_entry();
+
+ if(entry)
+ {
+ Glib::ustring mapname = entry->get_text();
+ if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
+ {
+ if(mapname=="Default")
+ {
+ mapname=edge_property_strings[i];
+ }
+
+ if( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() )
+ {
+ switch(i)
+ {
+ case E_WIDTH:
+ //gdc.changeEdgeWidth(mapname, edge);
+ std::cout << "If default map-value problem is solved, uncomment line in MapWin::edge_update!" << std::endl;
+ break;
+ case E_COLOR:
+ gdc.changeEdgeColor(mapname, edge);
+ break;
+ case E_TEXT:
+ gdc.changeEdgeText(mapname, edge);
+ break;
+ default:
+ std::cout<<"Error\n";
+ }
+ }
+ }
+ }
+ }
+}
Modified: hugo/trunk/gui/map_win.h
==============================================================================
--- hugo/trunk/gui/map_win.h (original)
+++ hugo/trunk/gui/map_win.h Fri Jun 24 20:16:12 2005
@@ -3,6 +3,8 @@
#ifndef MAP_WIN_H
#define MAP_WIN_H
+class MapWin;
+
#include <all_include.h>
#include <mapstorage.h>
#include <graph_displayer_canvas.h>
@@ -24,15 +26,14 @@
///The \ref MapStorage in which the visualizable maps are stored
MapStorage & ms;
- Gtk::Table table;
+ Gtk::Table * table;
- Gtk::HBox combos, * labelpluscombo;
- Gtk::Combo * combo_array;
-
- Gtk::VBox vbox_b, vbox_r1, vbox_r2;
+ Gtk::Combo * e_combo_array, * n_combo_array;
Gtk::Label * label;
+ Gtk::VBox vbox;
+
public:
///Constructor of MapWin creates the widgets shown in MapWin.
MapWin(const std::string& title, MapStorage &, GraphDisplayerCanvas &);
@@ -41,7 +42,19 @@
///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 combo_changed(int);
+ virtual void e_combo_changed(int);
+ ///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 n_combo_changed(int);
+
+ ///This function is created to set the appropriate maps on the newly created node
+ void update_node(Graph::Node);
+
+ ///This function is created to set the appropriate maps on the newly created edge
+ void update_edge(Graph::Edge);
+
virtual bool close_if_escape_is_pressed(GdkEventKey*);
};
Modified: hugo/trunk/gui/mapstorage.cc
==============================================================================
--- hugo/trunk/gui/mapstorage.cc (original)
+++ hugo/trunk/gui/mapstorage.cc Fri Jun 24 20:16:12 2005
@@ -2,20 +2,34 @@
MapStorage::MapStorage(Graph & graph):g(graph)
{
- for(int i=0;i<PROPERTY_NUM;i++)
+ for(int i=0;i<EDGE_PROPERTY_NUM;i++)
{
- Graph::EdgeMap<double> emd(g);
+ Graph::EdgeMap<double> emd(g,edge_property_defaults[i]);
default_edgemaps.push_back(emd);
- Graph::NodeMap<double> nmd(g);
+ }
+
+ for(int i=0;i<NODE_PROPERTY_NUM;i++)
+ {
+ Graph::NodeMap<double> nmd(g,node_property_defaults[i]);
default_nodemaps.push_back(nmd);
}
- for(int i=0;i<PROPERTY_NUM;i++)
+
+ for(int i=0;i<EDGE_PROPERTY_NUM;i++)
{
for (EdgeIt j(g); j!=INVALID; ++j)
{
- (default_edgemaps[i])[j]=property_defaults[i];
+ (default_edgemaps[i])[j]=edge_property_defaults[i];
+ }
+ addEdgeMap(edge_property_strings[i],&(default_edgemaps[i]));
+ }
+
+ for(int i=0;i<NODE_PROPERTY_NUM;i++)
+ {
+ for (NodeIt j(g); j!=INVALID; ++j)
+ {
+ (default_nodemaps[i])[j]=node_property_defaults[i];
}
- addEdgeMap(property_strings[i],&(default_edgemaps[i]));
+ addNodeMap(node_property_strings[i],&(default_nodemaps[i]));
}
};
@@ -99,7 +113,7 @@
// std::cout << std::endl;
// g_closure_invoke...
-// for(int i=0;i<PROPERTY_NUM;i++)
+// for(int i=0;i<EDGE_PROPERTY_NUM;i++)
// {
// (default_edgemaps[i])[e]=property_defaults[i];
// }
More information about the Lemon-commits
mailing list