COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas-edge.cc @ 68:1a27576aa199

gui
Last change on this file since 68:1a27576aa199 was 63:59768817442a, checked in by Akos Ladanyi, 19 years ago
  • id maps are not editable
  • handle exceptions thrown by the file reader
  • texts are always above the edges
  • store a default value for all maps, so that edges and nodes created after adding a new map receive the default value too
  • create node on button release, not on click (fixes a few oddities)
  • Property exe set to *
File size: 3.4 KB
RevLine 
[53]1#include "graph_displayer_canvas.h"
2#include "broken_edge.h"
[59]3#include <cmath>
[27]4
5
[62]6int GraphDisplayerCanvas::changeEdgeWidth (std::string mapname, Edge edge)
[27]7{
[31]8  Graph::EdgeMap<double> * actual_map;
[48]9  double min, max;
10
[31]11  if(mapname=="Default")
12    {
[48]13      min=edge_property_defaults[E_WIDTH];
14      max=edge_property_defaults[E_WIDTH];
[53]15      actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_WIDTH]);
[31]16    }
17  else
18    {
[48]19      min=mapstorage.minOfEdgeMap(mapname);
20      max=mapstorage.maxOfEdgeMap(mapname);
[31]21      actual_map=(mapstorage.edgemap_storage)[mapname];
22    }
23
[28]24  if(edge==INVALID)
[27]25    {
[53]26      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[28]27        {
[55]28          double v=fabs((*actual_map)[i]);
[48]29          int w;
30          if(min==max)
[28]31            {
[48]32              w=(int)(edge_property_defaults[E_WIDTH]);
[28]33            }
[48]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);
[28]39        }
40    }
41  else
42    {
[31]43      int w=(int)(*actual_map)[edge];
[27]44      if(w>=0)
45        {
[47]46          edgesmap[edge]->property_width_units().set_value(w);
[27]47        }
48    }
49  return 0;
50};
51
[62]52int GraphDisplayerCanvas::changeEdgeColor (std::string mapname, Edge edge)
[27]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
[31]58  Graph::EdgeMap<double> * actual_map;
59  if(mapname=="Default")
60    {
[53]61      actual_map=new Graph::EdgeMap<double>(mapstorage.graph,edge_property_defaults[E_COLOR]);
[31]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
[28]81  if(edge==INVALID)
82    {
[53]83      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[28]84        {
[31]85          double w=(*actual_map)[i];
86
[28]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
[27]100    {
[28]101      Gdk::Color color;
[31]102
103      double w=(*actual_map)[edge];
104
[28]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);
[27]115    }
116  return 0;
117};
118
[62]119int GraphDisplayerCanvas::changeEdgeText (std::string mapname, Edge edge)
[27]120{
121  //the number in the map will be written on the edge
[40]122  //EXCEPT when the name of the map is Default, because
[27]123  //in that case empty string will be written, because
124  //that is the deleter map
[63]125 
[28]126  if(edge==INVALID)
[27]127    {
[53]128      for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[27]129        {
[31]130          if(mapname!="Default")
[28]131            {
[35]132              edgemap_to_edit=mapname;
[28]133              double number=(*(mapstorage.edgemap_storage)[mapname])[i];
[44]134
135              std::ostringstream ostr;
136              ostr << number;
[45]137             
[44]138              edgetextmap[i]->property_text().set_value(ostr.str());
[28]139            }
140          else
141            {
[35]142              edgemap_to_edit="";
[28]143              edgetextmap[i]->property_text().set_value("");
144            }
145        }
146
147    }
148  else
149    {
[31]150      if(mapname!="Default")
[28]151        {
152          double number=(*(mapstorage.edgemap_storage)[mapname])[edge];
[45]153
154          std::ostringstream ostr;
155          ostr << number;
156         
157          edgetextmap[edge]->property_text().set_value(ostr.str());
[27]158        }
159      else
160        {
[28]161          edgetextmap[edge]->property_text().set_value("");
[27]162        }
[28]163         
[27]164    }
[28]165
[27]166  return 0;
[28]167
[27]168};
Note: See TracBrowser for help on using the repository browser.