graph_displayer_canvas-edge.cc
author hegyi
Fri, 13 Oct 2006 13:53:44 +0000
changeset 163 443bc769b344
parent 147 10ef59f6633c
child 167 30a7be486475
permissions -rwxr-xr-x
Dijkstra in GUI - and the body...
     1 #include "graph_displayer_canvas.h"
     2 #include <cmath>
     3 
     4 const int minimum_edge_width=2;
     5 
     6 int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
     7 {
     8   double min, max;
     9 
    10   min=edge_property_defaults[E_WIDTH];
    11   max=edge_property_defaults[E_WIDTH];
    12   Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]);
    13   
    14   if(edge==INVALID)
    15     {
    16       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    17 	{
    18 	  double v=fabs(actual_map[i]);
    19 	  int w;
    20 	  if(min==max)
    21 	    {
    22 	      w=(int)(edge_property_defaults[E_WIDTH]);
    23 	    }
    24 	  else
    25 	    {
    26 	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
    27 	    }
    28 	  if(zoomtrack)
    29 	    {
    30 	      double actual_ppu=get_pixels_per_unit();
    31 	      w=(int)(w/actual_ppu*fixed_zoom_factor);
    32 	    }
    33 	  edgesmap[i]->setLineWidth(w);
    34 	}
    35     }
    36   else
    37     {
    38       int w=(int)actual_map[edge];
    39       if(w>=0)
    40 	{
    41 	  edgesmap[edge]->setLineWidth(w);
    42 	}
    43     }
    44   return 0;
    45 }
    46 
    47 
    48 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
    49 {
    50   Graph::EdgeMap<double> * actual_map;
    51   double min, max;
    52 
    53   min=(mytab.mapstorage).minOfEdgeMap(mapname);
    54   max=(mytab.mapstorage).maxOfEdgeMap(mapname);
    55   actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
    56 
    57   if(edge==INVALID)
    58     {
    59       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
    60 	{
    61 	  double v=fabs((*actual_map)[i]);
    62 	  int w;
    63 	  if(autoscale)
    64 	    {
    65 	      if(min==max)
    66 		{
    67 		  w=(int)(edge_property_defaults[E_WIDTH]);
    68 		}
    69 	      else
    70 		{
    71 		  w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
    72 		}
    73 	    }
    74 	  else
    75 	    {
    76 	      w=(int)(v*edge_width);
    77 	    }
    78 	  if(w<minimum_edge_width)
    79 	    {
    80 	      w=minimum_edge_width;
    81 	    }
    82 	  if(zoomtrack)
    83 	    {
    84 	      double actual_ppu=get_pixels_per_unit();
    85 	      w=(int)(w/actual_ppu*fixed_zoom_factor);
    86 	    }
    87 	  edgesmap[i]->setLineWidth(w);
    88 	}
    89     }
    90   else
    91     {
    92       int w=(int)(*actual_map)[edge];
    93       if(w>=0)
    94 	{
    95 	  edgesmap[edge]->setLineWidth(w);
    96 	}
    97     }
    98   return 0;
    99 };
   100 
   101 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
   102 {  
   103 
   104   //function maps the range of the maximum and
   105   //the minimum of the nodemap to the range of
   106   //green in RGB
   107   Graph::EdgeMap<double> * actual_map;
   108   actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
   109 
   110   double max, min;
   111 
   112   max=(mytab.mapstorage).maxOfEdgeMap(mapname);
   113   min=(mytab.mapstorage).minOfEdgeMap(mapname);
   114 
   115   if(edge==INVALID)
   116     {
   117       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   118 	{
   119 	  double w=(*actual_map)[i];
   120 
   121 	  Gdk::Color color;
   122 	  if(max!=min)
   123 	    {
   124 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   125 	    }
   126 	  else
   127 	    {
   128 	      color.set_rgb_p (0, 100, 0);
   129 	    }
   130 	  edgesmap[i]->setFillColor(color);
   131 	}
   132     }
   133   else
   134     {
   135       Gdk::Color color;
   136 
   137       double w=(*actual_map)[edge];
   138 
   139       if(max!=min)
   140 	{
   141 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   142 	}
   143       else
   144 	{
   145 	  color.set_rgb_p (0, 100, 0);
   146 	}
   147 
   148       edgesmap[edge]->setFillColor(color);
   149     }
   150   return 0;
   151 };
   152 
   153 int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
   154 {  
   155 
   156   //function maps the range of the maximum and
   157   //the minimum of the nodemap to the range of
   158   //green in RGB
   159   Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]);
   160 
   161   double max, min;
   162 
   163   max=edge_property_defaults[E_COLOR];
   164   min=edge_property_defaults[E_COLOR];
   165 
   166   if(edge==INVALID)
   167     {
   168       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   169 	{
   170 	  double w=actual_map[i];
   171 
   172 	  Gdk::Color color;
   173 	  if(max!=min)
   174 	    {
   175 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   176 	    }
   177 	  else
   178 	    {
   179 	      color.set_rgb_p (0, 100, 0);
   180 	    }
   181 	  edgesmap[i]->setFillColor(color);
   182 	}
   183     }
   184   else
   185     {
   186       Gdk::Color color;
   187 
   188       double w=actual_map[edge];
   189 
   190       if(max!=min)
   191 	{
   192 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   193 	}
   194       else
   195 	{
   196 	  color.set_rgb_p (0, 100, 0);
   197 	}
   198 
   199       edgesmap[edge]->setFillColor(color);
   200     }
   201   return 0;
   202 };
   203 
   204 int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
   205 {
   206   //the number in the map will be written on the edge
   207   //EXCEPT when the name of the map is Default, because
   208   //in that case empty string will be written, because
   209   //that is the deleter map
   210   
   211   if(edge==INVALID)
   212     {
   213       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   214 	{
   215 	  edgemap_to_edit=mapname;
   216 	  double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i];
   217 	  
   218 	  std::ostringstream ostr;
   219 	  ostr << number;
   220 	  
   221 	  edgetextmap[i]->property_text().set_value(ostr.str());
   222 	}
   223 
   224     }
   225   else
   226     {
   227 	  double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge];
   228 
   229 	  std::ostringstream ostr;
   230 	  ostr << number;
   231 	  
   232 	  edgetextmap[edge]->property_text().set_value(ostr.str());
   233     }
   234 
   235   return 0;
   236 
   237 };
   238 
   239 int GraphDisplayerCanvas::resetEdgeText (Edge edge)
   240 {
   241   //the number in the map will be written on the edge
   242   //EXCEPT when the name of the map is Default, because
   243   //in that case empty string will be written, because
   244   //that is the deleter map
   245   
   246   if(edge==INVALID)
   247     {
   248       for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
   249 	{
   250 	  edgemap_to_edit="";
   251 	  edgetextmap[i]->property_text().set_value("");
   252 	}
   253 
   254     }
   255   else
   256     {
   257       edgetextmap[edge]->property_text().set_value("");
   258     }
   259 
   260   return 0;
   261 
   262 };