# HG changeset patch # User hegyi # Date 1129823423 0 # Node ID 616bc933c2bce4b90fe9854b1b41748d8e1bfd0d # Parent fffa6456548ae169070c6585ab74dc9b2f0b93ce Mapselector widget reached its first release, but there are still work to do on it, I know... diff -r fffa6456548a -r 616bc933c2bc gui/Makefile.am --- a/gui/Makefile.am Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/Makefile.am Thu Oct 20 15:50:23 2005 +0000 @@ -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) diff -r fffa6456548a -r 616bc933c2bc gui/all_include.h --- a/gui/all_include.h Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/all_include.h Thu Oct 20 15:50:23 2005 +0000 @@ -32,6 +32,7 @@ extern std::vector edge_property_defaults; extern std::vector node_property_strings; extern std::vector node_property_defaults; +extern int longest_property_string_length; #endif //MAIN_PART using namespace lemon; diff -r fffa6456548a -r 616bc933c2bc gui/graph-displayer.cc --- a/gui/graph-displayer.cc Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/graph-displayer.cc Thu Oct 20 15:50:23 2005 +0000 @@ -10,7 +10,7 @@ std::vector edge_property_defaults; std::vector node_property_strings; std::vector 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;ilongest_property_string_length) + { + longest_property_string_length=j; + } + } + for(int i=0;ilongest_property_string_length) + { + longest_property_string_length=j; + } + } + + //initializing GUI Gnome::Canvas::init(); diff -r fffa6456548a -r 616bc933c2bc gui/graph_displayer_canvas-edge.cc --- a/gui/graph_displayer_canvas-edge.cc Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/graph_displayer_canvas-edge.cc Thu Oct 20 15:50:23 2005 +0000 @@ -3,23 +3,52 @@ #include +int GraphDisplayerCanvas::resetEdgeWidth (Edge edge) +{ + Graph::EdgeMap * actual_map; + double min, max; + + min=edge_property_defaults[E_WIDTH]; + max=edge_property_defaults[E_WIDTH]; + actual_map=new Graph::EdgeMap(mapstorage.graph,edge_property_defaults[E_WIDTH]); + + if(edge==INVALID) + { + 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 + { + 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 * 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(mapstorage.graph,edge_property_defaults[E_WIDTH]); - } - else - { - min=mapstorage.minOfEdgeMap(mapname); - max=mapstorage.maxOfEdgeMap(mapname); - actual_map=(mapstorage.edgemap_storage)[mapname]; - } + 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 * actual_map; - if(mapname=="Default") + actual_map=(mapstorage.edgemap_storage)[mapname]; + + double max, min; + + max=mapstorage.maxOfEdgeMap(mapname); + min=mapstorage.minOfEdgeMap(mapname); + + if(edge==INVALID) { - actual_map=new Graph::EdgeMap(mapstorage.graph,edge_property_defaults[E_COLOR]); + 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 { - actual_map=(mapstorage.edgemap_storage)[mapname]; + 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 * actual_map; + actual_map=new Graph::EdgeMap(mapstorage.graph,edge_property_defaults[E_COLOR]); double max, min; - if(mapname!="Default") - { - max=mapstorage.maxOfEdgeMap(mapname); - min=mapstorage.minOfEdgeMap(mapname); - } - else - { - max=edge_property_defaults[E_COLOR]; - min=edge_property_defaults[E_COLOR]; - } + max=edge_property_defaults[E_COLOR]; + min=edge_property_defaults[E_COLOR]; if(edge==INVALID) { @@ -127,42 +193,51 @@ { 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 - { - edgetextmap[edge]->property_text().set_value(""); - } - } 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) + { + edgemap_to_edit=""; + edgetextmap[i]->property_text().set_value(""); + } + + } + else + { + edgetextmap[edge]->property_text().set_value(""); + } + + return 0; + +}; diff -r fffa6456548a -r 616bc933c2bc gui/graph_displayer_canvas-node.cc --- a/gui/graph_displayer_canvas-node.cc Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/graph_displayer_canvas-node.cc Thu Oct 20 15:50:23 2005 +0000 @@ -7,19 +7,67 @@ { Graph::NodeMap * 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(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 * actual_map; + double min, max; + min=node_property_defaults[N_RADIUS]; + max=node_property_defaults[N_RADIUS]; + actual_map=new Graph::NodeMap(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 * actual_map; - if(mapname=="Default") + actual_map=(mapstorage.nodemap_storage)[mapname]; + + double max, min; + + max=mapstorage.maxOfNodeMap(mapname); + min=mapstorage.minOfNodeMap(mapname); + + if(node==INVALID) { - actual_map=new Graph::NodeMap(mapstorage.graph,node_property_defaults[N_COLOR]); + + 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 { - actual_map=(mapstorage.nodemap_storage)[mapname]; + 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 * actual_map; + actual_map=new Graph::NodeMap(mapstorage.graph,node_property_defaults[N_COLOR]); double max, min; - if(mapname!="Default") - { - max=mapstorage.maxOfNodeMap(mapname); - min=mapstorage.minOfNodeMap(mapname); - } - else - { - max=node_property_defaults[N_COLOR]; - min=node_property_defaults[N_COLOR]; - } - + 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 * 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(""); - } + 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) + { + nodemap_to_edit=""; + nodetextmap[i]->property_text().set_value(""); + } + } + else + { + nodetextmap[node]->property_text().set_value(""); + } + return 0; +}; diff -r fffa6456548a -r 616bc933c2bc gui/graph_displayer_canvas.h --- a/gui/graph_displayer_canvas.h Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/graph_displayer_canvas.h Thu Oct 20 15:50:23 2005 +0000 @@ -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(); diff -r fffa6456548a -r 616bc933c2bc gui/map_win.cc --- a/gui/map_win.cc Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/map_win.cc Thu Oct 20 15:50:23 2005 +0000 @@ -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 listStrings; + e_combo_array[i]=new MapSelector(gdc, ms, *this, i, true); - listStrings.push_back("Default"); - - std::map< std::string,Graph::EdgeMap * >::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); - - + (*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 listStrings; + n_combo_array[i]=new MapSelector(gdc, ms, *this, i, false); - listStrings.push_back("Default"); - - std::map< std::string,Graph::NodeMap * >::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); - - + (*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 listStrings; + e_combo_array[i]->update_list(); + } - listStrings.push_back("Default"); - - std::map< std::string,Graph::EdgeMap * >::iterator emsi=ms.beginOfEdgeMaps(); - for(;emsi!=ms.endOfEdgeMaps();emsi++) - { - listStrings.push_back(emsi->first); - } - - e_combo_array[i].set_popdown_strings(listStrings); - } for(int i=0;i listStrings; - - listStrings.push_back("Default"); - - std::map< std::string,Graph::NodeMap * >::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;iget_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;iget_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 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 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); } diff -r fffa6456548a -r 616bc933c2bc gui/map_win.h --- a/gui/map_win.h Mon Oct 17 10:30:59 2005 +0000 +++ b/gui/map_win.h Thu Oct 20 15:50:23 2005 +0000 @@ -8,6 +8,7 @@ #include "all_include.h" #include "graph_displayer_canvas.h" #include "mapstorage.h" +#include "mapselector.h" #include #include @@ -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); diff -r fffa6456548a -r 616bc933c2bc gui/mapselector.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/mapselector.cc Thu Oct 20 15:50:23 2005 +0000 @@ -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 * >::iterator emsi=ms.beginOfEdgeMaps(); + for(;emsi!=ms.endOfEdgeMaps();emsi++) + { + cbt.append_text(emsi->first); + } + } + else + { + std::map< std::string,Graph::NodeMap * >::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); +} diff -r fffa6456548a -r 616bc933c2bc gui/mapselector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/mapselector.h Thu Oct 20 15:50:23 2005 +0000 @@ -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 +#include + +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