Merge branches/akos to trunk.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2006
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #include <graph_displayer_canvas.h>
20 #include <mapstorage.h>
24 const int minimum_node_radius=5;
26 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
28 MapStorage& ms = *mytab.mapstorage;
34 min = max = ms.get(mapname, n);
35 for (; n != INVALID; ++n)
37 if (static_cast<double>(ms.get(mapname, n)) > max)
38 max = ms.get(mapname, n);
39 if (static_cast<double>(ms.get(mapname, n)) < min)
40 min = ms.get(mapname, n);
46 for (NodeIt i(ms.graph); i!=INVALID; ++i)
48 double v=fabs(ms.get(mapname,i));
54 w=(int)(node_property_defaults[N_RADIUS]);
58 w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
63 w=(int)(v*radius_size);
66 if(w<minimum_node_radius)
68 w=minimum_node_radius;
73 double actual_ppu=get_pixels_per_unit();
74 w=(int)(w/actual_ppu*fixed_zoom_factor);
79 double x1, y1, x2, y2;
80 x1=nodesmap[i]->property_x1().get_value();
81 x2=nodesmap[i]->property_x2().get_value();
82 y1=nodesmap[i]->property_y1().get_value();
83 y2=nodesmap[i]->property_y2().get_value();
84 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
85 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
86 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
87 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
93 //I think only new nodes use this case
94 //that has no own value, only the default one
95 //int w=(int)(*actual_map)[node];
96 int w=(int)(node_property_defaults[N_RADIUS]);
99 double x1, y1, x2, y2;
100 x1=nodesmap[node]->property_x1().get_value();
101 x2=nodesmap[node]->property_x2().get_value();
102 y1=nodesmap[node]->property_y1().get_value();
103 y2=nodesmap[node]->property_y2().get_value();
104 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
105 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
106 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
107 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
113 int GraphDisplayerCanvas::resetNodeRadius (Node node)
115 MapStorage& ms = *mytab.mapstorage;
118 min=node_property_defaults[N_RADIUS];
119 max=node_property_defaults[N_RADIUS];
120 Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_RADIUS]);
124 for (NodeIt i(ms.graph); i!=INVALID; ++i)
126 double v=fabs(actual_map[i]);
130 w=(int)(node_property_defaults[N_RADIUS]);
134 w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
138 double actual_ppu=get_pixels_per_unit();
139 w=(int)(w/actual_ppu*fixed_zoom_factor);
143 double x1, y1, x2, y2;
144 x1=nodesmap[i]->property_x1().get_value();
145 x2=nodesmap[i]->property_x2().get_value();
146 y1=nodesmap[i]->property_y1().get_value();
147 y2=nodesmap[i]->property_y2().get_value();
148 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
149 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
150 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
151 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
157 //I think only new nodes use this case
158 // int w=(int)actual_map[node];
159 int w=(int)(node_property_defaults[N_RADIUS]);
162 double x1, y1, x2, y2;
163 x1=nodesmap[node]->property_x1().get_value();
164 x2=nodesmap[node]->property_x2().get_value();
165 y1=nodesmap[node]->property_y1().get_value();
166 y2=nodesmap[node]->property_y2().get_value();
167 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
168 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
169 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
170 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
176 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
178 MapStorage& ms = *mytab.mapstorage;
180 //function maps the range of the maximum and
181 //the minimum of the nodemap to the range of
188 min = max = ms.get(mapname, n);
189 for (; n != INVALID; ++n)
191 if (static_cast<double>(ms.get(mapname, n)) > max)
192 max = ms.get(mapname, n);
193 if (static_cast<double>(ms.get(mapname, n)) < min)
194 min = ms.get(mapname, n);
201 for (NodeIt i(ms.graph); i!=INVALID; ++i)
205 double w=ms.get(mapname, i);
209 color=rainbowColorCounter(min, max, w);
213 color.set_rgb_p (0, 0, 1);
216 nodesmap[i]->property_fill_color_gdk().set_value(color);
223 double w=ms.get(mapname, node);
227 color=rainbowColorCounter(min, max, w);
231 color.set_rgb_p (0, 0, 1);
234 nodesmap[node]->property_fill_color_gdk().set_value(color);
239 int GraphDisplayerCanvas::resetNodeColor (Node node)
241 MapStorage& ms = *mytab.mapstorage;
243 //function maps the range of the maximum and
244 //the minimum of the nodemap to the range of
247 Graph::NodeMap<double> actual_map(ms.graph,node_property_defaults[N_COLOR]);
251 max=node_property_defaults[N_COLOR];
252 min=node_property_defaults[N_COLOR];
257 for (NodeIt i(ms.graph); i!=INVALID; ++i)
261 double w=actual_map[i];
265 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
269 color.set_rgb_p (0, 0, 100);
272 nodesmap[i]->property_fill_color_gdk().set_value(color);
279 double w=actual_map[node];
283 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
287 color.set_rgb_p (0, 0, 100);
290 nodesmap[node]->property_fill_color_gdk().set_value(color);
295 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
297 MapStorage& ms = *mytab.mapstorage;
299 //the number in the map will be written on the node
300 //EXCEPT when the name of the map is Text, because
301 //in that case empty string will be written, because
302 //that is the deleter map
306 for (NodeIt i(ms.graph); i!=INVALID; ++i)
308 nodemap_to_edit=mapname;
310 nodetextmap[i]->property_text().set_value(
311 static_cast<std::string>(ms.get(mapname, i)));
316 nodetextmap[node]->property_text().set_value(
317 static_cast<std::string>(ms.get(mapname, node)));
322 int GraphDisplayerCanvas::resetNodeText (Node node)
324 MapStorage& ms = *mytab.mapstorage;
326 //the number in the map will be written on the node
327 //EXCEPT when the name of the map is Text, because
328 //in that case empty string will be written, because
329 //that is the deleter map
333 for (NodeIt i(ms.graph); i!=INVALID; ++i)
336 nodetextmap[i]->property_text().set_value("");
341 nodetextmap[node]->property_text().set_value("");