Revision 591
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.127/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFNewStoreParameters.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.dxf; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
|
|
6 |
import org.apache.commons.io.FileUtils; |
|
7 |
import org.apache.commons.io.FilenameUtils; |
|
8 |
import org.cresques.cts.ICRSFactory; |
|
9 |
import org.cresques.cts.IProjection; |
|
10 |
|
|
11 |
import org.gvsig.fmap.crs.CRSFactory; |
|
12 |
import org.gvsig.fmap.dal.DALLocator; |
|
13 |
import org.gvsig.fmap.dal.DataManager; |
|
14 |
import org.gvsig.fmap.dal.FileHelper; |
|
15 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
17 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
18 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
19 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
|
20 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
21 |
import static org.gvsig.fmap.dal.store.dxf.DXFOpenStoreParameters.CRS_PARAMTER_NAME; |
|
22 |
import static org.gvsig.fmap.dal.store.dxf.DXFOpenStoreParameters.FILE_PARAMTER_NAME; |
|
23 |
import static org.gvsig.fmap.dal.store.dxf.DXFOpenStoreParameters.PARAMETERS_DEFINITION_NAME; |
|
24 |
import org.gvsig.fmap.geom.Geometry; |
|
25 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
26 |
|
|
27 |
public class DXFNewStoreParameters |
|
28 |
extends AbstractDataParameters implements |
|
29 |
FilesystemStoreParameters, |
|
30 |
NewFeatureStoreParameters { |
|
31 |
|
|
32 |
private DelegatedDynObject parameters; |
|
33 |
|
|
34 |
public DXFNewStoreParameters() { |
|
35 |
this(PARAMETERS_DEFINITION_NAME); |
|
36 |
} |
|
37 |
|
|
38 |
protected DXFNewStoreParameters(String parametersDefinitionName) { |
|
39 |
this(parametersDefinitionName, DXFStoreProvider.NAME); |
|
40 |
} |
|
41 |
|
|
42 |
public DXFNewStoreParameters(String parametersDefinitionName, String name) { |
|
43 |
super(); |
|
44 |
this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName); |
|
45 |
this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public String getDataStoreName() { |
|
50 |
return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
|
51 |
} |
|
52 |
|
|
53 |
@Override |
|
54 |
public String getDescription() { |
|
55 |
return this.getDynClass().getDescription(); |
|
56 |
} |
|
57 |
|
|
58 |
@Override |
|
59 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
60 |
return parameters; |
|
61 |
} |
|
62 |
|
|
63 |
public void setCRS(String srs) { |
|
64 |
setDynValue(CRS_PARAMTER_NAME, srs); |
|
65 |
} |
|
66 |
|
|
67 |
public void setCRS(IProjection srs) { |
|
68 |
setDynValue(CRS_PARAMTER_NAME, srs); |
|
69 |
} |
|
70 |
|
|
71 |
public IProjection getCRS() { |
|
72 |
return (IProjection) getDynValue(CRS_PARAMTER_NAME); |
|
73 |
} |
|
74 |
|
|
75 |
public String getFileName() { |
|
76 |
if (this.getFile() == null) { |
|
77 |
return null; |
|
78 |
} |
|
79 |
return this.getFile().getPath(); |
|
80 |
} |
|
81 |
|
|
82 |
@Override |
|
83 |
public boolean isValid() { |
|
84 |
if (getCRS() == null) { |
|
85 |
return false; |
|
86 |
} |
|
87 |
return getFileName() != null; |
|
88 |
} |
|
89 |
|
|
90 |
@Override |
|
91 |
public File getFile() { |
|
92 |
return (File) this.getDynValue(FILE_PARAMTER_NAME); |
|
93 |
} |
|
94 |
|
|
95 |
@Override |
|
96 |
public void setFile(File file) { |
|
97 |
this.setDynValue(FILE_PARAMTER_NAME, file); |
|
98 |
|
|
99 |
if (getCRS() == null) { |
|
100 |
String wktEsri = loadPrj(file); |
|
101 |
if (wktEsri != null) { |
|
102 |
IProjection proj = CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, wktEsri); |
|
103 |
setCRS(proj); |
|
104 |
} |
|
105 |
} |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
public void setFile(String file) { |
|
110 |
this.setDynValue(FILE_PARAMTER_NAME, file); |
|
111 |
|
|
112 |
File dxfFile = (File) this.getDynValue(FILE_PARAMTER_NAME); |
|
113 |
if (getCRS() == null) { |
|
114 |
String wktEsri = loadPrj(dxfFile); |
|
115 |
if (wktEsri != null) { |
|
116 |
IProjection proj = CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, wktEsri); |
|
117 |
setCRS(proj); |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public EditableFeatureType getDefaultFeatureType() { |
|
125 |
// FIXME: Esto no se si funciona. |
|
126 |
DataManager manager = DALLocator.getDataManager(); |
|
127 |
EditableFeatureType featureType = manager.createFeatureType(); |
|
128 |
DXFStoreProvider.initializeFeatureType(featureType, null, Geometry.SUBTYPES.GEOM3D); |
|
129 |
return featureType; |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public void setDefaultFeatureType(FeatureType defaultFeatureType) { |
|
134 |
throw new UnsupportedOperationException(); |
|
135 |
} |
|
136 |
|
|
137 |
private String loadPrj(File dxfFile) { |
|
138 |
File prjFile = new File(FilenameUtils.removeExtension(dxfFile.getAbsolutePath()) + ".prj"); |
|
139 |
if (prjFile.exists()) { |
|
140 |
try { |
|
141 |
return FileUtils.readFileToString(prjFile); |
|
142 |
} catch (IOException e) { |
|
143 |
return null; |
|
144 |
} |
|
145 |
} |
|
146 |
return null; |
|
147 |
} |
|
148 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.127/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((DXFOpenStoreParameters) parameters, providerServices); |
|
23 |
} |
|
24 |
|
|
25 |
public DynObject createParameters() { |
|
26 |
return new DXFOpenStoreParameters(); |
|
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.127/org.gvsig.dxf.provider/src/main/java/org/gvsig/fmap/dal/store/dxf/DXFOpenStoreParameters.java | ||
---|---|---|
1 |
package org.gvsig.fmap.dal.store.dxf; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
|
|
6 |
import org.apache.commons.io.FileUtils; |
|
7 |
import org.apache.commons.io.FilenameUtils; |
|
8 |
import org.cresques.cts.ICRSFactory; |
|
9 |
import org.cresques.cts.IProjection; |
|
10 |
|
|
11 |
import org.gvsig.fmap.crs.CRSFactory; |
|
12 |
import org.gvsig.fmap.dal.FileHelper; |
|
13 |
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters; |
|
14 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
15 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
|
16 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
17 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
18 |
|
|
19 |
public class DXFOpenStoreParameters |
|
20 |
extends AbstractDataParameters |
|
21 |
implements |
|
22 |
OpenFeatureStoreParameters, |
|
23 |
FilesystemStoreParameters { |
|
24 |
|
|
25 |
public static final String PARAMETERS_DEFINITION_NAME = "DXFStoreParameters"; |
|
26 |
|
|
27 |
static final String FILE_PARAMTER_NAME = "File"; |
|
28 |
static final String CRS_PARAMTER_NAME = "CRS"; |
|
29 |
|
|
30 |
private DelegatedDynObject parameters; |
|
31 |
|
|
32 |
public DXFOpenStoreParameters() { |
|
33 |
this(PARAMETERS_DEFINITION_NAME); |
|
34 |
} |
|
35 |
|
|
36 |
protected DXFOpenStoreParameters(String parametersDefinitionName) { |
|
37 |
this(parametersDefinitionName, DXFStoreProvider.NAME); |
|
38 |
} |
|
39 |
|
|
40 |
public DXFOpenStoreParameters(String parametersDefinitionName, String name) { |
|
41 |
super(); |
|
42 |
this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName); |
|
43 |
this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public String getDataStoreName() { |
|
48 |
return (String) this.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public String getDescription() { |
|
53 |
return this.getDynClass().getDescription(); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
58 |
return parameters; |
|
59 |
} |
|
60 |
|
|
61 |
public void setCRS(String srs) { |
|
62 |
setDynValue(CRS_PARAMTER_NAME, srs); |
|
63 |
} |
|
64 |
|
|
65 |
public void setCRS(IProjection srs) { |
|
66 |
setDynValue(CRS_PARAMTER_NAME, srs); |
|
67 |
} |
|
68 |
|
|
69 |
public IProjection getCRS() { |
|
70 |
return (IProjection) getDynValue(CRS_PARAMTER_NAME); |
|
71 |
} |
|
72 |
|
|
73 |
public String getFileName() { |
|
74 |
if (this.getFile() == null) { |
|
75 |
return null; |
|
76 |
} |
|
77 |
return this.getFile().getPath(); |
|
78 |
} |
|
79 |
|
|
80 |
@Override |
|
81 |
public boolean isValid() { |
|
82 |
if (getCRS() == null) { |
|
83 |
return false; |
|
84 |
} |
|
85 |
return getFileName() != null; |
|
86 |
} |
|
87 |
|
|
88 |
@Override |
|
89 |
public File getFile() { |
|
90 |
return (File) this.getDynValue(FILE_PARAMTER_NAME); |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public void setFile(File file) { |
|
95 |
this.setDynValue(FILE_PARAMTER_NAME, file); |
|
96 |
|
|
97 |
if (getCRS() == null) { |
|
98 |
String wktEsri = loadPrj(file); |
|
99 |
if (wktEsri != null) { |
|
100 |
IProjection proj = CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, wktEsri); |
|
101 |
setCRS(proj); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
public void setFile(String file) { |
|
108 |
this.setDynValue(FILE_PARAMTER_NAME, file); |
|
109 |
|
|
110 |
File dxfFile = (File) this.getDynValue(FILE_PARAMTER_NAME); |
|
111 |
if (getCRS() == null) { |
|
112 |
String wktEsri = loadPrj(dxfFile); |
|
113 |
if (wktEsri != null) { |
|
114 |
IProjection proj = CRSFactory.getCRSFactory().get(ICRSFactory.FORMAT_WKT_ESRI, wktEsri); |
|
115 |
setCRS(proj); |
|
116 |
} |
|
117 |
} |
|
118 |
|
|
119 |
} |
|
120 |
|
|
121 |
private String loadPrj(File dxfFile) { |
|
122 |
File prjFile = new File(FilenameUtils.removeExtension(dxfFile.getAbsolutePath()) + ".prj"); |
|
123 |
if (prjFile.exists()) { |
|
124 |
try { |
|
125 |
return FileUtils.readFileToString(prjFile); |
|
126 |
} catch (IOException e) { |
|
127 |
return null; |
|
128 |
} |
|
129 |
} |
|
130 |
return null; |
|
131 |
} |
|
132 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.127/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.127/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 |
DXFOpenStoreParameters.PARAMETERS_DEFINITION_NAME, |
|
61 |
DXFOpenStoreParameters.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.127/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.DataServerExplorer; |
|
10 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
11 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
12 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
13 |
import org.gvsig.fmap.dal.exception.DataException; |
|
14 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
|
15 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
16 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
17 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
|
18 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
19 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
20 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
21 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.AbsolutePathRequiredException; |
|
22 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
|
23 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
|
24 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
|
25 |
|
|
26 |
public class DXFFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider |
|
27 |
implements FilesystemServerExplorerProvider, ResourceConsumer { |
|
28 |
|
|
29 |
private FilesystemServerExplorerProviderServices serverExplorer; |
|
30 |
|
|
31 |
@Override |
|
32 |
public String getDataStoreProviderName() { |
|
33 |
return DXFStoreProvider.NAME; |
|
34 |
} |
|
35 |
|
|
36 |
@Override |
|
37 |
public int getMode() { |
|
38 |
return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY; |
|
39 |
} |
|
40 |
|
|
41 |
@Override |
|
42 |
public boolean accept(File pathname) { |
|
43 |
return (pathname.getName().toLowerCase().endsWith(".dxf")); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public String getDescription() { |
|
48 |
return DXFStoreProvider.DESCRIPTION; |
|
49 |
} |
|
50 |
|
|
51 |
@Override |
|
52 |
public boolean canCreate() { |
|
53 |
return true; |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public boolean canCreate(NewDataStoreParameters parameters) { |
|
58 |
if (!(parameters instanceof DXFOpenStoreParameters)) { |
|
59 |
throw new IllegalArgumentException(); // FIXME ??? |
|
60 |
} |
|
61 |
DXFOpenStoreParameters dxfParams = (DXFOpenStoreParameters) parameters; |
|
62 |
// TODO comporbar si el ftype es correcto (para este formato es fijo) |
|
63 |
File file = new File(dxfParams.getFileName()); |
|
64 |
|
|
65 |
if (dxfParams.getCRS() == null) { |
|
66 |
return false; |
|
67 |
} |
|
68 |
// TODO comprobamos extension del fichero ?? |
|
69 |
if (file.exists()) { |
|
70 |
return file.canWrite(); |
|
71 |
} else { |
|
72 |
return file.getParentFile().canWrite(); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
@Override |
|
77 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
|
78 |
throws CreateException { |
|
79 |
|
|
80 |
final IProjection projection = null; |
|
81 |
DXFNewStoreParameters params = (DXFNewStoreParameters) parameters; |
|
82 |
|
|
83 |
File file = params.getFile(); |
|
84 |
if (!file.isAbsolute()) { |
|
85 |
throw new AbsolutePathRequiredException(file.getPath()); |
|
86 |
} |
|
87 |
|
|
88 |
if (file.exists()) { |
|
89 |
if (overwrite) { |
|
90 |
if (!file.delete()) { |
|
91 |
throw new CreateException(this.getDataStoreProviderName(), |
|
92 |
new IOException( |
|
93 |
"cannot delete file")); |
|
94 |
} |
|
95 |
} else { |
|
96 |
throw new CreateException(this.getDataStoreProviderName(), |
|
97 |
new IOException( |
|
98 |
"file already exist")); |
|
99 |
} |
|
100 |
} |
|
101 |
|
|
102 |
// projection = CRSFactory.getCRS(params.getSRSID()); |
|
103 |
final FileResource resource; |
|
104 |
try { |
|
105 |
resource = (FileResource) this.serverExplorer |
|
106 |
.getServerExplorerProviderServices().createResource( |
|
107 |
FileResource.NAME, |
|
108 |
new Object[]{file.getAbsolutePath()}); |
|
109 |
} catch (InitializeException e1) { |
|
110 |
throw new CreateException(params.getFileName(), e1); |
|
111 |
} |
|
112 |
resource.addConsumer(this); |
|
113 |
|
|
114 |
try { |
|
115 |
resource.execute(new ResourceAction() { |
|
116 |
public Object run() throws Exception { |
|
117 |
Builder builder |
|
118 |
= new Builder().initialice(resource.getFileName(), |
|
119 |
projection); |
|
120 |
resource.notifyOpen(); |
|
121 |
builder.begin(); |
|
122 |
builder.create(); |
|
123 |
builder.end(); |
|
124 |
resource.notifyClose(); |
|
125 |
|
|
126 |
resource.setData(null); // FIXME: Seguro que hay que ponerlo |
|
127 |
// a null ?? |
|
128 |
resource.notifyChanges(); |
|
129 |
return null; |
|
130 |
} |
|
131 |
}); |
|
132 |
} catch (Exception e) { |
|
133 |
throw new CreateException(params.getFileName(), e); |
|
134 |
} finally { |
|
135 |
resource.removeConsumer(this); |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
public class Builder { |
|
140 |
|
|
141 |
private String fileName; |
|
142 |
private IProjection projection; |
|
143 |
|
|
144 |
public Builder initialice(String fileName, IProjection projection) { |
|
145 |
this.fileName = fileName; |
|
146 |
this.projection = projection; |
|
147 |
return this; |
|
148 |
} |
|
149 |
|
|
150 |
public void begin() { |
|
151 |
|
|
152 |
} |
|
153 |
|
|
154 |
public void end() { |
|
155 |
|
|
156 |
} |
|
157 |
|
|
158 |
public void create() throws IOException { |
|
159 |
DxfEntityMaker entityMaker = new DxfEntityMaker(projection); |
|
160 |
DxfFile dxfFile = new DxfFile(null, fileName, entityMaker); |
|
161 |
dxfFile.setCadFlag(true); |
|
162 |
dxfFile.setDxf3DFlag(false); |
|
163 |
dxfFile.save(fileName); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
@Override |
|
168 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
|
169 |
return new DXFNewStoreParameters(); |
|
170 |
} |
|
171 |
|
|
172 |
@Override |
|
173 |
public void initialize( |
|
174 |
FilesystemServerExplorerProviderServices serverExplorer) { |
|
175 |
this.serverExplorer = serverExplorer; |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
179 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
180 |
File file = new File(((DXFOpenStoreParameters) parameters).getFileName()); |
|
181 |
if (!file.exists()) { |
|
182 |
throw new RemoveException(this.getDataStoreProviderName(), |
|
183 |
new FileNotFoundException(file)); |
|
184 |
} |
|
185 |
if (!file.delete()) { |
|
186 |
// FIXME throws ??? |
|
187 |
} |
|
188 |
|
|
189 |
} |
|
190 |
|
|
191 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
192 |
// while it is using a resource anyone can't close it |
|
193 |
return false; |
|
194 |
} |
|
195 |
|
|
196 |
@Override |
|
197 |
public void resourceChanged(ResourceProvider resource) { |
|
198 |
//Do nothing |
|
199 |
|
|
200 |
} |
|
201 |
|
|
202 |
} |
org.gvsig.dxf/tags/org.gvsig.dxf-2.0.127/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(DXFOpenStoreParameters 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 DXFOpenStoreParameters getDXFParameters() { |
|
187 |
return (DXFOpenStoreParameters) 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 |
} |
|
573 |
|
|
574 |
/** |
|
575 |
* |
|
576 |
*/ |
|
577 |
public void end() { |
|
578 |
if (leyendBuilder != null) { |
|
579 |
leyendBuilder.end(); |
|
580 |
} |
|
581 |
} |
|
582 |
|
|
583 |
/** |
|
584 |
* @return the list of feature types |
|
585 |
*/ |
|
586 |
public List<EditableFeatureType> getTypes() { |
|
587 |
return types; |
|
588 |
} |
|
589 |
|
|
590 |
/** |
|
591 |
* @return the default editable feature type |
|
592 |
*/ |
|
593 |
public EditableFeatureType getDefaultType() { |
|
594 |
return types.get(0); |
|
595 |
} |
|
596 |
|
|
597 |
private Double toDouble(String value) { |
|
598 |
if (value == null) { |
|
599 |
return Double.valueOf(0); |
|
600 |
} |
|
601 |
return Double.valueOf(value); |
|
602 |
} |
|
603 |
|
|
604 |
private FeatureProvider createFeature(Feature fea, FeatureType ft, int id) throws DataException { |
|
605 |
|
|
606 |
FeatureProvider feature = store.createFeatureProvider(ft); |
|
607 |
|
|
608 |
feature.setOID(new Long(id)); |
|
609 |
feature.set(ID_FIELD_ID, Integer.valueOf(id)); |
|
610 |
feature.set(ID_FIELD_ENTITY, fea.getProp("dxfEntity")); |
|
611 |
feature.set(ID_FIELD_LAYER, fea.getProp("layer")); |
|
612 |
feature.set(ID_FIELD_COLOR, Integer.valueOf(fea.getProp("color"))); |
|
613 |
feature.set(ID_FIELD_TEXT, fea.getProp("text")); |
|
614 |
feature.set(ID_FIELD_HEIGHTTEXT, toDouble(fea.getProp("textHeight"))); |
|
615 |
feature.set(ID_FIELD_ROTATIONTEXT, toDouble(fea.getProp("textRotation"))); |
|
616 |
feature.set(ID_FIELD_ELEVATION, toDouble(fea.getProp("elevation"))); |
|
617 |
feature.set(ID_FIELD_THICKNESS, toDouble(fea.getProp("thickness"))); |
|
618 |
feature.set(ID_FIELD_GEOMETRY, null); |
|
619 |
// FIXME: Habria que pillar el resto de atributos del DXF. |
|
620 |
|
|
621 |
// FIXME: Habia una incongruencia en el codigo ya que al |
|
622 |
// campo |
|
623 |
// ID_FIELD_GEOMETRY igual le asignaba una geometria que un |
|
624 |
// valor de cadena como 'Point3D', 'Polyline2D' o |
|
625 |
// 'Polyline3D' |
|
626 |
// Faltaria un atributo ID_FIELD_FSHAPE ? |
|
627 |
// |
|
628 |
return feature; |
|
629 |
} |
|
630 |
|
|
631 |
private Geometry processPoints(GeometryManager gManager, Feature dxffeature) throws CreateGeometryException { |
|
632 |
if (dxffeature.getGeometry() instanceof org.gvsig.dxf.px.gml.Point3D) { |
|
633 |
org.gvsig.dxf.px.gml.Point3D point = (org.gvsig.dxf.px.gml.Point3D) dxffeature.getGeometry(); |
|
634 |
Point3D pto = point.getPoint3D(0); |
|
635 |
org.gvsig.fmap.geom.primitive.Point geom = gManager.createPoint(pto.getX(), pto.getY(), SUBTYPES.GEOM3D); |
|
636 |
geom.setCoordinateAt(Geometry.DIMENSIONS.Z, pto.getZ()); |
|
637 |
|
|
638 |
if (point.isTextPoint()) { |
|
639 |
/// TODO labeling |
|
640 |
} |
|
641 |
return geom; |
|
642 |
|
|
643 |
} |
|
644 |
if (dxffeature.getGeometry() instanceof Point) { |
|
645 |
Point point = (Point) dxffeature.getGeometry(); |
|
646 |
Point2D pto = point.get(0); |
|
647 |
|
|
648 |
org.gvsig.fmap.geom.primitive.Point geom = gManager.createPoint(pto.getX(), pto.getY(), SUBTYPES.GEOM2D); |
|
649 |
|
|
650 |
if (point.isTextPoint()) { |
|
651 |
/// TODO labeling |
|
652 |
} |
|
653 |
return geom; |
|
654 |
} |
|
655 |
return null; |
|
656 |
} |
|
657 |
|
|
658 |
private Geometry processLines(GeometryManager gManager, Feature dxffeature) throws CreateGeometryException { |
|
659 |
if (dxffeature.getGeometry() instanceof LineString3D) { |
|
660 |
Line line = gManager.createLine(SUBTYPES.GEOM3D); |
|
661 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
662 |
Point3D point = ((LineString3D) dxffeature.getGeometry()).getPoint3D(j); |
|
663 |
line.addVertex(point.getX(), point.getY(), point.getZ()); |
|
664 |
} |
|
665 |
return line; |
|
666 |
|
|
667 |
} |
|
668 |
if (dxffeature.getGeometry() instanceof LineString) { |
|
669 |
Line line = gManager.createLine(SUBTYPES.GEOM2D); |
|
670 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
671 |
Point2D point = dxffeature.getGeometry().get(j); |
|
672 |
line.addVertex(point.getX(), point.getY()); |
|
673 |
} |
|
674 |
return line; |
|
675 |
} |
|
676 |
return null; |
|
677 |
} |
|
678 |
|
|
679 |
private Geometry processPolygons(GeometryManager gManager, Feature dxffeature) throws CreateGeometryException { |
|
680 |
org.gvsig.dxf.px.gml.Geometry geom = dxffeature.getGeometry(); |
|
681 |
if( geom instanceof Polygon ) { |
|
682 |
if ( ((Polygon) geom).is3D() ) { |
|
683 |
org.gvsig.fmap.geom.primitive.Polygon polygon = gManager.createPolygon(SUBTYPES.GEOM3D); |
|
684 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
685 |
Point3D point = (Point3D) dxffeature.getGeometry().get(j); |
|
686 |
polygon.addVertex(point.getX(), point.getY(), point.getZ()); |
|
687 |
} |
|
688 |
Point3D point = (Point3D) dxffeature.getGeometry().get(0); |
|
689 |
polygon.addVertex(point.getX(), point.getY(), point.getZ()); |
|
690 |
return polygon; |
|
691 |
|
|
692 |
} else { |
|
693 |
org.gvsig.fmap.geom.primitive.Polygon polygon = gManager.createPolygon(SUBTYPES.GEOM2D); |
|
694 |
for (int j = 0; j < dxffeature.getGeometry().pointNr(); j++) { |
|
695 |
Point2D point = dxffeature.getGeometry().get(j); |
|
696 |
polygon.addVertex(point.getX(), point.getY()); |
|
697 |
} |
|
698 |
Point2D point = dxffeature.getGeometry().get(0); |
|
699 |
polygon.addVertex(point.getX(), point.getY()); |
|
700 |
return polygon; |
|
701 |
} |
|
702 |
} |
|
703 |
return null; |
|
704 |
} |
|
705 |
|
|
706 |
private void addGeometryToFeature(Geometry geometry, FeatureProvider feature) { |
|
707 |
if( geometry != null ) { |
|
708 |
feature.set(ID_FIELD_GEOMETRY, geometry); |
|
709 |
feature.setDefaultGeometry(geometry); |
|
710 |
if (this.envelope == null) { |
|
711 |
this.envelope = geometry.getEnvelope(); |
|
712 |
} else { |
|
713 |
this.envelope.add(geometry.getEnvelope()); |
|
714 |
} |
|
715 |
} |
|
716 |
} |
|
717 |
|
|
718 |
private void addfeatureToLegend(FeatureProvider feature) { |
|
719 |
if (leyendBuilder != null) { |
|
720 |
try { |
|
721 |
leyendBuilder.process(feature); |
|
722 |
} catch (Exception e) { |
|
723 |
logger.warn( |
|
724 |
MessageFormat.format( |
|
725 |
"load: legendBuilder process fails in the feature {1}", |
|
726 |
feature |
|
727 |
) |
|
728 |
); |
|
729 |
} |
|
730 |
} |
|
731 |
} |
|
732 |
|
|
733 |
/** |
|
734 |
* @throws DataException |
|
735 |
*/ |
|
736 |
public void load() throws DataException { |
|
737 |
|
|
738 |
this.envelope = null; |
|
739 |
|
|
740 |
IObjList.vector features = (IObjList.vector)featureMaker.getObjects(); |
|
741 |
String acadVersion = headerManager.getAcadVersion(); |
|
742 |
|
|
743 |
logger.info("load: acadVersion = '" + acadVersion + "'"); |
|
744 |
|
|
745 |
GeometryManager gManager = GeometryLocator.getGeometryManager(); |
|
746 |
|
|
747 |
if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) { |
|
748 |
taskStatus.message("_fixing_3dgeometries"); |
|
749 |
Feature[] features2D = new Feature[features.size()]; |
|
750 |
taskStatus.setRangeOfValues(0,features.size()); |
|
751 |
for (int i = 0; i < features.size(); i++) { |
|
752 |
taskStatus.setCurValue(i); |
|
753 |
Feature fea = (Feature) features.get(i); |
|
754 |
if (fea.getGeometry() instanceof org.gvsig.dxf.px.gml.Point3D) { |
|
755 |
Point point = (Point) fea.getGeometry(); |
|
756 |
Point point2 = new Point(); |
|
757 |
for (int j = 0; j < point.pointNr(); j++) { |
|
758 |
point2.add(point.get(j)); |
|
759 |
} |
|
760 |
point2.setTextPoint(point.isTextPoint()); |
|
761 |
fea.setGeometry(point2); |
|
762 |
features2D[i] = fea; |
|
763 |
|
|
764 |
} else if (fea.getGeometry() instanceof LineString3D) { |
|
765 |
LineString lineString = (LineString) fea.getGeometry(); |
|
766 |
LineString lineString2 = new LineString(); |
|
767 |
for (int j = 0; j < lineString.pointNr(); j++) { |
|
768 |
lineString2.add(lineString.get(j)); |
|
769 |
} |
|
770 |
fea.setGeometry(lineString2); |
|
771 |
features2D[i] = fea; |
|
772 |
} else if (fea.getGeometry() instanceof Polygon3D) { |
|
773 |
Polygon polygon = (Polygon) fea.getGeometry(); |
|
774 |
Polygon polygon2 = new Polygon(); |
|
775 |
for (int j = 0; j < polygon.pointNr(); j++) { |
|
776 |
polygon2.add(polygon.get(j)); |
|
777 |
} |
|
778 |
fea.setGeometry(polygon2); |
|
779 |
features2D[i] = fea; |
|
780 |
} |
|
781 |
} |
|
782 |
features.clear(); |
|
783 |
for (int i = 0; i < features2D.length; i++) { |
|
784 |
features.add(features2D[i]); |
|
785 |
} |
|
786 |
} |
|
787 |
|
|
788 |
FilteredLogger logger = new FilteredLogger(DXFStoreProvider.logger,"DXFLoafing",20); |
|
789 |
|
|
790 |
FeatureType ft = store.getStoreServices().getDefaultFeatureType(); |
|
791 |
taskStatus.message("_loading"); |
|
792 |
// Nos recorremos las geometrias tres veces para cargarlas en orden: |
|
793 |
// - poligonos |
|
794 |
// - lineas |
|
795 |
// - puntos |
|
796 |
// Y garantizar que siempre se pinten los puntos sobre lineas y |
|
797 |
// poligonos y las lineas sobre los polignos. |
|
798 |
int n = 0; |
|
799 |
taskStatus.setRangeOfValues(0,features.size()*3); |
|
800 |
for (int i = 0; i < features.size(); i++) { |
|
801 |
taskStatus.setCurValue(n++); |
|
802 |
try { |
|
803 |
Feature dxffeature = (Feature) features.get(i); |
Also available in: Unified diff