gui/mapselector.cc
author marci
Sun, 13 Nov 2005 20:01:17 +0000
changeset 1787 932b8490caf0
parent 1733 5e0d97823ba2
permissions -rw-r--r--
bugfix in setCol, getting dual values
     1 #include "mapselector.h"
     2 
     3 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)
     4 {
     5   update_list();
     6 
     7   cbt.set_active(0);
     8 
     9   //binding signal to the actual entry
    10   cbt.signal_changed().connect
    11     (
    12      sigc::mem_fun((*this), &MapSelector::comboChanged),
    13      false
    14      );
    15   
    16   if(itisedge)
    17     {
    18       label=new Gtk::Label(edge_property_strings[id]);
    19     }
    20   else
    21     {
    22       label=new Gtk::Label(node_property_strings[id]);
    23     }
    24 
    25   label->set_width_chars(longest_property_string_length);
    26 
    27   defbut=new Gtk::Button();
    28   defbut->set_label("Reset");
    29 
    30   defbut->signal_pressed().connect
    31     (
    32      sigc::mem_fun(*this, &MapSelector::reset)
    33      );
    34 
    35   newbut=new Gtk::Button(Gtk::Stock::NEW);
    36 
    37   newbut->signal_pressed().connect
    38     (
    39      sigc::mem_fun(*this, &MapSelector::new_but_pressed)
    40      );
    41 
    42   add(*label);
    43 
    44   add(cbt);
    45 
    46   add(*defbut);
    47   add(*newbut);
    48 }
    49 
    50 void MapSelector::new_but_pressed()
    51 {
    52   set_new_map=true;
    53   nmw.showByPreChoose(itisedge);
    54 }
    55 
    56 void MapSelector::update_list()
    57 {
    58   cbt.clear();
    59   if(itisedge)
    60     {
    61       std::map< std::string,Graph::EdgeMap<double> * >::iterator emsi=ms.beginOfEdgeMaps();
    62       for(;emsi!=ms.endOfEdgeMaps();emsi++)
    63 	{
    64 	  cbt.append_text(emsi->first);
    65 	}
    66     }
    67   else
    68     {
    69       std::map< std::string,Graph::NodeMap<double> * >::iterator emsi=ms.beginOfNodeMaps();
    70       for(;emsi!=ms.endOfNodeMaps();emsi++)
    71 	{
    72 	  cbt.append_text(emsi->first);
    73 	}
    74     }
    75   cbt.prepend_text("Default values");
    76 }
    77 
    78 void MapSelector::comboChanged()
    79 {
    80   if(cbt.get_active_row_number()!=0)
    81     {
    82       default_state=false;
    83       Glib::ustring mapname = cbt.get_active_text();
    84       if(!(mapname.empty())) //We seem to get 2 signals, one when the text is empty.
    85 	{
    86 	  if(itisedge)
    87 	    {
    88 	      if( ( (ms.edgemap_storage).find(mapname) != (ms.edgemap_storage).end() ) )
    89 		{
    90 		  Edge edge=edge_to_update;
    91 		  switch(id)
    92 		    {
    93 		    case E_WIDTH:
    94 		      gdc.changeEdgeWidth(mapname, edge);
    95 		      break;
    96 		    case E_COLOR:
    97 		      gdc.changeEdgeColor(mapname, edge);
    98 		      break;
    99 		    case E_TEXT:
   100 		      gdc.changeEdgeText(mapname, edge);
   101 		      break;
   102 		    default:
   103 		      std::cerr<<"Error\n";
   104 		    }
   105 		}
   106 	    }
   107 	  else
   108 	    {
   109 	      if( ( (ms.nodemap_storage).find(mapname) != (ms.nodemap_storage).end() ) )
   110 		{
   111 		  Node node=node_to_update;
   112 		  switch(id)
   113 		    {
   114 		    case N_RADIUS:
   115 		      gdc.changeNodeRadius(mapname, node);
   116 		      break;
   117 		    case N_COLOR:
   118 		      gdc.changeNodeColor(mapname, node);
   119 		      break;
   120 		    case N_TEXT:
   121 		      gdc.changeNodeText(mapname, node);
   122 		      break;
   123 		    default:
   124 		      std::cerr<<"Error\n";
   125 		    }
   126 		}
   127 	    }
   128 	}
   129     }
   130   else if((!default_state)&&(cbt.get_active_row_number()==0))
   131     {
   132       reset();
   133     }
   134 }
   135 
   136 void MapSelector::reset()
   137 {
   138   default_state=true;
   139   cbt.set_active(0);
   140 
   141   if(itisedge)
   142     {
   143       Edge edge=edge_to_update;
   144       switch(id)
   145 	{
   146 	case E_WIDTH:
   147 	  gdc.resetEdgeWidth(edge);
   148 	  break;
   149 	case E_COLOR:
   150 	  gdc.resetEdgeColor(edge);
   151 	  break;
   152 	case E_TEXT:
   153 	  gdc.resetEdgeText(edge);
   154 	  break;
   155 	default:
   156 	  std::cerr<<"Error\n";
   157 	}
   158     }
   159   else
   160     {
   161       Node node=node_to_update;	
   162       switch(id)
   163 	{
   164 	case N_RADIUS:
   165 	  gdc.resetNodeRadius(node);
   166 	  break;
   167 	case N_COLOR:
   168 	  gdc.resetNodeColor(node);
   169 	  break;
   170 	case N_TEXT:
   171 	  gdc.resetNodeText(node);
   172 	  break;
   173 	default:
   174 	  std::cerr<<"Error\n";
   175 	}
   176     }
   177 }
   178 
   179 void MapSelector::update(Node node)
   180 {
   181   node_to_update=node;
   182   if(default_state)
   183     {
   184       reset();
   185     }
   186   else
   187     {
   188       comboChanged();
   189     }
   190   node_to_update=INVALID;
   191 }
   192 
   193 void MapSelector::update(Edge edge)
   194 {
   195   edge_to_update=edge;
   196   if(default_state)
   197     {
   198       reset();
   199     }
   200   else
   201     {
   202       comboChanged();
   203     }
   204   edge_to_update=INVALID;
   205 }
   206 
   207 Glib::ustring MapSelector::get_active_text()
   208 {
   209   return cbt.get_active_text();
   210 }
   211 
   212 void MapSelector::set_active_text(Glib::ustring text)
   213 {
   214   cbt.set_active_text(text);
   215 }
   216 
   217 void MapSelector::append_text(Glib::ustring text)
   218 {
   219   cbt.append_text(text);
   220   if(set_new_map)
   221     {
   222       set_active_text(text);
   223       set_new_map=false;
   224     }
   225 }