Revision 169

View differences:

org.gvsig.dxf/tags/org.gvsig.dxf-2.0.45/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.45/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.45/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.45/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.45/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.45/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.45</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.45/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.45/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.45/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.45/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.apache.commons.io.FilenameUtils;
15
import org.cresques.cts.IProjection;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

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

  
97
/**
98
 * @author gvSIG team
99
 *
100
 */
101
public class DXFStoreProvider extends AbstractMemoryStoreProvider implements
102
ResourceConsumer {
103
    private static final Logger logger = LoggerFactory.getLogger(DXFStoreProvider.class);
104

  
105
    public static final String NAME = "DXF";
106
    public static final String DESCRIPTION = "DXF file";
107

  
108
    public static final String METADATA_DEFINITION_NAME = NAME;
109

  
110
    public static final String NAME_FIELD_ID = "ID";
111
    public static final String NAME_FIELD_GEOMETRY = "Geometry";
112
    public static final String NAME_FIELD_ENTITY = "Entity";
113
    public static final String NAME_FIELD_LAYER = "Layer";
114
    public static final String NAME_FIELD_COLOR = "Color";
115
    public static final String NAME_FIELD_ELEVATION = "Elevation";
116
    public static final String NAME_FIELD_THICKNESS = "Thickness";
117
    public static final String NAME_FIELD_TEXT = "Text";
118
    public static final String NAME_FIELD_HEIGHTTEXT = "HeightText";
119
    public static final String NAME_FIELD_ROTATIONTEXT = "Rotation";
120

  
121
    private static final int ID_FIELD_ID = 0;
122
    private static final int ID_FIELD_GEOMETRY = 1;
123
    private static final int ID_FIELD_ENTITY = 2;
124
    private static final int ID_FIELD_LAYER = 3;
125
    private static final int ID_FIELD_COLOR = 4;
126
    private static final int ID_FIELD_ELEVATION = 5;
127
    private static final int ID_FIELD_THICKNESS = 6;
128
    private static final int ID_FIELD_TEXT = 7;
129
    private static final int ID_FIELD_HEIGHTTEXT = 8;
130
    private static final int ID_FIELD_ROTATIONTEXT = 9;
131

  
132
    private IProjection projection;
133
    private ResourceProvider resource;
134
    private LegendBuilder legendBuilder;
135

  
136
    private long counterNewsOIDs = 0;
137
    private Envelope envelope;
138
    private Writer writer;
139
    protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
140

  
141
    private SimpleTaskStatus taskStatus;
142

  
143

  
144
    /**
145
     * @param parameters
146
     * @param storeServices
147
     * @throws InitializeException
148
     */
149
    public DXFStoreProvider(DXFStoreParameters parameters,
150
        DataStoreProviderServices storeServices) throws InitializeException {
151
        super(
152
            parameters,
153
            storeServices,
154
            FileHelper.newMetadataContainer(METADATA_DEFINITION_NAME)
155
        );
156

  
157
        TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
158
        this.taskStatus = manager.createDefaultSimpleTaskStatus("DXF");
159

  
160
        counterNewsOIDs = 0;
161
        //		projection = CRSFactory.getCRS(getParameters().getSRSID());
162

  
163
        File file = getDXFParameters().getFile();
164
        resource = this.createResource(
165
            FileResource.NAME,
166
            new Object[] { file.getAbsolutePath() }
167
        );
168

  
169
        resource.addConsumer(this);
170

  
171
        this.projection = this.getDXFParameters().getCRS();
172

  
173

  
174
        try {
175
            legendBuilder = (LegendBuilder) this.invokeDynMethod(
176
                LegendBuilder.DYNMETHOD_BUILDER_NAME, null);
177
        } catch (DynMethodException e) {
178
            legendBuilder = null;
179
        } catch (Exception e) {
180
            throw new InitializeException(e);
181
        }
182

  
183
        this.initializeFeatureTypes();
184
    }
185

  
186
    private DXFStoreParameters getDXFParameters() {
187
        return (DXFStoreParameters) this.getParameters();
188
    }
189

  
190
    public String getProviderName() {
191
        return NAME;
192
    }
193

  
194
    public boolean allowWrite() {
195
        return true;
196
    }
197

  
198
    /**
199
     * @return the legend
200
     * @throws OpenException
201
     */
202
    public Object getLegend() throws OpenException {
203
        this.open();
204
        if (legendBuilder == null) {
205
            return null;
206
        }
207
        return legendBuilder.getLegend();
208
    }
209

  
210
    /**
211
     * @return the labeling strategy
212
     * @throws OpenException
213
     */
214
    public Object getLabeling() throws OpenException {
215
        this.open();
216
        if (legendBuilder == null) {
217
            return null;
218
        }
219
        return legendBuilder.getLabeling();
220
    }
221

  
222
    private class DXFData {
223
        public List<FeatureProvider> data = null;
224
        public FeatureType defaultFType = null;
225
        public List<FeatureType> fTypes = null;
226
        public Envelope envelope = null;
227
        public IProjection projection;
228
        public LegendBuilder legendBuilder;
229
        public Envelope getEnvelopeCopy() throws CreateEnvelopeException {
230
            if (envelope == null) {
231
                return null;
232
            }
233
            Envelope newEnvelope;
234
            if (envelope.getDimension() == 2) {
235
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D);
236
            } else {
237
                newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D);
238

  
239
            }
240
            newEnvelope.setLowerCorner(envelope.getLowerCorner());
241
            newEnvelope.setUpperCorner(envelope.getUpperCorner());
242
            return newEnvelope;
243
        }
