gui/graph_displayer_canvas-node.cc
author alpar
Wed, 07 Dec 2005 15:43:44 +0000
changeset 1855 c72636dcf0bd
parent 1837 8dd6160ff699
permissions -rwxr-xr-x
Eliminate warnins
     1 #include "graph_displayer_canvas.h"
     2 #include <cmath>
     3 
     4 
     5 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
     6 {
     7   Graph::NodeMap<double> * actual_map;
     8   double min, max;
     9   min=(mytab.mapstorage).minOfNodeMap(mapname);
    10   max=(mytab.mapstorage).maxOfNodeMap(mapname);
    11   actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
    12 
    13   if(node==INVALID)
    14     {
    15       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    16 	{
    17 	  double v=fabs((*actual_map)[i]);
    18 	  int w;
    19 	  if(min==max)
    20 	    {
    21 	      w=(int)(node_property_defaults[N_RADIUS]);
    22 	    }
    23 	  else
    24 	    {
    25 	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
    26 	    }
    27 	  if(w>=0)
    28 	    {
    29 	      double x1, y1, x2, y2;
    30 	      x1=nodesmap[i]->property_x1().get_value();
    31 	      x2=nodesmap[i]->property_x2().get_value();
    32 	      y1=nodesmap[i]->property_y1().get_value();
    33 	      y2=nodesmap[i]->property_y2().get_value();
    34 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    35 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    36 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    37 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    38 	    }
    39 	}
    40     }
    41   else
    42     {
    43       //I think only new nodes use this case
    44 //       int w=(int)(*actual_map)[node];
    45       int w=(int)(node_property_defaults[N_RADIUS]);
    46       if(w>=0)
    47 	{
    48 	  double x1, y1, x2, y2;
    49 	  x1=nodesmap[node]->property_x1().get_value();
    50 	  x2=nodesmap[node]->property_x2().get_value();
    51 	  y1=nodesmap[node]->property_y1().get_value();
    52 	  y2=nodesmap[node]->property_y2().get_value();
    53 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    54 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    55 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    56 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    57 	}
    58     }
    59   return 0;
    60 };
    61 
    62 int GraphDisplayerCanvas::resetNodeRadius (Node node)
    63 {
    64   double min, max;
    65   min=node_property_defaults[N_RADIUS];
    66   max=node_property_defaults[N_RADIUS];
    67   Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
    68   
    69   if(node==INVALID)
    70     {
    71       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    72 	{
    73 	  double v=fabs(actual_map[i]);
    74 	  int w;
    75 	  if(min==max)
    76 	    {
    77 	      w=(int)(node_property_defaults[N_RADIUS]);
    78 	    }
    79 	  else
    80 	    {
    81 	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
    82 	    }
    83 	  if(w>=0)
    84 	    {
    85 	      double x1, y1, x2, y2;
    86 	      x1=nodesmap[i]->property_x1().get_value();
    87 	      x2=nodesmap[i]->property_x2().get_value();
    88 	      y1=nodesmap[i]->property_y1().get_value();
    89 	      y2=nodesmap[i]->property_y2().get_value();
    90 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    91 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    92 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    93 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    94 	    }
    95 	}
    96     }
    97   else
    98     {
    99       //I think only new nodes use this case
   100 //       int w=(int)actual_map[node];
   101       int w=(int)(node_property_defaults[N_RADIUS]);
   102       if(w>=0)
   103 	{
   104 	  double x1, y1, x2, y2;
   105 	  x1=nodesmap[node]->property_x1().get_value();
   106 	  x2=nodesmap[node]->property_x2().get_value();
   107 	  y1=nodesmap[node]->property_y1().get_value();
   108 	  y2=nodesmap[node]->property_y2().get_value();
   109 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
   110 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
   111 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
   112 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
   113 	}
   114     }
   115   return 0;
   116 };
   117 
   118 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
   119 {  
   120 
   121   //function maps the range of the maximum and
   122   //the minimum of the nodemap to the range of
   123   //green in RGB
   124 
   125   Graph::NodeMap<double> * actual_map;
   126   actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
   127 
   128   double max, min;
   129 
   130   max=(mytab.mapstorage).maxOfNodeMap(mapname);
   131   min=(mytab.mapstorage).minOfNodeMap(mapname);
   132 
   133   if(node==INVALID)
   134     {
   135 
   136       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   137 	{
   138 	  Gdk::Color color;
   139 
   140 	  double w=(*actual_map)[i];
   141 
   142 	  if(max!=min)
   143 	    {
   144 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   145 	    }
   146 	  else
   147 	    {
   148 	      color.set_rgb_p (0, 0, 100);
   149 	    }
   150 
   151 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   152 	}
   153     }
   154   else
   155     {
   156       Gdk::Color color;
   157 
   158       double w=(*actual_map)[node];
   159 
   160       if(max!=min)
   161 	{
   162 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   163 	}
   164       else
   165 	{
   166 	  color.set_rgb_p (0, 0, 100);
   167 	}
   168 
   169       nodesmap[node]->property_fill_color_gdk().set_value(color);
   170     }
   171   return 0;
   172 };
   173 
   174 int GraphDisplayerCanvas::resetNodeColor (Node node)
   175 {  
   176 
   177   //function maps the range of the maximum and
   178   //the minimum of the nodemap to the range of
   179   //green in RGB
   180 
   181   Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
   182 
   183   double max, min;
   184 
   185   max=node_property_defaults[N_COLOR];
   186   min=node_property_defaults[N_COLOR];
   187 
   188   if(node==INVALID)
   189     {
   190 
   191       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   192 	{
   193 	  Gdk::Color color;
   194 
   195 	  double w=actual_map[i];
   196 
   197 	  if(max!=min)
   198 	    {
   199 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   200 	    }
   201 	  else
   202 	    {
   203 	      color.set_rgb_p (0, 0, 100);
   204 	    }
   205 
   206 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   207 	}
   208     }
   209   else
   210     {
   211       Gdk::Color color;
   212 
   213       double w=actual_map[node];
   214 
   215       if(max!=min)
   216 	{
   217 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   218 	}
   219       else
   220 	{
   221 	  color.set_rgb_p (0, 0, 100);
   222 	}
   223 
   224       nodesmap[node]->property_fill_color_gdk().set_value(color);
   225     }
   226   return 0;
   227 };
   228 
   229 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
   230 {
   231 
   232   //the number in the map will be written on the node
   233   //EXCEPT when the name of the map is Text, because
   234   //in that case empty string will be written, because
   235   //that is the deleter map
   236 
   237   Graph::NodeMap<double> * actual_map=NULL;
   238   actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
   239 
   240   if(node==INVALID)
   241     {
   242       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   243 	{
   244 	  nodemap_to_edit=mapname;
   245 	  double number=(*actual_map)[i];
   246 
   247 	  std::ostringstream ostr;
   248 	  ostr << number;
   249 	      
   250 	  nodetextmap[i]->property_text().set_value(ostr.str());
   251 	}
   252     }
   253   else
   254     {
   255       double number=(*actual_map)[node];
   256 
   257       std::ostringstream ostr;
   258       ostr << number;
   259 	      
   260       nodetextmap[node]->property_text().set_value(ostr.str());
   261     }
   262   return 0;
   263 };
   264 
   265 int GraphDisplayerCanvas::resetNodeText (Node node)
   266 {
   267 
   268   //the number in the map will be written on the node
   269   //EXCEPT when the name of the map is Text, because
   270   //in that case empty string will be written, because
   271   //that is the deleter map
   272 
   273   if(node==INVALID)
   274     {
   275       for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   276 	{
   277 	  nodemap_to_edit="";
   278 	  nodetextmap[i]->property_text().set_value("");
   279 	}
   280     }
   281   else
   282     {
   283       nodetextmap[node]->property_text().set_value("");
   284     }
   285   return 0;
   286 };