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