Revision 154

View differences:

org.gvsig.dgn/tags/org.gvsig.dgn-2.0.37/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.37/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.37/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.37/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.37/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.37/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.37</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
    <!--
99
    <dependency>
100
      <groupId>org.gvsig</groupId>
101
      <artifactId>org.gvsig.fmap.geometry.generalpath</artifactId>
102
      <scope>test</scope>
103
    </dependency>
104
    -->
105
    <dependency>
106
      <groupId>org.gvsig</groupId>
107
      <artifactId>org.gvsig.projection.cresques.impl</artifactId>
108
      <scope>test</scope>
109
    </dependency>
110
    <dependency>
111
      <groupId>org.gvsig</groupId>
112
      <artifactId>org.gvsig.timesupport.lib.impl</artifactId>
113
      <scope>test</scope>
114
    </dependency>   
115

  
116

  
117
  </dependencies>
118

  
119
</project>
0 120

  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.37/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
		DGNStoreParameters dgnParameters = null;
66

  
67
		dgnParameters = (DGNStoreParameters) 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.37/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(DGNStoreParameters 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.37/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.37/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.37/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.OrientablePrimitive;
69
import org.gvsig.fmap.geom.primitive.Point;
70
import org.gvsig.fmap.geom.type.GeometryType;
71
import org.gvsig.tools.dynobject.exception.DynMethodException;
72

  
73
public class DGNStoreProvider extends AbstractMemoryStoreProvider implements
74
    ResourceConsumer {
75

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

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

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

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

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

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

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

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

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

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

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

  
182
    DGNData dgndata = null;
183

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

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

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

  
197
        resource.addConsumer(this);
198

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

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

  
211
        this.initializeFeatureTypes();
212

  
213
    }
214

  
215
    private DGNStoreParameters getDGNParameters() {
216
        return (DGNStoreParameters) this.getParameters();
217
    }
218

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

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

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

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

  
244
    private class DGNData {
245

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

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

  
266
    public static class TimeCounter {
267

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

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

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

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

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

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

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

  
299
        public void restart(String msg) {
300
            this.stop();
301
            this.log(msg);
302
            this.restart();
303
        }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff