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>
20 #include <mapstorage.h>
24 const int minimum_arc_width=0;
26 int DigraphDisplayerCanvas::resetArcWidth (Arc arc)
28 MapStorage& ms = *mytab.mapstorage;
31 min=arc_property_defaults[E_WIDTH];
32 max=arc_property_defaults[E_WIDTH];
33 Digraph::ArcMap<double> actual_map(ms.digraph,arc_property_defaults[E_WIDTH]);
37 for (ArcIt i(ms.digraph); i!=INVALID; ++i)
39 double v=fabs(actual_map[i]);
43 w=(int)(arc_property_defaults[E_WIDTH]);
47 w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
51 double actual_ppu=get_pixels_per_unit();
52 w=(int)(w/actual_ppu*fixed_zoom_factor);
54 arcsmap[i]->setLineWidth(w);
59 int w=(int)actual_map[arc];
62 arcsmap[arc]->setLineWidth(w);
69 int DigraphDisplayerCanvas::changeArcWidth (std::string mapname, Arc arc)
71 MapStorage& ms = *mytab.mapstorage;
76 min = max = ms.get(mapname, e);
77 for (; e != INVALID; ++e)
79 if (static_cast<double>(ms.get(mapname, e)) > max)
80 max = ms.get(mapname, e);
81 if (static_cast<double>(ms.get(mapname, e)) < min)
82 min = ms.get(mapname, e);
88 for (ArcIt i(ms.digraph); i!=INVALID; ++i)
90 double v=ms.get(mapname, i);
96 w=(int)(arc_property_defaults[E_WIDTH]);
100 w=(int)(minimum_arc_width+(v-min)/(max-min)*(arc_width-minimum_arc_width));
105 w=(int)(v*arc_width);
114 if(w<minimum_arc_width)
120 double actual_ppu=get_pixels_per_unit();
121 w=(int)(w/actual_ppu*fixed_zoom_factor);
123 arcsmap[i]->setLineWidth(w);
129 int w=(int)ms.get(mapname, arc);
132 arcsmap[arc]->setLineWidth(w);
138 int DigraphDisplayerCanvas::changeArcColor (std::string mapname, Arc arc)
140 MapStorage& ms = *mytab.mapstorage;
142 //function maps the range of the maximum and
143 //the minimum of the nodemap to the range of
150 min = max = ms.get(mapname, e);
151 for (; e != INVALID; ++e)
153 if (static_cast<double>(ms.get(mapname, e)) > max)
154 max = ms.get(mapname, e);
155 if (static_cast<double>(ms.get(mapname, e)) < min)
156 min = ms.get(mapname, e);
162 for (ArcIt i(ms.digraph); i!=INVALID; ++i)
164 double w=ms.get(mapname, i);
169 color=rainbowColorCounter(min, max, w);
173 color.set_rgb_p (0, 1, 0);
175 arcsmap[i]->setFillColor(color);
182 double w=ms.get(mapname, arc);
186 color=rainbowColorCounter(min, max, w);
190 color.set_rgb_p (0, 1, 0);
193 arcsmap[arc]->setFillColor(color);
198 int DigraphDisplayerCanvas::resetArcColor (Arc arc)
200 MapStorage& ms = *mytab.mapstorage;
202 //function maps the range of the maximum and
203 //the minimum of the nodemap to the range of
205 Digraph::ArcMap<double> actual_map(ms.digraph,arc_property_defaults[E_COLOR]);
209 max=arc_property_defaults[E_COLOR];
210 min=arc_property_defaults[E_COLOR];
214 for (ArcIt i(ms.digraph); i!=INVALID; ++i)
216 double w=actual_map[i];
221 color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
225 color.set_rgb_p (0, 100, 0);
227 arcsmap[i]->setFillColor(color);
234 double w=actual_map[arc];
238 color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
242 color.set_rgb_p (0, 100, 0);
245 arcsmap[arc]->setFillColor(color);
250 int DigraphDisplayerCanvas::changeArcText (std::string mapname, Arc arc)
252 MapStorage& ms = *mytab.mapstorage;
254 //the number in the map will be written on the arc
255 //EXCEPT when the name of the map is Default, because
256 //in that case empty string will be written, because
257 //that is the deleter map
261 for (ArcIt i(ms.digraph); i!=INVALID; ++i)
263 arcmap_to_edit=mapname;
265 arctextmap[i]->property_text().set_value(
266 static_cast<std::string>(ms.get(mapname, i)));
272 arctextmap[arc]->property_text().set_value(
273 static_cast<std::string>(ms.get(mapname, arc)));
279 int DigraphDisplayerCanvas::resetArcText (Arc arc)
281 MapStorage& ms = *mytab.mapstorage;
283 //the number in the map will be written on the arc
284 //EXCEPT when the name of the map is Default, because
285 //in that case empty string will be written, because
286 //that is the deleter map
290 for (ArcIt i(ms.digraph); i!=INVALID; ++i)
293 arctextmap[i]->property_text().set_value("");
298 arctextmap[arc]->property_text().set_value("");