hegyi@1
|
1 |
/* -*- C++ -*-
|
hegyi@1
|
2 |
*
|
hegyi@1
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
hegyi@1
|
4 |
*
|
hegyi@1
|
5 |
* Copyright (C) 2003-2006
|
hegyi@1
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
hegyi@1
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
hegyi@1
|
8 |
*
|
hegyi@1
|
9 |
* Permission to use, modify and distribute this software is granted
|
hegyi@1
|
10 |
* provided that this copyright notice appears in all copies. For
|
hegyi@1
|
11 |
* precise terms see the accompanying LICENSE file.
|
hegyi@1
|
12 |
*
|
hegyi@1
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
hegyi@1
|
14 |
* express or implied, and with no claim as to its suitability for any
|
hegyi@1
|
15 |
* purpose.
|
hegyi@1
|
16 |
*
|
hegyi@1
|
17 |
*/
|
hegyi@1
|
18 |
|
hegyi@1
|
19 |
#include <graph_displayer_canvas.h>
|
hegyi@1
|
20 |
#include <mapstorage.h>
|
hegyi@1
|
21 |
#include <nbtab.h>
|
hegyi@1
|
22 |
#include <cmath>
|
hegyi@1
|
23 |
|
hegyi@1
|
24 |
const int minimum_arc_width=0;
|
hegyi@1
|
25 |
|
hegyi@1
|
26 |
int DigraphDisplayerCanvas::resetArcWidth (Arc arc)
|
hegyi@1
|
27 |
{
|
hegyi@1
|
28 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
29 |
double min, max;
|
hegyi@1
|
30 |
|
hegyi@1
|
31 |
min=arc_property_defaults[E_WIDTH];
|
hegyi@1
|
32 |
max=arc_property_defaults[E_WIDTH];
|
hegyi@1
|
33 |
Digraph::ArcMap<double> actual_map(ms.digraph,arc_property_defaults[E_WIDTH]);
|
hegyi@1
|
34 |
|
hegyi@1
|
35 |
if(arc==INVALID)
|
hegyi@1
|
36 |
{
|
hegyi@1
|
37 |
for (ArcIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
38 |
{
|
hegyi@1
|
39 |
double v=fabs(actual_map[i]);
|
hegyi@1
|
40 |
int w;
|
hegyi@1
|
41 |
if(min==max)
|
hegyi@1
|
42 |
{
|
hegyi@1
|
43 |
w=(int)(arc_property_defaults[E_WIDTH]);
|
hegyi@1
|
44 |
}
|
hegyi@1
|
45 |
else
|
hegyi@1
|
46 |
{
|
hegyi@1
|
47 |
w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
|
hegyi@1
|
48 |
}
|
hegyi@1
|
49 |
if(zoomtrack)
|
hegyi@1
|
50 |
{
|
hegyi@1
|
51 |
double actual_ppu=get_pixels_per_unit();
|
hegyi@1
|
52 |
w=(int)(w/actual_ppu*fixed_zoom_factor);
|
hegyi@1
|
53 |
}
|
hegyi@1
|
54 |
arcsmap[i]->setLineWidth(w);
|
hegyi@1
|
55 |
}
|
hegyi@1
|
56 |
}
|
hegyi@1
|
57 |
else
|
hegyi@1
|
58 |
{
|
hegyi@1
|
59 |
int w=(int)actual_map[arc];
|
hegyi@1
|
60 |
if(w>=0)
|
hegyi@1
|
61 |
{
|
hegyi@1
|
62 |
arcsmap[arc]->setLineWidth(w);
|
hegyi@1
|
63 |
}
|
hegyi@1
|
64 |
}
|
hegyi@1
|
65 |
return 0;
|
hegyi@1
|
66 |
}
|
hegyi@1
|
67 |
|
hegyi@1
|
68 |
|
hegyi@1
|
69 |
int DigraphDisplayerCanvas::changeArcWidth (std::string mapname, Arc arc)
|
hegyi@1
|
70 |
{
|
hegyi@1
|
71 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
72 |
double min, max;
|
hegyi@1
|
73 |
|
hegyi@1
|
74 |
{
|
hegyi@1
|
75 |
ArcIt e(ms.digraph);
|
hegyi@1
|
76 |
min = max = ms.get(mapname, e);
|
hegyi@1
|
77 |
for (; e != INVALID; ++e)
|
hegyi@1
|
78 |
{
|
hegyi@1
|
79 |
if (static_cast<double>(ms.get(mapname, e)) > max)
|
hegyi@1
|
80 |
max = ms.get(mapname, e);
|
hegyi@1
|
81 |
if (static_cast<double>(ms.get(mapname, e)) < min)
|
hegyi@1
|
82 |
min = ms.get(mapname, e);
|
hegyi@1
|
83 |
}
|
hegyi@1
|
84 |
}
|
hegyi@1
|
85 |
|
hegyi@1
|
86 |
if(arc==INVALID)
|
hegyi@1
|
87 |
{
|
hegyi@1
|
88 |
for (ArcIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
89 |
{
|
hegyi@1
|
90 |
double v=ms.get(mapname, i);
|
hegyi@1
|
91 |
int w;
|
hegyi@1
|
92 |
if(autoscale)
|
hegyi@1
|
93 |
{
|
hegyi@1
|
94 |
if(min==max)
|
hegyi@1
|
95 |
{
|
hegyi@1
|
96 |
w=(int)(arc_property_defaults[E_WIDTH]);
|
hegyi@1
|
97 |
}
|
hegyi@1
|
98 |
else
|
hegyi@1
|
99 |
{
|
hegyi@1
|
100 |
w=(int)(minimum_arc_width+(v-min)/(max-min)*(arc_width-minimum_arc_width));
|
hegyi@1
|
101 |
}
|
hegyi@1
|
102 |
}
|
hegyi@1
|
103 |
else
|
hegyi@1
|
104 |
{
|
hegyi@1
|
105 |
w=(int)(v*arc_width);
|
hegyi@1
|
106 |
}
|
hegyi@1
|
107 |
if(w<0)
|
hegyi@1
|
108 |
{
|
hegyi@1
|
109 |
arcsmap[i]->hide();
|
hegyi@1
|
110 |
}
|
hegyi@1
|
111 |
else
|
hegyi@1
|
112 |
{
|
hegyi@1
|
113 |
arcsmap[i]->show();
|
hegyi@1
|
114 |
if(w<minimum_arc_width)
|
hegyi@1
|
115 |
{
|
hegyi@1
|
116 |
w=minimum_arc_width;
|
hegyi@1
|
117 |
}
|
hegyi@1
|
118 |
if(zoomtrack)
|
hegyi@1
|
119 |
{
|
hegyi@1
|
120 |
double actual_ppu=get_pixels_per_unit();
|
hegyi@1
|
121 |
w=(int)(w/actual_ppu*fixed_zoom_factor);
|
hegyi@1
|
122 |
}
|
hegyi@1
|
123 |
arcsmap[i]->setLineWidth(w);
|
hegyi@1
|
124 |
}
|
hegyi@1
|
125 |
}
|
hegyi@1
|
126 |
}
|
hegyi@1
|
127 |
else
|
hegyi@1
|
128 |
{
|
hegyi@1
|
129 |
int w=(int)ms.get(mapname, arc);
|
hegyi@1
|
130 |
if(w>=0)
|
hegyi@1
|
131 |
{
|
hegyi@1
|
132 |
arcsmap[arc]->setLineWidth(w);
|
hegyi@1
|
133 |
}
|
hegyi@1
|
134 |
}
|
hegyi@1
|
135 |
return 0;
|
hegyi@1
|
136 |
};
|
hegyi@1
|
137 |
|
hegyi@1
|
138 |
int DigraphDisplayerCanvas::changeArcColor (std::string mapname, Arc arc)
|
hegyi@1
|
139 |
{
|
hegyi@1
|
140 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
141 |
|
hegyi@1
|
142 |
//function maps the range of the maximum and
|
hegyi@1
|
143 |
//the minimum of the nodemap to the range of
|
hegyi@1
|
144 |
//green in RGB
|
hegyi@1
|
145 |
|
hegyi@1
|
146 |
double max, min;
|
hegyi@1
|
147 |
|
hegyi@1
|
148 |
{
|
hegyi@1
|
149 |
ArcIt e(ms.digraph);
|
hegyi@1
|
150 |
min = max = ms.get(mapname, e);
|
hegyi@1
|
151 |
for (; e != INVALID; ++e)
|
hegyi@1
|
152 |
{
|
hegyi@1
|
153 |
if (static_cast<double>(ms.get(mapname, e)) > max)
|
hegyi@1
|
154 |
max = ms.get(mapname, e);
|
hegyi@1
|
155 |
if (static_cast<double>(ms.get(mapname, e)) < min)
|
hegyi@1
|
156 |
min = ms.get(mapname, e);
|
hegyi@1
|
157 |
}
|
hegyi@1
|
158 |
}
|
hegyi@1
|
159 |
|
hegyi@1
|
160 |
if(arc==INVALID)
|
hegyi@1
|
161 |
{
|
hegyi@1
|
162 |
for (ArcIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
163 |
{
|
hegyi@1
|
164 |
double w=ms.get(mapname, i);
|
hegyi@1
|
165 |
|
hegyi@1
|
166 |
Gdk::Color color;
|
hegyi@1
|
167 |
if(max!=min)
|
hegyi@1
|
168 |
{
|
hegyi@1
|
169 |
color=rainbowColorCounter(min, max, w);
|
hegyi@1
|
170 |
}
|
hegyi@1
|
171 |
else
|
hegyi@1
|
172 |
{
|
hegyi@1
|
173 |
color.set_rgb_p (0, 1, 0);
|
hegyi@1
|
174 |
}
|
hegyi@1
|
175 |
arcsmap[i]->setFillColor(color);
|
hegyi@1
|
176 |
}
|
hegyi@1
|
177 |
}
|
hegyi@1
|
178 |
else
|
hegyi@1
|
179 |
{
|
hegyi@1
|
180 |
Gdk::Color color;
|
hegyi@1
|
181 |
|
hegyi@1
|
182 |
double w=ms.get(mapname, arc);
|
hegyi@1
|
183 |
|
hegyi@1
|
184 |
if(max!=min)
|
hegyi@1
|
185 |
{
|
hegyi@1
|
186 |
color=rainbowColorCounter(min, max, w);
|
hegyi@1
|
187 |
}
|
hegyi@1
|
188 |
else
|
hegyi@1
|
189 |
{
|
hegyi@1
|
190 |
color.set_rgb_p (0, 1, 0);
|
hegyi@1
|
191 |
}
|
hegyi@1
|
192 |
|
hegyi@1
|
193 |
arcsmap[arc]->setFillColor(color);
|
hegyi@1
|
194 |
}
|
hegyi@1
|
195 |
return 0;
|
hegyi@1
|
196 |
};
|
hegyi@1
|
197 |
|
hegyi@1
|
198 |
int DigraphDisplayerCanvas::resetArcColor (Arc arc)
|
hegyi@1
|
199 |
{
|
hegyi@1
|
200 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
201 |
|
hegyi@1
|
202 |
//function maps the range of the maximum and
|
hegyi@1
|
203 |
//the minimum of the nodemap to the range of
|
hegyi@1
|
204 |
//green in RGB
|
hegyi@1
|
205 |
Digraph::ArcMap<double> actual_map(ms.digraph,arc_property_defaults[E_COLOR]);
|
hegyi@1
|
206 |
|
hegyi@1
|
207 |
double max, min;
|
hegyi@1
|
208 |
|
hegyi@1
|
209 |
max=arc_property_defaults[E_COLOR];
|
hegyi@1
|
210 |
min=arc_property_defaults[E_COLOR];
|
hegyi@1
|
211 |
|
hegyi@1
|
212 |
if(arc==INVALID)
|
hegyi@1
|
213 |
{
|
hegyi@1
|
214 |
for (ArcIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
215 |
{
|
hegyi@1
|
216 |
double w=actual_map[i];
|
hegyi@1
|
217 |
|
hegyi@1
|
218 |
Gdk::Color color;
|
hegyi@1
|
219 |
if(max!=min)
|
hegyi@1
|
220 |
{
|
hegyi@1
|
221 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1
|
222 |
}
|
hegyi@1
|
223 |
else
|
hegyi@1
|
224 |
{
|
hegyi@1
|
225 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1
|
226 |
}
|
hegyi@1
|
227 |
arcsmap[i]->setFillColor(color);
|
hegyi@1
|
228 |
}
|
hegyi@1
|
229 |
}
|
hegyi@1
|
230 |
else
|
hegyi@1
|
231 |
{
|
hegyi@1
|
232 |
Gdk::Color color;
|
hegyi@1
|
233 |
|
hegyi@1
|
234 |
double w=actual_map[arc];
|
hegyi@1
|
235 |
|
hegyi@1
|
236 |
if(max!=min)
|
hegyi@1
|
237 |
{
|
hegyi@1
|
238 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@1
|
239 |
}
|
hegyi@1
|
240 |
else
|
hegyi@1
|
241 |
{
|
hegyi@1
|
242 |
color.set_rgb_p (0, 100, 0);
|
hegyi@1
|
243 |
}
|
hegyi@1
|
244 |
|
hegyi@1
|
245 |
arcsmap[arc]->setFillColor(color);
|
hegyi@1
|
246 |
}
|
hegyi@1
|
247 |
return 0;
|
hegyi@1
|
248 |
};
|
hegyi@1
|
249 |
|
hegyi@1
|
250 |
int DigraphDisplayerCanvas::changeArcText (std::string mapname, Arc arc)
|
hegyi@1
|
251 |
{
|
hegyi@1
|
252 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
253 |
|
hegyi@1
|
254 |
//the number in the map will be written on the arc
|
hegyi@1
|
255 |
//EXCEPT when the name of the map is Default, because
|
hegyi@1
|
256 |
//in that case empty string will be written, because
|
hegyi@1
|
257 |
//that is the deleter map
|
hegyi@1
|
258 |
|
hegyi@1
|
259 |
if(arc==INVALID)
|
hegyi@1
|
260 |
{
|
hegyi@1
|
261 |
for (ArcIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
262 |
{
|
hegyi@1
|
263 |
arcmap_to_edit=mapname;
|
hegyi@1
|
264 |
|
hegyi@1
|
265 |
arctextmap[i]->property_text().set_value(
|
hegyi@1
|
266 |
static_cast<std::string>(ms.get(mapname, i)));
|
hegyi@1
|
267 |
}
|
hegyi@1
|
268 |
|
hegyi@1
|
269 |
}
|
hegyi@1
|
270 |
else
|
hegyi@1
|
271 |
{
|
hegyi@1
|
272 |
arctextmap[arc]->property_text().set_value(
|
hegyi@1
|
273 |
static_cast<std::string>(ms.get(mapname, arc)));
|
hegyi@1
|
274 |
}
|
hegyi@1
|
275 |
|
hegyi@1
|
276 |
return 0;
|
hegyi@1
|
277 |
};
|
hegyi@1
|
278 |
|
hegyi@1
|
279 |
int DigraphDisplayerCanvas::resetArcText (Arc arc)
|
hegyi@1
|
280 |
{
|
hegyi@1
|
281 |
MapStorage& ms = *mytab.mapstorage;
|
hegyi@1
|
282 |
|
hegyi@1
|
283 |
//the number in the map will be written on the arc
|
hegyi@1
|
284 |
//EXCEPT when the name of the map is Default, because
|
hegyi@1
|
285 |
//in that case empty string will be written, because
|
hegyi@1
|
286 |
//that is the deleter map
|
hegyi@1
|
287 |
|
hegyi@1
|
288 |
if(arc==INVALID)
|
hegyi@1
|
289 |
{
|
hegyi@1
|
290 |
for (ArcIt i(ms.digraph); i!=INVALID; ++i)
|
hegyi@1
|
291 |
{
|
hegyi@1
|
292 |
arcmap_to_edit="";
|
hegyi@1
|
293 |
arctextmap[i]->property_text().set_value("");
|
hegyi@1
|
294 |
}
|
hegyi@1
|
295 |
}
|
hegyi@1
|
296 |
else
|
hegyi@1
|
297 |
{
|
hegyi@1
|
298 |
arctextmap[arc]->property_text().set_value("");
|
hegyi@1
|
299 |
}
|
hegyi@1
|
300 |
|
hegyi@1
|
301 |
return 0;
|
hegyi@1
|
302 |
};
|