Revision 1635
branches/pilotoDWG/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/DefaultEditableFeatureSource.java | ||
---|---|---|
1 | 1 |
package com.iver.cit.gvsig.fmap.edition; |
2 | 2 |
|
3 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
4 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
5 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
6 |
|
|
7 |
import com.vividsolutions.jts.geom.Envelope; |
|
8 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
|
9 |
|
|
3 | 10 |
import java.awt.Image; |
4 | 11 |
import java.awt.geom.Rectangle2D; |
12 |
|
|
5 | 13 |
import java.io.IOException; |
14 |
|
|
6 | 15 |
import java.util.BitSet; |
7 | 16 |
import java.util.HashMap; |
8 | 17 |
import java.util.List; |
9 | 18 |
|
10 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
11 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
|
12 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
|
13 |
import com.vividsolutions.jts.geom.Envelope; |
|
14 |
import com.vividsolutions.jts.index.quadtree.Quadtree; |
|
15 | 19 |
|
16 |
|
|
17 | 20 |
/** |
18 | 21 |
* DOCUMENT ME! |
19 | 22 |
* |
... | ... | |
29 | 32 |
private Image selectionImage; |
30 | 33 |
private CommandRecord cr; |
31 | 34 |
private FBitSet fbitset; |
32 |
private boolean complex=false; |
|
33 |
private CommandCollection commands=null; |
|
35 |
private boolean complex = false; |
|
36 |
private CommandCollection commands = null; |
|
37 |
|
|
34 | 38 |
/** |
35 | 39 |
* Crea un nuevo AbstractEditableFeatureSource. |
36 | 40 |
* |
37 | 41 |
* @param ef DOCUMENT ME! |
38 | 42 |
* @param ofa DOCUMENT ME! |
43 |
* @param bitset DOCUMENT ME! |
|
39 | 44 |
*/ |
40 | 45 |
public DefaultEditableFeatureSource(ExpansionFile ef, |
41 |
OriginalFeatureAdapter ofa,FBitSet bitset) { |
|
46 |
OriginalFeatureAdapter ofa, FBitSet bitset) {
|
|
42 | 47 |
expansionFile = ef; |
43 | 48 |
this.ofa = ofa; |
44 |
this.cr= new MemoryCommandRecord(); |
|
45 |
fbitset=bitset;
|
|
49 |
this.cr = new MemoryCommandRecord();
|
|
50 |
fbitset = bitset;
|
|
46 | 51 |
} |
47 | 52 |
|
48 | 53 |
/** |
... | ... | |
51 | 56 |
* protocolos en los que sea necesario, ... |
52 | 57 |
* |
53 | 58 |
* @throws EditionException |
54 |
* @throws IOException |
|
55 |
* @throws DriverIOException |
|
56 | 59 |
*/ |
57 | 60 |
public void startEdition() throws EditionException { |
58 | 61 |
ofa.startEdition(); |
59 | 62 |
index = new Quadtree(); |
60 | 63 |
|
61 |
try { |
|
62 |
for (int i = 0; i < getGeometryCount(); i++) { |
|
63 |
IGeometry g = getGeometry(i); |
|
64 |
if (g == null) continue; |
|
65 |
Rectangle2D r = g.getBounds2D(); |
|
66 |
Envelope e = new Envelope(r.getX(), r.getX() + r.getWidth(), |
|
67 |
r.getY(), r.getY() + r.getHeight()); |
|
68 |
index.insert(e, new Integer(i)); |
|
64 |
try { |
|
65 |
for (int i = 0; i < getGeometryCount(); i++) { |
|
66 |
IGeometry g = getGeometry(i); |
|
67 |
|
|
68 |
if (g == null) { |
|
69 |
continue; |
|
69 | 70 |
} |
70 |
} catch (DriverIOException e) { |
|
71 |
throw new EditionException(e); |
|
72 |
} catch (IOException e) { |
|
73 |
throw new EditionException(e); |
|
71 |
|
|
72 |
Rectangle2D r = g.getBounds2D(); |
|
73 |
Envelope e = new Envelope(r.getX(), r.getX() + r.getWidth(), |
|
74 |
r.getY(), r.getY() + r.getHeight()); |
|
75 |
index.insert(e, new Integer(i)); |
|
74 | 76 |
} |
77 |
} catch (DriverIOException e) { |
|
78 |
throw new EditionException(e); |
|
79 |
} catch (IOException e) { |
|
80 |
throw new EditionException(e); |
|
81 |
} |
|
82 |
|
|
75 | 83 |
System.err.println("Se han metido en el ?ndice " + |
76 | 84 |
index.queryAll().size() + " geometr?as"); |
77 | 85 |
} |
... | ... | |
138 | 146 |
* @throws IOException |
139 | 147 |
*/ |
140 | 148 |
public void addGeometry(IGeometry g) throws DriverIOException, IOException { |
141 |
int virtualIndex=doAddGeometry(g); |
|
142 |
if (complex){ |
|
143 |
commands.add(new AddGeometryCommand(this,g,virtualIndex)); |
|
144 |
}else{ |
|
145 |
cr.pushCommand(new AddGeometryCommand(this,g,virtualIndex)); |
|
149 |
int virtualIndex = doAddGeometry(g); |
|
150 |
|
|
151 |
if (complex) { |
|
152 |
commands.add(new AddGeometryCommand(this, g, virtualIndex)); |
|
153 |
} else { |
|
154 |
cr.pushCommand(new AddGeometryCommand(this, g, virtualIndex)); |
|
146 | 155 |
} |
147 | 156 |
} |
148 | 157 |
|
... | ... | |
158 | 167 |
* @throws IOException |
159 | 168 |
*/ |
160 | 169 |
public void removeGeometry(int index) throws DriverIOException, IOException { |
161 |
if (complex){ |
|
162 |
commands.add(new RemoveGeometryCommand(this,index)); |
|
163 |
}else{
|
|
164 |
cr.pushCommand(new RemoveGeometryCommand(this,index)); |
|
170 |
if (complex) {
|
|
171 |
commands.add(new RemoveGeometryCommand(this, index));
|
|
172 |
} else {
|
|
173 |
cr.pushCommand(new RemoveGeometryCommand(this, index));
|
|
165 | 174 |
} |
175 |
|
|
166 | 176 |
doRemoveGeometry(index); |
167 | 177 |
} |
168 | 178 |
|
... | ... | |
182 | 192 |
*/ |
183 | 193 |
public void modifyGeometry(int index, IGeometry g) |
184 | 194 |
throws IOException, DriverIOException { |
185 |
int pos=doModifyGeometry(index,g); |
|
186 |
if (complex){ |
|
187 |
commands.add(new ModifyGeometryCommand(this,index,pos,g)); |
|
188 |
}else{ |
|
189 |
cr.pushCommand(new ModifyGeometryCommand(this,index,pos,g)); |
|
195 |
int pos = doModifyGeometry(index, g); |
|
196 |
|
|
197 |
if (complex) { |
|
198 |
commands.add(new ModifyGeometryCommand(this, index, pos, g)); |
|
199 |
} else { |
|
200 |
cr.pushCommand(new ModifyGeometryCommand(this, index, pos, g)); |
|
190 | 201 |
} |
191 | 202 |
} |
192 | 203 |
|
... | ... | |
243 | 254 |
* la relaci?n del mapa de relaciones |
244 | 255 |
* |
245 | 256 |
* @param index ?ndice de la geometr?a que se a?adi? |
257 |
* |
|
258 |
* @throws DriverIOException |
|
246 | 259 |
* @throws IOException |
247 |
* @throws DriverIOException |
|
248 | 260 |
*/ |
249 |
public void undoAddGeometry(int index) throws DriverIOException, IOException { |
|
261 |
public void undoAddGeometry(int index) |
|
262 |
throws DriverIOException, IOException { |
|
250 | 263 |
//doRemoveGeometry(index); |
251 |
IGeometry g=getGeometry(index);
|
|
252 |
Rectangle2D r=g.getBounds2D();
|
|
264 |
IGeometry g = getGeometry(index);
|
|
265 |
Rectangle2D r = g.getBounds2D();
|
|
253 | 266 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
254 | 267 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
255 |
|
|
256 |
expansionFile.deleteLastGeometry(); |
|
257 |
relations.remove(new Integer(index)); |
|
258 |
numAdd--; |
|
259 |
|
|
268 |
|
|
269 |
expansionFile.deleteLastGeometry(); |
|
270 |
relations.remove(new Integer(index)); |
|
271 |
numAdd--; |
|
260 | 272 |
} |
261 | 273 |
|
262 | 274 |
/** |
... | ... | |
264 | 276 |
* en el fichero original |
265 | 277 |
* |
266 | 278 |
* @param index DOCUMENT ME! |
279 |
* |
|
280 |
* @throws IOException |
|
267 | 281 |
* @throws DriverIOException |
268 |
* @throws IOException |
|
269 | 282 |
*/ |
270 |
public void undoRemoveGeometry(int index) throws IOException, DriverIOException { |
|
271 |
if (relations.containsKey(new Integer(index))){ |
|
272 |
expansionFile.validateGeometry(((Integer)relations.get(new Integer(index))).intValue()); |
|
273 |
}else{ |
|
274 |
delgeometries.set(index,false); |
|
283 |
public void undoRemoveGeometry(int index) |
|
284 |
throws IOException, DriverIOException { |
|
285 |
if (relations.containsKey(new Integer(index))) { |
|
286 |
expansionFile.validateGeometry(((Integer) relations.get( |
|
287 |
new Integer(index))).intValue()); |
|
288 |
} else { |
|
289 |
delgeometries.set(index, false); |
|
275 | 290 |
} |
276 |
IGeometry g=null; |
|
277 |
g = getGeometry(index); |
|
291 |
|
|
292 |
IGeometry g = null; |
|
293 |
g = getGeometry(index); |
|
294 |
|
|
278 | 295 |
Rectangle2D r = g.getBounds2D(); |
279 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(), |
|
280 |
r.getY() + r.getHeight()), new Integer(index)); |
|
281 |
|
|
296 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
|
297 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
|
282 | 298 |
} |
283 | 299 |
|
284 | 300 |
/** |
... | ... | |
294 | 310 |
* el expansionFile. Si vale -1 quiere decir que es una |
295 | 311 |
* modificaci?n de una geometr?a original y por tanto no hay que |
296 | 312 |
* actualizar el mapa de indices sino eliminar su entrada. |
313 |
* |
|
314 |
* @throws IOException |
|
297 | 315 |
* @throws DriverIOException |
298 |
* @throws IOException |
|
299 | 316 |
*/ |
300 | 317 |
public void undoModifyGeometry(int geometryIndex, |
301 | 318 |
int previousExpansionFileIndex) throws IOException, DriverIOException { |
302 |
if (previousExpansionFileIndex==-1){
|
|
319 |
if (previousExpansionFileIndex == -1) {
|
|
303 | 320 |
//eliminar geometr?a del expansion file. |
304 | 321 |
//expansionFile.invalidateGeometry(geometryIndex); |
305 |
IGeometry g= getGeometry(geometryIndex); |
|
306 |
Rectangle2D r=g.getBounds2D();
|
|
322 |
IGeometry g = getGeometry(geometryIndex);
|
|
323 |
Rectangle2D r = g.getBounds2D();
|
|
307 | 324 |
relations.remove(new Integer(geometryIndex)); |
308 |
|
|
309 |
IGeometry gAnt= getGeometry(geometryIndex); |
|
310 |
Rectangle2D rAnt=gAnt.getBounds2D();
|
|
325 |
|
|
326 |
IGeometry gAnt = getGeometry(geometryIndex);
|
|
327 |
Rectangle2D rAnt = gAnt.getBounds2D();
|
|
311 | 328 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
312 |
r.getY(), r.getY() + r.getHeight()), new Integer(geometryIndex)); |
|
313 |
this.index.insert(new Envelope(rAnt.getX(), rAnt.getX() + rAnt.getWidth(), |
|
314 |
rAnt.getY(), rAnt.getY() + rAnt.getHeight()), new Integer(geometryIndex)); |
|
315 |
expansionFile.deleteLastGeometry(); |
|
316 |
|
|
317 |
numAdd--; |
|
318 |
}else{ |
|
319 |
IGeometry g=null; |
|
320 |
g = getGeometry(geometryIndex); |
|
321 |
Rectangle2D r=g.getBounds2D(); |
|
329 |
r.getY(), r.getY() + r.getHeight()), |
|
330 |
new Integer(geometryIndex)); |
|
331 |
this.index.insert(new Envelope(rAnt.getX(), |
|
332 |
rAnt.getX() + rAnt.getWidth(), rAnt.getY(), |
|
333 |
rAnt.getY() + rAnt.getHeight()), new Integer(geometryIndex)); |
|
334 |
expansionFile.deleteLastGeometry(); |
|
335 |
|
|
336 |
numAdd--; |
|
337 |
} else { |
|
338 |
IGeometry g = null; |
|
339 |
g = getGeometry(geometryIndex); |
|
340 |
|
|
341 |
Rectangle2D r = g.getBounds2D(); |
|
322 | 342 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
323 |
r.getY(), r.getY() + r.getHeight()), new Integer(geometryIndex)); |
|
324 |
|
|
325 |
Integer integer=new Integer(geometryIndex); |
|
326 |
relations.put(new Integer(geometryIndex),new Integer(previousExpansionFileIndex)); |
|
343 |
r.getY(), r.getY() + r.getHeight()), |
|
344 |
new Integer(geometryIndex)); |
|
345 |
|
|
346 |
Integer integer = new Integer(geometryIndex); |
|
347 |
relations.put(new Integer(geometryIndex), |
|
348 |
new Integer(previousExpansionFileIndex)); |
|
327 | 349 |
expansionFile.validateGeometry(previousExpansionFileIndex); |
328 |
g = getGeometry(geometryIndex);
|
|
329 |
r=g.getBounds2D();
|
|
350 |
g = getGeometry(geometryIndex); |
|
351 |
r = g.getBounds2D();
|
|
330 | 352 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
331 |
r.getY(), r.getY() + r.getHeight()), new Integer(geometryIndex));
|
|
332 |
|
|
353 |
r.getY(), r.getY() + r.getHeight()), |
|
354 |
new Integer(geometryIndex)); |
|
333 | 355 |
} |
334 |
|
|
335 | 356 |
} |
336 | 357 |
|
337 | 358 |
/** |
... | ... | |
340 | 361 |
* |
341 | 362 |
* @param g geometr?a a guardar. |
342 | 363 |
* |
364 |
* @return DOCUMENT ME! |
|
365 |
* |
|
343 | 366 |
* @throws DriverIOException |
344 | 367 |
* @throws IOException |
345 | 368 |
*/ |
... | ... | |
368 | 391 |
* @throws DriverIOException |
369 | 392 |
* @throws IOException |
370 | 393 |
*/ |
371 |
public void doRemoveGeometry(int index) throws DriverIOException, IOException { |
|
394 |
public void doRemoveGeometry(int index) |
|
395 |
throws DriverIOException, IOException { |
|
372 | 396 |
Integer integer = new Integer(index); |
373 | 397 |
|
374 | 398 |
IGeometry g = null; |
... | ... | |
381 | 405 |
g = expansionFile.getGeometry(num); |
382 | 406 |
expansionFile.invalidateGeometry(num); |
383 | 407 |
} |
384 |
if (g != null){ |
|
385 |
Rectangle2D r = g.getBounds2D(); |
|
386 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
|
387 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
|
388 |
} |
|
408 |
|
|
409 |
if (g != null) { |
|
410 |
Rectangle2D r = g.getBounds2D(); |
|
411 |
this.index.remove(new Envelope(r.getX(), r.getX() + r.getWidth(), |
|
412 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
|
413 |
} |
|
414 |
|
|
389 | 415 |
// System.err.println(this.index.size()); |
390 |
|
|
391 | 416 |
} |
392 | 417 |
|
393 | 418 |
/** |
... | ... | |
401 | 426 |
* @param index DOCUMENT ME! |
402 | 427 |
* @param g DOCUMENT ME! |
403 | 428 |
* |
429 |
* @return DOCUMENT ME! |
|
430 |
* |
|
404 | 431 |
* @throws IOException |
405 | 432 |
* @throws DriverIOException |
406 | 433 |
*/ |
407 | 434 |
public int doModifyGeometry(int index, IGeometry g) |
408 | 435 |
throws IOException, DriverIOException { |
409 |
int pos=-1;
|
|
436 |
int pos = -1;
|
|
410 | 437 |
Integer integer = new Integer(index); |
411 | 438 |
|
412 | 439 |
IGeometry gAnt = null; |
... | ... | |
425 | 452 |
rAnt.getY() + rAnt.getHeight()), new Integer(index)); |
426 | 453 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
427 | 454 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
455 |
|
|
428 | 456 |
//pos=expansionIndex; |
429 | 457 |
} else { |
430 | 458 |
int num = ((Integer) relations.get(integer)).intValue(); |
431 |
pos=num;
|
|
459 |
pos = num;
|
|
432 | 460 |
gAnt = expansionFile.getGeometry(num); |
433 | 461 |
num = expansionFile.modifyGeometry(num, g); |
434 | 462 |
relations.put(integer, new Integer(num)); |
... | ... | |
441 | 469 |
rAnt.getY() + rAnt.getHeight()), new Integer(index)); |
442 | 470 |
this.index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), |
443 | 471 |
r.getY(), r.getY() + r.getHeight()), new Integer(index)); |
444 |
|
|
445 | 472 |
} |
446 | 473 |
|
447 | 474 |
// System.err.println(this.index.size()); |
... | ... | |
449 | 476 |
} |
450 | 477 |
|
451 | 478 |
/** |
452 |
* @throws IOException |
|
479 |
* DOCUMENT ME! |
|
480 |
* |
|
453 | 481 |
* @throws DriverIOException |
454 | 482 |
* @throws IOException |
455 |
* @throws DriverIOException
|
|
483 |
* |
|
456 | 484 |
* @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#undo() |
457 | 485 |
*/ |
458 |
public void undo() throws DriverIOException, IOException{ |
|
486 |
public void undo() throws DriverIOException, IOException {
|
|
459 | 487 |
fbitset.clear(); |
460 |
if (moreUndoCommands()) |
|
461 |
cr.undoCommand(); |
|
488 |
|
|
489 |
if (moreUndoCommands()) { |
|
490 |
cr.undoCommand(); |
|
491 |
} |
|
462 | 492 |
} |
493 |
|
|
463 | 494 |
/** |
464 |
* @throws IOException |
|
495 |
* DOCUMENT ME! |
|
496 |
* |
|
465 | 497 |
* @throws DriverIOException |
466 | 498 |
* @throws IOException |
467 |
* @throws DriverIOException
|
|
499 |
* |
|
468 | 500 |
* @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#redo() |
469 | 501 |
*/ |
470 |
public void redo() throws DriverIOException, IOException{ |
|
502 |
public void redo() throws DriverIOException, IOException {
|
|
471 | 503 |
fbitset.clear(); |
472 |
if (moreRedoCommands()) |
|
473 |
cr.redoCommand(); |
|
504 |
|
|
505 |
if (moreRedoCommands()) { |
|
506 |
cr.redoCommand(); |
|
507 |
} |
|
474 | 508 |
} |
475 |
|
|
476 | 509 |
|
477 | 510 |
/** |
478 | 511 |
* @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#moreUndoCommands() |
... | ... | |
492 | 525 |
* @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#startComplexGeometry() |
493 | 526 |
*/ |
494 | 527 |
public void startComplexGeometry() { |
495 |
complex=true;
|
|
496 |
commands=new CommandCollection();
|
|
528 |
complex = true;
|
|
529 |
commands = new CommandCollection();
|
|
497 | 530 |
} |
498 | 531 |
|
499 | 532 |
/** |
533 |
* DOCUMENT ME! |
|
534 |
* |
|
535 |
* @throws IOException |
|
500 | 536 |
* @throws DriverIOException |
501 |
* @throws IOException
|
|
537 |
* |
|
502 | 538 |
* @see com.iver.cit.gvsig.fmap.edition.EditableFeatureSource#endComplexGeometry() |
503 | 539 |
*/ |
504 | 540 |
public void endComplexGeometry() throws IOException, DriverIOException { |
505 | 541 |
cr.pushCommand(commands); |
506 |
complex=false;
|
|
542 |
complex = false;
|
|
507 | 543 |
} |
508 |
|
|
509 | 544 |
} |
Also available in: Unified diff