Revision 395

View differences:

org.gvsig.dgn/tags/org.gvsig.dgn-2.0.84/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.84/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.AbstractDynMethod;
33
import org.gvsig.tools.dynobject.DynClass;
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 extends AbstractDynMethod {
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 DGNGetLegendBuilder() {
54
            super(LegendBuilder.DYNMETHOD_BUILDER_NAME,"DGN LegendBuilder creator");
55
        }
56
        
57
        @Override
58
	public int getCode() throws DynMethodNotSupportedException {
59
		return code;
60
	}
61

  
62
        @Override
63
	public Object invoke(DynObject self, Object[] args)
64
			throws DynMethodException {
65
		return new DGNLegendBuilder();
66
	}
67

  
68
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.84/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

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

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

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

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

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

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

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

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

  
135

  
136
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.84/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.AbstractDynMethod;
35
import org.gvsig.tools.dynobject.DynClass;
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 extends AbstractDynMethod {
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
        
55
        public DGNGetLabeling() {
56
            super(LegendBuilder.DYNMETHOD_GETLABELING_NAME,"DGN Labeling");
57
        }
58
        
59
        @Override
60
	public int getCode() throws DynMethodNotSupportedException {
61
		return code;
62
	}
63

  
64
        @Override
65
	public Object invoke(DynObject self, Object[] args)
66
			throws DynMethodException {
67
		try {
68
			return ((DGNStoreProvider) self).getLabeling();
69
		} catch (OpenException e) {
70
			//FIXME
71
			throw new RuntimeException(e);
72
		}
73
	}
74

  
75
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.84/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.AbstractDynMethod;
35
import org.gvsig.tools.dynobject.DynClass;
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 extends AbstractDynMethod {
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
        
55
        public DGNGetLegend() {
56
            super(LegendBuilder.DYNMETHOD_GETLEGEND_NAME,"DGN Legend");
57
        }
58
        
59
        @Override
60
	public int getCode() throws DynMethodNotSupportedException {
61
		return code;
62
	}
63

  
64
        @Override
65
	public Object invoke(DynObject self, Object[] args)
66
			throws DynMethodException {
67
		try {
68
			return ((DGNStoreProvider) self).getLegend();
69
		} catch (OpenException e) {
70
			throw new RuntimeException(e);
71
		}
72
	}
73

  
74
}
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.84/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.84</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.84/org.gvsig.dgn.provider/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<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">
4

  
5
  <modelVersion>4.0.0</modelVersion>
6
  <artifactId>org.gvsig.dgn.provider</artifactId>
7
  <packaging>jar</packaging>
8
  <name>${project.artifactId}</name>
9
  <description>DAL provider for DGN files</description>
10
  <parent>
11
      <groupId>org.gvsig</groupId>
12
      <artifactId>org.gvsig.dgn</artifactId>
13
      <version>2.0.84</version>
14
  </parent>
15

  
16
  <dependencies>
17

  
18
    <dependency>
19
      <groupId>commons-io</groupId>
20
      <artifactId>commons-io</artifactId>
21
      <scope>compile</scope>
22
    </dependency>
23
    <dependency>
24
        <groupId>org.apache.commons</groupId>
25
        <artifactId>commons-lang3</artifactId>
26
      <scope>compile</scope>
27
    </dependency>
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.file.lib</artifactId>
46
        <scope>compile</scope>
47
    </dependency>
48
    <dependency>
49
        <groupId>org.gvsig</groupId>
50
        <artifactId>org.gvsig.fmap.dal.spi</artifactId>
51
        <scope>compile</scope>
52
    </dependency>
53
    <dependency>
54
        <groupId>org.gvsig</groupId>
55
        <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
56
        <scope>compile</scope>
57
    </dependency>
58
    <dependency>
59
        <groupId>org.gvsig</groupId>
60
        <artifactId>org.gvsig.fmap.geometry.api</artifactId>
61
        <scope>compile</scope>
62
    </dependency>
63
    <dependency>
64
        <groupId>org.gvsig</groupId>
65
        <artifactId>org.gvsig.timesupport.lib.api</artifactId>
66
        <scope>compile</scope>
67
    </dependency>  
68
    <dependency>
69
      <groupId>org.gvsig</groupId>
70
      <artifactId>org.gvsig.utils</artifactId>
71
      <scope>compile</scope>
72
    </dependency>
73

  
74

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

  
111

  
112
  </dependencies>
113
  
114
    <build>
115
      <plugins>
116
        <plugin>
117
          <!-- Skip compilation tests -->
118
          <groupId>org.apache.maven.plugins</groupId>
119
          <artifactId>maven-compiler-plugin</artifactId>
120
          <executions>
121
            <execution>
122
              <id>default-testCompile</id>
123
              <phase>process-test-sources</phase>
124
              <goals>
125
                <goal>testCompile</goal>
126
              </goals>
127
              <configuration>
128
                <skip>true</skip>
129
              </configuration>
130
            </execution>
131
          </executions>
132
        </plugin>
133
      </plugins>
134
    </build>
135
    
136
</project>
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.84/org.gvsig.dgn.provider/src/test/java/org/gvsig/fmap/dal/store/dgn/TestDGN.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

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

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

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

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

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

  
42
public class TestDGN extends AbstractLibraryAutoInitTestCase {
43

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

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

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

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

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

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

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

  
89

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

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

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

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

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

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

  
44
public class DGNLibrary extends AbstractLibrary {
45

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

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

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

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

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

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

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

  
3
import java.io.File;
4

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

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

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

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

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

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

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

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

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

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

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

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

  
78
    }
79

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

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

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

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

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

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

  
74
public class DGNStoreProvider extends AbstractMemoryStoreProvider implements
75
    ResourceConsumer {
76

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

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

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

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

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

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

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

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

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

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

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

  
183
    DGNData dgndata = null;
184

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

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

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

  
198
        resource.addConsumer(this);
199

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

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

  
212
        this.initializeFeatureTypes();
213

  
214
    }
215

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

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

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

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

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

  
245
    private class DGNData {
246

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

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

  
267
    public static class TimeCounter {
268

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

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

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

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

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

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

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

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

  
307
    public void open() throws OpenException {
308
        if (this.data != null) {
309
            return;
310
        }
311
        try {
312
            getResource().execute(new ResourceAction() {
313

  
314
                public Object run() throws Exception {
315

  
316
                    TimeCounter tc = new TimeCounter();
317
                    tc.start();
318

  
319
                    FeatureStoreProviderServices storeProviderServices = getStoreServices();
320
                    if (dgndata == null && !(getDGNParameters().useReload())) {
321
                        if (resource.getData() != null) {
322
                            dgndata =
323
                                (DGNData) ((Map) resource.getData())
324
                                    .get(projection.getAbrev()); // OJO no es del todo correcto (puede llevar reproyeccion)
325
                        } else {
326
                            resource.setData(new HashMap());
327
                        }
328
                    }
329
                    tc.restart("Retrive data from resource (data=" + dgndata + ")");
330

  
331
                    if (dgndata == null) {
332
                        dgndata = new DGNData();
333
                        dgndata.data = new ArrayList();
334
                        data = dgndata.data;
335
                        counterNewsOIDs = 0;
336
                        Reader reader = new Reader().initialice(getMemoryProvider(), (File) resource.get(), projection, legendBuilder);
337
                        reader.begin(storeProviderServices);
338
                        dgndata.defaultFType = reader.getDefaultType().getNotEditableCopy();
339
                        List types = new ArrayList();
340
                        Iterator it = reader.getTypes().iterator();
341
                        EditableFeatureType fType;
342
                        while (it.hasNext()) {
343
                            fType = (EditableFeatureType) it.next();
344
                            if (fType.getId().equals(dgndata.defaultFType.getId())) {
345
                                types.add(dgndata.defaultFType);
346
                            } else {
347
                                types.add(fType.getNotEditableCopy());
348
                            }
349
                        }
350
                        dgndata.fTypes = types;
351

  
352
                        resource.notifyOpen();
353
                        storeProviderServices.setFeatureTypes(dgndata.fTypes, dgndata.defaultFType);
354
                        reader.load();
355
                        dgndata.envelope = reader.getEnvelope();
356
                        dgndata.legendBuilder = legendBuilder;
357
                        dgndata.projection = projection;
358
                        reader.end();
359
                        if (resource.getData() == null) {
360
                            resource.setData(new HashMap());
361
                        }
362
                        ((Map) resource.getData()).put(projection.getAbrev(),dgndata); // OJO la reproyeccion
363
                        tc.restart("Loaded data from file (data=" + dgndata + ")");
364
                        resource.notifyClose();
365
                    }
366
                    // El feature type no lo compartimos entre las instancias del
367
                    // mismo resource ya que puede cambiar en funcion del filtro.
368
                    // Por lo menos el geometry-type.
369
                    List<FeatureType> featureTypes = getFeatureTypes(storeProviderServices);
370

  
371
                    tc.restart("Created featuretype (featureTypes=" + featureTypes + ")");
372

  
373
                    PostProcessFeatures postProcess = new PostProcessFeatures(getDGNParameters(), featureTypes.get(0));
374
                    if (postProcess.hasOperations()) {
375
                        data = postProcess.apply(dgndata.data);
376
                        setDynValue("Envelope", postProcess.getEnvelope());
377
                    } else {
378
                        data = dgndata.data;
379
                        setDynValue("Envelope", dgndata.getEnvelopeCopy());
380
                    }
381
                    tc.restart("PostProcessFeatures");
382

  
383
                    legendBuilder = dgndata.legendBuilder;
384
                    storeProviderServices.setFeatureTypes(featureTypes, featureTypes.get(0));
385
                    setDynValue("CRS", projection);
386
                    counterNewsOIDs = data.size();
387
                    tc.restart("load finished.");
388
                    return null;
389
                }
390
            });
391
        } catch (Exception e) {
392
            data = null;
393
            try {
394
                throw new OpenException(resource.getName(), e);
395
            } catch (AccessResourceException e1) {
396
                throw new OpenException(getProviderName(), e);
397
            }
398
        }
399
    }
400

  
401
    public DataServerExplorer getExplorer() throws ReadException {
402
        DataManager manager = DALLocator.getDataManager();
403
        FilesystemServerExplorerParameters params;
404
        try {
405
            params = (FilesystemServerExplorerParameters) manager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
406
            params.setRoot(this.getDGNParameters().getFile().getParent());
407
            return manager.openServerExplorer(FilesystemServerExplorer.NAME, params);
408
        } catch (DataException e) {
409
            throw new ReadException(this.getProviderName(), e);
410
        } catch (ValidateDataParametersException e) {
411
            throw new ReadException(this.getProviderName(), e);
412
        }
413

  
414
    }
415

  
416
    public void performChanges(Iterator deleteds, Iterator inserteds,
417
        Iterator updateds, Iterator originalFeatureTypesUpdated)
418
        throws PerformEditingException {
419
        // FIXME Exception
420
        throw new UnsupportedOperationException();
421
    }
422

  
423
    public List getFeatureTypes(FeatureStoreProviderServices store) {
424
        //FIXME: Habr?a que distinguir cuando se va a crear un DGN 3D o 2D, de momento siempre 3D
425
        return getFeatureTypes(store, Geometry.SUBTYPES.GEOM3D);
426
    }
427

  
428
    private List getFeatureTypes(FeatureStoreProviderServices store, int subtype) {
429
        EditableFeatureType featureType = store.createFeatureType(getName());
430

  
431
        featureType.setHasOID(true);
432

  
433
        ID_FIELD_ID = featureType.add(NAME_FIELD_ID, DataTypes.INT)
434
                .setDefaultValue(Integer.valueOf(0)).getIndex();
435

  
436
        ID_FIELD_PARENT = featureType.add(NAME_FIELD_PARENTID, DataTypes.INT)
437
                .setDefaultValue(Integer.valueOf(0)).getIndex();
438

  
439
        // FIXME: Cual es el size y el valor por defecto para Entity ?
440
        ID_FIELD_ENTITY = featureType.add(NAME_FIELD_ENTITY, DataTypes.STRING, 100)
441
                .setDefaultValue("").getIndex();
442

  
443
        // FIXME: Cual es el size de Layer ?
444
        ID_FIELD_LEVEL = featureType.add(NAME_FIELD_LEVEL, DataTypes.STRING, 100)
445
                .setDefaultValue("default").getIndex();
446
        ID_FIELD_LAYER = ID_FIELD_LEVEL;
447

  
448
        ID_FIELD_COLOR = featureType.add(NAME_FIELD_COLOR, DataTypes.INT)
449
                .setDefaultValue(Integer.valueOf(0)).getIndex();
450

  
451
        // FIXME: Cual es el size de Text ?
452
        ID_FIELD_TEXT = featureType.add(NAME_FIELD_TEXT, DataTypes.STRING, 100)
453
                .setDefaultValue("").getIndex();
454

  
455
        ID_FIELD_HEIGHTTEXT = featureType.add(NAME_FIELD_HEIGHTTEXT, DataTypes.DOUBLE)
456
                .setDefaultValue(Double.valueOf(10)).getIndex();
457

  
458
        ID_FIELD_HEIGHTTEXTRAW = featureType.add(NAME_FIELD_HEIGHTTEXTRAW, DataTypes.DOUBLE)
459
                .setDefaultValue(Double.valueOf(10)).getIndex();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff