root / branches / FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FArc2D.java @ 1762
History | View | Annotate | Download (12.7 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.cad.TrigonometricalFunctions; |
54 |
|
55 |
/**
|
56 |
* DOCUMENT ME!
|
57 |
*
|
58 |
* @author Vicente Caballero Navarro
|
59 |
*/
|
60 |
public class FArc2D extends FPolyline2D { |
61 |
private Point2D init; |
62 |
private Point2D center; |
63 |
private Point2D end; |
64 |
/**
|
65 |
* DOCUMENT ME!
|
66 |
*
|
67 |
* @param gpx
|
68 |
*/
|
69 |
public FArc2D(GeneralPathX gpx,Point2D i,Point2D c, Point2D e) { |
70 |
super(gpx);
|
71 |
init=i; |
72 |
center=c; |
73 |
end=e; |
74 |
} |
75 |
public Point2D getInit(){ |
76 |
return init;
|
77 |
} |
78 |
public Point2D getEnd(){ |
79 |
return end;
|
80 |
} |
81 |
public Point2D getCenter(){ |
82 |
return TrigonometricalFunctions.getCenter(init, center,end);
|
83 |
} |
84 |
public Point2D getMid(){ |
85 |
return center;
|
86 |
} |
87 |
/* (non-Javadoc)
|
88 |
* @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
|
89 |
*/
|
90 |
public FShape cloneFShape() {
|
91 |
FArc2D arc=new FArc2D((GeneralPathX) gp.clone(),init,center,end);
|
92 |
return arc;
|
93 |
} |
94 |
public void transform(AffineTransform at) { |
95 |
gp.transform(at); |
96 |
InitHandler inithandler=(InitHandler)getStretchingHandlers()[0];
|
97 |
//CenterHandler centerhandler=(CenterHandler)getHandlers()[1];
|
98 |
EndHandler endhandler=(EndHandler)getStretchingHandlers()[1];
|
99 |
Point2D aux1=new Point2D.Double(); |
100 |
Point2D aux2=new Point2D.Double(); |
101 |
Point2D aux3=new Point2D.Double(); |
102 |
at.transform(inithandler.getPoint(),aux1); |
103 |
inithandler.setPoint(aux1); |
104 |
//at.transform(centerhandler.getPoint(),aux2);
|
105 |
//centerhandler.setPoint(aux2);
|
106 |
at.transform(endhandler.getPoint(),aux3); |
107 |
endhandler.setPoint(aux3); |
108 |
CenterSelHandler centerhandler=(CenterSelHandler)getSelectHandlers()[1];
|
109 |
at.transform(centerhandler.getPoint(),aux2); |
110 |
centerhandler.setPoint(aux2); |
111 |
} |
112 |
/**
|
113 |
* @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
|
114 |
*/
|
115 |
public int getShapeType() { |
116 |
return FShape.ARC;
|
117 |
} |
118 |
/**
|
119 |
* DOCUMENT ME!
|
120 |
*
|
121 |
* @return DOCUMENT ME!
|
122 |
*/
|
123 |
public Handler[] getStretchingHandlers() { |
124 |
ArrayList handlers = new ArrayList(); |
125 |
|
126 |
handlers.add(new InitHandler(0, init.getX(), init.getY())); |
127 |
//handlers.add(new CenterHandler(1, center.getX(), center.getY()));
|
128 |
handlers.add(new EndHandler(1, end.getX(), end.getY())); |
129 |
|
130 |
return (Handler[]) handlers.toArray(new Handler[0]); |
131 |
} |
132 |
public Handler[] getSelectHandlers() { |
133 |
ArrayList handlers = new ArrayList(); |
134 |
|
135 |
handlers.add(new InitSelHandler(0, init.getX(), init.getY())); |
136 |
handlers.add(new CenterSelHandler(1, center.getX(), center.getY())); |
137 |
handlers.add(new EndSelHandler(2, end.getX(), end.getY())); |
138 |
|
139 |
return (Handler[]) handlers.toArray(new Handler[0]); |
140 |
} |
141 |
/**
|
142 |
* DOCUMENT ME!
|
143 |
*
|
144 |
* @author Vicente Caballero Navarro
|
145 |
*/
|
146 |
class CenterSelHandler extends AbstractHandler { |
147 |
/**
|
148 |
* Crea un nuevo PointHandler.
|
149 |
*
|
150 |
* @param i DOCUMENT ME!
|
151 |
* @param x DOCUMENT ME!
|
152 |
* @param y DOCUMENT ME!
|
153 |
*/
|
154 |
public CenterSelHandler(int i, double x, double y) { |
155 |
center = new Point2D.Double(x, y); |
156 |
index = i; |
157 |
} |
158 |
|
159 |
/**
|
160 |
* DOCUMENT ME!
|
161 |
*
|
162 |
* @param x DOCUMENT ME!
|
163 |
* @param y DOCUMENT ME!
|
164 |
*
|
165 |
* @return DOCUMENT ME!
|
166 |
*/
|
167 |
public void move(double x, double y) { |
168 |
|
169 |
/* Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
|
170 |
Point2D[] ps1=TrigonometricalFunctions.getPerpendicular(init,end,mediop);
|
171 |
|
172 |
Point2D unit=TrigonometricalFunctions.getUnitVector(mediop,center);
|
173 |
double dist=mediop.distance(center);
|
174 |
|
175 |
*/
|
176 |
|
177 |
//////////////
|
178 |
/* center=new Point2D.Double(center.getX()+x,center.getY()+y);
|
179 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
180 |
gp=new GeneralPathX(arco);
|
181 |
*/
|
182 |
} |
183 |
public void setPoint(Point2D p){ |
184 |
center=p; |
185 |
} |
186 |
public Point2D getPoint(){ |
187 |
return center;
|
188 |
} |
189 |
|
190 |
/**
|
191 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
192 |
*/
|
193 |
public void set(double x, double y) { |
194 |
center=new Point2D.Double(x,y); |
195 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
196 |
gp=new GeneralPathX(arco);
|
197 |
} |
198 |
} |
199 |
|
200 |
/**
|
201 |
* DOCUMENT ME!
|
202 |
*
|
203 |
* @author Vicente Caballero Navarro
|
204 |
*/
|
205 |
class InitHandler extends AbstractHandler { |
206 |
/**
|
207 |
* Crea un nuevo PointHandler.
|
208 |
*
|
209 |
* @param i DOCUMENT ME!
|
210 |
* @param x DOCUMENT ME!
|
211 |
* @param y DOCUMENT ME!
|
212 |
*/
|
213 |
public InitHandler(int i, double x, double y) { |
214 |
init = new Point2D.Double(x, y); |
215 |
index = i; |
216 |
} |
217 |
|
218 |
/**
|
219 |
* DOCUMENT ME!
|
220 |
*
|
221 |
* @param x DOCUMENT ME!
|
222 |
* @param y DOCUMENT ME!
|
223 |
*
|
224 |
* @return DOCUMENT ME!
|
225 |
*/
|
226 |
public void move(double x, double y) { |
227 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
228 |
double dist=mediop.distance(center);
|
229 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
230 |
|
231 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
232 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop); |
233 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){ |
234 |
dist=-dist; |
235 |
} |
236 |
center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
237 |
|
238 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
239 |
gp=new GeneralPathX(arco);
|
240 |
} |
241 |
public void setPoint(Point2D p){ |
242 |
init=p; |
243 |
} |
244 |
public Point2D getPoint(){ |
245 |
return init;
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
250 |
*/
|
251 |
public void set(double x, double y) { |
252 |
/* Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
|
253 |
double dist=mediop.distance(center);
|
254 |
init=new Point2D.Double(x,y);
|
255 |
|
256 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
|
257 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop);
|
258 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){
|
259 |
dist=-dist;
|
260 |
}
|
261 |
center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
262 |
|
263 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
264 |
gp=new GeneralPathX(arco);
|
265 |
*/
|
266 |
} |
267 |
} |
268 |
/**
|
269 |
* DOCUMENT ME!
|
270 |
*
|
271 |
* @author Vicente Caballero Navarro
|
272 |
*/
|
273 |
class EndHandler extends AbstractHandler { |
274 |
/**
|
275 |
* Crea un nuevo PointHandler.
|
276 |
*
|
277 |
* @param i DOCUMENT ME!
|
278 |
* @param x DOCUMENT ME!
|
279 |
* @param y DOCUMENT ME!
|
280 |
*/
|
281 |
public EndHandler(int i, double x, double y) { |
282 |
end = new Point2D.Double(x, y); |
283 |
index = i; |
284 |
} |
285 |
|
286 |
/**
|
287 |
* DOCUMENT ME!
|
288 |
*
|
289 |
* @param x DOCUMENT ME!
|
290 |
* @param y DOCUMENT ME!
|
291 |
*
|
292 |
* @return DOCUMENT ME!
|
293 |
*/
|
294 |
public void move(double x, double y) { |
295 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
296 |
double dist=mediop.distance(center);
|
297 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
298 |
|
299 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
300 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop); |
301 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){ |
302 |
dist=-dist; |
303 |
} |
304 |
center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
305 |
|
306 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
307 |
gp=new GeneralPathX(arco);
|
308 |
} |
309 |
public void setPoint(Point2D p){ |
310 |
end=p; |
311 |
} |
312 |
public Point2D getPoint(){ |
313 |
return end;
|
314 |
} |
315 |
|
316 |
/**
|
317 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
318 |
*/
|
319 |
public void set(double x, double y) { |
320 |
/* Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
|
321 |
double dist=mediop.distance(center);
|
322 |
end=new Point2D.Double(x,y);
|
323 |
|
324 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2);
|
325 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop);
|
326 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){
|
327 |
dist=-dist;
|
328 |
}
|
329 |
center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
330 |
|
331 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
332 |
gp=new GeneralPathX(arco);
|
333 |
*/
|
334 |
} |
335 |
} |
336 |
/**
|
337 |
* DOCUMENT ME!
|
338 |
*
|
339 |
* @author Vicente Caballero Navarro
|
340 |
*/
|
341 |
class InitSelHandler extends AbstractHandler { |
342 |
/**
|
343 |
* Crea un nuevo PointHandler.
|
344 |
*
|
345 |
* @param i DOCUMENT ME!
|
346 |
* @param x DOCUMENT ME!
|
347 |
* @param y DOCUMENT ME!
|
348 |
*/
|
349 |
public InitSelHandler(int i, double x, double y) { |
350 |
init = new Point2D.Double(x, y); |
351 |
index = i; |
352 |
} |
353 |
|
354 |
/**
|
355 |
* DOCUMENT ME!
|
356 |
*
|
357 |
* @param x DOCUMENT ME!
|
358 |
* @param y DOCUMENT ME!
|
359 |
*
|
360 |
* @return DOCUMENT ME!
|
361 |
*/
|
362 |
public void move(double x, double y) { |
363 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
364 |
double dist=mediop.distance(center);
|
365 |
init=new Point2D.Double(init.getX()+x,init.getY()+y); |
366 |
|
367 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
368 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop); |
369 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){ |
370 |
dist=-dist; |
371 |
} |
372 |
center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
373 |
|
374 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
375 |
gp=new GeneralPathX(arco);
|
376 |
} |
377 |
public void setPoint(Point2D p){ |
378 |
init=p; |
379 |
} |
380 |
public Point2D getPoint(){ |
381 |
return init;
|
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 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
389 |
double dist=mediop.distance(center);
|
390 |
init=new Point2D.Double(x,y); |
391 |
|
392 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
393 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop); |
394 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){ |
395 |
dist=-dist; |
396 |
} |
397 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
398 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
399 |
gp=new GeneralPathX(arco);
|
400 |
} |
401 |
} |
402 |
/**
|
403 |
* DOCUMENT ME!
|
404 |
*
|
405 |
* @author Vicente Caballero Navarro
|
406 |
*/
|
407 |
class EndSelHandler extends AbstractHandler { |
408 |
/**
|
409 |
* Crea un nuevo PointHandler.
|
410 |
*
|
411 |
* @param i DOCUMENT ME!
|
412 |
* @param x DOCUMENT ME!
|
413 |
* @param y DOCUMENT ME!
|
414 |
*/
|
415 |
public EndSelHandler(int i, double x, double y) { |
416 |
end = new Point2D.Double(x, y); |
417 |
index = i; |
418 |
} |
419 |
|
420 |
/**
|
421 |
* DOCUMENT ME!
|
422 |
*
|
423 |
* @param x DOCUMENT ME!
|
424 |
* @param y DOCUMENT ME!
|
425 |
*
|
426 |
* @return DOCUMENT ME!
|
427 |
*/
|
428 |
public void move(double x, double y) { |
429 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
430 |
double dist=mediop.distance(center);
|
431 |
end=new Point2D.Double(end.getX()+x,end.getY()+y); |
432 |
|
433 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
434 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop); |
435 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){ |
436 |
dist=-dist; |
437 |
} |
438 |
center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
439 |
|
440 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
441 |
gp=new GeneralPathX(arco);
|
442 |
} |
443 |
public void setPoint(Point2D p){ |
444 |
end=p; |
445 |
} |
446 |
public Point2D getPoint(){ |
447 |
return end;
|
448 |
} |
449 |
|
450 |
/**
|
451 |
* @see com.iver.cit.gvsig.fmap.core.Handler#set(double, double)
|
452 |
*/
|
453 |
public void set(double x, double y) { |
454 |
Point2D mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
455 |
double dist=mediop.distance(center);
|
456 |
end=new Point2D.Double(x,y); |
457 |
|
458 |
mediop=new Point2D.Double((init.getX()+end.getX())/2,(init.getY()+end.getY())/2); |
459 |
Point2D[] perp=TrigonometricalFunctions.getPerpendicular(init,end,mediop); |
460 |
if (TrigonometricalFunctions.getAngle(end,init)<=Math.PI){ |
461 |
dist=-dist; |
462 |
} |
463 |
///center=TrigonometricalFunctions.getPoint(mediop,perp[1],dist);
|
464 |
Arc2D arco = TrigonometricalFunctions.createArc(init,center, end);
|
465 |
gp=new GeneralPathX(arco);
|
466 |
} |
467 |
} |
468 |
} |