COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas-edge.cc @ 1579:ed7da82bbecf

Last change on this file since 1579:ed7da82bbecf was 1579:ed7da82bbecf, checked in by Hegyi Péter, 19 years ago

Edge and nodemap edition is done.

  • Property exe set to *
File size: 3.9 KB
Line 
1#include <graph_displayer_canvas.h>
2#include <broken_edge.h>
3#include <math.h>
4
5
6int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
7{
8  Graph::EdgeMap<double> * actual_map;
9  if(mapname=="Default")
10    {
11      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_WIDTH]);
12    }
13  else
14    {
15      actual_map=(mapstorage.edgemap_storage)[mapname];
16    }
17
18  if(edge==INVALID)
19    {
20      for (EdgeIt i(g); i!=INVALID; ++i)
21        {
22          int w=(int)(*actual_map)[i];
23          if(w>=0)
24            {
25              edgesmap[i]->property_width_pixels().set_value(w);
26            }
27        }
28    }
29  else
30    {
31      int w=(int)(*actual_map)[edge];
32      if(w>=0)
33        {
34          edgesmap[edge]->property_width_pixels().set_value(w);
35        }
36    }
37  return 0;
38};
39
40int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
41
42
43  //function maps the range of the maximum and
44  //the minimum of the nodemap to the range of
45  //green in RGB
46  Graph::EdgeMap<double> * actual_map;
47  if(mapname=="Default")
48    {
49      actual_map=new Graph::EdgeMap<double>(g,edge_property_defaults[E_COLOR]);
50    }
51  else
52    {
53      actual_map=(mapstorage.edgemap_storage)[mapname];
54    }
55
56  double max, min;
57
58  if(mapname!="Default")
59    {
60      max=mapstorage.maxOfEdgeMap(mapname);
61      min=mapstorage.minOfEdgeMap(mapname);
62    }
63  else
64    {
65      max=edge_property_defaults[E_COLOR];
66      min=edge_property_defaults[E_COLOR];
67    }
68
69  if(edge==INVALID)
70    {
71      for (EdgeIt i(g); i!=INVALID; ++i)
72        {
73          double w=(*actual_map)[i];
74
75          Gdk::Color color;
76          if(max!=min)
77            {
78              color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
79            }
80          else
81            {
82              color.set_rgb_p (0, 100, 0);
83            }
84          edgesmap[i]->property_fill_color_gdk().set_value(color);
85        }
86    }
87  else
88    {
89      Gdk::Color color;
90
91      double w=(*actual_map)[edge];
92
93      if(max!=min)
94        {
95          color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
96        }
97      else
98        {
99          color.set_rgb_p (0, 100, 0);
100        }
101
102      edgesmap[edge]->property_fill_color_gdk().set_value(color);
103    }
104  return 0;
105};
106
107int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
108{
109
110  //the number in the map will be written on the edge
111  //EXCEPT when the name of the map is Text, because
112  //in that case empty string will be written, because
113  //that is the deleter map
114
115  if(edge==INVALID)
116    {
117      for (EdgeIt i(g); i!=INVALID; ++i)
118        {
119          if(mapname!="Default")
120            {
121              edgemap_to_edit=mapname;
122              double number=(*(mapstorage.edgemap_storage)[mapname])[i];
123              int length=1;
124              //if number is smaller than one, length would be negative, or invalid
125              if(number>=1)
126                {
127                  length=(int)(floor(log(number)/log(10)))+1;
128                }
129              int maxpos=(int)(pow(10,length-1));
130              int strl=length+1+RANGE;
131              char * str=new char[strl];
132              str[length]='.';
133              str[strl]='\0';
134     
135              for(int j=0;j<strl;j++)
136                {
137                  if(j!=length)
138                    {
139                      int digit=(int)(number/maxpos);
140                      str[j]=(digit+'0');
141                      number-=digit*maxpos;
142                      number*=10;
143                    }
144                }
145     
146              edgetextmap[i]->property_text().set_value(str);
147            }
148          else
149            {
150              edgemap_to_edit="";
151              edgetextmap[i]->property_text().set_value("");
152            }
153        }
154
155    }
156  else
157    {
158      if(mapname!="Default")
159        {
160          double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
161          int length=1;
162          //if number is smaller than one, length would be negative, or invalid
163          if(number>=1)
164            {
165              length=(int)(floor(log(number)/log(10)))+1;
166            }
167          int maxpos=(int)(pow(10,length-1));
168          int strl=length+1+RANGE;
169          char * str=new char[strl];
170          str[length]='.';
171          str[strl]='\0';
172     
173          for(int j=0;j<strl;j++)
174            {
175              if(j!=length)
176                {
177                  int digit=(int)(number/maxpos);
178                  str[j]=(digit+'0');
179                  number-=digit*maxpos;
180                  number*=10;
181                }
182            }
183     
184          edgetextmap[edge]->property_text().set_value(str);
185        }
186      else
187        {
188          edgetextmap[edge]->property_text().set_value("");
189        }
190         
191    }
192
193  return 0;
194
195};
Note: See TracBrowser for help on using the repository browser.