Statistics
| Revision:

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

History | View | Annotate | Download (6.44 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.Rectangle2D;
64
import java.io.IOException;
65
import java.io.Serializable;
66

    
67

    
68
/**
69
 * Geometr?a.
70
 *
71
 * @author FJP
72
 */
73
public class FGeometry implements IGeometry3D {
74
        private FShape shp;
75

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

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

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

    
99
                                break;
100

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

    
104
                                break;
105

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

    
109
                                break;
110

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

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

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

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

    
152
                if (shp instanceof FPoint2D) {
153
                        ((FPoint2D) shp).transform(at);
154
                }
155
        }
156

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

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

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

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

    
185
                return aux;
186
        }
187

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

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

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

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

    
216
    /* (non-Javadoc)
217
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
218
     */
219
    public boolean fastIntersects(double x, double y, double w, double h) {
220
        return shp.intersects(x,y,w,h);
221
    }
222
    
223
    public byte[] toWKB() throws IOException{
224
        return WKBEncoder.encodeGeometry(toJTSGeometry());
225
    }
226
    /**
227
         * Devuelve un array con todos los valores de Z.
228
         *
229
         * @return Array de Zs.
230
         */
231
        public double[] getZs() {
232
                return ((FShape3D) shp).getZs();
233
        }
234
}