COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-node.cc @ 173:8339178ae43d

Last change on this file since 173:8339178ae43d 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
RevLine 
[53]1#include "graph_displayer_canvas.h"
[59]2#include <cmath>
[28]3
[157]4const int minimum_node_radius=5;
[28]5
[62]6int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
[28]7{
[31]8  Graph::NodeMap<double> * actual_map;
[48]9  double min, max;
[96]10  min=(mytab.mapstorage).minOfNodeMap(mapname);
11  max=(mytab.mapstorage).maxOfNodeMap(mapname);
12  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
[81]13
14  if(node==INVALID)
[31]15    {
[96]16      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]17        {
18          double v=fabs((*actual_map)[i]);
19          int w;
[154]20          if(autoscale)
[81]21            {
[154]22              if(min==max)
23                {
24                  w=(int)(node_property_defaults[N_RADIUS]);
25                }
26              else
27                {
[157]28                  w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
[154]29                }
[81]30            }
31          else
32            {
[157]33              w=(int)(v*radius_size);
[81]34            }
[155]35
[157]36          if(w<minimum_node_radius)
[155]37            {
[157]38              w=minimum_node_radius;
[155]39            }
40
[156]41          if(zoomtrack)
42            {
43              double actual_ppu=get_pixels_per_unit();
44              w=(int)(w/actual_ppu*fixed_zoom_factor);
45            }
46
[81]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        }
[31]60    }
61  else
62    {
[81]63      //I think only new nodes use this case
[154]64      //that has no own value, only the default one
65      //int w=(int)(*actual_map)[node];
[81]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        }
[31]79    }
[81]80  return 0;
81};
[31]82
[81]83int GraphDisplayerCanvas::resetNodeRadius (Node node)
84{
85  double min, max;
86  min=node_property_defaults[N_RADIUS];
87  max=node_property_defaults[N_RADIUS];
[96]88  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
[81]89 
[28]90  if(node==INVALID)
91    {
[96]92      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]93        {
[91]94          double v=fabs(actual_map[i]);
[48]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            }
[156]104          if(zoomtrack)
105            {
106              double actual_ppu=get_pixels_per_unit();
107              w=(int)(w/actual_ppu*fixed_zoom_factor);
108            }
[28]109          if(w>=0)
110            {
111              double x1, y1, x2, y2;
[31]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();
[28]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    {
[31]125      //I think only new nodes use this case
[91]126//       int w=(int)actual_map[node];
[31]127      int w=(int)(node_property_defaults[N_RADIUS]);
[28]128      if(w>=0)
129        {
130          double x1, y1, x2, y2;
[31]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();
[28]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
[62]144int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
[28]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
[31]151  Graph::NodeMap<double> * actual_map;
[96]152  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
[81]153
154  double max, min;
155
[96]156  max=(mytab.mapstorage).maxOfNodeMap(mapname);
157  min=(mytab.mapstorage).minOfNodeMap(mapname);
[81]158
159  if(node==INVALID)
[31]160    {
[81]161
[96]162      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]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        }
[31]179    }
180  else
181    {
[81]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);
[31]196    }
[81]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
[96]207  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
[31]208
209  double max, min;
210
[81]211  max=node_property_defaults[N_COLOR];
212  min=node_property_defaults[N_COLOR];
[31]213
[28]214  if(node==INVALID)
215    {
216
[96]217      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]218        {
219          Gdk::Color color;
[31]220
[91]221          double w=actual_map[i];
[31]222
[28]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;
[31]238
[91]239      double w=actual_map[node];
[31]240
[28]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
[62]255int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
[28]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
[31]262
[36]263  Graph::NodeMap<double> * actual_map=NULL;
[96]264  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
[28]265
266  if(node==INVALID)
267    {
[96]268      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]269        {
[81]270          nodemap_to_edit=mapname;
271          double number=(*actual_map)[i];
[45]272
[81]273          std::ostringstream ostr;
274          ostr << number;
[45]275             
[81]276          nodetextmap[i]->property_text().set_value(ostr.str());
[28]277        }
278    }
279  else
280    {
[81]281      double number=(*actual_map)[node];
[45]282
[81]283      std::ostringstream ostr;
284      ostr << number;
[45]285             
[81]286      nodetextmap[node]->property_text().set_value(ostr.str());
[28]287    }
288  return 0;
289};
[81]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    {
[96]301      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]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.