No segmentation fault will be occured if two nodes are exactly overlap each other, AND they are connected.
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"
22 const int minimum_node_radius=5;
24 int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
26 Graph::NodeMap<double> * actual_map;
28 min=(mytab.mapstorage).minOfNodeMap(mapname);
29 max=(mytab.mapstorage).maxOfNodeMap(mapname);
30 actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
34 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
36 double v=fabs((*actual_map)[i]);
42 w=(int)(node_property_defaults[N_RADIUS]);
46 w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
51 w=(int)(v*radius_size);
54 if(w<minimum_node_radius)
56 w=minimum_node_radius;
61 double actual_ppu=get_pixels_per_unit();
62 w=(int)(w/actual_ppu*fixed_zoom_factor);
67 double x1, y1, x2, y2;
68 x1=nodesmap[i]->property_x1().get_value();
69 x2=nodesmap[i]->property_x2().get_value();
70 y1=nodesmap[i]->property_y1().get_value();
71 y2=nodesmap[i]->property_y2().get_value();
72 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
73 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
74 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
75 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
81 //I think only new nodes use this case
82 //that has no own value, only the default one
83 //int w=(int)(*actual_map)[node];
84 int w=(int)(node_property_defaults[N_RADIUS]);
87 double x1, y1, x2, y2;
88 x1=nodesmap[node]->property_x1().get_value();
89 x2=nodesmap[node]->property_x2().get_value();
90 y1=nodesmap[node]->property_y1().get_value();
91 y2=nodesmap[node]->property_y2().get_value();
92 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
93 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
94 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
95 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
101 int GraphDisplayerCanvas::resetNodeRadius (Node node)
104 min=node_property_defaults[N_RADIUS];
105 max=node_property_defaults[N_RADIUS];
106 Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
110 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
112 double v=fabs(actual_map[i]);
116 w=(int)(node_property_defaults[N_RADIUS]);
120 w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
124 double actual_ppu=get_pixels_per_unit();
125 w=(int)(w/actual_ppu*fixed_zoom_factor);
129 double x1, y1, x2, y2;
130 x1=nodesmap[i]->property_x1().get_value();
131 x2=nodesmap[i]->property_x2().get_value();
132 y1=nodesmap[i]->property_y1().get_value();
133 y2=nodesmap[i]->property_y2().get_value();
134 nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
135 nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
136 nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
137 nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
143 //I think only new nodes use this case
144 // int w=(int)actual_map[node];
145 int w=(int)(node_property_defaults[N_RADIUS]);
148 double x1, y1, x2, y2;
149 x1=nodesmap[node]->property_x1().get_value();
150 x2=nodesmap[node]->property_x2().get_value();
151 y1=nodesmap[node]->property_y1().get_value();
152 y2=nodesmap[node]->property_y2().get_value();
153 nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
154 nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
155 nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
156 nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
162 int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
165 //function maps the range of the maximum and
166 //the minimum of the nodemap to the range of
169 Graph::NodeMap<double> * actual_map;
170 actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
174 max=(mytab.mapstorage).maxOfNodeMap(mapname);
175 min=(mytab.mapstorage).minOfNodeMap(mapname);
180 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
184 double w=(*actual_map)[i];
188 color=rainbowColorCounter(min, max, w);
192 color.set_rgb_p (0, 0, 1);
195 nodesmap[i]->property_fill_color_gdk().set_value(color);
202 double w=(*actual_map)[node];
206 color=rainbowColorCounter(min, max, w);
210 color.set_rgb_p (0, 0, 1);
213 nodesmap[node]->property_fill_color_gdk().set_value(color);
218 int GraphDisplayerCanvas::resetNodeColor (Node node)
221 //function maps the range of the maximum and
222 //the minimum of the nodemap to the range of
225 Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
229 max=node_property_defaults[N_COLOR];
230 min=node_property_defaults[N_COLOR];
235 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
239 double w=actual_map[i];
243 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
247 color.set_rgb_p (0, 0, 100);
250 nodesmap[i]->property_fill_color_gdk().set_value(color);
257 double w=actual_map[node];
261 color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
265 color.set_rgb_p (0, 0, 100);
268 nodesmap[node]->property_fill_color_gdk().set_value(color);
273 int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
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
281 Graph::NodeMap<double> * actual_map=NULL;
282 actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
286 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
288 nodemap_to_edit=mapname;
289 double number=(*actual_map)[i];
291 std::ostringstream ostr;
294 nodetextmap[i]->property_text().set_value(ostr.str());
299 double number=(*actual_map)[node];
301 std::ostringstream ostr;
304 nodetextmap[node]->property_text().set_value(ostr.str());
309 int GraphDisplayerCanvas::resetNodeText (Node node)
312 //the number in the map will be written on the node
313 //EXCEPT when the name of the map is Text, because
314 //in that case empty string will be written, because
315 //that is the deleter map
319 for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
322 nodetextmap[i]->property_text().set_value("");
327 nodetextmap[node]->property_text().set_value("");