Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 18621

History | View | Annotate | Download (8.99 KB)

1
/*
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
/* 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
package com.iver.cit.gvsig.fmap.core;
48

    
49
import java.awt.Graphics2D;
50
import java.awt.Rectangle;
51
import java.awt.Shape;
52
import java.awt.geom.AffineTransform;
53
import java.awt.geom.PathIterator;
54
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
import com.iver.cit.gvsig.fmap.ViewPort;
62
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
63
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
64
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
65
import com.iver.utiles.swing.threads.Cancellable;
66
import com.vividsolutions.jts.geom.Geometry;
67

    
68

    
69
/**
70
 * Geometr?a.
71
 *
72
 * @author FJP
73
 */
74
public class FGeometry extends AbstractGeometry implements IGeometry3D {
75
        /**
76
         *
77
         */
78
        private static final long serialVersionUID = 5431865770186523337L;
79
        private FShape shp;
80
        private Rectangle2D bounds2D;
81

    
82
        /**
83
         * Crea un nuevo FGeometry.
84
         *
85
         * @param shp DOCUMENT ME!
86
         */
87
        FGeometry(FShape shp) {
88
                this.shp = shp;
89
        }
90

    
91
        /* (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, ISymbol 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
//
101
//                switch (shp.getShapeType()) {
102
//                        case FShape.POINT:
103
//                                shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
104
//
105
//                                break;
106
//
107
//                        case FShape.LINE:
108
//                                shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
109
//
110
//                                break;
111
//
112
//                        case FShape.POLYGON:
113
//                                shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
114
//
115
//                                break;
116
//
117
//                        case FShape.TEXT:
118
//                                shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
119
//                }
120
//        }
121

    
122
        /**
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
        public void draw(Graphics2D g, ViewPort vp, ISymbol symbol, Cancellable cancel) {
131
                // 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
                symbol.draw(g, vp.getAffineTransform(), shp, cancel);
137
                // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
138
        }
139

    
140
    /* (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
    public void drawInts(Graphics2D g, ViewPort vp, ISymbol symbol, Cancellable cancel) {
144
            FShape decimatedShape;
145

    
146
            try
147
            {
148
                    decimatedShape = FConverter.transformToInts(this, vp.getAffineTransform());
149
                    symbol.draw(g, vp.getAffineTransform(), decimatedShape, cancel);
150
            }
151
            catch (Exception e)
152
            {
153
                    e.printStackTrace();
154
            }
155
        // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), decimatedShape, symbol);
156
    }
157

    
158
        /**
159
         * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
160
         * que se pasa como par?metro.
161
         *
162
         * @param at Matriz de transformaci?n.
163
         */
164
        public void transform(AffineTransform at) {
165
                shp.transform(at);
166
        }
167

    
168
        /* (non-Javadoc)
169
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
170
         */
171
        public boolean intersects(Rectangle2D r) {
172
                return shp.intersects(r);
173
        }
174

    
175
        /* (non-Javadoc)
176
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
177
         */
178
        public Rectangle2D getBounds2D() {
179
                if (bounds2D == null)
180
                {
181
                        bounds2D = shp.getBounds2D();
182
                }
183
                // return shp.getBounds2D();
184
                return bounds2D;
185
        }
186

    
187
        public Rectangle2D reCalculateBounds2D()
188
        {
189
                return shp.getBounds2D();
190
        }
191

    
192
        /* (non-Javadoc)
193
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
194
         */
195
        public Geometry toJTSGeometry() {
196
                return FConverter.java2d_to_jts(shp);
197
        }
198

    
199
        /* (non-Javadoc)
200
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
201
         */
202
        public FLabel[] createLabels(int position, boolean duplicates) {
203
                FLabel[] aux = new FLabel[1];
204
                aux[0] = FLabel.createFLabel(shp);
205

    
206
                return aux;
207
        }
208

    
209
        /**
210
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
211
         */
212
        public int getGeometryType() {
213
                return shp.getShapeType();
214
        }
215

    
216
        /* (non-Javadoc)
217
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
218
         */
219
        public IGeometry cloneGeometry() {
220
                return new FGeometry(shp.cloneFShape());
221
        }
222

    
223
        /* (non-Javadoc)
224
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
225
         */
226
        public void reProject(ICoordTrans ct) {
227
                shp.reProject(ct);
228
        }
229

    
230
        /**
231
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getPathIterator(AffineTransform)
232
         */
233
        public PathIterator getPathIterator(AffineTransform at) {
234
                return (GeneralPathXIterator)shp.getPathIterator(null);
235
        }
236

    
237

    
238

    
239
    /* (non-Javadoc)
240
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
241
     */
242
    public boolean fastIntersects(double x, double y, double w, double h) {
243
        return shp.intersects(x,y,w,h);
244
    }
245

    
246
    public byte[] toWKB() throws IOException{
247
        return WKBEncoder.encodeGeometry(toJTSGeometry());
248
    }
249
    /**
250
         * Devuelve un array con todos los valores de Z.
251
         *
252
         * @return Array de Zs.
253
         */
254
        public double[] getZs() {
255
                return ((FShape3D) shp).getZs();
256
        }
257
        /**
258
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
259
         */
260
        public Handler[] getHandlers(int type) {
261
                if (type==STRETCHINGHANDLER){
262
                return shp.getStretchingHandlers();
263
                }else if (type==SELECTHANDLER){
264
                        return shp.getSelectHandlers();
265
                }
266
                return null;
267
        }
268

    
269
        /* (non-Javadoc)
270
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator(java.awt.geom.AffineTransform, double)
271
         */
272
        public PathIterator getPathIterator(AffineTransform at, double flatness) {
273
                return shp.getPathIterator(at, flatness);
274
        }
275

    
276
        public boolean contains(double x, double y) {
277
                return shp.contains(x,y);
278
        }
279

    
280
        public boolean contains(double x, double y, double w, double h) {
281
                return shp.contains(x,y,w,h);
282
        }
283

    
284
        public boolean intersects(double x, double y, double w, double h) {
285
                return shp.intersects(x,y,w,h);
286
        }
287

    
288
        public Rectangle getBounds() {
289
                return shp.getBounds();
290
        }
291

    
292
        public boolean contains(Point2D p) {
293
                return shp.contains(p);
294
        }
295

    
296
        public boolean contains(Rectangle2D r) {
297
                return shp.contains(r);
298
        }
299

    
300
        public Shape getInternalShape() {
301
                return shp;
302
        }
303

    
304
        public void drawInts(Graphics2D graphics2D, ViewPort viewPort, double dpi,
305
                        CartographicSupport cartographicSymbol, Cancellable cancel) {
306
                // make the symbol to resize itself with the current rendering context
307
                double previousSize = cartographicSymbol.
308
                toCartographicSize(viewPort, dpi,  shp);
309

    
310
                // draw it as normally
311
                drawInts(graphics2D, viewPort, (ISymbol) cartographicSymbol, cancel);
312

    
313
                // restore previous size
314
                cartographicSymbol.setCartographicSize(previousSize, shp);
315
        }
316

    
317
        /* 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
}