COIN-OR::LEMON - Graph Library

source: glemon/graph_displayer_canvas-edge.cc

Last change on this file was 1:67188bd752db, checked in by Peter Hegyi <hegyi@…>, 16 years ago

SVN revision 3500 made compilable with Lemon 1.0.

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