Revision 91

View differences:

org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dxf/legend/DXFGetLabeling.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.dxf.legend;
29

  
30
import org.gvsig.fmap.dal.exception.OpenException;
31
import org.gvsig.fmap.dal.store.dxf.DXFStoreProvider;
32
import org.gvsig.fmap.dal.store.dxf.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.exception.DynMethodException;
38
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
39

  
40
public class DXFGetLabeling implements DynMethod {
41
	private static Integer code = null;
42

  
43
	static void register(DynClass dxfLegendDynClass) {
44
		if (code != null) {
45
			return;
46
		}
47
		code = new Integer(ToolsLocator.getDynObjectManager()
48
				.registerDynMethod(dxfLegendDynClass, new DXFGetLabeling()));
49

  
50
	}
51
	public int getCode() throws DynMethodNotSupportedException {
52
		return code.intValue();
53
	}
54

  
55
	public String getDescription() {
56
		return "DXF Labeling";
57
	}
58

  
59
	public String getName() {
60
		return LegendBuilder.DYNMETHOD_GETLABELING_NAME;
61
	}
62

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

  
73
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dxf/legend/DXFGetLegend.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.dxf.legend;
29

  
30
import org.gvsig.fmap.dal.exception.OpenException;
31
import org.gvsig.fmap.dal.store.dxf.DXFStoreProvider;
32
import org.gvsig.fmap.dal.store.dxf.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.exception.DynMethodException;
38
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
39

  
40
public class DXFGetLegend implements DynMethod {
41
	private static Integer code = null;
42

  
43
	static void register(DynClass dxfLegendDynClass) {
44
		if (code != null) {
45
			return;
46
		}
47
		code = new Integer(ToolsLocator.getDynObjectManager()
48
				.registerDynMethod(dxfLegendDynClass, new DXFGetLegend()));
49

  
50
	}
51
	public int getCode() throws DynMethodNotSupportedException {
52
		return code.intValue();
53
	}
54

  
55
	public String getDescription() {
56
		return "DXF Legend";
57
	}
58

  
59
	public String getName() {
60
		return LegendBuilder.DYNMETHOD_GETLEGEND_NAME;
61
	}
62

  
63
	public Object invoke(Object self, DynObject context)
64
			throws DynMethodException {
65
		try {
66
			return ((DXFStoreProvider) self).getLegend();
67
		} catch (OpenException e) {
68
			//FIXME
69
			throw new RuntimeException(e);
70
		}
71
	}
72

  
73
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dxf/legend/DXFLegendLibrary.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.dxf.legend;
32

  
33
import org.gvsig.fmap.dal.DALLibrary;
34
import org.gvsig.fmap.dal.store.dxf.DXFLibrary;
35
import org.gvsig.fmap.dal.store.dxf.DXFStoreProvider;
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 DXFLegendLibrary extends AbstractLibrary {
47

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

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

  
60
	@Override
61
	protected void doPostInitialize() throws LibraryException {
62
		DynClass metadataDefinition = (DynClass) MetadataLocator.getMetadataManager()
63
			.getDefinition(DXFStoreProvider.METADATA_DEFINITION_NAME);
64
		DXFGetLegendBuilder.register(metadataDefinition);
65
		DXFGetLegend.register(metadataDefinition);
66
		DXFGetLabeling.register(metadataDefinition);
67
	}
68
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dxf/legend/DXFGetLegendBuilder.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.dxf.legend;
29

  
30
import org.gvsig.fmap.dal.store.dxf.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.exception.DynMethodException;
36
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
37

  
38
public class DXFGetLegendBuilder implements DynMethod {
39
	private static Integer code = null;
40

  
41
	static void register(DynClass dxfLegendDynClass) {
42
		if (code != null) {
43
			return;
44
		}
45
		code = new Integer(ToolsLocator.getDynObjectManager()
46
				.registerDynMethod(
47
						dxfLegendDynClass, new DXFGetLegendBuilder()));
48

  
49
	}
50
	public int getCode() throws DynMethodNotSupportedException {
51
		return code.intValue();
52
	}
53

  
54
	public String getDescription() {
55
		return "DXF LegendBuilder creator";
56
	}
57

  
58
	public String getName() {
59
		return LegendBuilder.DYNMETHOD_BUILDER_NAME;
60
	}
61

  
62
	public Object invoke(Object self, DynObject context)
63
			throws DynMethodException {
64
		return new DXFLegendBuilder();
65
	}
66

  
67
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider.legend/src/main/java/org/gvsig/fmap/dal/store/dxf/legend/DXFLegendBuilder.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.dxf.legend;
29

  
30
import java.awt.Color;
31

  
32
import org.gvsig.dxf.px.dxf.AcadColor;
33
import org.gvsig.fmap.dal.DataTypes;
34
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
35
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
36
import org.gvsig.fmap.dal.store.dxf.DXFStoreProvider;
37
import org.gvsig.fmap.dal.store.dxf.LegendBuilder;
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

  
48
public class DXFLegendBuilder implements LegendBuilder {
49

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

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

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

  
60
	public void end() {
61
		defaultLegend.useDefaultSymbol(true);
62
	}
63

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

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

  
76
		ISymbol myDefaultSymbol =
77
				mapContextManager.getSymbolManager().createSymbol(
78
				Geometry.TYPES.GEOMETRY, Color.BLACK);
79

  
80
		defaultLegend.setDefaultSymbol(myDefaultSymbol);
81
		defaultLegend.useDefaultSymbol(false);
82

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

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

  
98
		if (defaultLegend.getSymbolByValue(clave) == null) {
99
			ISymbol theSymbol;
100
			Color color = null;
101
			try {
102
				color = AcadColor.getColor(clave.intValue());
103
			} catch (ArrayIndexOutOfBoundsException e) {
104
				color = AcadColor.getColor(255);
105
			}
106
			// jaume, moved to ISymbol
107
			theSymbol =
108
					mapContextManager.getSymbolManager().createSymbol(
109
							Geometry.TYPES.GEOMETRY,
110
					color);
111
			theSymbol.setDescription(clave.toString());
112
			// Asigna los colores de Autocad a los
113
			// bordes de los pol?gonos y pone el relleno transparente.
114
			if (theSymbol instanceof IFillSymbol) {
115
				((IFillSymbol) theSymbol).getOutline().setLineColor(color);
116
				Color fillColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), 0);
117
				((IFillSymbol) theSymbol).setFillColor(fillColor);
118
			}
119
			// Asigna los colores de Autocad a las l?neas
120
			if (theSymbol instanceof ILineSymbol) {
121
				((ILineSymbol) theSymbol).setLineColor(color);
122
			}
123
			if (theSymbol != null) {
124
				defaultLegend.addSymbol(clave, theSymbol);
125
			}
126
		}
127
	}
128

  
129
	public Object getLabeling() {
130
		return labelingStragegy;
131
	}
132

  
133

  
134
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.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.dxf.provider.legend</artifactId>
5
  <packaging>jar</packaging>
6
  <name>${project.artifactId}</name>
7
  <description>DAL provider for dxf files</description>
8
  <parent>
9
      <groupId>org.gvsig</groupId>
10
      <artifactId>org.gvsig.dxf</artifactId>
11
      <version>2.0.30</version>
12
  </parent>
13

  
14
  <dependencies>
15

  
16
    <dependency>
17
      <groupId>org.gvsig</groupId>
18
      <artifactId>org.gvsig.dxf.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
    <dependency>
64
        <groupId>org.gvsig</groupId>
65
        <artifactId>org.gvsig.dxf.provider</artifactId>
66
        <scope>compile</scope>
67
    </dependency>
68
    <dependency>
69
        <groupId>org.gvsig</groupId>
70
        <artifactId>org.gvsig.symbology.lib.api</artifactId>
71
        <scope>compile</scope>
72
    </dependency>
73
    <dependency>
74
        <groupId>org.gvsig</groupId>
75
        <artifactId>org.gvsig.timesupport.lib.api</artifactId>
76
        <scope>compile</scope>
77
    </dependency>  
78
    <dependency>
79
      <groupId>org.gvsig</groupId>
80
      <artifactId>org.gvsig.utils</artifactId>
81
      <scope>compile</scope>
82
    </dependency>
83

  
84

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

  
120

  
121
  </dependencies>
122

  
123
</project>
0 124

  
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFStoreProviderFactory.java
1
package org.gvsig.fmap.dal.store.dxf;
2

  
3
import java.util.List;
4

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

  
13
public class DXFStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory{
14

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

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

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

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

  
53
	public int allowMultipleGeometryTypes() {
54
		return NO;
55
	}
56
	
57
	public int allowEditableFeatureType() {
58
		return NO;
59
	}
60

  
61
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFStoreParameters.java
1
package org.gvsig.fmap.dal.store.dxf;
2

  
3
import java.io.File;
4

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

  
19
public class DXFStoreParameters extends AbstractDataParameters implements
20
		DataStoreParameters, FilesystemStoreParameters,
21
		NewFeatureStoreParameters {
22

  
23
    public static final String PARAMETERS_DEFINITION_NAME = "DXFStoreParameters";
24

  
25
    private static final String FILE_PARAMTER_NAME = "File";
26
    private static final String CRS_PARAMTER_NAME = "CRS";
27

  
28
	private DelegatedDynObject parameters;
29

  
30
	
31
	public DXFStoreParameters() {
32
		this(PARAMETERS_DEFINITION_NAME);
33
	}
34

  
35
	protected DXFStoreParameters(String parametersDefinitionName) {
36
		this(parametersDefinitionName, DXFStoreProvider.NAME);
37
	}
38

  
39
	public DXFStoreParameters(String parametersDefinitionName, String name) {
40
		super();
41
		this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
42
		this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
43
	}
44

  
45
	public String getDataStoreName() {
46
		return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME);
47
	}
48

  
49
	public String getDescription() {
50
		return this.getDynClass().getDescription();
51
	}
52

  
53
	protected DelegatedDynObject getDelegatedDynObject() {
54
		return parameters;
55
	}
56

  
57
	public void setCRS(String srs) {
58
		setDynValue(CRS_PARAMTER_NAME, srs);
59
	}
60

  
61
	public void setCRS(IProjection srs) {
62
		setDynValue(CRS_PARAMTER_NAME, srs);
63
	}
64

  
65
	public IProjection getCRS() {
66
		return (IProjection) getDynValue(CRS_PARAMTER_NAME);
67
	}
68

  
69
	public String getFileName() {
70
		if( this.getFile() == null ) {
71
			return null;
72
		}
73
		return this.getFile().getPath();
74
	}
75

  
76
	public boolean isValid() {
77
		if (getCRS() == null ) {
78
			return false;
79
		}
80
		if (getFileName() == null) {
81
			return false;
82
		}
83
		return true;
84
	}
85

  
86
	public File getFile() {
87
		return (File) this.getDynValue(FILE_PARAMTER_NAME);
88
	}
89

  
90
	public void setFile(File file) {
91
		this.setDynValue(FILE_PARAMTER_NAME, file);
92
	}
93

  
94
	public void setFile(String file) {
95
		this.setDynValue(FILE_PARAMTER_NAME, file);
96
	}
97

  
98
	public EditableFeatureType getDefaultFeatureType() {
99
		// FIXME: Esto no se si funciona.
100
    	DataManager manager = DALLocator.getDataManager();
101
    	EditableFeatureType featureType = manager.createFeatureType();
102
		DXFStoreProvider.initializeFeatureType(featureType, null, Geometry.SUBTYPES.GEOM3D);
103
		return featureType;
104
	}
105

  
106
	public void setDefaultFeatureType(FeatureType defaultFeatureType) {
107
		throw new UnsupportedOperationException();
108
	}
109
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/LegendBuilder.java
1
package org.gvsig.fmap.dal.store.dxf;
2

  
3
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
4
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider;
5

  
6

  
7
public interface LegendBuilder {
8

  
9
	final public static String DYNMETHOD_BUILDER_NAME = "getLegendBuilder";
10
	final public static String DYNMETHOD_GETLEGEND_NAME = "getLegend";
11
	final public static String DYNMETHOD_GETLABELING_NAME = "getLabeling";
12

  
13
	public LegendBuilder initialize(FeatureStoreProvider store);
14

  
15
	public void begin();
16

  
17
	public void process(FeatureProvider feature);
18

  
19
	public void end();
20

  
21
	public Object getLegend();
22
	public Object getLabeling();
23

  
24
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFLibrary.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.dxf;
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.exceptions.MetadataException;
40
import org.gvsig.tools.library.AbstractLibrary;
41
import org.gvsig.tools.library.LibraryException;
42

  
43
public class DXFLibrary extends AbstractLibrary {
44

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

  
51
	@Override
52
	protected void doInitialize() throws LibraryException {
53
	}
54

  
55
	@Override
56
	protected void doPostInitialize() throws LibraryException {
57
		List<Throwable> exs = new ArrayList<Throwable>();
58

  
59
		FileHelper.registerParametersDefinition(
60
				DXFStoreParameters.PARAMETERS_DEFINITION_NAME,
61
				DXFStoreParameters.class, "DXFParameters.xml");
62
		try {
63
			FileHelper.registerMetadataDefinition(
64
					DXFStoreProvider.METADATA_DEFINITION_NAME,
65
					DXFStoreProvider.class, "DXFMetadata.xml");
66
		} catch (MetadataException e) {
67
			exs.add(e);
68
		}
69

  
70
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator
71
				.getDataManager();
72

  
73
		try {
74
			if (!dataman.getStoreProviders().contains(DXFStoreProvider.NAME)) {
75
				dataman.registerStoreProviderFactory(new DXFStoreProviderFactory(DXFStoreProvider.NAME, DXFStoreProvider.DESCRIPTION));
76

  
77
			}
78
		} catch (RuntimeException e) {
79
			exs.add(e);
80
		}
81

  
82
		try {
83
			DALFileLocator.getFilesystemServerExplorerManager()
84
					.registerProvider(DXFStoreProvider.NAME,
85
							DXFStoreProvider.DESCRIPTION,
86
							DXFFilesystemServerProvider.class);
87
		} catch (RuntimeException e) {
88
			exs.add(e);
89
		}
90

  
91
		if (exs.size() > 0) {
92
			throw new LibraryException(this.getClass(), exs);
93
		}
94
	}
95
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFFilesystemServerProvider.java
1
package org.gvsig.fmap.dal.store.dxf;
2

  
3
import java.io.File;
4
import java.io.IOException;
5

  
6
import org.cresques.cts.IProjection;
7
import org.gvsig.dxf.io.DxfFile;
8
import org.gvsig.dxf.px.dxf.DxfEntityMaker;
9
import org.gvsig.fmap.dal.DALLocator;
10
import org.gvsig.fmap.dal.DataManager;
11
import org.gvsig.fmap.dal.DataServerExplorer;
12
import org.gvsig.fmap.dal.DataStoreParameters;
13
import org.gvsig.fmap.dal.NewDataStoreParameters;
14
import org.gvsig.fmap.dal.exception.CreateException;
15
import org.gvsig.fmap.dal.exception.DataException;
16
import org.gvsig.fmap.dal.exception.FileNotFoundException;
17
import org.gvsig.fmap.dal.exception.InitializeException;
18
import org.gvsig.fmap.dal.exception.RemoveException;
19
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
20
import org.gvsig.fmap.dal.resource.ResourceAction;
21
import org.gvsig.fmap.dal.resource.file.FileResource;
22
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
23
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
24
import org.gvsig.fmap.dal.serverexplorer.filesystem.AbsolutePathRequiredException;
25
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
26
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
27
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
28

  
29
public class DXFFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider 
30
	implements FilesystemServerExplorerProvider, ResourceConsumer {
31

  
32
	private FilesystemServerExplorerProviderServices serverExplorer;
33

  
34
	public String getDataStoreProviderName() {
35
		return DXFStoreProvider.NAME;
36
	}
37

  
38
	public int getMode() {
39
		return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY;
40
	}
41

  
42
	public boolean accept(File pathname) {
43
		return (pathname.getName().toLowerCase().endsWith(".dxf"));
44
	}
45

  
46
	public String getDescription() {
47
		return DXFStoreProvider.DESCRIPTION;
48
	}
49

  
50
	public DataStoreParameters getParameters(File file) throws DataException {
51
		DataManager manager = DALLocator.getDataManager();
52
		DXFStoreParameters params = (DXFStoreParameters) manager
53
				.createStoreParameters(this
54
				.getDataStoreProviderName());
55
		params.setFile(file.getPath());
56
		return params;
57
	}
58

  
59
	public boolean canCreate() {
60
		return true;
61
	}
62

  
63
	public boolean canCreate(NewDataStoreParameters parameters) {
64
		if (!(parameters instanceof DXFStoreParameters)) {
65
			throw new IllegalArgumentException(); // FIXME ???
66
		}
67
		DXFStoreParameters dxfParams = (DXFStoreParameters) parameters;
68
		// TODO comporbar si el ftype es correcto (para este formato es fijo)
69
		File file = new File(dxfParams.getFileName());
70

  
71
		if (dxfParams.getCRS() == null) {
72
			return false;
73
		}
74
		// TODO comprobamos extension del fichero ??
75
		if (file.exists()) {
76
			return file.canWrite();
77
		} else {
78
			return file.getParentFile().canWrite();
79
		}
80
	}
81

  
82
	public void create(NewDataStoreParameters parameters, boolean overwrite)
83
			throws CreateException {
84

  
85
		final IProjection projection = null;
86
		DXFStoreParameters params = (DXFStoreParameters) parameters;
87

  
88
		File file = params.getFile();
89
		if (!file.isAbsolute()) {
90
			throw new AbsolutePathRequiredException(file.getPath());
91
		}
92

  
93
		if (file.exists()) {
94
			if (overwrite) {
95
				if (!file.delete()) {
96
					throw new CreateException(this.getDataStoreProviderName(),
97
							new IOException(
98
							"cannot delete file"));
99
				}
100
			} else {
101
				throw new CreateException(this.getDataStoreProviderName(),
102
						new IOException(
103
						"file already exist"));
104
			}
105
		}
106

  
107
		//		projection = CRSFactory.getCRS(params.getSRSID());
108

  
109

  
110
		final FileResource resource;
111
		try {
112
			resource = (FileResource) this.serverExplorer
113
					.getServerExplorerProviderServices().createResource(
114
							FileResource.NAME,
115
					new Object[] { file.getAbsolutePath() });
116
		} catch (InitializeException e1) {
117
			throw new CreateException(params.getFileName(), e1);
118
		}
119
		resource.addConsumer(this);
120

  
121
		try {
122
			resource.execute(new ResourceAction() {
123
				public Object run() throws Exception {
124
					Builder builder =
125
							new Builder().initialice(resource.getFileName(),
126
									projection);
127
					resource.notifyOpen();
128
					builder.begin();
129
					builder.create();
130
					builder.end();
131
					resource.notifyClose();
132

  
133
					resource.setData(null); // FIXME: Seguro que hay que ponerlo
134
											// a null ??
135
					resource.notifyChanges();
136
					return null;
137
				}
138
			});
139
		} catch (Exception e) {
140
			throw new CreateException(params.getFileName(), e);
141
		} finally {
142
			resource.removeConsumer(this);
143
		}
144
	}
145

  
146
	public class Builder {
147
		private String fileName;
148
		private IProjection projection;
149

  
150
		public Builder initialice(String fileName, IProjection projection) {
151
			this.fileName = fileName;
152
			this.projection = projection;
153
			return this;
154
		}
155

  
156
		public void begin() {
157

  
158
		}
159

  
160
		public void end() {
161

  
162
		}
163

  
164
		public void create() throws IOException {
165
			DxfEntityMaker entityMaker = new DxfEntityMaker(projection);
166
			DxfFile dxfFile = new DxfFile(null, fileName, entityMaker);
167
			dxfFile.setCadFlag(true);
168
			dxfFile.setDxf3DFlag(false);
169
			dxfFile.save(fileName);
170
		}
171
	}
172

  
173
	public NewDataStoreParameters getCreateParameters() throws DataException {
174
		return (NewFeatureStoreParameters) DALLocator.getDataManager()
175
				.createStoreParameters(this.getDataStoreProviderName());
176
	}
177

  
178
	public void initialize(
179
			FilesystemServerExplorerProviderServices serverExplorer) {
180
		this.serverExplorer = serverExplorer;
181
	}
182

  
183
	public void remove(DataStoreParameters parameters) throws RemoveException {
184
		File file = new File(((DXFStoreParameters) parameters).getFileName());
185
		if (!file.exists()) {
186
			throw new RemoveException(this.getDataStoreProviderName(),
187
					new FileNotFoundException(file));
188
		}
189
		if (!file.delete()) {
190
			// FIXME throws ???
191
		}
192

  
193
	}
194

  
195
	public boolean closeResourceRequested(ResourceProvider resource) {
196
		// while it is using a resource anyone can't close it
197
		return false;
198
	}
199

  
200
	/*
201
	 * (non-Javadoc)
202
	 * 
203
	 * @see
204
	 * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
205
	 * gvsig.fmap.dal.resource.spi.ResourceProvider)
206
	 */
207
	public void resourceChanged(ResourceProvider resource) {
208
		//Do nothing
209

  
210
	}
211

  
212

  
213
}
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.30/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFStoreProvider.java
1
package org.gvsig.fmap.dal.store.dxf;
2

  
3
import java.awt.geom.PathIterator;
4
import java.awt.geom.Point2D;
5
import java.io.File;
6
import java.text.MessageFormat;
7
import java.util.ArrayList;
8
import java.util.HashMap;
9
import java.util.Iterator;
10
import java.util.List;
11
import java.util.Map;
12
import java.util.Vector;
13

  
14
import org.cresques.cts.IProjection;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

  
18
import org.gvsig.dxf.geo.Point3D;
19
import org.gvsig.dxf.io.DxfFile;
20
import org.gvsig.dxf.io.DxfGroup;
21
import org.gvsig.dxf.io.DxfGroupVector;
22
import org.gvsig.dxf.px.IObjList;
23
import org.gvsig.dxf.px.dxf.DxfEntityMaker;
24
import org.gvsig.dxf.px.dxf.DxfFeatureMaker;
25
import org.gvsig.dxf.px.dxf.DxfHeaderManager;
26
import org.gvsig.dxf.px.gml.Feature;
27
import org.gvsig.dxf.px.gml.LineString;
28
import org.gvsig.dxf.px.gml.LineString3D;
29
import org.gvsig.dxf.px.gml.Point;
30
import org.gvsig.dxf.px.gml.Polygon;
31
import org.gvsig.dxf.px.gml.Polygon3D;
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataManager;
34
import org.gvsig.fmap.dal.DataServerExplorer;
35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.fmap.dal.DataStoreNotification;
37
import org.gvsig.fmap.dal.DataTypes;
38
import org.gvsig.fmap.dal.FileHelper;
39
import org.gvsig.fmap.dal.exception.DataException;
40
import org.gvsig.fmap.dal.exception.InitializeException;
41
import org.gvsig.fmap.dal.exception.LoadException;
42
import org.gvsig.fmap.dal.exception.OpenException;
43
import org.gvsig.fmap.dal.exception.ReadException;
44
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
45
import org.gvsig.fmap.dal.exception.WriteException;
46
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
47
import org.gvsig.fmap.dal.feature.EditableFeatureType;
48
import org.gvsig.fmap.dal.feature.FeatureSet;
49
import org.gvsig.fmap.dal.feature.FeatureType;
50
import org.gvsig.fmap.dal.feature.exception.PerformEditingException;
51
import org.gvsig.fmap.dal.feature.spi.FeatureProvider;
52
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices;
53
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider;
54
import org.gvsig.fmap.dal.resource.ResourceAction;
55
import org.gvsig.fmap.dal.resource.exception.AccessResourceException;
56
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyCloseException;
57
import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException;
58
import org.gvsig.fmap.dal.resource.file.FileResource;
59
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer;
60
import org.gvsig.fmap.dal.resource.spi.ResourceProvider;
61
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
62
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
63
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
64
import org.gvsig.fmap.geom.Geometry;
65
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
66
import org.gvsig.fmap.geom.Geometry.TYPES;
67
import org.gvsig.fmap.geom.GeometryLocator;
68
import org.gvsig.fmap.geom.GeometryManager;
69
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
70
import org.gvsig.fmap.geom.exception.CreateGeometryException;
71
import org.gvsig.fmap.geom.operation.GeometryOperationContext;
72
import org.gvsig.fmap.geom.operation.distance.PointDistance;
73
import org.gvsig.fmap.geom.operation.utils.PointGetAngle;
74
import org.gvsig.fmap.geom.primitive.Arc;
75
import org.gvsig.fmap.geom.primitive.Circle;
76
import org.gvsig.fmap.geom.primitive.Ellipse;
77
import org.gvsig.fmap.geom.primitive.Envelope;
78
import org.gvsig.fmap.geom.primitive.Line;
79
import org.gvsig.fmap.geom.primitive.OrientablePrimitive;
80
import org.gvsig.fmap.geom.type.GeometryType;
81
import org.gvsig.tools.ToolsLocator;
82
import org.gvsig.tools.dispose.DisposableIterator;
83
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
84
import org.gvsig.tools.dynobject.exception.DynMethodException;
85
import org.gvsig.tools.exception.NotYetImplemented;
86
import org.gvsig.tools.logger.FilteredLogger;
87
import org.gvsig.tools.persistence.PersistentState;
88
import org.gvsig.tools.persistence.exception.PersistenceException;
89
import org.gvsig.tools.task.SimpleTaskStatus;
90
import org.gvsig.tools.task.TaskStatusManager;
91

  
92
public class DXFStoreProvider extends AbstractMemoryStoreProvider implements
93
ResourceConsumer {
94
    private static final Logger logger = LoggerFactory.getLogger(DXFStoreProvider.class);
95

  
96
    public static final String NAME = "DXF";
97
    public static final String DESCRIPTION = "DXF file";
98

  
99
    public static final String METADATA_DEFINITION_NAME = NAME;
100

  
101
    public static final String NAME_FIELD_ID = "ID";
102
    public static final String NAME_FIELD_GEOMETRY = "Geometry";
103
    public static final String NAME_FIELD_ENTITY = "Entity";
104
    public static final String NAME_FIELD_LAYER = "Layer";
105
    public static final String NAME_FIELD_COLOR = "Color";
106
    public static final String NAME_FIELD_ELEVATION = "Elevation";
107
    public static final String NAME_FIELD_THICKNESS = "Thickness";
108
    public static final String NAME_FIELD_TEXT = "Text";
109
    public static final String NAME_FIELD_HEIGHTTEXT = "HeightText";
110
    public static final String NAME_FIELD_ROTATIONTEXT = "Rotation";
111

  
112
    private static final int ID_FIELD_ID = 0;
113
    private static final int ID_FIELD_GEOMETRY = 1;
114
    private static final int ID_FIELD_ENTITY = 2;
115
    private static final int ID_FIELD_LAYER = 3;
116
    private static final int ID_FIELD_COLOR = 4;
117
    private static final int ID_FIELD_ELEVATION = 5;
118
    private static final int ID_FIELD_THICKNESS = 6;
119
    private static final int ID_FIELD_TEXT = 7;
120
    private static final int ID_FIELD_HEIGHTTEXT = 8;
121
    private static final int ID_FIELD_ROTATIONTEXT = 9;
122

  
123
    private IProjection projection;
124
    private ResourceProvider resource;
125
    private LegendBuilder legendBuilder;
126

  
127
    private long counterNewsOIDs = 0;
128
    private Envelope envelope;
129
    private Writer writer;
130
    protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
131

  
132
    private SimpleTaskStatus taskStatus;
133

  
134

  
135
    public DXFStoreProvider(DXFStoreParameters parameters,
136
        DataStoreProviderServices storeServices) throws InitializeException {
137
        super(
138
            parameters, 
139
            storeServices,
140
            FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME)
141
        );
142

  
143
        TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
144
        this.taskStatus = manager.creteDefaultSimpleTaskStatus("DXF");
145

  
146
        counterNewsOIDs = 0;
147
        //		projection = CRSFactory.getCRS(getParameters().getSRSID());
148

  
149
        File file = getDXFParameters().getFile();
150
        resource = this.createResource(
151
            FileResource.NAME,
152
            new Object[] { file.getAbsolutePath() }
153
        );
154

  
155
        resource.addConsumer(this);
156

  
157
        this.projection = this.getDXFParameters().getCRS();
158

  
159

  
160
        try {
161
            legendBuilder = (LegendBuilder) this.invokeDynMethod(
162
                LegendBuilder.DYNMETHOD_BUILDER_NAME, null);
163
        } catch (DynMethodException e) {
164
            legendBuilder = null;
165
        } catch (Exception e) {
166
            throw new InitializeException(e);
167
        }
168

  
169
        this.initializeFeatureTypes();
170

  
171
    }
172

  
173
    private DXFStoreParameters getDXFParameters() {
174
        return (DXFStoreParameters) this.getParameters();
175
    }
176

  
177
    public String getProviderName() {
178
        return NAME;
179
    }
180

  
181
    public boolean allowWrite() {
182
        return true;
183
    }
184

  
185
    public Object getLegend() throws OpenException {
186
        this.open();
187
        if (legendBuilder == null) {
188
            return null;
189
        }
190
        return legendBuilder.getLegend();
191
    }
192

  
193
    public Object getLabeling() throws OpenException {
194
        this.open();
195
        if (legendBuilder == null) {
196
            return null;
197
        }
198
        return legendBuilder.getLabeling();
199
    }
200

  
201
    private class DXFData {
202
        public List data = null;
203
        public FeatureType defaultFType = null;
204
        public List fTypes = null;
205
        public Envelope envelope = null;
206
        public IProjection projection;
207
        public LegendBuilder legendBuilder;
208
        public Envelope getEnvelopeCopy() throws CreateEnvelopeException {
209
            if (envelope == null) {
210
                return null;
211
            }
212
            Envelope newEnvelope;
213
            if (envelope.getDimension() == 2) {
214
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
215
            } else {
216
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
217

  
218
            }
219
            newEnvelope.setLowerCorner(envelope.getLowerCorner());
220
            newEnvelope.setUpperCorner(envelope.getUpperCorner());
221
            return newEnvelope;
222
        }
223
    }
224

  
225
    public void open() throws OpenException {
226
        if (this.data != null) {
227
            return;
228
        }
229
        openEver();
230
    }
231

  
232
    private void openEver() throws OpenException {
233
        try {
234
            this.taskStatus.add();
235
            getResource().execute(new ResourceAction() {
236
                public Object run() throws Exception {
237
                    DXFData dxfData = null;
238
                    resource.setData(new HashMap());
239
                    FeatureStoreProviderServices store = getStoreServices();
240
                    dxfData = new DXFData();
241
                    dxfData.data = new ArrayList();
242
                    data = dxfData.data;
243
                    counterNewsOIDs = 0;
244
                    Reader reader = new Reader().initialice(
245
                        getMemoryProvider(),
246
                        (File) resource.get(),
247
                        projection,
248
                        legendBuilder
249
                    );
250
                    reader.begin(store);
251
                    dxfData.defaultFType = reader.getDefaultType()
252
                    .getNotEditableCopy();
253
                    ArrayList types = new ArrayList();
254
                    Iterator it = reader.getTypes().iterator();
255
                    EditableFeatureType fType;
256
                    while (it.hasNext()) {
257
                        fType = (EditableFeatureType) it.next();
258
                        if (fType.getId().equals(dxfData.defaultFType.getId())) {
259
                            types.add(dxfData.defaultFType);
260
                        } else {
261
                            types.add(fType.getNotEditableCopy());
262
                        }
263
                    }
264
                    dxfData.fTypes = types;
265

  
266
                    resource.notifyOpen();
267
                    store.setFeatureTypes(dxfData.fTypes, dxfData.defaultFType);
268
                    reader.load();
269

  
270
                    dxfData.envelope = reader.getEnvelope();
271

  
272
                    dxfData.legendBuilder = legendBuilder;
273

  
274
                    dxfData.projection = projection;
275

  
276
                    reader.end();
277
                    resource.notifyClose();
278
                    ((Map) resource.getData()).put(projection.getAbrev(),
279
                        dxfData); // OJO la reproyeccion
280

  
281
                    data = dxfData.data;
282
                    store.setFeatureTypes(dxfData.fTypes, dxfData.defaultFType);
283
                    legendBuilder = dxfData.legendBuilder;
284
                    envelope= dxfData.getEnvelopeCopy();
285
                    // setDynValue("CRS", projection.getAbrev());
286
                    counterNewsOIDs = data.size();
287
                    return null;
288
                }
289
            });
290
            this.taskStatus.terminate();
291
        } catch (Exception e) {
292
            data = null;
293
            this.taskStatus.abort();
294
            try {
295
                throw new OpenException(resource.getName(), e);
296
            } catch (AccessResourceException e1) {
297
                throw new OpenException(getProviderName(), e);
298
            }
299
        } finally {
300
            this.taskStatus.remove();
301
        }
302
    }
303

  
304

  
305
    public DataServerExplorer getExplorer() throws ReadException {
306
        DataManager manager = DALLocator.getDataManager();
307
        FilesystemServerExplorerParameters params;
308
        try {
309
            params = (FilesystemServerExplorerParameters) manager
310
            .createServerExplorerParameters(FilesystemServerExplorer.NAME);
311
            params.setRoot(this.getDXFParameters().getFile().getParent());
312
            return manager.openServerExplorer(FilesystemServerExplorer.NAME,params);
313
        } catch (DataException e) {
314
            throw new ReadException(this.getProviderName(), e);
315
        } catch (ValidateDataParametersException e) {
316
            throw new ReadException(this.getProviderName(), e);
317
        }
318

  
319
    }
320

  
321

  
322

  
323
    public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
324

  
325
        try {
326
            this.taskStatus.add();
327
            taskStatus.message("_preparing");
328
            getResource().execute(new ResourceAction() {
329
                public Object run() throws Exception {
330
                    FeatureSet features = null;
331
                    DisposableIterator it = null;
332
                    try {
333
                        File file = (File) resource.get();
334
                        String fileName = file.getAbsolutePath();
335
                        writer = new Writer().initialice(file, projection);
336
                        features =
337
                            getStoreServices().getFeatureStore()
338
                            .getFeatureSet();
339
                        List newdata = new ArrayList();
340
                        writer.begin();
341
                        it = features.fastIterator();
342
                        taskStatus.setRangeOfValues(0,0);
343
                        long counter=0;
344
                        while (it.hasNext()) {
345
                            taskStatus.setCurValue(counter++);
346
                            FeatureProvider feature = getStoreServices().getFeatureProviderFromFeature(
347
                                (org.gvsig.fmap.dal.feature.Feature) it.next());
348
                            writer.add(feature);
349
                            if (feature.getOID() == null){
350
                                logger.warn("feature without OID");
351
                                feature.setOID(createNewOID());
352
                            }
353
                            newdata.add(feature);
354
                        }
355
                        data = newdata;
356
                        writer.end();
357
                        if (writer.getEnvelope() != null){
358
                            envelope = writer.getEnvelope().getGeometry().getEnvelope();
359
                        }
360
                        resource.notifyChanges();
361
                        //					counterNewsOIDs = 0;
362
                    } finally {
363
                        if (it != null) {
364
                            it.dispose();
365
                        }
366
                        if (features != null) {
367
                            features.dispose();
368
                        }
369
                    }
370
                    return null;
371
                }
372
            });
373
            this.taskStatus.terminate();
374
        } catch (Exception e) {
375
            this.taskStatus.abort();
376
            throw new PerformEditingException(getResource().toString(), e);
377
        } finally {
378
            this.taskStatus.remove();
379
        }
380
    }
381
    
382
    public static void initializeFeatureType(EditableFeatureType featureType, IProjection projection, int geometrySubtype){
383
        featureType.setHasOID(true);
384

  
385
//        ID_FIELD_ID = 0;
386
        featureType.add(NAME_FIELD_ID, DataTypes.INT)
387
        .setDefaultValue(Integer.valueOf(0))
388
        .getIndex();
389

  
390
        EditableFeatureAttributeDescriptor attr = featureType.add(
391
            NAME_FIELD_GEOMETRY, DataTypes.GEOMETRY);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff