root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 12728
History | View | Annotate | Download (8.88 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 | 12657 | jaume | import com.iver.cit.gvsig.fmap.MapContext; |
62 | 237 | fjp | import com.iver.cit.gvsig.fmap.ViewPort; |
63 | 9641 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
64 | 703 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
65 | 757 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
66 | 324 | fernando | import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
67 | 703 | fjp | import com.vividsolutions.jts.geom.Geometry; |
68 | 214 | fernando | |
69 | 1005 | vcaballero | |
70 | 214 | fernando | /**
|
71 | 1005 | vcaballero | * Geometr?a.
|
72 | *
|
||
73 | 305 | fjp | * @author FJP
|
74 | 214 | fernando | */
|
75 | 2196 | vcaballero | public class FGeometry implements IGeometry3D { |
76 | 5880 | fjp | /**
|
77 | *
|
||
78 | */
|
||
79 | private static final long serialVersionUID = 5431865770186523337L; |
||
80 | private FShape shp;
|
||
81 | private Rectangle2D bounds2D; |
||
82 | 214 | fernando | |
83 | 5880 | fjp | /**
|
84 | * Crea un nuevo FGeometry.
|
||
85 | *
|
||
86 | * @param shp DOCUMENT ME!
|
||
87 | */
|
||
88 | FGeometry(FShape shp) { |
||
89 | this.shp = shp;
|
||
90 | } |
||
91 | 1005 | vcaballero | |
92 | 5880 | fjp | /* (non-Javadoc)
|
93 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, org.geotools.renderer.style.Style2D)
|
||
94 | */
|
||
95 | public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) { |
||
96 | // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
|
||
97 | // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
|
||
98 | // SHAPE
|
||
99 | // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
|
||
100 | transform(vp.getAffineTransform()); |
||
101 | 1005 | vcaballero | |
102 | 5880 | fjp | switch (shp.getShapeType()) {
|
103 | case FShape.POINT:
|
||
104 | shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
|
||
105 | 1005 | vcaballero | |
106 | 5880 | fjp | break;
|
107 | 1005 | vcaballero | |
108 | 5880 | fjp | case FShape.LINE:
|
109 | shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
|
||
110 | 1005 | vcaballero | |
111 | 5880 | fjp | break;
|
112 | 1005 | vcaballero | |
113 | 5880 | fjp | case FShape.POLYGON:
|
114 | shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
|
||
115 | 1005 | vcaballero | |
116 | 5880 | fjp | break;
|
117 | 1005 | vcaballero | |
118 | 5880 | fjp | case FShape.TEXT:
|
119 | shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
|
||
120 | } |
||
121 | } |
||
122 | 458 | fjp | |
123 | 5880 | fjp | /**
|
124 | * Dibuja la geometria actual en el graphics que se le pasa como par?metro,
|
||
125 | * aplicandole las caracter?sticas del s?mbolo.
|
||
126 | *
|
||
127 | * @param g Graphics2D.
|
||
128 | * @param vp ViewPort.
|
||
129 | * @param symbol S?mbolo.
|
||
130 | */
|
||
131 | 7659 | fjp | public void draw(Graphics2D g, ViewPort vp, ISymbol symbol) { |
132 | 5880 | fjp | // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
|
133 | // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
|
||
134 | // SHAPE
|
||
135 | // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
|
||
136 | transform(vp.getAffineTransform()); |
||
137 | 7659 | fjp | symbol.draw(g, vp.getAffineTransform(), shp); |
138 | // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
|
||
139 | 5880 | fjp | } |
140 | 458 | fjp | |
141 | 2859 | fjp | /* (non-Javadoc)
|
142 | * @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)
|
||
143 | */
|
||
144 | 7659 | fjp | public void drawInts(Graphics2D g, ViewPort vp, ISymbol symbol) { |
145 | 11704 | jaume | FShape decimatedShape; |
146 | |||
147 | 8516 | jaume | try
|
148 | { |
||
149 | 11704 | jaume | decimatedShape = FConverter.transformToInts(this, vp.getAffineTransform());
|
150 | 8516 | jaume | symbol.draw(g, vp.getAffineTransform(), decimatedShape); |
151 | } |
||
152 | catch (Exception e) |
||
153 | { |
||
154 | e.printStackTrace(); |
||
155 | } |
||
156 | 7659 | fjp | // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), decimatedShape, symbol);
|
157 | 2859 | fjp | } |
158 | |||
159 | 5880 | fjp | /**
|
160 | * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
|
||
161 | * que se pasa como par?metro.
|
||
162 | *
|
||
163 | * @param at Matriz de transformaci?n.
|
||
164 | */
|
||
165 | public void transform(AffineTransform at) { |
||
166 | shp.transform(at); |
||
167 | } |
||
168 | 214 | fernando | |
169 | 5880 | fjp | /* (non-Javadoc)
|
170 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
||
171 | */
|
||
172 | public boolean intersects(Rectangle2D r) { |
||
173 | return shp.intersects(r);
|
||
174 | } |
||
175 | 214 | fernando | |
176 | 5880 | fjp | /* (non-Javadoc)
|
177 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
||
178 | */
|
||
179 | public Rectangle2D getBounds2D() { |
||
180 | if (bounds2D == null) |
||
181 | { |
||
182 | bounds2D = shp.getBounds2D(); |
||
183 | } |
||
184 | // return shp.getBounds2D();
|
||
185 | return bounds2D;
|
||
186 | } |
||
187 | 8516 | jaume | |
188 | 5880 | fjp | public Rectangle2D reCalculateBounds2D() |
189 | { |
||
190 | return shp.getBounds2D();
|
||
191 | } |
||
192 | 305 | fjp | |
193 | 5880 | fjp | /* (non-Javadoc)
|
194 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
|
||
195 | */
|
||
196 | public Geometry toJTSGeometry() {
|
||
197 | return FConverter.java2d_to_jts(shp);
|
||
198 | } |
||
199 | 305 | fjp | |
200 | 5880 | fjp | /* (non-Javadoc)
|
201 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
|
||
202 | */
|
||
203 | public FLabel[] createLabels(int position, boolean duplicates) { |
||
204 | FLabel[] aux = new FLabel[1]; |
||
205 | aux[0] = FLabel.createFLabel(shp);
|
||
206 | 1005 | vcaballero | |
207 | 5880 | fjp | return aux;
|
208 | } |
||
209 | 305 | fjp | |
210 | 5880 | fjp | /**
|
211 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
|
||
212 | */
|
||
213 | public int getGeometryType() { |
||
214 | return shp.getShapeType();
|
||
215 | } |
||
216 | 324 | fernando | |
217 | 5880 | fjp | /* (non-Javadoc)
|
218 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
||
219 | */
|
||
220 | public IGeometry cloneGeometry() {
|
||
221 | return new FGeometry(shp.cloneFShape()); |
||
222 | } |
||
223 | 627 | fjp | |
224 | 5880 | fjp | /* (non-Javadoc)
|
225 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
|
||
226 | */
|
||
227 | public void reProject(ICoordTrans ct) { |
||
228 | shp.reProject(ct); |
||
229 | } |
||
230 | 1132 | vcaballero | |
231 | 5880 | fjp | /**
|
232 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(AffineTransform)
|
||
233 | */
|
||
234 | public PathIterator getPathIterator(AffineTransform at) { |
||
235 | return (GeneralPathXIterator)shp.getPathIterator(null); |
||
236 | } |
||
237 | 1298 | fjp | |
238 | 4799 | fjp | |
239 | 8516 | jaume | |
240 | 1298 | fjp | /* (non-Javadoc)
|
241 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
|
||
242 | */
|
||
243 | public boolean fastIntersects(double x, double y, double w, double h) { |
||
244 | return shp.intersects(x,y,w,h);
|
||
245 | } |
||
246 | 3833 | caballero | |
247 | 2183 | fernando | public byte[] toWKB() throws IOException{ |
248 | return WKBEncoder.encodeGeometry(toJTSGeometry());
|
||
249 | } |
||
250 | 2196 | vcaballero | /**
|
251 | 5880 | fjp | * Devuelve un array con todos los valores de Z.
|
252 | *
|
||
253 | * @return Array de Zs.
|
||
254 | */
|
||
255 | public double[] getZs() { |
||
256 | return ((FShape3D) shp).getZs();
|
||
257 | } |
||
258 | /**
|
||
259 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
|
||
260 | */
|
||
261 | public Handler[] getHandlers(int type) { |
||
262 | if (type==STRETCHINGHANDLER){
|
||
263 | return shp.getStretchingHandlers();
|
||
264 | }else if (type==SELECTHANDLER){ |
||
265 | return shp.getSelectHandlers();
|
||
266 | } |
||
267 | return null; |
||
268 | } |
||
269 | 3885 | caballero | |
270 | 5880 | fjp | /* (non-Javadoc)
|
271 | * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator(java.awt.geom.AffineTransform, double)
|
||
272 | */
|
||
273 | public PathIterator getPathIterator(AffineTransform at, double flatness) { |
||
274 | return shp.getPathIterator(at, flatness);
|
||
275 | } |
||
276 | 4799 | fjp | |
277 | 5880 | fjp | public boolean contains(double x, double y) { |
278 | return shp.contains(x,y);
|
||
279 | } |
||
280 | 4879 | fjp | |
281 | 5880 | fjp | public boolean contains(double x, double y, double w, double h) { |
282 | return shp.contains(x,y,w,h);
|
||
283 | } |
||
284 | 4879 | fjp | |
285 | 5880 | fjp | public boolean intersects(double x, double y, double w, double h) { |
286 | return shp.intersects(x,y,w,h);
|
||
287 | } |
||
288 | 4879 | fjp | |
289 | 5880 | fjp | public Rectangle getBounds() { |
290 | return shp.getBounds();
|
||
291 | } |
||
292 | 4879 | fjp | |
293 | 5880 | fjp | public boolean contains(Point2D p) { |
294 | return shp.contains(p);
|
||
295 | } |
||
296 | 4879 | fjp | |
297 | 5880 | fjp | public boolean contains(Rectangle2D r) { |
298 | return shp.contains(r);
|
||
299 | } |
||
300 | 4879 | fjp | |
301 | 5880 | fjp | public Shape getInternalShape() { |
302 | return shp;
|
||
303 | } |
||
304 | 5008 | fjp | |
305 | 12657 | jaume | public void drawInts(Graphics2D graphics2D, ViewPort viewPort, double dpi, CartographicSupport cartographicSymbol) { |
306 | // make the symbol to resize itself with the current rendering context
|
||
307 | double previousSize = cartographicSymbol.
|
||
308 | toCartographicSize(viewPort, dpi, shp); |
||
309 | 12467 | jaume | |
310 | 12657 | jaume | // draw it as normally
|
311 | drawInts(graphics2D, viewPort, (ISymbol) cartographicSymbol); |
||
312 | |||
313 | // restore previous size
|
||
314 | cartographicSymbol.setCartographicSize(previousSize, null);
|
||
315 | 12467 | jaume | } |
316 | |||
317 | 5880 | fjp | /* public void move(double x, double y) {
|
318 | AffineTransform at = new AffineTransform();
|
||
319 | at.translate(x, y);
|
||
320 | transform(at);
|
||
321 | }
|
||
322 | public void rotate(double r, double x, double y) {
|
||
323 | AffineTransform at = new AffineTransform();
|
||
324 | at.rotate(r, x, y);
|
||
325 | transform(at);
|
||
326 | }
|
||
327 | public void scale(Point2D point,double x, double y) {
|
||
328 | AffineTransform at = new AffineTransform();
|
||
329 | at.setToTranslation(point.getX(),point.getY());
|
||
330 | at.scale(x,y);
|
||
331 | at.translate(-point.getX(),-point.getY());
|
||
332 | transform(at);
|
||
333 | } */
|
||
334 | 214 | fernando | } |