graph_displayer_canvas-node.cc
author hegyi
Mon, 21 Nov 2005 18:03:20 +0000
branchgui
changeset 90 e9f8f44f12a3
parent 81 5ad61c33487c
child 91 55cf06f14981
permissions -rwxr-xr-x
NewMapWin has become Dialog instead of Window. Therefore it is created dynamically, when there is need for it, instead of keeping one instance in memory. This solution is slower, but more correct than before.
     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=mapstorage.minOfNodeMap(mapname);
    10   max=mapstorage.maxOfNodeMap(mapname);
    11   actual_map=(mapstorage.nodemap_storage)[mapname];
    12 
    13   if(node==INVALID)
    14     {
    15       for (NodeIt i(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   Graph::NodeMap<double> * actual_map;
    65   double min, max;
    66   min=node_property_defaults[N_RADIUS];
    67   max=node_property_defaults[N_RADIUS];
    68   actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_RADIUS]);
    69   
    70   if(node==INVALID)
    71     {
    72       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
    73 	{
    74 	  double v=fabs((*actual_map)[i]);
    75 	  int w;
    76 	  if(min==max)
    77 	    {
    78 	      w=(int)(node_property_defaults[N_RADIUS]);
    79 	    }
    80 	  else
    81 	    {
    82 	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
    83 	    }
    84 	  if(w>=0)
    85 	    {
    86 	      double x1, y1, x2, y2;
    87 	      x1=nodesmap[i]->property_x1().get_value();
    88 	      x2=nodesmap[i]->property_x2().get_value();
    89 	      y1=nodesmap[i]->property_y1().get_value();
    90 	      y2=nodesmap[i]->property_y2().get_value();
    91 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    92 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    93 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    94 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    95 	    }
    96 	}
    97     }
    98   else
    99     {
   100       //I think only new nodes use this case
   101 //       int w=(int)(*actual_map)[node];
   102       int w=(int)(node_property_defaults[N_RADIUS]);
   103       if(w>=0)
   104 	{
   105 	  double x1, y1, x2, y2;
   106 	  x1=nodesmap[node]->property_x1().get_value();
   107 	  x2=nodesmap[node]->property_x2().get_value();
   108 	  y1=nodesmap[node]->property_y1().get_value();
   109 	  y2=nodesmap[node]->property_y2().get_value();
   110 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
   111 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
   112 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
   113 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
   114 	}
   115     }
   116   return 0;
   117 };
   118 
   119 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
   120 {  
   121 
   122   //function maps the range of the maximum and
   123   //the minimum of the nodemap to the range of
   124   //green in RGB
   125 
   126   Graph::NodeMap<double> * actual_map;
   127   actual_map=(mapstorage.nodemap_storage)[mapname];
   128 
   129   double max, min;
   130 
   131   max=mapstorage.maxOfNodeMap(mapname);
   132   min=mapstorage.minOfNodeMap(mapname);
   133 
   134   if(node==INVALID)
   135     {
   136 
   137       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   138 	{
   139 	  Gdk::Color color;
   140 
   141 	  double w=(*actual_map)[i];
   142 
   143 	  if(max!=min)
   144 	    {
   145 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   146 	    }
   147 	  else
   148 	    {
   149 	      color.set_rgb_p (0, 0, 100);
   150 	    }
   151 
   152 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   153 	}
   154     }
   155   else
   156     {
   157       Gdk::Color color;
   158 
   159       double w=(*actual_map)[node];
   160 
   161       if(max!=min)
   162 	{
   163 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   164 	}
   165       else
   166 	{
   167 	  color.set_rgb_p (0, 0, 100);
   168 	}
   169 
   170       nodesmap[node]->property_fill_color_gdk().set_value(color);
   171     }
   172   return 0;
   173 };
   174 
   175 int GraphDisplayerCanvas::resetNodeColor (Node node)
   176 {  
   177 
   178   //function maps the range of the maximum and
   179   //the minimum of the nodemap to the range of
   180   //green in RGB
   181 
   182   Graph::NodeMap<double> * actual_map;
   183   actual_map=new Graph::NodeMap<double>(mapstorage.graph,node_property_defaults[N_COLOR]);
   184 
   185   double max, min;
   186 
   187   max=node_property_defaults[N_COLOR];
   188   min=node_property_defaults[N_COLOR];
   189 
   190   if(node==INVALID)
   191     {
   192 
   193       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   194 	{
   195 	  Gdk::Color color;
   196 
   197 	  double w=(*actual_map)[i];
   198 
   199 	  if(max!=min)
   200 	    {
   201 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   202 	    }
   203 	  else
   204 	    {
   205 	      color.set_rgb_p (0, 0, 100);
   206 	    }
   207 
   208 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   209 	}
   210     }
   211   else
   212     {
   213       Gdk::Color color;
   214 
   215       double w=(*actual_map)[node];
   216 
   217       if(max!=min)
   218 	{
   219 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   220 	}
   221       else
   222 	{
   223 	  color.set_rgb_p (0, 0, 100);
   224 	}
   225 
   226       nodesmap[node]->property_fill_color_gdk().set_value(color);
   227     }
   228   return 0;
   229 };
   230 
   231 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
   232 {
   233 
   234   //the number in the map will be written on the node
   235   //EXCEPT when the name of the map is Text, because
   236   //in that case empty string will be written, because
   237   //that is the deleter map
   238 
   239   Graph::NodeMap<double> * actual_map=NULL;
   240   actual_map=(mapstorage.nodemap_storage)[mapname];
   241 
   242   if(node==INVALID)
   243     {
   244       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   245 	{
   246 	  nodemap_to_edit=mapname;
   247 	  double number=(*actual_map)[i];
   248 
   249 	  std::ostringstream ostr;
   250 	  ostr << number;
   251 	      
   252 	  nodetextmap[i]->property_text().set_value(ostr.str());
   253 	}
   254     }
   255   else
   256     {
   257       double number=(*actual_map)[node];
   258 
   259       std::ostringstream ostr;
   260       ostr << number;
   261 	      
   262       nodetextmap[node]->property_text().set_value(ostr.str());
   263     }
   264   return 0;
   265 };
   266 
   267 int GraphDisplayerCanvas::resetNodeText (Node node)
   268 {
   269 
   270   //the number in the map will be written on the node
   271   //EXCEPT when the name of the map is Text, because
   272   //in that case empty string will be written, because
   273   //that is the deleter map
   274 
   275   if(node==INVALID)
   276     {
   277       for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
   278 	{
   279 	  nodemap_to_edit="";
   280 	  nodetextmap[i]->property_text().set_value("");
   281 	}
   282     }
   283   else
   284     {
   285       nodetextmap[node]->property_text().set_value("");
   286     }
   287   return 0;
   288 };