244
    }
245

  
246
    public void open() throws OpenException {
247
        if (this.data != null) {
248
            return;
249
        }
250
        openEver();
251
    }
252

  
253
    private void openEver() throws OpenException {
254
        try {
255
            this.taskStatus.add();
256
            getResource().execute(new ResourceAction() {
257
                public Object run() throws Exception {
258
                    DXFData dxfData = null;
259
                    resource.setData(new HashMap<Object, Object>());
260
                    FeatureStoreProviderServices store = getStoreServices();
261
                    dxfData = new DXFData();
262
                    dxfData.data = new ArrayList<FeatureProvider>();
263
                    data = dxfData.data;
264
                    counterNewsOIDs = 0;
265
                    File file = (File) resource.get();
266
                    Reader reader = new Reader().initialice(
267
                        getMemoryProvider(),
268
                        file,
269
                        projection,
270
                        legendBuilder
271
                    );
272
                    reader.begin(store);
273
                    dxfData.defaultFType = reader.getDefaultType()
274
                    .getNotEditableCopy();
275
                    ArrayList<FeatureType> types = new ArrayList<FeatureType>();
276
                    Iterator<EditableFeatureType> it = reader.getTypes().iterator();
277
                    EditableFeatureType fType;
278
                    while (it.hasNext()) {
279
                        fType = it.next();
280
                        if (fType.getId().equals(dxfData.defaultFType.getId())) {
281
                            types.add(dxfData.defaultFType);
282
                        } else {
283
                            types.add(fType.getNotEditableCopy());
284
                        }
285
                    }
286
                    dxfData.fTypes = types;
287

  
288
                    resource.notifyOpen();
289
                    store.setFeatureTypes(dxfData.fTypes, dxfData.defaultFType);
290
                    reader.load();
291

  
292
                    dxfData.envelope = reader.getEnvelope();
293

  
294
                    dxfData.legendBuilder = legendBuilder;
295

  
296
                    dxfData.projection = projection;
297

  
298
                    reader.end();
299
                    resource.notifyClose();
300
                    ((Map<String, DXFData>) resource.getData()).put(projection.getAbrev(),
301
                        dxfData); // OJO la reproyeccion
302

  
303
                    data = dxfData.data;
304
                    store.setFeatureTypes(dxfData.fTypes, dxfData.defaultFType);
305
                    legendBuilder = dxfData.legendBuilder;
306
                    envelope= dxfData.getEnvelopeCopy();
307
                    // setDynValue("CRS", projection.getAbrev());
308
                    counterNewsOIDs = data.size();
309
                    return null;
310
                }
311
            });
312
            this.taskStatus.terminate();
313
        } catch (Exception e) {
314
            data = null;
315
            this.taskStatus.abort();
316
            try {
317
                throw new OpenException(resource.getName(), e);
318
            } catch (AccessResourceException e1) {
319
                throw new OpenException(getProviderName(), e);
320
            }
321
        } finally {
322
            this.taskStatus.remove();
323
        }
324
    }
