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