ladanyi@6: #include hegyi@17: #include ladanyi@6: #include ladanyi@6: hegyi@20: GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(0),active_item(NULL),target_item(NULL) ladanyi@6: { hegyi@9: hegyi@21: actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::create_node_event_handler), false); hegyi@21: actual_tool=CREATE_NODE; hegyi@9: hegyi@12: active_node=INVALID; hegyi@12: active_edge=INVALID; hegyi@12: ladanyi@6: //set_center_scroll_region(true); ladanyi@6: ladanyi@6: //first edges are drawn, to hide joining with nodes later ladanyi@6: ladanyi@6: for (EdgeIt i(g); i!=INVALID; ++i) ladanyi@6: { ladanyi@6: ladanyi@6: //drawing green lines, coordinates are from cm ladanyi@6: ladanyi@6: Gnome::Canvas::Points coos; ladanyi@6: coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); ladanyi@6: coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.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"); ladanyi@6: edgesmap[i]->property_width_pixels().set_value(10); ladanyi@6: ladanyi@6: //initializing edge-text as well, to empty string ladanyi@6: hegyi@25: xy text_pos=edgesmap[i]->get_arrow_pos(); 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, ""); ladanyi@6: edgetextmap[i]->property_fill_color().set_value("black"); ladanyi@6: } ladanyi@6: ladanyi@6: //afterwards nodes come to be drawn ladanyi@6: ladanyi@6: NodeIt i(g); ladanyi@6: int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; ladanyi@6: ladanyi@6: for (; i!=INVALID; ++i) ladanyi@6: { ladanyi@6: //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen) ladanyi@6: ladanyi@6: if(cm[i].x>maxx)maxx=(int)cm[i].x; ladanyi@6: if(cm[i].y>maxy)maxy=(int)cm[i].y; ladanyi@6: if(cm[i].xsignal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); ladanyi@6: } ladanyi@6: ladanyi@6: updateScrollRegion(); ladanyi@6: } ladanyi@6: ladanyi@6: GraphDisplayerCanvas::~GraphDisplayerCanvas() ladanyi@6: { ladanyi@6: ladanyi@6: //writing out the end state of the graph ladanyi@6: //\todo all the maps has to be write out! ladanyi@6: ladanyi@6: Graph::NodeMap id(g); ladanyi@6: Graph::NodeMap xc(g); ladanyi@6: Graph::NodeMap yc(g); ladanyi@6: ladanyi@6: int j=1; ladanyi@6: ladanyi@6: for (NodeIt i(g); i!=INVALID; ++i) ladanyi@6: { ladanyi@6: double x1,y1,x2,y2; ladanyi@6: nodesmap[i]->get_bounds(x1, y1, x2, y2); ladanyi@6: ladanyi@6: id[i]=j++; ladanyi@6: xc[i]=(x1+x2)/2; ladanyi@6: yc[i]=(y1+y2)/2; ladanyi@6: } ladanyi@6: ladanyi@6: GraphWriter writer(std::cout,g); ladanyi@6: ladanyi@6: writer.writeNodeMap("id", id); ladanyi@6: writer.writeNodeMap("coordinates_x", xc); ladanyi@6: writer.writeNodeMap("coordinates_y", yc); ladanyi@6: writer.run(); ladanyi@6: }