COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas.cc @ 59:c38925cc6a4d

gui
Last change on this file since 59:c38925cc6a4d was 59:c38925cc6a4d, checked in by Alpar Juttner, 19 years ago

math.h -> cmath

  • Property exe set to *
File size: 3.7 KB
RevLine 
[53]1#include "graph_displayer_canvas.h"
2#include "broken_edge.h"
[59]3#include <cmath>
[6]4
[55]5GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
[53]6  nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
7  nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0),
8  canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL),
9  target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw)
[6]10{
[55]11  parentwin=mainwin;
12
[53]13  //base event handler is move tool
14  actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
15  actual_tool=MOVE;
[34]16
17  //setting event handler for the editor widget
18  entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
19
[53]20  active_node=INVALID;
21  active_edge=INVALID;
22  forming_edge=INVALID;
23}
[9]24
[53]25GraphDisplayerCanvas::~GraphDisplayerCanvas()
26{
27  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
28  {
29    delete nodesmap[n];
30    delete nodetextmap[n];
31  }
[6]32
[53]33  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
34  {
35    delete edgesmap[e];
36    delete edgetextmap[e];
37  }
38
39  if(canvasentrywidget)
40  {
41    delete(canvasentrywidget);
42  }
43}
44
45void GraphDisplayerCanvas::drawGraph()
46{
[6]47  //first edges are drawn, to hide joining with nodes later
48
[53]49  for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
[6]50  {
51
[53]52    //drawing green lines, coordinates are from mapstorage.coords
[6]53
54    Gnome::Canvas::Points coos;
[53]55    coos.push_back(Gnome::Art::Point(
56          mapstorage.coords[mapstorage.graph.source(i)].x,
57          mapstorage.coords[mapstorage.graph.source(i)].y));
58    coos.push_back(Gnome::Art::Point(
59          mapstorage.coords[mapstorage.graph.target(i)].x,
60          mapstorage.coords[mapstorage.graph.target(i)].y));
[6]61   
[21]62    edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
[6]63    *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
[47]64    edgesmap[i]->property_width_units().set_value(10);   
[6]65   
66    //initializing edge-text as well, to empty string
67
[30]68    xy<double> text_pos=edgesmap[i]->getArrowPos();
[25]69    text_pos+=(xy<double>(10,10));
70
71    edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
[28]72    edgetextmap[i]->property_fill_color().set_value("darkgreen");
[48]73    edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
[6]74  }
75
76  //afterwards nodes come to be drawn
77
[53]78  for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
[6]79  {
80    //drawing bule nodes, with black line around them
81
[53]82    nodesmap[i]=new Gnome::Canvas::Ellipse(
83        displayed_graph,
84        mapstorage.coords[i].x-20,
85        mapstorage.coords[i].y-20,
86        mapstorage.coords[i].x+20,
87        mapstorage.coords[i].y+20);
[6]88    *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
89    *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
[28]90
91    //initializing edge-text as well, to empty string
92
[53]93    xy<double> text_pos(
94        (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
95        (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
[28]96
[53]97    nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
98        text_pos.x, text_pos.y, "");
[28]99    nodetextmap[i]->property_fill_color().set_value("darkblue");
[48]100    nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
[6]101  }
102
103  updateScrollRegion();
104}
105
[53]106void GraphDisplayerCanvas::clear()
[6]107{
[53]108  active_node=INVALID;
109  active_edge=INVALID;
110  forming_edge=INVALID;
[6]111
[53]112  for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
[6]113  {
[53]114    delete nodesmap[n];
115    delete nodetextmap[n];
[6]116  }
117
[53]118  for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
119  {
120    delete edgesmap[e];
121    delete edgetextmap[e];
122  }
[6]123}
Note: See TracBrowser for help on using the repository browser.