Revision 101

View differences:

org.gvsig.dgn/tags/org.gvsig.dgn-2.0.27/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.27</version>
12
  </parent>
13

  
14
  <dependencies>
15

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

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

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

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

  
80

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

  
114

  
115
  </dependencies>
116

  
117
</project>
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.27/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.27/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.27/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.27/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.27/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
}
0 76

  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.27/org.gvsig.dgn.provider/src/main/resources/org/gvsig/fmap/dal/store/dgn/DGNMetadata.xml
1
<?xml version="1.0"?>
2
<!--
3
Definitions of metadata fields of a shp file.  
4
 -->
5
<definitions>
6
  <version>1.0.0</version>
7
  <classes>
8
    
9
    <class name="DGN" namespace="Metadata">
10
      <extends>
11
      	<class namespace="Metadata" name="SpatialProvider"/>
12
      </extends>
13
      <description>Metadata of a DGN store</description>
14
      <fields>
15
      </fields>
16
    </class>
17

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

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

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

  
151
      </fields>
152
    </class>
153
  </classes>
154
</definitions>  
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.27/org.gvsig.dgn.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.store.dgn.DGNLibrary
org.gvsig.dgn/tags/org.gvsig.dgn-2.0.27/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.27/org.gvsig.dgn.provider/src/main/java/org/gvsig/fmap/dal/store/dgn/DGNStoreProvider.java
1
package org.gvsig.fmap.dal.store.dgn;
2

  
3
import java.awt.geom.AffineTransform;
4
import java.awt.geom.Arc2D;
5
import java.io.BufferedWriter;
6
import java.io.File;
7
import java.io.FileWriter;
8
import java.io.IOException;
9
import java.util.ArrayList;
10
import java.util.Collections;
11
import java.util.Comparator;
12
import java.util.HashMap;
13
import java.util.Iterator;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.regex.Pattern;
17
import org.apache.commons.io.IOUtils;
18
import org.apache.commons.lang3.StringUtils;
19

  
20
import org.cresques.cts.IProjection;
21
import org.gvsig.fmap.dal.DALLocator;
22
import org.gvsig.fmap.dal.DataManager;
23
import org.gvsig.fmap.dal.DataServerExplorer;
24
import org.gvsig.fmap.dal.DataStoreNotification;
25
import org.gvsig.fmap.dal.DataTypes;
26
import org.gvsig.fmap.dal.FileHelper;
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.exception.InitializeException;
29
import org.gvsig.fmap.dal.exception.LoadException;
30
import org.gvsig.fmap.dal.exception.OpenException;
31
import org.gvsig.fmap.dal.exception.ReadException;
32
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
33
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
34
import org.gvsig.fmap.dal.feature.EditableFeatureType;
35
import org.gvsig.fmap.dal.feature.FeatureType;
36
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
37
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
38
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
39
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider;
40
import org.gvsig.fmap.dal.resource.ResourceAction;
41
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
42
import org.gvsig.fmap.dal.resource.file.FileResource;
43
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
44
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
46
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
47
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
48
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemArc;
49
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemComplexHeader;
50
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemCore;
51
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemMultiPoint;
52
import org.gvsig.fmap.dal.store.dgn.lib.DGNElemText;
53
import org.gvsig.fmap.dal.store.dgn.lib.DGNFileHeader;
54
import org.gvsig.fmap.dal.store.dgn.lib.DGNLink;
55
import org.gvsig.fmap.dal.store.dgn.lib.DGNPoint;
56
import org.gvsig.fmap.dal.store.dgn.lib.DGNReader;
57
import org.gvsig.fmap.geom.Geometry;
58
import org.gvsig.fmap.geom.GeometryLocator;
59
import org.gvsig.fmap.geom.GeometryManager;
60
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
61
import org.gvsig.fmap.geom.Geometry.TYPES;
62
import org.gvsig.fmap.geom.aggregate.Aggregate;
63
import org.gvsig.fmap.geom.aggregate.MultiCurve;
64
import org.gvsig.fmap.geom.aggregate.MultiLine;
65
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
66
import org.gvsig.fmap.geom.aggregate.MultiPrimitive;
67
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
68
import org.gvsig.fmap.geom.exception.CreateGeometryException;
69
import org.gvsig.fmap.geom.primitive.Curve;
70
import org.gvsig.fmap.geom.primitive.Envelope;
71
import org.gvsig.fmap.geom.primitive.GeneralPathX;
72
import org.gvsig.fmap.geom.primitive.Line;
73
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
74
import org.gvsig.fmap.geom.primitive.Point;
75
import org.gvsig.fmap.geom.primitive.Polygon;
76
import org.gvsig.fmap.geom.primitive.Primitive;
77
import org.gvsig.fmap.geom.primitive.Surface;
78
import org.gvsig.fmap.geom.type.GeometryType;
79
import org.gvsig.tools.dynobject.exception.DynMethodException;
80
import org.gvsig.tools.logger.FilteredLogger;
81
import org.slf4j.Logger;
82
import org.slf4j.LoggerFactory;
83

  
84
public class DGNStoreProvider extends AbstractMemoryStoreProvider implements
85
        ResourceConsumer {
86

  
87
    private static final Logger logger = LoggerFactory.getLogger(DGNStoreProvider.class);
88

  
89
    public static final String NAME = "DGN";
90
    public static final String DESCRIPTION = "DGN file";
91

  
92
    public static final String METADATA_DEFINITION_NAME = NAME;
93
    public static final String METADATA_DEFINITION_DESCRIPTION = "DGN File Store";
94

  
95
    public static final int LOAD_MODE_PLAIN = 0;
96
    public static final int LOAD_MODE_GROUP1 = 1;
97

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

  
109
    public static final int GROUP_GEOMETRIES_NONE = 0;
110
    public static final int GROUP_GEOMETRIES_CONVEXHULL = 1;
111
    public static final int GROUP_GEOMETRIES_UNION = 2;
112
    public static final int GROUP_GEOMETRIES_INTERSECTION = 3;
113
    public static final int GROUP_GEOMETRIES_TOPOINTS = 4;
114
    public static final int GROUP_GEOMETRIES_TOLINES = 5;
115
    public static final int GROUP_GEOMETRIES_TOPOLYGONS = 6;
116
    public static final int GROUP_GEOMETRIES_TOPOLYGONS_FIX = 7;
117

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

  
148
    private int ID_FIELD_ID;
149
    private int ID_FIELD_TYPE;
150
    private int ID_FIELD_STYPE;
151
    private int ID_FIELD_ENTITY;
152
    private int ID_FIELD_LEVEL;
153
    private int ID_FIELD_COLOR;
154
    private int ID_FIELD_FILLCOLOR;
155
    private int ID_FIELD_ELEVATION;
156
    private int ID_FIELD_WEIGHT;
157
    private int ID_FIELD_TEXT;
158
    private int ID_FIELD_HEIGHTTEXT;
159
    private int ID_FIELD_HEIGHTTEXTRAW;
160
    private int ID_FIELD_ROTATIONTEXT;
161
    private int ID_FIELD_STYLE;
162
    private int ID_FIELD_GROUP;
163
    private int ID_FIELD_LAYER;
164
    private int ID_FIELD_ISCOMPLEXSHAPEHEADER;
165
    private int ID_FIELD_ISSHAPE;
166
    private int ID_FIELD_ISHOLE;
167
    private int ID_FIELD_ISCOMPLEX;
168
    private int ID_FIELD_PARENT;
169
    private int ID_FIELD_SCALE;
170
    private int ID_FIELD_LINKS_COUNT;
171
    private int ID_FIELD_LINK_INDEX;
172
    private int ID_FIELD_LINK_TYPE;
173
    private int ID_FIELD_LINK_ENTITY;
174
    private int ID_FIELD_LINK_MS;
175
    private int ID_FIELD_LINK_LENGTH;
176
    private int ID_FIELD_LINK_DATA;
177
    private int ID_FIELD_GEOMETRY;
178
    private int MAX_FIELD_ID;
179

  
180
    private IProjection projection;
181
    private ResourceProvider resource;
182
    private LegendBuilder legendBuilder;
183

  
184
    private long counterNewsOIDs = 0;
185
    protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
186

  
187
    private int groupByFieldIndex = -2;
188
    private Map<Object, FeatureProvider> groupedFeatures = null;
189

  
190
    DGNData dgndata = null;
191

  
192
    public DGNStoreProvider(DGNStoreParameters parameters,
193
            DataStoreProviderServices storeServices) throws InitializeException {
194
        super(
195
                parameters,
196
                storeServices,
197
                FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME)
198
        );
199

  
200
        counterNewsOIDs = 0;
201
        //		projection = CRSFactory.getCRS(getParameters().getSRSID());
202

  
203
        File file = getDGNParameters().getFile();
204
        resource = this.createResource(
205
                FileResource.NAME,
206
                new Object[]{file.getAbsolutePath()}
207
        );
208

  
209
        resource.addConsumer(this);
210

  
211
        this.projection = this.getDGNParameters().getCRS();
212

  
213
        try {
214
            legendBuilder = (LegendBuilder) this.invokeDynMethod(
215
                    LegendBuilder.DYNMETHOD_BUILDER_NAME, null);
216
        } catch (DynMethodException e) {
217
            legendBuilder = null;
218
        } catch (Exception e) {
219
            throw new InitializeException(e);
220
        }
221

  
222
        this.initializeFeatureTypes();
223

  
224
    }
225

  
226
    private DGNStoreParameters getDGNParameters() {
227
        return (DGNStoreParameters) this.getParameters();
228
    }
229

  
230
    public String getProviderName() {
231
        return NAME;
232
    }
233

  
234
    public boolean allowWrite() {
235
        // not yet
236
        return false;
237
    }
238

  
239
    public Object getLegend() throws OpenException {
240
        this.open();
241
        if (legendBuilder == null) {
242
            return null;
243
        }
244
        return legendBuilder.getLegend();
245
    }
246

  
247
    public Object getLabeling() throws OpenException {
248
        this.open();
249
        if (legendBuilder == null) {
250
            return null;
251
        }
252
        return legendBuilder.getLabeling();
253
    }
254

  
255
    private class DGNData {
256

  
257
        public List data = null;
258
        public FeatureType defaultFType = null;
259
        public List fTypes = null;
260
        public Envelope envelope = null;
261
        public IProjection projection;
262
        public LegendBuilder legendBuilder;
263

  
264
        public Envelope getEnvelopeCopy() throws CreateEnvelopeException {
265
            if (envelope == null) {
266
                return null;
267
            }
268
            try {
269
                return (Envelope) envelope.clone();
270
            } catch (CloneNotSupportedException ex) {
271
                logger.warn("Can't clone envelope.", ex);
272
                return null;
273
            }
274
        }
275
    }
276

  
277
    public void open() throws OpenException {
278
        if (this.data != null) {
279
            return;
280
        }
281
        try {
282
            getResource().execute(new ResourceAction() {
283
                public Object run() throws Exception {
284
                    FeatureStoreProviderServices store = getStoreServices();
285
                    if (dgndata == null
286
                            && !(getDGNParameters().useReload())) {
287
                        if (resource.getData() != null) {
288
                            dgndata = (DGNData) ((Map) resource.getData()).get(projection.getAbrev()); // OJO
289
                            // no es del todo correcto (puede llevar reproyeccion)
290
                        } else {
291
                            resource.setData(new HashMap());
292
                        }
293
                    }
294

  
295
                    if (dgndata == null) {
296
                        dgndata = new DGNData();
297
                        dgndata.data = new ArrayList();
298
                        data = dgndata.data;
299
                        counterNewsOIDs = 0;
300
                        Reader reader = new Reader().initialice(
301
                                getMemoryProvider(),
302
                                (File) resource.get(),
303
                                projection, legendBuilder);
304
                        reader.begin(store);
305
                        dgndata.defaultFType = reader.getDefaultType().getNotEditableCopy();
306
                        List types = new ArrayList();
307
                        Iterator it = reader.getTypes().iterator();
308
                        EditableFeatureType fType;
309
                        while (it.hasNext()) {
310
                            fType = (EditableFeatureType) it.next();
311
                            if (fType.getId().equals(
312
                                    dgndata.defaultFType.getId())) {
313
                                types.add(dgndata.defaultFType);
314
                            } else {
315
                                types.add(fType.getNotEditableCopy());
316
                            }
317
                        }
318
                        dgndata.fTypes = types;
319

  
320
                        resource.notifyOpen();
321
                        store.setFeatureTypes(dgndata.fTypes,
322
                                dgndata.defaultFType);
323
                        reader.load();
324
                        dgndata.envelope = reader.getEnvelope();
325
                        dgndata.legendBuilder = legendBuilder;
326
                        dgndata.projection = projection;
327
                        reader.end();
328
                        if (resource.getData() == null) {
329
                            resource.setData(new HashMap());
330
                        }
331
                        ((Map) resource.getData()).put(
332
                                projection.getAbrev(),
333
                                dgndata); // OJO la reproyeccion
334
                        resource.notifyClose();
335
                    }
336

  
337
                    data = dgndata.data;
338
                    store.setFeatureTypes(dgndata.fTypes, dgndata.defaultFType);
339
                    legendBuilder = dgndata.legendBuilder;
340
                    setDynValue("Envelope", dgndata.getEnvelopeCopy());
341
                    setDynValue("CRS", projection);
342
                    counterNewsOIDs = data.size();
343
                    return null;
344
                }
345
            });
346
        } catch (Exception e) {
347
            data = null;
348
            try {
349
                throw new OpenException(resource.getName(), e);
350
            } catch (AccessResourceException e1) {
351
                throw new OpenException(getProviderName(), e);
352
            }
353
        }
354
    }
