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@27
|
21 |
|
hegyi@167
|
22 |
const int minimum_edge_width=0;
|
hegyi@27
|
23 |
|
hegyi@81
|
24 |
int GraphDisplayerCanvas::resetEdgeWidth (Edge edge)
|
hegyi@81
|
25 |
{
|
hegyi@81
|
26 |
double min, max;
|
hegyi@81
|
27 |
|
hegyi@81
|
28 |
min=edge_property_defaults[E_WIDTH];
|
hegyi@81
|
29 |
max=edge_property_defaults[E_WIDTH];
|
hegyi@96
|
30 |
Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_WIDTH]);
|
hegyi@81
|
31 |
|
hegyi@81
|
32 |
if(edge==INVALID)
|
hegyi@81
|
33 |
{
|
hegyi@96
|
34 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
35 |
{
|
ladanyi@91
|
36 |
double v=fabs(actual_map[i]);
|
hegyi@81
|
37 |
int w;
|
hegyi@81
|
38 |
if(min==max)
|
hegyi@81
|
39 |
{
|
hegyi@81
|
40 |
w=(int)(edge_property_defaults[E_WIDTH]);
|
hegyi@81
|
41 |
}
|
hegyi@81
|
42 |
else
|
hegyi@81
|
43 |
{
|
hegyi@81
|
44 |
w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
|
hegyi@81
|
45 |
}
|
hegyi@157
|
46 |
if(zoomtrack)
|
hegyi@157
|
47 |
{
|
hegyi@157
|
48 |
double actual_ppu=get_pixels_per_unit();
|
hegyi@157
|
49 |
w=(int)(w/actual_ppu*fixed_zoom_factor);
|
hegyi@157
|
50 |
}
|
ladanyi@147
|
51 |
edgesmap[i]->setLineWidth(w);
|
hegyi@81
|
52 |
}
|
hegyi@81
|
53 |
}
|
hegyi@81
|
54 |
else
|
hegyi@81
|
55 |
{
|
ladanyi@91
|
56 |
int w=(int)actual_map[edge];
|
hegyi@81
|
57 |
if(w>=0)
|
hegyi@81
|
58 |
{
|
ladanyi@147
|
59 |
edgesmap[edge]->setLineWidth(w);
|
hegyi@81
|
60 |
}
|
hegyi@81
|
61 |
}
|
hegyi@81
|
62 |
return 0;
|
hegyi@81
|
63 |
}
|
hegyi@81
|
64 |
|
hegyi@81
|
65 |
|
alpar@62
|
66 |
int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
|
hegyi@27
|
67 |
{
|
hegyi@31
|
68 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@48
|
69 |
double min, max;
|
hegyi@48
|
70 |
|
hegyi@96
|
71 |
min=(mytab.mapstorage).minOfEdgeMap(mapname);
|
hegyi@96
|
72 |
max=(mytab.mapstorage).maxOfEdgeMap(mapname);
|
hegyi@96
|
73 |
actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
|
hegyi@31
|
74 |
|
hegyi@28
|
75 |
if(edge==INVALID)
|
hegyi@27
|
76 |
{
|
hegyi@96
|
77 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
78 |
{
|
hegyi@178
|
79 |
double v=(*actual_map)[i];
|
hegyi@48
|
80 |
int w;
|
hegyi@157
|
81 |
if(autoscale)
|
hegyi@28
|
82 |
{
|
hegyi@157
|
83 |
if(min==max)
|
hegyi@157
|
84 |
{
|
hegyi@157
|
85 |
w=(int)(edge_property_defaults[E_WIDTH]);
|
hegyi@157
|
86 |
}
|
hegyi@157
|
87 |
else
|
hegyi@157
|
88 |
{
|
hegyi@157
|
89 |
w=(int)(minimum_edge_width+(v-min)/(max-min)*(edge_width-minimum_edge_width));
|
hegyi@157
|
90 |
}
|
hegyi@28
|
91 |
}
|
hegyi@48
|
92 |
else
|
hegyi@48
|
93 |
{
|
hegyi@157
|
94 |
w=(int)(v*edge_width);
|
hegyi@157
|
95 |
}
|
hegyi@178
|
96 |
if(w<0)
|
hegyi@157
|
97 |
{
|
hegyi@178
|
98 |
edgesmap[i]->hide();
|
hegyi@157
|
99 |
}
|
hegyi@178
|
100 |
else
|
hegyi@157
|
101 |
{
|
hegyi@178
|
102 |
edgesmap[i]->show();
|
hegyi@178
|
103 |
if(w<minimum_edge_width)
|
hegyi@178
|
104 |
{
|
hegyi@178
|
105 |
w=minimum_edge_width;
|
hegyi@178
|
106 |
}
|
hegyi@178
|
107 |
if(zoomtrack)
|
hegyi@178
|
108 |
{
|
hegyi@178
|
109 |
double actual_ppu=get_pixels_per_unit();
|
hegyi@178
|
110 |
w=(int)(w/actual_ppu*fixed_zoom_factor);
|
hegyi@178
|
111 |
}
|
hegyi@178
|
112 |
edgesmap[i]->setLineWidth(w);
|
hegyi@48
|
113 |
}
|
hegyi@28
|
114 |
}
|
hegyi@28
|
115 |
}
|
hegyi@28
|
116 |
else
|
hegyi@28
|
117 |
{
|
hegyi@31
|
118 |
int w=(int)(*actual_map)[edge];
|
hegyi@27
|
119 |
if(w>=0)
|
hegyi@27
|
120 |
{
|
ladanyi@147
|
121 |
edgesmap[edge]->setLineWidth(w);
|
hegyi@27
|
122 |
}
|
hegyi@27
|
123 |
}
|
hegyi@27
|
124 |
return 0;
|
hegyi@27
|
125 |
};
|
hegyi@27
|
126 |
|
alpar@62
|
127 |
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
|
hegyi@27
|
128 |
{
|
hegyi@27
|
129 |
|
hegyi@27
|
130 |
//function maps the range of the maximum and
|
hegyi@27
|
131 |
//the minimum of the nodemap to the range of
|
hegyi@27
|
132 |
//green in RGB
|
hegyi@31
|
133 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@96
|
134 |
actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
|
hegyi@81
|
135 |
|
hegyi@81
|
136 |
double max, min;
|
hegyi@81
|
137 |
|
hegyi@96
|
138 |
max=(mytab.mapstorage).maxOfEdgeMap(mapname);
|
hegyi@96
|
139 |
min=(mytab.mapstorage).minOfEdgeMap(mapname);
|
hegyi@81
|
140 |
|
hegyi@81
|
141 |
if(edge==INVALID)
|
hegyi@31
|
142 |
{
|
hegyi@96
|
143 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
144 |
{
|
hegyi@81
|
145 |
double w=(*actual_map)[i];
|
hegyi@81
|
146 |
|
hegyi@81
|
147 |
Gdk::Color color;
|
hegyi@81
|
148 |
if(max!=min)
|
hegyi@81
|
149 |
{
|
hegyi@179
|
150 |
color=rainbowColorCounter(min, max, w);
|
hegyi@81
|
151 |
}
|
hegyi@81
|
152 |
else
|
hegyi@81
|
153 |
{
|
hegyi@179
|
154 |
color.set_rgb_p (0, 1, 0);
|
hegyi@81
|
155 |
}
|
ladanyi@147
|
156 |
edgesmap[i]->setFillColor(color);
|
hegyi@81
|
157 |
}
|
hegyi@31
|
158 |
}
|
hegyi@31
|
159 |
else
|
hegyi@31
|
160 |
{
|
hegyi@81
|
161 |
Gdk::Color color;
|
hegyi@81
|
162 |
|
hegyi@81
|
163 |
double w=(*actual_map)[edge];
|
hegyi@81
|
164 |
|
hegyi@81
|
165 |
if(max!=min)
|
hegyi@81
|
166 |
{
|
hegyi@179
|
167 |
color=rainbowColorCounter(min, max, w);
|
hegyi@81
|
168 |
}
|
hegyi@81
|
169 |
else
|
hegyi@81
|
170 |
{
|
hegyi@179
|
171 |
color.set_rgb_p (0, 1, 0);
|
hegyi@81
|
172 |
}
|
hegyi@81
|
173 |
|
ladanyi@147
|
174 |
edgesmap[edge]->setFillColor(color);
|
hegyi@31
|
175 |
}
|
hegyi@81
|
176 |
return 0;
|
hegyi@81
|
177 |
};
|
hegyi@81
|
178 |
|
hegyi@81
|
179 |
int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
|
hegyi@81
|
180 |
{
|
hegyi@81
|
181 |
|
hegyi@81
|
182 |
//function maps the range of the maximum and
|
hegyi@81
|
183 |
//the minimum of the nodemap to the range of
|
hegyi@81
|
184 |
//green in RGB
|
hegyi@96
|
185 |
Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]);
|
hegyi@31
|
186 |
|
hegyi@31
|
187 |
double max, min;
|
hegyi@31
|
188 |
|
hegyi@81
|
189 |
max=edge_property_defaults[E_COLOR];
|
hegyi@81
|
190 |
min=edge_property_defaults[E_COLOR];
|
hegyi@31
|
191 |
|
hegyi@28
|
192 |
if(edge==INVALID)
|
hegyi@28
|
193 |
{
|
hegyi@96
|
194 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
195 |
{
|
ladanyi@91
|
196 |
double w=actual_map[i];
|
hegyi@31
|
197 |
|
hegyi@28
|
198 |
Gdk::Color color;
|
hegyi@28
|
199 |
if(max!=min)
|
hegyi@28
|
200 |
{
|
hegyi@28
|
201 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@28
|
202 |
}
|
hegyi@28
|
203 |
else
|
hegyi@28
|
204 |
{
|
hegyi@28
|
205 |
color.set_rgb_p (0, 100, 0);
|
hegyi@28
|
206 |
}
|
ladanyi@147
|
207 |
edgesmap[i]->setFillColor(color);
|
hegyi@28
|
208 |
}
|
hegyi@28
|
209 |
}
|
hegyi@28
|
210 |
else
|
hegyi@27
|
211 |
{
|
hegyi@28
|
212 |
Gdk::Color color;
|
hegyi@31
|
213 |
|
ladanyi@91
|
214 |
double w=actual_map[edge];
|
hegyi@31
|
215 |
|
hegyi@28
|
216 |
if(max!=min)
|
hegyi@28
|
217 |
{
|
hegyi@28
|
218 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@28
|
219 |
}
|
hegyi@28
|
220 |
else
|
hegyi@28
|
221 |
{
|
hegyi@28
|
222 |
color.set_rgb_p (0, 100, 0);
|
hegyi@28
|
223 |
}
|
hegyi@28
|
224 |
|
ladanyi@147
|
225 |
edgesmap[edge]->setFillColor(color);
|
hegyi@27
|
226 |
}
|
hegyi@27
|
227 |
return 0;
|
hegyi@27
|
228 |
};
|
hegyi@27
|
229 |
|
alpar@62
|
230 |
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
|
hegyi@27
|
231 |
{
|
hegyi@27
|
232 |
//the number in the map will be written on the edge
|
hegyi@40
|
233 |
//EXCEPT when the name of the map is Default, because
|
hegyi@27
|
234 |
//in that case empty string will be written, because
|
hegyi@27
|
235 |
//that is the deleter map
|
ladanyi@63
|
236 |
|
hegyi@28
|
237 |
if(edge==INVALID)
|
hegyi@27
|
238 |
{
|
hegyi@96
|
239 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@27
|
240 |
{
|
hegyi@81
|
241 |
edgemap_to_edit=mapname;
|
hegyi@96
|
242 |
double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i];
|
hegyi@81
|
243 |
|
hegyi@81
|
244 |
std::ostringstream ostr;
|
hegyi@81
|
245 |
ostr << number;
|
hegyi@81
|
246 |
|
hegyi@81
|
247 |
edgetextmap[i]->property_text().set_value(ostr.str());
|
hegyi@28
|
248 |
}
|
hegyi@28
|
249 |
|
hegyi@28
|
250 |
}
|
hegyi@28
|
251 |
else
|
hegyi@28
|
252 |
{
|
hegyi@96
|
253 |
double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge];
|
hegyi@45
|
254 |
|
hegyi@45
|
255 |
std::ostringstream ostr;
|
hegyi@45
|
256 |
ostr << number;
|
hegyi@45
|
257 |
|
hegyi@45
|
258 |
edgetextmap[edge]->property_text().set_value(ostr.str());
|
hegyi@27
|
259 |
}
|
hegyi@28
|
260 |
|
hegyi@27
|
261 |
return 0;
|
hegyi@28
|
262 |
|
hegyi@27
|
263 |
};
|
hegyi@81
|
264 |
|
hegyi@81
|
265 |
int GraphDisplayerCanvas::resetEdgeText (Edge edge)
|
hegyi@81
|
266 |
{
|
hegyi@81
|
267 |
//the number in the map will be written on the edge
|
hegyi@81
|
268 |
//EXCEPT when the name of the map is Default, because
|
hegyi@81
|
269 |
//in that case empty string will be written, because
|
hegyi@81
|
270 |
//that is the deleter map
|
hegyi@81
|
271 |
|
hegyi@81
|
272 |
if(edge==INVALID)
|
hegyi@81
|
273 |
{
|
hegyi@96
|
274 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
275 |
{
|
hegyi@81
|
276 |
edgemap_to_edit="";
|
hegyi@81
|
277 |
edgetextmap[i]->property_text().set_value("");
|
hegyi@81
|
278 |
}
|
hegyi@81
|
279 |
|
hegyi@81
|
280 |
}
|
hegyi@81
|
281 |
else
|
hegyi@81
|
282 |
{
|
hegyi@81
|
283 |
edgetextmap[edge]->property_text().set_value("");
|
hegyi@81
|
284 |
}
|
hegyi@81
|
285 |
|
hegyi@81
|
286 |
return 0;
|
hegyi@81
|
287 |
|
hegyi@81
|
288 |
};
|