# HG changeset patch # User hegyi # Date 1112642524 0 # Node ID 1f3baf3bd1f2360f7ab42f2ccec47d15fe0c4f2c # Parent d1fc1bf7deccb3312711c82b725d82bc1af5b7b0 Graph displayer displays graphs now. diff -r d1fc1bf7decc -r 1f3baf3bd1f2 src/work/peter/graph-displayer.cc --- a/src/work/peter/graph-displayer.cc Mon Apr 04 16:19:29 2005 +0000 +++ b/src/work/peter/graph-displayer.cc Mon Apr 04 19:22:04 2005 +0000 @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -36,29 +37,20 @@ private: ///Event handler function that handles dragging nodes of displayed_graph - bool event_handler(GdkEvent* e, int b); + bool event_handler(GdkEvent* e, Node n); - ///Event handler function that handles dragging displayed_graph - bool tri_mover(GdkEvent* e); - - ///Coordinates of Weight Point of tirangle - Gnome::Art::Point * wp; - ///Array of nodes of planefigure - Gnome::Canvas::Ellipse ** nodes; - ///Sides of planefigure - Gnome::Canvas::Polygon * sides; + ///The graph, on which we work + Graph g; + ///Map of nodes of planefigure + Graph::NodeMap nodesmap; + ///Map of edges of planefigure + Graph::EdgeMap edgesmap; ///Group of graphical elements of displayed_graph Gnome::Canvas::Group displayed_graph; ///Indicates whether the button of mouse is pressed or not bool isbutton; - ///Number Of Elements - the number of nodes - int noe; - - ///Array of coordinates - double * coordinates; - ///At this location was the mousebutton pressed. ///It helps to calculate the distance of dragging. double clicked_x, clicked_y; @@ -72,53 +64,11 @@ }; -///When we click on the weight point we can drag the whole planefigure. This function resolves it. -bool GraphDisplayerCanvas::tri_mover(GdkEvent* e) -{ - switch(e->type) - { - case GDK_BUTTON_PRESS: - clicked_x=e->button.x; - clicked_y=e->button.y; - isbutton=true; - break; - case GDK_BUTTON_RELEASE: - isbutton=false; - active_item=NULL; - break; - case GDK_MOTION_NOTIFY: - if(isbutton) - { - double dx=e->motion.x-clicked_x; - double dy=e->motion.y-clicked_y; - - Gnome::Canvas::Points coos; - - for(int i=0;i<=noe;i++) - { - nodes[i]->move(dx,dy); - - double x=(coordinates[2*i]+=dx); - double y=(coordinates[2*i+1]+=dy); - - if(i!=noe)coos.push_back(Gnome::Art::Point(x,y)); - - } - - clicked_x=e->motion.x; - clicked_y=e->motion.y; - - sides->property_points().set_value(coos); - } - default: break; - } - return true; -} ///This function moves only one node of displayed_graph, ///but recalculate the location of weight point, ///and also redraw the sides of the planefigure. -bool GraphDisplayerCanvas::event_handler(GdkEvent* e, int b) +bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) { switch(e->type) { @@ -135,77 +85,98 @@ case GDK_MOTION_NOTIFY: if(isbutton) { - //double x1, y1, x2, y2; - //(get_item_at(e->motion.x, e->motion.y))->get_bounds(x1, y1, x2, y2); - //printf("Item coos: %d %d %d %d\n", (int)x1, (int)y1, (int)x2, (int)y2); - //printf("Mouse is moved! %d %d\n",(int)e->motion.x,(int)e->motion.y); double dx=e->motion.x-clicked_x; double dy=e->motion.y-clicked_y; active_item->move(dx, dy); - - coordinates[2*b]+=dx; - coordinates[2*b+1]+=dy; - - Gnome::Canvas::Points coos; - - double x_wp=0; - double y_wp=0; - - for(int i=0;iproperty_points().set_value(coos); - - x_wp/=noe; - y_wp/=noe; - - dx=x_wp-coordinates[noe*2]; - dy=y_wp-coordinates[noe*2+1]; - nodes[noe]->move(dx, dy); - - coordinates[noe*2]+=dx; - coordinates[noe*2+1]+=dy; - clicked_x=e->motion.x; clicked_y=e->motion.y; + + EdgeIt e; + + g.firstOut(e,n); + for(;e!=INVALID;g.nextOut(e)) + { + Gnome::Canvas::Points coos; + double x1, x2, y1, y2; + + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + edgesmap[e]->property_points().set_value(coos); + } + + g.firstIn(e,n); + for(;e!=INVALID;g.nextIn(e)) + { + Gnome::Canvas::Points coos; + double x1, x2, y1, y2; + + nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); + coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); + + edgesmap[e]->property_points().set_value(coos); + } } default: break; } return true; } -GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & g, CoordinatesMap & cm):displayed_graph(*(root()), 0, 0),isbutton(false),active_item(NULL) +GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm):g(gr),nodesmap(g),edgesmap(g),displayed_graph(*(root()), 0, 0),isbutton(false),active_item(NULL) { - nodes=new Gnome::Canvas::Ellipse* [countNodes(g)]; - int sorszam=0; - + for (EdgeIt i(g); i!=INVALID; ++i) + { + 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 Gnome::Canvas::Line(displayed_graph, coos); + *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); + edgesmap[i]->property_width_pixels().set_value(10); + } for (NodeIt i(g); i!=INVALID; ++i) { - nodes[sorszam]= new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20); - *(nodes[sorszam]) << Gnome::Canvas::Properties::fill_color("blue"); - *(nodes[sorszam]) << Gnome::Canvas::Properties::outline_color("black"); - (nodes[sorszam])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),sorszam)); - sorszam++; + nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20); + *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); + *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); + (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); } - for (EdgeIt i(g); i!=INVALID; ++i) - { - } - - } GraphDisplayerCanvas::~GraphDisplayerCanvas() { + 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.addNodeMap("id", id); + writer.addNodeMap("coordinates_x", xc); + writer.addNodeMap("coordinates_y", yc); + writer.run(); } + //MainWin: - class MainWin : public Gtk::Window { public: @@ -290,6 +261,7 @@ Graph g; CoordinatesMap cm(g); + Graph::EdgeMap cap(g); //we create one object to read x coordinates //and one to read y coordinate of nodes and write them to cm NodeMap. @@ -303,10 +275,6 @@ reader.addNodeMap("coordinates_y", yreader); reader.run(); - for (NodeIt i(g); i!=INVALID; ++i) - std::cout << " " << g.id(i) << " " << cm[i]; - std::cout << std::endl; - Gnome::Canvas::init(); Gtk::Main app(argc, argv); diff -r d1fc1bf7decc -r 1f3baf3bd1f2 src/work/peter/graphocska.lgf --- a/src/work/peter/graphocska.lgf Mon Apr 04 16:19:29 2005 +0000 +++ b/src/work/peter/graphocska.lgf Mon Apr 04 19:22:04 2005 +0000 @@ -1,11 +1,39 @@ @nodeset -id coordinates_x coordinates_y -1 300 300 -2 -300 -300 -3 300 -300 -4 -300 300 -5 100 100 -6 -100 -100 -7 -100 100 -8 100 -100 -@end +id coordinates_x coordinates_y +1 230 -80 +2 230 100 +3 120 -80 +4 120 100 +5 20 100 +6 20 -80 +7 -40 10 +8 -100 100 +9 -100 10 +10 -100 -80 +11 -200 -80 +12 -200 10 +13 -200 100 +14 -300 100 +15 -300 -80 + +@edgeset + cap +15 14 1 +14 13 2 +13 12 3 +13 8 4 +12 11 5 +12 9 6 +11 10 7 +10 9 8 +10 7 9 +9 8 10 +7 6 11 +6 5 12 +6 3 13 +5 4 14 +4 3 15 +3 2 16 +2 1 17 + +@end \ No newline at end of file