COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-node.cc @ 45:199f433eb7cd

gui
Last change on this file since 45:199f433eb7cd was 45:199f433eb7cd, checked in by Hegyi Péter, 19 years ago

Sorry for the previous commit, it was not ready yet, but that damned up arrow... So in this new revision string-double and double-string conversion is corrected to a more C++ way.

  • Property exe set to *
File size: 4.0 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
153              std::ostringstream ostr;
154              ostr << number;
155             
156              nodetextmap[i]->property_text().set_value(ostr.str());
157            }
158          else
159            {
160              nodemap_to_edit="";
161              nodetextmap[i]->property_text().set_value("");
162            }
163        }
164    }
165  else
166    {
167      if(mapname!="Default")
168        {
169          double number=(*actual_map)[node];
170
171          std::ostringstream ostr;
172          ostr << number;
173             
174          nodetextmap[node]->property_text().set_value(ostr.str());
175        }
176      else
177        {
178          nodetextmap[node]->property_text().set_value("");
179        }
180    }
181  return 0;
182};
Note: See TracBrowser for help on using the repository browser.