325

  
326

  
327
    public DataServerExplorer getExplorer() throws ReadException {
328
        DataManager manager = DALLocator.getDataManager();
329
        FilesystemServerExplorerParameters params;
330
        try {
331
            params = (FilesystemServerExplorerParameters) manager
332
            .createServerExplorerParameters(FilesystemServerExplorer.NAME);
333
            params.setRoot(this.getDXFParameters().getFile().getParent());
334
            return manager.openServerExplorer(FilesystemServerExplorer.NAME,params);
335
        } catch (DataException e) {
336
            throw new ReadException(this.getProviderName(), e);
337
        } catch (ValidateDataParametersException e) {
338
            throw new ReadException(this.getProviderName(), e);
339
        }
340

  
341
    }
342

  
343

  
344

  
345
    public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException {
346

  
347
        try {
348
            this.taskStatus.add();
349
            taskStatus.message("_preparing");
350
            getResource().execute(new ResourceAction() {
351
                public Object run() throws Exception {
352
                    FeatureSet features = null;
353
                    DisposableIterator it = null;
354
                    counterNewsOIDs = 0;
355
                    try {
356
                        File file = (File) resource.get();
357
                        writer = new Writer().initialice(file, projection);
358
                        features =
359
                            getStoreServices().getFeatureStore()
360
                            .getFeatureSet();
361
                        List<FeatureProvider> newdata = new ArrayList<FeatureProvider>();
362
                        writer.begin();
363
                        it = features.fastIterator();
364
                        taskStatus.setRangeOfValues(0,0);
365
                        long counter=0;
366
                        while (it.hasNext()) {
367
                            taskStatus.setCurValue(counter++);
368
                            FeatureProvider featureProvider = getStoreServices().getFeatureProviderFromFeature(
369
                                (org.gvsig.fmap.dal.feature.Feature) it.next());
370
                            writer.add(featureProvider);
371
                            featureProvider.setOID(createNewOID());
372
                            newdata.add(featureProvider);
373
                        }
374
                        data = newdata;
375
                        writer.end();
376
                        if (writer.getEnvelope() != null){
377
                            envelope = writer.getEnvelope().getGeometry().getEnvelope();
378
                        }
379
                        resource.notifyChanges();
380
//                        counterNewsOIDs = 0;
381

  
382
                        savePrjFile(file, projection);
383

  
384
                    } finally {
385
                        if (it != null) {
386
                            it.dispose();
387
                        }
388
                        if (features != null) {
389
                            features.dispose();
390
                        }
391
                    }
392
                    return null;
393
                }
394
            });
395
            this.taskStatus.terminate();
396
        } catch (Exception e) {
397
            this.taskStatus.abort();
398
            throw new PerformEditingException(getResource().toString(), e);
399
        } finally {
400
            this.taskStatus.remove();
401
        }
402
    }
403

  
404
    /**
405
     * @param featureType
406
     * @param projection
407
     * @param geometrySubtype
408
     * @throws LocatorException
409
     * @throws GeometryTypeNotValidException
410
     * @throws GeometryTypeNotSupportedException
411
     */