355

  
356
    private void sortRows() {
357
        List rows = this.data;
358

  
359
        Collections.sort(rows, new Comparator<FeatureProvider>() {
360
            public int compare(FeatureProvider o1, FeatureProvider o2) {
361
                Geometry g1 = o1.getDefaultGeometry();
362
                Geometry g2 = o2.getDefaultGeometry();
363
                if (g1 == null) {
364
                    if (g2 == null) {
365
                        return 0;
366
                    } else {
367
                        return -1;
368
                    }
369
                } else if (g2 == null) {
370
                    return 1;
371
                }
372
                return g2.getType() - g1.getType();
373
            }
374
        });
375
    }
376

  
377
    public DataServerExplorer getExplorer() throws ReadException {
378
        DataManager manager = DALLocator.getDataManager();
379
        FilesystemServerExplorerParameters params;
380
        try {
381
            params = (FilesystemServerExplorerParameters) manager
382
                    .createServerExplorerParameters(FilesystemServerExplorer.NAME);
383
            params.setRoot(this.getDGNParameters().getFile().getParent());
384
            return manager.openServerExplorer(FilesystemServerExplorer.NAME, params);
385
        } catch (DataException e) {
386
            throw new ReadException(this.getProviderName(), e);
387
        } catch (ValidateDataParametersException e) {
388
            throw new ReadException(this.getProviderName(), e);
389
        }
390

  
391
    }
392

  
393
    public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
394
        // FIXME Exception
395
        throw new UnsupportedOperationException();
396
    }
