Revision 72 org.gvsig.dxf/trunk/org.gvsig.dxf/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFStoreProvider.java
DXFStoreProvider.java | ||
---|---|---|
67 | 67 |
import org.gvsig.fmap.geom.GeometryLocator; |
68 | 68 |
import org.gvsig.fmap.geom.GeometryManager; |
69 | 69 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
70 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
70 | 71 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
71 | 72 |
import org.gvsig.fmap.geom.operation.distance.PointDistance; |
72 | 73 |
import org.gvsig.fmap.geom.operation.utils.PointGetAngle; |
73 | 74 |
import org.gvsig.fmap.geom.primitive.Arc; |
74 | 75 |
import org.gvsig.fmap.geom.primitive.Circle; |
75 |
import org.gvsig.fmap.geom.primitive.Curve; |
|
76 | 76 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
77 | 77 |
import org.gvsig.fmap.geom.primitive.Envelope; |
78 | 78 |
import org.gvsig.fmap.geom.primitive.Line; |
79 | 79 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
80 |
import org.gvsig.fmap.geom.primitive.Surface; |
|
81 | 80 |
import org.gvsig.fmap.geom.type.GeometryType; |
82 | 81 |
import org.gvsig.tools.ToolsLocator; |
83 | 82 |
import org.gvsig.tools.dispose.DisposableIterator; |
84 | 83 |
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
85 | 84 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
86 | 85 |
import org.gvsig.tools.exception.NotYetImplemented; |
86 |
import org.gvsig.tools.logger.FilteredLogger; |
|
87 | 87 |
import org.gvsig.tools.persistence.PersistentState; |
88 | 88 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
89 | 89 |
import org.gvsig.tools.task.SimpleTaskStatus; |
... | ... | |
462 | 462 |
private Envelope envelope; |
463 | 463 |
|
464 | 464 |
//Next two variables are used to read the DXF file |
465 |
private DxfFile.EntityFactory featureMaker;
|
|
466 |
private DxfFile.VarSettings headerManager;
|
|
465 |
private DxfFeatureMaker featureMaker;
|
|
466 |
private DxfHeaderManager headerManager;
|
|
467 | 467 |
|
468 | 468 |
public Reader initialice(AbstractMemoryStoreProvider store, File file, |
469 | 469 |
IProjection projection, |
... | ... | |
537 | 537 |
return Double.valueOf(value); |
538 | 538 |
} |
539 | 539 |
|
540 |
private FeatureProvider createFeature(Feature fea, FeatureType ft, int id) throws DataException { |
|
541 |
|
|
542 |
FeatureProvider feature = store.createFeatureProvider(ft); |
|
543 |
|
|
544 |
feature.setOID(new Long(id)); |
|
545 |
feature.set(ID_FIELD_ID, Integer.valueOf(id)); |
|
546 |
feature.set(ID_FIELD_ENTITY, fea.getProp("dxfEntity")); |
|
547 |
feature.set(ID_FIELD_LAYER, fea.getProp("layer")); |
|
548 |
feature.set(ID_FIELD_COLOR, Integer.valueOf(fea.getProp("color"))); |
|
549 |
feature.set(ID_FIELD_TEXT, fea.getProp("text")); |
|
550 |
feature.set(ID_FIELD_HEIGHTTEXT, toDouble(fea.getProp("textHeight"))); |
|
551 |
feature.set(ID_FIELD_ROTATIONTEXT, toDouble(fea.getProp("textRotation"))); |
|
552 |
feature.set(ID_FIELD_ELEVATION, toDouble(fea.getProp("elevation"))); |
|
553 |
feature.set(ID_FIELD_THICKNESS, toDouble(fea.getProp("thickness"))); |
|
554 |
feature.set(ID_FIELD_GEOMETRY, null); |
|
555 |
// FIXME: Abria que pillar el resto de atributos del DXF. |
|
556 |
|
|
557 |
// FIXME: Habia una incongruencia en el codigo ya que al |
|
558 |
// campo |
|
559 |
// ID_FIELD_GEOMETRY igual le asignaba una geometria que un |
|
560 |
// valor de cadena como 'Point3D', 'Polyline2D' o |
|
561 |
// 'Polyline3D' |
|
562 |
// Faltaria un atributo ID_FIELD_FSHAPE ? |
|
563 |
// |
|
564 |
return feature; |
|
565 |
} |
|
566 |
|
|
567 |
private Geometry processPoints(GeometryManager gManager, Feature dxffeature) throws CreateGeometryException { |
|
568 |
if (dxffeature.getGeometry() instanceof org.gvsig.dxf.px.gml.Point3D) { |
|
569 |
org.gvsig.dxf.px.gml.Point3D point = (org.gvsig.dxf.px.gml.Point3D) dxffeature.getGeometry(); |
|
570 |
Point3D pto = point.getPoint3D(0); |
|
571 |
org.gvsig.fmap.geom.primitive.Point geom = gManager.createPoint(pto.getX(), pto.getY(), SUBTYPES.GEOM3D); |
|
572 |
geom.setCoordinateAt(Geometry.DIMENSIONS.Z, pto.getZ()); |
|
573 |
|
|
574 |
if (point.isTextPoint()) { |
|
575 |
/// TODO labeling |
|
576 |
} |
|
577 |
return geom; |
|
578 |
|
|
579 |
} |
|
580 |
if (dxffeature.getGeometry() instanceof Point) { |
|
581 |
Point point = (Point) dxffeature.getGeometry(); |
|
582 |
Point2D pto = point.get(0); |
|
583 |
|
|
584 |
org.gvsig.fmap.geom.primitive.Point geom = gManager.createPoint(pto.getX(), pto.getY(), SUBTYPES.GEOM2D); |
|
585 |
|
|
586 |
if (point.isTextPoint()) { |
|
587 |
/// TODO labeling |
|
588 |
} |
|
589 |
return geom; |
|
590 |
} |
|
591 |
return null; |
|
592 |
} |
|
593 |
|
|
594 |
private Geometry processLines(GeometryManager gManager, Feature dxffeature) throws CreateGeometryException { |
|
595 |
if (dxffeature.getGeometry() instanceof LineString3D) { |
|
596 |
Line line = gManager.createLine(SUBTYPES.GEOM3D); |
|
597 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
598 |
Point3D point = ((LineString3D) dxffeature.getGeometry()).getPoint3D(j); |
|
599 |
line.addVertex(point.getX(), point.getY(), point.getZ()); |
|
600 |
} |
|
601 |
return line; |
|
602 |
|
|
603 |
} |
|
604 |
if (dxffeature.getGeometry() instanceof LineString) { |
|
605 |
Line line = gManager.createLine(SUBTYPES.GEOM2D); |
|
606 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
607 |
Point2D point = dxffeature.getGeometry().get(j); |
|
608 |
line.addVertex(point.getX(), point.getY()); |
|
609 |
} |
|
610 |
return line; |
|
611 |
} |
|
612 |
return null; |
|
613 |
} |
|
614 |
|
|
615 |
private Geometry processPolygons(GeometryManager gManager, Feature dxffeature) throws CreateGeometryException { |
|
616 |
if (dxffeature.getGeometry() instanceof Polygon3D) { |
|
617 |
org.gvsig.fmap.geom.primitive.Polygon polygon = gManager.createPolygon(SUBTYPES.GEOM3D); |
|
618 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
619 |
Point3D point = ((LineString3D) dxffeature.getGeometry()).getPoint3D(j); |
|
620 |
polygon.addVertex(point.getX(), point.getY(), point.getZ()); |
|
621 |
} |
|
622 |
Point3D point = ((LineString3D) dxffeature.getGeometry()).getPoint3D(0); |
|
623 |
polygon.addVertex(point.getX(), point.getY(), point.getZ()); |
|
624 |
return polygon; |
|
625 |
|
|
626 |
} |
|
627 |
if (dxffeature.getGeometry() instanceof Polygon) { |
|
628 |
org.gvsig.fmap.geom.primitive.Polygon polygon = gManager.createPolygon(SUBTYPES.GEOM2D); |
|
629 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
630 |
Point2D point = dxffeature.getGeometry().get(j); |
|
631 |
polygon.addVertex(point.getX(), point.getY()); |
|
632 |
} |
|
633 |
Point2D point = dxffeature.getGeometry().get(0); |
|
634 |
polygon.addVertex(point.getX(), point.getY()); |
|
635 |
return polygon; |
|
636 |
} |
|
637 |
return null; |
|
638 |
} |
|
639 |
|
|
640 |
private void addGeometryToFeature(Geometry geometry, FeatureProvider feature) { |
|
641 |
if( geometry != null ) { |
|
642 |
feature.set(ID_FIELD_GEOMETRY, geometry); |
|
643 |
feature.setDefaultGeometry(geometry); |
|
644 |
if (this.envelope == null) { |
|
645 |
this.envelope = geometry.getEnvelope(); |
|
646 |
} else { |
|
647 |
this.envelope.add(geometry.getEnvelope()); |
|
648 |
} |
|
649 |
} |
|
650 |
} |
|
651 |
|
|
652 |
private void addfeatureToLegend(FeatureProvider feature) { |
|
653 |
if (leyendBuilder != null) { |
|
654 |
try { |
|
655 |
leyendBuilder.process(feature); |
|
656 |
} catch (Exception e) { |
|
657 |
logger.warn( |
|
658 |
MessageFormat.format( |
|
659 |
"load: legendBuilder process fails in the feature {1}", |
|
660 |
feature |
|
661 |
) |
|
662 |
); |
|
663 |
} |
|
664 |
} |
|
665 |
} |
|
666 |
|
|
540 | 667 |
public void load() throws DataException { |
541 | 668 |
|
542 | 669 |
this.envelope = null; |
543 | 670 |
|
544 |
IObjList.vector features = (IObjList.vector) ((DxfFeatureMaker) featureMaker) |
|
545 |
.getObjects(); |
|
546 |
String acadVersion = ((DxfHeaderManager) headerManager) |
|
547 |
.getAcadVersion(); |
|
671 |
IObjList.vector features = (IObjList.vector)featureMaker.getObjects(); |
|
672 |
String acadVersion = headerManager.getAcadVersion(); |
|
548 | 673 |
|
549 |
|
|
550 | 674 |
logger.info("load: acadVersion = '" + acadVersion + "'"); |
551 | 675 |
|
552 | 676 |
GeometryManager gManager = GeometryLocator.getGeometryManager(); |
553 | 677 |
|
554 |
taskStatus.setRangeOfValues(0,features.size()); |
|
555 |
|
|
556 | 678 |
if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) { |
557 |
// y no est�n todos a 9999 |
|
558 | 679 |
taskStatus.message("_fixing_3dgeometries"); |
559 | 680 |
Feature[] features2D = new Feature[features.size()]; |
681 |
taskStatus.setRangeOfValues(0,features.size()); |
|
560 | 682 |
for (int i = 0; i < features.size(); i++) { |
561 | 683 |
taskStatus.setCurValue(i); |
562 | 684 |
Feature fea = (Feature) features.get(i); |
... | ... | |
594 | 716 |
} |
595 | 717 |
} |
596 | 718 |
|
597 |
|
|
598 |
|
|
719 |
FilteredLogger logger = new FilteredLogger(DXFStoreProvider.logger,"DXFLoafing",20); |
|
720 |
|
|
721 |
FeatureType ft = store.getStoreServices().getDefaultFeatureType(); |
|
599 | 722 |
taskStatus.message("_loading"); |
723 |
// Nos recorremos las geometrias tres veces para cargarlas en orden: |
|
724 |
// - poligonos |
|
725 |
// - lineas |
|
726 |
// - puntos |
|
727 |
// Y garantizar que siempre se pinten los puntos sobre lineas y |
|
728 |
// poligonos y las lineas sobre los polignos. |
|
729 |
int n = 0; |
|
730 |
taskStatus.setRangeOfValues(0,features.size()*3); |
|
600 | 731 |
for (int i = 0; i < features.size(); i++) { |
601 |
|
|
602 |
taskStatus.setCurValue(i); |
|
603 |
|
|
604 |
FeatureProvider feature = store.createFeatureProvider(store |
|
605 |
.getStoreServices().getDefaultFeatureType()); |
|
606 |
|
|
607 |
Feature fea = (Feature) features.get(i); |
|
732 |
taskStatus.setCurValue(n++); |
|
608 | 733 |
try { |
609 |
|
|
610 |
feature.setOID(new Long(i)); |
|
611 |
feature.set(ID_FIELD_ID, Integer.valueOf(i)); |
|
612 |
feature.set(ID_FIELD_ENTITY, fea.getProp("dxfEntity")); |
|
613 |
feature.set(ID_FIELD_LAYER, fea.getProp("layer")); |
|
614 |
feature.set(ID_FIELD_COLOR, Integer.valueOf(fea |
|
615 |
.getProp("color"))); |
|
616 |
feature.set(ID_FIELD_TEXT, fea.getProp("text")); |
|
617 |
feature.set(ID_FIELD_HEIGHTTEXT, toDouble(fea |
|
618 |
.getProp("textHeight"))); |
|
619 |
feature.set(ID_FIELD_ROTATIONTEXT, toDouble(fea |
|
620 |
.getProp("textRotation"))); |
|
621 |
feature.set(ID_FIELD_ELEVATION, toDouble(fea |
|
622 |
.getProp("elevation"))); |
|
623 |
feature.set(ID_FIELD_THICKNESS, toDouble(fea |
|
624 |
.getProp("thickness"))); |
|
625 |
feature.set(ID_FIELD_GEOMETRY, null); |
|
626 |
// FIXME: Abria que pillar el resto de atributos del DXF. |
|
627 |
|
|
628 |
// FIXME: Habia una incongruencia en el codigo ya que al |
|
629 |
// campo |
|
630 |
// ID_FIELD_GEOMETRY igual le asignaba una geometria que un |
|
631 |
// valor de cadena como 'Point3D', 'Polyline2D' o |
|
632 |
// 'Polyline3D' |
|
633 |
// Faltaria un atributo ID_FIELD_FSHAPE ? |
|
634 |
// |
|
635 |
|
|
636 |
Geometry geometry = null; |
|
637 |
|
|
638 |
if (fea.getGeometry() instanceof org.gvsig.dxf.px.gml.Point3D) { |
|
639 |
org.gvsig.dxf.px.gml.Point3D point = (org.gvsig.dxf.px.gml.Point3D) fea.getGeometry(); |
|
640 |
Point3D pto = point.getPoint3D(0); |
|
641 |
org.gvsig.fmap.geom.primitive.Point geom = gManager.createPoint(pto.getX(), pto.getY(),SUBTYPES.GEOM3D); |
|
642 |
geom.setCoordinateAt(Geometry.DIMENSIONS.Z, pto.getZ()); |
|
643 |
|
|
644 |
geometry = geom; |
|
645 |
|
|
646 |
if (point.isTextPoint()) { |
|
647 |
/// TODO labeling |
|
648 |
} |
|
649 |
|
|
650 |
} else if (fea.getGeometry() instanceof Point ) { |
|
651 |
Point point = (Point) fea.getGeometry(); |
|
652 |
Point2D pto = point.get(0); |
|
653 |
|
|
654 |
geometry = gManager.createPoint(pto.getX(), pto.getY(),SUBTYPES.GEOM2D); |
|
655 |
|
|
656 |
if (point.isTextPoint()) { |
|
657 |
/// TODO labeling |
|
658 |
} |
|
659 |
|
|
660 |
} else if (fea.getGeometry() instanceof LineString3D) { |
|
661 |
Line line = gManager.createLine(SUBTYPES.GEOM3D); |
|
662 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
|
663 |
Point3D point = ((LineString3D) fea.getGeometry()).getPoint3D(j); |
|
664 |
line.addVertex(point.getX(), point.getY(),point.getZ()); |
|
665 |
} |
|
666 |
geometry = line; |
|
667 |
|
|
668 |
} else if (fea.getGeometry() instanceof LineString ) { |
|
669 |
Line line = gManager.createLine(SUBTYPES.GEOM2D); |
|
670 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
|
671 |
Point2D point = fea.getGeometry().get(j); |
|
672 |
line.addVertex(point.getX(), point.getY()); |
|
673 |
} |
|
674 |
geometry = line; |
|
675 |
|
|
676 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
|
677 |
org.gvsig.fmap.geom.primitive.Polygon polygon = gManager.createPolygon(SUBTYPES.GEOM3D); |
|
678 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
|
679 |
Point3D point = ((LineString3D) fea.getGeometry()).getPoint3D(j); |
|
680 |
polygon.addVertex(point.getX(), point.getY(),point.getZ()); |
|
681 |
} |
|
682 |
Point3D point = ((LineString3D) fea.getGeometry()).getPoint3D(0); |
|
683 |
polygon.addVertex(point.getX(), point.getY(),point.getZ()); |
|
684 |
geometry = polygon; |
|
685 |
|
|
686 |
} else if (fea.getGeometry() instanceof Polygon ) { |
|
687 |
org.gvsig.fmap.geom.primitive.Polygon polygon = gManager.createPolygon(SUBTYPES.GEOM2D); |
|
688 |
for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
|
689 |
Point2D point = fea.getGeometry().get(j); |
|
690 |
polygon.addVertex(point.getX(), point.getY()); |
|
691 |
} |
|
692 |
Point2D point = fea.getGeometry().get(0); |
|
693 |
polygon.addVertex(point.getX(), point.getY()); |
|
694 |
geometry = polygon; |
|
695 |
|
|
696 |
} else { |
|
697 |
logger.warn( |
|
698 |
MessageFormat.format( |
|
699 |
"load: geometry type {1} not supported", |
|
700 |
new Object[] { fea.getGeometry().getClass().getName() } |
|
701 |
) |
|
702 |
); |
|
734 |
Feature dxffeature = (Feature) features.get(i); |
|
735 |
FeatureProvider feature = createFeature(dxffeature, ft, i); |
|
736 |
Geometry geometry = processPolygons(gManager, dxffeature); |
|
737 |
if( geometry != null ) { |
|
738 |
addGeometryToFeature(geometry, feature); |
|
739 |
store.addFeatureProvider(feature); |
|
740 |
addfeatureToLegend(feature); |
|
703 | 741 |
} |
704 |
|
|
705 |
feature.set(ID_FIELD_GEOMETRY, geometry); |
|
706 |
feature.setDefaultGeometry(geometry); |
|
707 |
if (this.envelope == null) { |
|
708 |
this.envelope = geometry.getEnvelope(); |
|
709 |
} else { |
|
710 |
this.envelope.add(geometry.getEnvelope()); |
|
742 |
} catch (Exception e) { |
|
743 |
logger.warn("Can't proccess feature '"+i+", of file '"+fileName+"'.", e); |
|
744 |
} |
|
745 |
} |
|
746 |
for (int i = 0; i < features.size(); i++) { |
|
747 |
taskStatus.setCurValue(n++); |
|
748 |
try { |
|
749 |
Feature dxffeature = (Feature) features.get(i); |
|
750 |
FeatureProvider feature = createFeature(dxffeature, ft, i); |
|
751 |
Geometry geometry = processLines(gManager, dxffeature); |
|
752 |
if( geometry != null ) { |
|
753 |
addGeometryToFeature(geometry, feature); |
|
754 |
store.addFeatureProvider(feature); |
|
755 |
addfeatureToLegend(feature); |
|
711 | 756 |
} |
712 |
|
|
713 |
//Add the feature to the store |
|
714 |
store.addFeatureProvider(feature); |
|
715 |
|
|
716 | 757 |
} catch (Exception e) { |
717 |
//throw new LoadException(e, fileName); |
|
718 |
// FIXME: add to log max 10 |
|
758 |
logger.warn("Can't proccess feature '"+i+", of file '"+fileName+"'.", e); |
|
719 | 759 |
} |
720 |
if (leyendBuilder != null) { |
|
721 |
try { |
|
722 |
leyendBuilder.process(feature); |
|
723 |
} catch (Exception e) { |
|
724 |
logger.warn( |
|
725 |
MessageFormat.format( |
|
726 |
"load: legendBuilder process fails in the feature {1}", |
|
727 |
fea |
|
728 |
) |
|
729 |
); |
|
760 |
} |
|
761 |
for (int i = 0; i < features.size(); i++) { |
|
762 |
taskStatus.setCurValue(n++); |
|
763 |
try { |
|
764 |
Feature dxffeature = (Feature) features.get(i); |
|
765 |
FeatureProvider feature = createFeature(dxffeature, ft, i); |
|
766 |
Geometry geometry = processPoints(gManager, dxffeature); |
|
767 |
if( geometry != null ) { |
|
768 |
addGeometryToFeature(geometry, feature); |
|
769 |
store.addFeatureProvider(feature); |
|
770 |
addfeatureToLegend(feature); |
|
730 | 771 |
} |
772 |
} catch (Exception e) { |
|
773 |
logger.warn("Can't proccess feature '"+i+", of file '"+fileName+"'.", e); |
|
731 | 774 |
} |
732 |
|
|
733 | 775 |
} |
734 | 776 |
} |
735 | 777 |
|
Also available in: Unified diff