COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-edge.cc @ 90:e9f8f44f12a3

gui
Last change on this file since 90:e9f8f44f12a3 was 89:4042761b21e3, checked in by Hegyi Péter, 18 years ago

Reorganizing.

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