root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 4115
History | View | Annotate | Download (7.15 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.geom.AffineTransform; |
51 |
import java.awt.geom.Point2D; |
52 |
import java.awt.geom.Rectangle2D; |
53 |
import java.io.IOException; |
54 |
|
55 |
import org.cresques.cts.ICoordTrans; |
56 |
import org.geotools.data.postgis.attributeio.WKBEncoder; |
57 |
|
58 |
import com.iver.cit.gvsig.fmap.ViewPort; |
59 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
60 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
61 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
62 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
63 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
64 |
import com.vividsolutions.jts.geom.Geometry; |
65 |
|
66 |
|
67 |
/**
|
68 |
* Geometr?a.
|
69 |
*
|
70 |
* @author FJP
|
71 |
*/
|
72 |
public class FGeometry implements IGeometry3D { |
73 |
/**
|
74 |
*
|
75 |
*/
|
76 |
private static final long serialVersionUID = 5431865770186523337L; |
77 |
private FShape shp;
|
78 |
|
79 |
/**
|
80 |
* Crea un nuevo FGeometry.
|
81 |
*
|
82 |
* @param shp DOCUMENT ME!
|
83 |
*/
|
84 |
FGeometry(FShape shp) { |
85 |
this.shp = shp;
|
86 |
} |
87 |
|
88 |
/* (non-Javadoc)
|
89 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, org.geotools.renderer.style.Style2D)
|
90 |
*/
|
91 |
public void draw(Graphics2D g, ViewPort vp, FStyle2D symbol) { |
92 |
// OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
|
93 |
// O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
|
94 |
// SHAPE
|
95 |
// Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
|
96 |
transform(vp.getAffineTransform()); |
97 |
|
98 |
switch (shp.getShapeType()) {
|
99 |
case FShape.POINT:
|
100 |
shpPainter.paint(g, shp, symbol.getPointStyle2D(), 0);
|
101 |
|
102 |
break;
|
103 |
|
104 |
case FShape.LINE:
|
105 |
shpPainter.paint(g, shp, symbol.getLineStyle2D(), 0);
|
106 |
|
107 |
break;
|
108 |
|
109 |
case FShape.POLYGON:
|
110 |
shpPainter.paint(g, shp, symbol.getPolygonStyle2D(), 0);
|
111 |
|
112 |
break;
|
113 |
|
114 |
case FShape.TEXT:
|
115 |
shpPainter.paint(g, shp, symbol.getTextStyle2D(), 0);
|
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Dibuja la geometria actual en el graphics que se le pasa como par?metro,
|
121 |
* aplicandole las caracter?sticas del s?mbolo.
|
122 |
*
|
123 |
* @param g Graphics2D.
|
124 |
* @param vp ViewPort.
|
125 |
* @param symbol S?mbolo.
|
126 |
*/
|
127 |
public void draw(Graphics2D g, ViewPort vp, FSymbol symbol) { |
128 |
// OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
|
129 |
// O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
|
130 |
// SHAPE
|
131 |
// Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
|
132 |
transform(vp.getAffineTransform()); |
133 |
FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), shp, symbol); |
134 |
} |
135 |
|
136 |
/* (non-Javadoc)
|
137 |
* @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)
|
138 |
*/
|
139 |
public void drawInts(Graphics2D g, ViewPort vp, FSymbol symbol) { |
140 |
FShape decimatedShape = FConverter.transformToInts(this, vp.getAffineTransform());
|
141 |
FGraphicUtilities.DrawShape(g, vp.getAffineTransform(), decimatedShape, symbol); |
142 |
} |
143 |
|
144 |
/**
|
145 |
* Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
|
146 |
* que se pasa como par?metro.
|
147 |
*
|
148 |
* @param at Matriz de transformaci?n.
|
149 |
*/
|
150 |
public void transform(AffineTransform at) { |
151 |
shp.transform(at); |
152 |
} |
153 |
|
154 |
/* (non-Javadoc)
|
155 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
156 |
*/
|
157 |
public boolean intersects(Rectangle2D r) { |
158 |
return shp.intersects(r);
|
159 |
} |
160 |
|
161 |
/* (non-Javadoc)
|
162 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
163 |
*/
|
164 |
public Rectangle2D getBounds2D() { |
165 |
return shp.getBounds2D();
|
166 |
} |
167 |
|
168 |
/* (non-Javadoc)
|
169 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
|
170 |
*/
|
171 |
public Geometry toJTSGeometry() {
|
172 |
return FConverter.java2d_to_jts(shp);
|
173 |
} |
174 |
|
175 |
/* (non-Javadoc)
|
176 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
|
177 |
*/
|
178 |
public FLabel[] createLabels(int position, boolean duplicates) { |
179 |
FLabel[] aux = new FLabel[1]; |
180 |
aux[0] = FLabel.createFLabel(shp);
|
181 |
|
182 |
return aux;
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
|
187 |
*/
|
188 |
public int getGeometryType() { |
189 |
return shp.getShapeType();
|
190 |
} |
191 |
|
192 |
/* (non-Javadoc)
|
193 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
194 |
*/
|
195 |
public IGeometry cloneGeometry() {
|
196 |
return new FGeometry(shp.cloneFShape()); |
197 |
} |
198 |
|
199 |
/* (non-Javadoc)
|
200 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
|
201 |
*/
|
202 |
public void reProject(ICoordTrans ct) { |
203 |
shp.reProject(ct); |
204 |
} |
205 |
|
206 |
/**
|
207 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
|
208 |
*/
|
209 |
public GeneralPathXIterator getGeneralPathXIterator() {
|
210 |
return (GeneralPathXIterator)shp.getPathIterator(null); |
211 |
} |
212 |
|
213 |
/* (non-Javadoc)
|
214 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
|
215 |
*/
|
216 |
public boolean fastIntersects(double x, double y, double w, double h) { |
217 |
return shp.intersects(x,y,w,h);
|
218 |
} |
219 |
|
220 |
public byte[] toWKB() throws IOException{ |
221 |
return WKBEncoder.encodeGeometry(toJTSGeometry());
|
222 |
} |
223 |
/**
|
224 |
* Devuelve un array con todos los valores de Z.
|
225 |
*
|
226 |
* @return Array de Zs.
|
227 |
*/
|
228 |
public double[] getZs() { |
229 |
return ((FShape3D) shp).getZs();
|
230 |
} |
231 |
/**
|
232 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
|
233 |
*/
|
234 |
public Handler[] getHandlers(int type) { |
235 |
if (type==STRETCHINGHANDLER){
|
236 |
return shp.getStretchingHandlers();
|
237 |
}else if (type==SELECTHANDLER){ |
238 |
return shp.getSelectHandlers();
|
239 |
} |
240 |
return null; |
241 |
} |
242 |
|
243 |
/* public void move(double x, double y) {
|
244 |
AffineTransform at = new AffineTransform();
|
245 |
at.translate(x, y);
|
246 |
transform(at);
|
247 |
}
|
248 |
public void rotate(double r, double x, double y) {
|
249 |
AffineTransform at = new AffineTransform();
|
250 |
at.rotate(r, x, y);
|
251 |
transform(at);
|
252 |
}
|
253 |
public void scale(Point2D point,double x, double y) {
|
254 |
AffineTransform at = new AffineTransform();
|
255 |
at.setToTranslation(point.getX(),point.getY());
|
256 |
at.scale(x,y);
|
257 |
at.translate(-point.getX(),-point.getY());
|
258 |
transform(at);
|
259 |
} */
|
260 |
} |