root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FArc2D.java @ 8949
History | View | Annotate | Download (11.1 KB)
1 |
/*
|
---|---|
2 |
* Created on 09-feb-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
21 |
USA.
|
22 |
*
|
23 |
* For more information, contact:
|
24 |
*
|
25 |
* Generalitat Valenciana
|
26 |
* Conselleria d'Infraestructures i Transport
|
27 |
* Av. Blasco Ib??ez, 50
|
28 |
* 46010 VALENCIA
|
29 |
* SPAIN
|
30 |
*
|
31 |
* +34 963862235
|
32 |
* gvsig@gva.es
|
33 |
* www.gvsig.gva.es
|
34 |
*
|
35 |
* or
|
36 |
*
|
37 |
* IVER T.I. S.A
|
38 |
* Salamanca 50
|
39 |
* 46005 Valencia
|
40 |
* Spain
|
41 |
*
|
42 |
* +34 963163400
|
43 |
* dac@iver.es
|
44 |
*/
|
45 |
package com.iver.cit.gvsig.fmap.core; |
46 |
|
47 |
import java.awt.geom.AffineTransform; |
48 |
import java.awt.geom.Arc2D; |
49 |
import java.awt.geom.Point2D; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
import java.util.ArrayList; |
52 |
|
53 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
54 |
|
55 |
|
56 |
/**
|
57 |
* DOCUMENT ME!
|
58 |
*
|
59 |
* @author Vicente Caballero Navarro
|
60 |
*/
|
61 |
public class FArc2D extends FPolyline2D { |
62 |
private Point2D init; |
63 |
private Point2D center; |
64 |
private Point2D end; |
65 |
/**
|
66 |
* DOCUMENT ME!
|
67 |
*
|
68 |
* @param gpx
|
69 |
*/
|
70 |
public FArc2D(GeneralPathX gpx,Point2D i,Point2D c, Point2D e) { |
71 |
super(gpx);
|
72 |
init=i; |
73 |
center=c; |
74 |
end=e; |
75 |
} |
76 |
public Point2D getInit(){ |
77 |
return init;
|
78 |
} |
79 |
public Point2D getEnd(){ |
80 |
return end;
|
81 |
} |
82 |
public Point2D getCenter(){ |
83 |
return UtilFunctions.getCenter(init, center,end);
|
84 |
} |
85 |
public Point2D getMid(){ |
86 |
return center;
|
87 |
} |
88 |
/* (non-Javadoc)
|
89 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
90 |
*/
|
91 |
public FShape cloneFShape() {
|
92 |
FArc2D arc=new FArc2D((GeneralPathX) gp.clone(),init,center,end);
|
93 |
return arc;
|
94 |
} |
95 |
public void transform(AffineTransform at) { |
96 |
gp.transform(at); |
97 |
InitHandler inithandler=(InitHandler)getStretchingHandlers()[0];
|
98 |
//CenterHandler centerhandler=(CenterHandler)getHandlers()[1];
|
99 |
EndHandler endhandler=(EndHandler)getStretchingHandlers()[1];
|
100 |
Point2D aux1=new Point2D.Double(); |
101 |
Point2D aux2=new Point2D.Double(); |
102 |
Point2D aux3=new Point2D.Double(); |
103 |
at.transform(inithandler.getPoint(),aux1); |
104 |
inithandler.setPoint(aux1); |
105 |
//at.transform(centerhandler.getPoint(),aux2);
|
106 |
//centerhandler.setPoint(aux2);
|
107 |
at.transform(endhandler.getPoint(),aux3); |
108 |
endhandler.setPoint(aux3); |
109 |
CenterSelHandler centerhandler=(CenterSelHandler)getSelectHandlers()[1];
|
110 |
at.transform(centerhandler.getPoint(),aux2); |
111 |
centerhandler.setPoint(aux2); |
112 |
|
113 |
} |
114 |
/**
|
115 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
116 |
*/
|
117 |
public int getShapeType() { |
118 |
return FShape.ARC;
|
119 |
} |
120 |
/**
|
121 |
* DOCUMENT ME!
|
122 |
*
|
123 |
* @return DOCUMENT ME!
|
124 |
*/
|
125 |
public Handler[] getStretchingHandlers() { |
126 |
ArrayList handlers = new ArrayList(); |
127 |
|
128 |
handlers.add(new InitHandler(0, init.getX(), init.getY())); |
129 |
//handlers.add(new CenterHandler(1, center.getX(), center.getY()));
|
130 |
handlers.add(new EndHandler(1, end.getX(), end.getY())); |
131 |
|
132 |
return (Handler[]) handlers.toArray(new Handler[0]); |
133 |
} |
134 |
|
135 |
public Handler[] getSelectHandlers() { |
136 |
ArrayList handlers = new ArrayList(); |
137 |
|
138 |
handlers.add(new InitSelHandler(0, init.getX(), init.getY())); |
139 |
handlers.add(new CenterSelHandler(1, center.getX(), center.getY())); |
140 |
handlers.add(new EndSelHandler(2, end.getX(), end.getY())); |
141 |
|
142 |
return (Handler[]) handlers.toArray(new Handler[0]); |
143 |
} |
144 |
/**
|
145 |
* DOCUMENT ME!
|
146 |
*
|
147 |
* @author Vicente Caballero Navarro
|
148 |
*/
|
149 |
class CenterSelHandler extends AbstractHandler implements ICenterHandler{ |
150 |
/**
|
151 |
* Crea un nuevo PointHandler.
|
152 |
*
|
153 |
* @param i DOCUMENT ME!
|
154 |
* @param x DOCUMENT ME!
|
155 |
* @param y DOCUMENT ME!
|
156 |
*/
|
157 |
public CenterSelHandler(int i, double x, double y) { |
158 |
center = new Point2D.Double(x, y); |
159 |
index = i; |
160 |
} |
161 |
|
162 |
/**
|
163 |
* DOCUMENT ME!
|
164 |
*
|
165 |
* @param x DOCUMENT ME!
|
166 |
* @param y DOCUMENT ME!
|
167 |
*
|
168 |
* @return DOCUMENT ME!
|
169 |
*/
|
170 |
public void move(double x, double y) { |
171 |
} |
172 |
public void setPoint(Point2D p){ |
173 |
center=p; |
174 |
} |
175 |
public Point2D getPoint(){ |
176 |
return center;
|
177 |
} |
178 |
|
179 |
/**
|
180 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
181 |
*/
|
182 |
public void set(double x, double y) { |
183 |
center=new Point2D.Double(x,y); |
184 |
Arc2D arco = UtilFunctions.createArc(init,center, end);
|
185 |
gp=new GeneralPathX(arco);
|
186 |
} |
187 |
} |
188 |
|
189 |
/**
|
190 |
* DOCUMENT ME!
|
191 |
*
|
192 |
* @author Vicente Caballero Navarro
|
193 |
*/
|
194 |
class InitHandler extends AbstractHandler implements IFinalHandler{ |
195 |
/**
|
196 |
* Crea un nuevo PointHandler.
|
197 |
*
|
198 |
* @param i DOCUMENT ME!
|
199 |
* @param x DOCUMENT ME!
|
200 |
* @param y DOCUMENT ME!
|
201 |
*/
|
202 |
public InitHandler(int i, double x, double y) { |
203 |
init = new Point2D.Double(x, y); |
204 |
index = i; |
205 |
} |
206 |
|
207 |
/**
|
208 |
* DOCUMENT ME!
|
209 |
*
|
210 |
* @param x DOCUMENT ME!
|
211 |
* @param y DOCUMENT ME!
|
212 |
*
|
213 |
* @return DOCUMENT ME!
|
214 |
*/
|
215 |
public void move(double x, double y) { |
216 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
217 |
double dist=mediop.distance(center);
|
218 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
219 |
|
220 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
221 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
222 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
223 |
dist=-dist; |
224 |
} |
225 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
226 |
|
227 |
Arc2D arco = UtilFunctions.createArc(init,center, end);
|
228 |
gp=new GeneralPathX(arco);
|
229 |
} |
230 |
public void setPoint(Point2D p){ |
231 |
init=p; |
232 |
} |
233 |
public Point2D getPoint(){ |
234 |
return init;
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
239 |
*/
|
240 |
public void set(double x, double y) { |
241 |
} |
242 |
} |
243 |
|
244 |
/**
|
245 |
* DOCUMENT ME!
|
246 |
*
|
247 |
* @author Vicente Caballero Navarro
|
248 |
*/
|
249 |
class EndHandler extends AbstractHandler implements IFinalHandler{ |
250 |
/**
|
251 |
* Crea un nuevo PointHandler.
|
252 |
*
|
253 |
* @param i DOCUMENT ME!
|
254 |
* @param x DOCUMENT ME!
|
255 |
* @param y DOCUMENT ME!
|
256 |
*/
|
257 |
public EndHandler(int i, double x, double y) { |
258 |
end = new Point2D.Double(x, y); |
259 |
index = i; |
260 |
} |
261 |
|
262 |
/**
|
263 |
* DOCUMENT ME!
|
264 |
*
|
265 |
* @param x DOCUMENT ME!
|
266 |
* @param y DOCUMENT ME!
|
267 |
*
|
268 |
* @return DOCUMENT ME!
|
269 |
*/
|
270 |
public void move(double x, double y) { |
271 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
272 |
double dist=mediop.distance(center);
|
273 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
274 |
|
275 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
276 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
277 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
278 |
dist=-dist; |
279 |
} |
280 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
281 |
|
282 |
Arc2D arco = UtilFunctions.createArc(init,center, end);
|
283 |
gp=new GeneralPathX(arco);
|
284 |
} |
285 |
public void setPoint(Point2D p){ |
286 |
end=p; |
287 |
} |
288 |
public Point2D getPoint(){ |
289 |
return end;
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
294 |
*/
|
295 |
public void set(double x, double y) { |
296 |
|
297 |
} |
298 |
} |
299 |
|
300 |
/**
|
301 |
* DOCUMENT ME!
|
302 |
*
|
303 |
* @author Vicente Caballero Navarro
|
304 |
*/
|
305 |
class InitSelHandler extends AbstractHandler implements IFinalHandler{ |
306 |
/**
|
307 |
* Crea un nuevo PointHandler.
|
308 |
*
|
309 |
* @param i DOCUMENT ME!
|
310 |
* @param x DOCUMENT ME!
|
311 |
* @param y DOCUMENT ME!
|
312 |
*/
|
313 |
public InitSelHandler(int i, double x, double y) { |
314 |
init = new Point2D.Double(x, y); |
315 |
index = i; |
316 |
} |
317 |
|
318 |
/**
|
319 |
* DOCUMENT ME!
|
320 |
*
|
321 |
* @param x DOCUMENT ME!
|
322 |
* @param y DOCUMENT ME!
|
323 |
*
|
324 |
* @return DOCUMENT ME!
|
325 |
*/
|
326 |
public void move(double x, double y) { |
327 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
328 |
double dist=mediop.distance(center);
|
329 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
330 |
|
331 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
332 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
333 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
334 |
dist=-dist; |
335 |
} |
336 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
337 |
|
338 |
Arc2D arco = UtilFunctions.createArc(init,center, end);
|
339 |
gp=new GeneralPathX(arco);
|
340 |
} |
341 |
public void setPoint(Point2D p){ |
342 |
init=p; |
343 |
} |
344 |
public Point2D getPoint(){ |
345 |
return init;
|
346 |
} |
347 |
|
348 |
/**
|
349 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
350 |
*/
|
351 |
public void set(double x, double y) { |
352 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
353 |
double dist=mediop.distance(center);
|
354 |
init=new Point2D.Double(x,y); |
355 |
|
356 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
357 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
358 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
359 |
dist=-dist; |
360 |
} |
361 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
362 |
Arc2D arco = UtilFunctions.createArc(init,center, end);
|
363 |
gp=new GeneralPathX(arco);
|
364 |
} |
365 |
} |
366 |
|
367 |
/**
|
368 |
* DOCUMENT ME!
|
369 |
*
|
370 |
* @author Vicente Caballero Navarro
|
371 |
*/
|
372 |
class EndSelHandler extends AbstractHandler implements IFinalHandler{ |
373 |
/**
|
374 |
* Crea un nuevo PointHandler.
|
375 |
*
|
376 |
* @param i DOCUMENT ME!
|
377 |
* @param x DOCUMENT ME!
|
378 |
* @param y DOCUMENT ME!
|
379 |
*/
|
380 |
public EndSelHandler(int i, double x, double y) { |
381 |
end = new Point2D.Double(x, y); |
382 |
index = i; |
383 |
} |
384 |
|
385 |
/**
|
386 |
* DOCUMENT ME!
|
387 |
*
|
388 |
* @param x DOCUMENT ME!
|
389 |
* @param y DOCUMENT ME!
|
390 |
*
|
391 |
* @return DOCUMENT ME!
|
392 |
*/
|
393 |
public void move(double x, double y) { |
394 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
395 |
double dist=mediop.distance(center);
|
396 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
397 |
|
398 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
399 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
400 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
401 |
dist=-dist; |
402 |
} |
403 |
center=UtilFunctions.getPoint(mediop,perp[1],dist);
|
404 |
|
405 |
Arc2D arco = UtilFunctions.createArc(init,center, end);
|
406 |
gp=new GeneralPathX(arco);
|
407 |
} |
408 |
public void setPoint(Point2D p){ |
409 |
end=p; |
410 |
} |
411 |
public Point2D getPoint(){ |
412 |
return end;
|
413 |
} |
414 |
|
415 |
/**
|
416 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
417 |
*/
|
418 |
public void set(double x, double y) { |
419 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
420 |
double dist=mediop.distance(center);
|
421 |
end=new Point2D.Double(x,y); |
422 |
|
423 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
424 |
Point2D[] perp=UtilFunctions.getPerpendicular(init,end,mediop); |
425 |
if (UtilFunctions.getAngle(end,init)<=Math.PI){ |
426 |
dist=-dist; |
427 |
} |
428 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
429 |
Arc2D arco = UtilFunctions.createArc(init,center, end);
|
430 |
gp=new GeneralPathX(arco);
|
431 |
} |
432 |
} |
433 |
|
434 |
/* (non-Javadoc)
|
435 |
* @see com.iver.cit.gvsig.fmap.core.FPolyline2D#intersects(java.awt.geom.Rectangle2D)
|
436 |
*/
|
437 |
public boolean intersects(Rectangle2D r) { |
438 |
return gp.intersects(r);
|
439 |
} |
440 |
|
441 |
|
442 |
} |