COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas-edge.cc @ 1878:409a31271efd

Last change on this file since 1878:409a31271efd was 1849:a4d1362397fe, checked in by Hegyi Péter, 18 years ago

Notebook style is provided. Without opportunity to close tabs. :-) But with all other necessary things (I think).

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