Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_907 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 11015

History | View | Annotate | Download (8.31 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.v02.FConverter;
63
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
64
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
65
import com.vividsolutions.jts.geom.Geometry;
66

    
67

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

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

    
90
        /* (non-Javadoc)
91
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, org.geotools.renderer.style.Style2D)
92
         */
93
        public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
94
                // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
95
                // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
96
                // SHAPE
97
                // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
98
                transform(vp.getAffineTransform());
99

    
100
                switch (shp.getShapeType()) {
101
                        case FShape.POINT:
102
                                shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
103

    
104
                                break;
105

    
106
                        case FShape.LINE:
107
                                shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
108

    
109
                                break;
110

    
111
                        case FShape.POLYGON:
112
                                shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
113

    
114
                                break;
115

    
116
                        case FShape.TEXT:
117
                                shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
118
                }
119
        }
120

    
121
        /**
122
         * Dibuja la geometria actual en el graphics que se le pasa como par?metro,
123
         * aplicandole las caracter?sticas del s?mbolo.
124
         *
125
         * @param g Graphics2D.
126
         * @param vp ViewPort.
127
         * @param symbol S?mbolo.
128
         */
129
        public void draw(Graphics2D g, ViewPort vp, ISymbol symbol) {
130
                // OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
131
                // O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
132
                // SHAPE
133
                // Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
134
                transform(vp.getAffineTransform());
135
                symbol.draw(g, vp.getAffineTransform(), shp);
136
                // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
137
        }
138

    
139
    /* (non-Javadoc)
140
     * @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)
141
     */
142
    public void drawInts(Graphics2D g, ViewPort vp, ISymbol symbol) {
143
            try
144
            {
145
                    FShape decimatedShape = FConverter.transformToInts(this, vp.getAffineTransform());
146
                    symbol.draw(g, vp.getAffineTransform(), decimatedShape);
147
            }
148
            catch (Exception e)
149
            {
150
                    e.printStackTrace();
151
            }
152
        // FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), decimatedShape, symbol);
153
    }
154

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

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

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

    
184
        public Rectangle2D reCalculateBounds2D()
185
        {
186
                return shp.getBounds2D();
187
        }
188

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

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

    
203
                return aux;
204
        }
205

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

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

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

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

    
234

    
235

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

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

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

    
273
        public boolean contains(double x, double y) {
274
                return shp.contains(x,y);
275
        }
276

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

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

    
285
        public Rectangle getBounds() {
286
                return shp.getBounds();
287
        }
288

    
289
        public boolean contains(Point2D p) {
290
                return shp.contains(p);
291
        }
292

    
293
        public boolean contains(Rectangle2D r) {
294
                return shp.contains(r);
295
        }
296

    
297
        public Shape getInternalShape() {
298
                return shp;
299
        }
300

    
301
        /* public void move(double x, double y) {
302
                AffineTransform at = new AffineTransform();
303
                at.translate(x, y);
304
                transform(at);
305
        }
306
        public void rotate(double r, double x, double y) {
307
                AffineTransform at = new AffineTransform();
308
                at.rotate(r, x, y);
309
                transform(at);
310
        }
311
        public void scale(Point2D point,double x, double y) {
312
                AffineTransform at = new AffineTransform();
313
                at.setToTranslation(point.getX(),point.getY());
314
                at.scale(x,y);
315
                at.translate(-point.getX(),-point.getY());
316
                transform(at);
317
        } */
318
}