NewMapWin has become Dialog instead of Window. Therefore it is created dynamically, when there is need for it, instead of keeping one instance in memory. This solution is slower, but more correct than before.
1 #include "graph_displayer_canvas.h"
4 GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) :
5 nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph),
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)
12 //base event handler is move tool
13 actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false);
21 GraphDisplayerCanvas::~GraphDisplayerCanvas()
23 for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
26 delete nodetextmap[n];
29 for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
32 delete edgetextmap[e];
36 void GraphDisplayerCanvas::drawGraph()
38 //first edges are drawn, to hide joining with nodes later
40 for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i)
43 //drawing green lines, coordinates are from mapstorage.coords
45 Gnome::Canvas::Points coos;
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));
53 edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this);
54 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green");
55 edgesmap[i]->property_width_units().set_value(10);
56 edgesmap[i]->lower_to_bottom();
58 //initializing edge-text as well, to empty string
60 xy<double> text_pos=edgesmap[i]->getArrowPos();
61 text_pos+=(xy<double>(10,10));
63 edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, "");
64 edgetextmap[i]->property_fill_color().set_value("darkgreen");
65 edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false);
66 edgetextmap[i]->raise_to_top();
69 //afterwards nodes come to be drawn
71 for (NodeIt i(mapstorage.graph); i!=INVALID; ++i)
73 //drawing bule nodes, with black line around them
75 nodesmap[i]=new Gnome::Canvas::Ellipse(
77 mapstorage.coords[i].x-20,
78 mapstorage.coords[i].y-20,
79 mapstorage.coords[i].x+20,
80 mapstorage.coords[i].y+20);
81 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue");
82 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black");
83 nodesmap[i]->raise_to_top();
85 //initializing edge-text as well, to empty string
88 (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5),
89 (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5));
91 nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph,
92 text_pos.x, text_pos.y, "");
93 nodetextmap[i]->property_fill_color().set_value("darkblue");
94 nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false);
95 nodetextmap[i]->raise_to_top();
101 void GraphDisplayerCanvas::clear()
105 forming_edge=INVALID;
107 for (NodeIt n(mapstorage.graph); n != INVALID; ++n)
110 delete nodetextmap[n];
113 for (EdgeIt e(mapstorage.graph); e != INVALID; ++e)
116 delete edgetextmap[e];