397

  
398
    public class Filter {
399

  
400
        private Pattern levelFilter = null;
401
        private Pattern colorFilter = null;
402
        private Pattern styleFilter = null;
403
        private Pattern weighFilter = null;
404
        private Pattern typeFilter = null;
405
        private Pattern stypeFilter = null;
406
        private Pattern idFilter = null;
407
        private Pattern groupFilter = null;
408
        private Pattern textFilter = null;
409
        private Point pointForCheckGeometries = null;
410
        private boolean hasfilter = false;
411
        private boolean skipCurruptGeometries = true;
412
        private int geometryTypeFilter = Geometry.TYPES.GEOMETRY;
413
        private int counter_exceptions = 0;
414
        private int cropOperationFilter;
415
        private Geometry cropFilter = null;
416

  
417
        Filter(DGNStoreParameters parameters, DGNReader dgnReader) {
418
            geometryTypeFilter = getDGNParameters().getGeometryTypeFilter();
419
            skipCurruptGeometries = getDGNParameters().skipCorruptGeometries();
420
            if (!StringUtils.isBlank(parameters.getLevelFilter())) {
421
                this.levelFilter = Pattern.compile(parameters.getLevelFilter());
422
                this.hasfilter = true;
423
            }
424
            if (!StringUtils.isBlank(parameters.getColorFilter())) {
425
                colorFilter = Pattern.compile(parameters.getColorFilter());
426
                this.hasfilter = true;
427
            }
428
            if (!StringUtils.isBlank(parameters.getStyleFilter())) {
429
                styleFilter = Pattern.compile(parameters.getStyleFilter());
430
                this.hasfilter = true;
431
            }
432
            if (!StringUtils.isBlank(parameters.getWeightFilter())) {
433
                weighFilter = Pattern.compile(parameters.getWeightFilter());
434
                this.hasfilter = true;
435
            }
436
            if (!StringUtils.isBlank(parameters.getTypeFilter())) {
437
                this.typeFilter = Pattern.compile(parameters.getTypeFilter());
438
                this.hasfilter = true;
439
            }
440
            if (!StringUtils.isBlank(parameters.getSTypeFilter())) {
441
                this.stypeFilter = Pattern.compile(parameters.getSTypeFilter());
442
                this.hasfilter = true;
443
            }
444
            if (!StringUtils.isBlank(parameters.getWeightFilter())) {
445
                weighFilter = Pattern.compile(parameters.getWeightFilter());
446
                this.hasfilter = true;
447
            }
448
            if (!StringUtils.isBlank(parameters.getGroupFilter())) {
449
                groupFilter = Pattern.compile(parameters.getGroupFilter());
450
                this.hasfilter = true;
451
            }
452
            if (!StringUtils.isBlank(parameters.getIDFilter())) {
453
                idFilter = Pattern.compile(parameters.getIDFilter());
454
                this.hasfilter = true;
455
            }
456
            if (!StringUtils.isBlank(parameters.getTextFilter())) {
457
                textFilter = Pattern.compile(parameters.getTextFilter());
458
                this.hasfilter = true;
459
            }
460
            if (this.geometryTypeFilter != Geometry.TYPES.GEOMETRY) {
461
                this.hasfilter = true;
462
            }
463
            this.cropFilter = getDGNParameters().getCropFilter();
464
            if (this.cropFilter != null) {
465
                this.hasfilter = true;
466
            }
467
            this.cropOperationFilter = getDGNParameters().getCropOperationFilter();
468
            if (this.cropOperationFilter == CROP_OPERATION_NONE) {
469
                this.cropFilter = null;
470
            }
471
            this.pointForCheckGeometries = null;
472
            if (skipCurruptGeometries) {
473
                try {
474
                    if (dgnReader.getInfo().dimension == 3) {
475
                        this.pointForCheckGeometries = geomManager.createPoint(1, 1, Geometry.SUBTYPES.GEOM3D);
476
                        this.pointForCheckGeometries.setCoordinateAt(2, 1);
477
                    } else {
478
                        this.pointForCheckGeometries = geomManager.createPoint(1, 1, Geometry.SUBTYPES.GEOM2D);
479
                    }
480
                } catch (Exception ex) {
481
                    this.pointForCheckGeometries = null;
482
                }
483
            }
484
        }
485

  
486
        private boolean match(Pattern exp, Object value) {
487
            if (exp == null) {
488
                return true;
489
            }
490
            if (value == null) {
491
                return false;
492
            }
493
            return exp.matcher(value.toString()).matches();
494
        }
495

  
496
        public boolean accept(FeatureProvider data) {
497

  
498
            if (!this.hasfilter) {
499
                return true;
500
            }
501

  
502
            Geometry geometry = data.getDefaultGeometry();
503
            if (this.pointForCheckGeometries != null) {
504
                if (geometry != null) {
505
                    try {
506
                        this.pointForCheckGeometries.intersects(geometry);
507
                    } catch (Exception ex) {
508
                        // Skip geometries with problems
509
                        data.setDefaultGeometry(null);
510
                        geometry = null;
511
                    }
512
                }
513
            }
514

  
515
            try {
516
                if (!match(levelFilter, data.get(ID_FIELD_LEVEL))) {
517
                    return false;
518
                }
519
                if (!match(colorFilter, data.get(ID_FIELD_COLOR))) {
520
                    return false;
521
                }
522
                if (!match(styleFilter, data.get(ID_FIELD_STYLE))) {
523
                    return false;
524
                }
525
                if (!match(weighFilter, data.get(ID_FIELD_WEIGHT))) {
526
                    return false;
527
                }
528
                if (!match(typeFilter, data.get(ID_FIELD_TYPE))) {
529
                    return false;
530
                }
531
                if (!match(stypeFilter, data.get(ID_FIELD_STYPE))) {
532
                    return false;
533
                }
534
                if (!match(groupFilter, data.get(ID_FIELD_GROUP))) {
535
                    return false;
536
                }
537
                if (!match(idFilter, data.get(ID_FIELD_ID))) {
538
                    return false;
539
                }
540
                if (!match(textFilter, data.get(ID_FIELD_TEXT))) {
541
                    return false;
542
                }
543

  
544
                if (geometry != null) {
545
                    if (geometryTypeFilter != Geometry.TYPES.GEOMETRY) {
546
                        GeometryType geomtype = geometry.getGeometryType();
547
                        switch (geometryTypeFilter) {
548
                            case Geometry.TYPES.POINT:
549
                                if (!geomtype.isTypeOf(Geometry.TYPES.POINT)
550
                                        && !geomtype.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
551
                                    return false;
552
                                }
553
                                break;
554
                            case Geometry.TYPES.CURVE:
555
                                if (!geomtype.isTypeOf(Geometry.TYPES.CURVE)
556
                                        && !geomtype.isTypeOf(Geometry.TYPES.MULTICURVE)) {
557
                                    return false;
558
                                }
559
                                break;
560
                            case Geometry.TYPES.SURFACE:
561
                                if (!geomtype.isTypeOf(Geometry.TYPES.SURFACE)
562
                                        && !geomtype.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
563
                                    return false;
564
                                }
565
                                break;
566
                            default:
567
                                break;
568
                        }
569
                    }
570
                    if (this.cropFilter != null) {
571
                        switch (this.cropOperationFilter) {
572
                            case CROP_OPERATION_CONTAINS:
573
                                if (!this.cropFilter.contains(geometry)) {
574
                                    return false;
575
                                }
576
                                break;
577
                            case CROP_OPERATION_COVEREDBY:
578
                                if (!this.cropFilter.coveredBy(geometry)) {
579
                                    return false;
580
                                }
581
                                break;
582
                            case CROP_OPERATION_COVERS:
583
                                if (!this.cropFilter.covers(geometry)) {
584
                                    return false;
585
                                }
586
                                break;
587
                            case CROP_OPERATION_CROSSES:
588
                                if (!this.cropFilter.crosses(geometry)) {
589
                                    return false;
590
                                }
591
                                break;
592
                            case CROP_OPERATION_DISJOINT:
593
                                if (!this.cropFilter.disjoint(geometry)) {
594
                                    return false;
595
                                }
596
                                break;
597
                            case CROP_OPERATION_INTERSECT:
598
                                if (!this.cropFilter.intersects(geometry)) {
599
                                    return false;
600
                                }
601
                                break;
602
                            case CROP_OPERATION_OVERLAPS:
603
                                if (!this.cropFilter.overlaps(geometry)) {
604
                                    return false;
605
                                }
606
                                break;
607
                            case CROP_OPERATION_TOUCHES:
608
                                if (!this.cropFilter.touches(geometry)) {
609
                                    return false;
610
                                }
611
                                break;
612
                            case CROP_OPERATION_WITHIN:
613
                                if (!this.cropFilter.within(geometry)) {
614
                                    return false;
615
                                }
616
                                break;
617
                        }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff