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