Statistics
| Revision:

root / branches / FMap_CAD / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 3513

History | View | Annotate | Download (7.79 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 com.iver.cit.gvsig.fmap.ViewPort;
50
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
51
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
52
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
53
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
54
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
55

    
56
import com.vividsolutions.jts.geom.Geometry;
57

    
58
import org.cresques.cts.ICoordTrans;
59
import org.geotools.data.postgis.attributeio.WKBEncoder;
60

    
61
import java.awt.Graphics2D;
62
import java.awt.geom.AffineTransform;
63
import java.awt.geom.Point2D;
64
import java.awt.geom.Rectangle2D;
65
import java.io.IOException;
66
import java.io.Serializable;
67

    
68
/**
69
 * Geometr?a.
70
 *
71
 * @author FJP
72
 */
73
public class FGeometry implements IGeometry3D {
74
        public static int SELECTHANDLER=0;
75
        public static int STRETCHINGHANDLER=1;
76
        private FShape shp;
77

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

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

    
97
                switch (shp.getShapeType()) {
98
                        case FShape.POINT:
99
                                shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
100

    
101
                                break;
102

    
103
                        case FShape.LINE:
104
                                shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
105

    
106
                                break;
107

    
108
                        case FShape.POLYGON:
109
                                shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
110

    
111
                                break;
112

    
113
                        case FShape.TEXT:
114
                                shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
115
                }
116
        }
117

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

    
135
    /* (non-Javadoc)
136
     * @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)
137
     */
138
    public void drawInts(Graphics2D g, ViewPort vp, FSymbol symbol) {
139
        FShape decimatedShape = FConverter.transformToInts(this, vp.getAffineTransform());
140
        FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), decimatedShape, symbol);
141
    }
142

    
143
        /**
144
         * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
145
         * que se pasa como par?metro.
146
         *
147
         * @param at Matriz de transformaci?n.
148
         */
149
        private void transform(AffineTransform at) {
150
                if (shp instanceof FPolyline2D) {
151
                        ((FPolyline2D) shp).transform(at);
152
                }
153

    
154
                if (shp instanceof FPoint2D) {
155
                        ((FPoint2D) shp).transform(at);
156
                }
157
        }
158

    
159
        /* (non-Javadoc)
160
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
161
         */
162
        public boolean intersectsBounds(Rectangle2D r) {
163
                return shp.intersects(r);
164
        }
165

    
166
        /* (non-Javadoc)
167
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
168
         */
169
        public Rectangle2D getBounds2D() {
170
                return shp.getBounds2D();
171
        }
172

    
173
        /* (non-Javadoc)
174
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
175
         */
176
        public Geometry toJTSGeometry() {
177
                return FConverter.java2d_to_jts(shp);
178
        }
179

    
180
        /* (non-Javadoc)
181
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
182
         */
183
        public FLabel[] createLabels(int position, boolean duplicates) {
184
                FLabel[] aux = new FLabel[1];
185
                aux[0] = FLabel.createFLabel(shp);
186

    
187
                return aux;
188
        }
189

    
190
        /**
191
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
192
         */
193
        public int getGeometryType() {
194
                return shp.getShapeType();
195
        }
196

    
197
        /* (non-Javadoc)
198
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
199
         */
200
        public IGeometry cloneGeometry() {
201
                return new FGeometry(shp.cloneFShape());
202
        }
203

    
204
        /* (non-Javadoc)
205
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
206
         */
207
        public void reProject(ICoordTrans ct) {
208
                shp.reProject(ct);
209
        }
210

    
211
        /**
212
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
213
         */
214
        public GeneralPathXIterator getGeneralPathXIterator() {
215
                return (GeneralPathXIterator)shp.getPathIterator(null);
216
        }
217

    
218
    /* (non-Javadoc)
219
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
220
     */
221
    public boolean fastIntersects(double x, double y, double w, double h) {
222
        return shp.intersects(x,y,w,h);
223
    }
224
    
225
    public byte[] toWKB() throws IOException{
226
        return WKBEncoder.encodeGeometry(toJTSGeometry());
227
    }
228
    /**
229
         * Devuelve un array con todos los valores de Z.
230
         *
231
         * @return Array de Zs.
232
         */
233
        public double[] getZs() {
234
                return ((FShape3D) shp).getZs();
235
        }
236
        /**
237
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#move(double, double)
238
         */
239
        public void move(double x, double y) {
240
                AffineTransform at = new AffineTransform();
241
                at.translate(x, y);
242
                transform(at);
243
        }
244

    
245
        /**
246
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#rotate(double, double,
247
         *                 double)
248
         */
249
        public void rotate(double r, double x, double y) {
250
                AffineTransform at = new AffineTransform();
251
                at.rotate(r, x, y);
252
                transform(at);
253
        }
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

    
267
        
268
        /**
269
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#scale(double, double)
270
         */
271
        public void scale(Point2D point,double x, double y) {
272
                AffineTransform at = new AffineTransform();
273
                at.setToTranslation(point.getX(),point.getY());
274
                at.scale(x,y);
275
                at.translate(-point.getX(),-point.getY());
276
                transform(at);
277
        }
278

    
279
        /**
280
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getShapes()
281
         */
282
        public FShape[] getShapes() {
283
                return new FShape[]{shp};
284
        }
285

    
286
        public boolean intersects(Rectangle2D r, double flatness) {
287
                return shp.intersects(r, flatness);
288
        }
289
}