root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 11139
History | View | Annotate | Download (8.36 KB)
1 | 305 | fjp | /*
|
---|---|---|---|
2 | * Created on 25-nov-2004
|
||
3 | *
|
||
4 | * TODO To change the template for this generated file go to
|
||
5 | * Window - Preferences - Java - Code Generation - Code and Comments
|
||
6 | */
|
||
7 | 1100 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | 214 | fernando | package com.iver.cit.gvsig.fmap.core; |
48 | |||
49 | 3885 | caballero | import java.awt.Graphics2D; |
50 | 4879 | fjp | import java.awt.Rectangle; |
51 | 5008 | fjp | import java.awt.Shape; |
52 | 3885 | caballero | import java.awt.geom.AffineTransform; |
53 | 4799 | fjp | import java.awt.geom.PathIterator; |
54 | 3885 | caballero | import java.awt.geom.Point2D; |
55 | import java.awt.geom.Rectangle2D; |
||
56 | import java.io.IOException; |
||
57 | |||
58 | import org.cresques.cts.ICoordTrans; |
||
59 | import org.geotools.data.postgis.attributeio.WKBEncoder; |
||
60 | |||
61 | 237 | fjp | import com.iver.cit.gvsig.fmap.ViewPort; |
62 | 9641 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
63 | 703 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
64 | 757 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
65 | 324 | fernando | import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
66 | 703 | fjp | import com.vividsolutions.jts.geom.Geometry; |
67 | 214 | fernando | |
68 | 1005 | vcaballero | |
69 | 214 | fernando | /**
|
70 | 1005 | vcaballero | * Geometr?a.
|
71 | *
|
||
72 | 305 | fjp | * @author FJP
|
73 | 214 | fernando | */
|
74 | 2196 | vcaballero | public class FGeometry implements IGeometry3D { |
75 | 5880 | fjp | /**
|
76 | *
|
||
77 | */
|
||
78 | private static final long serialVersionUID = 5431865770186523337L; |
||
79 | private FShape shp;
|
||
80 | private Rectangle2D bounds2D; |
||
81 | 214 | fernando | |
82 | 5880 | fjp | /**
|
83 | * Crea un nuevo FGeometry.
|
||
84 | *
|
||
85 | * @param shp DOCUMENT ME!
|
||
86 | */
|
||
87 | FGeometry(FShape shp) { |
||
88 | this.shp = shp;
|
||
89 | } |
||
90 | 1005 | vcaballero | |
91 | 5880 | fjp | /* (non-Javadoc)
|
92 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, org.geotools.renderer.style.Style2D)
|
||
93 | */
|
||
94 | public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) { |
||
95 | // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
|
||
96 | // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
|
||
97 | // SHAPE
|
||
98 | // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
|
||
99 | transform(vp.getAffineTransform()); |
||
100 | 1005 | vcaballero | |
101 | 5880 | fjp | switch (shp.getShapeType()) {
|
102 | case FShape.POINT:
|
||
103 | shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
|
||
104 | 1005 | vcaballero | |
105 | 5880 | fjp | break;
|
106 | 1005 | vcaballero | |
107 | 5880 | fjp | case FShape.LINE:
|
108 | shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
|
||
109 | 1005 | vcaballero | |
110 | 5880 | fjp | break;
|
111 | 1005 | vcaballero | |
112 | 5880 | fjp | case FShape.POLYGON:
|
113 | shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
|
||
114 | 1005 | vcaballero | |
115 | 5880 | fjp | break;
|
116 | 1005 | vcaballero | |
117 | 5880 | fjp | case FShape.TEXT:
|
118 | shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
|
||
119 | } |
||
120 | } |
||
121 | 458 | fjp | |
122 | 5880 | fjp | /**
|
123 | * Dibuja la geometria actual en el graphics que se le pasa como par?metro,
|
||
124 | * aplicandole las caracter?sticas del s?mbolo.
|
||
125 | *
|
||
126 | * @param g Graphics2D.
|
||
127 | * @param vp ViewPort.
|
||
128 | * @param symbol S?mbolo.
|
||
129 | */
|
||
130 | 7659 | fjp | public void draw(Graphics2D g, ViewPort vp, ISymbol symbol) { |
131 | 5880 | fjp | // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
|
132 | // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
|
||
133 | // SHAPE
|
||
134 | // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
|
||
135 | transform(vp.getAffineTransform()); |
||
136 | 7659 | fjp | symbol.draw(g, vp.getAffineTransform(), shp); |
137 | // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
|
||
138 | 5880 | fjp | } |
139 | 458 | fjp | |
140 | 2859 | fjp | /* (non-Javadoc)
|
141 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#drawInts(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
|
||
142 | */
|
||
143 | 7659 | fjp | public void drawInts(Graphics2D g, ViewPort vp, ISymbol symbol) { |
144 | 8516 | jaume | try
|
145 | { |
||
146 | FShape decimatedShape = FConverter.transformToInts(this, vp.getAffineTransform());
|
||
147 | symbol.draw(g, vp.getAffineTransform(), decimatedShape); |
||
148 | } |
||
149 | catch (Exception e) |
||
150 | { |
||
151 | e.printStackTrace(); |
||
152 | } |
||
153 | 7659 | fjp | // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), decimatedShape, symbol);
|
154 | 2859 | fjp | } |
155 | |||
156 | 5880 | fjp | /**
|
157 | * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
|
||
158 | * que se pasa como par?metro.
|
||
159 | *
|
||
160 | * @param at Matriz de transformaci?n.
|
||
161 | */
|
||
162 | public void transform(AffineTransform at) { |
||
163 | shp.transform(at); |
||
164 | } |
||
165 | 214 | fernando | |
166 | 5880 | fjp | /* (non-Javadoc)
|
167 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
||
168 | */
|
||
169 | public boolean intersects(Rectangle2D r) { |
||
170 | return shp.intersects(r);
|
||
171 | } |
||
172 | 214 | fernando | |
173 | 5880 | fjp | /* (non-Javadoc)
|
174 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
||
175 | */
|
||
176 | public Rectangle2D getBounds2D() { |
||
177 | if (bounds2D == null) |
||
178 | { |
||
179 | bounds2D = shp.getBounds2D(); |
||
180 | } |
||
181 | // return shp.getBounds2D();
|
||
182 | return bounds2D;
|
||
183 | } |
||
184 | 8516 | jaume | |
185 | 5880 | fjp | public Rectangle2D reCalculateBounds2D() |
186 | { |
||
187 | return shp.getBounds2D();
|
||
188 | } |
||
189 | 305 | fjp | |
190 | 5880 | fjp | /* (non-Javadoc)
|
191 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
|
||
192 | */
|
||
193 | public Geometry toJTSGeometry() {
|
||
194 | return FConverter.java2d_to_jts(shp);
|
||
195 | } |
||
196 | 305 | fjp | |
197 | 5880 | fjp | /* (non-Javadoc)
|
198 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
|
||
199 | */
|
||
200 | public FLabel[] createLabels(int position, boolean duplicates) { |
||
201 | FLabel[] aux = new FLabel[1]; |
||
202 | aux[0] = FLabel.createFLabel(shp);
|
||
203 | 1005 | vcaballero | |
204 | 5880 | fjp | return aux;
|
205 | } |
||
206 | 305 | fjp | |
207 | 5880 | fjp | /**
|
208 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
|
||
209 | */
|
||
210 | public int getGeometryType() { |
||
211 | return shp.getShapeType();
|
||
212 | } |
||
213 | 324 | fernando | |
214 | 5880 | fjp | /* (non-Javadoc)
|
215 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
||
216 | */
|
||
217 | public IGeometry cloneGeometry() {
|
||
218 | return new FGeometry(shp.cloneFShape()); |
||
219 | } |
||
220 | 627 | fjp | |
221 | 5880 | fjp | /* (non-Javadoc)
|
222 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
|
||
223 | */
|
||
224 | public void reProject(ICoordTrans ct) { |
||
225 | shp.reProject(ct); |
||
226 | } |
||
227 | 1132 | vcaballero | |
228 | 5880 | fjp | /**
|
229 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(AffineTransform)
|
||
230 | */
|
||
231 | public PathIterator getPathIterator(AffineTransform at) { |
||
232 | return (GeneralPathXIterator)shp.getPathIterator(null); |
||
233 | } |
||
234 | 1298 | fjp | |
235 | 4799 | fjp | |
236 | 8516 | jaume | |
237 | 1298 | fjp | /* (non-Javadoc)
|
238 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
|
||
239 | */
|
||
240 | public boolean fastIntersects(double x, double y, double w, double h) { |
||
241 | return shp.intersects(x,y,w,h);
|
||
242 | } |
||
243 | 3833 | caballero | |
244 | 2183 | fernando | public byte[] toWKB() throws IOException{ |
245 | return WKBEncoder.encodeGeometry(toJTSGeometry());
|
||
246 | } |
||
247 | 2196 | vcaballero | /**
|
248 | 5880 | fjp | * Devuelve un array con todos los valores de Z.
|
249 | *
|
||
250 | * @return Array de Zs.
|
||
251 | */
|
||
252 | public double[] getZs() { |
||
253 | return ((FShape3D) shp).getZs();
|
||
254 | } |
||
255 | /**
|
||
256 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
|
||
257 | */
|
||
258 | public Handler[] getHandlers(int type) { |
||
259 | if (type==STRETCHINGHANDLER){
|
||
260 | return shp.getStretchingHandlers();
|
||
261 | }else if (type==SELECTHANDLER){ |
||
262 | return shp.getSelectHandlers();
|
||
263 | } |
||
264 | return null; |
||
265 | } |
||
266 | 3885 | caballero | |
267 | 5880 | fjp | /* (non-Javadoc)
|
268 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator(java.awt.geom.AffineTransform, double)
|
||
269 | */
|
||
270 | public PathIterator getPathIterator(AffineTransform at, double flatness) { |
||
271 | return shp.getPathIterator(at, flatness);
|
||
272 | } |
||
273 | 4799 | fjp | |
274 | 5880 | fjp | public boolean contains(double x, double y) { |
275 | return shp.contains(x,y);
|
||
276 | } |
||
277 | 4879 | fjp | |
278 | 5880 | fjp | public boolean contains(double x, double y, double w, double h) { |
279 | return shp.contains(x,y,w,h);
|
||
280 | } |
||
281 | 4879 | fjp | |
282 | 5880 | fjp | public boolean intersects(double x, double y, double w, double h) { |
283 | return shp.intersects(x,y,w,h);
|
||
284 | } |
||
285 | 4879 | fjp | |
286 | 5880 | fjp | public Rectangle getBounds() { |
287 | return shp.getBounds();
|
||
288 | } |
||
289 | 4879 | fjp | |
290 | 5880 | fjp | public boolean contains(Point2D p) { |
291 | return shp.contains(p);
|
||
292 | } |
||
293 | 4879 | fjp | |
294 | 5880 | fjp | public boolean contains(Rectangle2D r) { |
295 | return shp.contains(r);
|
||
296 | } |
||
297 | 4879 | fjp | |
298 | 5880 | fjp | public Shape getInternalShape() { |
299 | return shp;
|
||
300 | } |
||
301 | 5008 | fjp | |
302 | 5880 | fjp | /* public void move(double x, double y) {
|
303 | AffineTransform at = new AffineTransform();
|
||
304 | at.translate(x, y);
|
||
305 | transform(at);
|
||
306 | }
|
||
307 | public void rotate(double r, double x, double y) {
|
||
308 | AffineTransform at = new AffineTransform();
|
||
309 | at.rotate(r, x, y);
|
||
310 | transform(at);
|
||
311 | }
|
||
312 | public void scale(Point2D point,double x, double y) {
|
||
313 | AffineTransform at = new AffineTransform();
|
||
314 | at.setToTranslation(point.getX(),point.getY());
|
||
315 | at.scale(x,y);
|
||
316 | at.translate(-point.getX(),-point.getY());
|
||
317 | transform(at);
|
||
318 | } */
|
||
319 | 214 | fernando | } |