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