ladanyi@1606: #include "graph_displayer_canvas.h" ladanyi@1606: #include "broken_edge.h" ladanyi@1442: #include ladanyi@1442: ladanyi@1606: GraphDisplayerCanvas::GraphDisplayerCanvas(MapStorage & ms, MapWin & mw) : ladanyi@1606: nodesmap(ms.graph), edgesmap(ms.graph), edgetextmap(ms.graph), ladanyi@1606: nodetextmap(ms.graph), displayed_graph(*(root()), 0, 0), ladanyi@1606: canvasentrywidget(NULL), mapstorage(ms), isbutton(0), active_item(NULL), ladanyi@1606: target_item(NULL), nodemap_to_edit(""), edgemap_to_edit(""), mapwin(mw) ladanyi@1442: { ladanyi@1606: //base event handler is move tool ladanyi@1606: actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); ladanyi@1606: actual_tool=MOVE; hegyi@1562: hegyi@1562: //setting event handler for the editor widget hegyi@1562: entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false); hegyi@1562: ladanyi@1606: active_node=INVALID; ladanyi@1606: active_edge=INVALID; ladanyi@1606: forming_edge=INVALID; ladanyi@1606: } hegyi@1468: ladanyi@1606: GraphDisplayerCanvas::~GraphDisplayerCanvas() ladanyi@1606: { ladanyi@1606: for (NodeIt n(mapstorage.graph); n != INVALID; ++n) ladanyi@1606: { ladanyi@1606: delete nodesmap[n]; ladanyi@1606: delete nodetextmap[n]; ladanyi@1606: } ladanyi@1442: ladanyi@1606: for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) ladanyi@1606: { ladanyi@1606: delete edgesmap[e]; ladanyi@1606: delete edgetextmap[e]; ladanyi@1606: } ladanyi@1606: ladanyi@1606: if(canvasentrywidget) ladanyi@1606: { ladanyi@1606: delete(canvasentrywidget); ladanyi@1606: } ladanyi@1606: } ladanyi@1606: ladanyi@1606: void GraphDisplayerCanvas::drawGraph() ladanyi@1606: { ladanyi@1442: //first edges are drawn, to hide joining with nodes later ladanyi@1442: ladanyi@1606: for (EdgeIt i(mapstorage.graph); i!=INVALID; ++i) ladanyi@1442: { ladanyi@1442: ladanyi@1606: //drawing green lines, coordinates are from mapstorage.coords ladanyi@1442: ladanyi@1442: Gnome::Canvas::Points coos; ladanyi@1606: coos.push_back(Gnome::Art::Point( ladanyi@1606: mapstorage.coords[mapstorage.graph.source(i)].x, ladanyi@1606: mapstorage.coords[mapstorage.graph.source(i)].y)); ladanyi@1606: coos.push_back(Gnome::Art::Point( ladanyi@1606: mapstorage.coords[mapstorage.graph.target(i)].x, ladanyi@1606: mapstorage.coords[mapstorage.graph.target(i)].y)); ladanyi@1442: hegyi@1501: edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this); ladanyi@1442: *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); hegyi@1598: edgesmap[i]->property_width_units().set_value(10); ladanyi@1442: ladanyi@1442: //initializing edge-text as well, to empty string ladanyi@1442: hegyi@1524: xy text_pos=edgesmap[i]->getArrowPos(); hegyi@1505: text_pos+=(xy(10,10)); hegyi@1505: hegyi@1505: edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); hegyi@1512: edgetextmap[i]->property_fill_color().set_value("darkgreen"); hegyi@1599: edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::edgeMapEditEventHandler), false); ladanyi@1442: } ladanyi@1442: ladanyi@1442: //afterwards nodes come to be drawn ladanyi@1442: ladanyi@1606: for (NodeIt i(mapstorage.graph); i!=INVALID; ++i) ladanyi@1442: { ladanyi@1442: //drawing bule nodes, with black line around them ladanyi@1442: ladanyi@1606: nodesmap[i]=new Gnome::Canvas::Ellipse( ladanyi@1606: displayed_graph, ladanyi@1606: mapstorage.coords[i].x-20, ladanyi@1606: mapstorage.coords[i].y-20, ladanyi@1606: mapstorage.coords[i].x+20, ladanyi@1606: mapstorage.coords[i].y+20); ladanyi@1442: *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); ladanyi@1442: *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); hegyi@1512: hegyi@1512: //initializing edge-text as well, to empty string hegyi@1512: ladanyi@1606: xy text_pos( ladanyi@1606: (mapstorage.coords[i].x+node_property_defaults[N_RADIUS]+5), ladanyi@1606: (mapstorage.coords[i].y+node_property_defaults[N_RADIUS]+5)); hegyi@1512: ladanyi@1606: nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, ladanyi@1606: text_pos.x, text_pos.y, ""); hegyi@1512: nodetextmap[i]->property_fill_color().set_value("darkblue"); hegyi@1599: nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::nodeMapEditEventHandler), false); ladanyi@1442: } ladanyi@1442: ladanyi@1442: updateScrollRegion(); ladanyi@1442: } ladanyi@1442: ladanyi@1606: void GraphDisplayerCanvas::clear() ladanyi@1442: { ladanyi@1606: active_node=INVALID; ladanyi@1606: active_edge=INVALID; ladanyi@1606: forming_edge=INVALID; ladanyi@1442: ladanyi@1606: for (NodeIt n(mapstorage.graph); n != INVALID; ++n) ladanyi@1442: { ladanyi@1606: delete nodesmap[n]; ladanyi@1606: delete nodetextmap[n]; ladanyi@1442: } ladanyi@1442: ladanyi@1606: for (EdgeIt e(mapstorage.graph); e != INVALID; ++e) ladanyi@1606: { ladanyi@1606: delete edgesmap[e]; ladanyi@1606: delete edgetextmap[e]; ladanyi@1606: } ladanyi@1442: }