gui/mapselector.cc
changeset 1731 616bc933c2bc
child 1733 5e0d97823ba2
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gui/mapselector.cc	Thu Oct 20 15:50:23 2005 +0000
     1.3 @@ -0,0 +1,209 @@
     1.4 +#include "mapselector.h"
     1.5 +
     1.6 +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)
     1.7 +{
     1.8 +  update_list();
     1.9 +
    1.10 +  cbt.set_active(0);
    1.11 +
    1.12 +  //binding signal to the actual entry
    1.13 +  cbt.signal_changed().connect
    1.14 +    (
    1.15 +     sigc::mem_fun((*this), &MapSelector::comboChanged),
    1.16 +     false
    1.17 +     );
    1.18 +  
    1.19 +  if(itisedge)
    1.20 +    {
    1.21 +      label=new Gtk::Label(edge_property_strings[id]);
    1.22 +    }
    1.23 +  else
    1.24 +    {
    1.25 +      label=new Gtk::Label(node_property_strings[id]);
    1.26 +    }
    1.27 +
    1.28 +  label->set_width_chars(longest_property_string_length);
    1.29 +
    1.30 +  defbut=new Gtk::Button();
    1.31 +  defbut->set_label("Reset");
    1.32 +
    1.33 +  defbut->signal_pressed().connect
    1.34 +    (
    1.35 +     sigc::mem_fun(*this, &MapSelector::reset)
    1.36 +     );
    1.37 +
    1.38 +  newbut=new Gtk::Button(Gtk::Stock::NEW);
    1.39 +
    1.40 +  add(*label);
    1.41 +
    1.42 +  add(cbt);
    1.43 +
    1.44 +  add(*defbut);
    1.45 +  add(*newbut);
    1.46 +}
    1.47 +
    1.48 +void MapSelector::update_list()
    1.49 +{
    1.50 +  cbt.clear();
    1.51 +  if(itisedge)
    1.52 +    {
    1.53 +      std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
    1.54 +      for(;emsi!=ms.endOfEdgeMaps();emsi++)
    1.55 +	{
    1.56 +	  cbt.append_text(emsi->first);
    1.57 +	}
    1.58 +    }
    1.59 +  else
    1.60 +    {
    1.61 +      std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
    1.62 +      for(;emsi!=ms.endOfNodeMaps();emsi++)
    1.63 +	{
    1.64 +	  cbt.append_text(emsi->first);
    1.65 +	}
    1.66 +    }
    1.67 +  cbt.prepend_text("Default values");
    1.68 +}
    1.69 +
    1.70 +void MapSelector::comboChanged()
    1.71 +{
    1.72 +  if(cbt.get_active_row_number()!=0)
    1.73 +    {
    1.74 +      default_state=false;
    1.75 +      Glib::ustring mapname = cbt.get_active_text();
    1.76 +      if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
    1.77 +	{
    1.78 +	  if(itisedge)
    1.79 +	    {
    1.80 +	      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) )
    1.81 +		{
    1.82 +		  Edge edge=edge_to_update;
    1.83 +		  switch(id)
    1.84 +		    {
    1.85 +		    case E_WIDTH:
    1.86 +		      gdc.changeEdgeWidth(mapname, edge);
    1.87 +		      break;
    1.88 +		    case E_COLOR:
    1.89 +		      gdc.changeEdgeColor(mapname, edge);
    1.90 +		      break;
    1.91 +		    case E_TEXT:
    1.92 +		      gdc.changeEdgeText(mapname, edge);
    1.93 +		      break;
    1.94 +		    default:
    1.95 +		      std::cerr<<"Error\n";
    1.96 +		    }
    1.97 +		}
    1.98 +	    }
    1.99 +	  else
   1.100 +	    {
   1.101 +	      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) )
   1.102 +		{
   1.103 +		  Node node=node_to_update;
   1.104 +		  switch(id)
   1.105 +		    {
   1.106 +		    case N_RADIUS:
   1.107 +		      gdc.changeNodeRadius(mapname, node);
   1.108 +		      break;
   1.109 +		    case N_COLOR:
   1.110 +		      gdc.changeNodeColor(mapname, node);
   1.111 +		      break;
   1.112 +		    case N_TEXT:
   1.113 +		      gdc.changeNodeText(mapname, node);
   1.114 +		      break;
   1.115 +		    default:
   1.116 +		      std::cerr<<"Error\n";
   1.117 +		    }
   1.118 +		}
   1.119 +	    }
   1.120 +	}
   1.121 +    }
   1.122 +  else if((!default_state)&&(cbt.get_active_row_number()==0))
   1.123 +    {
   1.124 +      reset();
   1.125 +    }
   1.126 +}
   1.127 +
   1.128 +void MapSelector::reset()
   1.129 +{
   1.130 +  default_state=true;
   1.131 +  cbt.set_active(0);
   1.132 +
   1.133 +  if(itisedge)
   1.134 +    {
   1.135 +      Edge edge=edge_to_update;
   1.136 +      switch(id)
   1.137 +	{
   1.138 +	case E_WIDTH:
   1.139 +	  gdc.resetEdgeWidth(edge);
   1.140 +	  break;
   1.141 +	case E_COLOR:
   1.142 +	  gdc.resetEdgeColor(edge);
   1.143 +	  break;
   1.144 +	case E_TEXT:
   1.145 +	  gdc.resetEdgeText(edge);
   1.146 +	  break;
   1.147 +	default:
   1.148 +	  std::cerr<<"Error\n";
   1.149 +	}
   1.150 +    }
   1.151 +  else
   1.152 +    {
   1.153 +      Node node=node_to_update;	
   1.154 +      switch(id)
   1.155 +	{
   1.156 +	case N_RADIUS:
   1.157 +	  gdc.resetNodeRadius(node);
   1.158 +	  break;
   1.159 +	case N_COLOR:
   1.160 +	  gdc.resetNodeColor(node);
   1.161 +	  break;
   1.162 +	case N_TEXT:
   1.163 +	  gdc.resetNodeText(node);
   1.164 +	  break;
   1.165 +	default:
   1.166 +	  std::cerr<<"Error\n";
   1.167 +	}
   1.168 +    }
   1.169 +}
   1.170 +
   1.171 +void MapSelector::update(Node node)
   1.172 +{
   1.173 +  node_to_update=node;
   1.174 +  if(default_state)
   1.175 +    {
   1.176 +      reset();
   1.177 +    }
   1.178 +  else
   1.179 +    {
   1.180 +      comboChanged();
   1.181 +    }
   1.182 +  node_to_update=INVALID;
   1.183 +}
   1.184 +
   1.185 +void MapSelector::update(Edge edge)
   1.186 +{
   1.187 +  edge_to_update=edge;
   1.188 +  if(default_state)
   1.189 +    {
   1.190 +      reset();
   1.191 +    }
   1.192 +  else
   1.193 +    {
   1.194 +      comboChanged();
   1.195 +    }
   1.196 +  edge_to_update=INVALID;
   1.197 +}
   1.198 +
   1.199 +Glib::ustring MapSelector::get_active_text()
   1.200 +{
   1.201 +  return cbt.get_active_text();
   1.202 +}
   1.203 +
   1.204 +void MapSelector::set_active_text(Glib::ustring text)
   1.205 +{
   1.206 +  cbt.set_active_text(text);
   1.207 +}
   1.208 +
   1.209 +void MapSelector::append_text(Glib::ustring text)
   1.210 +{
   1.211 +  cbt.append_text(text);
   1.212 +}