COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-node.cc @ 36:7a8c41aa3c29

gui
Last change on this file since 36:7a8c41aa3c29 was 36:7a8c41aa3c29, checked in by Hegyi Péter, 19 years ago

There were bugs, created yesterday, and there is still one. (I hope only one :) )

  • Property exe set to *
File size: 5.2 KB
Line 
1#include <graph_displayer_canvas.h>
2#include <broken_edge.h>
3#include <math.h>
4
5
6int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Graph::Node node)
7{
8  Graph::NodeMap<double> * actual_map;
9  if(mapname=="Default")
10    {
11      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_RADIUS]);
12    }
13  else
14    {
15      actual_map=(mapstorage.nodemap_storage)[mapname];
16    }
17
18  if(node==INVALID)
19    {
20      for (NodeIt i(g); i!=INVALID; ++i)
21        {
22          int w=(int)(*actual_map)[i];
23          if(w>=0)
24            {
25              double x1, y1, x2, y2;
26              x1=nodesmap[i]->property_x1().get_value();
27              x2=nodesmap[i]->property_x2().get_value();
28              y1=nodesmap[i]->property_y1().get_value();
29              y2=nodesmap[i]->property_y2().get_value();
30              nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
31              nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
32              nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
33              nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
34            }
35        }
36    }
37  else
38    {
39      //I think only new nodes use this case
40//       int w=(int)(*actual_map)[node];
41      int w=(int)(node_property_defaults[N_RADIUS]);
42      if(w>=0)
43        {
44          double x1, y1, x2, y2;
45          x1=nodesmap[node]->property_x1().get_value();
46          x2=nodesmap[node]->property_x2().get_value();
47          y1=nodesmap[node]->property_y1().get_value();
48          y2=nodesmap[node]->property_y2().get_value();
49          nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
50          nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
51          nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
52          nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
53        }
54    }
55  return 0;
56};
57
58int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Graph::Node node)
59
60
61  //function maps the range of the maximum and
62  //the minimum of the nodemap to the range of
63  //green in RGB
64
65  Graph::NodeMap<double> * actual_map;
66  if(mapname=="Default")
67    {
68      actual_map=new Graph::NodeMap<double>(g,node_property_defaults[N_COLOR]);
69    }
70  else
71    {
72      actual_map=(mapstorage.nodemap_storage)[mapname];
73    }
74
75  double max, min;
76
77  if(mapname!="Default")
78    {
79      max=mapstorage.maxOfNodeMap(mapname);
80      min=mapstorage.minOfNodeMap(mapname);
81    }
82  else
83    {
84      max=node_property_defaults[N_COLOR];
85      min=node_property_defaults[N_COLOR];
86    }
87
88
89  if(node==INVALID)
90    {
91
92      for (NodeIt i(g); i!=INVALID; ++i)
93        {
94          Gdk::Color color;
95
96          double w=(*actual_map)[i];
97
98          if(max!=min)
99            {
100              color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
101            }
102          else
103            {
104              color.set_rgb_p (0, 0, 100);
105            }
106
107          nodesmap[i]->property_fill_color_gdk().set_value(color);
108        }
109    }
110  else
111    {
112      Gdk::Color color;
113
114      double w=(*actual_map)[node];
115
116      if(max!=min)
117        {
118          color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
119        }
120      else
121        {
122          color.set_rgb_p (0, 0, 100);
123        }
124
125      nodesmap[node]->property_fill_color_gdk().set_value(color);
126    }
127  return 0;
128};
129
130int GraphDisplayerCanvas::changeNodeText (std::string mapname, Graph::Node node)
131{
132
133  //the number in the map will be written on the node
134  //EXCEPT when the name of the map is Text, because
135  //in that case empty string will be written, because
136  //that is the deleter map
137
138  Graph::NodeMap<double> * actual_map=NULL;
139  if(mapname!="Default")
140    {
141      actual_map=(mapstorage.nodemap_storage)[mapname];
142    }
143
144  if(node==INVALID)
145    {
146      for (NodeIt i(g); i!=INVALID; ++i)
147        {
148          if(mapname!="Default")
149            {
150              nodemap_to_edit=mapname;
151              double number=(*actual_map)[i];
152              int length=1;
153              //if number is smaller than one, length would be negative, or invalid
154              if(number>=1)
155                {
156                  length=(int)(floor(log(number)/log(10)))+1;
157                }
158              int maxpos=(int)(pow(10,length-1));
159              int strl=length+1+RANGE;
160              char * str=new char[strl];
161              str[length]='.';
162              str[strl]='\0';
163     
164              for(int j=0;j<strl;j++)
165                {
166                  if(j!=length)
167                    {
168//                    std::cout << (number) << "-" << (int)number << "=" << (number)-(int)number << std::endl;
169                      if((number-(int)number)>ALMOST_ONE)
170                        {
171//                        std::cout<<"rounding: " <<number<<std::endl;
172                          number=round(number);
173                        }
174                      int digit=(int)(number/maxpos);
175//                    std::cout << number << "/" << maxpos << "=" << digit << std::endl;
176                      str[j]=(digit+'0');
177                      number-=digit*maxpos;
178                      number*=10;
179                    }
180                }
181     
182              nodetextmap[i]->property_text().set_value(str);
183            }
184          else
185            {
186              nodemap_to_edit="";
187              nodetextmap[i]->property_text().set_value("");
188            }
189        }
190    }
191  else
192    {
193      if(mapname!="Default")
194        {
195          double number=(*actual_map)[node];
196          int length=1;
197          //if number is smaller than one, length would be negative, or invalid
198          if(number>=1)
199            {
200              length=(int)(floor(log(number)/log(10)))+1;
201            }
202          int maxpos=(int)(pow(10,length-1));
203          int strl=length+1+RANGE;
204          char * str=new char[strl];
205          str[length]='.';
206          str[strl]='\0';
207     
208          for(int j=0;j<strl;j++)
209            {
210              if(j!=length)
211                {
212                  if((number-(int)number)>ALMOST_ONE)
213                    {
214                      number=round(number);
215                    }
216                  int digit=(int)(number/maxpos);
217                  str[j]=(digit+'0');
218                  number-=digit*maxpos;
219                  number*=10;
220                }
221            }
222     
223          nodetextmap[node]->property_text().set_value(str);
224        }
225      else
226        {
227          nodetextmap[node]->property_text().set_value("");
228        }
229    }
230  return 0;
231};
Note: See TracBrowser for help on using the repository browser.