ladanyi@1442: #include hegyi@1497: #include ladanyi@1442: #include ladanyi@1442: hegyi@1581: 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) ladanyi@1442: { hegyi@1468: hegyi@1592: //Initializing values. hegyi@1562: active_node=INVALID; hegyi@1562: active_edge=INVALID; hegyi@1579: forming_edge=INVALID; 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: hegyi@1562: //base event handler is move tool hegyi@1525: actual_handler=signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::moveEventHandler), false); hegyi@1579: actual_tool=MOVE; hegyi@1468: ladanyi@1442: //set_center_scroll_region(true); ladanyi@1442: ladanyi@1442: //first edges are drawn, to hide joining with nodes later ladanyi@1442: ladanyi@1442: for (EdgeIt i(g); i!=INVALID; ++i) ladanyi@1442: { ladanyi@1442: ladanyi@1442: //drawing green lines, coordinates are from cm ladanyi@1442: ladanyi@1442: Gnome::Canvas::Points coos; ladanyi@1442: coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); ladanyi@1442: coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.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"); ladanyi@1442: edgesmap[i]->property_width_pixels().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"); ladanyi@1442: } ladanyi@1442: ladanyi@1442: //afterwards nodes come to be drawn ladanyi@1442: ladanyi@1442: NodeIt i(g); ladanyi@1442: int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; ladanyi@1442: ladanyi@1442: for (; i!=INVALID; ++i) ladanyi@1442: { ladanyi@1442: //minimum and maximum is gathered to be able to zoom to the graph correctly (whole figure should be seen) ladanyi@1442: ladanyi@1442: if(cm[i].x>maxx)maxx=(int)cm[i].x; ladanyi@1442: if(cm[i].y>maxy)maxy=(int)cm[i].y; ladanyi@1442: if(cm[i].x text_pos((cm[i].x+node_property_defaults[N_RADIUS]+5),(cm[i].y+node_property_defaults[N_RADIUS]+5)); hegyi@1512: hegyi@1512: nodetextmap[i]=new Gnome::Canvas::Text(displayed_graph, text_pos.x, text_pos.y, ""); hegyi@1512: nodetextmap[i]->property_fill_color().set_value("darkblue"); ladanyi@1442: } ladanyi@1442: ladanyi@1442: updateScrollRegion(); ladanyi@1442: } ladanyi@1442: ladanyi@1442: GraphDisplayerCanvas::~GraphDisplayerCanvas() ladanyi@1442: { hegyi@1550: if(canvasentrywidget) hegyi@1550: { hegyi@1550: delete(canvasentrywidget); hegyi@1550: } ladanyi@1442: ladanyi@1442: //writing out the end state of the graph ladanyi@1442: //\todo all the maps has to be write out! ladanyi@1442: ladanyi@1442: Graph::NodeMap id(g); ladanyi@1442: Graph::NodeMap xc(g); ladanyi@1442: Graph::NodeMap yc(g); ladanyi@1442: ladanyi@1442: int j=1; ladanyi@1442: ladanyi@1442: for (NodeIt i(g); i!=INVALID; ++i) ladanyi@1442: { ladanyi@1442: double x1,y1,x2,y2; ladanyi@1442: nodesmap[i]->get_bounds(x1, y1, x2, y2); ladanyi@1442: ladanyi@1442: id[i]=j++; ladanyi@1442: xc[i]=(x1+x2)/2; ladanyi@1442: yc[i]=(y1+y2)/2; ladanyi@1442: } ladanyi@1442: ladanyi@1442: GraphWriter writer(std::cout,g); ladanyi@1442: ladanyi@1442: writer.writeNodeMap("id", id); ladanyi@1442: writer.writeNodeMap("coordinates_x", xc); ladanyi@1442: writer.writeNodeMap("coordinates_y", yc); ladanyi@1442: writer.run(); ladanyi@1442: }