COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-node.cc @ 153:d79a71382836

gui
Last change on this file since 153:d79a71382836 was 96:e664d8aa3f72, checked in by Hegyi Péter, 18 years ago

Notebook style is provided. Without opportunity to close tabs. :-) But with all other necessary things (I think).

  • Property exe set to *
File size: 6.8 KB
RevLine 
[53]1#include "graph_displayer_canvas.h"
[59]2#include <cmath>
[28]3
4
[62]5int GraphDisplayerCanvas::changeNodeRadius (std::string mapname, Node node)
[28]6{
[31]7  Graph::NodeMap<double> * actual_map;
[48]8  double min, max;
[96]9  min=(mytab.mapstorage).minOfNodeMap(mapname);
10  max=(mytab.mapstorage).maxOfNodeMap(mapname);
11  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
[81]12
13  if(node==INVALID)
[31]14    {
[96]15      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]16        {
17          double v=fabs((*actual_map)[i]);
18          int w;
19          if(min==max)
20            {
21              w=(int)(node_property_defaults[N_RADIUS]);
22            }
23          else
24            {
25              w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
26            }
27          if(w>=0)
28            {
29              double x1, y1, x2, y2;
30              x1=nodesmap[i]->property_x1().get_value();
31              x2=nodesmap[i]->property_x2().get_value();
32              y1=nodesmap[i]->property_y1().get_value();
33              y2=nodesmap[i]->property_y2().get_value();
34              nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
35              nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
36              nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
37              nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
38            }
39        }
[31]40    }
41  else
42    {
[81]43      //I think only new nodes use this case
44//       int w=(int)(*actual_map)[node];
45      int w=(int)(node_property_defaults[N_RADIUS]);
46      if(w>=0)
47        {
48          double x1, y1, x2, y2;
49          x1=nodesmap[node]->property_x1().get_value();
50          x2=nodesmap[node]->property_x2().get_value();
51          y1=nodesmap[node]->property_y1().get_value();
52          y2=nodesmap[node]->property_y2().get_value();
53          nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
54          nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
55          nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
56          nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
57        }
[31]58    }
[81]59  return 0;
60};
[31]61
[81]62int GraphDisplayerCanvas::resetNodeRadius (Node node)
63{
64  double min, max;
65  min=node_property_defaults[N_RADIUS];
66  max=node_property_defaults[N_RADIUS];
[96]67  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_RADIUS]);
[81]68 
[28]69  if(node==INVALID)
70    {
[96]71      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]72        {
[91]73          double v=fabs(actual_map[i]);
[48]74          int w;
75          if(min==max)
76            {
77              w=(int)(node_property_defaults[N_RADIUS]);
78            }
79          else
80            {
81              w=(int)(MIN_NODE_RADIUS+(v-min)/(max-min)*(MAX_NODE_RADIUS-MIN_NODE_RADIUS));
82            }
[28]83          if(w>=0)
84            {
85              double x1, y1, x2, y2;
[31]86              x1=nodesmap[i]->property_x1().get_value();
87              x2=nodesmap[i]->property_x2().get_value();
88              y1=nodesmap[i]->property_y1().get_value();
89              y2=nodesmap[i]->property_y2().get_value();
[28]90              nodesmap[i]->property_x1().set_value((x1+x2)/2-w);
91              nodesmap[i]->property_x2().set_value((x1+x2)/2+w);
92              nodesmap[i]->property_y1().set_value((y1+y2)/2-w);
93              nodesmap[i]->property_y2().set_value((y1+y2)/2+w);
94            }
95        }
96    }
97  else
98    {
[31]99      //I think only new nodes use this case
[91]100//       int w=(int)actual_map[node];
[31]101      int w=(int)(node_property_defaults[N_RADIUS]);
[28]102      if(w>=0)
103        {
104          double x1, y1, x2, y2;
[31]105          x1=nodesmap[node]->property_x1().get_value();
106          x2=nodesmap[node]->property_x2().get_value();
107          y1=nodesmap[node]->property_y1().get_value();
108          y2=nodesmap[node]->property_y2().get_value();
[28]109          nodesmap[node]->property_x1().set_value((x1+x2)/2-w);
110          nodesmap[node]->property_x2().set_value((x1+x2)/2+w);
111          nodesmap[node]->property_y1().set_value((y1+y2)/2-w);
112          nodesmap[node]->property_y2().set_value((y1+y2)/2+w);
113        }
114    }
115  return 0;
116};
117
[62]118int GraphDisplayerCanvas::changeNodeColor (std::string mapname, Node node)
[28]119
120
121  //function maps the range of the maximum and
122  //the minimum of the nodemap to the range of
123  //green in RGB
124
[31]125  Graph::NodeMap<double> * actual_map;
[96]126  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
[81]127
128  double max, min;
129
[96]130  max=(mytab.mapstorage).maxOfNodeMap(mapname);
131  min=(mytab.mapstorage).minOfNodeMap(mapname);
[81]132
133  if(node==INVALID)
[31]134    {
[81]135
[96]136      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]137        {
138          Gdk::Color color;
139
140          double w=(*actual_map)[i];
141
142          if(max!=min)
143            {
144              color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
145            }
146          else
147            {
148              color.set_rgb_p (0, 0, 100);
149            }
150
151          nodesmap[i]->property_fill_color_gdk().set_value(color);
152        }
[31]153    }
154  else
155    {
[81]156      Gdk::Color color;
157
158      double w=(*actual_map)[node];
159
160      if(max!=min)
161        {
162          color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
163        }
164      else
165        {
166          color.set_rgb_p (0, 0, 100);
167        }
168
169      nodesmap[node]->property_fill_color_gdk().set_value(color);
[31]170    }
[81]171  return 0;
172};
173
174int GraphDisplayerCanvas::resetNodeColor (Node node)
175
176
177  //function maps the range of the maximum and
178  //the minimum of the nodemap to the range of
179  //green in RGB
180
[96]181  Graph::NodeMap<double> actual_map((mytab.mapstorage).graph,node_property_defaults[N_COLOR]);
[31]182
183  double max, min;
184
[81]185  max=node_property_defaults[N_COLOR];
186  min=node_property_defaults[N_COLOR];
[31]187
[28]188  if(node==INVALID)
189    {
190
[96]191      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]192        {
193          Gdk::Color color;
[31]194
[91]195          double w=actual_map[i];
[31]196
[28]197          if(max!=min)
198            {
199              color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
200            }
201          else
202            {
203              color.set_rgb_p (0, 0, 100);
204            }
205
206          nodesmap[i]->property_fill_color_gdk().set_value(color);
207        }
208    }
209  else
210    {
211      Gdk::Color color;
[31]212
[91]213      double w=actual_map[node];
[31]214
[28]215      if(max!=min)
216        {
217          color.set_rgb_p (0, 0, 100*(w-min)/(max-min));
218        }
219      else
220        {
221          color.set_rgb_p (0, 0, 100);
222        }
223
224      nodesmap[node]->property_fill_color_gdk().set_value(color);
225    }
226  return 0;
227};
228
[62]229int GraphDisplayerCanvas::changeNodeText (std::string mapname, Node node)
[28]230{
231
232  //the number in the map will be written on the node
233  //EXCEPT when the name of the map is Text, because
234  //in that case empty string will be written, because
235  //that is the deleter map
[31]236
[36]237  Graph::NodeMap<double> * actual_map=NULL;
[96]238  actual_map=((mytab.mapstorage).nodemap_storage)[mapname];
[28]239
240  if(node==INVALID)
241    {
[96]242      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[28]243        {
[81]244          nodemap_to_edit=mapname;
245          double number=(*actual_map)[i];
[45]246
[81]247          std::ostringstream ostr;
248          ostr << number;
[45]249             
[81]250          nodetextmap[i]->property_text().set_value(ostr.str());
[28]251        }
252    }
253  else
254    {
[81]255      double number=(*actual_map)[node];
[45]256
[81]257      std::ostringstream ostr;
258      ostr << number;
[45]259             
[81]260      nodetextmap[node]->property_text().set_value(ostr.str());
[28]261    }
262  return 0;
263};
[81]264
265int GraphDisplayerCanvas::resetNodeText (Node node)
266{
267
268  //the number in the map will be written on the node
269  //EXCEPT when the name of the map is Text, because
270  //in that case empty string will be written, because
271  //that is the deleter map
272
273  if(node==INVALID)
274    {
[96]275      for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[81]276        {
277          nodemap_to_edit="";
278          nodetextmap[i]->property_text().set_value("");
279        }
280    }
281  else
282    {
283      nodetextmap[node]->property_text().set_value("");
284    }
285  return 0;
286};
Note: See TracBrowser for help on using the repository browser.