COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas-edge.cc @ 1614:350c1d8bb7cc

Last change on this file since 1614:350c1d8bb7cc was 1614:350c1d8bb7cc, checked in by Hegyi Péter, 19 years ago

Alpar had the key, focus can be set in the window class. But it is not enough, the focused widget has to be activated, as well! Was a hard task to find out... By the way, two compilation warnings are removed.

  • Property exe set to *
File size: 3.4 KB
RevLine 
[1606]1#include "graph_displayer_canvas.h"
2#include "broken_edge.h"
[1510]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;
[1599]9  double min, max;
10
[1525]11  if(mapname=="Default")
12    {
[1599]13      min=edge_property_defaults[E_WIDTH];
14      max=edge_property_defaults[E_WIDTH];
[1606]15      actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
[1525]16    }
17  else
18    {
[1599]19      min=mapstorage.minOfEdgeMap(mapname);
20      max=mapstorage.maxOfEdgeMap(mapname);
[1525]21      actual_map=(mapstorage.edgemap_storage)[mapname];
22    }
23
[1512]24  if(edge==INVALID)
[1510]25    {
[1606]26      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[1512]27        {
[1614]28          double v=fabs((*actual_map)[i]);
[1599]29          int w;
30          if(min==max)
[1512]31            {
[1599]32              w=(int)(edge_property_defaults[E_WIDTH]);
[1512]33            }
[1599]34          else
35            {
36              w=(int)(MIN_EDGE_WIDTH+(v-min)/(max-min)*(MAX_EDGE_WIDTH-MIN_EDGE_WIDTH));
37            }
38          edgesmap[i]->property_width_units().set_value(w);
[1512]39        }
40    }
41  else
42    {
[1525]43      int w=(int)(*actual_map)[edge];
[1510]44      if(w>=0)
45        {
[1598]46          edgesmap[edge]->property_width_units().set_value(w);
[1510]47        }
48    }
49  return 0;
50};
51
[1512]52int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Graph::Edge edge)
[1510]53
54
55  //function maps the range of the maximum and
56  //the minimum of the nodemap to the range of
57  //green in RGB
[1525]58  Graph::EdgeMap<double> * actual_map;
59  if(mapname=="Default")
60    {
[1606]61      actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
[1525]62    }
63  else
64    {
65      actual_map=(mapstorage.edgemap_storage)[mapname];
66    }
67
68  double max, min;
69
70  if(mapname!="Default")
71    {
72      max=mapstorage.maxOfEdgeMap(mapname);
73      min=mapstorage.minOfEdgeMap(mapname);
74    }
75  else
76    {
77      max=edge_property_defaults[E_COLOR];
78      min=edge_property_defaults[E_COLOR];
79    }
80
[1512]81  if(edge==INVALID)
82    {
[1606]83      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[1512]84        {
[1525]85          double w=(*actual_map)[i];
86
[1512]87          Gdk::Color color;
88          if(max!=min)
89            {
90              color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
91            }
92          else
93            {
94              color.set_rgb_p (0, 100, 0);
95            }
96          edgesmap[i]->property_fill_color_gdk().set_value(color);
97        }
98    }
99  else
[1510]100    {
[1512]101      Gdk::Color color;
[1525]102
103      double w=(*actual_map)[edge];
104
[1512]105      if(max!=min)
106        {
107          color.set_rgb_p (0, 100*(w-min)/(max-min), 0);
108        }
109      else
110        {
111          color.set_rgb_p (0, 100, 0);
112        }
113
114      edgesmap[edge]->property_fill_color_gdk().set_value(color);
[1510]115    }
116  return 0;
117};
118
[1512]119int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Graph::Edge edge)
[1510]120{
121  //the number in the map will be written on the edge
[1589]122  //EXCEPT when the name of the map is Default, because
[1510]123  //in that case empty string will be written, because
124  //that is the deleter map
125
[1512]126  if(edge==INVALID)
[1510]127    {
[1606]128      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[1510]129        {
[1525]130          if(mapname!="Default")
[1512]131            {
[1579]132              edgemap_to_edit=mapname;
[1512]133              double number=(*(mapstorage.edgemap_storage)[mapname])[i];
[1595]134
135              std::ostringstream ostr;
136              ostr << number;
[1596]137             
[1595]138              edgetextmap[i]->property_text().set_value(ostr.str());
[1512]139            }
140          else
141            {
[1579]142              edgemap_to_edit="";
[1512]143              edgetextmap[i]->property_text().set_value("");
144            }
145        }
146
147    }
148  else
149    {
[1525]150      if(mapname!="Default")
[1512]151        {
152          double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
[1596]153
154          std::ostringstream ostr;
155          ostr << number;
156         
157          edgetextmap[edge]->property_text().set_value(ostr.str());
[1510]158        }
159      else
160        {
[1512]161          edgetextmap[edge]->property_text().set_value("");
[1510]162        }
[1512]163         
[1510]164    }
[1512]165
[1510]166  return 0;
[1512]167
[1510]168};
Note: See TracBrowser for help on using the repository browser.