Changeset 1301:1f3baf3bd1f2 in lemon-0.x for src/work
- Timestamp:
- 04/04/05 21:22:04 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1736
- Location:
- src/work/peter
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/peter/graph-displayer.cc
r1290 r1301 12 12 #include <lemon/list_graph.h> 13 13 #include <lemon/graph_reader.h> 14 #include <lemon/graph_writer.h> 14 15 #include <lemon/graph_utils.h> 15 16 #include <lemon/maps.h> … … 37 38 38 39 ///Event handler function that handles dragging nodes of displayed_graph 39 bool event_handler(GdkEvent* e, int b); 40 41 ///Event handler function that handles dragging displayed_graph 42 bool tri_mover(GdkEvent* e); 43 44 ///Coordinates of Weight Point of tirangle 45 Gnome::Art::Point * wp; 46 ///Array of nodes of planefigure 47 Gnome::Canvas::Ellipse ** nodes; 48 ///Sides of planefigure 49 Gnome::Canvas::Polygon * sides; 40 bool event_handler(GdkEvent* e, Node n); 41 42 ///The graph, on which we work 43 Graph g; 44 ///Map of nodes of planefigure 45 Graph::NodeMap<Gnome::Canvas::Ellipse *> nodesmap; 46 ///Map of edges of planefigure 47 Graph::EdgeMap<Gnome::Canvas::Line *> edgesmap; 50 48 ///Group of graphical elements of displayed_graph 51 49 Gnome::Canvas::Group displayed_graph; … … 53 51 ///Indicates whether the button of mouse is pressed or not 54 52 bool isbutton; 55 56 ///Number Of Elements - the number of nodes57 int noe;58 59 ///Array of coordinates60 double * coordinates;61 53 62 54 ///At this location was the mousebutton pressed. … … 73 65 }; 74 66 75 ///When we click on the weight point we can drag the whole planefigure. This function resolves it.76 bool GraphDisplayerCanvas::tri_mover(GdkEvent* e)77 {78 switch(e->type)79 {80 case GDK_BUTTON_PRESS:81 clicked_x=e->button.x;82 clicked_y=e->button.y;83 isbutton=true;84 break;85 case GDK_BUTTON_RELEASE:86 isbutton=false;87 active_item=NULL;88 break;89 case GDK_MOTION_NOTIFY:90 if(isbutton)91 {92 double dx=e->motion.x-clicked_x;93 double dy=e->motion.y-clicked_y;94 95 Gnome::Canvas::Points coos;96 97 for(int i=0;i<=noe;i++)98 {99 nodes[i]->move(dx,dy);100 101 double x=(coordinates[2*i]+=dx);102 double y=(coordinates[2*i+1]+=dy);103 104 if(i!=noe)coos.push_back(Gnome::Art::Point(x,y));105 106 }107 108 clicked_x=e->motion.x;109 clicked_y=e->motion.y;110 111 sides->property_points().set_value(coos);112 }113 default: break;114 }115 return true;116 }117 67 118 68 ///This function moves only one node of displayed_graph, 119 69 ///but recalculate the location of weight point, 120 70 ///and also redraw the sides of the planefigure. 121 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, int b)71 bool GraphDisplayerCanvas::event_handler(GdkEvent* e, Node n) 122 72 { 123 73 switch(e->type) … … 136 86 if(isbutton) 137 87 { 138 //double x1, y1, x2, y2;139 //(get_item_at(e->motion.x, e->motion.y))->get_bounds(x1, y1, x2, y2);140 //printf("Item coos: %d %d %d %d\n", (int)x1, (int)y1, (int)x2, (int)y2);141 //printf("Mouse is moved! %d %d\n",(int)e->motion.x,(int)e->motion.y);142 88 double dx=e->motion.x-clicked_x; 143 89 double dy=e->motion.y-clicked_y; 144 90 active_item->move(dx, dy); 145 146 coordinates[2*b]+=dx;147 coordinates[2*b+1]+=dy;148 149 Gnome::Canvas::Points coos;150 151 double x_wp=0;152 double y_wp=0;153 154 for(int i=0;i<noe;i++)155 {156 coos.push_back(Gnome::Art::Point(coordinates[2*i], coordinates[2*i+1]));157 158 x_wp+=coordinates[2*i];159 y_wp+=coordinates[2*i+1];160 }161 162 sides->property_points().set_value(coos);163 164 x_wp/=noe;165 y_wp/=noe;166 167 dx=x_wp-coordinates[noe*2];168 dy=y_wp-coordinates[noe*2+1];169 nodes[noe]->move(dx, dy);170 171 coordinates[noe*2]+=dx;172 coordinates[noe*2+1]+=dy;173 174 91 clicked_x=e->motion.x; 175 92 clicked_y=e->motion.y; 93 94 EdgeIt e; 95 96 g.firstOut(e,n); 97 for(;e!=INVALID;g.nextOut(e)) 98 { 99 Gnome::Canvas::Points coos; 100 double x1, x2, y1, y2; 101 102 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); 103 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 104 105 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); 106 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 107 108 edgesmap[e]->property_points().set_value(coos); 109 } 110 111 g.firstIn(e,n); 112 for(;e!=INVALID;g.nextIn(e)) 113 { 114 Gnome::Canvas::Points coos; 115 double x1, x2, y1, y2; 116 117 nodesmap[g.source(e)]->get_bounds(x1, y1, x2, y2); 118 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 119 120 nodesmap[g.target(e)]->get_bounds(x1, y1, x2, y2); 121 coos.push_back(Gnome::Art::Point((x1+x2)/2,(y1+y2)/2)); 122 123 edgesmap[e]->property_points().set_value(coos); 124 } 176 125 } 177 126 default: break; … … 180 129 } 181 130 182 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & g, CoordinatesMap & cm):displayed_graph(*(root()), 0, 0),isbutton(false),active_item(NULL) 183 { 184 nodes=new Gnome::Canvas::Ellipse* [countNodes(g)]; 185 int sorszam=0; 186 131 GraphDisplayerCanvas::GraphDisplayerCanvas(Graph & gr, CoordinatesMap & cm):g(gr),nodesmap(g),edgesmap(g),displayed_graph(*(root()), 0, 0),isbutton(false),active_item(NULL) 132 { 133 for (EdgeIt i(g); i!=INVALID; ++i) 134 { 135 Gnome::Canvas::Points coos; 136 coos.push_back(Gnome::Art::Point(cm[g.source(i)].x,cm[g.source(i)].y)); 137 coos.push_back(Gnome::Art::Point(cm[g.target(i)].x,cm[g.target(i)].y)); 138 edgesmap[i]=new Gnome::Canvas::Line(displayed_graph, coos); 139 *(edgesmap[i]) << Gnome::Canvas::Properties::fill_color("green"); 140 edgesmap[i]->property_width_pixels().set_value(10); 141 } 187 142 for (NodeIt i(g); i!=INVALID; ++i) 188 143 { 189 nodes[sorszam]= new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20); 190 *(nodes[sorszam]) << Gnome::Canvas::Properties::fill_color("blue"); 191 *(nodes[sorszam]) << Gnome::Canvas::Properties::outline_color("black"); 192 (nodes[sorszam])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),sorszam)); 193 sorszam++; 194 } 195 196 for (EdgeIt i(g); i!=INVALID; ++i) 197 { 198 } 199 144 nodesmap[i]=new Gnome::Canvas::Ellipse(displayed_graph, cm[i].x-20, cm[i].y-20, cm[i].x+20, cm[i].y+20); 145 *(nodesmap[i]) << Gnome::Canvas::Properties::fill_color("blue"); 146 *(nodesmap[i]) << Gnome::Canvas::Properties::outline_color("black"); 147 (nodesmap[i])->signal_event().connect(sigc::bind(sigc::mem_fun(*this, &GraphDisplayerCanvas::event_handler),i)); 148 } 200 149 201 150 } … … 203 152 GraphDisplayerCanvas::~GraphDisplayerCanvas() 204 153 { 205 } 154 Graph::NodeMap <int> id(g); 155 Graph::NodeMap <double> xc(g); 156 Graph::NodeMap <double> yc(g); 157 158 int j=1; 159 160 for (NodeIt i(g); i!=INVALID; ++i) 161 { 162 double x1,y1,x2,y2; 163 nodesmap[i]->get_bounds(x1, y1, x2, y2); 164 165 id[i]=j++; 166 xc[i]=(x1+x2)/2; 167 yc[i]=(y1+y2)/2; 168 } 169 170 GraphWriter<Graph> writer(std::cout,g); 171 172 writer.addNodeMap("id", id); 173 writer.addNodeMap("coordinates_x", xc); 174 writer.addNodeMap("coordinates_y", yc); 175 writer.run(); 176 } 177 206 178 207 179 //MainWin: 208 209 180 class MainWin : public Gtk::Window 210 181 { … … 291 262 292 263 CoordinatesMap cm(g); 264 Graph::EdgeMap<double> cap(g); 293 265 294 266 //we create one object to read x coordinates … … 304 276 reader.run(); 305 277 306 for (NodeIt i(g); i!=INVALID; ++i)307 std::cout << " " << g.id(i) << " " << cm[i];308 std::cout << std::endl;309 310 278 Gnome::Canvas::init(); 311 279 Gtk::Main app(argc, argv); -
src/work/peter/graphocska.lgf
r1290 r1301 1 1 @nodeset 2 id coordinates_x coordinates_y 3 1 300 300 4 2 -300 -300 5 3 300 -300 6 4 -300 300 7 5 100 100 8 6 -100 -100 9 7 -100 100 10 8 100 -100 2 id coordinates_x coordinates_y 3 1 230 -80 4 2 230 100 5 3 120 -80 6 4 120 100 7 5 20 100 8 6 20 -80 9 7 -40 10 10 8 -100 100 11 9 -100 10 12 10 -100 -80 13 11 -200 -80 14 12 -200 10 15 13 -200 100 16 14 -300 100 17 15 -300 -80 18 19 @edgeset 20 cap 21 15 14 1 22 14 13 2 23 13 12 3 24 13 8 4 25 12 11 5 26 12 9 6 27 11 10 7 28 10 9 8 29 10 7 9 30 9 8 10 31 7 6 11 32 6 5 12 33 6 3 13 34 5 4 14 35 4 3 15 36 3 2 16 37 2 1 17 38 11 39 @end
Note: See TracChangeset
for help on using the changeset viewer.