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