COIN-OR::LEMON - Graph Library

source: lemon-0.x/gui/graph_displayer_canvas.cc @ 1893:4a35c7847c77

Last change on this file since 1893:4a35c7847c77 was 1888:eed01ce27087, checked in by Hegyi Péter, 14 years ago

If default value of a new map is constant, the newly created elements will get that value as well. Documentation is added to BrokenEdge?, MapStorage? and GraphDisplazCanvas? classes.

  • Property exe set to *
File size: 5.8 KB
RevLine 
[1606]1#include "graph_displayer_canvas.h"
[1632]2#include <cmath>
[1442]3
[1849]4GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) :
[1837]5  nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph),
6  nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0),
[1648]7  isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""),
[1849]8  edgemap_to_edit(""), mytab(mainw)
[1442]9{
[1606]10  //base event handler is move tool
11  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
12  actual_tool=MOVE;
[1562]13
[1606]14  active_node=INVALID;
15  active_edge=INVALID;
16  forming_edge=INVALID;
17}
[1468]18
[1606]19GraphDisplayerCanvas::~GraphDisplayerCanvas()
20{
[1849]21  for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
[1837]22    {
23      delete nodesmap[n];
24      delete nodetextmap[n];
25    }
26 
[1849]27  for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
[1837]28    {
29      delete edgesmap[e];
30      delete edgetextmap[e];
31    }
32}
[1442]33
[1837]34void GraphDisplayerCanvas::propertyChange(bool itisedge, int prop)
35{
36  if(itisedge)
37    {
38      propertyUpdate(Edge(INVALID), prop);
39    }
40  else
41    {
42      propertyUpdate(Node(INVALID), prop);
43    }
44}
45
46void GraphDisplayerCanvas::propertyUpdate(Edge edge)
47{
48  for(int i=0;i<EDGE_PROPERTY_NUM;i++)
49    {
50      propertyUpdate(edge, i);
51    }
52}
53
54void GraphDisplayerCanvas::propertyUpdate(Node node)
55{
56  for(int i=0;i<NODE_PROPERTY_NUM;i++)
57    {
58      propertyUpdate(node, i);
59    }
60}
61
[1888]62void GraphDisplayerCanvas::propertyUpdate(Node node, int prop)
[1837]63{
[1888]64  //dummy=dummy;
[1837]65
[1849]66  std::string mapname=mytab.getActiveNodeMap(prop);
[1837]67
68  if(mapname!="")
69    {
[1849]70      if( ( ((mytab.mapstorage).nodemap_storage).find(mapname) != ((mytab.mapstorage).nodemap_storage).end() ) )
[1837]71        {
72          switch(prop)
73            {
74            case N_RADIUS:
75              changeNodeRadius(mapname, node);
76              break;
77            case N_COLOR:
78              changeNodeColor(mapname, node);
79              break;
80            case N_TEXT:
81              changeNodeText(mapname, node);
82              break;
83            default:
84              std::cerr<<"Error\n";
85            }
86        }
87    }
88  else //mapname==""
89    {
90      Node node=INVALID;       
91      switch(prop)
92        {
93        case N_RADIUS:
94          resetNodeRadius(node);
95          break;
96        case N_COLOR:
97          resetNodeColor(node);
98          break;
99        case N_TEXT:
100          resetNodeText(node);
101          break;
102        default:
103          std::cerr<<"Error\n";
104        }
105    }
106
107}
108
[1888]109void GraphDisplayerCanvas::propertyUpdate(Edge edge, int prop)
[1837]110{
[1888]111  //dummy=dummy;
[1837]112
[1849]113  std::string mapname=mytab.getActiveEdgeMap(prop);
[1837]114
115  if(mapname!="")
116    {
[1849]117      if( ( ((mytab.mapstorage).edgemap_storage).find(mapname) != ((mytab.mapstorage).edgemap_storage).end() ) )
[1837]118        {
119          switch(prop)
120            {
121            case E_WIDTH:
122              changeEdgeWidth(mapname, edge);
123              break;
124            case E_COLOR:
125              changeEdgeColor(mapname, edge);
126              break;
127            case E_TEXT:
128              changeEdgeText(mapname, edge);
129              break;
130            default:
131              std::cerr<<"Error\n";
132            }
133        }
134    }
135  else //mapname==""
136    {
137      switch(prop)
138        {
139        case E_WIDTH:
140          resetEdgeWidth(edge);
141          break;
142        case E_COLOR:
143          resetEdgeColor(edge);
144          break;
145        case E_TEXT:
146          resetEdgeText(edge);
147          break;
148        default:
149          std::cerr<<"Error\n";
150        }
151    }
[1606]152}
153
154void GraphDisplayerCanvas::drawGraph()
155{
[1442]156  //first edges are drawn, to hide joining with nodes later
157
[1849]158  for (EdgeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[1442]159  {
160
[1606]161    //drawing green lines, coordinates are from mapstorage.coords
[1442]162
163    Gnome::Canvas::Points coos;
[1606]164    coos.push_back(Gnome::Art::Point(
[1849]165          (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].x,
166          (mytab.mapstorage).coords[(mytab.mapstorage).graph.source(i)].y));
[1606]167    coos.push_back(Gnome::Art::Point(
[1849]168          (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].x,
169          (mytab.mapstorage).coords[(mytab.mapstorage).graph.target(i)].y));
[1442]170   
[1860]171    edgesmap[i]=new BrokenEdge(displayed_graph, i, *this);
[1442]172    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
[1598]173    edgesmap[i]->property_width_units().set_value(10);   
[1645]174    edgesmap[i]->lower_to_bottom();
[1442]175   
176    //initializing edge-text as well, to empty string
177
[1860]178    XY text_pos=mytab.mapstorage.arrow_pos[i];
179    text_pos+=(XY(10,10));
[1505]180
181    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
[1512]182    edgetextmap[i]->property_fill_color().set_value("darkgreen");
[1599]183    edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
[1645]184    edgetextmap[i]->raise_to_top();
[1442]185  }
186
187  //afterwards nodes come to be drawn
188
[1849]189  for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i)
[1442]190  {
191    //drawing bule nodes, with black line around them
192
[1606]193    nodesmap[i]=new Gnome::Canvas::Ellipse(
194        displayed_graph,
[1849]195        (mytab.mapstorage).coords[i].x-20,
196        (mytab.mapstorage).coords[i].y-20,
197        (mytab.mapstorage).coords[i].x+20,
198        (mytab.mapstorage).coords[i].y+20);
[1442]199    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
200    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
[1645]201    nodesmap[i]->raise_to_top();
[1512]202
203    //initializing edge-text as well, to empty string
204
[1606]205    xy<double> text_pos(
[1849]206        ((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5),
207        ((mytab.mapstorage).coords[i].y+node_property_defaults[N_RADIUS]+5));
[1512]208
[1606]209    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
210        text_pos.x, text_pos.y, "");
[1512]211    nodetextmap[i]->property_fill_color().set_value("darkblue");
[1599]212    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
[1645]213    nodetextmap[i]->raise_to_top();
[1442]214  }
215
216  updateScrollRegion();
217}
218
[1606]219void GraphDisplayerCanvas::clear()
[1442]220{
[1606]221  active_node=INVALID;
222  active_edge=INVALID;
223  forming_edge=INVALID;
[1442]224
[1849]225  for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n)
[1442]226  {
[1606]227    delete nodesmap[n];
228    delete nodetextmap[n];
[1442]229  }
230
[1849]231  for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e)
[1606]232  {
233    delete edgesmap[e];
234    delete edgetextmap[e];
235  }
[1442]236}
Note: See TracBrowser for help on using the repository browser.