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