#include #include #include GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms, MapWin * mw):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),nodetextmap(g),displayed_graph(*(root()), 0, 0),canvasentrywidget(NULL),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL),nodemap_to_edit(""),edgemap_to_edit(""),mapwin(mw) { active_node=INVALID; active_edge=INVALID; forming_edge=INVALID; //setting event handler for the editor widget entrywidget.signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::entryWidgetChangeHandler), false); //base event handler is move tool actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); actual_tool=MOVE; //set_center_scroll_region(true); //first edges are drawn, to hide joining with nodes later for (EdgeIt i(g); i!=INVALID; ++i) { //drawing green lines, coordinates are from cm Gnome::Canvas::Points coos; coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y)); edgesmap[i]=new BrokenEdge(displayed_graph, coos, *this); *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); edgesmap[i]->property_width_pixels().set_value(10); //initializing edge-text as well, to empty string xy text_pos=edgesmap[i]->getArrowPos(); text_pos+=(xy(10,10)); edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); edgetextmap[i]->property_fill_color().set_value("darkgreen"); } //afterwards nodes come to be drawn NodeIt i(g); int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; for (; i!=INVALID; ++i) { //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen) if(cm[i].x>maxx)maxx=(int)cm[i].x; if(cm[i].y>maxy)maxy=(int)cm[i].y; if(cm[i].x text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5)); nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); nodetextmap[i]->property_fill_color().set_value("darkblue"); } updateScrollRegion(); } GraphDisplayerCanvas::~GraphDisplayerCanvas() { if(canvasentrywidget) { delete(canvasentrywidget); } //writing out the end state of the graph //\todo all the maps has to be write out! Graph::NodeMap id(g); Graph::NodeMap xc(g); Graph::NodeMap yc(g); int j=1; for (NodeIt i(g); i!=INVALID; ++i) { double x1,y1,x2,y2; nodesmap[i]->get_bounds(x1, y1, x2, y2); id[i]=j++; xc[i]=(x1+x2)/2; yc[i]=(y1+y2)/2; } GraphWriter writer(std::cout,g); writer.writeNodeMap("id", id); writer.writeNodeMap("coordinates_x", xc); writer.writeNodeMap("coordinates_y", yc); writer.run(); }