[1606] | 1 | #include "graph_displayer_canvas.h" |
---|
[1632] | 2 | #include <cmath> |
---|
[1442] | 3 | |
---|
[1614] | 4 | GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw, Gtk::Window * mainwin) : |
---|
[1606] | 5 | nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph), |
---|
[1648] | 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) |
---|
[1442] | 9 | { |
---|
[1614] | 10 | parentwin=mainwin; |
---|
| 11 | |
---|
[1606] | 12 | //base event handler is move tool |
---|
| 13 | actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); |
---|
| 14 | actual_tool=MOVE; |
---|
[1562] | 15 | |
---|
[1606] | 16 | active_node=INVALID; |
---|
| 17 | active_edge=INVALID; |
---|
| 18 | forming_edge=INVALID; |
---|
| 19 | } |
---|
[1468] | 20 | |
---|
[1606] | 21 | GraphDisplayerCanvas::~GraphDisplayerCanvas() |
---|
| 22 | { |
---|
| 23 | for (NodeIt n(mapstorage.graph); n != INVALID; ++n) |
---|
| 24 | { |
---|
| 25 | delete nodesmap[n]; |
---|
| 26 | delete nodetextmap[n]; |
---|
| 27 | } |
---|
[1442] | 28 | |
---|
[1606] | 29 | for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) |
---|
| 30 | { |
---|
| 31 | delete edgesmap[e]; |
---|
| 32 | delete edgetextmap[e]; |
---|
| 33 | } |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | void GraphDisplayerCanvas::drawGraph() |
---|
| 37 | { |
---|
[1442] | 38 | //first edges are drawn, to hide joining with nodes later |
---|
| 39 | |
---|
[1606] | 40 | for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1442] | 41 | { |
---|
| 42 | |
---|
[1606] | 43 | //drawing green lines, coordinates are from mapstorage.coords |
---|
[1442] | 44 | |
---|
| 45 | Gnome::Canvas::Points coos; |
---|
[1606] | 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)); |
---|
[1442] | 52 | |
---|
[1501] | 53 | edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this); |
---|
[1442] | 54 | *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); |
---|
[1598] | 55 | edgesmap[i]->property_width_units().set_value(10); |
---|
[1645] | 56 | edgesmap[i]->lower_to_bottom(); |
---|
[1442] | 57 | |
---|
| 58 | //initializing edge-text as well, to empty string |
---|
| 59 | |
---|
[1524] | 60 | xy<double> text_pos=edgesmap[i]->getArrowPos(); |
---|
[1505] | 61 | text_pos+=(xy<double>(10,10)); |
---|
| 62 | |
---|
| 63 | edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); |
---|
[1512] | 64 | edgetextmap[i]->property_fill_color().set_value("darkgreen"); |
---|
[1599] | 65 | edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false); |
---|
[1645] | 66 | edgetextmap[i]->raise_to_top(); |
---|
[1442] | 67 | } |
---|
| 68 | |
---|
| 69 | //afterwards nodes come to be drawn |
---|
| 70 | |
---|
[1606] | 71 | for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) |
---|
[1442] | 72 | { |
---|
| 73 | //drawing bule nodes, with black line around them |
---|
| 74 | |
---|
[1606] | 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); |
---|
[1442] | 81 | *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); |
---|
| 82 | *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); |
---|
[1645] | 83 | nodesmap[i]->raise_to_top(); |
---|
[1512] | 84 | |
---|
| 85 | //initializing edge-text as well, to empty string |
---|
| 86 | |
---|
[1606] | 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)); |
---|
[1512] | 90 | |
---|
[1606] | 91 | nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, |
---|
| 92 | text_pos.x, text_pos.y, ""); |
---|
[1512] | 93 | nodetextmap[i]->property_fill_color().set_value("darkblue"); |
---|
[1599] | 94 | nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); |
---|
[1645] | 95 | nodetextmap[i]->raise_to_top(); |
---|
[1442] | 96 | } |
---|
| 97 | |
---|
| 98 | updateScrollRegion(); |
---|
| 99 | } |
---|
| 100 | |
---|
[1606] | 101 | void GraphDisplayerCanvas::clear() |
---|
[1442] | 102 | { |
---|
[1606] | 103 | active_node=INVALID; |
---|
| 104 | active_edge=INVALID; |
---|
| 105 | forming_edge=INVALID; |
---|
[1442] | 106 | |
---|
[1606] | 107 | for (NodeIt n(mapstorage.graph); n != INVALID; ++n) |
---|
[1442] | 108 | { |
---|
[1606] | 109 | delete nodesmap[n]; |
---|
| 110 | delete nodetextmap[n]; |
---|
[1442] | 111 | } |
---|
| 112 | |
---|
[1606] | 113 | for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) |
---|
| 114 | { |
---|
| 115 | delete edgesmap[e]; |
---|
| 116 | delete edgetextmap[e]; |
---|
| 117 | } |
---|
[1442] | 118 | } |
---|