Revision 75

View differences:

org.gvsig.dgn/trunk/org.gvsig.dgn/pom.xml
11 11
  <parent>
12 12
      <groupId>org.gvsig</groupId>
13 13
      <artifactId>org.gvsig.desktop</artifactId>
14
      <version>2.0.38</version>
14
      <version>2.0.40-SNAPSHOT</version>
15 15
  </parent>
16 16
  <url>https://devel.gvsig.org/redmine/projects/gvsig-dgn</url>
17 17

  
org.gvsig.dgn/trunk/org.gvsig.dgn/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNStoreParameters.java
44 44
    private static final String FIELD_IGNORE_Z = "ignoreZ";
45 45
    private static final String FIELD_GROUPBY = "groupby";
46 46
    private static final String FIELD_APPLYCONVEXHULL = "applyConvexHull";
47
    private static final String FIELD_USE_Z_AS_ELEVATION = "useZAsElevation";
48
    private static final String FIELD_ELEVATION_FACTOR = "elevationFactor";
49
    private static final String FIELD_ROUND_ELEVATION = "roundElevation";
47 50
    
48 51
    private DelegatedDynObject parameters;
49 52

  
......
119 122
        return x.intValue();
120 123
    }
121 124
    
125
    public double geElevationFactor() {
126
        Double x = (Double) this.getDynValue(FIELD_ELEVATION_FACTOR);
127
        if (x == null) {
128
            return 1;
129
        }
130
        return x.doubleValue();
131
    }
132
    
122 133
    public int getCropOperationFilter() {
123 134
        Integer x = (Integer) this.getDynValue(FIELD_CROPOPERATION_FILTER);
124 135
        if (x == null) {
......
188 199
        return x.booleanValue();
189 200
    }
190 201

  
202
    public boolean getApplyRoundToElevation() {
203
        Boolean x = (Boolean) this.getDynValue(FIELD_ROUND_ELEVATION);
204
        if (x == null) {
205
            return Boolean.FALSE;
206
        }
207
        return x.booleanValue();
208
    }
209

  
191 210
    public boolean ignoreZs() {
192 211
        Boolean x = (Boolean) this.getDynValue(FIELD_IGNORE_Z);
193 212
        if (x == null) {
......
212 231
        return x.booleanValue();
213 232
    }
214 233

  
234
    boolean useZAsElevation() {
235
        Boolean x = (Boolean) this.getDynValue(FIELD_USE_Z_AS_ELEVATION);
236
        if (x == null) {
237
            return Boolean.FALSE;
238
        }
239
        return x.booleanValue();
240
    }
215 241
    public boolean sortByGeometryType() {
216 242
        Boolean x = (Boolean) this.getDynValue(FIELD_SORT_BY_GEOMETRY_TYPE);
217 243
        if (x == null) {
......
243 269
    protected DelegatedDynObject getDelegatedDynObject() {
244 270
        return parameters;
245 271
    }
272

  
273

  
246 274
}
org.gvsig.dgn/trunk/org.gvsig.dgn/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNStoreProvider.java
239 239
            if (envelope == null) {
240 240
                return null;
241 241
            }
242
            Envelope newEnvelope;
243
            if (envelope.getDimension() == 2) {
244
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
245
            } else {
246
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
247

  
242
            try {
243
                return (Envelope) envelope.clone();
244
            } catch (CloneNotSupportedException ex) {
245
                logger.warn("Can't clone envelope.",ex);
246
                return null;
248 247
            }
249
            newEnvelope.setLowerCorner(envelope.getLowerCorner());
250
            newEnvelope.setUpperCorner(envelope.getUpperCorner());
251
            return newEnvelope;
252 248
        }
253 249
    }
254 250

  
......
783 779
//			}
784 780
//			return Double.valueOf(value);
785 781
//		}
786
        public void load() throws DataException {
782
        public void load() throws DataException, CreateEnvelopeException {
787 783
            switch (getDGNParameters().getLoadMode()) {
788 784
                case LOAD_MODE_PLAIN:
789 785
                default:
......
801 797
            BufferedWriter xmlbfw = null;
802 798

  
803 799
            this.envelope = null;
800

  
804 801
            boolean ignoreZs = getDGNParameters().ignoreZs();
805

  
802
            boolean useZAsElevation = getDGNParameters().useZAsElevation();
803
            boolean applyRoundToElevation = getDGNParameters().getApplyRoundToElevation();
804
            double elevationFactor = getDGNParameters().geElevationFactor();
805
                    
806 806
            try {
807 807
                if (getDGNParameters().getXMLFile() != null) {
808 808
                    File xmlfile = getDGNParameters().getXMLFile();
......
827 827

  
828 828
                DGNReader dgnReader = new DGNReader(file.getAbsolutePath(), getDGNParameters().logErrors());
829 829

  
830
                if ( dgnReader.getInfo().dimension == 2 || getDGNParameters().ignoreZs() ) {
831
                    envelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
832
                } else {
833
                    envelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
834
                }
835
                
830 836
                FeatureType type = getDefaultType().getNotEditableCopy();
831 837

  
832 838
                filter = new Filter(getDGNParameters(), dgnReader);
833 839

  
834 840
                int counterOfElement = 0;
835 841
                DGNElemComplexHeader parentElement = null;
842
                
843
                double zvalue = 0;
844
                
836 845
                for (int id = 0; id < dgnReader.getNumEntities(); id++) {
837 846
                    dgnReader.DGNGotoElement(id);
838 847

  
......
890 899
                    } else {
891 900
                        data.set(ID_FIELD_PARENT, parentElement.getID());
892 901
                    }
893

  
902
                    zvalue = 0;
894 903
                    try {
895 904
                        switch (elemento.stype) {
896 905
                            case DGNFileHeader.DGNST_COMPLEX_HEADER:
......
902 911
                                DGNElemMultiPoint dgnmultipoint = (DGNElemMultiPoint) elemento;
903 912
                                if (dgnmultipoint.isPoint()) {
904 913
                                    DGNPoint p = dgnmultipoint.getPoint(0);
905
                                    Point point = createPoint3D(p.x, p.y, ignoreZs ? 0 : p.z);
914
                                    Point point = createPoint3D(p.getX(), p.getY(), ignoreZs ? 0 : p.getZ());
906 915
                                    data.setDefaultGeometry(point);
907

  
916
                                    zvalue = p.getZ();
908 917
                                } else {
909 918
                                    OrientablePrimitive geom = null;
910 919
                                    if (dgnmultipoint.isPolygon()) {
......
933 942
                                        // Invertimos el orden porque es un agujero
934 943
                                        for (int i = numVertices - 2; i >= first; i--) {
935 944
                                            DGNPoint p = dgnmultipoint.getVertex(i);
936
                                            geom.addVertex(p.getX(), p.getY(), ignoreZs ? 0 : p.getZ());
945
                                            zvalue = p.getZ();
946
                                            geom.addVertex(p.getX(), p.getY(), ignoreZs ? 0 : zvalue);
937 947
                                        }
938 948
                                    } else {
939 949
                                        for (int i = first; i < numVertices; i++) {
940 950
                                            DGNPoint p = dgnmultipoint.getVertex(i);
941
                                            geom.addVertex(p.getX(), p.getY(), ignoreZs ? 0 : p.getZ());
951
                                            zvalue = p.getZ();
952
                                            geom.addVertex(p.getX(), p.getY(), ignoreZs ? 0 : zvalue);
942 953
                                        }
943 954
                                    }
944 955
                                    data.setDefaultGeometry(geom);
......
973 984
                                        -dgnarc.sweepang,
974 985
                                        Arc2D.OPEN);
975 986

  
987
                                zvalue = dgnarc.origin.getZ();
988
                                
976 989
                                GeneralPathX elShapeArc = new GeneralPathX(elArco.getPathIterator(null));
977 990

  
978 991
                                // Transformamos el GeneralPahtX porque si transformamos
......
1000 1013

  
1001 1014
                            case DGNFileHeader.DGNST_TEXT:
1002 1015
                                DGNElemText dgntext = (DGNElemText) elemento;
1016
                                zvalue = dgntext.getPoint().getZ();
1003 1017
                                Point point = createPoint3D(
1004 1018
                                        dgntext.getPoint().getX(),
1005 1019
                                        dgntext.getPoint().getY(),
1006
                                        ignoreZs ? 0 : dgntext.getPoint().getZ()
1020
                                        ignoreZs ? 0 : zvalue
1007 1021
                                );
1008 1022
                                data.set(ID_FIELD_HEIGHTTEXT, dgntext.getHeight());
1009 1023
                                data.set(ID_FIELD_HEIGHTTEXTRAW, dgntext.getRawHeight());
......
1020 1034
                    } catch (Exception ex) {
1021 1035
                        logger.warn("Can't process element", ex);
1022 1036
                    }
1037
                    if( useZAsElevation ) {
1038
                        if( !DGNStoreProvider.equals(elevationFactor, 1, 0.00001) ) {
1039
                            zvalue = zvalue*elevationFactor;
1040
                        }
1041
                        if( applyRoundToElevation ) {
1042
                            zvalue = Math.round(zvalue);
1043
                        }
1044
                        data.set(ID_FIELD_ELEVATION, zvalue);
1045
                    }
1023 1046
                    addFeature(data, dgnReader);
1024 1047
                } // for
1025 1048

  
......
1116 1139

  
1117 1140
        }
1118 1141

  
1119
        public void load_group1() throws DataException {
1142
        public void load_group1() throws DataException, CreateEnvelopeException {
1120 1143

  
1121 1144
            this.envelope = null;
1122 1145

  
......
1143 1166

  
1144 1167
            }
1145 1168
            DGNReader dgnReader = new DGNReader(file.getAbsolutePath());
1169
            if ( dgnReader.getInfo().dimension == 2) {
1170
                envelope = geomManager.createEnvelope(Geometry.SUBTYPES.GEOM2D);
1171
            } else {
1172
                envelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
1173
            }
1146 1174

  
1147 1175
            FeatureType type = getDefaultType().getNotEditableCopy();
1148 1176
            int fTypeSize = type.size();
......
1834 1862
        return resource;
1835 1863
    }
1836 1864

  
1865
    public static boolean equals(double a, double b, double precision) {
1866
        double v = Math.abs(a-b);
1867
        return v < precision;
1868
    }
1837 1869
}
org.gvsig.dgn/trunk/org.gvsig.dgn/org.gvsig.dgn.provider/src/main/resources/org/gvsig/fmap/dal/store/dgn/DGNParameters.xml
39 39
          <description>Apply convex hull to the grouped geometries.Don't take effect if do not group.</description>
40 40
        </field>
41 41

  
42
        <!-- Advanced -->
43
        <field name="useZAsElevation" label="Use Z as elevation" type="Boolean" defaultValue="false" mandatory="false" group="Advanced">
44
          <description>If set, use the Z value to fill the field elevation.</description>
45
        </field>
46
        <field name="elevationFactor" label="Elevation factor" type="Double" defaultValue="1" mandatory="false" group="Advanced">
47
          <description>Factor to apply to elevation when is retrived from the Z coordinate.</description>
48
        </field>
49
        <field name="roundElevation" label="Round elevation" type="Boolean" defaultValue="false" mandatory="false" group="Advanced">
50
          <description>If set, round the elevation to a integer value. This only apply when get elevation from the coordinete Z.</description>
51
        </field>
52

  
53

  
42 54
        <!-- Filter -->
43 55
        <field name="levelFilter" label="Level" group="Filter" type="String" defaultValue="" mandatory="false">
44
          <description>If specified load only elements with this level</description>
56
          <description>If specified load only elements with this level. Can use regular expresion to specify the filter.</description>
45 57
        </field>
46 58
        <field name="colorFilter" label="Color" group="Filter" type="String" defaultValue="" mandatory="false">
47
          <description>If specified load only elements with this color</description>
59
          <description>If specified load only elements with this color. Can use regular expresion to specify the filter.</description>
48 60
        </field>
49 61
        <field name="styleFilter" label="Style" group="Filter" type="String" defaultValue="" mandatory="false">
50
          <description>If specified load only elements with this style</description>
62
          <description>If specified load only elements with this style. Can use regular expresion to specify the filter.</description>
51 63
        </field>
52 64
        <field name="weightFilter" label="Weight" group="Filter" type="String" defaultValue="" mandatory="false">
53
          <description>If specified load only elements with this weight</description>
65
          <description>If specified load only elements with this weight. Can use regular expresion to specify the filter.</description>
54 66
        </field>
55 67
        <field name="typeFilter" label="Type" group="Filter" type="String" defaultValue="" mandatory="false">
56 68
          <description>If specified load only elements with this type</description>
......
103 115
        <field name="XMLFile" label="Output XML file" type="file" group="Debug" mandatory="false">
104 116
          <description>Generate XML file with DGN dump in this file</description>
105 117
        </field>
118
        <!--
106 119
        <field name="debugOptions" label="Debug options" type="String" group="Debug" mandatory="false">
107 120
          <description></description>
108 121
        </field>
122
        -->
109 123
        <field name="logErrors" label="log errors" group="Debug" type="Boolean" defaultValue="false" mandatory="false">
110 124
          <description>If checked the log of errors are enabled</description>
111 125
        </field>

Also available in: Unified diff