Revision 39441
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/DWGRegisterExtension.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 |
package org.gvsig.dwg; |
|
23 |
|
|
24 |
import org.gvsig.andami.IconThemeHelper; |
|
25 |
import org.gvsig.andami.plugins.Extension; |
|
26 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGLibrary; |
|
27 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGStoreProvider; |
|
28 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
29 |
|
|
30 |
/** |
|
31 |
* Dummy DWG extension, as all the registration happens in the |
|
32 |
* {@link DWGLibrary}. |
|
33 |
* |
|
34 |
* @author gvSIG Team |
|
35 |
*/ |
|
36 |
public class DWGRegisterExtension extends Extension { |
|
37 |
|
|
38 |
public void execute(String actionCommand) { |
|
39 |
// Nothing to do |
|
40 |
} |
|
41 |
|
|
42 |
public void initialize() { |
|
43 |
IconThemeHelper.registerIcon("layer", "layer-icon-dwg", this); |
|
44 |
} |
|
45 |
|
|
46 |
public void postInitialize() { |
|
47 |
MapContextLocator.getMapContextManager().registerIconLayer(DWGStoreProvider.NAME, "layer-icon-dwg"); |
|
48 |
} |
|
49 |
|
|
50 |
public boolean isEnabled() { |
|
51 |
// Nothing to do |
|
52 |
return false; |
|
53 |
} |
|
54 |
|
|
55 |
public boolean isVisible() { |
|
56 |
// Nothing to do |
|
57 |
return false; |
|
58 |
} |
|
59 |
|
|
60 |
} |
|
0 | 61 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/DWGStoreParameters.java | ||
---|---|---|
1 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.cresques.cts.IProjection; |
|
6 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
7 |
import org.gvsig.fmap.dal.FileHelper; |
|
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
9 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
10 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
11 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
12 |
import org.gvsig.fmap.dal.spi.AbstractDataParameters; |
|
13 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
14 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
15 |
|
|
16 |
public class DWGStoreParameters extends AbstractDataParameters implements |
|
17 |
DataStoreParameters, FilesystemStoreParameters, |
|
18 |
NewFeatureStoreParameters { |
|
19 |
|
|
20 |
public static final String PARAMETERS_DEFINITION_NAME = "DWGStoreParameters"; |
|
21 |
|
|
22 |
private static final String FIELD_FILE = "file"; |
|
23 |
private static final String FIELD_CRS = "CRS"; |
|
24 |
|
|
25 |
private DelegatedDynObject parameters; |
|
26 |
|
|
27 |
public DWGStoreParameters() { |
|
28 |
this(PARAMETERS_DEFINITION_NAME); |
|
29 |
} |
|
30 |
|
|
31 |
protected DWGStoreParameters(String parametersDefinitionName) { |
|
32 |
this(parametersDefinitionName, DWGStoreProvider.NAME); |
|
33 |
} |
|
34 |
|
|
35 |
public DWGStoreParameters(String parametersDefinitionName, String name) { |
|
36 |
super(); |
|
37 |
this.parameters = (DelegatedDynObject) FileHelper |
|
38 |
.newParameters(parametersDefinitionName); |
|
39 |
this |
|
40 |
.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, |
|
41 |
name); |
|
42 |
} |
|
43 |
|
|
44 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
45 |
return parameters; |
|
46 |
} |
|
47 |
|
|
48 |
public String getDataStoreName() { |
|
49 |
return (String) this |
|
50 |
.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
|
51 |
} |
|
52 |
|
|
53 |
public String getDescription() { |
|
54 |
return this.getDynClass().getDescription(); |
|
55 |
} |
|
56 |
|
|
57 |
public void setCRS(IProjection crs) { |
|
58 |
setDynValue(FIELD_CRS, crs); |
|
59 |
} |
|
60 |
|
|
61 |
public void setCRS(String crs) { |
|
62 |
setDynValue(FIELD_CRS, crs); |
|
63 |
} |
|
64 |
|
|
65 |
public IProjection getCRS() { |
|
66 |
return (IProjection) getDynValue(FIELD_CRS); |
|
67 |
} |
|
68 |
|
|
69 |
public String getFileName() { |
|
70 |
return this.getFile().getPath(); |
|
71 |
} |
|
72 |
|
|
73 |
public void setFileName(String file) { |
|
74 |
setDynValue(FIELD_FILE, file); |
|
75 |
} |
|
76 |
|
|
77 |
public boolean isValid() { |
|
78 |
if (getCRS() == null) { |
|
79 |
return false; |
|
80 |
} |
|
81 |
if (getFile() == null) { |
|
82 |
return false; |
|
83 |
} |
|
84 |
return true; |
|
85 |
} |
|
86 |
|
|
87 |
public File getFile() { |
|
88 |
return (File) this.getDynValue(FIELD_FILE); |
|
89 |
} |
|
90 |
|
|
91 |
public void setFile(File file) { |
|
92 |
this.setDynValue(FIELD_FILE, file); |
|
93 |
} |
|
94 |
|
|
95 |
public EditableFeatureType getDefaultFeatureType() { |
|
96 |
return null; //TODO ???? |
|
97 |
} |
|
98 |
|
|
99 |
public void setDefaultFeatureType(FeatureType defaultFeatureType) { |
|
100 |
throw new UnsupportedOperationException(); |
|
101 |
} |
|
102 |
|
|
103 |
} |
|
0 | 104 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/LegendBuilder.java | ||
---|---|---|
1 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
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 |
} |
|
0 | 25 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/DWGLibrary.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.dwg.fmap.dal.store.dwg; |
|
29 |
|
|
30 |
import org.gvsig.fmap.dal.DALFileLibrary; |
|
31 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
32 |
import org.gvsig.fmap.dal.DALLibrary; |
|
33 |
import org.gvsig.fmap.dal.DALLocator; |
|
34 |
import org.gvsig.fmap.dal.FileHelper; |
|
35 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
36 |
import org.gvsig.metadata.MetadataLibrary; |
|
37 |
import org.gvsig.metadata.exceptions.MetadataException; |
|
38 |
import org.gvsig.tools.ToolsLocator; |
|
39 |
import org.gvsig.tools.dynobject.DynClass; |
|
40 |
import org.gvsig.tools.dynobject.DynField; |
|
41 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
42 |
import org.gvsig.tools.library.AbstractLibrary; |
|
43 |
import org.gvsig.tools.library.LibraryException; |
|
44 |
|
|
45 |
public class DWGLibrary extends AbstractLibrary { |
|
46 |
|
|
47 |
@Override |
|
48 |
public void doRegistration() { |
|
49 |
registerAsImplementationOf(DWGLibrary.class); |
|
50 |
require(DALLibrary.class); |
|
51 |
require(DALFileLibrary.class); |
|
52 |
require(MetadataLibrary.class); |
|
53 |
} |
|
54 |
|
|
55 |
@Override |
|
56 |
protected void doInitialize() throws LibraryException { |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
protected void doPostInitialize() throws LibraryException { |
|
61 |
FileHelper.registerParametersDefinition( |
|
62 |
DWGStoreParameters.PARAMETERS_DEFINITION_NAME, |
|
63 |
DWGStoreParameters.class, |
|
64 |
"DWGParameters.xml" |
|
65 |
); |
|
66 |
try { |
|
67 |
FileHelper.registerMetadataDefinition( |
|
68 |
DWGStoreProvider.METADATA_DEFINITION_NAME, |
|
69 |
DWGStoreProvider.class, |
|
70 |
"DWGMetadata.xml" |
|
71 |
); |
|
72 |
} catch (MetadataException e) { |
|
73 |
throw new LibraryException(getClass(), e); |
|
74 |
} |
|
75 |
|
|
76 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator |
|
77 |
.getDataManager(); |
|
78 |
|
|
79 |
if (!dataman.getStoreProviders().contains(DWGStoreProvider.NAME)) { |
|
80 |
dataman.registerStoreProvider(DWGStoreProvider.NAME, |
|
81 |
DWGStoreProvider.class, DWGStoreParameters.class); |
|
82 |
} |
|
83 |
|
|
84 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
85 |
DWGStoreProvider.NAME, DWGStoreProvider.DESCRIPTION, |
|
86 |
DWGFilesystemServerProvider.class); |
|
87 |
|
|
88 |
DynObjectManager dynMan = ToolsLocator.getDynObjectManager(); |
|
89 |
DynClass dynClass = dynMan.get( |
|
90 |
DWGStoreProvider.METADATA_DEFINITION_NAME); |
|
91 |
DynField field; |
|
92 |
if (dynClass == null) { |
|
93 |
dynClass = dynMan.add( |
|
94 |
DWGStoreProvider.METADATA_DEFINITION_NAME); |
|
95 |
|
|
96 |
} |
|
97 |
} |
|
98 |
} |
|
0 | 99 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/DWGFilesystemServerProvider.java | ||
---|---|---|
1 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
|
|
5 |
import org.gvsig.fmap.dal.DALLocator; |
|
6 |
import org.gvsig.fmap.dal.DataManager; |
|
7 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
8 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
9 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
|
10 |
import org.gvsig.fmap.dal.exception.CreateException; |
|
11 |
import org.gvsig.fmap.dal.exception.DataException; |
|
12 |
import org.gvsig.fmap.dal.exception.FileNotFoundException; |
|
13 |
import org.gvsig.fmap.dal.exception.RemoveException; |
|
14 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
15 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
16 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
17 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider; |
|
18 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider; |
|
19 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices; |
|
20 |
|
|
21 |
public class DWGFilesystemServerProvider extends AbstractFilesystemServerExplorerProvider |
|
22 |
implements FilesystemServerExplorerProvider, ResourceConsumer { |
|
23 |
|
|
24 |
//private FilesystemServerExplorerProviderServices serverExplorer; |
|
25 |
|
|
26 |
public String getDataStoreProviderName() { |
|
27 |
return DWGStoreProvider.NAME; |
|
28 |
} |
|
29 |
|
|
30 |
public int getMode() { |
|
31 |
return DataServerExplorer.MODE_FEATURE | DataServerExplorer.MODE_GEOMETRY; |
|
32 |
} |
|
33 |
|
|
34 |
public boolean accept(File pathname) { |
|
35 |
return (pathname.getName().toLowerCase().endsWith(".dwg")); |
|
36 |
} |
|
37 |
|
|
38 |
public String getDescription() { |
|
39 |
return DWGStoreProvider.DESCRIPTION; |
|
40 |
} |
|
41 |
|
|
42 |
public DataStoreParameters getParameters(File file) throws DataException { |
|
43 |
DataManager manager = DALLocator.getDataManager(); |
|
44 |
DWGStoreParameters params = (DWGStoreParameters) manager |
|
45 |
.createStoreParameters(this |
|
46 |
.getDataStoreProviderName()); |
|
47 |
params.setFileName(file.getPath()); |
|
48 |
return params; |
|
49 |
} |
|
50 |
|
|
51 |
public boolean canCreate() { |
|
52 |
return true; |
|
53 |
} |
|
54 |
|
|
55 |
public boolean canCreate(NewDataStoreParameters parameters) { |
|
56 |
if (!(parameters instanceof DWGStoreParameters)) { |
|
57 |
throw new IllegalArgumentException(); // FIXME ??? |
|
58 |
} |
|
59 |
DWGStoreParameters dwgParams = (DWGStoreParameters) parameters; |
|
60 |
// TODO comporbar si el ftype es correcto (para este formato es fijo) |
|
61 |
File file = new File(dwgParams.getFileName()); |
|
62 |
|
|
63 |
if (dwgParams.getCRS() == null) { |
|
64 |
return false; |
|
65 |
} |
|
66 |
// TODO comprobamos extension del fichero ?? |
|
67 |
if (file.exists()) { |
|
68 |
return file.canWrite(); |
|
69 |
} else { |
|
70 |
return file.getParentFile().canWrite(); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
public void create(NewDataStoreParameters parameters, boolean overwrite) |
|
75 |
throws CreateException { |
|
76 |
// FIXME Exception |
|
77 |
throw new UnsupportedOperationException(); |
|
78 |
} |
|
79 |
|
|
80 |
public NewDataStoreParameters getCreateParameters() throws DataException { |
|
81 |
return (NewFeatureStoreParameters) DALLocator.getDataManager() |
|
82 |
.createStoreParameters(this.getDataStoreProviderName()); |
|
83 |
} |
|
84 |
|
|
85 |
public void initialize( |
|
86 |
FilesystemServerExplorerProviderServices serverExplorer) { |
|
87 |
//this.serverExplorer = serverExplorer; |
|
88 |
} |
|
89 |
|
|
90 |
public void remove(DataStoreParameters parameters) throws RemoveException { |
|
91 |
File file = new File(((DWGStoreParameters) parameters).getFileName()); |
|
92 |
if (!file.exists()) { |
|
93 |
throw new RemoveException(this.getDataStoreProviderName(), |
|
94 |
new FileNotFoundException(file)); |
|
95 |
} |
|
96 |
if (!file.delete()) { |
|
97 |
// FIXME throws ??? |
|
98 |
} |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
103 |
// while it is using a resource anyone can't close it |
|
104 |
return false; |
|
105 |
} |
|
106 |
|
|
107 |
/* |
|
108 |
* (non-Javadoc) |
|
109 |
* |
|
110 |
* @see |
|
111 |
* org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org. |
|
112 |
* gvsig.fmap.dal.resource.spi.ResourceProvider) |
|
113 |
*/ |
|
114 |
public void resourceChanged(ResourceProvider resource) { |
|
115 |
//Do nothing |
|
116 |
|
|
117 |
} |
|
118 |
|
|
119 |
|
|
120 |
} |
|
0 | 121 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/DWGStoreProvider.java | ||
---|---|---|
1 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.Iterator; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Map; |
|
10 |
|
|
11 |
import org.cresques.cts.IProjection; |
|
12 |
import org.gvsig.dwg.lib.DwgFile; |
|
13 |
import org.gvsig.dwg.lib.DwgObject; |
|
14 |
import org.gvsig.dwg.lib.DwgVersionNotSupportedException; |
|
15 |
import org.gvsig.dwg.lib.IDwg2FMap; |
|
16 |
import org.gvsig.dwg.lib.IDwg3DTestable; |
|
17 |
import org.gvsig.dwg.lib.objects.DwgMText; |
|
18 |
import org.gvsig.dwg.lib.objects.DwgText; |
|
19 |
import org.gvsig.fmap.dal.DALLocator; |
|
20 |
import org.gvsig.fmap.dal.DataManager; |
|
21 |
import org.gvsig.fmap.dal.DataServerExplorer; |
|
22 |
import org.gvsig.fmap.dal.DataStoreNotification; |
|
23 |
import org.gvsig.fmap.dal.DataTypes; |
|
24 |
import org.gvsig.fmap.dal.FileHelper; |
|
25 |
import org.gvsig.fmap.dal.exception.DataException; |
|
26 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
27 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
28 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
29 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
30 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
31 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
32 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
33 |
import org.gvsig.fmap.dal.feature.exception.CreateGeometryException; |
|
34 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
|
35 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
36 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
|
37 |
import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider; |
|
38 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
|
39 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
|
40 |
import org.gvsig.fmap.dal.resource.file.FileResource; |
|
41 |
import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
|
42 |
import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
|
43 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
|
44 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
|
45 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
46 |
import org.gvsig.fmap.geom.Geometry; |
|
47 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
48 |
import org.gvsig.fmap.geom.GeometryManager; |
|
49 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
50 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
|
51 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
52 |
import org.gvsig.fmap.geom.primitive.Point; |
|
53 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
|
54 |
import org.gvsig.tools.exception.NotYetImplemented; |
|
55 |
import org.gvsig.tools.persistence.PersistentState; |
|
56 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
57 |
import org.slf4j.Logger; |
|
58 |
import org.slf4j.LoggerFactory; |
|
59 |
|
|
60 |
public class DWGStoreProvider extends AbstractMemoryStoreProvider implements |
|
61 |
ResourceConsumer { |
|
62 |
private static final Logger logger = LoggerFactory.getLogger(DWGStoreProvider.class); |
|
63 |
|
|
64 |
public static final String NAME = "DWG"; |
|
65 |
public static final String DESCRIPTION = "DWG file"; |
|
66 |
public static final String METADATA_DEFINITION_NAME = NAME; |
|
67 |
|
|
68 |
public static final String NAME_FIELD_ID = "ID"; |
|
69 |
public static final String NAME_FIELD_GEOMETRY = "Geometry"; |
|
70 |
public static final String NAME_FIELD_ENTITY = "Entity"; |
|
71 |
public static final String NAME_FIELD_LAYER = "Layer"; |
|
72 |
public static final String NAME_FIELD_COLOR = "Color"; |
|
73 |
public static final String NAME_FIELD_ELEVATION = "Elevation"; |
|
74 |
public static final String NAME_FIELD_THICKNESS = "Thickness"; |
|
75 |
public static final String NAME_FIELD_TEXT = "Text"; |
|
76 |
public static final String NAME_FIELD_HEIGHTTEXT = "HeightText"; |
|
77 |
public static final String NAME_FIELD_ROTATIONTEXT = "Rotation"; |
|
78 |
|
|
79 |
private int ID_FIELD_ID = 0; |
|
80 |
private int ID_FIELD_GEOMETRY = 1; |
|
81 |
private int ID_FIELD_ENTITY = 2; |
|
82 |
private int ID_FIELD_LAYER = 3; |
|
83 |
private int ID_FIELD_COLOR = 4; |
|
84 |
private int ID_FIELD_ELEVATION = 5; |
|
85 |
private int ID_FIELD_THICKNESS = 6; |
|
86 |
private int ID_FIELD_TEXT = 7; |
|
87 |
private int ID_FIELD_HEIGHTTEXT = 8; |
|
88 |
private int ID_FIELD_ROTATIONTEXT = 9; |
|
89 |
|
|
90 |
private IProjection projection; |
|
91 |
private ResourceProvider resource; |
|
92 |
private LegendBuilder legendBuilder; |
|
93 |
|
|
94 |
private long counterNewsOIDs = 0; |
|
95 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
96 |
|
|
97 |
public DWGStoreProvider(DWGStoreParameters parameters, |
|
98 |
DataStoreProviderServices storeServices) throws InitializeException { |
|
99 |
super(parameters, storeServices, FileHelper |
|
100 |
.newMetadataContainer(METADATA_DEFINITION_NAME)); |
|
101 |
|
|
102 |
counterNewsOIDs = 0; |
|
103 |
// projection = CRSFactory.getCRS(getParameters().getSRSID()); |
|
104 |
|
|
105 |
File file = getDWGParameters().getFile(); |
|
106 |
resource = this.createResource( |
|
107 |
FileResource.NAME, |
|
108 |
new Object[] { file.getAbsolutePath() } |
|
109 |
); |
|
110 |
|
|
111 |
resource.addConsumer(this); |
|
112 |
|
|
113 |
this.projection = this.getDWGParameters().getCRS(); |
|
114 |
|
|
115 |
|
|
116 |
try { |
|
117 |
legendBuilder = (LegendBuilder) this.invokeDynMethod( |
|
118 |
LegendBuilder.DYNMETHOD_BUILDER_NAME, null); |
|
119 |
} catch (DynMethodException e) { |
|
120 |
legendBuilder = null; |
|
121 |
} catch (Exception e) { |
|
122 |
throw new InitializeException(e); |
|
123 |
} |
|
124 |
|
|
125 |
this.initializeFeatureTypes(); |
|
126 |
} |
|
127 |
|
|
128 |
private DWGStoreParameters getDWGParameters() { |
|
129 |
return (DWGStoreParameters) this.getParameters(); |
|
130 |
} |
|
131 |
|
|
132 |
|
|
133 |
public String getProviderName() { |
|
134 |
return NAME; |
|
135 |
} |
|
136 |
|
|
137 |
public boolean allowWrite() { |
|
138 |
return false; |
|
139 |
} |
|
140 |
|
|
141 |
public Object getLegend() throws OpenException { |
|
142 |
this.open(); |
|
143 |
if (legendBuilder == null) { |
|
144 |
return null; |
|
145 |
} |
|
146 |
return legendBuilder.getLegend(); |
|
147 |
} |
|
148 |
|
|
149 |
public Object getLabeling() throws OpenException { |
|
150 |
this.open(); |
|
151 |
if (legendBuilder == null) { |
|
152 |
return null; |
|
153 |
} |
|
154 |
return legendBuilder.getLabeling(); |
|
155 |
} |
|
156 |
|
|
157 |
private class DWGData { |
|
158 |
public ArrayList data = null; |
|
159 |
public FeatureType defaultFType = null; |
|
160 |
public List fTypes = null; |
|
161 |
public Envelope envelope = null; |
|
162 |
public IProjection projection; |
|
163 |
public LegendBuilder legendBuilder = null; |
|
164 |
public Envelope getEnvelopeCopy() throws CreateEnvelopeException { |
|
165 |
if (envelope == null) { |
|
166 |
return null; |
|
167 |
} |
|
168 |
Envelope newEnvelope; |
|
169 |
if (envelope.getDimension() == 2) { |
|
170 |
newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
|
171 |
} else { |
|
172 |
newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D); |
|
173 |
|
|
174 |
} |
|
175 |
newEnvelope.setLowerCorner(envelope.getLowerCorner()); |
|
176 |
newEnvelope.setUpperCorner(envelope.getUpperCorner()); |
|
177 |
return newEnvelope; |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
private AbstractMemoryStoreProvider getStoreProvider() { |
|
182 |
return this; |
|
183 |
} |
|
184 |
|
|
185 |
public void open() throws OpenException { |
|
186 |
if (this.data != null) { |
|
187 |
return; |
|
188 |
} |
|
189 |
// try { |
|
190 |
// this.resource.begin(); |
|
191 |
// } catch (ResourceExecuteException e2) { |
|
192 |
// try { |
|
193 |
// throw new OpenException(resource.getName(), e2); |
|
194 |
// } catch (AccessResourceException e1) { |
|
195 |
// throw new OpenException(this.getName(), e2); |
|
196 |
// } |
|
197 |
// |
|
198 |
// } |
|
199 |
try { |
|
200 |
getResource().execute(new ResourceAction() { |
|
201 |
public Object run() throws Exception { |
|
202 |
ResourceProvider resource = getResource(); |
|
203 |
DWGData dwgData = null; |
|
204 |
FeatureStoreProviderServices store = getStoreServices(); |
|
205 |
if (resource.getData() != null) { |
|
206 |
dwgData = |
|
207 |
(DWGData) ((Map) resource.getData()).get(projection.getAbrev()); |
|
208 |
// OJO no es del todo correcto (puede llevar |
|
209 |
// reproyeccion) |
|
210 |
} else { |
|
211 |
resource.setData(new HashMap()); |
|
212 |
} |
|
213 |
if (dwgData == null) { |
|
214 |
dwgData = new DWGData(); |
|
215 |
dwgData.data = new ArrayList(); |
|
216 |
data = dwgData.data; |
|
217 |
counterNewsOIDs = 0; |
|
218 |
Reader reader = |
|
219 |
new Reader().initialice(getStoreProvider(), |
|
220 |
(File)resource.get(), |
|
221 |
projection, legendBuilder); |
|
222 |
reader.begin(store); |
|
223 |
dwgData.defaultFType = |
|
224 |
reader.getDefaultType().getNotEditableCopy(); |
|
225 |
ArrayList types = new ArrayList(); |
|
226 |
Iterator it = reader.getTypes().iterator(); |
|
227 |
EditableFeatureType fType; |
|
228 |
while (it.hasNext()) { |
|
229 |
fType = (EditableFeatureType) it.next(); |
|
230 |
if (fType.getId().equals( |
|
231 |
dwgData.defaultFType.getId())) { |
|
232 |
types.add(dwgData.defaultFType); |
|
233 |
} else { |
|
234 |
types.add(fType.getNotEditableCopy()); |
|
235 |
} |
|
236 |
} |
|
237 |
dwgData.fTypes = types; |
|
238 |
dwgData.legendBuilder = legendBuilder; |
|
239 |
|
|
240 |
resource.notifyOpen(); |
|
241 |
store.setFeatureTypes(dwgData.fTypes, |
|
242 |
dwgData.defaultFType); |
|
243 |
reader.load(); |
|
244 |
// this.envelope = reader.getEnvelope(); |
|
245 |
|
|
246 |
dwgData.envelope = reader.getEnvelope(); |
|
247 |
|
|
248 |
|
|
249 |
dwgData.projection = projection; |
|
250 |
|
|
251 |
reader.end(); |
|
252 |
resource.notifyClose(); |
|
253 |
((Map) resource.getData()).put(projection.getAbrev(), |
|
254 |
dwgData); // OJO la reproyeccion |
|
255 |
} |
|
256 |
|
|
257 |
data = dwgData.data; |
|
258 |
store.setFeatureTypes(dwgData.fTypes, dwgData.defaultFType); |
|
259 |
legendBuilder = dwgData.legendBuilder; |
|
260 |
setDynValue("Envelope", dwgData.getEnvelopeCopy()); |
|
261 |
setDynValue("CRS", projection); |
|
262 |
counterNewsOIDs = data.size(); |
|
263 |
return null; |
|
264 |
} |
|
265 |
}); |
|
266 |
} catch (Exception e) { |
|
267 |
this.data = null; |
|
268 |
try { |
|
269 |
throw new OpenException(resource.getName(), e); |
|
270 |
} catch (AccessResourceException e1) { |
|
271 |
throw new OpenException(this.getProviderName(), e); |
|
272 |
} |
|
273 |
// } finally { |
|
274 |
// this.resource.end(); |
|
275 |
} |
|
276 |
} |
|
277 |
|
|
278 |
|
|
279 |
public DataServerExplorer getExplorer() throws ReadException { |
|
280 |
DataManager manager = DALLocator.getDataManager(); |
|
281 |
FilesystemServerExplorerParameters params; |
|
282 |
try { |
|
283 |
params = (FilesystemServerExplorerParameters) manager |
|
284 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
285 |
params.setRoot(this.getDWGParameters().getFile().getParent()); |
|
286 |
return manager.createServerExplorer(params); |
|
287 |
} catch (DataException e) { |
|
288 |
throw new ReadException(this.getProviderName(), e); |
|
289 |
} catch (ValidateDataParametersException e) { |
|
290 |
throw new ReadException(this.getProviderName(), e); |
|
291 |
} |
|
292 |
|
|
293 |
} |
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException { |
|
298 |
// FIXME Exception |
|
299 |
throw new UnsupportedOperationException(); |
|
300 |
} |
|
301 |
|
|
302 |
public class Reader { |
|
303 |
private File file; |
|
304 |
private String fileName; |
|
305 |
private IProjection projection; |
|
306 |
private List types; |
|
307 |
private LegendBuilder leyendBuilder; |
|
308 |
private AbstractMemoryStoreProvider store; |
|
309 |
private Envelope envelope; |
|
310 |
private DwgFile dwgFeatureFile; |
|
311 |
|
|
312 |
public Reader initialice(AbstractMemoryStoreProvider store, File file, |
|
313 |
IProjection projection, |
|
314 |
LegendBuilder leyendBuilder) { |
|
315 |
this.store = store; |
|
316 |
this.file = file; |
|
317 |
this.fileName = file.getAbsolutePath(); |
|
318 |
this.projection = projection; |
|
319 |
this.leyendBuilder = leyendBuilder; |
|
320 |
if (leyendBuilder != null) { |
|
321 |
leyendBuilder.initialize(store); |
|
322 |
} |
|
323 |
return this; |
|
324 |
} |
|
325 |
|
|
326 |
public Envelope getEnvelope() { |
|
327 |
return this.envelope; |
|
328 |
} |
|
329 |
|
|
330 |
public void begin(FeatureStoreProviderServices store) throws UnsupportedDWGVersionException, ReadException { |
|
331 |
dwgFeatureFile = new DwgFile(file.getAbsolutePath()); |
|
332 |
|
|
333 |
try { |
|
334 |
dwgFeatureFile.read(); |
|
335 |
} catch (DwgVersionNotSupportedException e1) { |
|
336 |
throw new UnsupportedDWGVersionException(file.getName(), e1); |
|
337 |
} catch (IOException e) { |
|
338 |
throw new ReadException(NAME, e); |
|
339 |
} |
|
340 |
|
|
341 |
EditableFeatureType featureType = store.createFeatureType(); |
|
342 |
|
|
343 |
featureType.setHasOID(true); |
|
344 |
|
|
345 |
ID_FIELD_ID = featureType.add(NAME_FIELD_ID, DataTypes.INT) |
|
346 |
.setDefaultValue(Integer.valueOf(0)) |
|
347 |
.getIndex(); |
|
348 |
|
|
349 |
EditableFeatureAttributeDescriptor attr = featureType.add( |
|
350 |
NAME_FIELD_GEOMETRY, DataTypes.GEOMETRY); |
|
351 |
attr.setSRS(this.projection); |
|
352 |
attr.setGeometryType(Geometry.TYPES.GEOMETRY); |
|
353 |
boolean is3dFile = dwgFeatureFile.isDwg3DFile(); |
|
354 |
if (is3dFile){ |
|
355 |
attr.setGeometrySubType(Geometry.SUBTYPES.GEOM3D); |
|
356 |
}else{ |
|
357 |
attr.setGeometrySubType(Geometry.SUBTYPES.GEOM2D); |
|
358 |
} |
|
359 |
ID_FIELD_GEOMETRY = attr.getIndex(); |
|
360 |
|
|
361 |
featureType.setDefaultGeometryAttributeName(NAME_FIELD_GEOMETRY); |
|
362 |
|
|
363 |
// FIXME: Cual es el size y el valor por defecto para Entity ? |
|
364 |
ID_FIELD_ENTITY = featureType.add(NAME_FIELD_ENTITY, |
|
365 |
DataTypes.STRING, 100) |
|
366 |
.setDefaultValue("") |
|
367 |
.getIndex(); |
|
368 |
|
|
369 |
// FIXME: Cual es el size de Layer ? |
|
370 |
ID_FIELD_LAYER = featureType.add(NAME_FIELD_LAYER, |
|
371 |
DataTypes.STRING, 100) |
|
372 |
.setDefaultValue( |
|
373 |
"default").getIndex(); |
|
374 |
|
|
375 |
ID_FIELD_COLOR = featureType.add(NAME_FIELD_COLOR, |
|
376 |
DataTypes.INT) |
|
377 |
.setDefaultValue( |
|
378 |
Integer.valueOf(0)).getIndex(); |
|
379 |
|
|
380 |
ID_FIELD_ELEVATION = featureType.add(NAME_FIELD_ELEVATION, |
|
381 |
DataTypes.DOUBLE) |
|
382 |
.setDefaultValue( |
|
383 |
Double.valueOf(0)).getIndex(); |
|
384 |
|
|
385 |
ID_FIELD_THICKNESS = featureType.add(NAME_FIELD_THICKNESS, |
|
386 |
DataTypes.DOUBLE) |
|
387 |
.setDefaultValue( |
|
388 |
Double.valueOf(0)).getIndex(); |
|
389 |
|
|
390 |
// FIXME: Cual es el size de Text ? |
|
391 |
ID_FIELD_TEXT = featureType.add(NAME_FIELD_TEXT, |
|
392 |
DataTypes.STRING, 100) |
|
393 |
.setDefaultValue("") |
|
394 |
.getIndex(); |
|
395 |
|
|
396 |
ID_FIELD_HEIGHTTEXT = featureType.add(NAME_FIELD_HEIGHTTEXT, |
|
397 |
DataTypes.DOUBLE).setDefaultValue( |
|
398 |
Double.valueOf(10)).getIndex(); |
|
399 |
|
|
400 |
ID_FIELD_ROTATIONTEXT = featureType.add(NAME_FIELD_ROTATIONTEXT, |
|
401 |
DataTypes.DOUBLE).setDefaultValue( |
|
402 |
Double.valueOf(0)).getIndex(); |
|
403 |
|
|
404 |
|
|
405 |
|
|
406 |
// FIXME: Parece que el DXF puede tener mas atributos opcionales. |
|
407 |
// Habria que ver de pillarlos ? |
|
408 |
|
|
409 |
types = new ArrayList(); |
|
410 |
types.add(featureType); |
|
411 |
|
|
412 |
if (leyendBuilder != null) { |
|
413 |
leyendBuilder.begin(); |
|
414 |
} |
|
415 |
|
|
416 |
} |
|
417 |
|
|
418 |
public void end() { |
|
419 |
if (leyendBuilder != null) { |
|
420 |
leyendBuilder.end(); |
|
421 |
} |
|
422 |
} |
|
423 |
|
|
424 |
public List getTypes() { |
|
425 |
return types; |
|
426 |
} |
|
427 |
|
|
428 |
public EditableFeatureType getDefaultType() { |
|
429 |
return (EditableFeatureType) types.get(0); |
|
430 |
} |
|
431 |
|
|
432 |
private Double toDouble(String value) { |
|
433 |
if (value == null) { |
|
434 |
return Double.valueOf(0); |
|
435 |
} |
|
436 |
return Double.valueOf(value); |
|
437 |
} |
|
438 |
|
|
439 |
public void load() throws DataException { |
|
440 |
|
|
441 |
this.envelope = null; |
|
442 |
|
|
443 |
long count_not_fmap_interface = 0; |
|
444 |
long count_null_geometry = 0; |
|
445 |
long count_bad_envelope = 0; |
|
446 |
long count_envelope_out_of_aoi = 0; |
|
447 |
|
|
448 |
dwgFeatureFile.calculateGisModelDwgPolylines(); |
|
449 |
dwgFeatureFile.blockManagement2(); |
|
450 |
List entities = dwgFeatureFile.getDwgObjects(); |
|
451 |
|
|
452 |
int id = -1; |
|
453 |
try{ |
|
454 |
int envelopeSubType = Geometry.SUBTYPES.GEOM2D; |
|
455 |
boolean is3dFile = dwgFeatureFile.isDwg3DFile(); |
|
456 |
|
|
457 |
this.envelope = geomManager.createEnvelope(envelopeSubType); |
|
458 |
|
|
459 |
boolean updateEnvelope = true; |
|
460 |
|
|
461 |
double[] extMin = (double[]) dwgFeatureFile |
|
462 |
.getHeader("MSPACE_EXTMIN"); |
|
463 |
double[] extMax = (double[]) dwgFeatureFile |
|
464 |
.getHeader("MSPACE_EXTMAX"); |
|
465 |
if (extMin != null && extMax != null) { |
|
466 |
updateEnvelope = false; |
|
467 |
Point point = (Point) geomManager.create( |
|
468 |
Geometry.TYPES.POINT, envelopeSubType); |
|
469 |
point.setCoordinates(extMin); |
|
470 |
this.envelope.setLowerCorner(point); |
|
471 |
point = (Point) geomManager.create(Geometry.TYPES.POINT, |
|
472 |
envelopeSubType); |
|
473 |
point.setCoordinates(extMax); |
|
474 |
this.envelope.setUpperCorner(point); |
|
475 |
} |
|
476 |
|
|
477 |
|
|
478 |
Iterator iter = entities.iterator(); |
|
479 |
|
|
480 |
FeatureProvider featureProvider; |
|
481 |
Envelope gEnvelope; |
|
482 |
|
|
483 |
while (iter.hasNext()) { |
|
484 |
id++; |
|
485 |
DwgObject entity = (DwgObject) iter.next(); |
|
486 |
|
|
487 |
if (!(entity instanceof IDwg2FMap)) { |
|
488 |
count_not_fmap_interface++; |
|
489 |
/* |
|
490 |
logger.warn("load: entity type {}(id:{}) not loadded", |
|
491 |
new Object[] { entity.getType() }, id); |
|
492 |
*/ |
|
493 |
continue; |
|
494 |
} |
|
495 |
|
|
496 |
IDwg2FMap dwgEnt = (IDwg2FMap) entity; |
|
497 |
Geometry geometry = dwgEnt.toFMapGeometry(is3dFile); |
|
498 |
if (geometry == null) { |
|
499 |
count_null_geometry++; |
|
500 |
/* |
|
501 |
logger.warn("load: entity {}(id:{}) with null geometry", |
|
502 |
new Object[] { entity.getType(), id }); |
|
503 |
*/ |
|
504 |
continue; |
|
505 |
} |
|
506 |
// FIXME: Estas 6 lineas es por si la geometr??a no se ha |
|
507 |
// creado correctamente |
|
508 |
gEnvelope = null; |
|
509 |
try { |
|
510 |
gEnvelope = geometry.getEnvelope(); |
|
511 |
} catch (Exception e) { |
|
512 |
gEnvelope = null; |
|
513 |
} |
|
514 |
if (gEnvelope == null) { |
|
515 |
count_bad_envelope++; |
|
516 |
/* |
|
517 |
logger.warn("load: entity {}(id:{}) with null envelope", |
|
518 |
new Object[] { entity.getType(), id }); |
|
519 |
*/ |
|
520 |
continue; |
|
521 |
} |
|
522 |
// we check for Region of Interest of the CAD file |
|
523 |
if (!this.envelope.intersects(geometry.getEnvelope())) { |
|
524 |
count_envelope_out_of_aoi++; |
|
525 |
/* |
|
526 |
logger.warn("load: entity {}(id:{}) out of envelope", |
|
527 |
new Object[] { entity.getType(), id }); |
|
528 |
*/ |
|
529 |
continue; |
|
530 |
} |
|
531 |
featureProvider = store.createFeatureProvider(store |
|
532 |
.getStoreServices().getDefaultFeatureType()); |
|
533 |
|
|
534 |
featureProvider.set(ID_FIELD_ID, id); |
|
535 |
|
|
536 |
featureProvider.set(ID_FIELD_ENTITY, dwgEnt.toString()); |
|
537 |
|
|
538 |
featureProvider.set(ID_FIELD_LAYER, dwgFeatureFile |
|
539 |
.getLayerName(entity)); |
|
540 |
|
|
541 |
int colorByLayer = dwgFeatureFile.getColorByLayer(entity); |
|
542 |
int color = entity.getColor(); |
|
543 |
if (color < 0) { |
|
544 |
color = Math.abs(color); |
|
545 |
} |
|
546 |
if (color > 255) { |
|
547 |
color = colorByLayer; |
|
548 |
} |
|
549 |
|
|
550 |
featureProvider.set(ID_FIELD_COLOR, color); |
|
551 |
|
|
552 |
if (entity instanceof IDwg3DTestable) { |
|
553 |
featureProvider.set(ID_FIELD_ELEVATION, |
|
554 |
((IDwg3DTestable) entity).getZ()); |
|
555 |
} |
|
556 |
|
|
557 |
featureProvider.set(ID_FIELD_THICKNESS, 0.0); |
|
558 |
featureProvider.set(ID_FIELD_HEIGHTTEXT, 0.0); |
|
559 |
featureProvider.set(ID_FIELD_ROTATIONTEXT, 0.0); |
|
560 |
featureProvider.set(ID_FIELD_TEXT, ""); |
|
561 |
|
|
562 |
if (entity instanceof DwgMText) { |
|
563 |
DwgMText mtext = (DwgMText) entity; |
|
564 |
featureProvider.set(ID_FIELD_HEIGHTTEXT, mtext.getHeight()); |
|
565 |
featureProvider.set(ID_FIELD_TEXT, mtext.getText()); |
|
566 |
} else if (entity instanceof DwgText) { |
|
567 |
DwgText text = (DwgText) entity; |
|
568 |
featureProvider |
|
569 |
.set(ID_FIELD_THICKNESS, text.getThickness()); |
|
570 |
featureProvider.set(ID_FIELD_HEIGHTTEXT, text.getHeight()); |
|
571 |
featureProvider.set(ID_FIELD_ROTATIONTEXT, text |
|
572 |
.getRotationAngle()); |
|
573 |
featureProvider.set(ID_FIELD_TEXT, text.getText()); |
|
574 |
}// if-else |
|
575 |
|
|
576 |
featureProvider.setDefaultGeometry(geometry); |
|
577 |
|
|
578 |
store.addFeatureProvider(featureProvider); |
|
579 |
if (this.leyendBuilder != null) { |
|
580 |
this.leyendBuilder.process(featureProvider); |
|
581 |
} |
|
582 |
|
|
583 |
} |
|
584 |
|
|
585 |
logger.info("Issues while loading DWG entities:+\n" |
|
586 |
+ " Entities not implementing IDwg2FMap interface: " + count_not_fmap_interface + "\n" |
|
587 |
+ " Entities with non-convertible geometry: " + count_null_geometry + "\n" |
|
588 |
+ " Entities without valid envelope: " + count_bad_envelope + "\n" |
|
589 |
+ " Entities with envelope out of global envelope: " + count_envelope_out_of_aoi); |
|
590 |
|
|
591 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
592 |
throw new CreateGeometryException(e); |
|
593 |
} catch (org.gvsig.fmap.geom.exception.CreateEnvelopeException e) { |
|
594 |
throw new CreateGeometryException(e); |
|
595 |
} |
|
596 |
} |
|
597 |
|
|
598 |
} |
|
599 |
|
|
600 |
|
|
601 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
602 |
return true; |
|
603 |
} |
|
604 |
|
|
605 |
public int getOIDType() { |
|
606 |
return DataTypes.LONG; |
|
607 |
} |
|
608 |
|
|
609 |
public boolean supportsAppendMode() { |
|
610 |
return false; |
|
611 |
} |
|
612 |
|
|
613 |
public void append(FeatureProvider featureProvider) { |
|
614 |
// FIXME Exception |
|
615 |
throw new UnsupportedOperationException(); |
|
616 |
} |
|
617 |
|
|
618 |
public void beginAppend() { |
|
619 |
// FIXME Exception |
|
620 |
throw new UnsupportedOperationException(); |
|
621 |
|
|
622 |
} |
|
623 |
|
|
624 |
public void endAppend() { |
|
625 |
// FIXME Exception |
|
626 |
throw new UnsupportedOperationException(); |
|
627 |
} |
|
628 |
|
|
629 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
630 |
// TODO Auto-generated method stub |
|
631 |
throw new NotYetImplemented(); |
|
632 |
} |
|
633 |
|
|
634 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
635 |
// TODO Auto-generated method stub |
|
636 |
throw new NotYetImplemented(); |
|
637 |
} |
|
638 |
|
|
639 |
public Object createNewOID() { |
|
640 |
return new Long(counterNewsOIDs++); |
|
641 |
} |
|
642 |
|
|
643 |
protected void initializeFeatureTypes() throws InitializeException { |
|
644 |
try { |
|
645 |
this.open(); |
|
646 |
} catch (OpenException e) { |
|
647 |
throw new InitializeException(this.getProviderName(), e); |
|
648 |
} |
|
649 |
} |
|
650 |
|
|
651 |
public Envelope getEnvelope() throws DataException { |
|
652 |
this.open(); |
|
653 |
return (Envelope) this.getDynValue("Envelope"); |
|
654 |
} |
|
655 |
|
|
656 |
|
|
657 |
/* |
|
658 |
* (non-Javadoc) |
|
659 |
* |
|
660 |
* @see |
|
661 |
* org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org. |
|
662 |
* gvsig.fmap.dal.resource.spi.ResourceProvider) |
|
663 |
*/ |
|
664 |
public void resourceChanged(ResourceProvider resource) { |
|
665 |
this.getStoreServices().notifyChange( |
|
666 |
DataStoreNotification.RESOURCE_CHANGED, |
|
667 |
resource); |
|
668 |
} |
|
669 |
|
|
670 |
public Object getSourceId() { |
|
671 |
return this.getDWGParameters().getFile(); |
|
672 |
} |
|
673 |
|
|
674 |
|
|
675 |
public String getName() { |
|
676 |
String name = this.getDWGParameters().getFile().getName(); |
|
677 |
int n = name.lastIndexOf("."); |
|
678 |
if( n<1 ) { |
|
679 |
return name; |
|
680 |
} |
|
681 |
return name.substring(0, n); |
|
682 |
} |
|
683 |
|
|
684 |
public String getFullName() { |
|
685 |
return this.getDWGParameters().getFile().getAbsolutePath(); |
|
686 |
} |
|
687 |
|
|
688 |
|
|
689 |
|
|
690 |
public ResourceProvider getResource() { |
|
691 |
return resource; |
|
692 |
} |
|
693 |
|
|
694 |
} |
|
0 | 695 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/legend/DWGLegendLibrary.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.dwg.fmap.dal.store.dwg.legend; |
|
32 |
|
|
33 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGLibrary; |
|
34 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGStoreProvider; |
|
35 |
import org.gvsig.fmap.dal.DALLibrary; |
|
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 DWGLegendLibrary extends AbstractLibrary { |
|
47 |
|
|
48 |
@Override |
|
49 |
public void doRegistration() { |
|
50 |
registerAsImplementationOf(DWGLegendLibrary.class); |
|
51 |
require(MetadataLibrary.class); |
|
52 |
require(DWGLibrary.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 dynClass = (DynClass) MetadataLocator.getMetadataManager() |
|
63 |
.getDefinition(DWGStoreProvider.METADATA_DEFINITION_NAME); |
|
64 |
|
|
65 |
DWGGetLegendBuilder.register(dynClass); |
|
66 |
DWGGetLegend.register(dynClass); |
|
67 |
DWGGetLabeling.register(dynClass); |
|
68 |
} |
|
69 |
} |
|
0 | 70 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/legend/DWGGetLegendBuilder.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.dwg.fmap.dal.store.dwg.legend; |
|
29 |
|
|
30 |
import org.gvsig.dwg.fmap.dal.store.dwg.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 DWGGetLegendBuilder implements DynMethod { |
|
39 |
private static Integer code = null; |
|
40 |
|
|
41 |
static void register(DynClass dwgLegendDynClass) { |
|
42 |
if (code != null) { |
|
43 |
return; |
|
44 |
} |
|
45 |
code = new Integer(ToolsLocator.getDynObjectManager() |
|
46 |
.registerDynMethod( |
|
47 |
dwgLegendDynClass, new DWGGetLegendBuilder())); |
|
48 |
|
|
49 |
} |
|
50 |
public int getCode() throws DynMethodNotSupportedException { |
|
51 |
return code.intValue(); |
|
52 |
} |
|
53 |
|
|
54 |
public String getDescription() { |
|
55 |
return "DWG 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 DWGLegendBuilder(); |
|
65 |
} |
|
66 |
|
|
67 |
} |
|
0 | 68 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/legend/DWGLegendBuilder.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.dwg.fmap.dal.store.dwg.legend; |
|
29 |
|
|
30 |
import java.awt.Color; |
|
31 |
|
|
32 |
import org.gvsig.dwg.fmap.dal.store.dwg.DWGStoreProvider; |
|
33 |
import org.gvsig.dwg.fmap.dal.store.dwg.LegendBuilder; |
|
34 |
import org.gvsig.dxf.px.dxf.AcadColor; |
|
35 |
import org.gvsig.fmap.dal.DataTypes; |
|
36 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
37 |
import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
|
38 |
import org.gvsig.fmap.geom.Geometry; |
|
39 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
|
40 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialUniqueValueLegend; |
|
41 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
|
42 |
import org.gvsig.symbology.SymbologyLocator; |
|
43 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
|
44 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
|
45 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
|
46 |
|
|
47 |
public class DWGLegendBuilder implements LegendBuilder { |
|
48 |
|
|
49 |
|
|
50 |
private IVectorialUniqueValueLegend defaultLegend = null; |
|
51 |
private IAttrInTableLabelingStrategy labelingStragegy = null; |
|
52 |
|
|
53 |
public void begin() { |
|
54 |
// Nothing to do |
|
55 |
} |
|
56 |
|
|
57 |
public void end() { |
|
58 |
// Nothing to do |
|
59 |
} |
|
60 |
|
|
61 |
public Object getLegend() { |
|
62 |
return defaultLegend; |
|
63 |
} |
|
64 |
|
|
65 |
public LegendBuilder initialize(FeatureStoreProvider store) { |
|
66 |
defaultLegend = (IVectorialUniqueValueLegend) MapContextLocator |
|
67 |
.getMapContextManager().createLegend( |
|
68 |
IVectorialUniqueValueLegend.LEGEND_NAME); |
|
69 |
defaultLegend.setShapeType(Geometry.TYPES.GEOMETRY); |
|
70 |
defaultLegend |
|
71 |
.setClassifyingFieldNames(new String[] { DWGStoreProvider.NAME_FIELD_COLOR }); |
|
72 |
defaultLegend.setClassifyingFieldTypes(new int[] { DataTypes.INT }); |
|
73 |
|
|
74 |
ISymbol myDefaultSymbol = |
|
75 |
MapContextLocator.getSymbolManager() |
|
76 |
.createSymbol(Geometry.TYPES.GEOMETRY, Color.BLACK); |
|
77 |
|
|
78 |
defaultLegend.setDefaultSymbol(myDefaultSymbol); |
|
79 |
|
|
80 |
|
|
81 |
labelingStragegy = |
|
82 |
SymbologyLocator.getSymbologyManager() |
|
83 |
.createAttrInTableLabelingStrategy(); |
|
84 |
labelingStragegy.setTextField(DWGStoreProvider.NAME_FIELD_TEXT); |
|
85 |
labelingStragegy |
|
86 |
.setRotationField(DWGStoreProvider.NAME_FIELD_ROTATIONTEXT); |
|
87 |
labelingStragegy.setHeightField(DWGStoreProvider.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 |
if (defaultLegend.getSymbolByValue(clave) == null) { |
|
98 |
ISymbol theSymbol; |
|
99 |
Color color = null; |
|
100 |
try { |
|
101 |
color = AcadColor.getColor(clave.intValue()); |
|
102 |
} catch (ArrayIndexOutOfBoundsException e) { |
|
103 |
color = AcadColor.getColor(255); |
|
104 |
} |
|
105 |
// jaume, moved to ISymbol |
|
106 |
theSymbol = |
|
107 |
MapContextLocator.getSymbolManager().createSymbol( |
|
108 |
Geometry.TYPES.GEOMETRY, color); |
|
109 |
|
|
110 |
theSymbol.setDescription(clave.toString()); |
|
111 |
// Asigna los colores de Autocad a los |
|
112 |
// bordes de los pol?gonos y pone el relleno transparente. |
|
113 |
if (theSymbol instanceof IFillSymbol) { |
|
114 |
((IFillSymbol) theSymbol).getOutline().setLineColor(color); |
|
115 |
Color fillColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), 0); |
|
116 |
((IFillSymbol) theSymbol).setFillColor(fillColor); |
|
117 |
} |
|
118 |
// Asigna los colores de Autocad a las l?neas |
|
119 |
if (theSymbol instanceof ILineSymbol) { |
|
120 |
((ILineSymbol) theSymbol).setLineColor(color); |
|
121 |
} |
|
122 |
if (theSymbol != null) { |
|
123 |
defaultLegend.addSymbol(clave, theSymbol); |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
} |
|
128 |
|
|
129 |
public Object getLabeling() { |
|
130 |
return labelingStragegy; |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
} |
|
0 | 135 |
tags/v2_0_0_Build_2061/extensions/extDwg/src/org/gvsig/dwg/fmap/dal/store/dwg/legend/DWGGetLabeling.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): |
Also available in: Unified diff