Statistics
| Revision:

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

History | View | Annotate | Download (6.44 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 237 fjp
import com.iver.cit.gvsig.fmap.ViewPort;
50 703 fjp
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
51 458 fjp
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
52 757 fjp
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
53 458 fjp
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
54 324 fernando
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
55 1005 vcaballero
56 703 fjp
import com.vividsolutions.jts.geom.Geometry;
57 214 fernando
58 1005 vcaballero
import org.cresques.cts.ICoordTrans;
59 2183 fernando
import org.geotools.data.postgis.attributeio.WKBEncoder;
60 1005 vcaballero
61
import java.awt.Graphics2D;
62
import java.awt.geom.AffineTransform;
63
import java.awt.geom.Rectangle2D;
64 2183 fernando
import java.io.IOException;
65
import java.io.Serializable;
66 1005 vcaballero
67
68 214 fernando
/**
69 1005 vcaballero
 * Geometr?a.
70
 *
71 305 fjp
 * @author FJP
72 214 fernando
 */
73 2196 vcaballero
public class FGeometry implements IGeometry3D {
74 324 fernando
        private FShape shp;
75 214 fernando
76 1005 vcaballero
        /**
77
         * Crea un nuevo FGeometry.
78
         *
79
         * @param shp DOCUMENT ME!
80
         */
81
        FGeometry(FShape shp) {
82
                this.shp = shp;
83
        }
84
85 305 fjp
        /* (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 214 fernando
         */
88 324 fernando
        public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) {
89 305 fjp
                // 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 1005 vcaballero
95
                switch (shp.getShapeType()) {
96 324 fernando
                        case FShape.POINT:
97
                                shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
98 1005 vcaballero
99 324 fernando
                                break;
100 1005 vcaballero
101 324 fernando
                        case FShape.LINE:
102
                                shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
103 1005 vcaballero
104 324 fernando
                                break;
105 1005 vcaballero
106 324 fernando
                        case FShape.POLYGON:
107
                                shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
108 1005 vcaballero
109 324 fernando
                                break;
110 1005 vcaballero
111 324 fernando
                        case FShape.TEXT:
112
                                shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
113
                }
114 305 fjp
        }
115 458 fjp
116 1005 vcaballero
        /**
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 458 fjp
        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 1005 vcaballero
                FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol);
131 458 fjp
        }
132
133 2859 fjp
    /* (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 1005 vcaballero
        /**
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 305 fjp
        }
156 214 fernando
157 305 fjp
        /* (non-Javadoc)
158
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
159 214 fernando
         */
160 305 fjp
        public boolean intersects(Rectangle2D r) {
161
                return shp.intersects(r);
162
        }
163 214 fernando
164 305 fjp
        /* (non-Javadoc)
165
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
166 214 fernando
         */
167 305 fjp
        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 703 fjp
                return FConverter.java2d_to_jts(shp);
176 305 fjp
        }
177
178
        /* (non-Javadoc)
179
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
180
         */
181 757 fjp
        public FLabel[] createLabels(int position, boolean duplicates) {
182
                FLabel[] aux = new FLabel[1];
183 1005 vcaballero
                aux[0] = FLabel.createFLabel(shp);
184
185
                return aux;
186 305 fjp
        }
187
188 324 fernando
        /**
189
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
190
         */
191
        public int getGeometryType() {
192
                return shp.getShapeType();
193
        }
194
195 703 fjp
        /* (non-Javadoc)
196
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
197
         */
198
        public IGeometry cloneGeometry() {
199
                return new FGeometry(shp.cloneFShape());
200 627 fjp
        }
201
202 885 fjp
        /* (non-Javadoc)
203
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
204
         */
205
        public void reProject(ICoordTrans ct) {
206 1005 vcaballero
                shp.reProject(ct);
207 885 fjp
        }
208 1132 vcaballero
209
        /**
210
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
211
         */
212
        public GeneralPathXIterator getGeneralPathXIterator() {
213
                return (GeneralPathXIterator)shp.getPathIterator(null);
214
        }
215 1298 fjp
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 2183 fernando
223
    public byte[] toWKB() throws IOException{
224
        return WKBEncoder.encodeGeometry(toJTSGeometry());
225
    }
226 2196 vcaballero
    /**
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 214 fernando
}