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
Line 
1#include "graph_displayer_canvas.h"
2#include <cmath>
3
4const int minimum_node_radius=0;
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_max-minimum_node_radius));
29                }
30            }
31          else
32            {
33              w=(int)(v*radius_max);
34            }
35
36          if(w<5)
37            {
38              w=5;
39            }
40
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        }
54    }
55  else
56    {
57      //I think only new nodes use this case
58      //that has no own value, only the default one
59      //int w=(int)(*actual_map)[node];
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        }
73    }
74  return 0;
75};
76
77int GraphDisplayerCanvas::resetNodeRadius (Node node)
78{
79  double min, max;
80  min=node_property_defaults[N_RADIUS];
81  max=node_property_defaults[N_RADIUS];
82  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
83 
84  if(node==INVALID)
85    {
86      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
87        {
88          double v=fabs(actual_map[i]);
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            }
98          if(w>=0)
99            {
100              double x1, y1, x2, y2;
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();
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    {
114      //I think only new nodes use this case
115//       int w=(int)actual_map[node];
116      int w=(int)(node_property_defaults[N_RADIUS]);
117      if(w>=0)
118        {
119          double x1, y1, x2, y2;
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();
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
133int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
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
140  Graph::NodeMap<double> * actual_map;
141  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
142
143  double max, min;
144
145  max=(mytab.mapstorage).maxOfNodeMap(mapname);
146  min=(mytab.mapstorage).minOfNodeMap(mapname);
147
148  if(node==INVALID)
149    {
150
151      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
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        }
168    }
169  else
170    {
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);
185    }
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
196  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
197
198  double max, min;
199
200  max=node_property_defaults[N_COLOR];
201  min=node_property_defaults[N_COLOR];
202
203  if(node==INVALID)
204    {
205
206      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
207        {
208          Gdk::Color color;
209
210          double w=actual_map[i];
211
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;
227
228      double w=actual_map[node];
229
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
244int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
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
251
252  Graph::NodeMap<double> * actual_map=NULL;
253  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
254
255  if(node==INVALID)
256    {
257      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
258        {
259          nodemap_to_edit=mapname;
260          double number=(*actual_map)[i];
261
262          std::ostringstream ostr;
263          ostr << number;
264             
265          nodetextmap[i]->property_text().set_value(ostr.str());
266        }
267    }
268  else
269    {
270      double number=(*actual_map)[node];
271
272      std::ostringstream ostr;
273      ostr << number;
274             
275      nodetextmap[node]->property_text().set_value(ostr.str());
276    }
277  return 0;
278};
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    {
290      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
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.