root / branches / FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / ShapeFactory.java @ 1762
History | View | Annotate | Download (5.42 KB)
1 | 1100 | fjp | /* 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 | 214 | fernando | package com.iver.cit.gvsig.fmap.core; |
42 | |||
43 | 1434 | fernando | import java.awt.geom.AffineTransform; |
44 | import java.awt.geom.Arc2D; |
||
45 | 1401 | fernando | import java.awt.geom.Point2D; |
46 | |||
47 | 1439 | fernando | import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
48 | |||
49 | 214 | fernando | /**
|
50 | 1005 | vcaballero | * Clase que crea las geometr?as, contendra un m?todo create por cada tipo de
|
51 | * geometria que soporte gvSIG
|
||
52 | 214 | fernando | */
|
53 | public class ShapeFactory { |
||
54 | 1005 | vcaballero | /**
|
55 | * Crea una geometr?a que contiene como shape un punto 2D.
|
||
56 | *
|
||
57 | * @param x Coordenada x.
|
||
58 | * @param y Coordenada y.
|
||
59 | *
|
||
60 | * @return Geometr?a.
|
||
61 | */
|
||
62 | public static IGeometry createPoint2D(double x, double y) { |
||
63 | return new FGeometry(new FPoint2D(x, y)); |
||
64 | } |
||
65 | 214 | fernando | |
66 | 1005 | vcaballero | /**
|
67 | * Crea una geometr?a que contiene como shape un Multipunto 2D.
|
||
68 | *
|
||
69 | * @param x Coordenada x.
|
||
70 | * @param y Coordenada y.
|
||
71 | *
|
||
72 | * @return Geometr?a.
|
||
73 | */
|
||
74 | public static IGeometry createMultipoint2D(double[] x, double[] y) { |
||
75 | return new FMultiPoint2D(x, y); |
||
76 | } |
||
77 | 214 | fernando | |
78 | 1005 | vcaballero | /**
|
79 | * Crea una geometr?a que contiene como shape un punto 3D.
|
||
80 | *
|
||
81 | * @param x Coordenada x.
|
||
82 | * @param y Coordenada y.
|
||
83 | * @param z Coordenada z.
|
||
84 | *
|
||
85 | * @return Geometr?a.
|
||
86 | */
|
||
87 | public static IGeometry createPoint3D(double x, double y, double z) { |
||
88 | return new FGeometry(new FPoint3D(x, y, z)); |
||
89 | } |
||
90 | 214 | fernando | |
91 | 1005 | vcaballero | /**
|
92 | * Crea una geometr?a que contiene como shape un Multipunto 3D.
|
||
93 | *
|
||
94 | * @param x Coordenada x.
|
||
95 | * @param y Coordenada y.
|
||
96 | * @param z Coordenada z.
|
||
97 | *
|
||
98 | * @return Geometr?a.
|
||
99 | */
|
||
100 | public static IGeometry createMultipoint3D(double[] x, double[] y, |
||
101 | double[] z) { |
||
102 | return new FMultipoint3D(x, y, z); |
||
103 | } |
||
104 | |||
105 | /**
|
||
106 | * Crea una geometr?a que contiene como shape un Polil?nea 2D.
|
||
107 | *
|
||
108 | * @param shape GeneralPathX.
|
||
109 | *
|
||
110 | * @return Geometr?a.
|
||
111 | */
|
||
112 | public static IGeometry createPolyline2D(GeneralPathX shape) { |
||
113 | return new FGeometry(new FPolyline2D(shape)); |
||
114 | } |
||
115 | |||
116 | /**
|
||
117 | * Crea una geometr?a que contiene como shape un Polil?nea 3D.
|
||
118 | *
|
||
119 | * @param shape GeneralPathX.
|
||
120 | * @param pZ Vector de Z.
|
||
121 | *
|
||
122 | * @return Geometr?a.
|
||
123 | */
|
||
124 | public static IGeometry createPolyline3D(GeneralPathX shape, double[] pZ) { |
||
125 | return new FGeometry(new FPolyline3D(shape, pZ)); |
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | * Crea una geometr?a que contiene como shape un Pol?gono 2D.
|
||
130 | *
|
||
131 | * @param shape GeneralPathX.
|
||
132 | *
|
||
133 | * @return Geometr?a.
|
||
134 | */
|
||
135 | public static IGeometry createPolygon2D(GeneralPathX shape) { |
||
136 | return new FGeometry(new FPolygon2D(shape)); |
||
137 | } |
||
138 | |||
139 | 1401 | fernando | public static IGeometry createCircle(Point2D center, Point2D r){ |
140 | double radio = center.distance(r);
|
||
141 | 1434 | fernando | return createCircle(center, radio);
|
142 | 1401 | fernando | } |
143 | |||
144 | 1434 | fernando | public static IGeometry createCircle(Point2D center, double radio){ |
145 | Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio, |
||
146 | 2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
||
147 | |||
148 | 1535 | vcaballero | return new FGeometry(new FCircle2D(new GeneralPathX(arc),center,radio)); |
149 | 1401 | fernando | } |
150 | 1762 | vcaballero | public static IGeometry createCircle(Point2D p1, Point2D p2, Point2D p3){ |
151 | Point2D center = TrigonometricalFunctions.getCenter(p1, p2, p3);
|
||
152 | if (center!=null) |
||
153 | return createCircle(center,p1);
|
||
154 | return null; |
||
155 | } |
||
156 | 1401 | fernando | public static IGeometry createEllipse(Point2D axis1Start, Point2D axis1End, double axis2Length){ |
157 | 1434 | fernando | double xAxis = axis1Start.distance(axis1End);
|
158 | Arc2D.Double arc = new Arc2D.Double(axis1Start.getX(), |
||
159 | axis1Start.getY() - axis2Length, xAxis, 2 * axis2Length, 0, 360, Arc2D.OPEN); |
||
160 | 1436 | fernando | Point2D rotationPoint = new Point2D.Double(axis1Start.getX() + xAxis /2, axis1Start.getY()); |
161 | |||
162 | 1434 | fernando | // double angle = Math.atan2(axis1End.getX() - axis1Start.getX(),
|
163 | // axis1End.getY() - axis1Start.getY());
|
||
164 | 1439 | fernando | double angle = TrigonometricalFunctions.getAngle(axis1Start, axis1End);
|
165 | // double distortedAngle = Math.atan2(Math.sin(angle) * xAxis, Math.cos(angle) * 2 * axis2Length);
|
||
166 | 1436 | fernando | AffineTransform mT = AffineTransform.getRotateInstance(angle, axis1Start.getX(), axis1Start.getY()); |
167 | 1434 | fernando | GeneralPathX gp = new GeneralPathX(arc);
|
168 | gp.transform(mT); |
||
169 | |||
170 | 1532 | vcaballero | return new FGeometry(new FEllipse2D(new GeneralPathX(gp),axis1Start,axis1End,axis2Length)); |
171 | 1401 | fernando | } |
172 | |||
173 | 1439 | fernando | public static IGeometry createArc(Point2D p1, Point2D p2, Point2D p3){ |
174 | Arc2D arco = TrigonometricalFunctions.createArc(p1, p2, p3);
|
||
175 | 1505 | fernando | if (arco == null) return null; |
176 | 1519 | vcaballero | FArc2D arc=new FArc2D(new GeneralPathX(arco),p1,p2,p3); |
177 | 1450 | vcaballero | return new FGeometry(arc); |
178 | 1439 | fernando | } |
179 | |||
180 | 1005 | vcaballero | /**
|
181 | * Crea a partir de un FShape una geometr?a.
|
||
182 | *
|
||
183 | * @param shp FShape.
|
||
184 | *
|
||
185 | * @return Geometr?a.
|
||
186 | */
|
||
187 | public static FGeometry createGeometry(FShape shp) { |
||
188 | return new FGeometry(shp); |
||
189 | } |
||
190 | 214 | fernando | } |