Revision 1821 branches/FMap_piloto_CAD_Layout_version/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/DefaultEditableFeatureSource.java
DefaultEditableFeatureSource.java | ||
---|---|---|
23 | 23 |
* @author Vicente Caballero Navarro |
24 | 24 |
*/ |
25 | 25 |
public class DefaultEditableFeatureSource implements EditableFeatureSource { |
26 |
/*
|
|
26 |
/* |
|
27 | 27 |
* Fichero en el que se guardan las nuevas geometr?as, producto de adiciones |
28 | 28 |
* o de modificaciones |
29 | 29 |
*/ |
30 | 30 |
private ExpansionFile expansionFile; |
31 |
|
|
31 | 32 |
/* |
32 | 33 |
* Fuente de datos original que se est? editando |
33 | 34 |
*/ |
34 | 35 |
private OriginalFeatureAdapter ofa; |
36 |
|
|
35 | 37 |
/* |
36 | 38 |
* Geometr?as modificadas de la fuente de datos original |
37 | 39 |
*/ |
38 | 40 |
private BitSet delgeometries = new BitSet(); |
41 |
|
|
39 | 42 |
/* |
40 | 43 |
* Establece una relaci?n entre los ?ndices de las geometr?as en el EditableFeatureSource |
41 | 44 |
* y los ?ndices en el fichero de expansi?n |
42 | 45 |
*/ |
43 |
private HashMap relations = new HashMap();
|
|
46 |
protected HashMap relations = new HashMap();
|
|
44 | 47 |
private int numAdd = 0; |
48 |
|
|
45 | 49 |
// ?ndice espacial |
46 | 50 |
private Quadtree index; |
47 | 51 |
private Image selectionImage; |
48 | 52 |
protected CommandRecord cr; |
49 |
private FBitSet seleccion; |
|
50 |
/** Flag que indica que hay que tomar las siguientes operaciones como una operaci?n at?mica **/ |
|
53 |
protected FBitSet seleccion; |
|
54 |
|
|
55 |
/** |
|
56 |
* Flag que indica que hay que tomar las siguientes operaciones como una |
|
57 |
* operaci?n at?mica |
|
58 |
*/ |
|
51 | 59 |
protected boolean complex = false; |
52 | 60 |
protected CommandCollection commands = null; |
53 | 61 |
|
... | ... | |
74 | 82 |
* @throws EditionException |
75 | 83 |
*/ |
76 | 84 |
public void startEdition() throws EditionException { |
77 |
if (ofa!=null){
|
|
78 |
ofa.startEdition(); |
|
85 |
if (ofa != null) {
|
|
86 |
ofa.startEdition();
|
|
79 | 87 |
} |
88 |
|
|
80 | 89 |
try { |
81 | 90 |
expansionFile.open(); |
82 | 91 |
index = new Quadtree(); |
... | ... | |
138 | 147 |
* @throws DriverIOException |
139 | 148 |
*/ |
140 | 149 |
public int getGeometryCount() throws DriverIOException { |
141 |
if (ofa!=null) |
|
142 |
return ofa.getGeometryCount() + numAdd; //expansionFile.getGeometryCount() - relations.size(); |
|
150 |
if (ofa != null) { |
|
151 |
return ofa.getGeometryCount() + numAdd; //expansionFile.getGeometryCount() - relations.size(); |
|
152 |
} |
|
153 |
|
|
143 | 154 |
return numAdd; |
144 | 155 |
} |
145 | 156 |
|
... | ... | |
185 | 196 |
* @throws IOException |
186 | 197 |
*/ |
187 | 198 |
public void addGeometry(IGeometry g) throws DriverIOException, IOException { |
188 |
int virtualIndex = doAddGeometry(g); |
|
199 |
int[] virtualIndex = doAddGeometry(g);
|
|
189 | 200 |
|
190 | 201 |
if (complex) { |
191 |
commands.add(new AddGeometryCommand(this, g, virtualIndex)); |
|
202 |
commands.add(new AddGeometryCommand(this, g, virtualIndex[1]));
|
|
192 | 203 |
} else { |
193 |
cr.pushCommand(new AddGeometryCommand(this, g, virtualIndex)); |
|
204 |
cr.pushCommand(new AddGeometryCommand(this, g, virtualIndex[1]));
|
|
194 | 205 |
} |
195 | 206 |
} |
196 | 207 |
|
... | ... | |
231 | 242 |
*/ |
232 | 243 |
public void modifyGeometry(int index, IGeometry g) |
233 | 244 |
throws IOException, DriverIOException { |
234 |
int pos = doModifyGeometry(index, g); |
|
245 |
int[] pos = doModifyGeometry(index, g);
|
|
235 | 246 |
|
236 | 247 |
if (complex) { |
237 |
commands.add(new ModifyGeometryCommand(this, index, pos, g)); |
|
248 |
commands.add(new ModifyGeometryCommand(this, index, pos[0], g));
|
|
238 | 249 |
} else { |
239 |
cr.pushCommand(new ModifyGeometryCommand(this, index, pos, g)); |
|
250 |
cr.pushCommand(new ModifyGeometryCommand(this, index, pos[0], g));
|
|
240 | 251 |
} |
241 | 252 |
} |
242 | 253 |
|
... | ... | |
356 | 367 |
*/ |
357 | 368 |
public void undoModifyGeometry(int geometryIndex, |
358 | 369 |
int previousExpansionFileIndex) throws IOException, DriverIOException { |
359 |
/*
|
|
370 |
/* |
|
360 | 371 |
* Si la acci?n de modificar se realiz? sobre una geometr?a original |
361 | 372 |
*/ |
362 | 373 |
if (previousExpansionFileIndex == -1) { |
363 | 374 |
//Se obtiene la geometr?a para actualizar el ?ndice |
364 | 375 |
IGeometry g = getGeometry(geometryIndex); |
365 | 376 |
Rectangle2D r = g.getBounds2D(); |
377 |
|
|
366 | 378 |
//Se elimina de las relaciones y del fichero de expansi?n |
367 | 379 |
relations.remove(new Integer(geometryIndex)); |
368 | 380 |
expansionFile.deleteLastGeometry(); |
... | ... | |
377 | 389 |
rAnt.getX() + rAnt.getWidth(), rAnt.getY(), |
378 | 390 |
rAnt.getY() + rAnt.getHeight()), new Integer(geometryIndex)); |
379 | 391 |
} else { |
380 |
|
|
381 | 392 |
//Se obtiene la geometr?a para actualizar el ?ndice |
382 | 393 |
IGeometry g = null; |
383 | 394 |
g = getGeometry(geometryIndex); |
... | ... | |
394 | 405 |
|
395 | 406 |
//Se recupera la geometr?a |
396 | 407 |
expansionFile.validateGeometry(previousExpansionFileIndex); |
397 |
|
|
408 |
|
|
398 | 409 |
//Se actualizan los ?ndices |
399 | 410 |
g = getGeometry(geometryIndex); |
400 | 411 |
r = g.getBounds2D(); |
... | ... | |
415 | 426 |
* @throws DriverIOException |
416 | 427 |
* @throws IOException |
417 | 428 |
*/ |
418 |
public int doAddGeometry(IGeometry g) throws DriverIOException, IOException { |
|
419 |
int virtualIndex=0; |
|
429 |
public int[] doAddGeometry(IGeometry g) throws DriverIOException, IOException { |
|
430 |
int virtualIndex = 0; |
|
431 |
|
|
420 | 432 |
//A?ade la geometr?a |
421 |
if (ofa!=null){
|
|
433 |
if (ofa != null) {
|
|
422 | 434 |
virtualIndex = ofa.getGeometryCount() + numAdd; |
423 |
}else{
|
|
435 |
} else {
|
|
424 | 436 |
virtualIndex = numAdd; |
425 | 437 |
} |
438 |
|
|
426 | 439 |
int pos = expansionFile.addGeometry(g); |
427 | 440 |
relations.put(new Integer(virtualIndex), new Integer(pos)); |
428 | 441 |
numAdd++; |
... | ... | |
432 | 445 |
index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(), |
433 | 446 |
r.getY() + r.getHeight()), new Integer(virtualIndex)); |
434 | 447 |
|
435 |
return virtualIndex;
|
|
448 |
return new int[]{pos,virtualIndex};
|
|
436 | 449 |
} |
437 | 450 |
|
438 | 451 |
/** |
... | ... | |
481 | 494 |
* @param index DOCUMENT ME! |
482 | 495 |
* @param g DOCUMENT ME! |
483 | 496 |
* |
484 |
* @return DOCUMENT ME! |
|
497 |
* @return vector de enteros en la posici?n 0= la posici?n anterior de la |
|
498 |
* geometr?a y en la posici?n 1= la posici?n actual de la |
|
499 |
* geometr?a |
|
485 | 500 |
* |
486 | 501 |
* @throws IOException |
487 | 502 |
* @throws DriverIOException |
488 | 503 |
*/ |
489 |
public int doModifyGeometry(int index, IGeometry g) |
|
504 |
public int[] doModifyGeometry(int index, IGeometry g)
|
|
490 | 505 |
throws IOException, DriverIOException { |
506 |
int num = -1; |
|
491 | 507 |
int pos = -1; |
492 | 508 |
Integer integer = new Integer(index); |
493 | 509 |
|
... | ... | |
510 | 526 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
511 | 527 |
} else { |
512 | 528 |
//Obtenemos el ?ndice en el fichero de expansi?n |
513 |
int num = ((Integer) relations.get(integer)).intValue();
|
|
529 |
num = ((Integer) relations.get(integer)).intValue(); |
|
514 | 530 |
pos = num; |
531 |
|
|
515 | 532 |
//Obtenemos la geometr?a para actualiza el ?ndice espacialposteriormente |
516 | 533 |
gAnt = expansionFile.getGeometry(num); |
534 |
|
|
517 | 535 |
/* |
518 | 536 |
* Se modifica la geometr?a y nos guardamos el ?ndice dentro del fichero |
519 | 537 |
* de expansi?n en el que se encuentra la geometr?a modificada |
520 | 538 |
*/ |
521 | 539 |
num = expansionFile.modifyGeometry(num, g); |
540 |
|
|
522 | 541 |
/* |
523 | 542 |
* Actualiza la relaci?n del ?ndice de la geometr?a al ?ndice en el fichero |
524 | 543 |
* de expansi?n. |
... | ... | |
535 | 554 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
536 | 555 |
} |
537 | 556 |
|
538 |
return pos;
|
|
557 |
return new int[]{pos,num};
|
|
539 | 558 |
} |
540 | 559 |
|
541 | 560 |
/** |
Also available in: Unified diff