alpar@174
|
1 |
/* -*- C++ -*-
|
alpar@174
|
2 |
*
|
alpar@174
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@174
|
4 |
*
|
alpar@174
|
5 |
* Copyright (C) 2003-2006
|
alpar@174
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@174
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@174
|
8 |
*
|
alpar@174
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@174
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@174
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@174
|
12 |
*
|
alpar@174
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@174
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@174
|
15 |
* purpose.
|
alpar@174
|
16 |
*
|
alpar@174
|
17 |
*/
|
alpar@174
|
18 |
|
ladanyi@53
|
19 |
#include "graph_displayer_canvas.h"
|
alpar@59
|
20 |
#include <cmath>
|
hegyi@28
|
21 |
|
hegyi@157
|
22 |
const int minimum_node_radius=5;
|
hegyi@28
|
23 |
|
alpar@62
|
24 |
int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
|
hegyi@28
|
25 |
{
|
hegyi@31
|
26 |
Graph::NodeMap<double> * actual_map;
|
hegyi@48
|
27 |
double min, max;
|
hegyi@96
|
28 |
min=(mytab.mapstorage).minOfNodeMap(mapname);
|
hegyi@96
|
29 |
max=(mytab.mapstorage).maxOfNodeMap(mapname);
|
hegyi@96
|
30 |
actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
|
hegyi@81
|
31 |
|
hegyi@81
|
32 |
if(node==INVALID)
|
hegyi@31
|
33 |
{
|
hegyi@96
|
34 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
35 |
{
|
hegyi@81
|
36 |
double v=fabs((*actual_map)[i]);
|
hegyi@81
|
37 |
int w;
|
hegyi@154
|
38 |
if(autoscale)
|
hegyi@81
|
39 |
{
|
hegyi@154
|
40 |
if(min==max)
|
hegyi@154
|
41 |
{
|
hegyi@154
|
42 |
w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@154
|
43 |
}
|
hegyi@154
|
44 |
else
|
hegyi@154
|
45 |
{
|
hegyi@157
|
46 |
w=(int)(minimum_node_radius+(v-min)/(max-min)*(radius_size-minimum_node_radius));
|
hegyi@154
|
47 |
}
|
hegyi@81
|
48 |
}
|
hegyi@81
|
49 |
else
|
hegyi@81
|
50 |
{
|
hegyi@157
|
51 |
w=(int)(v*radius_size);
|
hegyi@81
|
52 |
}
|
hegyi@155
|
53 |
|
hegyi@157
|
54 |
if(w<minimum_node_radius)
|
hegyi@155
|
55 |
{
|
hegyi@157
|
56 |
w=minimum_node_radius;
|
hegyi@155
|
57 |
}
|
hegyi@155
|
58 |
|
hegyi@156
|
59 |
if(zoomtrack)
|
hegyi@156
|
60 |
{
|
hegyi@156
|
61 |
double actual_ppu=get_pixels_per_unit();
|
hegyi@156
|
62 |
w=(int)(w/actual_ppu*fixed_zoom_factor);
|
hegyi@156
|
63 |
}
|
hegyi@156
|
64 |
|
hegyi@81
|
65 |
if(w>=0)
|
hegyi@81
|
66 |
{
|
hegyi@81
|
67 |
double x1, y1, x2, y2;
|
hegyi@81
|
68 |
x1=nodesmap[i]->property_x1().get_value();
|
hegyi@81
|
69 |
x2=nodesmap[i]->property_x2().get_value();
|
hegyi@81
|
70 |
y1=nodesmap[i]->property_y1().get_value();
|
hegyi@81
|
71 |
y2=nodesmap[i]->property_y2().get_value();
|
hegyi@81
|
72 |
nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@81
|
73 |
nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@81
|
74 |
nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@81
|
75 |
nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@81
|
76 |
}
|
hegyi@81
|
77 |
}
|
hegyi@31
|
78 |
}
|
hegyi@31
|
79 |
else
|
hegyi@31
|
80 |
{
|
hegyi@81
|
81 |
//I think only new nodes use this case
|
hegyi@154
|
82 |
//that has no own value, only the default one
|
hegyi@154
|
83 |
//int w=(int)(*actual_map)[node];
|
hegyi@81
|
84 |
int w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@81
|
85 |
if(w>=0)
|
hegyi@81
|
86 |
{
|
hegyi@81
|
87 |
double x1, y1, x2, y2;
|
hegyi@81
|
88 |
x1=nodesmap[node]->property_x1().get_value();
|
hegyi@81
|
89 |
x2=nodesmap[node]->property_x2().get_value();
|
hegyi@81
|
90 |
y1=nodesmap[node]->property_y1().get_value();
|
hegyi@81
|
91 |
y2=nodesmap[node]->property_y2().get_value();
|
hegyi@81
|
92 |
nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@81
|
93 |
nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@81
|
94 |
nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@81
|
95 |
nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@81
|
96 |
}
|
hegyi@31
|
97 |
}
|
hegyi@81
|
98 |
return 0;
|
hegyi@81
|
99 |
};
|
hegyi@31
|
100 |
|
hegyi@81
|
101 |
int GraphDisplayerCanvas::resetNodeRadius (Node node)
|
hegyi@81
|
102 |
{
|
hegyi@81
|
103 |
double min, max;
|
hegyi@81
|
104 |
min=node_property_defaults[N_RADIUS];
|
hegyi@81
|
105 |
max=node_property_defaults[N_RADIUS];
|
hegyi@96
|
106 |
Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
|
hegyi@81
|
107 |
|
hegyi@28
|
108 |
if(node==INVALID)
|
hegyi@28
|
109 |
{
|
hegyi@96
|
110 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
111 |
{
|
ladanyi@91
|
112 |
double v=fabs(actual_map[i]);
|
hegyi@48
|
113 |
int w;
|
hegyi@48
|
114 |
if(min==max)
|
hegyi@48
|
115 |
{
|
hegyi@48
|
116 |
w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@48
|
117 |
}
|
hegyi@48
|
118 |
else
|
hegyi@48
|
119 |
{
|
hegyi@48
|
120 |
w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
|
hegyi@48
|
121 |
}
|
hegyi@156
|
122 |
if(zoomtrack)
|
hegyi@156
|
123 |
{
|
hegyi@156
|
124 |
double actual_ppu=get_pixels_per_unit();
|
hegyi@156
|
125 |
w=(int)(w/actual_ppu*fixed_zoom_factor);
|
hegyi@156
|
126 |
}
|
hegyi@28
|
127 |
if(w>=0)
|
hegyi@28
|
128 |
{
|
hegyi@28
|
129 |
double x1, y1, x2, y2;
|
hegyi@31
|
130 |
x1=nodesmap[i]->property_x1().get_value();
|
hegyi@31
|
131 |
x2=nodesmap[i]->property_x2().get_value();
|
hegyi@31
|
132 |
y1=nodesmap[i]->property_y1().get_value();
|
hegyi@31
|
133 |
y2=nodesmap[i]->property_y2().get_value();
|
hegyi@28
|
134 |
nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@28
|
135 |
nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@28
|
136 |
nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@28
|
137 |
nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@28
|
138 |
}
|
hegyi@28
|
139 |
}
|
hegyi@28
|
140 |
}
|
hegyi@28
|
141 |
else
|
hegyi@28
|
142 |
{
|
hegyi@31
|
143 |
//I think only new nodes use this case
|
ladanyi@91
|
144 |
// int w=(int)actual_map[node];
|
hegyi@31
|
145 |
int w=(int)(node_property_defaults[N_RADIUS]);
|
hegyi@28
|
146 |
if(w>=0)
|
hegyi@28
|
147 |
{
|
hegyi@28
|
148 |
double x1, y1, x2, y2;
|
hegyi@31
|
149 |
x1=nodesmap[node]->property_x1().get_value();
|
hegyi@31
|
150 |
x2=nodesmap[node]->property_x2().get_value();
|
hegyi@31
|
151 |
y1=nodesmap[node]->property_y1().get_value();
|
hegyi@31
|
152 |
y2=nodesmap[node]->property_y2().get_value();
|
hegyi@28
|
153 |
nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
|
hegyi@28
|
154 |
nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
|
hegyi@28
|
155 |
nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
|
hegyi@28
|
156 |
nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
|
hegyi@28
|
157 |
}
|
hegyi@28
|
158 |
}
|
hegyi@28
|
159 |
return 0;
|
hegyi@28
|
160 |
};
|
hegyi@28
|
161 |
|
alpar@62
|
162 |
int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
|
hegyi@28
|
163 |
{
|
hegyi@28
|
164 |
|
hegyi@28
|
165 |
//function maps the range of the maximum and
|
hegyi@28
|
166 |
//the minimum of the nodemap to the range of
|
hegyi@28
|
167 |
//green in RGB
|
hegyi@28
|
168 |
|
hegyi@31
|
169 |
Graph::NodeMap<double> * actual_map;
|
hegyi@96
|
170 |
actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
|
hegyi@81
|
171 |
|
hegyi@81
|
172 |
double max, min;
|
hegyi@81
|
173 |
|
hegyi@96
|
174 |
max=(mytab.mapstorage).maxOfNodeMap(mapname);
|
hegyi@96
|
175 |
min=(mytab.mapstorage).minOfNodeMap(mapname);
|
hegyi@81
|
176 |
|
hegyi@81
|
177 |
if(node==INVALID)
|
hegyi@31
|
178 |
{
|
hegyi@81
|
179 |
|
hegyi@96
|
180 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
181 |
{
|
hegyi@81
|
182 |
Gdk::Color color;
|
hegyi@81
|
183 |
|
hegyi@81
|
184 |
double w=(*actual_map)[i];
|
hegyi@81
|
185 |
|
hegyi@81
|
186 |
if(max!=min)
|
hegyi@81
|
187 |
{
|
hegyi@179
|
188 |
color=rainbowColorCounter(min, max, w);
|
hegyi@81
|
189 |
}
|
hegyi@81
|
190 |
else
|
hegyi@81
|
191 |
{
|
hegyi@179
|
192 |
color.set_rgb_p (0, 0, 1);
|
hegyi@81
|
193 |
}
|
hegyi@81
|
194 |
|
hegyi@81
|
195 |
nodesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@81
|
196 |
}
|
hegyi@31
|
197 |
}
|
hegyi@31
|
198 |
else
|
hegyi@31
|
199 |
{
|
hegyi@81
|
200 |
Gdk::Color color;
|
hegyi@81
|
201 |
|
hegyi@81
|
202 |
double w=(*actual_map)[node];
|
hegyi@81
|
203 |
|
hegyi@81
|
204 |
if(max!=min)
|
hegyi@81
|
205 |
{
|
hegyi@179
|
206 |
color=rainbowColorCounter(min, max, w);
|
hegyi@81
|
207 |
}
|
hegyi@81
|
208 |
else
|
hegyi@81
|
209 |
{
|
hegyi@179
|
210 |
color.set_rgb_p (0, 0, 1);
|
hegyi@81
|
211 |
}
|
hegyi@81
|
212 |
|
hegyi@81
|
213 |
nodesmap[node]->property_fill_color_gdk().set_value(color);
|
hegyi@31
|
214 |
}
|
hegyi@81
|
215 |
return 0;
|
hegyi@81
|
216 |
};
|
hegyi@81
|
217 |
|
hegyi@81
|
218 |
int GraphDisplayerCanvas::resetNodeColor (Node node)
|
hegyi@81
|
219 |
{
|
hegyi@81
|
220 |
|
hegyi@81
|
221 |
//function maps the range of the maximum and
|
hegyi@81
|
222 |
//the minimum of the nodemap to the range of
|
hegyi@81
|
223 |
//green in RGB
|
hegyi@81
|
224 |
|
hegyi@96
|
225 |
Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
|
hegyi@31
|
226 |
|
hegyi@31
|
227 |
double max, min;
|
hegyi@31
|
228 |
|
hegyi@81
|
229 |
max=node_property_defaults[N_COLOR];
|
hegyi@81
|
230 |
min=node_property_defaults[N_COLOR];
|
hegyi@31
|
231 |
|
hegyi@28
|
232 |
if(node==INVALID)
|
hegyi@28
|
233 |
{
|
hegyi@28
|
234 |
|
hegyi@96
|
235 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
236 |
{
|
hegyi@28
|
237 |
Gdk::Color color;
|
hegyi@31
|
238 |
|
ladanyi@91
|
239 |
double w=actual_map[i];
|
hegyi@31
|
240 |
|
hegyi@28
|
241 |
if(max!=min)
|
hegyi@28
|
242 |
{
|
hegyi@28
|
243 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@28
|
244 |
}
|
hegyi@28
|
245 |
else
|
hegyi@28
|
246 |
{
|
hegyi@28
|
247 |
color.set_rgb_p (0, 0, 100);
|
hegyi@28
|
248 |
}
|
hegyi@28
|
249 |
|
hegyi@28
|
250 |
nodesmap[i]->property_fill_color_gdk().set_value(color);
|
hegyi@28
|
251 |
}
|
hegyi@28
|
252 |
}
|
hegyi@28
|
253 |
else
|
hegyi@28
|
254 |
{
|
hegyi@28
|
255 |
Gdk::Color color;
|
hegyi@31
|
256 |
|
ladanyi@91
|
257 |
double w=actual_map[node];
|
hegyi@31
|
258 |
|
hegyi@28
|
259 |
if(max!=min)
|
hegyi@28
|
260 |
{
|
hegyi@28
|
261 |
color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
|
hegyi@28
|
262 |
}
|
hegyi@28
|
263 |
else
|
hegyi@28
|
264 |
{
|
hegyi@28
|
265 |
color.set_rgb_p (0, 0, 100);
|
hegyi@28
|
266 |
}
|
hegyi@28
|
267 |
|
hegyi@28
|
268 |
nodesmap[node]->property_fill_color_gdk().set_value(color);
|
hegyi@28
|
269 |
}
|
hegyi@28
|
270 |
return 0;
|
hegyi@28
|
271 |
};
|
hegyi@28
|
272 |
|
alpar@62
|
273 |
int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
|
hegyi@28
|
274 |
{
|
hegyi@28
|
275 |
|
hegyi@28
|
276 |
//the number in the map will be written on the node
|
hegyi@28
|
277 |
//EXCEPT when the name of the map is Text, because
|
hegyi@28
|
278 |
//in that case empty string will be written, because
|
hegyi@28
|
279 |
//that is the deleter map
|
hegyi@31
|
280 |
|
hegyi@36
|
281 |
Graph::NodeMap<double> * actual_map=NULL;
|
hegyi@96
|
282 |
actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
|
hegyi@28
|
283 |
|
hegyi@28
|
284 |
if(node==INVALID)
|
hegyi@28
|
285 |
{
|
hegyi@96
|
286 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
287 |
{
|
hegyi@81
|
288 |
nodemap_to_edit=mapname;
|
hegyi@81
|
289 |
double number=(*actual_map)[i];
|
hegyi@45
|
290 |
|
hegyi@81
|
291 |
std::ostringstream ostr;
|
hegyi@81
|
292 |
ostr << number;
|
hegyi@45
|
293 |
|
hegyi@81
|
294 |
nodetextmap[i]->property_text().set_value(ostr.str());
|
hegyi@28
|
295 |
}
|
hegyi@28
|
296 |
}
|
hegyi@28
|
297 |
else
|
hegyi@28
|
298 |
{
|
hegyi@81
|
299 |
double number=(*actual_map)[node];
|
hegyi@45
|
300 |
|
hegyi@81
|
301 |
std::ostringstream ostr;
|
hegyi@81
|
302 |
ostr << number;
|
hegyi@45
|
303 |
|
hegyi@81
|
304 |
nodetextmap[node]->property_text().set_value(ostr.str());
|
hegyi@28
|
305 |
}
|
hegyi@28
|
306 |
return 0;
|
hegyi@28
|
307 |
};
|
hegyi@81
|
308 |
|
hegyi@81
|
309 |
int GraphDisplayerCanvas::resetNodeText (Node node)
|
hegyi@81
|
310 |
{
|
hegyi@81
|
311 |
|
hegyi@81
|
312 |
//the number in the map will be written on the node
|
hegyi@81
|
313 |
//EXCEPT when the name of the map is Text, because
|
hegyi@81
|
314 |
//in that case empty string will be written, because
|
hegyi@81
|
315 |
//that is the deleter map
|
hegyi@81
|
316 |
|
hegyi@81
|
317 |
if(node==INVALID)
|
hegyi@81
|
318 |
{
|
hegyi@96
|
319 |
for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
320 |
{
|
hegyi@81
|
321 |
nodemap_to_edit="";
|
hegyi@81
|
322 |
nodetextmap[i]->property_text().set_value("");
|
hegyi@81
|
323 |
}
|
hegyi@81
|
324 |
}
|
hegyi@81
|
325 |
else
|
hegyi@81
|
326 |
{
|
hegyi@81
|
327 |
nodetextmap[node]->property_text().set_value("");
|
hegyi@81
|
328 |
}
|
hegyi@81
|
329 |
return 0;
|
hegyi@81
|
330 |
};
|