412
    public static void initializeFeatureType(EditableFeatureType featureType, IProjection projection, int geometrySubtype) {
413
        featureType.setHasOID(true);
414

  
415
//        ID_FIELD_ID = 0;
416
        featureType.add(NAME_FIELD_ID, DataTypes.INT)
417
        .setDefaultValue(Integer.valueOf(0))
418
        .getIndex();
419

  
420
        EditableFeatureAttributeDescriptor attr = featureType.add(
421
            NAME_FIELD_GEOMETRY, DataTypes.GEOMETRY);
422
        attr.setSRS(projection);
423
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
424

  
425
        try {
426
            GeometryType geometryType = geometryManager.getGeometryType(Geometry.TYPES.GEOMETRY, geometrySubtype);
427
            attr.setGeometryType(geometryType);
428
        } catch (GeometryTypeNotSupportedException | GeometryTypeNotValidException e) {
429
            logger.error("Can't create geometry type " + Geometry.TYPES.GEOMETRY + " with subtype " + geometrySubtype, e);
430
            attr.setGeometryType(Geometry.TYPES.GEOMETRY);
431
            attr.setGeometrySubType(geometrySubtype);
432
        }
433

  
434
//        ID_FIELD_GEOMETRY = 1; //attr.getIndex();
435

  
436
        featureType.setDefaultGeometryAttributeName(NAME_FIELD_GEOMETRY);
437

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

  
445
        // FIXME: Cual es el size de Layer ?
446
//        ID_FIELD_LAYER = 3;
447
        featureType.add(NAME_FIELD_LAYER,
448
            DataTypes.STRING, 100)
449
            .setDefaultValue(
450
            "default").getIndex();
451

  
452
//        ID_FIELD_COLOR = 4;
453
        featureType.add(NAME_FIELD_COLOR,
454
            DataTypes.INT)
455
            .setDefaultValue(
456
                Integer.valueOf(0)).getIndex();
457

  
458
//        ID_FIELD_ELEVATION = 5;
459
        featureType.add(NAME_FIELD_ELEVATION,
460
            DataTypes.DOUBLE)
461
            .setDefaultValue(
462
                Double.valueOf(0)).getIndex();
463

  
464
//        ID_FIELD_THICKNESS = 6;
465
        featureType.add(NAME_FIELD_THICKNESS,
466
            DataTypes.DOUBLE)
467
            .setDefaultValue(
468
                Double.valueOf(0)).getIndex();
469

  
470
        // FIXME: Cual es el size de Text ?
471
//        ID_FIELD_TEXT = 7;
472
        featureType.add(NAME_FIELD_TEXT,
473
            DataTypes.STRING, 100)
474
            .setDefaultValue("")
475
            .getIndex();
476

  
477
//        ID_FIELD_HEIGHTTEXT = 8;
478
        featureType.add(NAME_FIELD_HEIGHTTEXT,
479
            DataTypes.DOUBLE).setDefaultValue(
480
                Double.valueOf(10)).getIndex();
481

  
482
//        ID_FIELD_ROTATIONTEXT = 9;
483
        featureType.add(NAME_FIELD_ROTATIONTEXT,
484
            DataTypes.DOUBLE).setDefaultValue(
485
                Double.valueOf(0)).getIndex();
486

  
487
        // FIXME: Parece que el DXF puede tener mas atributos opcionales.
488
        // Habria que ver de pillarlos ?
489

  
490
    }
491

  
492
    /**
493
     * @author gvSIG team
494
     *
495
     */
496
    public class Reader {
497
        private File file;
498
        private String fileName;
499
        private IProjection projection;
500
        private List<EditableFeatureType> types;
501
        private LegendBuilder leyendBuilder;
502
        private AbstractMemoryStoreProvider store;
503
        private Envelope envelope;
504

  
505
        //Next two variables are used to read the DXF file
506
        private DxfFeatureMaker featureMaker;
507
        private DxfHeaderManager headerManager;
508

  
509
        /**
510
         * @param store
511
         * @param file
512
         * @param projection
513
         * @param leyendBuilder
514
         * @return the reader
515
         */
516
        public Reader initialice(AbstractMemoryStoreProvider store, File file,
517
            IProjection projection,
518
            LegendBuilder leyendBuilder) {
519
            this.store = store;
520
            this.file = file;
521
            this.fileName = file.getAbsolutePath();
522
            this.projection = projection;
523
            this.leyendBuilder = leyendBuilder;
524
            if (leyendBuilder != null) {
525
                leyendBuilder.initialize(store);
526
            }
527
            return this;
528
        }
529

  
530
        /**
531
         * @return the envelope
532
         */
533
        public Envelope getEnvelope() {
534
            return this.envelope;
535
        }
536

  
537
        /**
538
         * @param store
539
         * @throws LoadException
540
         */
541
        public void begin(FeatureStoreProviderServices store) throws LoadException {
542
            taskStatus.message("_preloading_data");
543
            featureMaker = new DxfFeatureMaker(projection);
544
            headerManager = new DxfHeaderManager();
545
            DxfFile dxfFeatureFile = new DxfFile(projection, file
546
                .getAbsolutePath(), featureMaker, headerManager);
547

  
548
            try {
549
                dxfFeatureFile.load();
550
            } catch (Exception e1) {
551
                throw new LoadException(e1, fileName);
552
            }
553

  
554
            taskStatus.message("_preparing_featureType");
555
            int geometrySubtype;
556
			if (featureMaker.isDxf3DFile() && headerManager.isWritedDxf3D()){
557
                geometrySubtype = Geometry.SUBTYPES.GEOM3D;
558
            }else{
559
            	geometrySubtype = Geometry.SUBTYPES.GEOM2D;
560
            }
561
			EditableFeatureType featureType = store.createFeatureType(getName());
562
			initializeFeatureType(featureType, this.projection, geometrySubtype);
563

  
564
            types = new ArrayList<EditableFeatureType>();
565
            types.add(featureType);
566

  
567
            if (leyendBuilder != null) {
568
                taskStatus.message("_preparing_leyend");
569
                leyendBuilder.begin();
570
            }
571

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

Also available in: Unified diff