[Lemon-commits] [lemon_svn] hegyi: r2258 - hugo/trunk/gui
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:51:19 CET 2006
Author: hegyi
Date: Thu Oct 20 17:50:23 2005
New Revision: 2258
Added:
hugo/trunk/gui/mapselector.cc
hugo/trunk/gui/mapselector.h
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-node.cc
hugo/trunk/gui/graph_displayer_canvas.h
hugo/trunk/gui/map_win.cc
hugo/trunk/gui/map_win.h
Log:
Mapselector widget reached its first release, but there are still work to do on it, I know...
Modified: hugo/trunk/gui/Makefile.am
==============================================================================
--- hugo/trunk/gui/Makefile.am (original)
+++ hugo/trunk/gui/Makefile.am Thu Oct 20 17:50:23 2005
@@ -26,7 +26,10 @@
new_map_win.cc \
new_map_win.h \
xymap.h \
- icons/guipixbufs.h
+ icons/guipixbufs.h\
+ mapselector.h\
+ mapselector.cc
+
glemon_CXXFLAGS = $(GTK_CFLAGS)
glemon_LDFLAGS = $(GTK_LIBS)
Modified: hugo/trunk/gui/all_include.h
==============================================================================
--- hugo/trunk/gui/all_include.h (original)
+++ hugo/trunk/gui/all_include.h Thu Oct 20 17:50:23 2005
@@ -32,6 +32,7 @@
extern std::vector <double> edge_property_defaults;
extern std::vector <std::string> node_property_strings;
extern std::vector <double> node_property_defaults;
+extern int longest_property_string_length;
#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 Thu Oct 20 17:50:23 2005
@@ -10,7 +10,7 @@
std::vector <double> edge_property_defaults;
std::vector <std::string> node_property_strings;
std::vector <double> node_property_defaults;
-
+int longest_property_string_length;
int main(int argc, char *argv[])
{
@@ -37,6 +37,25 @@
node_property_defaults[N_COLOR]=100;
node_property_defaults[N_TEXT]=0;
+ longest_property_string_length=0;
+ for(int i=0;i<EDGE_PROPERTY_NUM;i++)
+ {
+ int j=edge_property_strings[i].size();
+ if(j>longest_property_string_length)
+ {
+ longest_property_string_length=j;
+ }
+ }
+ for(int i=0;i<NODE_PROPERTY_NUM;i++)
+ {
+ int j=node_property_strings[i].size();
+ if(j>longest_property_string_length)
+ {
+ longest_property_string_length=j;
+ }
+ }
+
+
//initializing GUI
Gnome::Canvas::init();
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 Thu Oct 20 17:50:23 2005
@@ -3,23 +3,52 @@
#include <cmath>
-int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
+int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
{
Graph::EdgeMap<double> * actual_map;
double min, max;
- if(mapname=="Default")
+ min=edge_property_defaults[E_WIDTH];
+ max=edge_property_defaults[E_WIDTH];
+ actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
+
+ if(edge==INVALID)
{
- min=edge_property_defaults[E_WIDTH];
- max=edge_property_defaults[E_WIDTH];
- actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
+ for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ double v=fabs((*actual_map)[i]);
+ int w;
+ if(min==max)
+ {
+ w=(int)(edge_property_defaults[E_WIDTH]);
+ }
+ else
+ {
+ w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
+ }
+ edgesmap[i]->property_width_units().set_value(w);
+ }
}
else
{
- min=mapstorage.minOfEdgeMap(mapname);
- max=mapstorage.maxOfEdgeMap(mapname);
- actual_map=(mapstorage.edgemap_storage)[mapname];
+ int w=(int)(*actual_map)[edge];
+ if(w>=0)
+ {
+ edgesmap[edge]->property_width_units().set_value(w);
+ }
}
+ return 0;
+}
+
+
+int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
+{
+ Graph::EdgeMap<double> * actual_map;
+ double min, max;
+
+ min=mapstorage.minOfEdgeMap(mapname);
+ max=mapstorage.maxOfEdgeMap(mapname);
+ actual_map=(mapstorage.edgemap_storage)[mapname];
if(edge==INVALID)
{
@@ -56,27 +85,64 @@
//the minimum of the nodemap to the range of
//green in RGB
Graph::EdgeMap<double> * actual_map;
- if(mapname=="Default")
- {
- actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
- }
- else
- {
- actual_map=(mapstorage.edgemap_storage)[mapname];
- }
+ actual_map=(mapstorage.edgemap_storage)[mapname];
double max, min;
- if(mapname!="Default")
+ max=mapstorage.maxOfEdgeMap(mapname);
+ min=mapstorage.minOfEdgeMap(mapname);
+
+ if(edge==INVALID)
{
- max=mapstorage.maxOfEdgeMap(mapname);
- min=mapstorage.minOfEdgeMap(mapname);
+ for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ double w=(*actual_map)[i];
+
+ 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
{
- max=edge_property_defaults[E_COLOR];
- min=edge_property_defaults[E_COLOR];
+ Gdk::Color color;
+
+ double w=(*actual_map)[edge];
+
+ if(max!=min)
+ {
+ color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
+ }
+ else
+ {
+ color.set_rgb_p (0, 100, 0);
+ }
+
+ edgesmap[edge]->property_fill_color_gdk().set_value(color);
}
+ return 0;
+};
+
+int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
+{
+
+ //function maps the range of the maximum and
+ //the minimum of the nodemap to the range of
+ //green in RGB
+ Graph::EdgeMap<double> * actual_map;
+ actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
+
+ double max, min;
+
+ max=edge_property_defaults[E_COLOR];
+ min=edge_property_defaults[E_COLOR];
if(edge==INVALID)
{
@@ -127,40 +193,49 @@
{
for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
{
- if(mapname!="Default")
- {
- edgemap_to_edit=mapname;
- double number=(*(mapstorage.edgemap_storage)[mapname])[i];
-
- std::ostringstream ostr;
- ostr << number;
-
- edgetextmap[i]->property_text().set_value(ostr.str());
- }
- else
- {
- edgemap_to_edit="";
- edgetextmap[i]->property_text().set_value("");
- }
+ edgemap_to_edit=mapname;
+ double number=(*(mapstorage.edgemap_storage)[mapname])[i];
+
+ std::ostringstream ostr;
+ ostr << number;
+
+ edgetextmap[i]->property_text().set_value(ostr.str());
}
}
else
{
- if(mapname!="Default")
- {
double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
std::ostringstream ostr;
ostr << number;
edgetextmap[edge]->property_text().set_value(ostr.str());
- }
- else
+ }
+
+ return 0;
+
+};
+
+int GraphDisplayerCanvas::resetEdgeText (Edge edge)
+{
+ //the number in the map will be written on the edge
+ //EXCEPT when the name of the map is Default, because
+ //in that case empty string will be written, because
+ //that is the deleter map
+
+ if(edge==INVALID)
+ {
+ for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
{
- edgetextmap[edge]->property_text().set_value("");
+ edgemap_to_edit="";
+ edgetextmap[i]->property_text().set_value("");
}
-
+
+ }
+ else
+ {
+ edgetextmap[edge]->property_text().set_value("");
}
return 0;
Modified: hugo/trunk/gui/graph_displayer_canvas-node.cc
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas-node.cc (original)
+++ hugo/trunk/gui/graph_displayer_canvas-node.cc Thu Oct 20 17:50:23 2005
@@ -7,19 +7,67 @@
{
Graph::NodeMap<double> * actual_map;
double min, max;
- if(mapname=="Default")
+ min=mapstorage.minOfNodeMap(mapname);
+ max=mapstorage.maxOfNodeMap(mapname);
+ actual_map=(mapstorage.nodemap_storage)[mapname];
+
+ if(node==INVALID)
{
- min=node_property_defaults[N_RADIUS];
- max=node_property_defaults[N_RADIUS];
- actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
+ for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ double v=fabs((*actual_map)[i]);
+ int w;
+ if(min==max)
+ {
+ w=(int)(node_property_defaults[N_RADIUS]);
+ }
+ else
+ {
+ w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
+ }
+ if(w>=0)
+ {
+ double x1, y1, x2, y2;
+ x1=nodesmap[i]->property_x1().get_value();
+ x2=nodesmap[i]->property_x2().get_value();
+ y1=nodesmap[i]->property_y1().get_value();
+ y2=nodesmap[i]->property_y2().get_value();
+ 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
{
- min=mapstorage.minOfNodeMap(mapname);
- max=mapstorage.maxOfNodeMap(mapname);
- actual_map=(mapstorage.nodemap_storage)[mapname];
+ //I think only new nodes use this case
+// int w=(int)(*actual_map)[node];
+ int w=(int)(node_property_defaults[N_RADIUS]);
+ if(w>=0)
+ {
+ double x1, y1, x2, y2;
+ x1=nodesmap[node]->property_x1().get_value();
+ x2=nodesmap[node]->property_x2().get_value();
+ y1=nodesmap[node]->property_y1().get_value();
+ y2=nodesmap[node]->property_y2().get_value();
+ 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::resetNodeRadius (Node node)
+{
+ Graph::NodeMap<double> * actual_map;
+ double min, max;
+ min=node_property_defaults[N_RADIUS];
+ max=node_property_defaults[N_RADIUS];
+ actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
+
if(node==INVALID)
{
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
@@ -77,28 +125,68 @@
//green in RGB
Graph::NodeMap<double> * actual_map;
- if(mapname=="Default")
- {
- actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
- }
- else
- {
- actual_map=(mapstorage.nodemap_storage)[mapname];
- }
+ actual_map=(mapstorage.nodemap_storage)[mapname];
double max, min;
- if(mapname!="Default")
+ max=mapstorage.maxOfNodeMap(mapname);
+ min=mapstorage.minOfNodeMap(mapname);
+
+ if(node==INVALID)
{
- max=mapstorage.maxOfNodeMap(mapname);
- min=mapstorage.minOfNodeMap(mapname);
+
+ for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
+ {
+ Gdk::Color color;
+
+ double w=(*actual_map)[i];
+
+ 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
{
- max=node_property_defaults[N_COLOR];
- min=node_property_defaults[N_COLOR];
+ Gdk::Color color;
+
+ double w=(*actual_map)[node];
+
+ 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::resetNodeColor (Node node)
+{
+
+ //function maps the range of the maximum and
+ //the minimum of the nodemap to the range of
+ //green in RGB
+
+ Graph::NodeMap<double> * actual_map;
+ actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
+
+ double max, min;
+ max=node_property_defaults[N_COLOR];
+ min=node_property_defaults[N_COLOR];
if(node==INVALID)
{
@@ -150,47 +238,52 @@
//that is the deleter map
Graph::NodeMap<double> * actual_map=NULL;
- if(mapname!="Default")
- {
- actual_map=(mapstorage.nodemap_storage)[mapname];
- }
+ actual_map=(mapstorage.nodemap_storage)[mapname];
if(node==INVALID)
{
for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
{
- if(mapname!="Default")
- {
- nodemap_to_edit=mapname;
- double number=(*actual_map)[i];
+ nodemap_to_edit=mapname;
+ double number=(*actual_map)[i];
- std::ostringstream ostr;
- ostr << number;
+ std::ostringstream ostr;
+ ostr << number;
- nodetextmap[i]->property_text().set_value(ostr.str());
- }
- else
- {
- nodemap_to_edit="";
- nodetextmap[i]->property_text().set_value("");
- }
+ nodetextmap[i]->property_text().set_value(ostr.str());
}
}
else
{
- if(mapname!="Default")
- {
- double number=(*actual_map)[node];
+ double number=(*actual_map)[node];
- std::ostringstream ostr;
- ostr << number;
+ std::ostringstream ostr;
+ ostr << number;
- nodetextmap[node]->property_text().set_value(ostr.str());
- }
- else
+ nodetextmap[node]->property_text().set_value(ostr.str());
+ }
+ return 0;
+};
+
+int GraphDisplayerCanvas::resetNodeText (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
+
+ if(node==INVALID)
+ {
+ for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
{
- nodetextmap[node]->property_text().set_value("");
+ nodemap_to_edit="";
+ nodetextmap[i]->property_text().set_value("");
}
}
+ else
+ {
+ nodetextmap[node]->property_text().set_value("");
+ }
return 0;
};
Modified: hugo/trunk/gui/graph_displayer_canvas.h
==============================================================================
--- hugo/trunk/gui/graph_displayer_canvas.h (original)
+++ hugo/trunk/gui/graph_displayer_canvas.h Thu Oct 20 17:50:23 2005
@@ -24,26 +24,32 @@
///Changes the linewidth attribute according to the given map.
///\param mapname is the name of the map which contains the new values
int changeEdgeWidth (std::string mapname, Edge new_item=INVALID);
+ int resetEdgeWidth (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 changeEdgeColor (std::string mapname, Edge new_item=INVALID);
+ int resetEdgeColor (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 changeEdgeText (std::string mapname, Edge new_item=INVALID);
+ int resetEdgeText (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, Node new_item=INVALID);
+ int resetNodeRadius (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, Node new_item=INVALID);
+ int resetNodeColor (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, Node new_item=INVALID);
+ int resetNodeText (Node new_item=INVALID);
///Callback for 'ViewZoomIn' action.
virtual void zoomIn();
Modified: hugo/trunk/gui/map_win.cc
==============================================================================
--- hugo/trunk/gui/map_win.cc (original)
+++ hugo/trunk/gui/map_win.cc Thu Oct 20 17:50:23 2005
@@ -17,47 +17,15 @@
signal_key_press_event().connect(sigc::mem_fun(*this, &MapWin::closeIfEscapeIsPressed));
- e_combo_array=new Gtk::Combo [EDGE_PROPERTY_NUM];
+ e_combo_array=new MapSelector * [EDGE_PROPERTY_NUM];
- table=new Gtk::Table(EDGE_PROPERTY_NUM, 2, false);
+ table=new Gtk::Table(EDGE_PROPERTY_NUM, 1, false);
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
{
- //filling in combo box with choices
- std::list<Glib::ustring> listStrings;
-
- listStrings.push_back("Default");
-
- std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
- for(;emsi!=ms.endOfEdgeMaps();emsi++)
- {
- listStrings.push_back(emsi->first);
- }
-
- e_combo_array[i].set_popdown_strings(listStrings);
-
- //Restrict it to these choices only:
- e_combo_array[i].set_value_in_list();
-
- //binding signal to the actual entry
- e_combo_array[i].get_entry()->signal_changed().connect
- (
- sigc::bind
- (
- sigc::mem_fun(*this, &MapWin::eComboChanged),
- i
- )
- );
-
- //placing actual entry in the right place
-
- label=new Gtk::Label;
- label->set_text(edge_property_strings[i]);
-
- (*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);
-
+ e_combo_array[i]=new MapSelector(gdc, ms, *this, i, true);
+ (*table).attach((*(e_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
}
vbox.pack_start(*(new Gtk::Label("Edge properties")));
@@ -66,51 +34,15 @@
vbox.pack_start(*(new Gtk::HSeparator));
- n_combo_array=new Gtk::Combo [NODE_PROPERTY_NUM];
+ n_combo_array=new MapSelector * [NODE_PROPERTY_NUM];
- table=new Gtk::Table(NODE_PROPERTY_NUM, 2, false);
+ table=new Gtk::Table(NODE_PROPERTY_NUM, 1, false);
for(int i=0;i<NODE_PROPERTY_NUM;i++)
{
- //filling in combo box with choices
- std::list<Glib::ustring> listStrings;
-
- listStrings.push_back("Default");
-
- std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
-
- for(;emsi!=ms.endOfNodeMaps();emsi++)
- {
- if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
- {
- listStrings.push_back(emsi->first);
- }
- }
-
- 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::nComboChanged),
- 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);
-
+ n_combo_array[i]=new MapSelector(gdc, ms, *this, i, false);
+ (*table).attach((*(n_combo_array[i])),0,1,i,i+1,Gtk::SHRINK,Gtk::SHRINK,10,3);
}
add(vbox);
@@ -127,132 +59,21 @@
{
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
{
- //filling in combo box with choices
- std::list<Glib::ustring> listStrings;
-
- listStrings.push_back("Default");
-
- std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
- for(;emsi!=ms.endOfEdgeMaps();emsi++)
- {
- listStrings.push_back(emsi->first);
- }
-
- e_combo_array[i].set_popdown_strings(listStrings);
+ e_combo_array[i]->update_list();
}
+
for(int i=0;i<NODE_PROPERTY_NUM;i++)
{
- //filling in combo box with choices
- std::list<Glib::ustring> listStrings;
-
- listStrings.push_back("Default");
-
- std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
-
- for(;emsi!=ms.endOfNodeMaps();emsi++)
- {
- if ((emsi->first != "coordinates_x") && (emsi->first != "coordinates_y"))
- {
- listStrings.push_back(emsi->first);
- }
- }
-
- n_combo_array[i].set_popdown_strings(listStrings);
+ n_combo_array[i]->update_list();
}
}
-void MapWin::eComboChanged(int prop)
-{
-
- Gtk::Entry* entry = e_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( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
- {
- switch(prop)
- {
- case E_WIDTH:
- gdc.changeEdgeWidth(mapname);
- break;
- case E_COLOR:
- gdc.changeEdgeColor(mapname);
- break;
- case E_TEXT:
- gdc.changeEdgeText(mapname);
- break;
- default:
- std::cerr<<"Error\n";
- }
- }
- }
- }
-};
-
-void MapWin::nComboChanged(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( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
- {
- switch(prop)
- {
- case N_RADIUS:
- gdc.changeNodeRadius(mapname);
- break;
- case N_COLOR:
- gdc.changeNodeColor(mapname);
- break;
- case N_TEXT:
- gdc.changeNodeText(mapname);
- break;
- default:
- std::cerr<<"Error\n";
- }
- }
- }
- }
-};
void MapWin::updateNode(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( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) || (mapname=="Default") )
- {
- switch(i)
- {
- case N_RADIUS:
- gdc.changeNodeRadius(mapname, node);
- break;
- case N_COLOR:
- gdc.changeNodeColor(mapname, node);
- break;
- case N_TEXT:
- gdc.changeNodeText(mapname, node);
- break;
- default:
- std::cerr<<"Error\n";
- }
- }
- }
- }
+ n_combo_array[i]->update(node);
}
}
@@ -260,34 +81,7 @@
{
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( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) || (mapname=="Default") )
- {
- switch(i)
- {
- case E_WIDTH:
- gdc.changeEdgeWidth(mapname, edge);
- break;
- case E_COLOR:
- gdc.changeEdgeColor(mapname, edge);
- break;
- case E_TEXT:
- gdc.changeEdgeText(mapname, edge);
- break;
- default:
- std::cerr<<"Error\n";
- }
- }
- }
- }
+ e_combo_array[i]->update(edge);
}
}
@@ -296,13 +90,10 @@
for(int i=0;i<EDGE_PROPERTY_NUM;i++)
{
//filling in combo box with choices
- std::list<Glib::ustring> listStrings=e_combo_array[i].get_popdown_strings();
- listStrings.push_back(newmapname);
- e_combo_array[i].set_popdown_strings(listStrings);
+ e_combo_array[i]->append_text((Glib::ustring)newmapname);
}
//setting text property for the new map
- Gtk::Entry* entry = e_combo_array[E_TEXT].get_entry();
- entry->set_text((Glib::ustring)newmapname);
+ e_combo_array[N_TEXT]->set_active_text((Glib::ustring)newmapname);
}
void MapWin::registerNewNodeMap(std::string newmapname)
@@ -310,11 +101,8 @@
for(int i=0;i<NODE_PROPERTY_NUM;i++)
{
//filling in combo box with choices
- std::list<Glib::ustring> listStrings=n_combo_array[i].get_popdown_strings();
- listStrings.push_back(newmapname);
- n_combo_array[i].set_popdown_strings(listStrings);
+ e_combo_array[i]->append_text((Glib::ustring)newmapname);
}
//setting text property for the new map
- Gtk::Entry* entry = n_combo_array[N_TEXT].get_entry();
- entry->set_text((Glib::ustring)newmapname);
+ n_combo_array[N_TEXT]->set_active_text((Glib::ustring)newmapname);
}
Modified: hugo/trunk/gui/map_win.h
==============================================================================
--- hugo/trunk/gui/map_win.h (original)
+++ hugo/trunk/gui/map_win.h Thu Oct 20 17:50:23 2005
@@ -8,6 +8,7 @@
#include "all_include.h"
#include "graph_displayer_canvas.h"
#include "mapstorage.h"
+#include "mapselector.h"
#include <libgnomecanvasmm.h>
#include <libgnomecanvasmm/polygon.h>
@@ -28,7 +29,7 @@
Gtk::Table * table;
- Gtk::Combo * e_combo_array, * n_combo_array;
+ MapSelector ** e_combo_array, ** n_combo_array;
Gtk::Label * label;
@@ -38,17 +39,6 @@
///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 eComboChanged(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 nComboChanged(int);
-
///This function is created to set the appropriate maps on the newly created node
void updateNode(Graph::Node);
Added: hugo/trunk/gui/mapselector.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/gui/mapselector.cc Thu Oct 20 17:50:23 2005
@@ -0,0 +1,209 @@
+#include "mapselector.h"
+
+MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, MapWin & mapw, int identifier, bool edge):gdc(grdispc),ms(mapst),mw(mapw),id(identifier),itisedge(edge),default_state(true),node_to_update(INVALID),edge_to_update(INVALID)
+{
+ update_list();
+
+ cbt.set_active(0);
+
+ //binding signal to the actual entry
+ cbt.signal_changed().connect
+ (
+ sigc::mem_fun((*this), &MapSelector::comboChanged),
+ false
+ );
+
+ if(itisedge)
+ {
+ label=new Gtk::Label(edge_property_strings[id]);
+ }
+ else
+ {
+ label=new Gtk::Label(node_property_strings[id]);
+ }
+
+ label->set_width_chars(longest_property_string_length);
+
+ defbut=new Gtk::Button();
+ defbut->set_label("Reset");
+
+ defbut->signal_pressed().connect
+ (
+ sigc::mem_fun(*this, &MapSelector::reset)
+ );
+
+ newbut=new Gtk::Button(Gtk::Stock::NEW);
+
+ add(*label);
+
+ add(cbt);
+
+ add(*defbut);
+ add(*newbut);
+}
+
+void MapSelector::update_list()
+{
+ cbt.clear();
+ if(itisedge)
+ {
+ std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
+ for(;emsi!=ms.endOfEdgeMaps();emsi++)
+ {
+ cbt.append_text(emsi->first);
+ }
+ }
+ else
+ {
+ std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
+ for(;emsi!=ms.endOfNodeMaps();emsi++)
+ {
+ cbt.append_text(emsi->first);
+ }
+ }
+ cbt.prepend_text("Default values");
+}
+
+void MapSelector::comboChanged()
+{
+ if(cbt.get_active_row_number()!=0)
+ {
+ default_state=false;
+ Glib::ustring mapname = cbt.get_active_text();
+ if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
+ {
+ if(itisedge)
+ {
+ if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) )
+ {
+ Edge edge=edge_to_update;
+ switch(id)
+ {
+ case E_WIDTH:
+ gdc.changeEdgeWidth(mapname, edge);
+ break;
+ case E_COLOR:
+ gdc.changeEdgeColor(mapname, edge);
+ break;
+ case E_TEXT:
+ gdc.changeEdgeText(mapname, edge);
+ break;
+ default:
+ std::cerr<<"Error\n";
+ }
+ }
+ }
+ else
+ {
+ if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) )
+ {
+ Node node=node_to_update;
+ switch(id)
+ {
+ case N_RADIUS:
+ gdc.changeNodeRadius(mapname, node);
+ break;
+ case N_COLOR:
+ gdc.changeNodeColor(mapname, node);
+ break;
+ case N_TEXT:
+ gdc.changeNodeText(mapname, node);
+ break;
+ default:
+ std::cerr<<"Error\n";
+ }
+ }
+ }
+ }
+ }
+ else if((!default_state)&&(cbt.get_active_row_number()==0))
+ {
+ reset();
+ }
+}
+
+void MapSelector::reset()
+{
+ default_state=true;
+ cbt.set_active(0);
+
+ if(itisedge)
+ {
+ Edge edge=edge_to_update;
+ switch(id)
+ {
+ case E_WIDTH:
+ gdc.resetEdgeWidth(edge);
+ break;
+ case E_COLOR:
+ gdc.resetEdgeColor(edge);
+ break;
+ case E_TEXT:
+ gdc.resetEdgeText(edge);
+ break;
+ default:
+ std::cerr<<"Error\n";
+ }
+ }
+ else
+ {
+ Node node=node_to_update;
+ switch(id)
+ {
+ case N_RADIUS:
+ gdc.resetNodeRadius(node);
+ break;
+ case N_COLOR:
+ gdc.resetNodeColor(node);
+ break;
+ case N_TEXT:
+ gdc.resetNodeText(node);
+ break;
+ default:
+ std::cerr<<"Error\n";
+ }
+ }
+}
+
+void MapSelector::update(Node node)
+{
+ node_to_update=node;
+ if(default_state)
+ {
+ reset();
+ }
+ else
+ {
+ comboChanged();
+ }
+ node_to_update=INVALID;
+}
+
+void MapSelector::update(Edge edge)
+{
+ edge_to_update=edge;
+ if(default_state)
+ {
+ reset();
+ }
+ else
+ {
+ comboChanged();
+ }
+ edge_to_update=INVALID;
+}
+
+Glib::ustring MapSelector::get_active_text()
+{
+ return cbt.get_active_text();
+}
+
+void MapSelector::set_active_text(Glib::ustring text)
+{
+ cbt.set_active_text(text);
+}
+
+void MapSelector::append_text(Glib::ustring text)
+{
+ cbt.append_text(text);
+}
Added: hugo/trunk/gui/mapselector.h
==============================================================================
--- (empty file)
+++ hugo/trunk/gui/mapselector.h Thu Oct 20 17:50:23 2005
@@ -0,0 +1,63 @@
+// -*- C++ -*- //
+
+#ifndef MAP_SELECTOR_H
+#define MAP_SELECTOR_H
+
+class MapSelector;
+
+#include "all_include.h"
+#include "mapstorage.h"
+#include "map_win.h"
+#include "graph_displayer_canvas.h"
+#include <libgnomecanvasmm.h>
+#include <libgnomecanvasmm/polygon.h>
+
+class MapSelector : public Gtk::HBox
+{
+protected:
+ GraphDisplayerCanvas & gdc;
+ ///The \ref MapStorage in which the visualizable maps are stored
+ MapStorage & ms;
+ MapWin & mw;
+
+ int id;
+
+ bool itisedge;
+
+ bool default_state;
+
+ Gtk::ComboBoxText cbt;
+
+ Gtk::Button * newbut, * defbut;
+
+ Gtk::HBox hbox;
+
+ Gtk::Label * label;
+
+ Node node_to_update;
+ Edge edge_to_update;
+
+
+public:
+
+ MapSelector(GraphDisplayerCanvas &, MapStorage &, MapWin &, int, bool);
+
+ void update_list();
+
+ ///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 comboChanged();
+
+ virtual void reset();
+
+ virtual void update(Node node);
+ virtual void update(Edge edge);
+
+ Glib::ustring get_active_text();
+ void set_active_text(Glib::ustring);
+ void append_text(Glib::ustring);
+};
+
+#endif
More information about the Lemon-commits
mailing list