ladanyi@53: #include "graph_displayer_canvas.h" hegyi@167: #include alpar@59: #include ladanyi@6: hegyi@96: GraphDisplayerCanvas::GraphDisplayerCanvas(NoteBookTab & mainw) : hegyi@94: nodesmap(mainw.mapstorage.graph), edgesmap(mainw.mapstorage.graph), edgetextmap(mainw.mapstorage.graph), hegyi@94: nodetextmap(mainw.mapstorage.graph), displayed_graph(*(root()), 0, 0), ladanyi@66: isbutton(0), active_item(NULL), target_item(NULL), nodemap_to_edit(""), hegyi@160: edgemap_to_edit(""), autoscale(true), zoomtrack(false), radius_size(20), edge_width(10), hegyi@172: iterations(20), attraction(0.05), propulsation(40000), was_redesigned(false), is_drawn(false), mytab(mainw) ladanyi@6: { 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: 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: { hegyi@96: for (NodeIt n((mytab.mapstorage).graph); n != INVALID; ++n) hegyi@94: { hegyi@94: delete nodesmap[n]; hegyi@94: delete nodetextmap[n]; hegyi@94: } hegyi@94: hegyi@96: for (EdgeIt e((mytab.mapstorage).graph); e != INVALID; ++e) hegyi@94: { hegyi@94: delete edgesmap[e]; hegyi@94: delete edgetextmap[e]; hegyi@94: } hegyi@94: } ladanyi@6: hegyi@94: void GraphDisplayerCanvas::propertyChange(bool itisedge, int prop) hegyi@94: { hegyi@94: if(itisedge) hegyi@94: { hegyi@94: propertyUpdate(Edge(INVALID), prop); hegyi@94: } hegyi@94: else hegyi@94: { hegyi@94: propertyUpdate(Node(INVALID), prop); hegyi@94: } hegyi@94: } hegyi@94: hegyi@94: void GraphDisplayerCanvas::propertyUpdate(Edge edge) hegyi@94: { hegyi@94: for(int i=0;iproperty_fill_color().set_value("darkgreen"); hegyi@149: edgetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false); ladanyi@63: edgetextmap[i]->raise_to_top(); ladanyi@6: } ladanyi@6: ladanyi@6: //afterwards nodes come to be drawn ladanyi@6: hegyi@96: for (NodeIt i((mytab.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, hegyi@96: (mytab.mapstorage).coords[i].x-20, hegyi@96: (mytab.mapstorage).coords[i].y-20, hegyi@96: (mytab.mapstorage).coords[i].x+20, hegyi@96: (mytab.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: hegyi@150: XY text_pos( hegyi@96: ((mytab.mapstorage).coords[i].x+node_property_defaults[N_RADIUS]+5), hegyi@96: ((mytab.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@149: nodetextmap[i]->signal_event().connect(sigc::mem_fun(*this, &GraphDisplayerCanvas::mapEditEventHandler), false); ladanyi@63: nodetextmap[i]->raise_to_top(); ladanyi@6: } ladanyi@6: hegyi@172: is_drawn=true; hegyi@172: hegyi@172: //upon drawing graph hegyi@172: //properties have to hegyi@172: //be set in as well hegyi@172: for(int i=0;i init(init_vector_length*rnd(), alpar@168: init_vector_length*rnd()); hegyi@166: moveNode(init.x, init.y, nodesmap[i], i); hegyi@166: was_redesigned=true; hegyi@166: } hegyi@166: hegyi@160: hegyi@160: //iteration counter hegyi@160: for(int l=0;l x(mytab.mapstorage.graph); hegyi@160: Graph::NodeMap y(mytab.mapstorage.graph); hegyi@160: XYMap > actual_forces; hegyi@160: actual_forces.setXMap(x); hegyi@160: actual_forces.setYMap(y); hegyi@160: hegyi@160: lemon::dim2::Point delta; hegyi@160: hegyi@160: //count actual force for each nodes hegyi@160: for (NodeIt i((mytab.mapstorage).graph); i!=INVALID; ++i) hegyi@160: { hegyi@160: //propulsation of nodes hegyi@160: for (NodeIt j((mytab.mapstorage).graph); j!=INVALID; ++j) hegyi@160: { hegyi@160: if(i!=j) hegyi@160: { hegyi@160: delta=((mytab.mapstorage).coords[i]-(mytab.mapstorage).coords[j]); hegyi@160: hegyi@160: double length_sqr=delta.normSquare(); hegyi@160: double length=sqrt(length_sqr); hegyi@160: if(length_sqr