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