COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-edge.cc @ 88:c397e85ec555

gui
Last change on this file since 88:c397e85ec555 was 81:5ad61c33487c, checked in by Hegyi Péter, 18 years ago

Mapselector widget reached its first release, but there are still work to do on it, I know...

  • Property exe set to *
File size: 4.9 KB
Line 
1#include "graph_displayer_canvas.h"
2#include "broken_edge.h"
3#include <cmath>
4
5
6int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
7{
8  Graph::EdgeMap<double> * actual_map;
9  double min, max;
10
11  min=edge_property_defaults[E_WIDTH];
12  max=edge_property_defaults[E_WIDTH];
13  actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
14 
15  if(edge==INVALID)
16    {
17      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
18        {
19          double v=fabs((*actual_map)[i]);
20          int w;
21          if(min==max)
22            {
23              w=(int)(edge_property_defaults[E_WIDTH]);
24            }
25          else
26            {
27              w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
28            }
29          edgesmap[i]->property_width_units().set_value(w);
30        }
31    }
32  else
33    {
34      int w=(int)(*actual_map)[edge];
35      if(w>=0)
36        {
37          edgesmap[edge]->property_width_units().set_value(w);
38        }
39    }
40  return 0;
41}
42
43
44int 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;
79};
80
81int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
82
83
84  //function maps the range of the maximum and
85  //the minimum of the nodemap to the range of
86  //green in RGB
87  Graph::EdgeMap<double> * actual_map;
88  actual_map=(mapstorage.edgemap_storage)[mapname];
89
90  double max, min;
91
92  max=mapstorage.maxOfEdgeMap(mapname);
93  min=mapstorage.minOfEdgeMap(mapname);
94
95  if(edge==INVALID)
96    {
97      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
98        {
99          double w=(*actual_map)[i];
100
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
133int 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];
146
147  if(edge==INVALID)
148    {
149      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
150        {
151          double w=(*actual_map)[i];
152
153          Gdk::Color color;
154          if(max!=min)
155            {
156              color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
157            }
158          else
159            {
160              color.set_rgb_p (0, 100, 0);
161            }
162          edgesmap[i]->property_fill_color_gdk().set_value(color);
163        }
164    }
165  else
166    {
167      Gdk::Color color;
168
169      double w=(*actual_map)[edge];
170
171      if(max!=min)
172        {
173          color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
174        }
175      else
176        {
177          color.set_rgb_p (0, 100, 0);
178        }
179
180      edgesmap[edge]->property_fill_color_gdk().set_value(color);
181    }
182  return 0;
183};
184
185int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
186{
187  //the number in the map will be written on the edge
188  //EXCEPT when the name of the map is Default, because
189  //in that case empty string will be written, because
190  //that is the deleter map
191 
192  if(edge==INVALID)
193    {
194      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
195        {
196          edgemap_to_edit=mapname;
197          double number=(*(mapstorage.edgemap_storage)[mapname])[i];
198         
199          std::ostringstream ostr;
200          ostr << number;
201         
202          edgetextmap[i]->property_text().set_value(ostr.str());
203        }
204
205    }
206  else
207    {
208          double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
209
210          std::ostringstream ostr;
211          ostr << number;
212         
213          edgetextmap[edge]->property_text().set_value(ostr.str());
214    }
215
216  return 0;
217
218};
219
220int GraphDisplayerCanvas::resetEdgeText (Edge edge)
221{
222  //the number in the map will be written on the edge
223  //EXCEPT when the name of the map is Default, because
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};
Note: See TracBrowser for help on using the repository browser.