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@55
|
79 |
double v=fabs((*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@157
|
96 |
if(w<minimum_edge_width)
|
hegyi@157
|
97 |
{
|
hegyi@157
|
98 |
w=minimum_edge_width;
|
hegyi@157
|
99 |
}
|
hegyi@157
|
100 |
if(zoomtrack)
|
hegyi@157
|
101 |
{
|
hegyi@157
|
102 |
double actual_ppu=get_pixels_per_unit();
|
hegyi@157
|
103 |
w=(int)(w/actual_ppu*fixed_zoom_factor);
|
hegyi@48
|
104 |
}
|
ladanyi@147
|
105 |
edgesmap[i]->setLineWidth(w);
|
hegyi@28
|
106 |
}
|
hegyi@28
|
107 |
}
|
hegyi@28
|
108 |
else
|
hegyi@28
|
109 |
{
|
hegyi@31
|
110 |
int w=(int)(*actual_map)[edge];
|
hegyi@27
|
111 |
if(w>=0)
|
hegyi@27
|
112 |
{
|
ladanyi@147
|
113 |
edgesmap[edge]->setLineWidth(w);
|
hegyi@27
|
114 |
}
|
hegyi@27
|
115 |
}
|
hegyi@27
|
116 |
return 0;
|
hegyi@27
|
117 |
};
|
hegyi@27
|
118 |
|
alpar@62
|
119 |
int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
|
hegyi@27
|
120 |
{
|
hegyi@27
|
121 |
|
hegyi@27
|
122 |
//function maps the range of the maximum and
|
hegyi@27
|
123 |
//the minimum of the nodemap to the range of
|
hegyi@27
|
124 |
//green in RGB
|
hegyi@31
|
125 |
Graph::EdgeMap<double> * actual_map;
|
hegyi@96
|
126 |
actual_map=((mytab.mapstorage).edgemap_storage)[mapname];
|
hegyi@81
|
127 |
|
hegyi@81
|
128 |
double max, min;
|
hegyi@81
|
129 |
|
hegyi@96
|
130 |
max=(mytab.mapstorage).maxOfEdgeMap(mapname);
|
hegyi@96
|
131 |
min=(mytab.mapstorage).minOfEdgeMap(mapname);
|
hegyi@81
|
132 |
|
hegyi@81
|
133 |
if(edge==INVALID)
|
hegyi@31
|
134 |
{
|
hegyi@96
|
135 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
136 |
{
|
hegyi@81
|
137 |
double w=(*actual_map)[i];
|
hegyi@81
|
138 |
|
hegyi@81
|
139 |
Gdk::Color color;
|
hegyi@81
|
140 |
if(max!=min)
|
hegyi@81
|
141 |
{
|
hegyi@81
|
142 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@81
|
143 |
}
|
hegyi@81
|
144 |
else
|
hegyi@81
|
145 |
{
|
hegyi@81
|
146 |
color.set_rgb_p (0, 100, 0);
|
hegyi@81
|
147 |
}
|
ladanyi@147
|
148 |
edgesmap[i]->setFillColor(color);
|
hegyi@81
|
149 |
}
|
hegyi@31
|
150 |
}
|
hegyi@31
|
151 |
else
|
hegyi@31
|
152 |
{
|
hegyi@81
|
153 |
Gdk::Color color;
|
hegyi@81
|
154 |
|
hegyi@81
|
155 |
double w=(*actual_map)[edge];
|
hegyi@81
|
156 |
|
hegyi@81
|
157 |
if(max!=min)
|
hegyi@81
|
158 |
{
|
hegyi@81
|
159 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@81
|
160 |
}
|
hegyi@81
|
161 |
else
|
hegyi@81
|
162 |
{
|
hegyi@81
|
163 |
color.set_rgb_p (0, 100, 0);
|
hegyi@81
|
164 |
}
|
hegyi@81
|
165 |
|
ladanyi@147
|
166 |
edgesmap[edge]->setFillColor(color);
|
hegyi@31
|
167 |
}
|
hegyi@81
|
168 |
return 0;
|
hegyi@81
|
169 |
};
|
hegyi@81
|
170 |
|
hegyi@81
|
171 |
int GraphDisplayerCanvas::resetEdgeColor (Edge edge)
|
hegyi@81
|
172 |
{
|
hegyi@81
|
173 |
|
hegyi@81
|
174 |
//function maps the range of the maximum and
|
hegyi@81
|
175 |
//the minimum of the nodemap to the range of
|
hegyi@81
|
176 |
//green in RGB
|
hegyi@96
|
177 |
Graph::EdgeMap<double> actual_map((mytab.mapstorage).graph,edge_property_defaults[E_COLOR]);
|
hegyi@31
|
178 |
|
hegyi@31
|
179 |
double max, min;
|
hegyi@31
|
180 |
|
hegyi@81
|
181 |
max=edge_property_defaults[E_COLOR];
|
hegyi@81
|
182 |
min=edge_property_defaults[E_COLOR];
|
hegyi@31
|
183 |
|
hegyi@28
|
184 |
if(edge==INVALID)
|
hegyi@28
|
185 |
{
|
hegyi@96
|
186 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@28
|
187 |
{
|
ladanyi@91
|
188 |
double w=actual_map[i];
|
hegyi@31
|
189 |
|
hegyi@28
|
190 |
Gdk::Color color;
|
hegyi@28
|
191 |
if(max!=min)
|
hegyi@28
|
192 |
{
|
hegyi@28
|
193 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@28
|
194 |
}
|
hegyi@28
|
195 |
else
|
hegyi@28
|
196 |
{
|
hegyi@28
|
197 |
color.set_rgb_p (0, 100, 0);
|
hegyi@28
|
198 |
}
|
ladanyi@147
|
199 |
edgesmap[i]->setFillColor(color);
|
hegyi@28
|
200 |
}
|
hegyi@28
|
201 |
}
|
hegyi@28
|
202 |
else
|
hegyi@27
|
203 |
{
|
hegyi@28
|
204 |
Gdk::Color color;
|
hegyi@31
|
205 |
|
ladanyi@91
|
206 |
double w=actual_map[edge];
|
hegyi@31
|
207 |
|
hegyi@28
|
208 |
if(max!=min)
|
hegyi@28
|
209 |
{
|
hegyi@28
|
210 |
color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
|
hegyi@28
|
211 |
}
|
hegyi@28
|
212 |
else
|
hegyi@28
|
213 |
{
|
hegyi@28
|
214 |
color.set_rgb_p (0, 100, 0);
|
hegyi@28
|
215 |
}
|
hegyi@28
|
216 |
|
ladanyi@147
|
217 |
edgesmap[edge]->setFillColor(color);
|
hegyi@27
|
218 |
}
|
hegyi@27
|
219 |
return 0;
|
hegyi@27
|
220 |
};
|
hegyi@27
|
221 |
|
alpar@62
|
222 |
int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
|
hegyi@27
|
223 |
{
|
hegyi@27
|
224 |
//the number in the map will be written on the edge
|
hegyi@40
|
225 |
//EXCEPT when the name of the map is Default, because
|
hegyi@27
|
226 |
//in that case empty string will be written, because
|
hegyi@27
|
227 |
//that is the deleter map
|
ladanyi@63
|
228 |
|
hegyi@28
|
229 |
if(edge==INVALID)
|
hegyi@27
|
230 |
{
|
hegyi@96
|
231 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@27
|
232 |
{
|
hegyi@81
|
233 |
edgemap_to_edit=mapname;
|
hegyi@96
|
234 |
double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[i];
|
hegyi@81
|
235 |
|
hegyi@81
|
236 |
std::ostringstream ostr;
|
hegyi@81
|
237 |
ostr << number;
|
hegyi@81
|
238 |
|
hegyi@81
|
239 |
edgetextmap[i]->property_text().set_value(ostr.str());
|
hegyi@28
|
240 |
}
|
hegyi@28
|
241 |
|
hegyi@28
|
242 |
}
|
hegyi@28
|
243 |
else
|
hegyi@28
|
244 |
{
|
hegyi@96
|
245 |
double number=(*((mytab.mapstorage).edgemap_storage)[mapname])[edge];
|
hegyi@45
|
246 |
|
hegyi@45
|
247 |
std::ostringstream ostr;
|
hegyi@45
|
248 |
ostr << number;
|
hegyi@45
|
249 |
|
hegyi@45
|
250 |
edgetextmap[edge]->property_text().set_value(ostr.str());
|
hegyi@27
|
251 |
}
|
hegyi@28
|
252 |
|
hegyi@27
|
253 |
return 0;
|
hegyi@28
|
254 |
|
hegyi@27
|
255 |
};
|
hegyi@81
|
256 |
|
hegyi@81
|
257 |
int GraphDisplayerCanvas::resetEdgeText (Edge edge)
|
hegyi@81
|
258 |
{
|
hegyi@81
|
259 |
//the number in the map will be written on the edge
|
hegyi@81
|
260 |
//EXCEPT when the name of the map is Default, because
|
hegyi@81
|
261 |
//in that case empty string will be written, because
|
hegyi@81
|
262 |
//that is the deleter map
|
hegyi@81
|
263 |
|
hegyi@81
|
264 |
if(edge==INVALID)
|
hegyi@81
|
265 |
{
|
hegyi@96
|
266 |
for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
|
hegyi@81
|
267 |
{
|
hegyi@81
|
268 |
edgemap_to_edit="";
|
hegyi@81
|
269 |
edgetextmap[i]->property_text().set_value("");
|
hegyi@81
|
270 |
}
|
hegyi@81
|
271 |
|
hegyi@81
|
272 |
}
|
hegyi@81
|
273 |
else
|
hegyi@81
|
274 |
{
|
hegyi@81
|
275 |
edgetextmap[edge]->property_text().set_value("");
|
hegyi@81
|
276 |
}
|
hegyi@81
|
277 |
|
hegyi@81
|
278 |
return 0;
|
hegyi@81
|
279 |
|
hegyi@81
|
280 |
};
|