COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas-edge.cc @ 1595:3bde58e2d5ca

Last change on this file since 1595:3bde58e2d5ca was 1595:3bde58e2d5ca, checked in by Hegyi Péter, 19 years ago

Documentation was added to GUI.

  • Property exe set to *
File size: 4.3 KB
RevLine 
[1510]1#include <graph_displayer_canvas.h>
2#include <broken_edge.h>
3#include <math.h>
4
5
[1512]6int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Graph::Edge edge)
[1510]7{
[1525]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
[1512]18  if(edge==INVALID)
[1510]19    {
[1512]20      for (EdgeIt i(g); i!=INVALID; ++i)
21        {
[1525]22          int w=(int)(*actual_map)[i];
[1512]23          if(w>=0)
24            {
25              edgesmap[i]->property_width_pixels().set_value(w);
26            }
27        }
28    }
29  else
30    {
[1525]31      int w=(int)(*actual_map)[edge];
[1510]32      if(w>=0)
33        {
[1512]34          edgesmap[edge]->property_width_pixels().set_value(w);
[1510]35        }
36    }
37  return 0;
38};
39
[1512]40int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
[1510]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
[1525]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
[1512]69  if(edge==INVALID)
70    {
71      for (EdgeIt i(g); i!=INVALID; ++i)
72        {
[1525]73          double w=(*actual_map)[i];
74
[1512]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
[1510]88    {
[1512]89      Gdk::Color color;
[1525]90
91      double w=(*actual_map)[edge];
92
[1512]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);
[1510]103    }
104  return 0;
105};
106
[1512]107int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
[1510]108{
109  //the number in the map will be written on the edge
[1589]110  //EXCEPT when the name of the map is Default, because
[1510]111  //in that case empty string will be written, because
112  //that is the deleter map
113
[1512]114  if(edge==INVALID)
[1510]115    {
[1512]116      for (EdgeIt i(g); i!=INVALID; ++i)
[1510]117        {
[1525]118          if(mapname!="Default")
[1512]119            {
[1579]120              edgemap_to_edit=mapname;
[1512]121              double number=(*(mapstorage.edgemap_storage)[mapname])[i];
[1595]122//            int length=1;
123//            //if number is smaller than one, length would be negative, or invalid
124//            if(number>=1)
125//              {
126//                length=(int)(floor(log(number)/log(10)))+1;
127//              }
128//            int maxpos=(int)(pow(10,length-1));
129//            int strl=length+1+RANGE;
130//            char * str=new char[strl];
131//            str[length]='.';
132//            str[strl]='\0';
[1512]133     
[1595]134//            for(int j=0;j<strl;j++)
135//              {
136//                if(j!=length)
137//                  {
138//                    if((number-(int)number)>ALMOST_ONE)
139//                      {
140//                        number=round(number);
141//                      }
142//                    int digit=(int)(number/maxpos);
143//                    str[j]=(digit+'0');
144//                    number-=digit*maxpos;
145//                    number*=10;
146//                  }
147//              }
148//                    edgetextmap[i]->property_text().set_value(str);
149
150              std::ostringstream ostr;
151              ostr << number;
152
153              edgetextmap[i]->property_text().set_value(ostr.str());
[1512]154            }
155          else
156            {
[1579]157              edgemap_to_edit="";
[1512]158              edgetextmap[i]->property_text().set_value("");
159            }
160        }
161
162    }
163  else
164    {
[1525]165      if(mapname!="Default")
[1512]166        {
167          double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
[1510]168          int length=1;
169          //if number is smaller than one, length would be negative, or invalid
170          if(number>=1)
171            {
172              length=(int)(floor(log(number)/log(10)))+1;
173            }
174          int maxpos=(int)(pow(10,length-1));
175          int strl=length+1+RANGE;
176          char * str=new char[strl];
177          str[length]='.';
178          str[strl]='\0';
179     
180          for(int j=0;j<strl;j++)
181            {
182              if(j!=length)
183                {
[1581]184                  if((number-(int)number)>ALMOST_ONE)
185                    {
186                      number=round(number);
187                    }
[1510]188                  int digit=(int)(number/maxpos);
189                  str[j]=(digit+'0');
190                  number-=digit*maxpos;
191                  number*=10;
192                }
193            }
194     
[1512]195          edgetextmap[edge]->property_text().set_value(str);
[1510]196        }
197      else
198        {
[1512]199          edgetextmap[edge]->property_text().set_value("");
[1510]200        }
[1512]201         
[1510]202    }
[1512]203
[1510]204  return 0;
[1512]205
[1510]206};
Note: See TracBrowser for help on using the repository browser.