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