Statistics
| Revision:

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

History | View | Annotate | Download (5.85 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 IGeometry {
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
        /**
134
         * Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
135
         * que se pasa como par?metro.
136
         *
137
         * @param at Matriz de transformaci?n.
138
         */
139
        private void transform(AffineTransform at) {
140
                if (shp instanceof FPolyline2D) {
141
                        ((FPolyline2D) shp).transform(at);
142
                }
143

    
144
                if (shp instanceof FPoint2D) {
145
                        ((FPoint2D) shp).transform(at);
146
                }
147
        }
148

    
149
        /* (non-Javadoc)
150
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
151
         */
152
        public boolean intersects(Rectangle2D r) {
153
                return shp.intersects(r);
154
        }
155

    
156
        /* (non-Javadoc)
157
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
158
         */
159
        public Rectangle2D getBounds2D() {
160
                return shp.getBounds2D();
161
        }
162

    
163
        /* (non-Javadoc)
164
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
165
         */
166
        public Geometry toJTSGeometry() {
167
                return FConverter.java2d_to_jts(shp);
168
        }
169

    
170
        /* (non-Javadoc)
171
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
172
         */
173
        public FLabel[] createLabels(int position, boolean duplicates) {
174
                FLabel[] aux = new FLabel[1];
175
                aux[0] = FLabel.createFLabel(shp);
176

    
177
                return aux;
178
        }
179

    
180
        /**
181
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
182
         */
183
        public int getGeometryType() {
184
                return shp.getShapeType();
185
        }
186

    
187
        /* (non-Javadoc)
188
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
189
         */
190
        public IGeometry cloneGeometry() {
191
                return new FGeometry(shp.cloneFShape());
192
        }
193

    
194
        /* (non-Javadoc)
195
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
196
         */
197
        public void reProject(ICoordTrans ct) {
198
                shp.reProject(ct);
199
        }
200

    
201
        /**
202
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
203
         */
204
        public GeneralPathXIterator getGeneralPathXIterator() {
205
                return (GeneralPathXIterator)shp.getPathIterator(null);
206
        }
207

    
208
    /* (non-Javadoc)
209
     * @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
210
     */
211
    public boolean fastIntersects(double x, double y, double w, double h) {
212
        return shp.intersects(x,y,w,h);
213
    }
214
    
215
    public byte[] toWKB() throws IOException{
216
        return WKBEncoder.encodeGeometry(toJTSGeometry());
217
    }
218
}