COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-node.cc @ 154:65c1b103443d

Last change on this file since 154:65c1b103443d was 154:65c1b103443d, checked in by Hegyi Péter, 18 years ago

Node view

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