root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FEllipse2D.java @ 38563
History | View | Annotate | Download (11.1 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.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
import java.util.ArrayList; |
48 |
|
49 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
50 |
|
51 |
|
52 |
/**
|
53 |
* DOCUMENT ME!
|
54 |
*
|
55 |
* @author Vicente Caballero Navarro
|
56 |
*/
|
57 |
public class FEllipse2D extends FPolygon2D { |
58 |
private Point2D init; |
59 |
private Point2D end; |
60 |
private double ydist; |
61 |
/**
|
62 |
* DOCUMENT ME!
|
63 |
*
|
64 |
* @param gpx
|
65 |
*/
|
66 |
public FEllipse2D(GeneralPathX gpx,Point2D i,Point2D e,double d) { |
67 |
super(gpx);
|
68 |
init=i; |
69 |
end=e; |
70 |
ydist=d; |
71 |
} |
72 |
|
73 |
public Point2D getInit(){ |
74 |
return init;
|
75 |
} |
76 |
public Point2D getEnd(){ |
77 |
return end;
|
78 |
} |
79 |
public double getDist(){ |
80 |
return ydist;
|
81 |
} |
82 |
/* (non-Javadoc)
|
83 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
84 |
*/
|
85 |
public FShape cloneFShape() {
|
86 |
return new FEllipse2D((GeneralPathX) gp.clone(),init,end,ydist); |
87 |
} |
88 |
/**
|
89 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
90 |
*/
|
91 |
public int getShapeType() { |
92 |
return FShape.ELLIPSE;
|
93 |
} |
94 |
/**
|
95 |
* DOCUMENT ME!
|
96 |
*
|
97 |
* @param at DOCUMENT ME!
|
98 |
*/
|
99 |
public void transform(AffineTransform at) { |
100 |
Point2D center=new Point2D.Double((init.getX() + end.getX()) / 2, |
101 |
(init.getY() + end.getY()) / 2);
|
102 |
Point2D pdist=UtilFunctions.getPerpendicularPoint(init,end,center,ydist);
|
103 |
Point2D aux1=new Point2D.Double(); |
104 |
at.transform(init,aux1); |
105 |
init=aux1; |
106 |
Point2D aux2=new Point2D.Double(); |
107 |
at.transform(end,aux2); |
108 |
end=aux2; |
109 |
|
110 |
center=new Point2D.Double((init.getX() + end.getX()) / 2, |
111 |
(init.getY() + end.getY()) / 2);
|
112 |
|
113 |
Point2D aux3=new Point2D.Double(); |
114 |
at.transform(pdist,aux3); |
115 |
ydist=center.distance(aux3); |
116 |
gp.transform(at); |
117 |
} |
118 |
/**
|
119 |
* DOCUMENT ME!
|
120 |
*
|
121 |
* @return DOCUMENT ME!
|
122 |
*/
|
123 |
public Handler[] getStretchingHandlers() { |
124 |
ArrayList handlers = new ArrayList(); |
125 |
Rectangle2D rect = this.getBounds2D(); |
126 |
handlers.add(new CenterHandler(0, rect.getCenterX(), rect.getCenterY())); |
127 |
return (Handler[]) handlers.toArray(new Handler[0]); |
128 |
} |
129 |
public Handler[] getSelectHandlers() { |
130 |
ArrayList handlers = new ArrayList(); |
131 |
Rectangle2D rect = this.getBounds2D(); |
132 |
handlers.add(new CenterSelHandler(0, rect.getCenterX(), rect.getCenterY())); |
133 |
handlers.add(new InitSelHandler(1, init.getX(), init.getY())); |
134 |
handlers.add(new EndSelHandler(2, end.getX(), end.getY())); |
135 |
Point2D mediop = new Point2D.Double((end.getX() + init.getX()) / 2, |
136 |
(end.getY() + init.getY()) / 2);
|
137 |
Point2D[] p=UtilFunctions.getPerpendicular(init,end,mediop); |
138 |
Point2D u=UtilFunctions.getPoint(mediop,p[1],ydist); |
139 |
Point2D d=UtilFunctions.getPoint(mediop,p[1],-ydist); |
140 |
|
141 |
handlers.add(new RadioSelYHandler(3, u.getX(), u.getY())); |
142 |
handlers.add(new RadioSelYHandler(4, d.getX(), d.getY())); |
143 |
|
144 |
return (Handler[]) handlers.toArray(new Handler[0]); |
145 |
} |
146 |
|
147 |
/**
|
148 |
* DOCUMENT ME!
|
149 |
*
|
150 |
* @author Vicente Caballero Navarro
|
151 |
*/
|
152 |
class CenterHandler extends AbstractHandler implements ICenterHandler { |
153 |
/**
|
154 |
* Crea un nuevo PointHandler.
|
155 |
*
|
156 |
* @param i DOCUMENT ME!
|
157 |
* @param x DOCUMENT ME!
|
158 |
* @param y DOCUMENT ME!
|
159 |
*/
|
160 |
public CenterHandler(int i, double x, double y) { |
161 |
point = new Point2D.Double(x, y); |
162 |
index = i; |
163 |
} |
164 |
|
165 |
/**
|
166 |
* DOCUMENT ME!
|
167 |
*
|
168 |
* @param x DOCUMENT ME!
|
169 |
* @param y DOCUMENT ME!
|
170 |
*
|
171 |
* @return DOCUMENT ME!
|
172 |
*/
|
173 |
public void move(double x, double y) { |
174 |
for (int i=0;i<gp.numCoords/2;i++){ |
175 |
gp.pointCoords[i*2]+=x;
|
176 |
gp.pointCoords[i*2+1]+=y; |
177 |
} |
178 |
init = new Point2D.Double(init.getX() + x, init.getY() + y); |
179 |
end = new Point2D.Double(end.getX() + x, end.getY() + y); |
180 |
} |
181 |
|
182 |
/**
|
183 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
184 |
*/
|
185 |
public void set(double x, double y) { |
186 |
} |
187 |
} |
188 |
/**
|
189 |
* DOCUMENT ME!
|
190 |
*
|
191 |
* @author Vicente Caballero Navarro
|
192 |
*/
|
193 |
class CenterSelHandler extends AbstractHandler implements ICenterHandler{ |
194 |
/**
|
195 |
* Crea un nuevo PointHandler.
|
196 |
*
|
197 |
* @param i DOCUMENT ME!
|
198 |
* @param x DOCUMENT ME!
|
199 |
* @param y DOCUMENT ME!
|
200 |
*/
|
201 |
public CenterSelHandler(int i, double x, double y) { |
202 |
point = new Point2D.Double(x, y); |
203 |
index = i; |
204 |
} |
205 |
|
206 |
/**
|
207 |
* DOCUMENT ME!
|
208 |
*
|
209 |
* @param x DOCUMENT ME!
|
210 |
* @param y DOCUMENT ME!
|
211 |
*
|
212 |
* @return DOCUMENT ME!
|
213 |
*/
|
214 |
public void move(double x, double y) { |
215 |
for (int i=0;i<gp.numCoords/2;i++){ |
216 |
gp.pointCoords[i*2]+=x;
|
217 |
gp.pointCoords[i*2+1]+=y; |
218 |
} |
219 |
} |
220 |
|
221 |
/**
|
222 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
223 |
*/
|
224 |
public void set(double x, double y) { |
225 |
Point2D center=new Point2D.Double((init.getX() + end.getX()) / 2, |
226 |
(init.getY() + end.getY()) / 2);
|
227 |
double dx=x-center.getX();
|
228 |
double dy=y-center.getY();
|
229 |
for (int i=0;i<gp.numCoords/2;i++){ |
230 |
gp.pointCoords[i*2]+=dx;
|
231 |
gp.pointCoords[i*2+1]+=dy; |
232 |
} |
233 |
init=new Point2D.Double(init.getX()+dx,init.getY()+dy); |
234 |
end=new Point2D.Double(end.getX()+dx,end.getY()+dy); |
235 |
} |
236 |
} |
237 |
|
238 |
/**
|
239 |
* DOCUMENT ME!
|
240 |
*
|
241 |
* @author Vicente Caballero Navarro
|
242 |
*/
|
243 |
class InitSelHandler extends AbstractHandler implements ICuadrantHandler{ |
244 |
/**
|
245 |
* Crea un nuevo PointHandler.
|
246 |
*
|
247 |
* @param i DOCUMENT ME!
|
248 |
* @param x DOCUMENT ME!
|
249 |
* @param y DOCUMENT ME!
|
250 |
*/
|
251 |
public InitSelHandler(int i, double x, double y) { |
252 |
point = new Point2D.Double(x, y); |
253 |
index = i; |
254 |
} |
255 |
|
256 |
/**
|
257 |
* DOCUMENT ME!
|
258 |
*
|
259 |
* @param x DOCUMENT ME!
|
260 |
* @param y DOCUMENT ME!
|
261 |
*
|
262 |
* @return DOCUMENT ME!
|
263 |
*/
|
264 |
public void move(double x, double y) { |
265 |
|
266 |
} |
267 |
|
268 |
/**
|
269 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
270 |
*/
|
271 |
public void set(double x, double y) { |
272 |
double dx=x-init.getX();
|
273 |
double dy=y-init.getY();
|
274 |
Point2D center=new Point2D.Double((init.getX() + end.getX()) / 2, |
275 |
(init.getY() + end.getY()) / 2);
|
276 |
// Point2D[] p1=TrigonometricalFunctions.getPerpendicular(init,end,center);
|
277 |
// Point2D[] p2=TrigonometricalFunctions.getPerpendicular(p1[0],p1[1],new Point2D.Double(x,y));
|
278 |
|
279 |
// Point2D pl=TrigonometricalFunctions.getIntersection(p2[0],p2[1],p1[0],p1[1]);
|
280 |
// double xdist=2*pl.distance(x,y);
|
281 |
double xdist=2*center.distance(x,y); |
282 |
//init=new Point2D.Double(init.getX()+dx,init.getY()+dy);
|
283 |
init=UtilFunctions.getPoint(center,init,center.distance(x,y)); |
284 |
end=UtilFunctions.getPoint(init,center,xdist); |
285 |
Arc2D.Double arc = new Arc2D.Double(init.getX(), |
286 |
init.getY() - ydist, xdist, 2 * ydist, 0, 360, Arc2D.OPEN); |
287 |
Point2D rotationPoint = new Point2D.Double(init.getX() + xdist /2, init.getY()); |
288 |
|
289 |
double angle = UtilFunctions.getAngle(init, end);
|
290 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, init.getX(), init.getY()); |
291 |
gp = new GeneralPathX(arc);
|
292 |
gp.transform(mT); |
293 |
|
294 |
} |
295 |
} |
296 |
/**
|
297 |
* DOCUMENT ME!
|
298 |
*
|
299 |
* @author Vicente Caballero Navarro
|
300 |
*/
|
301 |
class EndSelHandler extends AbstractHandler implements ICuadrantHandler{ |
302 |
/**
|
303 |
* Crea un nuevo PointHandler.
|
304 |
*
|
305 |
* @param i DOCUMENT ME!
|
306 |
* @param x DOCUMENT ME!
|
307 |
* @param y DOCUMENT ME!
|
308 |
*/
|
309 |
public EndSelHandler(int i, double x, double y) { |
310 |
point = new Point2D.Double(x, y); |
311 |
index = i; |
312 |
} |
313 |
|
314 |
/**
|
315 |
* DOCUMENT ME!
|
316 |
*
|
317 |
* @param x DOCUMENT ME!
|
318 |
* @param y DOCUMENT ME!
|
319 |
*
|
320 |
* @return DOCUMENT ME!
|
321 |
*/
|
322 |
public void move(double x, double y) { |
323 |
|
324 |
} |
325 |
|
326 |
/**
|
327 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
328 |
*/
|
329 |
public void set(double x, double y) { |
330 |
double dx=x-getPoint().getX();
|
331 |
double dy=y-getPoint().getY();
|
332 |
Point2D center=new Point2D.Double((init.getX() + end.getX()) / 2, |
333 |
(init.getY() + end.getY()) / 2);
|
334 |
// Point2D[] p1=TrigonometricalFunctions.getPerpendicular(init,end,center);
|
335 |
// Point2D[] p2=TrigonometricalFunctions.getPerpendicular(p1[0],p1[1],new Point2D.Double(x,y));
|
336 |
|
337 |
// Point2D pl=TrigonometricalFunctions.getIntersection(p2[0],p2[1],p1[0],p1[1]);
|
338 |
// double xdist=2*pl.distance(x,y);
|
339 |
double xdist=2*center.distance(x,y); |
340 |
end=UtilFunctions.getPoint(center,end,center.distance(x,y)); |
341 |
//end=new Point2D.Double(end.getX()+dx,end.getY()+dy);
|
342 |
init=UtilFunctions.getPoint(end,center,xdist); |
343 |
Arc2D.Double arc = new Arc2D.Double(init.getX(), |
344 |
init.getY() - ydist, xdist, 2 * ydist, 0, 360, Arc2D.OPEN); |
345 |
Point2D rotationPoint = new Point2D.Double(init.getX() + xdist /2, init.getY()); |
346 |
|
347 |
double angle = UtilFunctions.getAngle(init, end);
|
348 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, init.getX(), init.getY()); |
349 |
gp = new GeneralPathX(arc);
|
350 |
gp.transform(mT); |
351 |
|
352 |
} |
353 |
} |
354 |
/**
|
355 |
* DOCUMENT ME!
|
356 |
*
|
357 |
* @author Vicente Caballero Navarro
|
358 |
*/
|
359 |
class RadioSelYHandler extends AbstractHandler implements ICuadrantHandler{ |
360 |
/**
|
361 |
* Crea un nuevo PointHandler.
|
362 |
*
|
363 |
* @param i DOCUMENT ME!
|
364 |
* @param x DOCUMENT ME!
|
365 |
* @param y DOCUMENT ME!
|
366 |
*/
|
367 |
public RadioSelYHandler(int i, double x, double y) { |
368 |
point = new Point2D.Double(x, y); |
369 |
index = i; |
370 |
} |
371 |
|
372 |
/**
|
373 |
* DOCUMENT ME!
|
374 |
*
|
375 |
* @param x DOCUMENT ME!
|
376 |
* @param y DOCUMENT ME!
|
377 |
*
|
378 |
* @return DOCUMENT ME!
|
379 |
*/
|
380 |
public void move(double x, double y) { |
381 |
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
386 |
*/
|
387 |
public void set(double x, double y) { |
388 |
ydist=new Point2D.Double((init.getX() + end.getX()) / 2, |
389 |
(init.getY() + end.getY()) / 2).distance(x,y);
|
390 |
//ydist=getSelectHandlers()[1].getPoint().distance(x,y);
|
391 |
// Point2D center=new Point2D.Double((init.getX() + end.getX()) / 2,
|
392 |
// (init.getY() + end.getY()) / 2);
|
393 |
// Point2D[] p=TrigonometricalFunctions.getPerpendicular(init,end,new Point2D.Double(x,y));
|
394 |
// Point2D pl=TrigonometricalFunctions.getIntersection(p[0],p[1],init,end);
|
395 |
// double xdist=2*pl.distance(x,y);
|
396 |
double xdist = init.distance(end);
|
397 |
Arc2D.Double arc = new Arc2D.Double(init.getX(), |
398 |
init.getY() - ydist, xdist, 2 * ydist, 0, 360, Arc2D.OPEN); |
399 |
Point2D rotationPoint = new Point2D.Double(init.getX() + xdist /2, init.getY()); |
400 |
|
401 |
double angle = UtilFunctions.getAngle(init, end);
|
402 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, init.getX(), init.getY()); |
403 |
gp = new GeneralPathX(arc);
|
404 |
gp.transform(mT); |
405 |
} |
406 |
} |
407 |
|
408 |
/* (non-Javadoc)
|
409 |
* @see com.iver.cit.gvsig.fmap.core.FPolyline2D#intersects(java.awt.geom.Rectangle2D)
|
410 |
*/
|
411 |
public boolean intersects(Rectangle2D r) { |
412 |
return gp.intersects(r);
|
413 |
} |
414 |
|
415 |
} |