Revision 39119 branches/v2_0_0_prep/extensions/extEditing/src/org/gvsig/editing/gui/cad/tools/EditVertexCADTool.java
EditVertexCADTool.java | ||
---|---|---|
26 | 26 |
import java.awt.geom.PathIterator; |
27 | 27 |
import java.awt.geom.Point2D; |
28 | 28 |
import java.awt.geom.Rectangle2D; |
29 |
import java.util.ArrayList; |
|
30 | 29 |
|
31 | 30 |
import javax.swing.JOptionPane; |
32 | 31 |
|
32 |
import org.slf4j.Logger; |
|
33 |
import org.slf4j.LoggerFactory; |
|
34 |
|
|
33 | 35 |
import org.gvsig.andami.PluginServices; |
34 | 36 |
import org.gvsig.andami.messages.NotificationManager; |
37 |
import org.gvsig.app.ApplicationLocator; |
|
35 | 38 |
import org.gvsig.editing.CADExtension; |
36 | 39 |
import org.gvsig.editing.gui.cad.DefaultCADTool; |
37 | 40 |
import org.gvsig.editing.gui.cad.exception.CommandException; |
... | ... | |
45 | 48 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
46 | 49 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
47 | 50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
51 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
|
48 | 52 |
import org.gvsig.fmap.geom.Geometry; |
49 | 53 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
50 | 54 |
import org.gvsig.fmap.geom.handler.Handler; |
55 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
56 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
51 | 57 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
58 |
import org.gvsig.fmap.geom.primitive.Primitive; |
|
52 | 59 |
import org.gvsig.fmap.mapcontext.ViewPort; |
53 | 60 |
import org.gvsig.fmap.mapcontrol.MapControlDrawer; |
54 | 61 |
import org.gvsig.tools.dispose.DisposableIterator; |
... | ... | |
65 | 72 |
protected int numSelect = 0; |
66 | 73 |
protected int numHandlers; |
67 | 74 |
protected boolean addVertex = false; |
75 |
|
|
76 |
private static Logger logger = |
|
77 |
LoggerFactory.getLogger(EditVertexCADTool.class); |
|
68 | 78 |
|
69 | 79 |
/** |
70 | 80 |
* M?todo de incio, para poner el c?digo de todo lo que se requiera de una |
... | ... | |
267 | 277 |
handlers[numSelect]); |
268 | 278 |
} else { |
269 | 279 |
newGeometry = |
270 |
removeVertex(ig, handlers, numSelect);
|
|
280 |
removeVertex(ig, handlers[numSelect]);
|
|
271 | 281 |
} |
272 | 282 |
try { |
273 | 283 |
EditableFeature eFeature = |
... | ... | |
293 | 303 |
addVertex = true; |
294 | 304 |
} |
295 | 305 |
} |
296 |
} catch (ReadException e1) { |
|
297 |
// TODO Auto-generated catch block |
|
298 |
e1.printStackTrace(); |
|
299 |
} catch (DataException e) { |
|
300 |
// TODO Auto-generated catch block |
|
301 |
e.printStackTrace(); |
|
306 |
} catch (Exception e1) { |
|
307 |
|
|
308 |
ApplicationLocator.getManager().message( |
|
309 |
e1.getMessage(), JOptionPane.ERROR_MESSAGE); |
|
310 |
logger.info("Error in add option.", e1); |
|
302 | 311 |
} finally { |
303 | 312 |
if (iterator != null) { |
304 | 313 |
iterator.dispose(); |
... | ... | |
347 | 356 |
public void addValue(double d) { |
348 | 357 |
} |
349 | 358 |
|
350 |
private Geometry removeVertex(Geometry gp, Handler[] handlers, |
|
351 |
int numHandler) { |
|
359 |
private Geometry removeVertex(Geometry gp, Handler hand) { |
|
352 | 360 |
GeneralPathX newGp = new GeneralPathX(); |
353 | 361 |
double[] theData = new double[6]; |
354 | 362 |
|
... | ... | |
375 | 383 |
case PathIterator.SEG_MOVETO: |
376 | 384 |
numParts++; |
377 | 385 |
ptSrc.setLocation(theData[0], theData[1]); |
378 |
if (ptSrc.equals(handlers[numHandler].getPoint())) {
|
|
386 |
if (ptSrc.equals(hand.getPoint())) { |
|
379 | 387 |
numParts--; |
380 | 388 |
bFirst = true; |
381 | 389 |
break; |
... | ... | |
387 | 395 |
|
388 | 396 |
case PathIterator.SEG_LINETO: |
389 | 397 |
ptSrc.setLocation(theData[0], theData[1]); |
390 |
if (ptSrc.equals(handlers[numHandler].getPoint())) {
|
|
398 |
if (ptSrc.equals(hand.getPoint())) { |
|
391 | 399 |
break; |
392 | 400 |
} |
393 | 401 |
newGp.lineTo(ptSrc.getX(), ptSrc.getY()); |
... | ... | |
439 | 447 |
return ig; |
440 | 448 |
} |
441 | 449 |
|
442 |
private Geometry removeVertexGC(MultiPrimitive gc, Handler handler) { |
|
443 |
|
|
444 |
// Geometry[] geoms = gc.getGeometries(); // getPrimitives es de la implemetacion, no esta en el API |
|
450 |
private Geometry removeVertexGC(MultiPrimitive gc, Handler handler) |
|
451 |
throws GeometryOperationNotSupportedException, |
|
452 |
GeometryOperationException, CreateGeometryException { |
|
453 |
|
|
454 |
Primitive prim = null; |
|
455 |
int np = gc.getPrimitivesNumber(); |
|
456 |
|
|
457 |
for (int i = 0; i < np; i++) { |
|
458 |
prim = gc.getPrimitiveAt(i); |
|
459 |
Handler[] hh = prim.getHandlers(Geometry.SELECTHANDLER); |
|
460 |
int nh = hh.length; |
|
461 |
for (int j=0; j<nh; j++) { |
|
462 |
if (hh[j].equalsPoint(handler)) { |
|
463 |
/* |
|
464 |
* Find the first primitive which has a handler |
|
465 |
* matching received handler |
|
466 |
*/ |
|
467 |
Geometry resp = this.removeVertex(prim, handler); |
|
468 |
for (int k=0; k<np; k++) { |
|
469 |
if (k != i) { |
|
470 |
resp = resp.union(gc.getPrimitiveAt(k)); |
|
471 |
} |
|
472 |
} |
|
473 |
return resp; |
|
474 |
} |
|
475 |
} |
|
476 |
} |
|
477 |
throw new CreateGeometryException( |
|
478 |
new Exception("Unable to remove vertex")); |
|
479 |
/* |
|
445 | 480 |
Geometry[] geoms = new Geometry[gc.getPrimitivesNumber()]; |
446 | 481 |
for( int i=0; i<gc.getPrimitivesNumber(); i++) { |
447 | 482 |
geoms[i] = gc.getPrimitiveAt(i); |
... | ... | |
493 | 528 |
|
494 | 529 |
return createMultiPrimitive((Geometry[]) newGeoms |
495 | 530 |
.toArray(new Geometry[0])); |
531 |
*/ |
|
496 | 532 |
} |
497 | 533 |
|
498 | 534 |
private Geometry addVertex(Geometry geome, Point2D p, Rectangle2D rect) { |
... | ... | |
577 | 613 |
geom1 = createCurve(gpxAux); |
578 | 614 |
if (geom1.intersects(rect) || finish) { |
579 | 615 |
newGp.lineTo(p.getX(), p.getY()); |
580 |
newGp.lineTo(pLast.getX(), pLast.getY()); |
|
616 |
// newGp.lineTo(pLast.getX(), pLast.getY());
|
|
581 | 617 |
} else { |
582 | 618 |
newGp.lineTo(pLast.getX(), pLast.getY()); |
583 | 619 |
} |
... | ... | |
606 | 642 |
return shp; |
607 | 643 |
} |
608 | 644 |
|
609 |
private Geometry addVertexGC(MultiPrimitive gc, Point2D p, |
|
610 |
Rectangle2D rect) { |
|
611 |
// Geometry[] geoms = gc.getGeometries(); // getPrimitives es de la implemetacion, no esta en el API |
|
645 |
private Geometry addVertexGC( |
|
646 |
MultiPrimitive mpri, |
|
647 |
Point2D p, |
|
648 |
Rectangle2D rect) |
|
649 |
throws GeometryOperationNotSupportedException, |
|
650 |
GeometryOperationException, CreateGeometryException |
|
651 |
{ |
|
652 |
|
|
653 |
int n = mpri.getPrimitivesNumber(); |
|
654 |
Primitive item = null; |
|
655 |
for (int i=0; i<n; i++) { |
|
656 |
item = mpri.getPrimitiveAt(i); |
|
657 |
if (item.intersects(rect)) { |
|
658 |
/* |
|
659 |
* Only the first primitive that intersects |
|
660 |
* with rect will be treated |
|
661 |
*/ |
|
662 |
Geometry newg = this.addVertex(item, p, rect); |
|
663 |
for (int k=0; k<n; k++) { |
|
664 |
if (k != i) { |
|
665 |
newg = newg.union(mpri.getPrimitiveAt(k)); |
|
666 |
} |
|
667 |
return newg; |
|
668 |
} |
|
669 |
} |
|
670 |
} |
|
671 |
throw new CreateGeometryException( |
|
672 |
new Exception("Unable to add vertex")); |
|
673 |
|
|
674 |
/* |
|
612 | 675 |
Geometry[] geoms = new Geometry[gc.getPrimitivesNumber()]; |
613 | 676 |
for( int i=0; i<gc.getPrimitivesNumber(); i++) { |
614 | 677 |
geoms[i] = gc.getPrimitiveAt(i); |
... | ... | |
645 | 708 |
} else { |
646 | 709 |
return null; |
647 | 710 |
} |
711 |
*/ |
|
648 | 712 |
} |
649 | 713 |
|
650 | 714 |
public String getName() { |
... | ... | |
738 | 802 |
} |
739 | 803 |
} |
740 | 804 |
|
741 |
} catch (DataException e) { |
|
742 |
e.printStackTrace(); |
|
805 |
} catch (Exception e) { |
|
806 |
|
|
807 |
ApplicationLocator.getManager().message( |
|
808 |
e.getMessage(), JOptionPane.ERROR_MESSAGE); |
|
809 |
logger.info("Error in select handler.", e); |
|
743 | 810 |
} finally { |
744 | 811 |
if (iterator != null) { |
745 | 812 |
iterator.dispose(); |
Also available in: Unified diff