gui/graph_displayer_canvas-edge.cc
changeset 1766 6c59b1386fe8
parent 1645 4a04bb856ac7
child 1819 fd82adfbe905
equal deleted inserted replaced
14:feeddff356fe 15:ede90d7953fb
     1 #include "graph_displayer_canvas.h"
     1 #include "graph_displayer_canvas.h"
     2 #include "broken_edge.h"
     2 #include "broken_edge.h"
     3 #include <cmath>
     3 #include <cmath>
     4 
     4 
     5 
     5 
     6 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
     6 int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
     7 {
     7 {
     8   Graph::EdgeMap<double> * actual_map;
     8   Graph::EdgeMap<double> * actual_map;
     9   double min, max;
     9   double min, max;
    10 
    10 
    11   if(mapname=="Default")
    11   min=edge_property_defaults[E_WIDTH];
    12     {
    12   max=edge_property_defaults[E_WIDTH];
    13       min=edge_property_defaults[E_WIDTH];
    13   actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
    14       max=edge_property_defaults[E_WIDTH];
    14   
    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)
    15   if(edge==INVALID)
    25     {
    16     {
    26       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    17       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    27 	{
    18 	{
    28 	  double v=fabs((*actual_map)[i]);
    19 	  double v=fabs((*actual_map)[i]);
    45 	{
    36 	{
    46 	  edgesmap[edge]->property_width_units().set_value(w);
    37 	  edgesmap[edge]->property_width_units().set_value(w);
    47 	}
    38 	}
    48     }
    39     }
    49   return 0;
    40   return 0;
       
    41 }
       
    42 
       
    43 
       
    44 int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
       
    45 {
       
    46   Graph::EdgeMap<double> * actual_map;
       
    47   double min, max;
       
    48 
       
    49   min=mapstorage.minOfEdgeMap(mapname);
       
    50   max=mapstorage.maxOfEdgeMap(mapname);
       
    51   actual_map=(mapstorage.edgemap_storage)[mapname];
       
    52 
       
    53   if(edge==INVALID)
       
    54     {
       
    55       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
       
    56 	{
       
    57 	  double v=fabs((*actual_map)[i]);
       
    58 	  int w;
       
    59 	  if(min==max)
       
    60 	    {
       
    61 	      w=(int)(edge_property_defaults[E_WIDTH]);
       
    62 	    }
       
    63 	  else
       
    64 	    {
       
    65 	      w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
       
    66 	    }
       
    67 	  edgesmap[i]->property_width_units().set_value(w);
       
    68 	}
       
    69     }
       
    70   else
       
    71     {
       
    72       int w=(int)(*actual_map)[edge];
       
    73       if(w>=0)
       
    74 	{
       
    75 	  edgesmap[edge]->property_width_units().set_value(w);
       
    76 	}
       
    77     }
       
    78   return 0;
    50 };
    79 };
    51 
    80 
    52 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
    81 int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
    53 {  
    82 {  
    54 
    83 
    55   //function maps the range of the maximum and
    84   //function maps the range of the maximum and
    56   //the minimum of the nodemap to the range of
    85   //the minimum of the nodemap to the range of
    57   //green in RGB
    86   //green in RGB
    58   Graph::EdgeMap<double> * actual_map;
    87   Graph::EdgeMap<double> * actual_map;
    59   if(mapname=="Default")
    88   actual_map=(mapstorage.edgemap_storage)[mapname];
    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 
    89 
    68   double max, min;
    90   double max, min;
    69 
    91 
    70   if(mapname!="Default")
    92   max=mapstorage.maxOfEdgeMap(mapname);
    71     {
    93   min=mapstorage.minOfEdgeMap(mapname);
    72       max=mapstorage.maxOfEdgeMap(mapname);
    94 
    73       min=mapstorage.minOfEdgeMap(mapname);
    95   if(edge==INVALID)
    74     }
    96     {
    75   else
    97       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    76     {
    98 	{
    77       max=edge_property_defaults[E_COLOR];
    99 	  double w=(*actual_map)[i];
    78       min=edge_property_defaults[E_COLOR];
   100 
    79     }
   101 	  Gdk::Color color;
       
   102 	  if(max!=min)
       
   103 	    {
       
   104 	      color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
       
   105 	    }
       
   106 	  else
       
   107 	    {
       
   108 	      color.set_rgb_p (0, 100, 0);
       
   109 	    }
       
   110 	  edgesmap[i]->property_fill_color_gdk().set_value(color);
       
   111 	}
       
   112     }
       
   113   else
       
   114     {
       
   115       Gdk::Color color;
       
   116 
       
   117       double w=(*actual_map)[edge];
       
   118 
       
   119       if(max!=min)
       
   120 	{
       
   121 	  color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
       
   122 	}
       
   123       else
       
   124 	{
       
   125 	  color.set_rgb_p (0, 100, 0);
       
   126 	}
       
   127 
       
   128       edgesmap[edge]->property_fill_color_gdk().set_value(color);
       
   129     }
       
   130   return 0;
       
   131 };
       
   132 
       
   133 int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
       
   134 {  
       
   135 
       
   136   //function maps the range of the maximum and
       
   137   //the minimum of the nodemap to the range of
       
   138   //green in RGB
       
   139   Graph::EdgeMap<double> * actual_map;
       
   140   actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
       
   141 
       
   142   double max, min;
       
   143 
       
   144   max=edge_property_defaults[E_COLOR];
       
   145   min=edge_property_defaults[E_COLOR];
    80 
   146 
    81   if(edge==INVALID)
   147   if(edge==INVALID)
    82     {
   148     {
    83       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   149       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
    84 	{
   150 	{
   125   
   191   
   126   if(edge==INVALID)
   192   if(edge==INVALID)
   127     {
   193     {
   128       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   194       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
   129 	{
   195 	{
   130 	  if(mapname!="Default")
   196 	  edgemap_to_edit=mapname;
   131 	    {
   197 	  double number=(*(mapstorage.edgemap_storage)[mapname])[i];
   132 	      edgemap_to_edit=mapname;
   198 	  
   133 	      double number=(*(mapstorage.edgemap_storage)[mapname])[i];
   199 	  std::ostringstream ostr;
   134 
   200 	  ostr << number;
   135 	      std::ostringstream ostr;
   201 	  
   136 	      ostr << number;
   202 	  edgetextmap[i]->property_text().set_value(ostr.str());
   137 	      
   203 	}
   138       	      edgetextmap[i]->property_text().set_value(ostr.str());
   204 
   139 	    }
   205     }
   140 	  else
   206   else
   141 	    {
   207     {
   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];
   208 	  double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
   153 
   209 
   154 	  std::ostringstream ostr;
   210 	  std::ostringstream ostr;
   155 	  ostr << number;
   211 	  ostr << number;
   156 	  
   212 	  
   157 	  edgetextmap[edge]->property_text().set_value(ostr.str());
   213 	  edgetextmap[edge]->property_text().set_value(ostr.str());
   158 	}
   214     }
   159       else
   215 
   160 	{
   216   return 0;
   161 	  edgetextmap[edge]->property_text().set_value("");
   217 
   162 	}
   218 };
   163 	  
   219 
   164     }
   220 int GraphDisplayerCanvas::resetEdgeText (Edge edge)
   165 
   221 {
   166   return 0;
   222   //the number in the map will be written on the edge
   167 
   223   //EXCEPT when the name of the map is Default, because
   168 };
   224   //in that case empty string will be written, because
       
   225   //that is the deleter map
       
   226   
       
   227   if(edge==INVALID)
       
   228     {
       
   229       for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
       
   230 	{
       
   231 	  edgemap_to_edit="";
       
   232 	  edgetextmap[i]->property_text().set_value("");
       
   233 	}
       
   234 
       
   235     }
       
   236   else
       
   237     {
       
   238       edgetextmap[edge]->property_text().set_value("");
       
   239     }
       
   240 
       
   241   return 0;
       
   242 
       
   243 };