COIN-OR::LEMON - Graph Library

source: glemon-0.x/graph_displayer_canvas.cc @ 89:4042761b21e3

gui
Last change on this file since 89:4042761b21e3 was 89:4042761b21e3, checked in by Hegyi Péter, 16 years ago

Reorganizing.

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