COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-node.cc @ 155:74065e83844d

Last change on this file since 155:74065e83844d was 155:74065e83844d, checked in by Hegyi Péter, 18 years ago

Small modification in node view settings.

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