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