1 #include "graph_displayer_canvas.h"
2 #include "broken_edge.h"
5 GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) :
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)
11 //base event handler is move tool
12 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
15 //setting event handler for the editor widget
16 entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false);
23 GraphDisplayerCanvas::~GraphDisplayerCanvas()
25 for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
28 delete nodetextmap[n];
31 for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
34 delete edgetextmap[e];
39 delete(canvasentrywidget);
43 void GraphDisplayerCanvas::drawGraph()
45 //first edges are drawn, to hide joining with nodes later
47 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
50 //drawing green lines, coordinates are from mapstorage.coords
52 Gnome::Canvas::Points coos;
53 coos.push_back(Gnome::Art::Point(
54 mapstorage.coords[mapstorage.graph.source(i)].x,
55 mapstorage.coords[mapstorage.graph.source(i)].y));
56 coos.push_back(Gnome::Art::Point(
57 mapstorage.coords[mapstorage.graph.target(i)].x,
58 mapstorage.coords[mapstorage.graph.target(i)].y));
60 edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
61 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
62 edgesmap[i]->property_width_units().set_value(10);
64 //initializing edge-text as well, to empty string
66 xy<double> text_pos=edgesmap[i]->getArrowPos();
67 text_pos+=(xy<double>(10,10));
69 edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
70 edgetextmap[i]->property_fill_color().set_value("darkgreen");
71 edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
74 //afterwards nodes come to be drawn
76 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
78 //drawing bule nodes, with black line around them
80 nodesmap[i]=new Gnome::Canvas::Ellipse(
82 mapstorage.coords[i].x-20,
83 mapstorage.coords[i].y-20,
84 mapstorage.coords[i].x+20,
85 mapstorage.coords[i].y+20);
86 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
87 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
89 //initializing edge-text as well, to empty string
92 (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
93 (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
95 nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
96 text_pos.x, text_pos.y, "");
97 nodetextmap[i]->property_fill_color().set_value("darkblue");
98 nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
101 updateScrollRegion();
104 void GraphDisplayerCanvas::clear()
108 forming_edge=INVALID;
110 for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
113 delete nodetextmap[n];
116 for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
119 delete edgetextmap[e];