Revision 90

View differences:

org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNGetLabeling.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.legend;
29

  
30
import org.gvsig.fmap.dal.exception.OpenException;
31
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
32
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynClass;
35
import org.gvsig.tools.dynobject.DynMethod;
36
import org.gvsig.tools.dynobject.DynObject;
37
import org.gvsig.tools.dynobject.DynObjectManager;
38
import org.gvsig.tools.dynobject.exception.DynMethodException;
39
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
40

  
41
public class DGNGetLabeling implements DynMethod {
42
	private static int code = DynObjectManager.NULLCODE;
43

  
44
	static void register(DynClass DGNDynClass) {
45
		if (code != DynObjectManager.NULLCODE) {
46
			return;
47
		}
48
		code = ToolsLocator.getDynObjectManager().registerDynMethod(
49
			DGNDynClass, 
50
			new DGNGetLabeling()
51
		);
52

  
53
	}
54
	public int getCode() throws DynMethodNotSupportedException {
55
		return code;
56
	}
57

  
58
	public String getDescription() {
59
		return "DGN Labeling";
60
	}
61

  
62
	public String getName() {
63
		return LegendBuilder.DYNMETHOD_GETLABELING_NAME;
64
	}
65

  
66
	public Object invoke(Object self, DynObject context)
67
			throws DynMethodException {
68
		try {
69
			return ((DGNStoreProvider) self).getLabeling();
70
		} catch (OpenException e) {
71
			//FIXME
72
			throw new RuntimeException(e);
73
		}
74
	}
75

  
76
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNGetLegend.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.legend;
29

  
30
import org.gvsig.fmap.dal.exception.OpenException;
31
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
32
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.dynobject.DynClass;
35
import org.gvsig.tools.dynobject.DynMethod;
36
import org.gvsig.tools.dynobject.DynObject;
37
import org.gvsig.tools.dynobject.DynObjectManager;
38
import org.gvsig.tools.dynobject.exception.DynMethodException;
39
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
40

  
41
public class DGNGetLegend implements DynMethod {
42
	private static int code = DynObjectManager.NULLCODE;
43

  
44
	static void register(DynClass DGNDynClass) {
45
		if (code != DynObjectManager.NULLCODE) {
46
			return;
47
		}
48
		code = ToolsLocator.getDynObjectManager().registerDynMethod(
49
			DGNDynClass, 
50
			new DGNGetLegend()
51
		);
52

  
53
	}
54
	public int getCode() throws DynMethodNotSupportedException {
55
		return code;
56
	}
57

  
58
	public String getDescription() {
59
		return "DGN Legend";
60
	}
61

  
62
	public String getName() {
63
		return LegendBuilder.DYNMETHOD_GETLEGEND_NAME;
64
	}
65

  
66
	public Object invoke(Object self, DynObject context)
67
			throws DynMethodException {
68
		try {
69
			return ((DGNStoreProvider) self).getLegend();
70
		} catch (OpenException e) {
71
			throw new RuntimeException(e);
72
		}
73
	}
74

  
75
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNLegendLibrary.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
/**
29
 *
30
 */
31
package org.gvsig.fmap.dal.store.dgn.legend;
32

  
33
import org.gvsig.fmap.dal.DALLibrary;
34
import org.gvsig.fmap.dal.store.dgn.DGNLibrary;
35
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
36
import org.gvsig.metadata.MetadataLibrary;
37
import org.gvsig.metadata.MetadataLocator;
38
import org.gvsig.tools.dynobject.DynClass;
39
import org.gvsig.tools.library.AbstractLibrary;
40
import org.gvsig.tools.library.LibraryException;
41

  
42
/**
43
 * @author jmvivo
44
 *
45
 */
46
public class DGNLegendLibrary extends AbstractLibrary {
47

  
48
    @Override
49
    public void doRegistration() {
50
        registerAsServiceOf(DALLibrary.class);
51
        require(DGNLibrary.class);
52
        require(MetadataLibrary.class);
53
    }
54

  
55
	@Override
56
	protected void doInitialize() throws LibraryException {
57
	}
58

  
59
	@Override
60
	protected void doPostInitialize() throws LibraryException {
61
		DynClass metadataDefinition = (DynClass) MetadataLocator.getMetadataManager()
62
			.getDefinition(DGNStoreProvider.METADATA_DEFINITION_NAME);
63
		DGNGetLegendBuilder.register(metadataDefinition);
64
		DGNGetLegend.register(metadataDefinition);
65
		DGNGetLabeling.register(metadataDefinition);
66
	}
67
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNGetLegendBuilder.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.legend;
29

  
30
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.dynobject.DynClass;
33
import org.gvsig.tools.dynobject.DynMethod;
34
import org.gvsig.tools.dynobject.DynObject;
35
import org.gvsig.tools.dynobject.DynObjectManager;
36
import org.gvsig.tools.dynobject.exception.DynMethodException;
37
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
38

  
39
public class DGNGetLegendBuilder implements DynMethod {
40
	private static int code = DynObjectManager.NULLCODE;
41

  
42
	static void register(DynClass DGNDynClass) {
43
		if (code != DynObjectManager.NULLCODE) {
44
			return;
45
		}
46
		code = ToolsLocator.getDynObjectManager().registerDynMethod(
47
			DGNDynClass, 
48
			new DGNGetLegendBuilder()
49
		);
50

  
51
	}
52
	
53
	public int getCode() throws DynMethodNotSupportedException {
54
		return code;
55
	}
56

  
57
	public String getDescription() {
58
		return "DGN LegendBuilder creator";
59
	}
60

  
61
	public String getName() {
62
		return LegendBuilder.DYNMETHOD_BUILDER_NAME;
63
	}
64

  
65
	public Object invoke(Object self, DynObject context)
66
			throws DynMethodException {
67
		return new DGNLegendBuilder();
68
	}
69

  
70
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dgn/legend/DGNLegendBuilder.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.legend;
29

  
30
import java.awt.Color;
31

  
32
import org.gvsig.fmap.dal.DataTypes;
33
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
34
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
35
import org.gvsig.fmap.dal.store.dgn.DGNStoreProvider;
36
import org.gvsig.fmap.dal.store.dgn.LegendBuilder;
37
import org.gvsig.fmap.dal.store.dgn.lib.DGNReader;
38
import org.gvsig.fmap.geom.Geometry;
39
import org.gvsig.fmap.mapcontext.MapContextLocator;
40
import org.gvsig.fmap.mapcontext.MapContextManager;
41
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
43
import org.gvsig.symbology.SymbologyLocator;
44
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy;
45
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
46
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
47
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
48

  
49
public class DGNLegendBuilder implements LegendBuilder {
50

  
51
	private MapContextManager mapContextManager = MapContextLocator
52
			.getMapContextManager();
53

  
54
	private IVectorialUniqueValueLegend defaultLegend = null;
55
	private IAttrInTableLabelingStrategy labelingStragegy = null;
56

  
57
	public void begin() {
58
		// Nothing to do
59
	}
60

  
61
	public void end() {
62
		// Nothing to do
63
	}
64

  
65
	public Object getLegend() {
66
		return defaultLegend;
67
	}
68

  
69
	public LegendBuilder initialize(FeatureStoreProvider store) {
70
		defaultLegend = (IVectorialUniqueValueLegend) mapContextManager.createLegend(
71
						IVectorialUniqueValueLegend.LEGEND_NAME);
72
		defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY);
73
		defaultLegend
74
				.setClassifyingFieldNames(new String[] { DGNStoreProvider.NAME_FIELD_COLOR });
75
		defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT });
76

  
77
		ISymbol myDefaultSymbol =
78
				mapContextManager.getSymbolManager()
79
				.createSymbol(Geometry.TYPES.GEOMETRY); 
80

  
81
		defaultLegend.setDefaultSymbol(myDefaultSymbol);
82
		defaultLegend.useDefaultSymbol(true);
83

  
84
		labelingStragegy = SymbologyLocator.getSymbologyManager().createAttrInTableLabelingStrategy();
85
		labelingStragegy.setTextField(DGNStoreProvider.NAME_FIELD_TEXT);
86
		labelingStragegy
87
				.setRotationField(DGNStoreProvider.NAME_FIELD_ROTATIONTEXT);
88
		labelingStragegy.setHeightField(DGNStoreProvider.NAME_FIELD_HEIGHTTEXT);
89
		labelingStragegy.setUnit(1); // MapContext.NAMES[1] (meters)
90
		return this;
91
	}
92

  
93
	public void process(FeatureProvider feature, DGNReader dgnReader) {
94
		Integer clave = (Integer) feature.get("Color");
95
		if (clave == null) {
96
			return;
97
		}
98

  
99
		defaultLegend.useDefaultSymbol(false);
100
		if (defaultLegend.getSymbolByValue(clave) == null) {
101
			ISymbol theSymbol;
102
			Color color = dgnReader.DGNLookupColor(clave.intValue());
103
			theSymbol =
104
					mapContextManager.getSymbolManager().createSymbol(
105
					Geometry.TYPES.GEOMETRY, color); 
106

  
107
			theSymbol.setDescription(clave.toString());
108

  
109
			if (theSymbol instanceof IMarkerSymbol) {
110
				((IMarkerSymbol) theSymbol).setSize(1);
111
			}
112

  
113
			if (theSymbol instanceof ILineSymbol) {
114
				ILineSymbol lineSymbol = (ILineSymbol) theSymbol;
115
				lineSymbol.setLineWidth(1);
116
				lineSymbol.setLineColor(color);
117
			}
118

  
119
			if (theSymbol instanceof IFillSymbol) {
120
				IFillSymbol fillSymbol = (IFillSymbol) theSymbol;
121
				fillSymbol.getOutline().setLineColor(color);
122
				fillSymbol.getOutline().setLineWidth(1);
123
				fillSymbol.setFillColor(null);
124
			}
125
			if (theSymbol != null) {
126
				defaultLegend.addSymbol(clave, theSymbol);
127
			}
128
		}
129
	}
130

  
131
	public Object getLabeling() {
132
		return labelingStragegy;
133
	}
134

  
135

  
136
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider.legend/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
  <modelVersion>4.0.0</modelVersion>
4
  <artifactId>org.gvsig.dgn.provider.legend</artifactId>
5
  <packaging>jar</packaging>
6
  <name>${project.artifactId}</name>
7
  <description>DAL provider for DGN files</description>
8
  <parent>
9
      <groupId>org.gvsig</groupId>
10
      <artifactId>org.gvsig.dgn</artifactId>
11
      <version>2.0.25</version>
12
  </parent>
13

  
14
  <dependencies>
15

  
16
    <dependency>
17
      <groupId>org.gvsig</groupId>
18
      <artifactId>org.gvsig.dgn.provider</artifactId>
19
      <scope>compile</scope>
20
    </dependency>
21

  
22
    <dependency>
23
      <groupId>commons-io</groupId>
24
      <artifactId>commons-io</artifactId>
25
      <scope>compile</scope>
26
    </dependency>
27

  
28
    <dependency>
29
        <groupId>org.gvsig</groupId>
30
        <artifactId>org.gvsig.tools.lib</artifactId>
31
        <scope>compile</scope>
32
    </dependency>
33
    <dependency>
34
        <groupId>org.gvsig</groupId>
35
        <artifactId>org.gvsig.projection.api</artifactId>
36
        <scope>compile</scope>
37
    </dependency>
38
    <dependency>
39
        <groupId>org.gvsig</groupId>
40
        <artifactId>org.gvsig.fmap.dal.api</artifactId>
41
        <scope>compile</scope>
42
    </dependency>
43
    <dependency>
44
        <groupId>org.gvsig</groupId>
45
        <artifactId>org.gvsig.fmap.dal.spi</artifactId>
46
        <scope>compile</scope>
47
    </dependency>
48
    <dependency>
49
        <groupId>org.gvsig</groupId>
50
        <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
51
        <scope>compile</scope>
52
    </dependency>
53
    <dependency>
54
        <groupId>org.gvsig</groupId>
55
        <artifactId>org.gvsig.fmap.geometry.api</artifactId>
56
        <scope>compile</scope>
57
    </dependency>
58
    <dependency>
59
        <groupId>org.gvsig</groupId>
60
        <artifactId>org.gvsig.fmap.mapcontext.api</artifactId>
61
        <scope>compile</scope>
62
    </dependency>
63

  
64
    <dependency>
65
        <groupId>org.gvsig</groupId>
66
        <artifactId>org.gvsig.symbology.lib.api</artifactId>
67
        <scope>compile</scope>
68
    </dependency>
69
    <dependency>
70
        <groupId>org.gvsig</groupId>
71
        <artifactId>org.gvsig.timesupport.lib.api</artifactId>
72
        <scope>compile</scope>
73
    </dependency>  
74
    <dependency>
75
      <groupId>org.gvsig</groupId>
76
      <artifactId>org.gvsig.utils</artifactId>
77
      <scope>compile</scope>
78
    </dependency>
79

  
80

  
81
    <!-- TESTS -->
82
    <dependency>
83
      <groupId>org.gvsig</groupId>
84
      <artifactId>org.gvsig.tools.lib</artifactId>
85
      <type>test-jar</type>
86
      <scope>test</scope>
87
    </dependency>
88
    <dependency>
89
      <groupId>org.gvsig</groupId>
90
      <artifactId>org.gvsig.compat.se</artifactId>
91
      <scope>test</scope>
92
    </dependency>
93
    <dependency>
94
      <groupId>org.gvsig</groupId>
95
      <artifactId>org.gvsig.fmap.dal.impl</artifactId>
96
      <scope>test</scope>
97
    </dependency>
98
    <dependency>
99
      <groupId>org.gvsig</groupId>
100
      <artifactId>org.gvsig.fmap.geometry.impl</artifactId>
101
      <scope>test</scope>
102
    </dependency>
103
    <dependency>
104
      <groupId>org.gvsig</groupId>
105
      <artifactId>org.gvsig.projection.cresques.impl</artifactId>
106
      <scope>test</scope>
107
    </dependency>
108
    <dependency>
109
      <groupId>org.gvsig</groupId>
110
      <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
111
      <scope>test</scope>
112
    </dependency>   
113

  
114

  
115
  </dependencies>
116

  
117
</project>
0 118

  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/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

  
32
import org.gvsig.fmap.dal.DataStoreParameters;
33
import org.gvsig.fmap.dal.exception.DataException;
34
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore;
35
import org.gvsig.fmap.dal.feature.FeatureStore;
36

  
37
public class TestDGN extends BaseTestFeatureStore {
38

  
39
	public static final File file_prueba = new File(TestDGN.class.getResource(
40
			"data/prueba.dgn").getFile());
41
	
42
	/*
43
	 * (non-Javadoc)
44
	 *
45
	 * @see
46
	 * org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters
47
	 * ()
48
	 */
49
	public DataStoreParameters getDefaultDataStoreParameters()
50
			throws DataException {
51
		DGNStoreParameters dgnParameters = null;
52

  
53
		dgnParameters = (DGNStoreParameters) dataManager
54
				.createStoreParameters(DGNStoreProvider.NAME);
55

  
56
		dgnParameters.setFile(file_prueba.getAbsolutePath());
57
		dgnParameters.setCRS("EPSG:23030");
58
		return dgnParameters;
59
	}
60

  
61
	/*
62
	 * (non-Javadoc)
63
	 *
64
	 * @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer()
65
	 */
66
	public boolean hasExplorer() {
67
		// TODO Auto-generated method stub
68
		return false;
69
	}
70

  
71
	public boolean usesResources() {
72
		return true;
73
	}
74

  
75

  
76
	public void testLegendAndLabeling() throws Exception {
77
		FeatureStore store = (FeatureStore) dataManager
78
				.createStore(getDefaultDataStoreParameters());
79

  
80
		assertNotNull(store.invokeDynMethod("getLegend", null));
81
		assertNotNull(store.invokeDynMethod("getLabeling", null));
82
		store.dispose();
83
	}
84
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/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.25/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="ignoreZ" label="Ignore Z" type="Boolean" defaultValue="false" mandatory="false">
30
          <description>If checked and DGN has Z dimension, set all Zs to 0.</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="applyConvexHull" label="Apply convex hull" type="boolean" defaultValue="false" mandatory="false">
39
          <description>Apply convex hull to the grouped geometries.Don't take effect if do not group.</description>
40
        </field>
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

  
54
        <!-- Filter -->
55
        <field name="levelFilter" label="Level" group="Filter" type="String" defaultValue="" mandatory="false">
56
          <description>If specified load only elements with this level. Can use regular expresion to specify the filter.</description>
57
        </field>
58
        <field name="colorFilter" label="Color" group="Filter" type="String" defaultValue="" mandatory="false">
59
          <description>If specified load only elements with this color. Can use regular expresion to specify the filter.</description>
60
        </field>
61
        <field name="styleFilter" label="Style" group="Filter" type="String" defaultValue="" mandatory="false">
62
          <description>If specified load only elements with this style. Can use regular expresion to specify the filter.</description>
63
        </field>
64
        <field name="weightFilter" label="Weight" group="Filter" type="String" defaultValue="" mandatory="false">
65
          <description>If specified load only elements with this weight. Can use regular expresion to specify the filter.</description>
66
        </field>
67
        <field name="typeFilter" label="Type" group="Filter" type="String" defaultValue="" mandatory="false">
68
          <description>If specified load only elements with this type</description>
69
        </field>
70
        <field name="stypeFilter" label="SType" group="Filter" type="String" defaultValue="" mandatory="false">
71
          <description>If specified load only elements with this stype</description>
72
        </field>
73
        <field name="groupFilter" label="Group" group="Filter" type="String" defaultValue="" mandatory="false">
74
          <description>If specified load only elements with this group</description>
75
        </field>
76
        <field name="idFilter" label="Id" group="Filter" type="String" defaultValue="" mandatory="false">
77
          <description>If specified load only elements with this id</description>
78
        </field>
79
        <field name="textFilter" label="Text" group="Filter" type="String" defaultValue="" mandatory="false">
80
          <description>If specified load only elements that match this text</description>
81
        </field>
82
        <field name="geomtypeFilter" label="Geometry type" group="Filter" defaultValue="0" type="Integer" mandatory="false">
83
          <description>If specified load only elements with this type of geometry</description>
84
     	  <availableValues>
85
            <value label="All">0</value>
86
            <value label="Points">1</value>
87
            <value label="Lines">2</value>
88
            <value label="Poligons">3</value>
89
     	  </availableValues>
90
        </field>
91
        <field name="skipCorruptGeometries" label="Skip corrupt geometries" group="Filter" type="Boolean" defaultValue="false" mandatory="false">
92
          <description>If specified skip corrupt geometries</description>
93
        </field>
94
        <field name="cropOperationFilter" label="Crop operation" group="Filter" defaultValue="1" type="Integer" mandatory="false">
95
          <description>If specified load only elements with this type of geometry</description>
96
     	  <availableValues>
97
            <value label="None">0</value>
98
            <value label="Contains">1</value>
99
            <value label="Covered by">2</value>
100
            <value label="Covers">3</value>
101
            <value label="Crosses">4</value>
102
            <value label="Disjoint">5</value>
103
            <value label="Intersect">6</value>
104
            <value label="Overlaps">7</value>
105
            <value label="Touches">8</value>
106
            <value label="With in">9</value>
107
     	  </availableValues>
108
        </field>
109
        <field name="cropFilter" label="Crop to" group="Filter" type="Geometry" defaultValue="" mandatory="false">
110
          <description>Crop the result to this value</description>
111
        </field>
112
        
113
                        
114
        <!-- Debug -->
115
        <field name="XMLFile" label="Output XML file" type="file" group="Debug" mandatory="false">
116
          <description>Generate XML file with DGN dump in this file</description>
117
        </field>
118
        <!--
119
        <field name="debugOptions" label="Debug options" type="String" group="Debug" mandatory="false">
120
          <description></description>
121
        </field>
122
        -->
123
        <field name="logErrors" label="log errors" group="Debug" type="Boolean" defaultValue="false" mandatory="false">
124
          <description>If checked the log of errors are enabled</description>
125
        </field>
126

  
127
      </fields>
128
    </class>
129
  </classes>
130
</definitions>  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.store.dgn.DGNLibrary
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNStoreParameters.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import java.io.File;
4

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

  
17
public class DGNStoreParameters extends AbstractDataParameters implements
18
        DataStoreParameters, FilesystemStoreParameters,
19
        NewFeatureStoreParameters {
20

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

  
23
    private static final String FIELD_FILE = "file";
24
    private static final String FIELD_CRS = "CRS";
25
    private static final String FIELD_XMLFILE = "XMLFile";
26
    private static final String FIELD_LOAD_MODE = "LoadMode";
27
    private static final String FIELD_RELOAD = "Reload";
28
    private static final String FIELD_GEOMTYPE_FILTER = "geomtypeFilter";
29
    private static final String FIELD_LEVEL_FILTER = "levelFilter";
30
    private static final String FIELD_TEXT_FILTER = "textFilter";
31
    private static final String FIELD_COLOR_FILTER = "colorFilter";
32
    private static final String FIELD_STYLE_FILTER = "styleFilter";
33
    private static final String FIELD_WEIGHT_FILTER = "weightFilter";
34
    private static final String FIELD_TYPE_FILTER = "typeFilter";
35
    private static final String FIELD_STYPE_FILTER = "stypeFilter";
36
    private static final String FIELD_GROUP_FILTER = "groupFilter";
37
    private static final String FIELD_ID_FILTER = "idFilter";
38
    private static final String FIELD_CROP_FILTER = "cropFilter";
39
    private static final String FIELD_CROPOPERATION_FILTER = "cropOperationFilter";
40
    private static final String FIELD_SKYPCORRUPTGEOMETRIES_FILTER = "skipCorruptGeometries";
41
    private static final String FIELD_SORT_BY_GEOMETRY_TYPE = "sortByGeometryType";
42
    private static final String FIELD_LOGS_ERRORS = "logErrors";
43
    private static final String FIELD_IGNORE_Z = "ignoreZ";
44
    private static final String FIELD_GROUPBY = "groupby";
45
    private static final String FIELD_APPLYCONVEXHULL = "applyConvexHull";
46
    private static final String FIELD_USE_Z_AS_ELEVATION = "useZAsElevation";
47
    private static final String FIELD_ELEVATION_FACTOR = "elevationFactor";
48
    private static final String FIELD_ROUND_ELEVATION = "roundElevation";
49
    
50
    private DelegatedDynObject parameters;
51

  
52
    public DGNStoreParameters() {
53
        this(PARAMETERS_DEFINITION_NAME);
54
    }
55

  
56
    protected DGNStoreParameters(String parametersDefinitionName) {
57
        this(parametersDefinitionName, DGNStoreProvider.NAME);
58
    }
59

  
60
    public DGNStoreParameters(String parametersDefinitionName, String name) {
61
        super();
62
        this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
63
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
64
    }
65

  
66
    public String getDataStoreName() {
67
        return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
68
    }
69

  
70
    public String getDescription() {
71
        return this.getDynClass().getDescription();
72
    }
73

  
74
    public void setCRS(IProjection srs) {
75
        setDynValue(FIELD_CRS, srs);
76
    }
77

  
78
    public void setCRS(String srs) {
79
        setDynValue(FIELD_CRS, srs);
80
    }
81

  
82
    public IProjection getCRS() {
83
        return (IProjection) getDynValue(FIELD_CRS);
84
    }
85

  
86
    public String getFileName() {
87
        return this.getFile().getPath();
88
    }
89

  
90
    public boolean isValid() {
91
        if (getCRS() == null) {
92
            return false;
93
        }
94
        if (getFile() == null) {
95
            return false;
96
        }
97
        return true;
98
    }
99

  
100
    public File getFile() {
101
        return (File) this.getDynValue(FIELD_FILE);
102
    }
103

  
104
    public File getXMLFile() {
105
        return (File) this.getDynValue(FIELD_XMLFILE);
106
    }
107

  
108
    public int getGeometryTypeFilter() {
109
        Integer x = (Integer) this.getDynValue(FIELD_GEOMTYPE_FILTER);
110
        if (x == null) {
111
            return Geometry.TYPES.GEOMETRY;
112
        }
113
        return x.intValue();
114
    }
115

  
116
    public int getLoadMode() {
117
        Integer x = (Integer) this.getDynValue(FIELD_LOAD_MODE);
118
        if (x == null) {
119
            return DGNStoreProvider.LOAD_MODE_PLAIN;
120
        }
121
        return x.intValue();
122
    }
123
    
124
    public double geElevationFactor() {
125
        Double x = (Double) this.getDynValue(FIELD_ELEVATION_FACTOR);
126
        if (x == null) {
127
            return 1;
128
        }
129
        return x.doubleValue();
130
    }
131
    
132
    public int getCropOperationFilter() {
133
        Integer x = (Integer) this.getDynValue(FIELD_CROPOPERATION_FILTER);
134
        if (x == null) {
135
            return DGNStoreProvider.CROP_OPERATION_NONE;
136
        }
137
        return x.intValue();
138
    }
139

  
140
    public Geometry getCropFilter() {
141
        Geometry x = (Geometry) this.getDynValue(FIELD_CROP_FILTER);
142
        return x;
143
    }
144

  
145
    public String getGroupBy() {
146
        return (String) this.getDynValue(FIELD_GROUPBY);
147
    }
148

  
149
    public String getLevelFilter() {
150
        return (String) this.getDynValue(FIELD_LEVEL_FILTER);
151
    }
152

  
153
    public String getGroupFilter() {
154
        return (String) this.getDynValue(FIELD_GROUP_FILTER);
155
    }
156

  
157
    public String getTextFilter() {
158
        return (String) this.getDynValue(FIELD_TEXT_FILTER);
159
    }
160

  
161
    public String getIDFilter() {
162
        return (String) this.getDynValue(FIELD_ID_FILTER);
163
    }
164

  
165
    public String getTypeFilter() {
166
        return (String) this.getDynValue(FIELD_TYPE_FILTER);
167
    }
168

  
169
    public String getSTypeFilter() {
170
        return (String) this.getDynValue(FIELD_STYPE_FILTER);
171
    }
172

  
173
    public String getColorFilter() {
174
        return (String) this.getDynValue(FIELD_COLOR_FILTER);
175
    }
176

  
177
    public String getStyleFilter() {
178
        return (String) this.getDynValue(FIELD_STYLE_FILTER);
179
    }
180

  
181
    public String getWeightFilter() {
182
        return (String) this.getDynValue(FIELD_WEIGHT_FILTER);
183
    }
184

  
185
    public boolean useReload() {
186
        Boolean x = (Boolean) this.getDynValue(FIELD_RELOAD);
187
        if (x == null) {
188
            return Boolean.FALSE;
189
        }
190
        return x.booleanValue();
191
    }
192

  
193
    public boolean getApplyConvexHull() {
194
        Boolean x = (Boolean) this.getDynValue(FIELD_APPLYCONVEXHULL);
195
        if (x == null) {
196
            return Boolean.FALSE;
197
        }
198
        return x.booleanValue();
199
    }
200

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

  
209
    public boolean ignoreZs() {
210
        Boolean x = (Boolean) this.getDynValue(FIELD_IGNORE_Z);
211
        if (x == null) {
212
            return Boolean.FALSE;
213
        }
214
        return x.booleanValue();
215
    }
216

  
217
    public boolean logErrors() {
218
        Boolean x = (Boolean) this.getDynValue(FIELD_LOGS_ERRORS);
219
        if (x == null) {
220
            return Boolean.FALSE;
221
        }
222
        return x.booleanValue();
223
    }
224

  
225
    public boolean skipCorruptGeometries() {
226
        Boolean x = (Boolean) this.getDynValue(FIELD_SKYPCORRUPTGEOMETRIES_FILTER);
227
        if (x == null) {
228
            return Boolean.FALSE;
229
        }
230
        return x.booleanValue();
231
    }
232

  
233
    boolean useZAsElevation() {
234
        Boolean x = (Boolean) this.getDynValue(FIELD_USE_Z_AS_ELEVATION);
235
        if (x == null) {
236
            return Boolean.FALSE;
237
        }
238
        return x.booleanValue();
239
    }
240
    public boolean sortByGeometryType() {
241
        Boolean x = (Boolean) this.getDynValue(FIELD_SORT_BY_GEOMETRY_TYPE);
242
        if (x == null) {
243
            return Boolean.TRUE;
244
        }
245
        return x.booleanValue();
246
    }
247

  
248
    public void setFile(File file) {
249
        this.setDynValue(FIELD_FILE, file);
250
    }
251

  
252
    public void setFile(String file) {
253
        this.setDynValue(FIELD_FILE, file);
254
    }
255

  
256
    public EditableFeatureType getDefaultFeatureType() {
257
        return null; //TODO ????
258
    }
259

  
260
    public void setDefaultFeatureType(FeatureType defaultFeatureType) {
261
        throw new UnsupportedOperationException();
262
    }
263

  
264
    protected DelegatedDynObject getDelegatedDynObject() {
265
        return parameters;
266
    }
267

  
268

  
269
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/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
				DGNStoreParameters.PARAMETERS_DEFINITION_NAME, 
63
				DGNStoreParameters.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.25/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.DALLocator;
6
import org.gvsig.fmap.dal.DataManager;
7
import org.gvsig.fmap.dal.DataServerExplorer;
8
import org.gvsig.fmap.dal.DataStoreParameters;
9
import org.gvsig.fmap.dal.NewDataStoreParameters;
10
import org.gvsig.fmap.dal.exception.CreateException;
11
import org.gvsig.fmap.dal.exception.DataException;
12
import org.gvsig.fmap.dal.exception.FileNotFoundException;
13
import org.gvsig.fmap.dal.exception.RemoveException;
14
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
15
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
16
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
17
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
18
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
19

  
20
public class DGNFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider 
21
	implements FilesystemServerExplorerProvider, ResourceConsumer {
22

  
23
//	private FilesystemServerExplorerProviderServices serverExplorer;
24

  
25
	public String getDataStoreProviderName() {
26
		return DGNStoreProvider.NAME;
27
	}
28

  
29
	public int getMode() {
30
		return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY;
31
	}
32

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

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

  
41
	public DataStoreParameters getParameters(File file) throws DataException {
42
		DataManager manager = DALLocator.getDataManager();
43
		DGNStoreParameters params = (DGNStoreParameters) manager
44
				.createStoreParameters(this
45
				.getDataStoreProviderName());
46
		params.setFile(file);
47
		return params;
48
	}
49

  
50
	public boolean canCreate() {
51
		return false;
52
	}
53

  
54
	public boolean canCreate(NewDataStoreParameters parameters) {
55
		return this.canCreate();
56
	}
57

  
58
	public void create(NewDataStoreParameters parameters, boolean overwrite)
59
			throws CreateException {
60
		throw new UnsupportedOperationException();
61
	}
62

  
63
	public NewDataStoreParameters getCreateParameters() throws DataException {
64
		return null;
65
	}
66

  
67
	public void initialize(
68
			FilesystemServerExplorerProviderServices serverExplorer) {
69
//		this.serverExplorer = serverExplorer;
70
	}
71

  
72
	public void remove(DataStoreParameters parameters) throws RemoveException {
73
		File file = new File(((DGNStoreParameters) parameters).getFileName());
74
		if (!file.exists()) {
75
			throw new RemoveException(this.getDataStoreProviderName(),
76
					new FileNotFoundException(file));
77
		}
78
		if (!file.delete()) {
79
			// FIXME throws ???
80
		}
81

  
82
	}
83

  
84
	public boolean closeResourceRequested(ResourceProvider resource) {
85
		// while it is using a resource anyone can't close it
86
		return false;
87
	}
88

  
89
	/*
90
	 * (non-Javadoc)
91
	 *
92
	 * @see
93
	 * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
94
	 * gvsig.fmap.dal.resource.spi.ResourceProvider)
95
	 */
96
	public void resourceChanged(ResourceProvider resource) {
97
		//Do nothing
98

  
99
	}
100

  
101

  
102
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.25/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.io.BufferedWriter;
6
import java.io.File;
7
import java.io.FileWriter;
8
import java.io.IOException;
9
import java.util.ArrayList;
10
import java.util.Collections;
11
import java.util.Comparator;
12
import java.util.HashMap;
13
import java.util.Iterator;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.logging.Level;
17
import java.util.regex.Pattern;
18
import org.apache.commons.io.IOUtils;
19
import org.apache.commons.lang3.StringUtils;
20

  
21
import org.cresques.cts.IProjection;
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.OpenException;
31
import org.gvsig.fmap.dal.exception.ReadException;
32
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
33
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
34
import org.gvsig.fmap.dal.feature.EditableFeatureType;
35
import org.gvsig.fmap.dal.feature.FeatureType;
36
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
37
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
38
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
39
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider;
40
import org.gvsig.fmap.dal.resource.ResourceAction;
41
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
42
import org.gvsig.fmap.dal.resource.file.FileResource;
43
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
44
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
46
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
47
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
48
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemArc;
49
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemComplexHeader;
50
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemCore;
51
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemMultiPoint;
52
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemText;
53
import org.gvsig.fmap.dal.store.dgn.lib.DGNFileHeader;
54
import org.gvsig.fmap.dal.store.dgn.lib.DGNPoint;
55
import org.gvsig.fmap.dal.store.dgn.lib.DGNReader;
56
import org.gvsig.fmap.geom.Geometry;
57
import org.gvsig.fmap.geom.GeometryLocator;
58
import org.gvsig.fmap.geom.GeometryManager;
59
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
60
import org.gvsig.fmap.geom.Geometry.TYPES;
61
import org.gvsig.fmap.geom.aggregate.MultiPoint;
62
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
63
import org.gvsig.fmap.geom.aggregate.MultiSurface;
64
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
65
import org.gvsig.fmap.geom.exception.CreateGeometryException;
66
import org.gvsig.fmap.geom.operation.GeometryOperationException;
67
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
68
import org.gvsig.fmap.geom.primitive.Curve;
69
import org.gvsig.fmap.geom.primitive.Envelope;
70
import org.gvsig.fmap.geom.primitive.GeneralPathX;
71
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
72
import org.gvsig.fmap.geom.primitive.Point;
73
import org.gvsig.fmap.geom.primitive.Primitive;
74
import org.gvsig.fmap.geom.primitive.Surface;
75
import org.gvsig.fmap.geom.type.GeometryType;
76
import org.gvsig.tools.dynobject.exception.DynMethodException;
77
import org.gvsig.tools.logger.FilteredLogger;
78
import org.slf4j.Logger;
79
import org.slf4j.LoggerFactory;
80

  
81
public class DGNStoreProvider extends AbstractMemoryStoreProvider implements
82
        ResourceConsumer {
83

  
84
    private static final Logger logger = LoggerFactory.getLogger(DGNStoreProvider.class);
85

  
86
    public static final String NAME = "DGN";
87
    public static final String DESCRIPTION = "DGN file";
88

  
89
    public static final String METADATA_DEFINITION_NAME = NAME;
90
    private static final String METADATA_DEFINITION_DESCRIPTION = "DGN File Store";
91

  
92
    public static final int LOAD_MODE_PLAIN = 0;
93
    public static final int LOAD_MODE_GROUP1 = 1;
94

  
95
    public static final int CROP_OPERATION_NONE = 0;
96
    private static final int CROP_OPERATION_CONTAINS = 1;
97
    private static final int CROP_OPERATION_COVERS = 2;
98
    private static final int CROP_OPERATION_COVEREDBY = 3;
99
    private static final int CROP_OPERATION_CROSSES = 4;
100
    private static final int CROP_OPERATION_DISJOINT = 5;
101
    private static final int CROP_OPERATION_INTERSECT = 6;
102
    private static final int CROP_OPERATION_OVERLAPS = 7;
103
    private static final int CROP_OPERATION_TOUCHES = 8;
104
    private static final int CROP_OPERATION_WITHIN = 9;
105

  
106
    private static final String NAME_FIELD_ID = "ID";
107
    private static final String NAME_FIELD_GEOMETRY = "Geometry";
108
    private static final String NAME_FIELD_TYPE = "Type";
109
    private static final String NAME_FIELD_STYPE = "SType";
110
    private static final String NAME_FIELD_ENTITY = "Entity";
111
    private static final String NAME_FIELD_LEVEL = "Layer";
112
    public static final String NAME_FIELD_COLOR = "Color";
113
    public static final String NAME_FIELD_FILLCOLOR = "FillColor";
114
    private static final String NAME_FIELD_ELEVATION = "Elevation";
115
    private static final String NAME_FIELD_WEIGHT = "Weight";
116
    public static final String NAME_FIELD_TEXT = "Text";
117
    public static final String NAME_FIELD_HEIGHTTEXT = "HeightText";
118
    public static final String NAME_FIELD_HEIGHTTEXTRAW = "HeightTextRaw";
119
    public static final String NAME_FIELD_ROTATIONTEXT = "Rotation";
120
    public static final String NAME_FIELD_STYLE = "Style";
121
    public static final String NAME_FIELD_GROUP = "Group";
122
    public static final String NAME_FIELD_ISSHAPE = "IsShape";
123
    public static final String NAME_FIELD_ISCOMPLEXSHAPEHEADER = "IsComplexShapeHeader";
124
    public static final String NAME_FIELD_ISHOLE = "IsHole";
125
    public static final String NAME_FIELD_ISCOMPLEX = "IsComplex";
126
    public static final String NAME_FIELD_PARENTID = "ParentId";
127
    public static final String NAME_FIELD_SCALE = "Scale";
128

  
129
    private int ID_FIELD_ID;
130
    private int ID_FIELD_TYPE;
131
    private int ID_FIELD_STYPE;
132
    private int ID_FIELD_ENTITY;
133
    private int ID_FIELD_LEVEL;
134
    private int ID_FIELD_COLOR;
135
    private int ID_FIELD_FILLCOLOR;
136
    private int ID_FIELD_ELEVATION;
137
    private int ID_FIELD_WEIGHT;
138
    private int ID_FIELD_TEXT;
139
    private int ID_FIELD_HEIGHTTEXT;
140
    private int ID_FIELD_HEIGHTTEXTRAW;
141
    private int ID_FIELD_ROTATIONTEXT;
142
    private int ID_FIELD_STYLE;
143
    private int ID_FIELD_GROUP;
144
    private int ID_FIELD_LAYER;
145
    private int ID_FIELD_ISCOMPLEXSHAPEHEADER;
146
    private int ID_FIELD_ISSHAPE;
147
    private int ID_FIELD_ISHOLE;
148
    private int ID_FIELD_ISCOMPLEX;
149
    private int ID_FIELD_PARENT;
150
    private int ID_FIELD_SCALE;
151
    private int ID_FIELD_GEOMETRY;
152
    private int MAX_FIELD_ID;
153

  
154
    private IProjection projection;
155
    private ResourceProvider resource;
156
    private LegendBuilder legendBuilder;
157

  
158
    private long counterNewsOIDs = 0;
159
    protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
160

  
161
    private int groupByFieldIndex = -2;
162
    private Map<Object, FeatureProvider> groupedFeatures = null;
163

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff