Revision 524

View differences:

org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/test/java/org/gvsig/fmap/dal/store/dgn/TestDGN.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.dgn;
29

  
30
import java.io.File;
31
import java.net.URL;
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataManager;
34

  
35
import org.gvsig.fmap.dal.DataStoreParameters;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.feature.FeatureStore;
38
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
39

  
40
import static junit.framework.Assert.assertNotNull;
41

  
42
public class TestDGN extends AbstractLibraryAutoInitTestCase {
43

  
44
	private File file_prueba = null;
45
        private DataManager dataManager = null;
46

  
47
        @Override
48
        protected void doSetUp() throws Exception {
49
            URL res = TestDGN.class.getResource("data/prueba.dgn");
50
            this.file_prueba = new File(res.getFile());
51
            this.dataManager = DALLocator.getDataManager();
52
        }
53

  
54
        
55
	/*
56
	 * (non-Javadoc)
57
	 *
58
	 * @see
59
	 * org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters
60
	 * ()
61
	 */
62
	public DataStoreParameters getDefaultDataStoreParameters()
63
			throws DataException {
64
            
65
		DGNOpenStoreParameters dgnParameters = null;
66

  
67
		dgnParameters = (DGNOpenStoreParameters) dataManager
68
				.createStoreParameters(DGNStoreProvider.NAME);
69

  
70
		dgnParameters.setFile(file_prueba.getAbsolutePath());
71
		dgnParameters.setCRS("EPSG:23030");
72
		return dgnParameters;
73
	}
74

  
75
	/*
76
	 * (non-Javadoc)
77
	 *
78
	 * @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
79
	 */
80
	public boolean hasExplorer() {
81
		// TODO Auto-generated method stub
82
		return false;
83
	}
84

  
85
	public boolean usesResources() {
86
		return true;
87
	}
88

  
89

  
90
	public void testLegendAndLabeling() throws Exception {
91
		FeatureStore store = (FeatureStore) dataManager.openStore(
92
                        DGNStoreProvider.NAME,
93
                        getDefaultDataStoreParameters()
94
                );
95

  
96
		assertNotNull(store.invokeDynMethod("getLegend", null));
97
		assertNotNull(store.invokeDynMethod("getLabeling", null));
98
		store.dispose();
99
	}
100
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/resources/org/gvsig/fmap/dal/store/dgn/DGNMetadata.xml
1
<?xml version="1.0"?>
2
<!--
3
Definitions of metadata fields of a shp file.  
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    
9
    <class name="DGN" namespace="Metadata">
10
      <extends>
11
      	<class namespace="Metadata" name="SpatialProvider"/>
12
      </extends>
13
      <description>Metadata of a DGN store</description>
14
      <fields>
15
      </fields>
16
    </class>
17

  
18
  </classes>
19
</definitions>  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/resources/org/gvsig/fmap/dal/store/dgn/DGNParameters.xml
1
<?xml version= "1.0 "?>
2
<definitions>
3
  <version>1.0.0</version>
4
  <classes>
5
    <class name="DGN">
6
      <extends>
7
      	<class namespace="dal" name="ProviderParameters"/>
8
      </extends>
9
      <description>Store the parameters need to open a dgn file</description>
10
      <fields>
11
        
12
        <!-- General -->
13
        <field name="file" type="file" mandatory="true">
14
          <description>dgn file</description>
15
        </field>
16
        <field name="CRS" type="crs" mandatory="true">
17
          <description>The coordinate reference system used in this dgn file</description>
18
        </field>
19
        <field name="LoadMode" label="Load mode" defaultValue="0" type="integer" mandatory="false">
20
          <description>Set the strategy to use for loading DGN elements</description>
21
     	  <availableValues>
22
            <value label="Plain">0</value>
23
            <value label="Group elements (1)">1</value>
24
     	  </availableValues>
25
        </field>
26
        <field name="sortByGeometryType" label="Sort by geometry type" type="Boolean" defaultValue="true" mandatory="false">
27
          <description>If checked sort the rows of table by the geometry type (none,suface,curve,point)</description>
28
        </field>
29
        <field name="force2d" label="Force 2D" type="Boolean" defaultValue="false" mandatory="false">
30
          <description>If checked and DGN has Z dimension create all geometry in 2D and ignore the Zs.</description>
31
        </field>
32
        <field name="Reload" label="Reload" type="Boolean" defaultValue="false" mandatory="false">
33
          <description>Reload an already loaded DGN as a new layer</description>
34
        </field>
35
        <field name="groupby" label="Field for group" type="String" defaultValue="" mandatory="false">
36
          <description>The field name to use for grouping rows</description>
37
        </field>
38
        <field name="GroupGeometriesOperation" label="Group geometries as" type="integer" defaultValue="0" mandatory="false">
39
          <description>If a 'group by' is applied, apply this operation to the resultant geometries</description>
40
     	  <availableValues>
41
            <value label="None, return the agregate">0</value>
42
            <value label="Convexhull">1</value>
43
            <value label="Union">2</value>
44
            <value label="Intersection">3</value>
45
            <value label="Convert to points">4</value>
46
            <value label="Convert to line">5</value>
47
            <value label="Convert to poligon">7</value>
48
            <value label="Convert to poligon and fix it">7</value>
49
     	  </availableValues>
50
        </field>
51

  
52
        <!-- Advanced -->
53
        <field name="ignoreZ" label="Ignore Z" type="Boolean" defaultValue="false" mandatory="false">
54
          <description>If checked and DGN has Z dimension, set all Zs to 0.</description>
55
        </field>
56
        <field name="useZAsElevation" label="Use Z as elevation" type="Boolean" defaultValue="false" mandatory="false" group="Advanced">
57
          <description>If set, use the Z value to fill the field elevation.</description>
58
        </field>
59
        <field name="elevationFactor" label="Elevation factor" type="Double" defaultValue="1" mandatory="false" group="Advanced">
60
          <description>Factor to apply to elevation when is retrived from the Z coordinate.</description>
61
        </field>
62
        <field name="roundElevation" label="Round elevation" type="Boolean" defaultValue="false" mandatory="false" group="Advanced">
63
          <description>If set, round the elevation to a integer value. This only apply when get elevation from the coordinete Z.</description>
64
        </field>
65
        <field name="LinkFilterIndex" label="Link filter index" type="integer" defaultValue="0" mandatory="false" group="Advanced">
66
          <description>If set, return the link with this index</description>
67
        </field>
68
        <field name="LinkFilterType" label="Link filter type" type="integer" defaultValue="" mandatory="false" group="Advanced">
69
          <description>If set, return the link with this type</description>
70
        </field>
71
        <field name="LinkFilterEntity" label="Link filter entity" type="integer" defaultValue="" mandatory="false" group="Advanced">
72
          <description>If set, return the link with this entity</description>
73
        </field>
74
        <field name="LinkFilterMS" label="Link filter MSLink" type="integer" defaultValue="" mandatory="false" group="Advanced">
75
          <description>If set, return the link with this MSLink</description>
76
        </field>
77
        <field name="LinkFilterData" label="Link filter Data" type="string" defaultValue="" mandatory="false" group="Advanced">
78
          <description>This is a regular expresion. If set, return the link that match this regular expresion in the data of link represented in hexadecimal value</description>
79
        </field>
80

  
81
        <!-- Filter -->
82
        <field name="levelFilter" label="Level" group="Filter" type="String" defaultValue="" mandatory="false">
83
          <description>If specified load only elements with this level. Can use regular expresion to specify the filter.</description>
84
        </field>
85
        <field name="colorFilter" label="Color" group="Filter" type="String" defaultValue="" mandatory="false">
86
          <description>If specified load only elements with this color. Can use regular expresion to specify the filter.</description>
87
        </field>
88
        <field name="styleFilter" label="Style" group="Filter" type="String" defaultValue="" mandatory="false">
89
          <description>If specified load only elements with this style. Can use regular expresion to specify the filter.</description>
90
        </field>
91
        <field name="weightFilter" label="Weight" group="Filter" type="String" defaultValue="" mandatory="false">
92
          <description>If specified load only elements with this weight. Can use regular expresion to specify the filter.</description>
93
        </field>
94
        <field name="typeFilter" label="Type" group="Filter" type="String" defaultValue="" mandatory="false">
95
          <description>If specified load only elements with this type</description>
96
        </field>
97
        <field name="stypeFilter" label="SType" group="Filter" type="String" defaultValue="" mandatory="false">
98
          <description>If specified load only elements with this stype</description>
99
        </field>
100
        <field name="groupFilter" label="Group" group="Filter" type="String" defaultValue="" mandatory="false">
101
          <description>If specified load only elements with this group</description>
102
        </field>
103
        <field name="idFilter" label="Id" group="Filter" type="String" defaultValue="" mandatory="false">
104
          <description>If specified load only elements with this id</description>
105
        </field>
106
        <field name="textFilter" label="Text" group="Filter" type="String" defaultValue="" mandatory="false">
107
          <description>If specified load only elements that match this text</description>
108
        </field>
109
        <field name="geomtypeFilter" label="Geometry type" group="Filter" defaultValue="0" type="Integer" mandatory="false">
110
          <description>If specified load only elements with this type of geometry</description>
111
     	  <availableValues>
112
            <value label="All">0</value>
113
            <value label="Points">1</value>
114
            <value label="Lines">2</value>
115
            <value label="Poligons">3</value>
116
     	  </availableValues>
117
        </field>
118
        <field name="skipCorruptGeometries" label="Skip corrupt geometries" group="Filter" type="Boolean" defaultValue="false" mandatory="false">
119
          <description>If specified skip corrupt geometries</description>
120
        </field>
121
        <field name="cropOperationFilter" label="Crop operation" group="Filter" defaultValue="1" type="Integer" mandatory="false">
122
          <description>If specified load only elements with this type of geometry</description>
123
     	  <availableValues>
124
            <value label="None">0</value>
125
            <value label="Contains">1</value>
126
            <value label="Covered by">2</value>
127
            <value label="Covers">3</value>
128
            <value label="Crosses">4</value>
129
            <value label="Disjoint">5</value>
130
            <value label="Intersect">6</value>
131
            <value label="Overlaps">7</value>
132
            <value label="Touches">8</value>
133
            <value label="With in">9</value>
134
     	  </availableValues>
135
        </field>
136
        <field name="cropFilter" label="Crop to" group="Filter" type="Geometry" defaultValue="" mandatory="false">
137
          <description>Crop the result to this value</description>
138
        </field>
139
        
140
                        
141
        <!-- Debug -->
142
        <field name="XMLFile" label="Output XML file" type="file" group="Debug" mandatory="false">
143
          <description>Generate XML file with DGN dump in this file</description>
144
        </field>
145
        <!--
146
        <field name="debugOptions" label="Debug options" type="String" group="Debug" mandatory="false">
147
          <description></description>
148
        </field>
149
        -->
150
        <field name="logErrors" label="log errors" group="Debug" type="Boolean" defaultValue="false" mandatory="false">
151
          <description>If checked the log of errors are enabled</description>
152
        </field>
153

  
154
      </fields>
155
    </class>
156
  </classes>
157
</definitions>  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.store.dgn.DGNLibrary
2
org.gvsig.fmap.dal.store.dgn.legend.DGNLegendLibrary
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNStoreProviderFactory.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import java.util.List;
4

  
5
import org.gvsig.fmap.dal.DataParameters;
6
import org.gvsig.fmap.dal.DataStoreProvider;
7
import org.gvsig.fmap.dal.exception.InitializeException;
8
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
9
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory;
10
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
11
import org.gvsig.tools.dynobject.DynObject;
12

  
13
public class DGNStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory{
14

  
15
	protected DGNStoreProviderFactory(String name, String description) {
16
		super(name, description);
17
	}
18

  
19
	public DataStoreProvider createProvider(DataParameters parameters,
20
			DataStoreProviderServices providerServices)
21
			throws InitializeException {
22
		return new DGNStoreProvider((DGNOpenStoreParameters) parameters, providerServices);
23
	}
24

  
25
	public DynObject createParameters() {
26
		return new DGNOpenStoreParameters();
27
	}
28
	
29
	public int allowCreate() {
30
		return NO;
31
	}
32
	
33
	public int allowWrite() {
34
		return NO;
35
	}
36

  
37
	public int allowRead() {
38
		return YES;
39
	}
40
	
41
	public int hasRasterSupport() {
42
		return NO;
43
	}
44
	
45
	public int hasTabularSupport() {
46
		return YES;
47
	}
48
	
49
	public int hasVectorialSupport() {
50
		return YES;
51
	}
52

  
53
	public int allowMultipleGeometryTypes() {
54
		return YES;
55
	}
56
	
57
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNOpenStoreParameters.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import java.io.File;
4
import java.util.regex.Pattern;
5
import org.apache.commons.lang3.StringUtils;
6

  
7
import org.cresques.cts.IProjection;
8
import org.gvsig.fmap.dal.FileHelper;
9
import org.gvsig.fmap.dal.feature.EditableFeatureType;
10
import org.gvsig.fmap.dal.feature.FeatureType;
11
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters;
12
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
13
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
14
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
15
import org.gvsig.fmap.geom.Geometry;
16
import org.gvsig.tools.dynobject.DelegatedDynObject;
17

  
18
public class DGNOpenStoreParameters extends AbstractDataParameters implements
19
        FilesystemStoreParameters,
20
        OpenFeatureStoreParameters {
21

  
22
    public static final String PARAMETERS_DEFINITION_NAME = "DGN";
23

  
24
    private static final String FIELD_FILE = "file";
25
    private static final String FIELD_CRS = "CRS";
26
    private static final String FIELD_XMLFILE = "XMLFile";
27
    private static final String FIELD_LOAD_MODE = "LoadMode";
28
    private static final String FIELD_RELOAD = "Reload";
29
    private static final String FIELD_GEOMTYPE_FILTER = "geomtypeFilter";
30
    private static final String FIELD_LEVEL_FILTER = "levelFilter";
31
    private static final String FIELD_TEXT_FILTER = "textFilter";
32
    private static final String FIELD_COLOR_FILTER = "colorFilter";
33
    private static final String FIELD_STYLE_FILTER = "styleFilter";
34
    private static final String FIELD_WEIGHT_FILTER = "weightFilter";
35
    private static final String FIELD_TYPE_FILTER = "typeFilter";
36
    private static final String FIELD_STYPE_FILTER = "stypeFilter";
37
    private static final String FIELD_GROUP_FILTER = "groupFilter";
38
    private static final String FIELD_ID_FILTER = "idFilter";
39
    private static final String FIELD_CROP_FILTER = "cropFilter";
40
    private static final String FIELD_CROPOPERATION_FILTER = "cropOperationFilter";
41
    private static final String FIELD_SKYPCORRUPTGEOMETRIES_FILTER = "skipCorruptGeometries";
42
    private static final String FIELD_SORT_BY_GEOMETRY_TYPE = "sortByGeometryType";
43
    private static final String FIELD_LOGS_ERRORS = "logErrors";
44
    private static final String FIELD_IGNORE_Z = "ignoreZ";
45
    private static final String FIELD_GROUPBY = "groupby";
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";
50

  
51
    public static final String FIELD_LINK_FILTER_INDEX = "LinkFilterIndex";
52
    public static final String FIELD_LINK_FILTER_TYPE = "LinkFilterType";
53
    public static final String FIELD_LINK_FILTER_ENTITY = "LinkFilterEntity";
54
    public static final String FIELD_LINK_FILTER_MS = "LinkFilterMS";
55
    public static final String FIELD_LINK_FILTER_DATA = "LinkFilterData";
56

  
57
    public static final String FIELD_GROUP_GEOMETRIES_OPERATION = "GroupGeometriesOperation";
58
    public static final String FIELD_FORZE2D = "force2D";
59
    
60
    
61
    private DelegatedDynObject parameters;
62

  
63
    public DGNOpenStoreParameters() {
64
        this(PARAMETERS_DEFINITION_NAME);
65
    }
66

  
67
    protected DGNOpenStoreParameters(String parametersDefinitionName) {
68
        this(parametersDefinitionName, DGNStoreProvider.NAME);
69
    }
70

  
71
    public DGNOpenStoreParameters(String parametersDefinitionName, String name) {
72
        super();
73
        this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
74
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
75
    }
76

  
77
    public String getDataStoreName() {
78
        return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
79
    }
80

  
81
    public String getDescription() {
82
        return this.getDynClass().getDescription();
83
    }
84

  
85
    public void setCRS(IProjection srs) {
86
        setDynValue(FIELD_CRS, srs);
87
    }
88

  
89
    public void setCRS(String srs) {
90
        setDynValue(FIELD_CRS, srs);
91
    }
92

  
93
    public IProjection getCRS() {
94
        return (IProjection) getDynValue(FIELD_CRS);
95
    }
96

  
97
    public String getFileName() {
98
        return this.getFile().getPath();
99
    }
100

  
101
    public boolean isValid() {
102
        if (getCRS() == null) {
103
            return false;
104
        }
105
        if (getFile() == null) {
106
            return false;
107
        }
108
        return true;
109
    }
110

  
111
    public File getFile() {
112
        return (File) this.getDynValue(FIELD_FILE);
113
    }
114

  
115
    public File getXMLFile() {
116
        return (File) this.getDynValue(FIELD_XMLFILE);
117
    }
118

  
119
    public int getGeometryTypeFilter() {
120
        Integer x = (Integer) this.getDynValue(FIELD_GEOMTYPE_FILTER);
121
        if (x == null) {
122
            return Geometry.TYPES.GEOMETRY;
123
        }
124
        return x.intValue();
125
    }
126

  
127
    public int getLoadMode() {
128
        Integer x = (Integer) this.getDynValue(FIELD_LOAD_MODE);
129
        if (x == null) {
130
            return DGNStoreProvider.LOAD_MODE_PLAIN;
131
        }
132
        return x.intValue();
133
    }
134
    
135
    public int getGroupGeometriesOperation() {
136
        Integer x = (Integer) this.getDynValue(FIELD_GROUP_GEOMETRIES_OPERATION);
137
        if (x == null) {
138
            return DGNStoreProvider.GROUP_GEOMETRIES_NONE;
139
        }
140
        return x.intValue();
141
    }
142
    
143
    public double geElevationFactor() {
144
        Double x = (Double) this.getDynValue(FIELD_ELEVATION_FACTOR);
145
        if (x == null) {
146
            return 1;
147
        }
148
        return x.doubleValue();
149
    }
150
    
151
    public int getCropOperationFilter() {
152
        Integer x = (Integer) this.getDynValue(FIELD_CROPOPERATION_FILTER);
153
        if (x == null) {
154
            return DGNStoreProvider.CROP_OPERATION_NONE;
155
        }
156
        return x.intValue();
157
    }
158

  
159
    public Geometry getCropFilter() {
160
        Geometry x = (Geometry) this.getDynValue(FIELD_CROP_FILTER);
161
        return x;
162
    }
163

  
164
    public String getGroupBy() {
165
        return (String) this.getDynValue(FIELD_GROUPBY);
166
    }
167

  
168
    public String getLevelFilter() {
169
        return (String) this.getDynValue(FIELD_LEVEL_FILTER);
170
    }
171

  
172
    public String getGroupFilter() {
173
        return (String) this.getDynValue(FIELD_GROUP_FILTER);
174
    }
175

  
176
    public String getTextFilter() {
177
        return (String) this.getDynValue(FIELD_TEXT_FILTER);
178
    }
179

  
180
    public String getIDFilter() {
181
        return (String) this.getDynValue(FIELD_ID_FILTER);
182
    }
183

  
184
    public String getTypeFilter() {
185
        return (String) this.getDynValue(FIELD_TYPE_FILTER);
186
    }
187

  
188
    public String getSTypeFilter() {
189
        return (String) this.getDynValue(FIELD_STYPE_FILTER);
190
    }
191

  
192
    public String getColorFilter() {
193
        return (String) this.getDynValue(FIELD_COLOR_FILTER);
194
    }
195

  
196
    public String getStyleFilter() {
197
        return (String) this.getDynValue(FIELD_STYLE_FILTER);
198
    }
199

  
200
    public String getWeightFilter() {
201
        return (String) this.getDynValue(FIELD_WEIGHT_FILTER);
202
    }
203

  
204
    public boolean useReload() {
205
        Boolean x = (Boolean) this.getDynValue(FIELD_RELOAD);
206
        if (x == null) {
207
            return Boolean.FALSE;
208
        }
209
        return x.booleanValue();
210
    }
211

  
212
//    public boolean getApplyConvexHull() {
213
//        Boolean x = (Boolean) this.getDynValue(FIELD_APPLYCONVEXHULL);
214
//        if (x == null) {
215
//            return Boolean.FALSE;
216
//        }
217
//        return x.booleanValue();
218
//    }
219

  
220
    public boolean getApplyRoundToElevation() {
221
        Boolean x = (Boolean) this.getDynValue(FIELD_ROUND_ELEVATION);
222
        if (x == null) {
223
            return Boolean.FALSE;
224
        }
225
        return x.booleanValue();
226
    }
227

  
228
     public String getLinkFilterData() {
229
        return StringUtils.trimToNull((String) this.getDynValue(FIELD_LINK_FILTER_DATA));
230
    }
231

  
232
     public Pattern getLinkFilterDataAsPattern() {
233
        String s = getLinkFilterData();
234
        if( s == null ) {
235
            return null;
236
        }
237
        return Pattern.compile(s);
238
    }
239

  
240
    public Integer getLinkFilterIndex() {
241
        return (Integer) this.getDynValue(FIELD_LINK_FILTER_INDEX);
242
    }
243

  
244
    public Integer getLinkFilterType() {
245
        return (Integer) this.getDynValue(FIELD_LINK_FILTER_TYPE);
246
    }
247

  
248
    public Integer getLinkFilterEntity() {
249
        return (Integer) this.getDynValue(FIELD_LINK_FILTER_ENTITY);
250
    }
251

  
252
    public Integer getLinkFilterMS() {
253
        return (Integer) this.getDynValue(FIELD_LINK_FILTER_MS);
254
    }
255

  
256
    
257
    public boolean ignoreZs() {
258
        Boolean x = (Boolean) this.getDynValue(FIELD_IGNORE_Z);
259
        if (x == null) {
260
            return Boolean.FALSE;
261
        }
262
        return x.booleanValue();
263
    }
264

  
265
    public boolean logErrors() {
266
        Boolean x = (Boolean) this.getDynValue(FIELD_LOGS_ERRORS);
267
        if (x == null) {
268
            return Boolean.FALSE;
269
        }
270
        return x.booleanValue();
271
    }
272

  
273
    public boolean skipCorruptGeometries() {
274
        Boolean x = (Boolean) this.getDynValue(FIELD_SKYPCORRUPTGEOMETRIES_FILTER);
275
        if (x == null) {
276
            return Boolean.FALSE;
277
        }
278
        return x.booleanValue();
279
    }
280

  
281
    boolean useZAsElevation() {
282
        Boolean x = (Boolean) this.getDynValue(FIELD_USE_Z_AS_ELEVATION);
283
        if (x == null) {
284
            return Boolean.FALSE;
285
        }
286
        return x.booleanValue();
287
    }
288

  
289
    boolean force2D() {
290
        Boolean x = (Boolean) this.getDynValue(FIELD_FORZE2D);
291
        if (x == null) {
292
            return Boolean.FALSE;
293
        }
294
        return x.booleanValue();
295
    }
296

  
297
    public boolean sortByGeometryType() {
298
        Boolean x = (Boolean) this.getDynValue(FIELD_SORT_BY_GEOMETRY_TYPE);
299
        if (x == null) {
300
            return Boolean.TRUE;
301
        }
302
        return x.booleanValue();
303
    }
304

  
305
    public void setFile(File file) {
306
        this.setDynValue(FIELD_FILE, file);
307
    }
308

  
309
    public void setFile(String file) {
310
        this.setDynValue(FIELD_FILE, file);
311
    }
312

  
313
    public EditableFeatureType getDefaultFeatureType() {
314
        return null; //TODO ????
315
    }
316

  
317
    public void setDefaultFeatureType(FeatureType defaultFeatureType) {
318
        throw new UnsupportedOperationException();
319
    }
320

  
321
    protected DelegatedDynObject getDelegatedDynObject() {
322
        return parameters;
323
    }
324

  
325

  
326
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/PostProcessFilterOperation.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import java.util.regex.Pattern;
4
import org.apache.commons.lang3.StringUtils;
5
import org.gvsig.fmap.dal.feature.FeatureType;
6
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
7
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_CONTAINS;
8
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_COVEREDBY;
9
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_COVERS;
10
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_CROSSES;
11
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_DISJOINT;
12
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_INTERSECT;
13
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_NONE;
14
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_OVERLAPS;
15
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_TOUCHES;
16
import static org.gvsig.fmap.dal.store.dgn.DGNStoreProvider.CROP_OPERATION_WITHIN;
17
import org.gvsig.fmap.geom.Geometry;
18
import org.gvsig.fmap.geom.GeometryLocator;
19
import org.gvsig.fmap.geom.GeometryManager;
20
import org.gvsig.fmap.geom.primitive.Point;
21
import org.gvsig.fmap.geom.type.GeometryType;
22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

  
25
public class PostProcessFilterOperation {
26

  
27
    private static final Logger logger = LoggerFactory.getLogger(PostProcessFilterOperation.class);
28
            
29
    private Pattern levelFilter = null;
30
    private Pattern colorFilter = null;
31
    private Pattern styleFilter = null;
32
    private Pattern weighFilter = null;
33
    private Pattern typeFilter = null;
34
    private Pattern stypeFilter = null;
35
    private Pattern idFilter = null;
36
    private Pattern groupFilter = null;
37
    private Pattern textFilter = null;
38
    private Point pointForCheckGeometries = null;
39
    private boolean hasfilter = false;
40
    private boolean skipCurruptGeometries = true;
41
    private int geometryTypeFilter = Geometry.TYPES.GEOMETRY;
42
    private int counter_exceptions = 0;
43
    private int cropOperationFilter;
44
    private Geometry cropFilter = null;
45
    private int ID_FIELD_LEVEL = -1;
46
    private int ID_FIELD_COLOR = -1;
47
    private int ID_FIELD_STYLE = -1;
48
    private int ID_FIELD_WEIGHT = -1;
49
    private int ID_FIELD_TYPE = -1;
50
    private int ID_FIELD_STYPE = -1;
51
    private int ID_FIELD_GROUP = -1;
52
    private int ID_FIELD_ID = -1;
53
    private int ID_FIELD_TEXT = -1;
54

  
55
    PostProcessFilterOperation(DGNOpenStoreParameters parameters, FeatureType featureType) {
56
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
57

  
58
        geometryTypeFilter = parameters.getGeometryTypeFilter();
59
        skipCurruptGeometries = parameters.skipCorruptGeometries();
60
        if (!StringUtils.isBlank(parameters.getLevelFilter())) {
61
            this.levelFilter = Pattern.compile(parameters.getLevelFilter());
62
            this.ID_FIELD_LEVEL = featureType.getIndex(DGNStoreProvider.NAME_FIELD_LEVEL);
63
            this.hasfilter = true;
64
        }
65
        if (!StringUtils.isBlank(parameters.getColorFilter())) {
66
            colorFilter = Pattern.compile(parameters.getColorFilter());
67
            this.ID_FIELD_COLOR = featureType.getIndex(DGNStoreProvider.NAME_FIELD_COLOR);
68
            this.hasfilter = true;
69
        }
70
        if (!StringUtils.isBlank(parameters.getStyleFilter())) {
71
            styleFilter = Pattern.compile(parameters.getStyleFilter());
72
            this.ID_FIELD_STYLE = featureType.getIndex(DGNStoreProvider.NAME_FIELD_STYLE);
73
            this.hasfilter = true;
74
        }
75
        if (!StringUtils.isBlank(parameters.getTypeFilter())) {
76
            this.typeFilter = Pattern.compile(parameters.getTypeFilter());
77
            this.ID_FIELD_TYPE = featureType.getIndex(DGNStoreProvider.NAME_FIELD_TYPE);
78
            this.hasfilter = true;
79
        }
80
        if (!StringUtils.isBlank(parameters.getSTypeFilter())) {
81
            this.stypeFilter = Pattern.compile(parameters.getSTypeFilter());
82
            this.ID_FIELD_STYPE = featureType.getIndex(DGNStoreProvider.NAME_FIELD_STYPE);
83
            this.hasfilter = true;
84
        }
85
        if (!StringUtils.isBlank(parameters.getWeightFilter())) {
86
            weighFilter = Pattern.compile(parameters.getWeightFilter());
87
            this.ID_FIELD_WEIGHT = featureType.getIndex(DGNStoreProvider.NAME_FIELD_WEIGHT);
88
            this.hasfilter = true;
89
        }
90
        if (!StringUtils.isBlank(parameters.getGroupFilter())) {
91
            groupFilter = Pattern.compile(parameters.getGroupFilter());
92
            this.ID_FIELD_GROUP = featureType.getIndex(DGNStoreProvider.NAME_FIELD_GROUP);
93
            this.hasfilter = true;
94
        }
95
        if (!StringUtils.isBlank(parameters.getIDFilter())) {
96
            idFilter = Pattern.compile(parameters.getIDFilter());
97
            this.ID_FIELD_ID = featureType.getIndex(DGNStoreProvider.NAME_FIELD_ID);
98
            this.hasfilter = true;
99
        }
100
        if (!StringUtils.isBlank(parameters.getTextFilter())) {
101
            textFilter = Pattern.compile(parameters.getTextFilter());
102
            this.ID_FIELD_TEXT = featureType.getIndex(DGNStoreProvider.NAME_FIELD_TEXT);
103
            this.hasfilter = true;
104
        }
105
        if (this.geometryTypeFilter != Geometry.TYPES.GEOMETRY) {
106
            this.hasfilter = true;
107
        }
108
        this.cropFilter = parameters.getCropFilter();
109
        if (this.cropFilter != null) {
110
            this.hasfilter = true;
111
        }
112
        this.cropOperationFilter = parameters.getCropOperationFilter();
113
        if (this.cropOperationFilter == CROP_OPERATION_NONE) {
114
            this.cropFilter = null;
115
        }
116
        this.pointForCheckGeometries = null;
117
        if (skipCurruptGeometries) {
118
            try {
119
                int geomSubtype = featureType.getDefaultGeometryAttribute().getGeomType().getSubType();
120
                this.pointForCheckGeometries = geomManager.createPoint(1, 1, geomSubtype);
121
                if (geomSubtype == Geometry.SUBTYPES.GEOM3D) {
122
                    this.pointForCheckGeometries.setCoordinateAt(Geometry.DIMENSIONS.Z, 1);
123
                }
124
            } catch (Exception ex) {
125
                this.pointForCheckGeometries = null;
126
            }
127
        }
128
    }
129
    
130
    public boolean hasFilter() {
131
        return this.hasfilter;
132
    }
133

  
134
    private boolean match(Pattern exp, Object value) {
135
        if (value == null) {
136
            return false;
137
        }
138
        return exp.matcher(value.toString()).matches();
139
    }
140

  
141
    public boolean accept(FeatureProvider data) {
142

  
143
        if (!this.hasfilter) {
144
            return true;
145
        }
146

  
147
        Geometry geometry = data.getDefaultGeometry();
148
        if (this.pointForCheckGeometries != null) {
149
            if (geometry != null) {
150
                try {
151
                    this.pointForCheckGeometries.intersects(geometry);
152
                } catch (Exception ex) {
153
                    // Skip geometries with problems
154
                    data.setDefaultGeometry(null);
155
                    geometry = null;
156
                }
157
            }
158
        }
159

  
160
        try {
161
            if (levelFilter!=null && !match(levelFilter, data.get(ID_FIELD_LEVEL))) {
162
                return false;
163
            }
164
            if (colorFilter!=null && !match(colorFilter, data.get(ID_FIELD_COLOR))) {
165
                return false;
166
            }
167
            if (styleFilter!=null && !match(styleFilter, data.get(ID_FIELD_STYLE))) {
168
                return false;
169
            }
170
            if (weighFilter!=null && !match(weighFilter, data.get(ID_FIELD_WEIGHT))) {
171
                return false;
172
            }
173
            if (typeFilter!=null && !match(typeFilter, data.get(ID_FIELD_TYPE))) {
174
                return false;
175
            }
176
            if (stypeFilter!=null && !match(stypeFilter, data.get(ID_FIELD_STYPE))) {
177
                return false;
178
            }
179
            if (groupFilter!=null && !match(groupFilter, data.get(ID_FIELD_GROUP))) {
180
                return false;
181
            }
182
            if (idFilter!=null && !match(idFilter, data.get(ID_FIELD_ID))) {
183
                return false;
184
            }
185
            if (textFilter!=null && !match(textFilter, data.get(ID_FIELD_TEXT))) {
186
                return false;
187
            }
188

  
189
            if (geometry != null) {
190
                if (geometryTypeFilter != Geometry.TYPES.GEOMETRY) {
191
                    GeometryType geomtype = geometry.getGeometryType();
192
                    switch (geometryTypeFilter) {
193
                        case Geometry.TYPES.POINT:
194
                            if (!geomtype.isTypeOf(Geometry.TYPES.POINT)
195
                                    && !geomtype.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
196
                                return false;
197
                            }
198
                            break;
199
                        case Geometry.TYPES.CURVE:
200
                            if (!geomtype.isTypeOf(Geometry.TYPES.CURVE)
201
                                    && !geomtype.isTypeOf(Geometry.TYPES.MULTICURVE)) {
202
                                return false;
203
                            }
204
                            break;
205
                        case Geometry.TYPES.SURFACE:
206
                            if (!geomtype.isTypeOf(Geometry.TYPES.SURFACE)
207
                                    && !geomtype.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
208
                                return false;
209
                            }
210
                            break;
211
                        default:
212
                            break;
213
                    }
214
                }
215
                if (this.cropFilter != null) {
216
                    switch (this.cropOperationFilter) {
217
                        case CROP_OPERATION_CONTAINS:
218
                            if (!this.cropFilter.contains(geometry)) {
219
                                return false;
220
                            }
221
                            break;
222
                        case CROP_OPERATION_COVEREDBY:
223
                            if (!this.cropFilter.coveredBy(geometry)) {
224
                                return false;
225
                            }
226
                            break;
227
                        case CROP_OPERATION_COVERS:
228
                            if (!this.cropFilter.covers(geometry)) {
229
                                return false;
230
                            }
231
                            break;
232
                        case CROP_OPERATION_CROSSES:
233
                            if (!this.cropFilter.crosses(geometry)) {
234
                                return false;
235
                            }
236
                            break;
237
                        case CROP_OPERATION_DISJOINT:
238
                            if (!this.cropFilter.disjoint(geometry)) {
239
                                return false;
240
                            }
241
                            break;
242
                        case CROP_OPERATION_INTERSECT:
243
                            if (!this.cropFilter.intersects(geometry)) {
244
                                return false;
245
                            }
246
                            break;
247
                        case CROP_OPERATION_OVERLAPS:
248
                            if (!this.cropFilter.overlaps(geometry)) {
249
                                return false;
250
                            }
251
                            break;
252
                        case CROP_OPERATION_TOUCHES:
253
                            if (!this.cropFilter.touches(geometry)) {
254
                                return false;
255
                            }
256
                            break;
257
                        case CROP_OPERATION_WITHIN:
258
                            if (!this.cropFilter.within(geometry)) {
259
                                return false;
260
                            }
261
                            break;
262
                    }
263
                }
264
            }
265
        } catch (Exception ex) {
266
            if (++counter_exceptions < 10) {
267
                logger.warn("Can't filter data, accept it.", ex);
268
            } else if (counter_exceptions == 10) {
269
                logger.warn("Can't filter data, accept it.", ex);
270
                logger.warn("Too many exceptions, dont show more.");
271
            }
272
            return true;
273
        }
274
        return true;
275
    }
276

  
277
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27

  
28
package org.gvsig.fmap.dal.store.dgn;
29

  
30
import java.util.ArrayList;
31
import java.util.List;
32

  
33
import org.gvsig.fmap.dal.DALFileLibrary;
34
import org.gvsig.fmap.dal.DALFileLocator;
35
import org.gvsig.fmap.dal.DALLibrary;
36
import org.gvsig.fmap.dal.DALLocator;
37
import org.gvsig.fmap.dal.FileHelper;
38
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
39
import org.gvsig.metadata.MetadataLibrary;
40
import org.gvsig.metadata.exceptions.MetadataException;
41
import org.gvsig.tools.library.AbstractLibrary;
42
import org.gvsig.tools.library.LibraryException;
43

  
44
public class DGNLibrary extends AbstractLibrary {
45

  
46
    @Override
47
    public void doRegistration() {
48
        registerAsServiceOf(DALLibrary.class);
49
        require(DALFileLibrary.class);
50
        require(MetadataLibrary.class);
51
    }
52

  
53
	@Override
54
	protected void doInitialize() throws LibraryException {
55
	}
56

  
57
	@Override
58
	protected void doPostInitialize() throws LibraryException {
59
		List<Throwable> exs = new ArrayList<Throwable>();
60
				
61
		FileHelper.registerParametersDefinition(
62
				DGNOpenStoreParameters.PARAMETERS_DEFINITION_NAME, 
63
				DGNOpenStoreParameters.class,
64
				"DGNParameters.xml"
65
		);
66
		try {
67
			FileHelper.registerMetadataDefinition(
68
					DGNStoreProvider.METADATA_DEFINITION_NAME, 
69
					DGNStoreProvider.class,
70
					"DGNMetadata.xml"
71
			);
72
		} catch (MetadataException e) {
73
			exs.add(e);
74
		}
75

  
76
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator
77
				.getDataManager();
78

  
79
		try {
80
			if (!dataman.getStoreProviders().contains(DGNStoreProvider.NAME)) {
81
				dataman.registerStoreProviderFactory(new DGNStoreProviderFactory(DGNStoreProvider.NAME, DGNStoreProvider.DESCRIPTION));
82
			}
83
		} catch (RuntimeException e) {
84
			exs.add(e);
85
		}
86

  
87
		try {
88
			DALFileLocator.getFilesystemServerExplorerManager()
89
					.registerProvider(DGNStoreProvider.NAME,
90
							DGNStoreProvider.DESCRIPTION,
91
							DGNFilesystemServerProvider.class);
92
		} catch (RuntimeException e) {
93
			exs.add(e);
94
		}
95

  
96
		if( exs.size()>0 ) {
97
			throw new LibraryException(this.getClass(), exs);
98
		}
99
	}
100
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNFilesystemServerProvider.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import java.io.File;
4

  
5
import org.gvsig.fmap.dal.DataServerExplorer;
6
import org.gvsig.fmap.dal.DataStoreParameters;
7
import org.gvsig.fmap.dal.NewDataStoreParameters;
8
import org.gvsig.fmap.dal.exception.CreateException;
9
import org.gvsig.fmap.dal.exception.DataException;
10
import org.gvsig.fmap.dal.exception.FileNotFoundException;
11
import org.gvsig.fmap.dal.exception.RemoveException;
12
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
13
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
14
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
15
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
16
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
17

  
18
public class DGNFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider
19
        implements FilesystemServerExplorerProvider, ResourceConsumer {
20

  
21
    @Override
22
    public String getDataStoreProviderName() {
23
        return DGNStoreProvider.NAME;
24
    }
25

  
26
    @Override
27
    public int getMode() {
28
        return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY;
29
    }
30

  
31
    @Override
32
    public boolean accept(File pathname) {
33
        return (pathname.getName().toLowerCase().endsWith(".dgn"));
34
    }
35

  
36
    @Override
37
    public String getDescription() {
38
        return DGNStoreProvider.DESCRIPTION;
39
    }
40

  
41
    @Override
42
    public boolean canCreate() {
43
        return false;
44
    }
45

  
46
    @Override
47
    public boolean canCreate(NewDataStoreParameters parameters) {
48
        return false;
49
    }
50

  
51
    @Override
52
    public void create(NewDataStoreParameters parameters, boolean overwrite)
53
            throws CreateException {
54
        throw new UnsupportedOperationException();
55
    }
56

  
57
    @Override
58
    public NewDataStoreParameters getCreateParameters() throws DataException {
59
        return null;
60
    }
61

  
62
    @Override
63
    public void initialize(
64
            FilesystemServerExplorerProviderServices serverExplorer) {
65
    }
66

  
67
    @Override
68
    public void remove(DataStoreParameters parameters) throws RemoveException {
69
        File file = new File(((DGNOpenStoreParameters) parameters).getFileName());
70
        if (!file.exists()) {
71
            throw new RemoveException(this.getDataStoreProviderName(),
72
                    new FileNotFoundException(file));
73
        }
74
        if (!file.delete()) {
75
            // FIXME throws ???
76
        }
77

  
78
    }
79

  
80
    @Override
81
    public boolean closeResourceRequested(ResourceProvider resource) {
82
        // while it is using a resource anyone can't close it
83
        return false;
84
    }
85

  
86
    @Override
87
    public void resourceChanged(ResourceProvider resource) {
88
        //Do nothing
89
    }
90

  
91
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.110/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNStoreProvider.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import java.awt.geom.AffineTransform;
4
import java.awt.geom.Arc2D;
5
import java.awt.geom.PathIterator;
6
import java.io.BufferedWriter;
7
import java.io.File;
8
import java.io.FileWriter;
9
import java.io.IOException;
10
import java.util.ArrayList;
11
import java.util.Date;
12
import java.util.HashMap;
13
import java.util.Iterator;
14
import java.util.List;
15
import java.util.Map;
16

  
17
import org.apache.commons.io.IOUtils;
18
import org.cresques.cts.IProjection;
19
import org.slf4j.Logger;
20
import org.slf4j.LoggerFactory;
21

  
22
import org.gvsig.fmap.dal.DALLocator;
23
import org.gvsig.fmap.dal.DataManager;
24
import org.gvsig.fmap.dal.DataServerExplorer;
25
import org.gvsig.fmap.dal.DataStoreNotification;
26
import org.gvsig.fmap.dal.DataTypes;
27
import org.gvsig.fmap.dal.FileHelper;
28
import org.gvsig.fmap.dal.exception.DataException;
29
import org.gvsig.fmap.dal.exception.InitializeException;
30
import org.gvsig.fmap.dal.exception.LoadException;
31
import org.gvsig.fmap.dal.exception.OpenException;
32
import org.gvsig.fmap.dal.exception.ReadException;
33
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
34
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
35
import org.gvsig.fmap.dal.feature.EditableFeatureType;
36
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
37
import org.gvsig.fmap.dal.feature.FeatureType;
38
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
39
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
40
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
41
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider;
42
import org.gvsig.fmap.dal.resource.ResourceAction;
43
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
44
import org.gvsig.fmap.dal.resource.file.FileResource;
45
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
46
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
47
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
48
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
49
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
50
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemArc;
51
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemComplexHeader;
52
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemCore;
53
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemMultiPoint;
54
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemText;
55
import org.gvsig.fmap.dal.store.dgn.lib.DGNFileHeader;
56
import org.gvsig.fmap.dal.store.dgn.lib.DGNLink;
57
import org.gvsig.fmap.dal.store.dgn.lib.DGNPoint;
58
import org.gvsig.fmap.dal.store.dgn.lib.DGNReader;
59
import org.gvsig.fmap.geom.Geometry;
60
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
61
import org.gvsig.fmap.geom.Geometry.TYPES;
62
import org.gvsig.fmap.geom.GeometryLocator;
63
import org.gvsig.fmap.geom.GeometryManager;
64
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
65
import org.gvsig.fmap.geom.exception.CreateGeometryException;
66
import org.gvsig.fmap.geom.primitive.Envelope;
67
import org.gvsig.fmap.geom.primitive.GeneralPathX;
68
import org.gvsig.fmap.geom.primitive.IGeneralPathX;
69
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
70
import org.gvsig.fmap.geom.primitive.Point;
71
import org.gvsig.fmap.geom.type.GeometryType;
72
import org.gvsig.tools.dynobject.exception.DynMethodException;
73

  
74
public class DGNStoreProvider extends AbstractMemoryStoreProvider implements
75
    ResourceConsumer {
76

  
77
    private static final Logger logger = LoggerFactory.getLogger(DGNStoreProvider.class);
78

  
79
    public static final String NAME = "DGN";
80
    public static final String DESCRIPTION = "DGN file";
81

  
82
    public static final String METADATA_DEFINITION_NAME = NAME;
83
    public static final String METADATA_DEFINITION_DESCRIPTION = "DGN File Store";
84

  
85
    public static final int LOAD_MODE_PLAIN = 0;
86
    public static final int LOAD_MODE_GROUP1 = 1;
87

  
88
    public static final int CROP_OPERATION_NONE = 0;
89
    public static final int CROP_OPERATION_CONTAINS = 1;
90
    public static final int CROP_OPERATION_COVERS = 2;
91
    public static final int CROP_OPERATION_COVEREDBY = 3;
92
    public static final int CROP_OPERATION_CROSSES = 4;
93
    public static final int CROP_OPERATION_DISJOINT = 5;
94
    public static final int CROP_OPERATION_INTERSECT = 6;
95
    public static final int CROP_OPERATION_OVERLAPS = 7;
96
    public static final int CROP_OPERATION_TOUCHES = 8;
97
    public static final int CROP_OPERATION_WITHIN = 9;
98

  
99
    public static final int GROUP_GEOMETRIES_NONE = 0;
100
    public static final int GROUP_GEOMETRIES_CONVEXHULL = 1;
101
    public static final int GROUP_GEOMETRIES_UNION = 2;
102
    public static final int GROUP_GEOMETRIES_INTERSECTION = 3;
103
    public static final int GROUP_GEOMETRIES_TOPOINTS = 4;
104
    public static final int GROUP_GEOMETRIES_TOLINES = 5;
105
    public static final int GROUP_GEOMETRIES_TOPOLYGONS = 6;
106
    public static final int GROUP_GEOMETRIES_TOPOLYGONS_FIX = 7;
107

  
108
    public static final String NAME_FIELD_ID = "ID";
109
    public static final String NAME_FIELD_GEOMETRY = "Geometry";
110
    public static final String NAME_FIELD_TYPE = "Type";
111
    public static final String NAME_FIELD_STYPE = "SType";
112
    public static final String NAME_FIELD_ENTITY = "Entity";
113
    public static final String NAME_FIELD_LEVEL = "Layer";
114
    public static final String NAME_FIELD_COLOR = "Color";
115
    public static final String NAME_FIELD_FILLCOLOR = "FillColor";
116
    public static final String NAME_FIELD_ELEVATION = "Elevation";
117
    public static final String NAME_FIELD_WEIGHT = "Weight";
118
    public static final String NAME_FIELD_TEXT = "Text";
119
    public static final String NAME_FIELD_HEIGHTTEXT = "HeightText";
120
    public static final String NAME_FIELD_HEIGHTTEXTRAW = "HeightTextRaw";
121
    public static final String NAME_FIELD_ROTATIONTEXT = "Rotation";
122
    public static final String NAME_FIELD_STYLE = "Style";
123
    public static final String NAME_FIELD_GROUP = "Group";
124
    public static final String NAME_FIELD_ISSHAPE = "IsShape";
125
    public static final String NAME_FIELD_ISCOMPLEXSHAPEHEADER = "IsComplexShapeHeader";
126
    public static final String NAME_FIELD_ISHOLE = "IsHole";
127
    public static final String NAME_FIELD_ISCOMPLEX = "IsComplex";
128
    public static final String NAME_FIELD_PARENTID = "ParentId";
129
    public static final String NAME_FIELD_SCALE = "Scale";
130
    public static final String NAME_FIELD_LINKS_COUNT = "LinksCount";
131
    public static final String NAME_FIELD_LINK_INDEX = "LinkIndex";
132
    public static final String NAME_FIELD_LINK_TYPE = "LinkType";
133
    public static final String NAME_FIELD_LINK_ENTITY = "LinkEntity";
134
    public static final String NAME_FIELD_LINK_MS = "LinkMS";
135
    public static final String NAME_FIELD_LINK_LENGTH = "LinkLength";
136
    public static final String NAME_FIELD_LINK_DATA = "LinkData";
137
    public static final String NAME_FIELD_DATA = "Data";
138

  
139
    private int ID_FIELD_ID;
140
    private int ID_FIELD_TYPE;
141
    private int ID_FIELD_STYPE;
142
    private int ID_FIELD_ENTITY;
143
    private int ID_FIELD_LEVEL;
144
    private int ID_FIELD_COLOR;
145
    private int ID_FIELD_FILLCOLOR;
146
    private int ID_FIELD_ELEVATION;
147
    private int ID_FIELD_WEIGHT;
148
    private int ID_FIELD_TEXT;
149
    private int ID_FIELD_HEIGHTTEXT;
150
    private int ID_FIELD_HEIGHTTEXTRAW;
151
    private int ID_FIELD_ROTATIONTEXT;
152
    private int ID_FIELD_STYLE;
153
    private int ID_FIELD_GROUP;
154
    private int ID_FIELD_LAYER;
155
    private int ID_FIELD_ISCOMPLEXSHAPEHEADER;
156
    private int ID_FIELD_ISSHAPE;
157
    private int ID_FIELD_ISHOLE;
158
    private int ID_FIELD_ISCOMPLEX;
159
    private int ID_FIELD_PARENT;
160
    private int ID_FIELD_SCALE;
161
    private int ID_FIELD_LINKS_COUNT;
162
    private int ID_FIELD_LINK_INDEX;
163
    private int ID_FIELD_LINK_TYPE;
164
    private int ID_FIELD_LINK_ENTITY;
165
    private int ID_FIELD_LINK_MS;
166
    private int ID_FIELD_LINK_LENGTH;
167
    private int ID_FIELD_LINK_DATA;
168
    private int ID_FIELD_DATA;
169
    private int ID_FIELD_GEOMETRY;
170
    private int MAX_FIELD_ID;
171

  
172
    private IProjection projection;
173
    private ResourceProvider resource;
174
    private LegendBuilder legendBuilder;
175

  
176
    private long counterNewsOIDs = 0;
177
    protected GeometryManager geomManager = GeometryLocator
178
        .getGeometryManager();
179

  
180
    private int groupByFieldIndex = -2;
181
    private Map<Object, FeatureProvider> groupedFeatures = null;
182

  
183
    DGNData dgndata = null;
184

  
185
    public DGNStoreProvider(DGNOpenStoreParameters parameters,
186
        DataStoreProviderServices storeServices) throws InitializeException {
187
        super(parameters, storeServices, FileHelper
188
            .newMetadataContainer(METADATA_DEFINITION_NAME));
189

  
190
        counterNewsOIDs = 0;
191
        // projection = CRSFactory.getCRS(getParameters().getSRSID());
192

  
193
        File file = getDGNParameters().getFile();
194
        resource =
195
            this.createResource(FileResource.NAME,
196
                new Object[] { file.getAbsolutePath() });
197

  
198
        resource.addConsumer(this);
199

  
200
        this.projection = this.getDGNParameters().getCRS();
201

  
202
        try {
203
            legendBuilder =
204
                (LegendBuilder) this.invokeDynMethod(
205
                    LegendBuilder.DYNMETHOD_BUILDER_NAME, null);
206
        } catch (DynMethodException e) {
207
            legendBuilder = null;
208
        } catch (Exception e) {
209
            throw new InitializeException(e);
210
        }
211

  
212
        this.initializeFeatureTypes();
213

  
214
    }
215

  
216
    private DGNOpenStoreParameters getDGNParameters() {
217
        return (DGNOpenStoreParameters) this.getParameters();
218
    }
219

  
220
    public String getProviderName() {
221
        return NAME;
222
    }
223

  
224
    public boolean allowWrite() {
225
        // not yet
226
        return false;
227
    }
228

  
229
    public Object getLegend() throws OpenException {
230
        this.open();
231
        if (legendBuilder == null) {
232
            return null;
233
        }
234
        return legendBuilder.getLegend();
235
    }
236

  
237
    public Object getLabeling() throws OpenException {
238
        this.open();
239
        if (legendBuilder == null) {
240
            return null;
241
        }
242
        return legendBuilder.getLabeling();
243
    }
244

  
245
    private class DGNData {
246

  
247
        public List<FeatureProvider> data = null;
248
        public FeatureType defaultFType = null;
249
        public List<FeatureType> fTypes = null;
250
        public Envelope envelope = null;
251
        public IProjection projection;
252
        public LegendBuilder legendBuilder;
253

  
254
        public Envelope getEnvelopeCopy() throws CreateEnvelopeException {
255
            if (envelope == null) {
256
                return null;
257
            }
258
            try {
259
                return (Envelope) envelope.clone();
260
            } catch (CloneNotSupportedException ex) {
261
                logger.warn("Can't clone envelope.", ex);
262
                return null;
263
            }
264
        }
265
    }
266

  
267
    public static class TimeCounter {
268

  
269
        private static final Logger logger = LoggerFactory
270
            .getLogger(TimeCounter.class);
271

  
272
        private long counter = 0;
273
        private Date t1;
274
        private Date t2;
275

  
276
        public void start() {
277
            this.t1 = new Date();
278
            this.t2 = this.t1;
279
        }
280

  
281
        public void restart() {
282
            this.t1 = new Date();
283
            this.t2 = this.t1;
284
            this.counter = 0;
285
        }
286

  
287
        public void stop() {
288
            this.t2 = new Date();
289
            this.counter += this.t2.getTime() - this.t1.getTime();
290
        }
291

  
292
        public long get() {
293
            return this.counter;
294
        }
295

  
296
        public void log(String msg) {
297
            logger.debug("Time " + get() + " ms. " + msg);
298
        }
299

  
300
        public void restart(String msg) {
301
            this.stop();
302
            this.log(msg);
303
            this.restart();
304
        }
305
    }
306

  
307
    public void open() throws OpenException {
308
        if (this.data != null) {
309
            return;
310
        }
311
        try {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff