COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-node.cc @ 157:7e6ad28aeb9e

Last change on this file since 157:7e6ad28aeb9e was 157:7e6ad28aeb9e, checked in by Hegyi Péter, 18 years ago

View settings also for edges.

  • Property exe set to *
File size: 7.3 KB
Line 
1#include "graph_displayer_canvas.h"
2#include <cmath>
3
4const int minimum_node_radius=5;
5
6int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
7{
8  Graph::NodeMap<double> * actual_map;
9  double min, max;
10  min=(mytab.mapstorage).minOfNodeMap(mapname);
11  max=(mytab.mapstorage).maxOfNodeMap(mapname);
12  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
13
14  if(node==INVALID)
15    {
16      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
17        {
18          double v=fabs((*actual_map)[i]);
19          int w;
20          if(autoscale)
21            {
22              if(min==max)
23                {
24                  w=(int)(node_property_defaults[N_RADIUS]);
25                }
26              else
27                {
28                  w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
29                }
30            }
31          else
32            {
33              w=(int)(v*radius_size);
34            }
35
36          if(w<minimum_node_radius)
37            {
38              w=minimum_node_radius;
39            }
40
41          if(zoomtrack)
42            {
43              double actual_ppu=get_pixels_per_unit();
44              w=(int)(w/actual_ppu*fixed_zoom_factor);
45            }
46
47          if(w>=0)
48            {
49              double x1, y1, x2, y2;
50              x1=nodesmap[i]->property_x1().get_value();
51              x2=nodesmap[i]->property_x2().get_value();
52              y1=nodesmap[i]->property_y1().get_value();
53              y2=nodesmap[i]->property_y2().get_value();
54              nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
55              nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
56              nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
57              nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
58            }
59        }
60    }
61  else
62    {
63      //I think only new nodes use this case
64      //that has no own value, only the default one
65      //int w=(int)(*actual_map)[node];
66      int w=(int)(node_property_defaults[N_RADIUS]);
67      if(w>=0)
68        {
69          double x1, y1, x2, y2;
70          x1=nodesmap[node]->property_x1().get_value();
71          x2=nodesmap[node]->property_x2().get_value();
72          y1=nodesmap[node]->property_y1().get_value();
73          y2=nodesmap[node]->property_y2().get_value();
74          nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
75          nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
76          nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
77          nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
78        }
79    }
80  return 0;
81};
82
83int GraphDisplayerCanvas::resetNodeRadius (Node node)
84{
85  double min, max;
86  min=node_property_defaults[N_RADIUS];
87  max=node_property_defaults[N_RADIUS];
88  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
89 
90  if(node==INVALID)
91    {
92      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
93        {
94          double v=fabs(actual_map[i]);
95          int w;
96          if(min==max)
97            {
98              w=(int)(node_property_defaults[N_RADIUS]);
99            }
100          else
101            {
102              w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
103            }
104          if(zoomtrack)
105            {
106              double actual_ppu=get_pixels_per_unit();
107              w=(int)(w/actual_ppu*fixed_zoom_factor);
108            }
109          if(w>=0)
110            {
111              double x1, y1, x2, y2;
112              x1=nodesmap[i]->property_x1().get_value();
113              x2=nodesmap[i]->property_x2().get_value();
114              y1=nodesmap[i]->property_y1().get_value();
115              y2=nodesmap[i]->property_y2().get_value();
116              nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
117              nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
118              nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
119              nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
120            }
121        }
122    }
123  else
124    {
125      //I think only new nodes use this case
126//       int w=(int)actual_map[node];
127      int w=(int)(node_property_defaults[N_RADIUS]);
128      if(w>=0)
129        {
130          double x1, y1, x2, y2;
131          x1=nodesmap[node]->property_x1().get_value();
132          x2=nodesmap[node]->property_x2().get_value();
133          y1=nodesmap[node]->property_y1().get_value();
134          y2=nodesmap[node]->property_y2().get_value();
135          nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
136          nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
137          nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
138          nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
139        }
140    }
141  return 0;
142};
143
144int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
145
146
147  //function maps the range of the maximum and
148  //the minimum of the nodemap to the range of
149  //green in RGB
150
151  Graph::NodeMap<double> * actual_map;
152  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
153
154  double max, min;
155
156  max=(mytab.mapstorage).maxOfNodeMap(mapname);
157  min=(mytab.mapstorage).minOfNodeMap(mapname);
158
159  if(node==INVALID)
160    {
161
162      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
163        {
164          Gdk::Color color;
165
166          double w=(*actual_map)[i];
167
168          if(max!=min)
169            {
170              color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
171            }
172          else
173            {
174              color.set_rgb_p (0, 0, 100);
175            }
176
177          nodesmap[i]->property_fill_color_gdk().set_value(color);
178        }
179    }
180  else
181    {
182      Gdk::Color color;
183
184      double w=(*actual_map)[node];
185
186      if(max!=min)
187        {
188          color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
189        }
190      else
191        {
192          color.set_rgb_p (0, 0, 100);
193        }
194
195      nodesmap[node]->property_fill_color_gdk().set_value(color);
196    }
197  return 0;
198};
199
200int GraphDisplayerCanvas::resetNodeColor (Node node)
201
202
203  //function maps the range of the maximum and
204  //the minimum of the nodemap to the range of
205  //green in RGB
206
207  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
208
209  double max, min;
210
211  max=node_property_defaults[N_COLOR];
212  min=node_property_defaults[N_COLOR];
213
214  if(node==INVALID)
215    {
216
217      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
218        {
219          Gdk::Color color;
220
221          double w=actual_map[i];
222
223          if(max!=min)
224            {
225              color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
226            }
227          else
228            {
229              color.set_rgb_p (0, 0, 100);
230            }
231
232          nodesmap[i]->property_fill_color_gdk().set_value(color);
233        }
234    }
235  else
236    {
237      Gdk::Color color;
238
239      double w=actual_map[node];
240
241      if(max!=min)
242        {
243          color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
244        }
245      else
246        {
247          color.set_rgb_p (0, 0, 100);
248        }
249
250      nodesmap[node]->property_fill_color_gdk().set_value(color);
251    }
252  return 0;
253};
254
255int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
256{
257
258  //the number in the map will be written on the node
259  //EXCEPT when the name of the map is Text, because
260  //in that case empty string will be written, because
261  //that is the deleter map
262
263  Graph::NodeMap<double> * actual_map=NULL;
264  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
265
266  if(node==INVALID)
267    {
268      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
269        {
270          nodemap_to_edit=mapname;
271          double number=(*actual_map)[i];
272
273          std::ostringstream ostr;
274          ostr << number;
275             
276          nodetextmap[i]->property_text().set_value(ostr.str());
277        }
278    }
279  else
280    {
281      double number=(*actual_map)[node];
282
283      std::ostringstream ostr;
284      ostr << number;
285             
286      nodetextmap[node]->property_text().set_value(ostr.str());
287    }
288  return 0;
289};
290
291int GraphDisplayerCanvas::resetNodeText (Node node)
292{
293
294  //the number in the map will be written on the node
295  //EXCEPT when the name of the map is Text, because
296  //in that case empty string will be written, because
297  //that is the deleter map
298
299  if(node==INVALID)
300    {
301      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
302        {
303          nodemap_to_edit="";
304          nodetextmap[i]->property_text().set_value("");
305        }
306    }
307  else
308    {
309      nodetextmap[node]->property_text().set_value("");
310    }
311  return 0;
312};
Note: See TracBrowser for help on using the repository browser.