graph_displayer_canvas-node.cc
author hegyi
Thu, 01 Mar 2007 13:33:46 +0000
changeset 196 c220f9de6545
parent 179 1f436ea3ef4f
child 201 879e47e5b731
permissions -rwxr-xr-x
EpsWin and DesignWin does not need to know NoteBookTab.
     1 /* -*- C++ -*-
     2  *
     3  * This file is a part of LEMON, a generic C++ optimization library
     4  *
     5  * Copyright (C) 2003-2006
     6  * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     7  * (Egervary Research Group on Combinatorial Optimization, EGRES).
     8  *
     9  * Permission to use, modify and distribute this software is granted
    10  * provided that this copyright notice appears in all copies. For
    11  * precise terms see the accompanying LICENSE file.
    12  *
    13  * This software is provided "AS IS" with no warranty of any kind,
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    16  *
    17  */
    18 
    19 #include <graph_displayer_canvas.h>
    20 #include <mapstorage.h>
    21 #include <nbtab.h>
    22 #include <cmath>
    23 
    24 const int minimum_node_radius=5;
    25 
    26 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
    27 {
    28   Graph::NodeMap<double> * actual_map;
    29   double min, max;
    30   min=(mytab.mapstorage)->minOfNodeMap(mapname);
    31   max=(mytab.mapstorage)->maxOfNodeMap(mapname);
    32   actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
    33 
    34   if(node==INVALID)
    35     {
    36       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
    37 	{
    38 	  double v=fabs((*actual_map)[i]);
    39 	  int w;
    40 	  if(autoscale)
    41 	    {
    42 	      if(min==max)
    43 		{
    44 		  w=(int)(node_property_defaults[N_RADIUS]);
    45 		}
    46 	      else
    47 		{
    48 		  w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
    49 		}
    50 	    }
    51 	  else
    52 	    {
    53 	      w=(int)(v*radius_size);
    54 	    }
    55 
    56 	  if(w<minimum_node_radius)
    57 	    {
    58 	      w=minimum_node_radius;
    59 	    }
    60 
    61 	  if(zoomtrack)
    62 	    {
    63 	      double actual_ppu=get_pixels_per_unit();
    64 	      w=(int)(w/actual_ppu*fixed_zoom_factor);
    65 	    }
    66 
    67 	  if(w>=0)
    68 	    {
    69 	      double x1, y1, x2, y2;
    70 	      x1=nodesmap[i]->property_x1().get_value();
    71 	      x2=nodesmap[i]->property_x2().get_value();
    72 	      y1=nodesmap[i]->property_y1().get_value();
    73 	      y2=nodesmap[i]->property_y2().get_value();
    74 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
    75 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
    76 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
    77 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
    78 	    }
    79 	}
    80     }
    81   else
    82     {
    83       //I think only new nodes use this case
    84       //that has no own value, only the default one
    85       //int w=(int)(*actual_map)[node];
    86       int w=(int)(node_property_defaults[N_RADIUS]);
    87       if(w>=0)
    88 	{
    89 	  double x1, y1, x2, y2;
    90 	  x1=nodesmap[node]->property_x1().get_value();
    91 	  x2=nodesmap[node]->property_x2().get_value();
    92 	  y1=nodesmap[node]->property_y1().get_value();
    93 	  y2=nodesmap[node]->property_y2().get_value();
    94 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
    95 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
    96 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
    97 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
    98 	}
    99     }
   100   return 0;
   101 };
   102 
   103 int GraphDisplayerCanvas::resetNodeRadius (Node node)
   104 {
   105   double min, max;
   106   min=node_property_defaults[N_RADIUS];
   107   max=node_property_defaults[N_RADIUS];
   108   Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_RADIUS]);
   109   
   110   if(node==INVALID)
   111     {
   112       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
   113 	{
   114 	  double v=fabs(actual_map[i]);
   115 	  int w;
   116 	  if(min==max)
   117 	    {
   118 	      w=(int)(node_property_defaults[N_RADIUS]);
   119 	    }
   120 	  else
   121 	    {
   122 	      w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
   123 	    }
   124 	  if(zoomtrack)
   125 	    {
   126 	      double actual_ppu=get_pixels_per_unit();
   127 	      w=(int)(w/actual_ppu*fixed_zoom_factor);
   128 	    }
   129 	  if(w>=0)
   130 	    {
   131 	      double x1, y1, x2, y2;
   132 	      x1=nodesmap[i]->property_x1().get_value();
   133 	      x2=nodesmap[i]->property_x2().get_value();
   134 	      y1=nodesmap[i]->property_y1().get_value();
   135 	      y2=nodesmap[i]->property_y2().get_value();
   136 	      nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
   137 	      nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
   138 	      nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
   139 	      nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
   140 	    }
   141 	}
   142     }
   143   else
   144     {
   145       //I think only new nodes use this case
   146 //       int w=(int)actual_map[node];
   147       int w=(int)(node_property_defaults[N_RADIUS]);
   148       if(w>=0)
   149 	{
   150 	  double x1, y1, x2, y2;
   151 	  x1=nodesmap[node]->property_x1().get_value();
   152 	  x2=nodesmap[node]->property_x2().get_value();
   153 	  y1=nodesmap[node]->property_y1().get_value();
   154 	  y2=nodesmap[node]->property_y2().get_value();
   155 	  nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
   156 	  nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
   157 	  nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
   158 	  nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
   159 	}
   160     }
   161   return 0;
   162 };
   163 
   164 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
   165 {  
   166 
   167   //function maps the range of the maximum and
   168   //the minimum of the nodemap to the range of
   169   //green in RGB
   170 
   171   Graph::NodeMap<double> * actual_map;
   172   actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
   173 
   174   double max, min;
   175 
   176   max=(mytab.mapstorage)->maxOfNodeMap(mapname);
   177   min=(mytab.mapstorage)->minOfNodeMap(mapname);
   178 
   179   if(node==INVALID)
   180     {
   181 
   182       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
   183 	{
   184 	  Gdk::Color color;
   185 
   186 	  double w=(*actual_map)[i];
   187 
   188 	  if(max!=min)
   189 	    {
   190 	      color=rainbowColorCounter(min, max, w);
   191 	    }
   192 	  else
   193 	    {
   194 	      color.set_rgb_p (0, 0, 1);
   195 	    }
   196 
   197 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   198 	}
   199     }
   200   else
   201     {
   202       Gdk::Color color;
   203 
   204       double w=(*actual_map)[node];
   205 
   206       if(max!=min)
   207 	{
   208 	  color=rainbowColorCounter(min, max, w);
   209 	}
   210       else
   211 	{
   212 	  color.set_rgb_p (0, 0, 1);
   213 	}
   214 
   215       nodesmap[node]->property_fill_color_gdk().set_value(color);
   216     }
   217   return 0;
   218 };
   219 
   220 int GraphDisplayerCanvas::resetNodeColor (Node node)
   221 {  
   222 
   223   //function maps the range of the maximum and
   224   //the minimum of the nodemap to the range of
   225   //green in RGB
   226 
   227   Graph::NodeMap<double> actual_map((mytab.mapstorage)->graph,node_property_defaults[N_COLOR]);
   228 
   229   double max, min;
   230 
   231   max=node_property_defaults[N_COLOR];
   232   min=node_property_defaults[N_COLOR];
   233 
   234   if(node==INVALID)
   235     {
   236 
   237       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
   238 	{
   239 	  Gdk::Color color;
   240 
   241 	  double w=actual_map[i];
   242 
   243 	  if(max!=min)
   244 	    {
   245 	      color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   246 	    }
   247 	  else
   248 	    {
   249 	      color.set_rgb_p (0, 0, 100);
   250 	    }
   251 
   252 	  nodesmap[i]->property_fill_color_gdk().set_value(color);
   253 	}
   254     }
   255   else
   256     {
   257       Gdk::Color color;
   258 
   259       double w=actual_map[node];
   260 
   261       if(max!=min)
   262 	{
   263 	  color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
   264 	}
   265       else
   266 	{
   267 	  color.set_rgb_p (0, 0, 100);
   268 	}
   269 
   270       nodesmap[node]->property_fill_color_gdk().set_value(color);
   271     }
   272   return 0;
   273 };
   274 
   275 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
   276 {
   277 
   278   //the number in the map will be written on the node
   279   //EXCEPT when the name of the map is Text, because
   280   //in that case empty string will be written, because
   281   //that is the deleter map
   282 
   283   Graph::NodeMap<double> * actual_map=NULL;
   284   actual_map=((mytab.mapstorage)->nodemap_storage)[mapname];
   285 
   286   if(node==INVALID)
   287     {
   288       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
   289 	{
   290 	  nodemap_to_edit=mapname;
   291 	  double number=(*actual_map)[i];
   292 
   293 	  std::ostringstream ostr;
   294 	  ostr << number;
   295 	      
   296 	  nodetextmap[i]->property_text().set_value(ostr.str());
   297 	}
   298     }
   299   else
   300     {
   301       double number=(*actual_map)[node];
   302 
   303       std::ostringstream ostr;
   304       ostr << number;
   305 	      
   306       nodetextmap[node]->property_text().set_value(ostr.str());
   307     }
   308   return 0;
   309 };
   310 
   311 int GraphDisplayerCanvas::resetNodeText (Node node)
   312 {
   313 
   314   //the number in the map will be written on the node
   315   //EXCEPT when the name of the map is Text, because
   316   //in that case empty string will be written, because
   317   //that is the deleter map
   318 
   319   if(node==INVALID)
   320     {
   321       for (NodeIt i((mytab.mapstorage)->graph); i!=INVALID; ++i)
   322 	{
   323 	  nodemap_to_edit="";
   324 	  nodetextmap[i]->property_text().set_value("");
   325 	}
   326     }
   327   else
   328     {
   329       nodetextmap[node]->property_text().set_value("");
   330     }
   331   return 0;
   332 };