svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / AbstractPrimitive.java @ 20964
History | View | Annotate | Download (5.42 KB)
1 |
package org.gvsig.fmap.geom.primitive; |
---|---|
2 |
|
3 |
import java.awt.Shape; |
4 |
import java.awt.geom.AffineTransform; |
5 |
import java.awt.geom.Point2D; |
6 |
import java.io.Serializable; |
7 |
|
8 |
import org.cresques.cts.ICoordTrans; |
9 |
import org.cresques.cts.IProjection; |
10 |
import org.gvsig.fmap.geom.Geometry; |
11 |
import org.gvsig.fmap.geom.GeometryManager; |
12 |
import org.gvsig.fmap.geom.handler.Handler; |
13 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
14 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
15 |
import org.gvsig.fmap.geom.type.GeometryType; |
16 |
|
17 |
|
18 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
19 |
*
|
20 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
21 |
*
|
22 |
* This program is free software; you can redistribute it and/or
|
23 |
* modify it under the terms of the GNU General Public License
|
24 |
* as published by the Free Software Foundation; either version 2
|
25 |
* of the License, or (at your option) any later version.
|
26 |
*
|
27 |
* This program is distributed in the hope that it will be useful,
|
28 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
* GNU General Public License for more details.
|
31 |
*
|
32 |
* You should have received a copy of the GNU General Public License
|
33 |
* along with this program; if not, write to the Free Software
|
34 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
35 |
*
|
36 |
* For more information, contact:
|
37 |
*
|
38 |
* Generalitat Valenciana
|
39 |
* Conselleria d'Infraestructures i Transport
|
40 |
* Av. Blasco Ib��ez, 50
|
41 |
* 46010 VALENCIA
|
42 |
* SPAIN
|
43 |
*
|
44 |
* +34 963862235
|
45 |
* gvsig@gva.es
|
46 |
* www.gvsig.gva.es
|
47 |
*
|
48 |
* or
|
49 |
*
|
50 |
* IVER T.I. S.A
|
51 |
* Salamanca 50
|
52 |
* 46005 Valencia
|
53 |
* Spain
|
54 |
*
|
55 |
* +34 963163400
|
56 |
* dac@iver.es
|
57 |
*/
|
58 |
/* CVS MESSAGES:
|
59 |
*
|
60 |
* $Id: AbstractGeometry.java,v 1.2 2008/03/25 08:47:41 cvs Exp $
|
61 |
* $Log: AbstractGeometry.java,v $
|
62 |
* Revision 1.2 2008/03/25 08:47:41 cvs
|
63 |
* Visitors removed
|
64 |
*
|
65 |
* Revision 1.1 2008/03/12 08:46:20 cvs
|
66 |
* *** empty log message ***
|
67 |
*
|
68 |
*
|
69 |
*/
|
70 |
/**
|
71 |
* @author Jorge Piera Llodr� (jorge.piera@iver.es)
|
72 |
*/
|
73 |
public abstract class AbstractPrimitive implements Geometry, FShape, Serializable { |
74 |
private static final long serialVersionUID = 1L; |
75 |
protected String id = null; |
76 |
protected IProjection projection = null; |
77 |
// protected GeometryOperationsSet operationsSet = null;
|
78 |
|
79 |
public AbstractPrimitive(String id, IProjection projection) { |
80 |
super();
|
81 |
this.id = id;
|
82 |
this.projection = projection;
|
83 |
/*
|
84 |
try {
|
85 |
operationsSet = GeometryOperationsRegistry.getOperationSet(getGeometryType());
|
86 |
} catch (NotRegisteredOperationSetException e) {
|
87 |
//It is not possible to do any operation with this geometry!!!
|
88 |
}*/
|
89 |
} |
90 |
|
91 |
public AbstractPrimitive(IProjection projection) {
|
92 |
this(null, projection); |
93 |
} |
94 |
|
95 |
/*
|
96 |
* (non-Javadoc)
|
97 |
* @see com.iver.cit.gvsig.fmap.core.Geometry#getInternalShape()
|
98 |
*/
|
99 |
public Shape getInternalShape() { |
100 |
return this; |
101 |
} |
102 |
|
103 |
/*
|
104 |
* (non-Javadoc)
|
105 |
* @see org.gvsig.geometries.iso.AbstractGeometry#getBoundary()
|
106 |
*/
|
107 |
public Box getBoundary() { |
108 |
return new BaseBox(getBounds2D()); |
109 |
} |
110 |
|
111 |
/* (non-Javadoc)
|
112 |
* @see org.gvsig.geometries.iso.AbstractGeometry#getId()
|
113 |
*/
|
114 |
public String getId() { |
115 |
return id;
|
116 |
} |
117 |
|
118 |
/* (non-Javadoc)
|
119 |
* @see org.gvsig.geometries.iso.AbstractGeometry#getSRS()
|
120 |
*/
|
121 |
public IProjection getSRS() {
|
122 |
return projection;
|
123 |
} |
124 |
|
125 |
/* (non-Javadoc)
|
126 |
* @see org.gvsig.geometries.iso.AbstractGeometry#transform(org.cresques.cts.IProjection)
|
127 |
*/
|
128 |
public AbstractPrimitive transform(IProjection newProjection) {
|
129 |
Geometry newGeom = cloneGeometry(); |
130 |
ICoordTrans coordTrans = projection.getCT(newProjection); |
131 |
newGeom.reProject(coordTrans); |
132 |
return (AbstractPrimitive)newGeom;
|
133 |
} |
134 |
|
135 |
|
136 |
/*
|
137 |
* TODO adaptar metodo procedente de UtilFunctions
|
138 |
*/
|
139 |
public static void rotateGeom(Geometry geometry, double radAngle, double basex, double basey) { |
140 |
AffineTransform at = new AffineTransform(); |
141 |
at.rotate(radAngle,basex,basey); |
142 |
geometry.transform(at); |
143 |
|
144 |
} |
145 |
|
146 |
/*
|
147 |
* TODO adaptar metodo procedente de UtilFunctions
|
148 |
*/
|
149 |
public static void moveGeom(Geometry geometry, double dx, double dy) { |
150 |
AffineTransform at = new AffineTransform(); |
151 |
at.translate(dx, dy); |
152 |
geometry.transform(at); |
153 |
} |
154 |
|
155 |
/*
|
156 |
* TODO adaptar metodo procedente de UtilFunctions
|
157 |
*/
|
158 |
public static void scaleGeom(Geometry geometry, Point2D basePoint, double sx, double sy) { |
159 |
AffineTransform at = new AffineTransform(); |
160 |
at.setToTranslation(basePoint.getX(),basePoint.getY()); |
161 |
at.scale(sx,sy); |
162 |
at.translate(-basePoint.getX(),-basePoint.getY()); |
163 |
geometry.transform(at); |
164 |
} |
165 |
|
166 |
public boolean fastIntersects(double x, double y, double w, double h) { |
167 |
return intersects(x,y,w,h);
|
168 |
} |
169 |
|
170 |
public double[] getZs() { |
171 |
return null; |
172 |
} |
173 |
|
174 |
public Geometry cloneGeometry() {
|
175 |
return (Geometry)cloneFShape();
|
176 |
} |
177 |
|
178 |
public Handler[] getHandlers(int type) { |
179 |
if (type==STRETCHINGHANDLER){
|
180 |
return getStretchingHandlers();
|
181 |
}else if (type==SELECTHANDLER){ |
182 |
return getSelectHandlers();
|
183 |
} |
184 |
return null; |
185 |
} |
186 |
|
187 |
public boolean isSimple() { |
188 |
return true; |
189 |
} |
190 |
|
191 |
public abstract GeometryType getGeometryType(); |
192 |
|
193 |
/**
|
194 |
* Invoca una operación.
|
195 |
* @param index
|
196 |
* @return
|
197 |
*/
|
198 |
public Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationException { |
199 |
return GeometryManager.getInstance().invokeOperation(index, this, ctx); |
200 |
//return getGeometryType().getGeometryOperation(index).invoke(this, ctx);
|
201 |
} |
202 |
|
203 |
/**
|
204 |
*
|
205 |
* @return una de las ctes de FShape
|
206 |
*/
|
207 |
public abstract int getShapeType(); |
208 |
|
209 |
} |