svn-gvsig-desktop / branches / FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / FGeometry.java @ 1821
History | View | Annotate | Download (8.25 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.FConstant; |
51 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
52 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
53 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
54 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
55 |
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
56 |
import com.iver.utiles.XMLEntity; |
57 |
|
58 |
import com.vividsolutions.jts.geom.Geometry; |
59 |
|
60 |
import org.cresques.cts.ICoordTrans; |
61 |
|
62 |
import java.awt.Color; |
63 |
import java.awt.Graphics2D; |
64 |
import java.awt.geom.AffineTransform; |
65 |
import java.awt.geom.Point2D; |
66 |
import java.awt.geom.Rectangle2D; |
67 |
|
68 |
/**
|
69 |
* Geometr?a.
|
70 |
*
|
71 |
* @author FJP
|
72 |
*/
|
73 |
public class FGeometry implements IGeometry { |
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 |
/**
|
136 |
* Aplica la transformaci?n a la geometr?a de la matriz de transformaci?n
|
137 |
* que se pasa como par?metro.
|
138 |
*
|
139 |
* @param at Matriz de transformaci?n.
|
140 |
*/
|
141 |
private void transform(AffineTransform at) { |
142 |
if (shp instanceof FPolyline2D) { |
143 |
((FPolyline2D) shp).transform(at); |
144 |
} |
145 |
|
146 |
if (shp instanceof FPoint2D) { |
147 |
((FPoint2D) shp).transform(at); |
148 |
} |
149 |
} |
150 |
|
151 |
/* (non-Javadoc)
|
152 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#intersects(java.awt.geom.Rectangle2D)
|
153 |
*/
|
154 |
public boolean intersects(Rectangle2D r) { |
155 |
return shp.intersects(r);
|
156 |
} |
157 |
|
158 |
/* (non-Javadoc)
|
159 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
|
160 |
*/
|
161 |
public Rectangle2D getBounds2D() { |
162 |
return shp.getBounds2D();
|
163 |
} |
164 |
|
165 |
/* (non-Javadoc)
|
166 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#toJTSGeometry()
|
167 |
*/
|
168 |
public Geometry toJTSGeometry() {
|
169 |
return FConverter.java2d_to_jts(shp);
|
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#createLabels(int, boolean)
|
174 |
*/
|
175 |
public FLabel[] createLabels(int position, boolean duplicates) { |
176 |
FLabel[] aux = new FLabel[1]; |
177 |
aux[0] = FLabel.createFLabel(shp);
|
178 |
|
179 |
return aux;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeometryType()
|
184 |
*/
|
185 |
public int getGeometryType() { |
186 |
return shp.getShapeType();
|
187 |
} |
188 |
|
189 |
/* (non-Javadoc)
|
190 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
|
191 |
*/
|
192 |
public IGeometry cloneGeometry() {
|
193 |
return new FGeometry(shp.cloneFShape()); |
194 |
} |
195 |
|
196 |
/* (non-Javadoc)
|
197 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#reProject(org.cresques.cts.ICoordTrans)
|
198 |
*/
|
199 |
public void reProject(ICoordTrans ct) { |
200 |
shp.reProject(ct); |
201 |
} |
202 |
|
203 |
/**
|
204 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getGeneralPathXIterator()
|
205 |
*/
|
206 |
public GeneralPathXIterator getGeneralPathXIterator() {
|
207 |
return (GeneralPathXIterator) shp.getPathIterator(null); |
208 |
} |
209 |
|
210 |
/* (non-Javadoc)
|
211 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#fastIntersects(double, double, double, double)
|
212 |
*/
|
213 |
public boolean fastIntersects(double x, double y, double w, double h) { |
214 |
return shp.intersects(x, y, w, h);
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#move(double, double)
|
219 |
*/
|
220 |
public void move(double x, double y) { |
221 |
AffineTransform at = new AffineTransform(); |
222 |
at.translate(x, y); |
223 |
transform(at); |
224 |
} |
225 |
|
226 |
/**
|
227 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#rotate(double, double,
|
228 |
* double)
|
229 |
*/
|
230 |
public void rotate(double r, double x, double y) { |
231 |
AffineTransform at = new AffineTransform(); |
232 |
at.rotate(r, x, y); |
233 |
transform(at); |
234 |
} |
235 |
|
236 |
/**
|
237 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getHandlers()
|
238 |
*/
|
239 |
public Handler[] getHandlers(int type) { |
240 |
if (type==STRETCHINGHANDLER){
|
241 |
return shp.getStretchingHandlers();
|
242 |
}else if (type==SELECTHANDLER){ |
243 |
return shp.getSelectHandlers();
|
244 |
} |
245 |
return null; |
246 |
} |
247 |
|
248 |
|
249 |
/**
|
250 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#scale(double, double)
|
251 |
*/
|
252 |
public void scale(Point2D point,double x, double y) { |
253 |
AffineTransform at = new AffineTransform(); |
254 |
at.setToTranslation(point.getX(),point.getY()); |
255 |
at.scale(x,y); |
256 |
at.translate(-point.getX(),-point.getY()); |
257 |
transform(at); |
258 |
} |
259 |
|
260 |
/**
|
261 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#getShapes()
|
262 |
*/
|
263 |
public FShape[] getShapes() { |
264 |
return new FShape[]{shp}; |
265 |
} |
266 |
|
267 |
/**
|
268 |
* @see com.iver.cit.gvsig.fmap.core.IGeometry#draw(java.awt.Graphics2D, java.awt.geom.AffineTransform, com.iver.cit.gvsig.fmap.core.v02.FSymbol)
|
269 |
*/
|
270 |
public void draw(Graphics2D g, AffineTransform at, FSymbol symbol) { |
271 |
// OJO CON LA PRECISION. DEBERIAMOS USAR: ((GeneralPathX) shp.m_Polyline).transform(mT);
|
272 |
// O HACER UNA FUNCION DE TRANSFORMACI?N QUE USE LOS DOUBLES DEL
|
273 |
// SHAPE
|
274 |
// Shape shpTrans = vp.getAffineTransform().createTransformedShape(shp);
|
275 |
transform(at); |
276 |
FGraphicUtilities.DrawShape(g, at, shp, symbol); |
277 |
} |
278 |
|
279 |
public static IGeometry createFromXML(XMLEntity xml){ |
280 |
FShape shp = null;
|
281 |
|
282 |
try {
|
283 |
Class clase = Class.forName(xml.getStringProperty("className")); |
284 |
shp = (FShape) clase.newInstance(); |
285 |
} catch (Exception e) { |
286 |
//TODO
|
287 |
} |
288 |
shp.setXMLEntity(xml); |
289 |
IGeometry geometry=new FGeometry(shp);
|
290 |
return geometry;
|
291 |
} |
292 |
public XMLEntity getXMLEntity(){
|
293 |
XMLEntity xml=new XMLEntity();
|
294 |
xml.putProperty("className",shp.getClass().getName());
|
295 |
xml.addChild(shp.getXMLEntity()); |
296 |
return xml;
|
297 |
} |
298 |
public boolean equals(Object o){ |
299 |
IGeometry g=(IGeometry)o; |
300 |
FShape[] s=g.getShapes();
|
301 |
FShape[] shapes=getShapes();
|
302 |
for (int i=0;i<s.length;i++){ |
303 |
if (!s[i].getPathIterator(null).equals(shapes[i].getPathIterator(null))){ |
304 |
return false; |
305 |
} |
306 |
} |
307 |
return true; |
308 |
} |
309 |
} |