svn-gvsig-desktop / tags / v1_1_Build_1012 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / VectorialEditableAdapter.java @ 12987
History | View | Annotate | Download (32 KB)
1 | 3612 | fjp | /*
|
---|---|---|---|
2 | * Created on 12-ene-2006 by fjp
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | 3722 | caballero | *
|
6 | 3612 | fjp | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 | 3722 | caballero | *
|
8 | 3612 | fjp | * This program is free software; you can redistribute it and/or
|
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | 3722 | caballero | *
|
13 | 3612 | fjp | * This program is distributed in the hope that it will be useful,
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | 3722 | caballero | *
|
18 | 3612 | fjp | * You should have received a copy of the GNU General Public License
|
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||
21 | 3722 | caballero | *
|
22 | 3612 | fjp | * For more information, contact:
|
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | 3722 | caballero | *
|
34 | 3612 | fjp | * or
|
35 | 3722 | caballero | *
|
36 | 3612 | fjp | * IVER T.I. S.A
|
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | 3722 | caballero | *
|
41 | 3612 | fjp | * +34 963163400
|
42 | * dac@iver.es
|
||
43 | */
|
||
44 | /* CVS MESSAGES:
|
||
45 | 3722 | caballero | *
|
46 | 3612 | fjp | * $Id$
|
47 | * $Log$
|
||
48 | 12734 | caballero | * Revision 1.62.4.9 2007-07-23 07:39:09 caballero
|
49 | * editing projection
|
||
50 | *
|
||
51 | * Revision 1.62.4.8 2007/07/18 06:35:35 caballero
|
||
52 | 12654 | caballero | * FNullGeometry editing
|
53 | *
|
||
54 | * Revision 1.62.4.7 2007/06/21 10:19:37 caballero
|
||
55 | 12269 | caballero | * bug acceso a la tabla simultaneamente en edici?n
|
56 | *
|
||
57 | * Revision 1.62.4.6 2007/05/07 09:01:50 caballero
|
||
58 | 11468 | caballero | * editing memory
|
59 | *
|
||
60 | * Revision 1.62.4.5 2007/04/04 14:25:22 caballero
|
||
61 | 11049 | caballero | * indice espacial diferente si es BoundShapes
|
62 | *
|
||
63 | * Revision 1.62.4.4 2007/02/09 11:25:44 caballero
|
||
64 | 10234 | caballero | * gr?fico o alfanum?rico
|
65 | *
|
||
66 | * Revision 1.62.4.3 2006/11/22 09:23:09 fjp
|
||
67 | 8913 | fjp | * Fallo al editar una capa de postgis 8.0 o superior. Y de paso, para que al guardar los cambios no haga falta leer todos los registros.
|
68 | *
|
||
69 | * Revision 1.62.4.2 2006/11/15 00:08:24 jjdelcerro
|
||
70 | 8765 | jjdelcerro | * *** empty log message ***
|
71 | 7272 | jaume | *
|
72 | 8765 | jjdelcerro | * Revision 1.64 2006/09/21 17:32:11 azabala
|
73 | * *** empty log message ***
|
||
74 | *
|
||
75 | 7272 | jaume | * Revision 1.62 2006/08/10 08:20:31 caballero
|
76 | 6714 | caballero | * flatness
|
77 | *
|
||
78 | * Revision 1.61 2006/07/20 13:03:07 fjp
|
||
79 | 6478 | fjp | * nuevos campos
|
80 | *
|
||
81 | * Revision 1.60 2006/07/12 11:48:41 fjp
|
||
82 | 6212 | fjp | * Draft to add, remove and delete fields
|
83 | *
|
||
84 | 6323 | fjp | * Revision 1.59 2006/07/12 10:34:52 fjp
|
85 | * Draft to add, remove and delete fields
|
||
86 | *
|
||
87 | 6313 | fjp | * Revision 1.58 2006/07/06 08:31:29 fjp
|
88 | * Draft to add, remove and delete fields
|
||
89 | *
|
||
90 | 6212 | fjp | * Revision 1.57 2006/06/22 11:38:12 caballero
|
91 | 5987 | caballero | * soluci?n error al borrar geometr?as
|
92 | *
|
||
93 | * Revision 1.56 2006/06/16 10:44:01 fjp
|
||
94 | 5880 | fjp | * Por mandato de Vicente
|
95 | 5879 | caballero | *
|
96 | * Revision 1.54 2006/06/01 16:15:16 fjp
|
||
97 | 5595 | fjp | * Escritura que permite crear drivers de manera m?s sencilla.
|
98 | *
|
||
99 | * Revision 1.53 2006/05/30 13:03:41 fjp
|
||
100 | 5535 | fjp | * setFlatness solo se debe aplicar a bases de datos espaciales.
|
101 | *
|
||
102 | * Revision 1.52 2006/05/24 09:29:30 caballero
|
||
103 | 5389 | caballero | * a?adir flatness
|
104 | *
|
||
105 | * Revision 1.51 2006/05/16 16:07:19 fjp
|
||
106 | 5223 | fjp | * snapping. Revisar
|
107 | *
|
||
108 | * Revision 1.50 2006/05/16 07:07:46 caballero
|
||
109 | 5197 | caballero | * Modificar la geometr?a desde fuera
|
110 | *
|
||
111 | * Revision 1.49 2006/05/15 10:52:23 caballero
|
||
112 | 5184 | caballero | * Saber si se realiza una operaci?n desde la vista o desde la tabla.
|
113 | *
|
||
114 | * Revision 1.48 2006/05/09 15:58:37 caballero
|
||
115 | 5115 | caballero | * Para el IGN
|
116 | *
|
||
117 | * Revision 1.47 2006/05/09 10:28:28 caballero
|
||
118 | 5114 | caballero | * faltaba controlar undo y redo
|
119 | *
|
||
120 | * Revision 1.46 2006/04/27 06:44:56 caballero
|
||
121 | 4954 | caballero | * Soluci?n undo y redo de anotaciones
|
122 | *
|
||
123 | * Revision 1.45 2006/04/18 06:56:55 caballero
|
||
124 | 4847 | caballero | * Cambiar VectorialAdapter por ReadableVectorial
|
125 | *
|
||
126 | * Revision 1.44 2006/04/12 17:13:39 fjp
|
||
127 | 4835 | fjp | * *** empty log message ***
|
128 | *
|
||
129 | * Revision 1.43 2006/04/11 12:12:29 fjp
|
||
130 | 4799 | fjp | * Con edici?n en PostGIS y guardando pseudo-arcos en los shapes.
|
131 | *
|
||
132 | * Revision 1.42 2006/04/11 06:53:20 fjp
|
||
133 | 4792 | fjp | * Preparando el driver de escritura PostGIS
|
134 | *
|
||
135 | * Revision 1.41 2006/04/04 11:27:16 fjp
|
||
136 | 4727 | fjp | * Consola escuchando bien y selecci?n en tabla sincronizada cuando hay edici?n
|
137 | *
|
||
138 | * Revision 1.40 2006/04/03 11:04:48 caballero
|
||
139 | 4709 | caballero | * Posibilidad de a?adir una anotaci?n
|
140 | *
|
||
141 | * Revision 1.39 2006/03/29 06:26:37 caballero
|
||
142 | 4637 | caballero | * acelerar con una imagen las herramientas
|
143 | *
|
||
144 | * Revision 1.38 2006/03/23 16:20:52 fjp
|
||
145 | 4568 | fjp | * Un fallo un tanto inverosimil con el mapOverview
|
146 | *
|
||
147 | * Revision 1.37 2006/03/23 10:08:11 caballero
|
||
148 | 4554 | caballero | * calculo del fullExtent recorriendo todas las geometr?as
|
149 | *
|
||
150 | * Revision 1.36 2006/03/22 11:46:29 caballero
|
||
151 | 4523 | caballero | * Editar capa de anotaciones
|
152 | *
|
||
153 | * Revision 1.35 2006/02/28 18:15:22 fjp
|
||
154 | 4225 | fjp | * Consola de CAD
|
155 | *
|
||
156 | * Revision 1.34 2006/02/24 11:30:32 fjp
|
||
157 | 4193 | fjp | * FUNCIONA!!! (Creo)
|
158 | *
|
||
159 | 4195 | fjp | * Revision 1.33 2006/02/24 07:57:58 fjp
|
160 | * FUNCIONA!!! (Creo)
|
||
161 | *
|
||
162 | 4193 | fjp | * Revision 1.32 2006/02/23 17:55:45 fjp
|
163 | 4147 | fjp | * Preparando para poder editar con el EditionManager
|
164 | *
|
||
165 | 4191 | fjp | * Revision 1.31 2006/02/21 16:44:08 fjp
|
166 | * Preparando para poder editar con el EditionManager
|
||
167 | *
|
||
168 | 4181 | fjp | * Revision 1.30 2006/02/20 18:14:59 fjp
|
169 | * Preparando para poder editar con el EditionManager
|
||
170 | *
|
||
171 | 4171 | fjp | * Revision 1.29 2006/02/20 10:32:54 fjp
|
172 | * Preparando para poder editar con el EditionManager
|
||
173 | *
|
||
174 | 4159 | fjp | * Revision 1.28 2006/02/17 13:40:03 fjp
|
175 | * Preparando para poder editar con el EditionManager
|
||
176 | *
|
||
177 | 4147 | fjp | * Revision 1.27 2006/02/17 10:41:14 fjp
|
178 | 4144 | fjp | * Evento de edici?n lanzado cuando una capa se pone en edici?n
|
179 | *
|
||
180 | * Revision 1.26 2006/02/17 08:21:19 fjp
|
||
181 | 4135 | fjp | * *** empty log message ***
|
182 | *
|
||
183 | * Revision 1.25 2006/02/16 09:38:10 fjp
|
||
184 | 4123 | fjp | * Preparando compatibilidad para bases de datos (y de paso, acelerando :-)
|
185 | *
|
||
186 | * Revision 1.24 2006/02/16 09:06:28 caballero
|
||
187 | 4120 | caballero | * commandStack
|
188 | *
|
||
189 | * Revision 1.23 2006/02/15 18:16:02 fjp
|
||
190 | 4085 | fjp | * POR TERMINAR
|
191 | *
|
||
192 | 4115 | fjp | * Revision 1.22 2006/02/13 18:18:31 fjp
|
193 | * POR TERMINAR
|
||
194 | *
|
||
195 | 4085 | fjp | * Revision 1.21 2006/02/10 13:28:23 caballero
|
196 | 4061 | caballero | * poder cambiar la selecci?n
|
197 | *
|
||
198 | * Revision 1.20 2006/02/09 13:11:54 caballero
|
||
199 | 4026 | caballero | * *** empty log message ***
|
200 | *
|
||
201 | * Revision 1.19 2006/02/08 16:45:29 caballero
|
||
202 | 4000 | caballero | * elimnar c?dio no usado
|
203 | *
|
||
204 | * Revision 1.18 2006/02/08 15:18:45 caballero
|
||
205 | 3996 | caballero | * control de las rows eliminadas
|
206 | *
|
||
207 | * Revision 1.17 2006/02/07 10:18:44 caballero
|
||
208 | 3980 | caballero | * Con BoundedShape
|
209 | *
|
||
210 | * Revision 1.16 2006/02/06 12:01:41 caballero
|
||
211 | 3958 | caballero | * driver del ova
|
212 | *
|
||
213 | * Revision 1.15 2006/02/03 14:09:32 fjp
|
||
214 | 3943 | fjp | * Preparando edici?n
|
215 | *
|
||
216 | 3952 | fjp | * Revision 1.14 2006/02/03 12:16:33 fjp
|
217 | * Preparando edici?n
|
||
218 | *
|
||
219 | 3943 | fjp | * Revision 1.13 2006/02/03 11:54:12 caballero
|
220 | 3940 | caballero | * tablas con vectorialEditableAdapter en edici?n
|
221 | 3936 | fjp | *
|
222 | * Revision 1.11 2006/01/31 08:10:05 caballero
|
||
223 | 3849 | caballero | * cambio de feature a row
|
224 | *
|
||
225 | * Revision 1.10 2006/01/30 08:18:14 caballero
|
||
226 | 3836 | caballero | * m?todos para deshacer y rehacer
|
227 | *
|
||
228 | * Revision 1.9 2006/01/23 17:30:28 caballero
|
||
229 | 3728 | caballero | * coger los datos del ova
|
230 | *
|
||
231 | * Revision 1.8 2006/01/23 16:16:16 caballero
|
||
232 | 3722 | caballero | * getRowIndex
|
233 | *
|
||
234 | * Revision 1.7 2006/01/20 08:37:10 fjp
|
||
235 | 3695 | fjp | * Preparando la edici?n
|
236 | *
|
||
237 | * Revision 1.6 2006/01/19 12:48:20 caballero
|
||
238 | 3688 | caballero | * poder modificar su vectorial Adapter
|
239 | *
|
||
240 | * Revision 1.5 2006/01/19 09:28:11 fjp
|
||
241 | 3686 | fjp | * Preparando la edici?n
|
242 | *
|
||
243 | * Revision 1.4 2006/01/17 10:24:02 fjp
|
||
244 | 3651 | fjp | * Preparando edici?n
|
245 | *
|
||
246 | 3653 | fjp | * Revision 1.3 2006/01/16 12:47:38 fjp
|
247 | * Preparando edici?n
|
||
248 | *
|
||
249 | 3652 | fjp | * Revision 1.2 2006/01/16 11:23:00 fjp
|
250 | * Preparando edici?n
|
||
251 | *
|
||
252 | 3651 | fjp | * Revision 1.1 2006/01/12 13:39:14 fjp
|
253 | 3612 | fjp | * preaparar edicion
|
254 | *
|
||
255 | *
|
||
256 | */
|
||
257 | package com.iver.cit.gvsig.fmap.edition; |
||
258 | |||
259 | 4727 | fjp | import java.awt.Image; |
260 | 3612 | fjp | import java.awt.geom.Rectangle2D; |
261 | 4637 | caballero | import java.awt.image.BufferedImage; |
262 | 3612 | fjp | import java.io.IOException; |
263 | 3722 | caballero | import java.util.List; |
264 | 3612 | fjp | |
265 | 12734 | caballero | import org.cresques.cts.ICoordTrans; |
266 | |||
267 | 5595 | fjp | import com.hardcode.driverManager.Driver; |
268 | 3612 | fjp | import com.hardcode.driverManager.DriverLoadException; |
269 | 3943 | fjp | import com.hardcode.gdbms.engine.data.DataSource; |
270 | import com.hardcode.gdbms.engine.values.Value; |
||
271 | 3940 | caballero | import com.iver.cit.gvsig.fmap.DriverException; |
272 | 8765 | jjdelcerro | import com.iver.cit.gvsig.fmap.DriverIOExceptionType; |
273 | import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType; |
||
274 | 3940 | caballero | import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
275 | 12654 | caballero | import com.iver.cit.gvsig.fmap.core.FNullGeometry; |
276 | 3980 | caballero | import com.iver.cit.gvsig.fmap.core.FShape; |
277 | 3612 | fjp | import com.iver.cit.gvsig.fmap.core.IFeature; |
278 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
279 | 3652 | fjp | import com.iver.cit.gvsig.fmap.core.IRow; |
280 | 4159 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
281 | 3980 | caballero | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
282 | 3940 | caballero | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
283 | 3612 | fjp | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
284 | 3940 | caballero | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
285 | 4061 | caballero | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
286 | 3940 | caballero | import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
287 | 3652 | fjp | import com.vividsolutions.jts.geom.Envelope; |
288 | 4523 | caballero | import com.vividsolutions.jts.index.SpatialIndex; |
289 | 3652 | fjp | import com.vividsolutions.jts.index.quadtree.Quadtree; |
290 | 3612 | fjp | |
291 | /**
|
||
292 | * @author fjp
|
||
293 | 5389 | caballero | *
|
294 | 3612 | fjp | */
|
295 | 5223 | fjp | public class VectorialEditableAdapter extends EditableAdapter implements |
296 | ReadableVectorial, BoundedShapes { |
||
297 | 4847 | caballero | protected ReadableVectorial ova;
|
298 | 5223 | fjp | |
299 | 4159 | fjp | protected Quadtree index;
|
300 | 4523 | caballero | |
301 | 4225 | fjp | protected Rectangle2D fullExtent; |
302 | 5223 | fjp | |
303 | 4792 | fjp | protected Image selectionImage; |
304 | 5223 | fjp | |
305 | 4792 | fjp | protected BufferedImage handlersImage; |
306 | 4523 | caballero | |
307 | 12734 | caballero | private ICoordTrans ct;
|
308 | |||
309 | 6714 | caballero | //private double flatness=0.8;
|
310 | 5223 | fjp | /*
|
311 | * private class MyFeatureIterator implements IFeatureIterator { int numReg =
|
||
312 | * 0; Rectangle2D rect; String epsg; IFeatureIterator origFeatIt; boolean
|
||
313 | * bHasNext = true;
|
||
314 | 5389 | caballero | *
|
315 | 5223 | fjp | * public MyFeatureIterator(Rectangle2D r, String strEPSG) throws
|
316 | * DriverException { rect = r; epsg = strEPSG; origFeatIt =
|
||
317 | * ova.getFeatureIterator(r, epsg); } public boolean hasNext() throws
|
||
318 | * DriverException { return bHasNext; }
|
||
319 | 5389 | caballero | *
|
320 | 5223 | fjp | * public IFeature next() throws DriverException { IFeature aux =
|
321 | * origFeatIt.next(); return null; }
|
||
322 | 5389 | caballero | *
|
323 | 5223 | fjp | * public void closeIterator() throws DriverException {
|
324 | * }
|
||
325 | * }
|
||
326 | */
|
||
327 | 4523 | caballero | |
328 | 5223 | fjp | public VectorialEditableAdapter() {
|
329 | 3940 | caballero | super();
|
330 | 3652 | fjp | } |
331 | 5223 | fjp | |
332 | public void setOriginalVectorialAdapter(ReadableVectorial rv) { |
||
333 | ova = rv; |
||
334 | 3940 | caballero | try {
|
335 | 3958 | caballero | setOriginalDataSource(rv.getRecordset()); |
336 | 3940 | caballero | } catch (DriverLoadException e) {
|
337 | e.printStackTrace(); |
||
338 | 6212 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
339 | // TODO Auto-generated catch block
|
||
340 | e.printStackTrace(); |
||
341 | 3652 | fjp | } |
342 | } |
||
343 | 5223 | fjp | |
344 | 3652 | fjp | /*
|
345 | * (non-Javadoc)
|
||
346 | 5389 | caballero | *
|
347 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#start()
|
348 | */
|
||
349 | public void start() throws DriverIOException { |
||
350 | 3653 | fjp | ova.start(); |
351 | 3652 | fjp | } |
352 | |||
353 | 5595 | fjp | public IWriter getWriter() {
|
354 | if (ova.getDriver() instanceof IWriteable) |
||
355 | { |
||
356 | IWriter writer = ((IWriteable) ova.getDriver()).getWriter(); |
||
357 | if (writer instanceof ISpatialWriter) |
||
358 | return writer;
|
||
359 | } |
||
360 | return null; |
||
361 | } |
||
362 | |||
363 | 3652 | fjp | /*
|
364 | * (non-Javadoc)
|
||
365 | 5389 | caballero | *
|
366 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#stop()
|
367 | */
|
||
368 | public void stop() throws DriverIOException { |
||
369 | 3653 | fjp | ova.stop(); |
370 | 3652 | fjp | } |
371 | |||
372 | /*
|
||
373 | * (non-Javadoc)
|
||
374 | 5389 | caballero | *
|
375 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
|
376 | */
|
||
377 | public IGeometry getShape(int rowIndex) throws DriverIOException { |
||
378 | // Si no est? en el fichero de expansi?n
|
||
379 | 5223 | fjp | int calculatedIndex = getCalculatedIndex(rowIndex);
|
380 | 3996 | caballero | Integer integer = new Integer(calculatedIndex); |
381 | 3652 | fjp | if (!relations.containsKey(integer)) {
|
382 | // Si ha sido eliminada
|
||
383 | 5223 | fjp | /*
|
384 | * if (delRows.get(integer.intValue())) { return null; } else {
|
||
385 | */
|
||
386 | return ova.getShape(calculatedIndex);
|
||
387 | // }
|
||
388 | 3652 | fjp | } else {
|
389 | int num = ((Integer) relations.get(integer)).intValue(); |
||
390 | 3722 | caballero | DefaultRowEdited feat; |
391 | 3652 | fjp | try {
|
392 | 3722 | caballero | feat = (DefaultRowEdited) expansionFile.getRow(num); |
393 | 5223 | fjp | return ((IFeature) feat.getLinkedRow()).getGeometry()
|
394 | .cloneGeometry();// getGeometry();
|
||
395 | 3652 | fjp | } catch (IOException e) { |
396 | e.printStackTrace(); |
||
397 | throw new DriverIOException(e); |
||
398 | } |
||
399 | } |
||
400 | |||
401 | } |
||
402 | |||
403 | /*
|
||
404 | * (non-Javadoc)
|
||
405 | 5389 | caballero | *
|
406 | 3652 | fjp | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
|
407 | */
|
||
408 | public int getShapeType() throws DriverIOException { |
||
409 | 3653 | fjp | return ova.getShapeType();
|
410 | 3652 | fjp | } |
411 | 5223 | fjp | |
412 | public ReadableVectorial getOriginalAdapter() {
|
||
413 | 3940 | caballero | return ova;
|
414 | 3652 | fjp | } |
415 | 5223 | fjp | |
416 | 3940 | caballero | public VectorialDriver getDriver() {
|
417 | 3958 | caballero | return ova.getDriver();
|
418 | 3652 | fjp | } |
419 | 5223 | fjp | |
420 | 3940 | caballero | public void setDriver(VectorialDriver driver) { |
421 | 3958 | caballero | this.ova.setDriver(driver);
|
422 | 3652 | fjp | } |
423 | 5223 | fjp | |
424 | public DriverAttributes getDriverAttributes() {
|
||
425 | 3958 | caballero | return ova.getDriverAttributes();
|
426 | 3940 | caballero | } |
427 | 5223 | fjp | /**
|
428 | 12734 | caballero | * Inserta las coordenadas de transformaci?n.
|
429 | *
|
||
430 | * @param ct Coordenadas de transformaci?n.
|
||
431 | */
|
||
432 | public void setCoordTrans(ICoordTrans ct) { |
||
433 | this.ct=ct;
|
||
434 | } |
||
435 | |||
436 | /**
|
||
437 | 5223 | fjp | * DOCUMENT ME!
|
438 | 5389 | caballero | *
|
439 | 5223 | fjp | * @throws EditionException
|
440 | * DOCUMENT ME!
|
||
441 | */
|
||
442 | public void startEdition(int sourceType) throws EditionException { |
||
443 | super.startEdition(sourceType);
|
||
444 | 5595 | fjp | Driver drv = ova.getDriver();
|
445 | if (drv instanceof IWriteable) |
||
446 | { |
||
447 | setWriter(((IWriteable) drv).getWriter()); |
||
448 | } |
||
449 | 3652 | fjp | |
450 | 5595 | fjp | |
451 | 5223 | fjp | try {
|
452 | expansionFile.open(); |
||
453 | if (index == null || fullExtent == null) { |
||
454 | // TODO: Si la capa dispone de un ?ndice espacial, hacer
|
||
455 | // algo aqu? para que se use ese ?ndice espacial.
|
||
456 | index = new Quadtree();
|
||
457 | for (int i = 0; i < ova.getShapeCount(); i++) { |
||
458 | 11049 | caballero | Rectangle2D r=null; |
459 | if (ova.getDriver() instanceof BoundedShapes) { |
||
460 | r = ((BoundedShapes) ova.getDriver()).getShapeBounds(i); |
||
461 | } else {
|
||
462 | IGeometry g = null;
|
||
463 | try {
|
||
464 | g = ((DefaultFeature) ova.getFeature(i)) |
||
465 | .getGeometry(); |
||
466 | } catch (DriverException e1) {
|
||
467 | e1.printStackTrace(); |
||
468 | } |
||
469 | 3653 | fjp | |
470 | 11049 | caballero | if (g == null) { |
471 | continue;
|
||
472 | } |
||
473 | |||
474 | r = g.getBounds2D(); |
||
475 | 5223 | fjp | } |
476 | 12734 | caballero | if (ct != null) { |
477 | r = ct.convert(r); |
||
478 | } |
||
479 | 5223 | fjp | Envelope e = new Envelope(r.getX(),
|
480 | r.getX() + r.getWidth(), r.getY(), r.getY() |
||
481 | + r.getHeight()); |
||
482 | index.insert(e, new Integer(i)); |
||
483 | if (fullExtent == null) { |
||
484 | fullExtent = r; |
||
485 | } else {
|
||
486 | fullExtent = fullExtent.createUnion(r); |
||
487 | } |
||
488 | } |
||
489 | } |
||
490 | } catch (DriverIOException e) {
|
||
491 | throw new EditionException(e); |
||
492 | } catch (IOException e) { |
||
493 | throw new EditionException(e); |
||
494 | } |
||
495 | 3652 | fjp | |
496 | 5223 | fjp | System.err.println("Se han metido en el ?ndice " |
497 | + index.queryAll().size() + " geometr?as");
|
||
498 | } |
||
499 | 3652 | fjp | |
500 | 5223 | fjp | /*
|
501 | * (non-Javadoc)
|
||
502 | 5389 | caballero | *
|
503 | 5223 | fjp | * @see com.iver.cit.gvsig.fmap.edition.IEditableSource#getRow(int)
|
504 | */
|
||
505 | public IRowEdited getRow(int index) throws DriverIOException, IOException { |
||
506 | 12269 | caballero | start(); |
507 | 5223 | fjp | int calculatedIndex = getCalculatedIndex(index);
|
508 | Integer integer = new Integer(calculatedIndex); |
||
509 | // Si no est? en el fichero de expansi?n
|
||
510 | DefaultRowEdited edRow = null;
|
||
511 | if (!relations.containsKey(integer)) {
|
||
512 | 4115 | fjp | try {
|
513 | edRow = new DefaultRowEdited(ova.getFeature(calculatedIndex),
|
||
514 | 5223 | fjp | DefaultRowEdited.STATUS_ORIGINAL, index); |
515 | 12269 | caballero | stop(); |
516 | 6313 | fjp | return createExternalRow(edRow, 0); |
517 | 4115 | fjp | } catch (DriverException e) {
|
518 | e.printStackTrace(); |
||
519 | 8913 | fjp | throw new DriverIOException(e); |
520 | 4115 | fjp | } |
521 | 3652 | fjp | |
522 | 8913 | fjp | // return edRow;
|
523 | 5223 | fjp | } else {
|
524 | int num = ((Integer) relations.get(integer)).intValue(); |
||
525 | IRowEdited aux = expansionFile.getRow(num); |
||
526 | edRow = new DefaultRowEdited(aux.getLinkedRow().cloneRow(), aux
|
||
527 | .getStatus(), index); |
||
528 | 12269 | caballero | stop(); |
529 | 5223 | fjp | return edRow;
|
530 | } |
||
531 | } |
||
532 | |||
533 | /**
|
||
534 | * Elimina una geometria. Si es una geometr?a original de la capa en edici?n
|
||
535 | * se marca como eliminada (haya sido modificada o no). Si es una geometr?a
|
||
536 | * a?adida posteriormente se invalida en el fichero de expansi?n, para que
|
||
537 | * una futura compactaci?n termine con ella.
|
||
538 | 5389 | caballero | *
|
539 | 5223 | fjp | * @param index
|
540 | * ?ndice de la geometr?a.
|
||
541 | 5389 | caballero | *
|
542 | 5223 | fjp | * @throws DriverIOException
|
543 | * @throws IOException
|
||
544 | */
|
||
545 | public IRow doRemoveRow(int index, int sourceType) |
||
546 | throws DriverIOException, IOException { |
||
547 | boolean cancel = fireBeforeRemoveRow(index, sourceType);
|
||
548 | 5114 | caballero | if (cancel)
|
549 | return null; |
||
550 | 5223 | fjp | // Llega el calculatedIndex
|
551 | Integer integer = new Integer(index); |
||
552 | 3652 | fjp | |
553 | 5223 | fjp | IFeature feat = null;
|
554 | delRows.set(index, true);
|
||
555 | // Si la geometr?a no ha sido modificada
|
||
556 | if (!relations.containsKey(integer)) {
|
||
557 | 3996 | caballero | |
558 | 5223 | fjp | try {
|
559 | 3940 | caballero | feat = (DefaultFeature) (ova.getFeature(index)); |
560 | } catch (DriverException e) {
|
||
561 | // TODO Auto-generated catch block
|
||
562 | e.printStackTrace(); |
||
563 | } |
||
564 | 5223 | fjp | } else {
|
565 | 3940 | caballero | int num = ((Integer) relations.get(integer)).intValue(); |
566 | feat = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
||
567 | 5223 | fjp | // expansionFile.invalidateRow(num);
|
568 | 3653 | fjp | } |
569 | 5223 | fjp | System.err.println("Elimina una Row en la posici?n: " + index); |
570 | // Se actualiza el ?ndice
|
||
571 | if (feat != null) { |
||
572 | Rectangle2D r = feat.getGeometry().getBounds2D();
|
||
573 | boolean borrado = this.index.remove(new Envelope(r.getX(), r.getX() |
||
574 | + r.getWidth(), r.getY(), r.getY() + r.getHeight()), |
||
575 | new Integer(index)); |
||
576 | System.out.println("Est? borrado : " + borrado); |
||
577 | System.out.println("Index.lenght : " + this.index.size()); |
||
578 | 8765 | jjdelcerro | isFullExtentDirty = true;
|
579 | 5223 | fjp | } |
580 | setSelection(new FBitSet());
|
||
581 | fireAfterRemoveRow(index, sourceType); |
||
582 | return feat;
|
||
583 | } |
||
584 | |||
585 | /**
|
||
586 | * Si se intenta modificar una geometr?a original de la capa en edici?n se
|
||
587 | * a?ade al fichero de expansi?n y se registra la posici?n en la que se
|
||
588 | * a?adi?. Si se intenta modificar una geometria que se encuentra en el
|
||
589 | * fichero de expansi?n (por ser nueva o original pero modificada) se invoca
|
||
590 | * el m?todo modifyGeometry y se actualiza el ?ndice de la geometria en el
|
||
591 | * fichero.
|
||
592 | 5389 | caballero | *
|
593 | 5223 | fjp | * @param calculatedIndex
|
594 | * DOCUMENT ME!
|
||
595 | * @param feat
|
||
596 | * DOCUMENT ME!
|
||
597 | 5389 | caballero | *
|
598 | 5223 | fjp | * @return position inside ExpansionFile
|
599 | 5389 | caballero | *
|
600 | 5223 | fjp | * @throws IOException
|
601 | * @throws DriverIOException
|
||
602 | */
|
||
603 | public int doModifyRow(int calculatedIndex, IRow feat, int sourceType) |
||
604 | throws IOException, DriverIOException { |
||
605 | boolean cancel = fireBeforeModifyRow(feat, calculatedIndex, sourceType);
|
||
606 | 5114 | caballero | if (cancel)
|
607 | return -1; |
||
608 | 5223 | fjp | int posAnteriorInExpansionFile = -1; |
609 | Integer integer = new Integer(calculatedIndex); |
||
610 | 3652 | fjp | |
611 | 5223 | fjp | IFeature featAnt = null;
|
612 | 10234 | caballero | // System.err.println("Modifica una Row en la posici?n: "
|
613 | // + calculatedIndex);
|
||
614 | 5223 | fjp | // Si la geometr?a no ha sido modificada
|
615 | if (!relations.containsKey(integer)) {
|
||
616 | int newPosition = expansionFile.addRow(feat,
|
||
617 | 6212 | fjp | IRowEdited.STATUS_MODIFIED, actualIndexFields); |
618 | 5223 | fjp | relations.put(integer, new Integer(newPosition)); |
619 | 3652 | fjp | |
620 | 10234 | caballero | if (sourceType == EditionEvent.GRAPHIC) {
|
621 | // Se actualiza el ?ndice espacial
|
||
622 | try {
|
||
623 | featAnt = (DefaultFeature) (ova.getFeature(calculatedIndex)); |
||
624 | } catch (DriverException e) {
|
||
625 | e.printStackTrace(); |
||
626 | } |
||
627 | IGeometry g = featAnt.getGeometry(); |
||
628 | Rectangle2D rAnt = g.getBounds2D();
|
||
629 | Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
||
630 | this.index.remove(new Envelope(rAnt.getX(), rAnt.getX() |
||
631 | + rAnt.getWidth(), rAnt.getY(), rAnt.getY() |
||
632 | + rAnt.getHeight()), new Integer(calculatedIndex)); |
||
633 | this.index.insert(new Envelope(r.getX(), r.getX() |
||
634 | + r.getWidth(), r.getY(), r.getY() + r.getHeight()), |
||
635 | new Integer(calculatedIndex)); |
||
636 | 3940 | caballero | } |
637 | 5223 | fjp | } else {
|
638 | // Obtenemos el ?ndice en el fichero de expansi?n
|
||
639 | int num = ((Integer) relations.get(integer)).intValue(); |
||
640 | posAnteriorInExpansionFile = num; |
||
641 | 3653 | fjp | |
642 | 5223 | fjp | // Obtenemos la geometr?a para actualiza el ?ndice
|
643 | // espacialposteriormente
|
||
644 | featAnt = (IFeature) expansionFile.getRow(num).getLinkedRow(); |
||
645 | 3652 | fjp | |
646 | 5223 | fjp | /*
|
647 | * Se modifica la geometr?a y nos guardamos el ?ndice dentro del
|
||
648 | * fichero de expansi?n en el que se encuentra la geometr?a
|
||
649 | * modificada
|
||
650 | */
|
||
651 | 6212 | fjp | num = expansionFile.modifyRow(num, feat, actualIndexFields); |
652 | 3652 | fjp | |
653 | 5223 | fjp | /*
|
654 | * Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el
|
||
655 | * fichero de expansi?n.
|
||
656 | */
|
||
657 | relations.put(integer, new Integer(num)); |
||
658 | 10234 | caballero | if (sourceType == EditionEvent.GRAPHIC) {
|
659 | // Se modifica el ?ndice espacial
|
||
660 | Rectangle2D rAnt = featAnt.getGeometry().getBounds2D();
|
||
661 | Rectangle2D r = ((IFeature) feat).getGeometry().getBounds2D();
|
||
662 | this.index.remove(new Envelope(rAnt.getX(), rAnt.getX() |
||
663 | + rAnt.getWidth(), rAnt.getY(), rAnt.getY() |
||
664 | + rAnt.getHeight()), new Integer(calculatedIndex)); |
||
665 | this.index.insert(new Envelope(r.getX(), r.getX() |
||
666 | + r.getWidth(), r.getY(), r.getY() + r.getHeight()), |
||
667 | new Integer(calculatedIndex)); |
||
668 | } |
||
669 | 5223 | fjp | } |
670 | 7272 | jaume | isFullExtentDirty = true;
|
671 | 5223 | fjp | fireAfterModifyRow(calculatedIndex, sourceType); |
672 | return posAnteriorInExpansionFile;
|
||
673 | } |
||
674 | 5197 | caballero | |
675 | 5223 | fjp | /**
|
676 | * Actualiza en el mapa de ?ndices, la posici?n en la que estaba la
|
||
677 | * geometr?a antes de ser modificada. Se marca como v?lida, en caso de que
|
||
678 | * fuera una modificaci?n de una geometr?a que estuviese en el fichero de
|
||
679 | * expansi?n antes de ser modificada y se pone el puntero de escritura del
|
||
680 | * expansion file a justo despues de la penultima geometr?a
|
||
681 | 5389 | caballero | *
|
682 | 5223 | fjp | * @param calculatedIndex
|
683 | * ?ndice de la geometr?a que se quiere deshacer su modificaci?n
|
||
684 | * @param previousExpansionFileIndex
|
||
685 | * ?ndice que ten?a antes la geometr?a en el expansionFile. Si
|
||
686 | * vale -1 quiere decir que es una modificaci?n de una geometr?a
|
||
687 | * original y por tanto no hay que actualizar el mapa de indices
|
||
688 | * sino eliminar su entrada.
|
||
689 | 5389 | caballero | *
|
690 | 5223 | fjp | * @throws IOException
|
691 | * @throws DriverIOException
|
||
692 | */
|
||
693 | public void undoModifyRow(int calculatedIndex, |
||
694 | int previousExpansionFileIndex, int sourceType) throws IOException, |
||
695 | DriverIOException { |
||
696 | 5197 | caballero | |
697 | 5223 | fjp | // Llega el CalculatedIndex
|
698 | /*
|
||
699 | * Si la acci?n de modificar se realiz? sobre una geometr?a original
|
||
700 | */
|
||
701 | if (previousExpansionFileIndex == -1) { |
||
702 | |||
703 | // Se obtiene la geometr?a para actualizar el ?ndice
|
||
704 | // IGeometry g = ((DefaultFeature)
|
||
705 | // getRow(calculatedIndex).getLinkedRow()).getGeometry();
|
||
706 | int inverse = getInversedIndex(calculatedIndex);
|
||
707 | DefaultFeature df = (DefaultFeature) getRow(inverse).getLinkedRow(); |
||
708 | boolean cancel = fireBeforeModifyRow(df, calculatedIndex,
|
||
709 | sourceType); |
||
710 | 5197 | caballero | if (cancel)
|
711 | return;
|
||
712 | 5223 | fjp | IGeometry g = df.getGeometry(); |
713 | // IGeometry g = ova.getShape(calculatedIndex);
|
||
714 | Rectangle2D r = g.getBounds2D();
|
||
715 | 3652 | fjp | |
716 | 5223 | fjp | // Se elimina de las relaciones y del fichero de expansi?n
|
717 | relations.remove(new Integer(calculatedIndex)); |
||
718 | expansionFile.deleteLastRow(); |
||
719 | 3652 | fjp | |
720 | 5223 | fjp | // Se actualizan los ?ndices
|
721 | IGeometry gAnt = ova.getShape(calculatedIndex); |
||
722 | /*
|
||
723 | * IGeometry gAnt = ((DefaultFeature) getRow(calculatedIndex)
|
||
724 | * .getLinkedRow()).getGeometry();
|
||
725 | */
|
||
726 | Rectangle2D rAnt = gAnt.getBounds2D();
|
||
727 | this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
728 | .getY(), r.getY() + r.getHeight()), new Integer( |
||
729 | calculatedIndex)); |
||
730 | this.index.insert(new Envelope(rAnt.getX(), rAnt.getX() |
||
731 | + rAnt.getWidth(), rAnt.getY(), rAnt.getY() |
||
732 | + rAnt.getHeight()), new Integer(calculatedIndex)); |
||
733 | } else {
|
||
734 | // Se obtiene la geometr?a para actualizar el ?ndice
|
||
735 | IGeometry g = null;
|
||
736 | int inverse = getInversedIndex(calculatedIndex);
|
||
737 | DefaultFeature df = (DefaultFeature) getRow(inverse).getLinkedRow(); |
||
738 | boolean cancel = fireBeforeModifyRow(df, calculatedIndex,
|
||
739 | sourceType); |
||
740 | 5197 | caballero | if (cancel)
|
741 | return;
|
||
742 | 5223 | fjp | g = df.getGeometry(); |
743 | System.out.println("Actual: " + g.toString()); |
||
744 | 3652 | fjp | |
745 | 5223 | fjp | Rectangle2D r = g.getBounds2D();
|
746 | this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
747 | .getY(), r.getY() + r.getHeight()), new Integer( |
||
748 | calculatedIndex)); |
||
749 | 3652 | fjp | |
750 | 5223 | fjp | // Se actualiza la relaci?n de ?ndices
|
751 | // Integer integer = new Integer(geometryIndex);
|
||
752 | relations.put(new Integer(calculatedIndex), new Integer( |
||
753 | previousExpansionFileIndex)); |
||
754 | 3652 | fjp | |
755 | 5223 | fjp | // Se recupera la geometr?a
|
756 | // expansionFile.validateRow(previousExpansionFileIndex);
|
||
757 | 3652 | fjp | |
758 | 5223 | fjp | // Se actualizan los ?ndices
|
759 | // g = ((IFeature)
|
||
760 | // (expansionFile.getRow(previousExpansionFileIndex).getLinkedRow())).getGeometry();
|
||
761 | // System.out.println("Anterior a la que volvemos : " +
|
||
762 | // g.toString());
|
||
763 | g = ((DefaultFeature) getRow(inverse).getLinkedRow()).getGeometry(); |
||
764 | r = g.getBounds2D(); |
||
765 | this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
766 | .getY(), r.getY() + r.getHeight()), new Integer( |
||
767 | calculatedIndex)); |
||
768 | 5114 | caballero | |
769 | 5223 | fjp | } |
770 | fireAfterModifyRow(calculatedIndex, sourceType); |
||
771 | } |
||
772 | 3653 | fjp | |
773 | 5223 | fjp | /**
|
774 | * A?ade una geometria al fichero de expansi?n y guarda la correspondencia
|
||
775 | * en la tabla relations.
|
||
776 | 5389 | caballero | *
|
777 | 5223 | fjp | * @param feat
|
778 | * geometr?a a guardar.
|
||
779 | 5389 | caballero | *
|
780 | 5223 | fjp | * @return calculatedIndex
|
781 | 5389 | caballero | *
|
782 | 5223 | fjp | * @throws DriverIOException
|
783 | * @throws IOException
|
||
784 | */
|
||
785 | public int doAddRow(IRow feat, int sourceType) throws DriverIOException, |
||
786 | IOException {
|
||
787 | int calculatedIndex = super.doAddRow(feat, sourceType); |
||
788 | 3940 | caballero | // Actualiza el ?ndice espacial
|
789 | 5223 | fjp | IGeometry g = ((IFeature) feat).getGeometry(); |
790 | Rectangle2D r = g.getBounds2D();
|
||
791 | index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(),
|
||
792 | r.getY() + r.getHeight()), new Integer(calculatedIndex)); |
||
793 | 7272 | jaume | isFullExtentDirty = true;
|
794 | 5223 | fjp | return calculatedIndex;
|
795 | } |
||
796 | 3653 | fjp | |
797 | 5223 | fjp | /**
|
798 | * Se desmarca como invalidada en el fichero de expansion o como eliminada
|
||
799 | * en el fichero original
|
||
800 | 5389 | caballero | *
|
801 | 5223 | fjp | * @param index
|
802 | * DOCUMENT ME!
|
||
803 | 5389 | caballero | *
|
804 | 5223 | fjp | * @throws IOException
|
805 | * @throws DriverIOException
|
||
806 | */
|
||
807 | public void undoRemoveRow(int index, int sourceType) throws IOException, |
||
808 | DriverIOException { |
||
809 | super.undoRemoveRow(index, sourceType);
|
||
810 | 3653 | fjp | |
811 | 5223 | fjp | IGeometry g = null;
|
812 | 5987 | caballero | g = ((IFeature) getRow(getInversedIndex(index)).getLinkedRow()).getGeometry(); |
813 | 3653 | fjp | |
814 | 5223 | fjp | Rectangle2D r = g.getBounds2D();
|
815 | this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
816 | .getY(), r.getY() + r.getHeight()), new Integer(index)); |
||
817 | } |
||
818 | 3653 | fjp | |
819 | 5223 | fjp | /**
|
820 | * Se elimina del final del fichero de expansi?n poniendo el puntero de
|
||
821 | * escritura apuntando al final de la pen?ltima geometr?a. Deber? quitar la
|
||
822 | * relaci?n del mapa de relaciones
|
||
823 | 5389 | caballero | *
|
824 | 5223 | fjp | * @param index
|
825 | * ?ndice de la geometr?a que se a?adi?
|
||
826 | 5389 | caballero | *
|
827 | 5223 | fjp | * @throws DriverIOException
|
828 | * @throws IOException
|
||
829 | */
|
||
830 | public void undoAddRow(int calculatedIndex, int sourceType) |
||
831 | throws DriverIOException, IOException { |
||
832 | int inverse = getInversedIndex(calculatedIndex);
|
||
833 | IGeometry g = ((IFeature) getRow(inverse).getLinkedRow()).getGeometry(); |
||
834 | Rectangle2D r = g.getBounds2D();
|
||
835 | this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), r |
||
836 | .getY(), r.getY() + r.getHeight()), |
||
837 | new Integer(calculatedIndex)); |
||
838 | 3653 | fjp | |
839 | 5223 | fjp | super.undoAddRow(calculatedIndex, sourceType);
|
840 | setSelection(new FBitSet());
|
||
841 | } |
||
842 | |||
843 | /**
|
||
844 | * Obtiene las geometr?as que se encuentran en el rect?ngulo que se pasa
|
||
845 | * como par?metro haciendo uso del ?ndice espacial
|
||
846 | 5389 | caballero | *
|
847 | 5223 | fjp | * @param r
|
848 | * Rect?ngulo indicando la porci?n del espacio para el cual se
|
||
849 | * quiere saber los ?ndices de las geometr?as que se encuentran
|
||
850 | * dentro de ?l
|
||
851 | 5389 | caballero | *
|
852 | 5223 | fjp | * @return Array de ?ndices para su uso con getGeometry, removeGeometry, ...
|
853 | */
|
||
854 | /*
|
||
855 | * public int[] getRowsIndexes_OL(Rectangle2D r) { Envelope e = new
|
||
856 | * Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(), r.getY() +
|
||
857 | * r.getHeight()); List l = index.query(e); int[] indexes = new
|
||
858 | * int[l.size()];
|
||
859 | 5389 | caballero | *
|
860 | 5223 | fjp | * for (int index = 0; index < l.size(); index++) { Integer i = (Integer)
|
861 | * l.get(index); indexes[index] = getInversedIndex(i.intValue()); }
|
||
862 | 5389 | caballero | *
|
863 | 5223 | fjp | * return indexes; }
|
864 | */
|
||
865 | /**
|
||
866 | 3940 | caballero | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
|
867 | 3836 | caballero | */
|
868 | 3940 | caballero | public int getShapeCount() throws DriverIOException { |
869 | 3996 | caballero | try {
|
870 | return getRowCount();
|
||
871 | 5223 | fjp | } catch (IOException e) { |
872 | 3996 | caballero | throw new DriverIOException(e); |
873 | } |
||
874 | 3836 | caballero | } |
875 | 3722 | caballero | |
876 | 3836 | caballero | /**
|
877 | 3940 | caballero | * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
|
878 | 3836 | caballero | */
|
879 | 3940 | caballero | public Rectangle2D getFullExtent() throws DriverIOException { |
880 | 5223 | fjp | if (fullExtent == null) { |
881 | fullExtent = ova.getFullExtent(); |
||
882 | } |
||
883 | 7272 | jaume | |
884 | if (isFullExtentDirty) {
|
||
885 | fullExtent = reCalculateFullExtent(); |
||
886 | isFullExtentDirty = false;
|
||
887 | } |
||
888 | 12734 | caballero | |
889 | 5223 | fjp | return fullExtent;
|
890 | } |
||
891 | 4554 | caballero | |
892 | 5223 | fjp | /**
|
893 | * Use it BEFORE writing to a file.
|
||
894 | 5389 | caballero | *
|
895 | 5223 | fjp | * @return real full extent.
|
896 | * @throws DriverIOException
|
||
897 | */
|
||
898 | public Rectangle2D reCalculateFullExtent() throws DriverIOException { |
||
899 | if (getShapeCount() > 0) { |
||
900 | fullExtent = getShape(0).getBounds2D();
|
||
901 | for (int i = 1; i < getShapeCount(); i++) { |
||
902 | 12654 | caballero | IGeometry geom=getShape(i); |
903 | if (fullExtent==null) { |
||
904 | fullExtent=geom.getBounds2D(); |
||
905 | continue;
|
||
906 | } |
||
907 | if (!(geom instanceof FNullGeometry)) { |
||
908 | fullExtent.add(geom.getBounds2D()); |
||
909 | } |
||
910 | 5223 | fjp | } |
911 | } else {
|
||
912 | fullExtent = ova.getFullExtent(); |
||
913 | } |
||
914 | return fullExtent;
|
||
915 | 3836 | caballero | } |
916 | 3958 | caballero | |
917 | 5223 | fjp | /**
|
918 | * En la implementaci?n por defecto podemos hacer que cada feature tenga ID =
|
||
919 | * numero de registro. En el DBAdapter podr?amos "overrride" este m?todo y
|
||
920 | * poner como ID de la Feature el campo ?nico escogido en la base de datos.
|
||
921 | 5389 | caballero | *
|
922 | 5223 | fjp | * @param numReg
|
923 | * @return
|
||
924 | * @throws DriverException
|
||
925 | */
|
||
926 | public IFeature getFeature(int numReg) throws DriverException { |
||
927 | IGeometry geom; |
||
928 | IFeature feat = null;
|
||
929 | try {
|
||
930 | geom = getShape(numReg); |
||
931 | DataSource rs = getRecordset();
|
||
932 | Value[] regAtt = new Value[rs.getFieldCount()]; |
||
933 | for (int fieldId = 0; fieldId < rs.getFieldCount(); fieldId++) { |
||
934 | regAtt[fieldId] = rs.getFieldValue(numReg, fieldId); |
||
935 | } |
||
936 | feat = new DefaultFeature(geom, regAtt, numReg + ""); |
||
937 | } catch (DriverIOException e) {
|
||
938 | 8765 | jjdelcerro | DriverIOExceptionType type = |
939 | new DriverIOExceptionType();
|
||
940 | type.setDriverName(this.getDriver().getName());
|
||
941 | throw new DriverException(e, type); |
||
942 | 10234 | caballero | |
943 | 5223 | fjp | } catch (DriverLoadException e) {
|
944 | 8765 | jjdelcerro | DriverNotLoadedExceptionType type = |
945 | new DriverNotLoadedExceptionType();
|
||
946 | type.setDriverName(getDriver().getName()); |
||
947 | throw new DriverException(e, type); |
||
948 | 10234 | caballero | |
949 | |||
950 | 5223 | fjp | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
951 | 10234 | caballero | |
952 | 5223 | fjp | throw new DriverException(e); |
953 | } |
||
954 | return feat;
|
||
955 | } |
||
956 | |||
957 | public void stopEdition(IWriter writer, int sourceType) |
||
958 | throws EditionException {
|
||
959 | 11468 | caballero | // ISpatialWriter spatialWriter = (ISpatialWriter) writer;
|
960 | 6714 | caballero | // spatialWriter.setFlatness(FConverter.flatness);
|
961 | 5184 | caballero | super.stopEdition(writer, sourceType);
|
962 | 12734 | caballero | // try {
|
963 | // ova.getDriver().reload();
|
||
964 | // } catch (IOException e) {
|
||
965 | // e.printStackTrace();
|
||
966 | // throw new EditionException(e);
|
||
967 | // } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
968 | // e.printStackTrace();
|
||
969 | // throw new EditionException(e);
|
||
970 | // }
|
||
971 | 11468 | caballero | index=null;
|
972 | writer=null;
|
||
973 | 3952 | fjp | } |
974 | 5223 | fjp | |
975 | 3980 | caballero | public Rectangle2D getShapeBounds(int index) throws IOException { |
976 | 5223 | fjp | // Solo se utiliza cuando el driver es BoundedShapes
|
977 | // Si no est? en el fichero de expansi?n
|
||
978 | 3980 | caballero | Integer integer = new Integer((int) index); |
979 | if (!relations.containsKey(integer)) {
|
||
980 | 5223 | fjp | if (ova.getDriver() instanceof BoundedShapes) { |
981 | 3980 | caballero | BoundedShapes bs = (BoundedShapes) ova.getDriver(); |
982 | return bs.getShapeBounds(index);
|
||
983 | 5223 | fjp | } else {
|
984 | 3980 | caballero | return ova.getDriver().getShape(index).getBounds2D();
|
985 | } |
||
986 | |||
987 | } else {
|
||
988 | int num = ((Integer) relations.get(integer)).intValue(); |
||
989 | DefaultRowEdited feat; |
||
990 | feat = (DefaultRowEdited) expansionFile.getRow(num); |
||
991 | if (feat.getStatus() == IRowEdited.STATUS_DELETED)
|
||
992 | return null; |
||
993 | 5223 | fjp | IGeometry geom = ((IFeature) feat.getLinkedRow()).getGeometry(); |
994 | return geom.getBounds2D();// getGeometry(); |
||
995 | 3980 | caballero | } |
996 | |||
997 | } |
||
998 | 5223 | fjp | |
999 | 3980 | caballero | public int getShapeType(int index) { |
1000 | try {
|
||
1001 | return ova.getShapeType();
|
||
1002 | } catch (DriverIOException e) {
|
||
1003 | // TODO Auto-generated catch block
|
||
1004 | e.printStackTrace(); |
||
1005 | } |
||
1006 | return FShape.MULTI;
|
||
1007 | } |
||
1008 | 5223 | fjp | |
1009 | 4115 | fjp | /**
|
1010 | 5223 | fjp | * Usar solo cuando est?s seguro de que puedes gastar memoria. Nosotros lo
|
1011 | * usamos para las b?squedas por ?ndice espacial con el handle. La idea es
|
||
1012 | * usarlo una vez, guardar las geometr?as que necesitas en ese extent y
|
||
1013 | * trabajar con ellas hasta el siguiente cambio de extent.
|
||
1014 | 5389 | caballero | *
|
1015 | 4115 | fjp | * @param r
|
1016 | * @param strEPSG
|
||
1017 | * @return
|
||
1018 | * @throws DriverException
|
||
1019 | */
|
||
1020 | 5223 | fjp | public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) |
1021 | throws DriverException {
|
||
1022 | 4115 | fjp | // En esta clase suponemos random access.
|
1023 | // Luego tendremos otra clase que sea VectorialEditableDBAdapter
|
||
1024 | // que reescribir? este m?todo.
|
||
1025 | 5223 | fjp | Envelope e = FConverter.convertRectangle2DtoEnvelope(r); |
1026 | List l = index.query(e);
|
||
1027 | IRowEdited[] feats = new IRowEdited[l.size()]; |
||
1028 | try {
|
||
1029 | for (int index = 0; index < l.size(); index++) { |
||
1030 | Integer i = (Integer) l.get(index); |
||
1031 | int inverse = getInversedIndex(i.intValue());
|
||
1032 | 4181 | fjp | feats[index] = (IRowEdited) getRow(inverse); |
1033 | 5223 | fjp | } |
1034 | 8765 | jjdelcerro | } catch (IOException ex) { |
1035 | DriverIOExceptionType type = |
||
1036 | new DriverIOExceptionType();
|
||
1037 | type.setDriverName(this.getDriver().getName());
|
||
1038 | throw new DriverException(ex, type); |
||
1039 | 10234 | caballero | |
1040 | 8765 | jjdelcerro | } catch (DriverLoadException ex) {
|
1041 | DriverNotLoadedExceptionType type = |
||
1042 | new DriverNotLoadedExceptionType();
|
||
1043 | type.setDriverName(getDriver().getName()); |
||
1044 | throw new DriverException(ex, type); |
||
1045 | } catch (DriverIOException ex) {
|
||
1046 | DriverIOExceptionType type = |
||
1047 | new DriverIOExceptionType();
|
||
1048 | type.setDriverName(this.getDriver().getName());
|
||
1049 | throw new DriverException(ex, type); |
||
1050 | 10234 | caballero | } |
1051 | 4115 | fjp | return feats;
|
1052 | 4085 | fjp | } |
1053 | 5223 | fjp | |
1054 | 4523 | caballero | public void setSpatialIndex(SpatialIndex spatialIndex) { |
1055 | 5223 | fjp | index = (Quadtree) spatialIndex; |
1056 | 4523 | caballero | } |
1057 | 5223 | fjp | |
1058 | 4523 | caballero | public void setFullExtent(Rectangle2D fullExtent2) { |
1059 | 5223 | fjp | fullExtent = fullExtent2; |
1060 | 4523 | caballero | } |
1061 | 5223 | fjp | |
1062 | 4727 | fjp | /**
|
1063 | * DOCUMENT ME!
|
||
1064 | 5389 | caballero | *
|
1065 | 4727 | fjp | * @return DOCUMENT ME!
|
1066 | */
|
||
1067 | public Image getSelectionImage() { |
||
1068 | 5223 | fjp | return selectionImage;
|
1069 | 4727 | fjp | } |
1070 | 5223 | fjp | |
1071 | 4727 | fjp | public Image getHandlersImage() { |
1072 | return handlersImage;
|
||
1073 | } |
||
1074 | 5223 | fjp | |
1075 | 4792 | fjp | /**
|
1076 | * DOCUMENT ME!
|
||
1077 | 5389 | caballero | *
|
1078 | 5223 | fjp | * @param i
|
1079 | * DOCUMENT ME!
|
||
1080 | 4792 | fjp | */
|
1081 | public void setSelectionImage(Image i) { |
||
1082 | 5223 | fjp | selectionImage = i; |
1083 | 4792 | fjp | } |
1084 | 5223 | fjp | |
1085 | 4792 | fjp | public void setHandlersImage(BufferedImage handlersImage) { |
1086 | 5223 | fjp | this.handlersImage = handlersImage;
|
1087 | 4792 | fjp | } |
1088 | 5389 | caballero | |
1089 | 11468 | caballero | public void cancelEdition(int sourceType) throws IOException { |
1090 | super.cancelEdition(sourceType);
|
||
1091 | index=null;
|
||
1092 | setWriter(null);
|
||
1093 | System.gc();
|
||
1094 | } |
||
1095 | |||
1096 | 6714 | caballero | // public double getFlatness() {
|
1097 | // return flatness;
|
||
1098 | // }
|
||
1099 | //
|
||
1100 | // public void setFlatness(double d) {
|
||
1101 | // flatness=d;
|
||
1102 | // }
|
||
1103 | 5389 | caballero | |
1104 | 3612 | fjp | } |