# HG changeset patch # User hegyi # Date 1132574825 0 # Node ID fd82adfbe905d55c0e1a8a4fbf987b5e2a36502c # Parent 8f9905c4e1c16cb4352842f04d4840d79dc84743 Reorganizing. diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/Makefile.am --- a/gui/Makefile.am Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/Makefile.am Mon Nov 21 12:07:05 2005 +0000 @@ -15,20 +15,18 @@ graph_displayer_canvas-zoom.cc \ graph_displayer_canvas.h \ graph-displayer.cc \ + gdc-broken_edge.cc \ main_win.cc \ main_win.h \ mapstorage.cc \ mapstorage.h \ map_win.cc \ map_win.h \ - broken_edge.cc \ - broken_edge.h \ + mw-mapselector.cc \ new_map_win.cc \ new_map_win.h \ xymap.h \ - icons/guipixbufs.h\ - mapselector.h\ - mapselector.cc + icons/guipixbufs.h glemon_CXXFLAGS = $(GTK_CFLAGS) diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/broken_edge.cc --- a/gui/broken_edge.cc Mon Nov 21 09:08:16 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,214 +0,0 @@ -#include "broken_edge.h" -#include - -BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false) -{ - my_points=new Gnome::Art::Point[3]; - - arrow=new Gnome::Canvas::Polygon(g); - *arrow << Gnome::Canvas::Properties::fill_color("red"); - arrow->signal_event().connect(sigc::mem_fun(*this, &BrokenEdge::edgeFormerEventHandler)); - arrow->lower_to_bottom(); - setPoints(p); -} - -BrokenEdge::~BrokenEdge() -{ - if(arrow)delete(arrow); -} - -void BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move) -{ - bool set_arrow=false; - //red arrow losts its position-right button - if(!move) - { - if(p.size()==2) - { - set_arrow=true; - Gnome::Canvas::Points points_with_center; - points_with_center.push_back(my_points[0]=p[0]); - points_with_center.push_back(my_points[1]=Gnome::Art::Point( (p[0].get_x()+p[1].get_x())/2+0 , (p[0].get_y()+p[1].get_y())/2 )+0 ); - points_with_center.push_back(my_points[2]=p[1]); - property_points().set_value(points_with_center); - } - if(p.size()==3) - { - set_arrow=true; - property_points().set_value(p); - for(int i=0;i<3;i++) - { - my_points[i]=p[i]; - } - } - } - else - { - //arrow keeps its position-left button - -// if(p.size()==2) -// { -// Gnome::Canvas::Points points; -// my_points[0]=p[0]; -// my_points[2]=p[1]; -// for(int i=0;i<3;i++) -// { -// points.push_back(my_points[i]); -// } -// property_points().set_value(points); -// } - set_arrow=true; - - ////////////////////////////////////////////////////////////////////////////////////////////////////// - /////////// keeps shape-with scalar multiplication - version 2. - ////////////////////////////////////////////////////////////////////////////////////////////////////// - - if(p.size()==2) - { - //old vector from one to the other node - a - xy a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y()); - //new vector from one to the other node - b - xy b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y()); - - double absa=sqrt(a_v.normSquare()); - double absb=sqrt(b_v.normSquare()); - - //old vector from one node to the breakpoint - c - xy c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y()); - - //unit vector with the same direction to a_v - xy a_v_u(a_v.x/absa,a_v.y/absa); - - //normal vector of unit vector with the same direction to a_v - xy a_v_u_n(((-1)*a_v_u.y),a_v_u.x); - - //unit vector with the same direction to b_v - xy b_v_u(b_v.x/absb,b_v.y/absb); - - //normal vector of unit vector with the same direction to b_v - xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); - - //vector c in a_v_u and a_v_u_n co-ordinate system - xy c_a(c_v*a_v_u,c_v*a_v_u_n); - - //new vector from one node to the breakpoint - d - we have to calculate this one - xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); - - my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y()); - - my_points[0]=p[0]; - my_points[2]=p[1]; - - Gnome::Canvas::Points points; - for(int i=0;i<3;i++) - { - points.push_back(my_points[i]); - } - property_points().set_value(points); - } - } - if(set_arrow) - { - //calculating coordinates of the direction indicator arrow - - xy target( my_points[2].get_x(), my_points[2].get_y() ); - xy center( my_points[1].get_x(), my_points[1].get_y() ); - - xy unit_vector_in_dir(target-center); - // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <property_points().set_value(arrow_points); - } -} - -bool BrokenEdge::edgeFormerEventHandler(GdkEvent* e) -{ - switch(e->type) - { - case GDK_BUTTON_PRESS: - //we mark the location of the event to be able to calculate parameters of dragging - if(gdc.getActualTool()!=CREATE_NODE) - { - gdc.toggleEdgeActivity(this, true); - clicked_x=e->button.x; - clicked_y=e->button.y; - isbutton=true; - } - break; - case GDK_BUTTON_RELEASE: - if(gdc.getActualTool()!=CREATE_NODE) - { - gdc.toggleEdgeActivity(this, false); - isbutton=false; - } - 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; - - Gnome::Canvas::Points points_new; - - points_new.push_back(my_points[0]); - points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy)); - points_new.push_back(my_points[2]); - - setPoints(points_new); - gdc.textReposition(xy(my_points[1].get_x(),my_points[1].get_y())); - - clicked_x=e->motion.x; - clicked_y=e->motion.y; - - } - default: break; - } - - return true; -} - -xy BrokenEdge::getArrowPos() -{ - xy ret_val(my_points[1].get_x(),my_points[1].get_y()); - return ret_val; -} diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/broken_edge.h --- a/gui/broken_edge.h Mon Nov 21 09:08:16 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -// -*- C++ -*- // - -#ifndef BROKEN_EDGE_H -#define BROKEN_EDGE_H - -class BrokenEdge; - -#include "all_include.h" -#include -#include -#include "graph_displayer_canvas.h" -#include - -class BrokenEdge : public Gnome::Canvas::Line -{ - GraphDisplayerCanvas & gdc; - Gnome::Canvas::Polygon * arrow; - Gnome::Art::Point * my_points; - - - ///Indicates whether the button of mouse is pressed or not - bool isbutton; - - ///At this location was the mousebutton pressed. - ///It helps to calculate the distance of dragging. - double clicked_x, clicked_y; - - ///event handler for forming edges - bool edgeFormerEventHandler(GdkEvent*); - public: - BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &); - ~BrokenEdge(); - void setPoints(Gnome::Canvas::Points, bool move=false); - xy getArrowPos(); -}; - - -#endif //BROKEN_EDGE_H - diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/gdc-broken_edge.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/gdc-broken_edge.cc Mon Nov 21 12:07:05 2005 +0000 @@ -0,0 +1,214 @@ +#include "graph_displayer_canvas.h" +#include + +GraphDisplayerCanvas::BrokenEdge::BrokenEdge(Gnome::Canvas::Group & g, Gnome::Canvas::Points p, GraphDisplayerCanvas & gc) : Line(g), gdc(gc), isbutton(false) +{ + my_points=new Gnome::Art::Point[3]; + + arrow=new Gnome::Canvas::Polygon(g); + *arrow << Gnome::Canvas::Properties::fill_color("red"); + arrow->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler)); + arrow->lower_to_bottom(); + setPoints(p); +} + +GraphDisplayerCanvas::BrokenEdge::~BrokenEdge() +{ + if(arrow)delete(arrow); +} + +void GraphDisplayerCanvas::BrokenEdge::setPoints(Gnome::Canvas::Points p, bool move) +{ + bool set_arrow=false; + //red arrow losts its position-right button + if(!move) + { + if(p.size()==2) + { + set_arrow=true; + Gnome::Canvas::Points points_with_center; + points_with_center.push_back(my_points[0]=p[0]); + points_with_center.push_back(my_points[1]=Gnome::Art::Point( (p[0].get_x()+p[1].get_x())/2+0 , (p[0].get_y()+p[1].get_y())/2 )+0 ); + points_with_center.push_back(my_points[2]=p[1]); + property_points().set_value(points_with_center); + } + if(p.size()==3) + { + set_arrow=true; + property_points().set_value(p); + for(int i=0;i<3;i++) + { + my_points[i]=p[i]; + } + } + } + else + { + //arrow keeps its position-left button + +// if(p.size()==2) +// { +// Gnome::Canvas::Points points; +// my_points[0]=p[0]; +// my_points[2]=p[1]; +// for(int i=0;i<3;i++) +// { +// points.push_back(my_points[i]); +// } +// property_points().set_value(points); +// } + set_arrow=true; + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + /////////// keeps shape-with scalar multiplication - version 2. + ////////////////////////////////////////////////////////////////////////////////////////////////////// + + if(p.size()==2) + { + //old vector from one to the other node - a + xy a_v(my_points[2].get_x()-my_points[0].get_x(),my_points[2].get_y()-my_points[0].get_y()); + //new vector from one to the other node - b + xy b_v(p[1].get_x()-p[0].get_x(),p[1].get_y()-p[0].get_y()); + + double absa=sqrt(a_v.normSquare()); + double absb=sqrt(b_v.normSquare()); + + //old vector from one node to the breakpoint - c + xy c_v(my_points[1].get_x()-my_points[0].get_x(),my_points[1].get_y()-my_points[0].get_y()); + + //unit vector with the same direction to a_v + xy a_v_u(a_v.x/absa,a_v.y/absa); + + //normal vector of unit vector with the same direction to a_v + xy a_v_u_n(((-1)*a_v_u.y),a_v_u.x); + + //unit vector with the same direction to b_v + xy b_v_u(b_v.x/absb,b_v.y/absb); + + //normal vector of unit vector with the same direction to b_v + xy b_v_u_n(((-1)*b_v_u.y),b_v_u.x); + + //vector c in a_v_u and a_v_u_n co-ordinate system + xy c_a(c_v*a_v_u,c_v*a_v_u_n); + + //new vector from one node to the breakpoint - d - we have to calculate this one + xy d_v=absb/absa*(c_a.x*b_v_u+c_a.y*b_v_u_n); + + my_points[1]=Gnome::Art::Point(d_v.x+p[0].get_x(),d_v.y+p[0].get_y()); + + my_points[0]=p[0]; + my_points[2]=p[1]; + + Gnome::Canvas::Points points; + for(int i=0;i<3;i++) + { + points.push_back(my_points[i]); + } + property_points().set_value(points); + } + } + if(set_arrow) + { + //calculating coordinates of the direction indicator arrow + + xy target( my_points[2].get_x(), my_points[2].get_y() ); + xy center( my_points[1].get_x(), my_points[1].get_y() ); + + xy unit_vector_in_dir(target-center); + // std::cout << target << " - " << center << " = " << unit_vector_in_dir << " / " <property_points().set_value(arrow_points); + } +} + +bool GraphDisplayerCanvas::BrokenEdge::edgeFormerEventHandler(GdkEvent* e) +{ + switch(e->type) + { + case GDK_BUTTON_PRESS: + //we mark the location of the event to be able to calculate parameters of dragging + if(gdc.getActualTool()!=CREATE_NODE) + { + gdc.toggleEdgeActivity(this, true); + clicked_x=e->button.x; + clicked_y=e->button.y; + isbutton=true; + } + break; + case GDK_BUTTON_RELEASE: + if(gdc.getActualTool()!=CREATE_NODE) + { + gdc.toggleEdgeActivity(this, false); + isbutton=false; + } + 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; + + Gnome::Canvas::Points points_new; + + points_new.push_back(my_points[0]); + points_new.push_back(my_points[1]=Gnome::Art::Point(my_points[1].get_x()+dx,my_points[1].get_y()+dy)); + points_new.push_back(my_points[2]); + + setPoints(points_new); + gdc.textReposition(xy(my_points[1].get_x(),my_points[1].get_y())); + + clicked_x=e->motion.x; + clicked_y=e->motion.y; + + } + default: break; + } + + return true; +} + +xy GraphDisplayerCanvas::BrokenEdge::getArrowPos() +{ + xy ret_val(my_points[1].get_x(),my_points[1].get_y()); + return ret_val; +} diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/graph_displayer_canvas-edge.cc --- a/gui/graph_displayer_canvas-edge.cc Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/graph_displayer_canvas-edge.cc Mon Nov 21 12:07:05 2005 +0000 @@ -1,5 +1,4 @@ #include "graph_displayer_canvas.h" -#include "broken_edge.h" #include diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/graph_displayer_canvas-event.cc --- a/gui/graph_displayer_canvas-event.cc Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/graph_displayer_canvas-event.cc Mon Nov 21 12:07:05 2005 +0000 @@ -1,5 +1,4 @@ #include "graph_displayer_canvas.h" -#include "broken_edge.h" #include diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/graph_displayer_canvas-node.cc --- a/gui/graph_displayer_canvas-node.cc Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/graph_displayer_canvas-node.cc Mon Nov 21 12:07:05 2005 +0000 @@ -1,5 +1,4 @@ #include "graph_displayer_canvas.h" -#include "broken_edge.h" #include diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/graph_displayer_canvas-zoom.cc --- a/gui/graph_displayer_canvas-zoom.cc Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/graph_displayer_canvas-zoom.cc Mon Nov 21 12:07:05 2005 +0000 @@ -1,5 +1,4 @@ #include "graph_displayer_canvas.h" -#include "broken_edge.h" #include void GraphDisplayerCanvas::zoomIn() diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/graph_displayer_canvas.cc --- a/gui/graph_displayer_canvas.cc Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/graph_displayer_canvas.cc Mon Nov 21 12:07:05 2005 +0000 @@ -1,5 +1,4 @@ #include "graph_displayer_canvas.h" -#include "broken_edge.h" #include GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) : diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/graph_displayer_canvas.h --- a/gui/graph_displayer_canvas.h Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/graph_displayer_canvas.h Mon Nov 21 12:07:05 2005 +0000 @@ -7,14 +7,36 @@ #include "all_include.h" #include "mapstorage.h" -#include "broken_edge.h" #include "map_win.h" #include #include +#include ///This class is the canvas, on which the graph can be drawn. class GraphDisplayerCanvas : public Gnome::Canvas::CanvasAA { + class BrokenEdge : public Gnome::Canvas::Line + { + GraphDisplayerCanvas & gdc; + Gnome::Canvas::Polygon * arrow; + Gnome::Art::Point * my_points; + + + ///Indicates whether the button of mouse is pressed or not + bool isbutton; + + ///At this location was the mousebutton pressed. + ///It helps to calculate the distance of dragging. + double clicked_x, clicked_y; + + ///event handler for forming edges + bool edgeFormerEventHandler(GdkEvent*); + public: + BrokenEdge(Gnome::Canvas::Group &, Gnome::Canvas::Points, GraphDisplayerCanvas &); + ~BrokenEdge(); + void setPoints(Gnome::Canvas::Points, bool move=false); + xy getArrowPos(); + }; typedef Gnome::Canvas::CanvasAA Parent; public: diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/map_win.h --- a/gui/map_win.h Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/map_win.h Mon Nov 21 12:07:05 2005 +0000 @@ -9,7 +9,6 @@ #include "graph_displayer_canvas.h" #include "mapstorage.h" #include "new_map_win.h" -#include "mapselector.h" #include #include @@ -18,6 +17,61 @@ ///assigned to maps. class MapWin : public Gtk::Window { + + class MapSelector : public Gtk::HBox + { + protected: + GraphDisplayerCanvas & gdc; + ///The \ref MapStorage in which the visualizable maps are stored + MapStorage & ms; + NewMapWin & nmw; + + int id; + + bool itisedge; + + bool default_state; + + bool set_new_map; + + 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 &, NewMapWin &, 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 new_but_pressed(); + + 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); + }; + + + protected: ///The \ref GraphDisplayerCanvas on which the graph will be drawn. ///It has to be known for this class, because diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/mapselector.cc --- a/gui/mapselector.cc Mon Nov 21 09:08:16 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,225 +0,0 @@ -#include "mapselector.h" - -MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, NewMapWin & newmapw, int identifier, bool edge):gdc(grdispc),ms(mapst),nmw(newmapw),id(identifier),itisedge(edge),default_state(true),set_new_map(false),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); - - newbut->signal_pressed().connect - ( - sigc::mem_fun(*this, &MapSelector::new_but_pressed) - ); - - add(*label); - - add(cbt); - - add(*defbut); - add(*newbut); -} - -void MapSelector::new_but_pressed() -{ - set_new_map=true; - nmw.showByPreChoose(itisedge); -} - -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); - if(set_new_map) - { - set_active_text(text); - set_new_map=false; - } -} diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/mapselector.h --- a/gui/mapselector.h Mon Nov 21 09:08:16 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -// -*- C++ -*- // - -#ifndef MAP_SELECTOR_H -#define MAP_SELECTOR_H - -class MapSelector; - -#include "all_include.h" -#include "mapstorage.h" -#include "new_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; - NewMapWin & nmw; - - int id; - - bool itisedge; - - bool default_state; - - bool set_new_map; - - 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 &, NewMapWin &, 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 new_but_pressed(); - - 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 diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/mw-mapselector.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/mw-mapselector.cc Mon Nov 21 12:07:05 2005 +0000 @@ -0,0 +1,225 @@ +#include "map_win.h" + +MapWin::MapSelector::MapSelector(GraphDisplayerCanvas & grdispc, MapStorage & mapst, NewMapWin & newmapw, int identifier, bool edge):gdc(grdispc),ms(mapst),nmw(newmapw),id(identifier),itisedge(edge),default_state(true),set_new_map(false),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), &MapWin::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, &MapWin::MapSelector::reset) + ); + + newbut=new Gtk::Button(Gtk::Stock::NEW); + + newbut->signal_pressed().connect + ( + sigc::mem_fun(*this, &MapWin::MapSelector::new_but_pressed) + ); + + add(*label); + + add(cbt); + + add(*defbut); + add(*newbut); +} + +void MapWin::MapSelector::new_but_pressed() +{ + set_new_map=true; + nmw.showByPreChoose(itisedge); +} + +void MapWin::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 MapWin::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 MapWin::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 MapWin::MapSelector::update(Node node) +{ + node_to_update=node; + if(default_state) + { + reset(); + } + else + { + comboChanged(); + } + node_to_update=INVALID; +} + +void MapWin::MapSelector::update(Edge edge) +{ + edge_to_update=edge; + if(default_state) + { + reset(); + } + else + { + comboChanged(); + } + edge_to_update=INVALID; +} + +Glib::ustring MapWin::MapSelector::get_active_text() +{ + return cbt.get_active_text(); +} + +void MapWin::MapSelector::set_active_text(Glib::ustring text) +{ + cbt.set_active_text(text); +} + +void MapWin::MapSelector::append_text(Glib::ustring text) +{ + cbt.append_text(text); + if(set_new_map) + { + set_active_text(text); + set_new_map=false; + } +} diff -r 8f9905c4e1c1 -r fd82adfbe905 gui/new_map_win.cc --- a/gui/new_map_win.cc Mon Nov 21 09:08:16 2005 +0000 +++ b/gui/new_map_win.cc Mon Nov 21 12:07:05 2005 +0000 @@ -318,8 +318,8 @@ { unsigned int pr=10000; bool prevmult=false; - unsigned int prev_change; - unsigned int prev_br=10000; + unsigned int prev_change=pr; + unsigned int prev_br=pr; int counter=0; std::string comm_nobr=""; std::vector p; @@ -392,7 +392,7 @@ NewMapWin::tree_node * NewMapWin::weightedString2Tree(std::string to_tree, std::vector & p, int offset) { - int min=p[offset]; + unsigned int min=p[offset]; int minplace=0; for(int i=0;i<(int)to_tree.size();i++) {