gui/graph_displayer_canvas-edge.cc
author ladanyi
Tue, 23 Aug 2005 07:36:09 +0000
changeset 1645 4a04bb856ac7
parent 1643 9285f3777553
child 1731 616bc933c2bc
permissions -rwxr-xr-x
- id maps are not editable
- handle exceptions thrown by the file reader
- texts are always above the edges
- store a default value for all maps, so that edges and nodes created after
adding a new map receive the default value too
- create node on button release, not on click (fixes a few oddities)
     1 #include "graph_displayer_canvas.h"
     2 #include "broken_edge.h"
     3 #include <cmath>
     4 
     5 
     6 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
     7 {
     8   Graph::EdgeMap<double> * actual_map;
     9   double min, max;
    10 
    11   if(mapname=="Default")
    12     {
    13       min=edge_property_defaults[E_WIDTH];
    14       max=edge_property_defaults[E_WIDTH];
    15       actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
    16     }
    17   else
    18     {
    19       min=mapstorage.minOfEdgeMap(mapname);
    20       max=mapstorage.maxOfEdgeMap(mapname);
    21       actual_map=(mapstorage.edgemap_storage)[mapname];
    22     }
    23 
    24   if(edge==INVALID)
    25     {
    26       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    27 	{
    28 	  double v=fabs((*actual_map)[i]);
    29 	  int w;
    30 	  if(min==max)
    31 	    {
    32 	      w=(int)(edge_property_defaults[E_WIDTH]);
    33 	    }
    34 	  else
    35 	    {
    36 	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
    37 	    }
    38 	  edgesmap[i]->property_width_units().set_value(w);
    39 	}
    40     }
    41   else
    42     {
    43       int w=(int)(*actual_map)[edge];
    44       if(w>=0)
    45 	{
    46 	  edgesmap[edge]->property_width_units().set_value(w);
    47 	}
    48     }
    49   return 0;
    50 };
    51 
    52 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
    53 {  
    54 
    55   //function maps the range of the maximum and
    56   //the minimum of the nodemap to the range of
    57   //green in RGB
    58   Graph::EdgeMap<double> * actual_map;
    59   if(mapname=="Default")
    60     {
    61       actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
    62     }
    63   else
    64     {
    65       actual_map=(mapstorage.edgemap_storage)[mapname];
    66     }
    67 
    68   double max, min;
    69 
    70   if(mapname!="Default")
    71     {
    72       max=mapstorage.maxOfEdgeMap(mapname);
    73       min=mapstorage.minOfEdgeMap(mapname);
    74     }
    75   else
    76     {
    77       max=edge_property_defaults[E_COLOR];
    78       min=edge_property_defaults[E_COLOR];
    79     }
    80 
    81   if(edge==INVALID)
    82     {
    83       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    84 	{
    85 	  double w=(*actual_map)[i];
    86 
    87 	  Gdk::Color color;
    88 	  if(max!=min)
    89 	    {
    90 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
    91 	    }
    92 	  else
    93 	    {
    94 	      color.set_rgb_p (0, 100, 0);
    95 	    }
    96 	  edgesmap[i]->property_fill_color_gdk().set_value(color);
    97 	}
    98     }
    99   else
   100     {
   101       Gdk::Color color;
   102 
   103       double w=(*actual_map)[edge];
   104 
   105       if(max!=min)
   106 	{
   107 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
   108 	}
   109       else
   110 	{
   111 	  color.set_rgb_p (0, 100, 0);
   112 	}
   113 
   114       edgesmap[edge]->property_fill_color_gdk().set_value(color);
   115     }
   116   return 0;
   117 };
   118 
   119 int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
   120 {
   121   //the number in the map will be written on the edge
   122   //EXCEPT when the name of the map is Default, because
   123   //in that case empty string will be written, because
   124   //that is the deleter map
   125   
   126   if(edge==INVALID)
   127     {
   128       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   129 	{
   130 	  if(mapname!="Default")
   131 	    {
   132 	      edgemap_to_edit=mapname;
   133 	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
   134 
   135 	      std::ostringstream ostr;
   136 	      ostr << number;
   137 	      
   138       	      edgetextmap[i]->property_text().set_value(ostr.str());
   139 	    }
   140 	  else
   141 	    {
   142 	      edgemap_to_edit="";
   143 	      edgetextmap[i]->property_text().set_value("");
   144 	    }
   145 	}
   146 
   147     }
   148   else
   149     {
   150       if(mapname!="Default")
   151 	{
   152 	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
   153 
   154 	  std::ostringstream ostr;
   155 	  ostr << number;
   156 	  
   157 	  edgetextmap[edge]->property_text().set_value(ostr.str());
   158 	}
   159       else
   160 	{
   161 	  edgetextmap[edge]->property_text().set_value("");
   162 	}
   163 	  
   164     }
   165 
   166   return 0;
   167 
   168 };