gui/graph_displayer_canvas-node.cc
author klao
Fri, 16 Sep 2005 09:57:02 +0000
changeset 1688 61ce46476787
parent 1632 93ac8c521fe5
child 1731 616bc933c2bc
permissions -rwxr-xr-x
Permissions and svn:ignore cleanup.
     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   if(mapname=="Default")
    11     {
    12       min=node_property_defaults[N_RADIUS];
    13       max=node_property_defaults[N_RADIUS];
    14       actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
    15     }
    16   else
    17     {
    18       min=mapstorage.minOfNodeMap(mapname);
    19       max=mapstorage.maxOfNodeMap(mapname);
    20       actual_map=(mapstorage.nodemap_storage)[mapname];
    21     }
    22 
    23   if(node==INVALID)
    24     {
    25       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    26 	{
    27 	  double v=fabs((*actual_map)[i]);
    28 	  int w;
    29 	  if(min==max)
    30 	    {
    31 	      w=(int)(node_property_defaults[N_RADIUS]);
    32 	    }
    33 	  else
    34 	    {
    35 	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
    36 	    }
    37 	  if(w>=0)
    38 	    {
    39 	      double x1, y1, x2, y2;
    40 	      x1=nodesmap[i]->property_x1().get_value();
    41 	      x2=nodesmap[i]->property_x2().get_value();
    42 	      y1=nodesmap[i]->property_y1().get_value();
    43 	      y2=nodesmap[i]->property_y2().get_value();
    44 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    45 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    46 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    47 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    48 	    }
    49 	}
    50     }
    51   else
    52     {
    53       //I think only new nodes use this case
    54 //       int w=(int)(*actual_map)[node];
    55       int w=(int)(node_property_defaults[N_RADIUS]);
    56       if(w>=0)
    57 	{
    58 	  double x1, y1, x2, y2;
    59 	  x1=nodesmap[node]->property_x1().get_value();
    60 	  x2=nodesmap[node]->property_x2().get_value();
    61 	  y1=nodesmap[node]->property_y1().get_value();
    62 	  y2=nodesmap[node]->property_y2().get_value();
    63 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    64 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    65 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    66 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    67 	}
    68     }
    69   return 0;
    70 };
    71 
    72 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
    73 {  
    74 
    75   //function maps the range of the maximum and
    76   //the minimum of the nodemap to the range of
    77   //green in RGB
    78 
    79   Graph::NodeMap<double> * actual_map;
    80   if(mapname=="Default")
    81     {
    82       actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
    83     }
    84   else
    85     {
    86       actual_map=(mapstorage.nodemap_storage)[mapname];
    87     }
    88 
    89   double max, min;
    90 
    91   if(mapname!="Default")
    92     {
    93       max=mapstorage.maxOfNodeMap(mapname);
    94       min=mapstorage.minOfNodeMap(mapname);
    95     }
    96   else
    97     {
    98       max=node_property_defaults[N_COLOR];
    99       min=node_property_defaults[N_COLOR];
   100     }
   101 
   102 
   103   if(node==INVALID)
   104     {
   105 
   106       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   107 	{
   108 	  Gdk::Color color;
   109 
   110 	  double w=(*actual_map)[i];
   111 
   112 	  if(max!=min)
   113 	    {
   114 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   115 	    }
   116 	  else
   117 	    {
   118 	      color.set_rgb_p (0, 0, 100);
   119 	    }
   120 
   121 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   122 	}
   123     }
   124   else
   125     {
   126       Gdk::Color color;
   127 
   128       double w=(*actual_map)[node];
   129 
   130       if(max!=min)
   131 	{
   132 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   133 	}
   134       else
   135 	{
   136 	  color.set_rgb_p (0, 0, 100);
   137 	}
   138 
   139       nodesmap[node]->property_fill_color_gdk().set_value(color);
   140     }
   141   return 0;
   142 };
   143 
   144 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
   145 {
   146 
   147   //the number in the map will be written on the node
   148   //EXCEPT when the name of the map is Text, because
   149   //in that case empty string will be written, because
   150   //that is the deleter map
   151 
   152   Graph::NodeMap<double> * actual_map=NULL;
   153   if(mapname!="Default")
   154     {
   155       actual_map=(mapstorage.nodemap_storage)[mapname];
   156     }
   157 
   158   if(node==INVALID)
   159     {
   160       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   161 	{
   162 	  if(mapname!="Default")
   163 	    {
   164 	      nodemap_to_edit=mapname;
   165 	      double number=(*actual_map)[i];
   166 
   167 	      std::ostringstream ostr;
   168 	      ostr << number;
   169 	      
   170       	      nodetextmap[i]->property_text().set_value(ostr.str());
   171 	    }
   172 	  else
   173 	    {
   174 	      nodemap_to_edit="";
   175 	      nodetextmap[i]->property_text().set_value("");
   176 	    }
   177 	}
   178     }
   179   else
   180     {
   181       if(mapname!="Default")
   182 	{
   183 	  double number=(*actual_map)[node];
   184 
   185 	  std::ostringstream ostr;
   186 	  ostr << number;
   187 	      
   188 	  nodetextmap[node]->property_text().set_value(ostr.str());
   189 	}
   190       else
   191 	{
   192 	  nodetextmap[node]->property_text().set_value("");
   193 	}
   194     }
   195   return 0;
   196 };