ladanyi@1412: #include ladanyi@1412: ladanyi@1412: GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm, MapStorage & ms):g(gr),nodesmap(g),edgesmap(g),edgetextmap(g),displayed_graph(*(root()), 0, 0),mapstorage(ms),isbutton(false),active_item(NULL) ladanyi@1412: { ladanyi@1412: ladanyi@1412: for (EdgeIt i(g); i!=INVALID; ++i) ladanyi@1412: { ladanyi@1412: Gnome::Canvas::Points coos; ladanyi@1412: coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); ladanyi@1412: coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y)); ladanyi@1412: ladanyi@1412: edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos); ladanyi@1412: *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); ladanyi@1412: edgesmap[i]->property_width_pixels().set_value(10); ladanyi@1412: ladanyi@1412: ladanyi@1412: double x1, x2, y1, y2; ladanyi@1412: edgesmap[i]->get_bounds(x1, y1, x2, y2); ladanyi@1412: ladanyi@1412: edgetextmap[i]=new Gnome::Canvas::Text(displayed_graph,(x1+x2)/2, (y1+y2)/2, ""); ladanyi@1412: edgetextmap[i]->property_fill_color().set_value("black"); ladanyi@1412: } ladanyi@1412: ladanyi@1412: NodeIt i(g); ladanyi@1412: int maxx=0, maxy=0, minx=(int)cm[i].x, miny=(int)cm[i].y; ladanyi@1412: ladanyi@1412: for (; i!=INVALID; ++i) ladanyi@1412: { ladanyi@1412: if(cm[i].x>maxx)maxx=(int)cm[i].x; ladanyi@1412: if(cm[i].y>maxy)maxy=(int)cm[i].y; ladanyi@1412: if(cm[i].xsignal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); ladanyi@1412: } ladanyi@1412: ladanyi@1412: double biggest_x=(abs(maxx)>abs(minx))?(abs(maxx)+80):(abs(minx)+80); ladanyi@1412: double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); ladanyi@1412: ladanyi@1412: set_pixels_per_unit((biggest_x>biggest_y)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2)); ladanyi@1412: std::cout< id(g); ladanyi@1412: Graph::NodeMap xc(g); ladanyi@1412: Graph::NodeMap yc(g); ladanyi@1412: ladanyi@1412: int j=1; ladanyi@1412: ladanyi@1412: for (NodeIt i(g); i!=INVALID; ++i) ladanyi@1412: { ladanyi@1412: double x1,y1,x2,y2; ladanyi@1412: nodesmap[i]->get_bounds(x1, y1, x2, y2); ladanyi@1412: ladanyi@1412: id[i]=j++; ladanyi@1412: xc[i]=(x1+x2)/2; ladanyi@1412: yc[i]=(y1+y2)/2; ladanyi@1412: } ladanyi@1412: ladanyi@1412: GraphWriter writer(std::cout,g); ladanyi@1412: ladanyi@1412: writer.writeNodeMap("id", id); ladanyi@1412: writer.writeNodeMap("coordinates_x", xc); ladanyi@1412: writer.writeNodeMap("coordinates_y", yc); ladanyi@1412: writer.run(); ladanyi@1412: } ladanyi@1412: ladanyi@1412: int GraphDisplayerCanvas::changeLineWidth (std::string mapname) ladanyi@1412: { ladanyi@1412: for (EdgeIt i(g); i!=INVALID; ++i) ladanyi@1412: { ladanyi@1412: int w=(int)(*(mapstorage.edgemap_storage)[mapname])[i]; ladanyi@1412: edgesmap[i]->property_width_pixels().set_value(w); ladanyi@1412: } ladanyi@1412: return 0; ladanyi@1412: }; ladanyi@1412: ladanyi@1412: int GraphDisplayerCanvas::changeColor (std::string mapname) ladanyi@1412: { ladanyi@1412: for (EdgeIt i(g); i!=INVALID; ++i) ladanyi@1412: { ladanyi@1412: double w=(*(mapstorage.edgemap_storage)[mapname])[i]; ladanyi@1412: double max=mapstorage.maxOfEdgeMap(mapname); ladanyi@1412: double min=mapstorage.minOfEdgeMap(mapname); ladanyi@1412: ladanyi@1412: //std::cout<property_fill_color_gdk().set_value(color); ladanyi@1412: } ladanyi@1412: return 0; ladanyi@1412: }; ladanyi@1412: ladanyi@1412: int GraphDisplayerCanvas::changeText (std::string mapname) ladanyi@1412: { ladanyi@1412: for (EdgeIt i(g); i!=INVALID; ++i) ladanyi@1412: { ladanyi@1412: if(mapname!="Text") ladanyi@1412: { ladanyi@1412: double number=(*(mapstorage.edgemap_storage)[mapname])[i]; ladanyi@1412: int length=(int)(floor(log(number)/log(10)))+1; ladanyi@1412: int maxpos=(int)(pow(10,length-1)); ladanyi@1412: int strl=length+1+RANGE; ladanyi@1412: char * str=new char[strl]; ladanyi@1412: str[length]='.'; ladanyi@1412: str[strl]='\0'; ladanyi@1412: ladanyi@1412: for(int j=0;jproperty_text().set_value(str); ladanyi@1412: } ladanyi@1412: else ladanyi@1412: { ladanyi@1412: edgetextmap[i]->property_text().set_value(""); ladanyi@1412: } ladanyi@1412: } ladanyi@1412: return 0; ladanyi@1412: }; ladanyi@1412: ladanyi@1412: ladanyi@1412: int GraphDisplayerCanvas::rezoom () ladanyi@1412: { ladanyi@1412: double x1, x2, y1, y2; ladanyi@1412: int x,y; ladanyi@1412: ladanyi@1412: NodeIt i(g); ladanyi@1412: nodesmap[i]->get_bounds(x1, y1, x2, y2); ladanyi@1412: ladanyi@1412: x=(int)((x1+x2)/2); ladanyi@1412: y=(int)((y1+y2)/2); ladanyi@1412: ladanyi@1412: int maxx=0, maxy=0, minx=(int)x, miny=(int)y; ladanyi@1412: ladanyi@1412: for (; i!=INVALID; ++i) ladanyi@1412: { ladanyi@1412: nodesmap[i]->get_bounds(x1, y1, x2, y2); ladanyi@1412: ladanyi@1412: x=(int)((x1+x2)/2); ladanyi@1412: y=(int)((y1+y2)/2); ladanyi@1412: ladanyi@1412: if(x>maxx)maxx=x; ladanyi@1412: if(y>maxy)maxy=y; ladanyi@1412: if(xabs(minx))?(abs(maxx)+80):(abs(minx)+80); ladanyi@1412: double biggest_y=(abs(maxy)>abs(miny))?(abs(maxy)+80):(abs(miny)+80); ladanyi@1412: ladanyi@1412: set_pixels_per_unit((biggest_x-WIN_WIDTH>biggest_y-WIN_HEIGHT)?(WIN_WIDTH/biggest_x/2):(WIN_HEIGHT/biggest_y/2)); ladanyi@1412: return 0; ladanyi@1412: }; ladanyi@1412: ladanyi@1412: ladanyi@1412: ///This function moves only one node of displayed_graph, ladanyi@1412: ///but recalculate the location of weight point, ladanyi@1412: ///and also redraw the sides of the planefigure. ladanyi@1412: bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) ladanyi@1412: { ladanyi@1412: switch(e->type) ladanyi@1412: { ladanyi@1412: case GDK_BUTTON_PRESS: ladanyi@1412: clicked_x=e->button.x; ladanyi@1412: clicked_y=e->button.y; ladanyi@1412: active_item=(get_item_at(e->button.x, e->button.y)); ladanyi@1412: isbutton=true; ladanyi@1412: break; ladanyi@1412: case GDK_BUTTON_RELEASE: ladanyi@1412: isbutton=false; ladanyi@1412: active_item=NULL; ladanyi@1412: break; ladanyi@1412: case GDK_MOTION_NOTIFY: ladanyi@1412: if(isbutton) ladanyi@1412: { ladanyi@1412: double dx=e->motion.x-clicked_x; ladanyi@1412: double dy=e->motion.y-clicked_y; ladanyi@1412: active_item->move(dx, dy); ladanyi@1412: clicked_x=e->motion.x; ladanyi@1412: clicked_y=e->motion.y; ladanyi@1412: ladanyi@1412: EdgeIt e; ladanyi@1412: ladanyi@1412: g.firstOut(e,n); ladanyi@1412: for(;e!=INVALID;g.nextOut(e)) ladanyi@1412: { ladanyi@1412: Gnome::Canvas::Points coos; ladanyi@1412: double x1, x2, y1, y2; ladanyi@1412: ladanyi@1412: nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); ladanyi@1412: coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); ladanyi@1412: ladanyi@1412: nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); ladanyi@1412: coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); ladanyi@1412: ladanyi@1412: edgesmap[e]->property_points().set_value(coos); ladanyi@1412: ladanyi@1412: edgesmap[e]->get_bounds(x1, y1, x2, y2); ladanyi@1412: ladanyi@1412: edgetextmap[e]->property_x().set_value((x1+x2)/2); ladanyi@1412: edgetextmap[e]->property_y().set_value((y1+y2)/2); ladanyi@1412: } ladanyi@1412: ladanyi@1412: g.firstIn(e,n); ladanyi@1412: for(;e!=INVALID;g.nextIn(e)) ladanyi@1412: { ladanyi@1412: Gnome::Canvas::Points coos; ladanyi@1412: double x1, x2, y1, y2; ladanyi@1412: ladanyi@1412: nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); ladanyi@1412: coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); ladanyi@1412: ladanyi@1412: nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); ladanyi@1412: coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); ladanyi@1412: ladanyi@1412: edgesmap[e]->property_points().set_value(coos); ladanyi@1412: ladanyi@1412: edgesmap[e]->get_bounds(x1, y1, x2, y2); ladanyi@1412: ladanyi@1412: edgetextmap[e]->property_x().set_value((x1+x2)/2); ladanyi@1412: edgetextmap[e]->property_y().set_value((y1+y2)/2); ladanyi@1412: } ladanyi@1412: } ladanyi@1412: default: break; ladanyi@1412: } ladanyi@1412: return true; ladanyi@1412: } ladanyi@1412: ladanyi@1412: bool GraphDisplayerCanvas::on_expose_event(GdkEventExpose *event) ladanyi@1412: { ladanyi@1412: Gnome::Canvas::CanvasAA::on_expose_event(event); ladanyi@1412: //usleep(10000); ladanyi@1412: //rezoom(); ladanyi@1412: return true; ladanyi@1412: }