root / branches / pilotoDWG / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / ShapeFactory.java @ 1532
History | View | Annotate | Download (5.2 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 |
|
47 |
import com.iver.cit.gvsig.fmap.edition.cad.TrigonometricalFunctions; |
48 |
|
49 |
/**
|
50 |
* Clase que crea las geometr?as, contendra un m?todo create por cada tipo de
|
51 |
* geometria que soporte gvSIG
|
52 |
*/
|
53 |
public class ShapeFactory { |
54 |
/**
|
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 |
|
66 |
/**
|
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 |
|
78 |
/**
|
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 |
|
91 |
/**
|
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 |
public static IGeometry createCircle(Point2D center, Point2D r){ |
140 |
double radio = center.distance(r);
|
141 |
return createCircle(center, radio);
|
142 |
} |
143 |
|
144 |
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 |
return new FGeometry(new FCircle2D(new GeneralPathX(arc))); |
149 |
} |
150 |
|
151 |
public static IGeometry createEllipse(Point2D axis1Start, Point2D axis1End, double axis2Length){ |
152 |
double xAxis = axis1Start.distance(axis1End);
|
153 |
Arc2D.Double arc = new Arc2D.Double(axis1Start.getX(), |
154 |
axis1Start.getY() - axis2Length, xAxis, 2 * axis2Length, 0, 360, Arc2D.OPEN); |
155 |
Point2D rotationPoint = new Point2D.Double(axis1Start.getX() + xAxis /2, axis1Start.getY()); |
156 |
|
157 |
// double angle = Math.atan2(axis1End.getX() - axis1Start.getX(),
|
158 |
// axis1End.getY() - axis1Start.getY());
|
159 |
double angle = TrigonometricalFunctions.getAngle(axis1Start, axis1End);
|
160 |
// double distortedAngle = Math.atan2(Math.sin(angle) * xAxis, Math.cos(angle) * 2 * axis2Length);
|
161 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, axis1Start.getX(), axis1Start.getY()); |
162 |
GeneralPathX gp = new GeneralPathX(arc);
|
163 |
gp.transform(mT); |
164 |
|
165 |
return new FGeometry(new FEllipse2D(new GeneralPathX(gp),axis1Start,axis1End,axis2Length)); |
166 |
} |
167 |
|
168 |
public static IGeometry createArc(Point2D p1, Point2D p2, Point2D p3){ |
169 |
Arc2D arco = TrigonometricalFunctions.createArc(p1, p2, p3);
|
170 |
if (arco == null) return null; |
171 |
FArc2D arc=new FArc2D(new GeneralPathX(arco),p1,p2,p3); |
172 |
return new FGeometry(arc); |
173 |
} |
174 |
|
175 |
/**
|
176 |
* Crea a partir de un FShape una geometr?a.
|
177 |
*
|
178 |
* @param shp FShape.
|
179 |
*
|
180 |
* @return Geometr?a.
|
181 |
*/
|
182 |
public static FGeometry createGeometry(FShape shp) { |
183 |
return new FGeometry(shp); |
184 |
} |
185 |
} |