Revision 1314
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.dwg.fmap.dal.store.dwg.DWGLibrary |
|
2 |
org.gvsig.dwg.fmap.dal.store.dwg.legend.DWGLegendLibrary |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/resources/org/gvsig/dwg/fmap/dal/store/dwg/DWGMetadata.xml | ||
---|---|---|
1 |
<?xml version="1.0"?> |
|
2 |
<!-- |
|
3 |
Definitions of metadata fields of a DWG file. |
|
4 |
--> |
|
5 |
<definitions> |
|
6 |
<version>1.0.0</version> |
|
7 |
<classes> |
|
8 |
|
|
9 |
<class name="DWG" namespace="Metadata"> |
|
10 |
<extends> |
|
11 |
<class namespace="Metadata" name="SpatialProvider"/> |
|
12 |
</extends> |
|
13 |
<description>Metadata of a DWG store</description> |
|
14 |
<fields> |
|
15 |
</fields> |
|
16 |
</class> |
|
17 |
|
|
18 |
</classes> |
|
19 |
</definitions> |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/resources/org/gvsig/dwg/fmap/dal/store/dwg/DWGParameters.xml | ||
---|---|---|
1 |
<?xml version= "1.0 "?> |
|
2 |
<definitions> |
|
3 |
<version>1.0.0</version> |
|
4 |
<classes> |
|
5 |
<class name="DWGStoreParameters"> |
|
6 |
<extends> |
|
7 |
<class namespace="dal" name="ProviderParameters"/> |
|
8 |
</extends> |
|
9 |
<description>Store the parameters need to open a dwg file</description> |
|
10 |
<fields> |
|
11 |
<field name="file" type="file" mandatory="true" group="Basic"> |
|
12 |
<description>dwg file</description> |
|
13 |
</field> |
|
14 |
<field name="CRS" type="crs" mandatory="true" group="Basic"> |
|
15 |
<description>The coordinate reference system used in this dwg file</description> |
|
16 |
</field> |
|
17 |
</fields> |
|
18 |
</class> |
|
19 |
</classes> |
|
20 |
</definitions> |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/java/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 |
DWGOpenStoreParameters params = (DWGOpenStoreParameters) 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 DWGOpenStoreParameters)) { |
|
57 |
throw new IllegalArgumentException(); // FIXME ??? |
|
58 |
} |
|
59 |
DWGOpenStoreParameters dwgParams = (DWGOpenStoreParameters) 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(((DWGOpenStoreParameters) 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 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/java/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 |
|
|
63 |
private static final Logger logger = LoggerFactory.getLogger(DWGStoreProvider.class); |
|
64 |
|
|
65 |
public static final String NAME = "DWG"; |
|
66 |
public static final String DESCRIPTION = "DWG file"; |
|
67 |
public static final String METADATA_DEFINITION_NAME = NAME; |
|
68 |
|
|
69 |
public static final String NAME_FIELD_ID = "ID"; |
|
70 |
public static final String NAME_FIELD_GEOMETRY = "Geometry"; |
|
71 |
public static final String NAME_FIELD_ENTITY = "Entity"; |
|
72 |
public static final String NAME_FIELD_LAYER = "Layer"; |
|
73 |
public static final String NAME_FIELD_COLOR = "Color"; |
|
74 |
public static final String NAME_FIELD_ELEVATION = "Elevation"; |
|
75 |
public static final String NAME_FIELD_THICKNESS = "Thickness"; |
|
76 |
public static final String NAME_FIELD_TEXT = "Text"; |
|
77 |
public static final String NAME_FIELD_HEIGHTTEXT = "HeightText"; |
|
78 |
public static final String NAME_FIELD_ROTATIONTEXT = "Rotation"; |
|
79 |
|
|
80 |
private int ID_FIELD_ID = 0; |
|
81 |
private int ID_FIELD_GEOMETRY = 1; |
|
82 |
private int ID_FIELD_ENTITY = 2; |
|
83 |
private int ID_FIELD_LAYER = 3; |
|
84 |
private int ID_FIELD_COLOR = 4; |
|
85 |
private int ID_FIELD_ELEVATION = 5; |
|
86 |
private int ID_FIELD_THICKNESS = 6; |
|
87 |
private int ID_FIELD_TEXT = 7; |
|
88 |
private int ID_FIELD_HEIGHTTEXT = 8; |
|
89 |
private int ID_FIELD_ROTATIONTEXT = 9; |
|
90 |
|
|
91 |
private IProjection projection; |
|
92 |
private ResourceProvider resource; |
|
93 |
private LegendBuilder legendBuilder; |
|
94 |
|
|
95 |
private long counterNewsOIDs = 0; |
|
96 |
protected GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
97 |
|
|
98 |
public DWGStoreProvider(DWGOpenStoreParameters parameters, |
|
99 |
DataStoreProviderServices storeServices) throws InitializeException { |
|
100 |
super(parameters, storeServices, FileHelper |
|
101 |
.newMetadataContainer(METADATA_DEFINITION_NAME)); |
|
102 |
|
|
103 |
counterNewsOIDs = 0; |
|
104 |
// projection = CRSFactory.getCRS(getParameters().getSRSID()); |
|
105 |
|
|
106 |
File file = getDWGParameters().getFile(); |
|
107 |
resource = this.createResource( |
|
108 |
FileResource.NAME, |
|
109 |
new Object[]{file.getAbsolutePath()} |
|
110 |
); |
|
111 |
|
|
112 |
resource.addConsumer(this); |
|
113 |
|
|
114 |
this.projection = this.getDWGParameters().getCRS(); |
|
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 DWGOpenStoreParameters getDWGParameters() { |
|
129 |
return (DWGOpenStoreParameters) this.getParameters(); |
|
130 |
} |
|
131 |
|
|
132 |
public String getProviderName() { |
|
133 |
return NAME; |
|
134 |
} |
|
135 |
|
|
136 |
public boolean allowWrite() { |
|
137 |
return false; |
|
138 |
} |
|
139 |
|
|
140 |
public Object getLegend() throws OpenException { |
|
141 |
this.open(); |
|
142 |
if (legendBuilder == null) { |
|
143 |
return null; |
|
144 |
} |
|
145 |
return legendBuilder.getLegend(); |
|
146 |
} |
|
147 |
|
|
148 |
public Object getLabeling() throws OpenException { |
|
149 |
this.open(); |
|
150 |
if (legendBuilder == null) { |
|
151 |
return null; |
|
152 |
} |
|
153 |
return legendBuilder.getLabeling(); |
|
154 |
} |
|
155 |
|
|
156 |
private class DWGData { |
|
157 |
|
|
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 |
|
|
165 |
public Envelope getEnvelopeCopy() throws CreateEnvelopeException { |
|
166 |
if (envelope == null) { |
|
167 |
return null; |
|
168 |
} |
|
169 |
Envelope newEnvelope; |
|
170 |
if (envelope.getDimension() == 2) { |
|
171 |
newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
|
172 |
} else { |
|
173 |
newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D); |
|
174 |
|
|
175 |
} |
|
176 |
newEnvelope.setLowerCorner(envelope.getLowerCorner()); |
|
177 |
newEnvelope.setUpperCorner(envelope.getUpperCorner()); |
|
178 |
return newEnvelope; |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
private AbstractMemoryStoreProvider getStoreProvider() { |
|
183 |
return this; |
|
184 |
} |
|
185 |
|
|
186 |
public void open() throws OpenException { |
|
187 |
if (this.data != null) { |
|
188 |
return; |
|
189 |
} |
|
190 |
// try { |
|
191 |
// this.resource.begin(); |
|
192 |
// } catch (ResourceExecuteException e2) { |
|
193 |
// try { |
|
194 |
// throw new OpenException(resource.getName(), e2); |
|
195 |
// } catch (AccessResourceException e1) { |
|
196 |
// throw new OpenException(this.getName(), e2); |
|
197 |
// } |
|
198 |
// |
|
199 |
// } |
|
200 |
try { |
|
201 |
getResource().execute(new ResourceAction() { |
|
202 |
public Object run() throws Exception { |
|
203 |
ResourceProvider resource = getResource(); |
|
204 |
DWGData dwgData = null; |
|
205 |
FeatureStoreProviderServices store = getStoreServices(); |
|
206 |
if (resource.getData() != null) { |
|
207 |
dwgData |
|
208 |
= (DWGData) ((Map) resource.getData()).get(projection.getAbrev()); |
|
209 |
// OJO no es del todo correcto (puede llevar |
|
210 |
// reproyeccion) |
|
211 |
} else { |
|
212 |
resource.setData(new HashMap()); |
|
213 |
} |
|
214 |
if (dwgData == null) { |
|
215 |
dwgData = new DWGData(); |
|
216 |
dwgData.data = new ArrayList(); |
|
217 |
data = dwgData.data; |
|
218 |
counterNewsOIDs = 0; |
|
219 |
Reader reader |
|
220 |
= new Reader().initialice(getStoreProvider(), |
|
221 |
(File) resource.get(), |
|
222 |
projection, legendBuilder); |
|
223 |
reader.begin(store); |
|
224 |
dwgData.defaultFType |
|
225 |
= reader.getDefaultType().getNotEditableCopy(); |
|
226 |
ArrayList types = new ArrayList(); |
|
227 |
Iterator it = reader.getTypes().iterator(); |
|
228 |
EditableFeatureType fType; |
|
229 |
while (it.hasNext()) { |
|
230 |
fType = (EditableFeatureType) it.next(); |
|
231 |
if (fType.getId().equals( |
|
232 |
dwgData.defaultFType.getId())) { |
|
233 |
types.add(dwgData.defaultFType); |
|
234 |
} else { |
|
235 |
types.add(fType.getNotEditableCopy()); |
|
236 |
} |
|
237 |
} |
|
238 |
dwgData.fTypes = types; |
|
239 |
dwgData.legendBuilder = legendBuilder; |
|
240 |
|
|
241 |
resource.notifyOpen(); |
|
242 |
store.setFeatureTypes(dwgData.fTypes, |
|
243 |
dwgData.defaultFType); |
|
244 |
reader.load(); |
|
245 |
// this.envelope = reader.getEnvelope(); |
|
246 |
|
|
247 |
dwgData.envelope = reader.getEnvelope(); |
|
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 |
public DataServerExplorer getExplorer() throws ReadException { |
|
279 |
DataManager manager = DALLocator.getDataManager(); |
|
280 |
FilesystemServerExplorerParameters params; |
|
281 |
try { |
|
282 |
params = (FilesystemServerExplorerParameters) manager |
|
283 |
.createServerExplorerParameters(FilesystemServerExplorer.NAME); |
|
284 |
params.setRoot(this.getDWGParameters().getFile().getParent()); |
|
285 |
return manager.createServerExplorer(params); |
|
286 |
} catch (DataException e) { |
|
287 |
throw new ReadException(this.getProviderName(), e); |
|
288 |
} catch (ValidateDataParametersException e) { |
|
289 |
throw new ReadException(this.getProviderName(), e); |
|
290 |
} |
|
291 |
|
|
292 |
} |
|
293 |
|
|
294 |
public void performChanges(Iterator deleteds, Iterator inserteds, Iterator updateds, Iterator originalFeatureTypesUpdated) throws PerformEditingException { |
|
295 |
// FIXME Exception |
|
296 |
throw new UnsupportedOperationException(); |
|
297 |
} |
|
298 |
|
|
299 |
public class Reader { |
|
300 |
|
|
301 |
private File file; |
|
302 |
private String fileName; |
|
303 |
private IProjection projection; |
|
304 |
private List types; |
|
305 |
private LegendBuilder leyendBuilder; |
|
306 |
private AbstractMemoryStoreProvider store; |
|
307 |
private Envelope envelope; |
|
308 |
private DwgFile dwgFeatureFile; |
|
309 |
|
|
310 |
public Reader initialice(AbstractMemoryStoreProvider store, File file, |
|
311 |
IProjection projection, |
|
312 |
LegendBuilder leyendBuilder) { |
|
313 |
this.store = store; |
|
314 |
this.file = file; |
|
315 |
this.fileName = file.getAbsolutePath(); |
|
316 |
this.projection = projection; |
|
317 |
this.leyendBuilder = leyendBuilder; |
|
318 |
if (leyendBuilder != null) { |
|
319 |
leyendBuilder.initialize(store); |
|
320 |
} |
|
321 |
return this; |
|
322 |
} |
|
323 |
|
|
324 |
public Envelope getEnvelope() { |
|
325 |
return this.envelope; |
|
326 |
} |
|
327 |
|
|
328 |
public void begin(FeatureStoreProviderServices store) throws UnsupportedDWGVersionException, ReadException { |
|
329 |
dwgFeatureFile = new DwgFile(file.getAbsolutePath()); |
|
330 |
|
|
331 |
try { |
|
332 |
dwgFeatureFile.read(); |
|
333 |
} catch (DwgVersionNotSupportedException e1) { |
|
334 |
throw new UnsupportedDWGVersionException(file.getName(), e1); |
|
335 |
} catch (IOException e) { |
|
336 |
throw new ReadException(NAME, e); |
|
337 |
} |
|
338 |
|
|
339 |
EditableFeatureType featureType = store.createFeatureType(getName()); |
|
340 |
|
|
341 |
featureType.setHasOID(true); |
|
342 |
|
|
343 |
ID_FIELD_ID = featureType.add(NAME_FIELD_ID, DataTypes.INT) |
|
344 |
.setDefaultValue(Integer.valueOf(0)) |
|
345 |
.getIndex(); |
|
346 |
|
|
347 |
EditableFeatureAttributeDescriptor attr = featureType.add( |
|
348 |
NAME_FIELD_GEOMETRY, DataTypes.GEOMETRY); |
|
349 |
attr.setSRS(this.projection); |
|
350 |
attr.setGeometryType(Geometry.TYPES.GEOMETRY); |
|
351 |
boolean is3dFile = dwgFeatureFile.isDwg3DFile(); |
|
352 |
if (is3dFile) { |
|
353 |
attr.setGeometrySubType(Geometry.SUBTYPES.GEOM3D); |
|
354 |
} else { |
|
355 |
attr.setGeometrySubType(Geometry.SUBTYPES.GEOM2D); |
|
356 |
} |
|
357 |
ID_FIELD_GEOMETRY = attr.getIndex(); |
|
358 |
|
|
359 |
featureType.setDefaultGeometryAttributeName(NAME_FIELD_GEOMETRY); |
|
360 |
|
|
361 |
// FIXME: Cual es el size y el valor por defecto para Entity ? |
|
362 |
ID_FIELD_ENTITY = featureType.add(NAME_FIELD_ENTITY, |
|
363 |
DataTypes.STRING, 100) |
|
364 |
.setDefaultValue("") |
|
365 |
.getIndex(); |
|
366 |
|
|
367 |
// FIXME: Cual es el size de Layer ? |
|
368 |
ID_FIELD_LAYER = featureType.add(NAME_FIELD_LAYER, |
|
369 |
DataTypes.STRING, 100) |
|
370 |
.setDefaultValue( |
|
371 |
"default").getIndex(); |
|
372 |
|
|
373 |
ID_FIELD_COLOR = featureType.add(NAME_FIELD_COLOR, |
|
374 |
DataTypes.INT) |
|
375 |
.setDefaultValue( |
|
376 |
Integer.valueOf(0)).getIndex(); |
|
377 |
|
|
378 |
ID_FIELD_ELEVATION = featureType.add(NAME_FIELD_ELEVATION, |
|
379 |
DataTypes.DOUBLE) |
|
380 |
.setDefaultValue( |
|
381 |
Double.valueOf(0)).getIndex(); |
|
382 |
|
|
383 |
ID_FIELD_THICKNESS = featureType.add(NAME_FIELD_THICKNESS, |
|
384 |
DataTypes.DOUBLE) |
|
385 |
.setDefaultValue( |
|
386 |
Double.valueOf(0)).getIndex(); |
|
387 |
|
|
388 |
// FIXME: Cual es el size de Text ? |
|
389 |
ID_FIELD_TEXT = featureType.add(NAME_FIELD_TEXT, |
|
390 |
DataTypes.STRING, 100) |
|
391 |
.setDefaultValue("") |
|
392 |
.getIndex(); |
|
393 |
|
|
394 |
ID_FIELD_HEIGHTTEXT = featureType.add(NAME_FIELD_HEIGHTTEXT, |
|
395 |
DataTypes.DOUBLE).setDefaultValue( |
|
396 |
Double.valueOf(10)).getIndex(); |
|
397 |
|
|
398 |
ID_FIELD_ROTATIONTEXT = featureType.add(NAME_FIELD_ROTATIONTEXT, |
|
399 |
DataTypes.DOUBLE).setDefaultValue( |
|
400 |
Double.valueOf(0)).getIndex(); |
|
401 |
|
|
402 |
// FIXME: Parece que el DXF puede tener mas atributos opcionales. |
|
403 |
// Habria que ver de pillarlos ? |
|
404 |
types = new ArrayList(); |
|
405 |
types.add(featureType); |
|
406 |
|
|
407 |
if (leyendBuilder != null) { |
|
408 |
leyendBuilder.begin(); |
|
409 |
} |
|
410 |
|
|
411 |
} |
|
412 |
|
|
413 |
public void end() { |
|
414 |
if (leyendBuilder != null) { |
|
415 |
leyendBuilder.end(); |
|
416 |
} |
|
417 |
} |
|
418 |
|
|
419 |
public List getTypes() { |
|
420 |
return types; |
|
421 |
} |
|
422 |
|
|
423 |
public EditableFeatureType getDefaultType() { |
|
424 |
return (EditableFeatureType) types.get(0); |
|
425 |
} |
|
426 |
|
|
427 |
private Double toDouble(String value) { |
|
428 |
if (value == null) { |
|
429 |
return Double.valueOf(0); |
|
430 |
} |
|
431 |
return Double.valueOf(value); |
|
432 |
} |
|
433 |
|
|
434 |
public void load() throws DataException { |
|
435 |
|
|
436 |
this.envelope = null; |
|
437 |
|
|
438 |
long count_not_fmap_interface = 0; |
|
439 |
long count_null_geometry = 0; |
|
440 |
long count_bad_envelope = 0; |
|
441 |
long count_envelope_out_of_aoi = 0; |
|
442 |
|
|
443 |
dwgFeatureFile.calculateGisModelDwgPolylines(); |
|
444 |
dwgFeatureFile.blockManagement2(); |
|
445 |
List entities = dwgFeatureFile.getDwgObjects(); |
|
446 |
|
|
447 |
int id = -1; |
|
448 |
try { |
|
449 |
int envelopeSubType = Geometry.SUBTYPES.GEOM2D; |
|
450 |
boolean is3dFile = dwgFeatureFile.isDwg3DFile(); |
|
451 |
|
|
452 |
this.envelope = geomManager.createEnvelope(envelopeSubType); |
|
453 |
|
|
454 |
boolean updateEnvelope = true; |
|
455 |
|
|
456 |
double[] extMin = (double[]) dwgFeatureFile |
|
457 |
.getHeader("MSPACE_EXTMIN"); |
|
458 |
double[] extMax = (double[]) dwgFeatureFile |
|
459 |
.getHeader("MSPACE_EXTMAX"); |
|
460 |
if (extMin != null && extMax != null) { |
|
461 |
updateEnvelope = false; |
|
462 |
Point point = geomManager.createPoint(extMin[0], extMin[1],envelopeSubType); |
|
463 |
this.envelope.setLowerCorner(point); |
|
464 |
point = geomManager.createPoint(extMax[0], extMax[1],envelopeSubType); |
|
465 |
this.envelope.setUpperCorner(point); |
|
466 |
} |
|
467 |
|
|
468 |
Iterator iter = entities.iterator(); |
|
469 |
|
|
470 |
FeatureProvider featureProvider; |
|
471 |
Envelope gEnvelope; |
|
472 |
|
|
473 |
while (iter.hasNext()) { |
|
474 |
id++; |
|
475 |
DwgObject entity = (DwgObject) iter.next(); |
|
476 |
|
|
477 |
if (!(entity instanceof IDwg2FMap)) { |
|
478 |
count_not_fmap_interface++; |
|
479 |
/* |
|
480 |
logger.warn("load: entity type {}(id:{}) not loadded", |
|
481 |
new Object[] { entity.getType() }, id); |
|
482 |
*/ |
|
483 |
continue; |
|
484 |
} |
|
485 |
|
|
486 |
IDwg2FMap dwgEnt = (IDwg2FMap) entity; |
|
487 |
Geometry geometry = dwgEnt.toFMapGeometry(is3dFile); |
|
488 |
if (geometry == null) { |
|
489 |
count_null_geometry++; |
|
490 |
/* |
|
491 |
logger.warn("load: entity {}(id:{}) with null geometry", |
|
492 |
new Object[] { entity.getType(), id }); |
|
493 |
*/ |
|
494 |
continue; |
|
495 |
} |
|
496 |
|
|
497 |
// we check for Region of Interest of the CAD file |
|
498 |
if (!this.envelope.intersects(geometry.getEnvelope())) { |
|
499 |
count_envelope_out_of_aoi++; |
|
500 |
/* |
|
501 |
logger.warn("load: entity {}(id:{}) out of envelope", |
|
502 |
new Object[] { entity.getType(), id }); |
|
503 |
*/ |
|
504 |
continue; |
|
505 |
} |
|
506 |
featureProvider = store.createFeatureProvider(store |
|
507 |
.getStoreServices().getDefaultFeatureType()); |
|
508 |
|
|
509 |
featureProvider.set(ID_FIELD_ID, id); |
|
510 |
|
|
511 |
featureProvider.set(ID_FIELD_ENTITY, dwgEnt.toString()); |
|
512 |
|
|
513 |
featureProvider.set(ID_FIELD_LAYER, dwgFeatureFile |
|
514 |
.getLayerName(entity)); |
|
515 |
|
|
516 |
int colorByLayer = dwgFeatureFile.getColorByLayer(entity); |
|
517 |
int color = entity.getColor(); |
|
518 |
if (color < 0) { |
|
519 |
color = Math.abs(color); |
|
520 |
} |
|
521 |
if (color > 255) { |
|
522 |
color = colorByLayer; |
|
523 |
} |
|
524 |
|
|
525 |
featureProvider.set(ID_FIELD_COLOR, color); |
|
526 |
|
|
527 |
if (entity instanceof IDwg3DTestable) { |
|
528 |
featureProvider.set(ID_FIELD_ELEVATION, |
|
529 |
((IDwg3DTestable) entity).getZ()); |
|
530 |
} |
|
531 |
|
|
532 |
featureProvider.set(ID_FIELD_THICKNESS, 0.0); |
|
533 |
featureProvider.set(ID_FIELD_HEIGHTTEXT, 0.0); |
|
534 |
featureProvider.set(ID_FIELD_ROTATIONTEXT, 0.0); |
|
535 |
featureProvider.set(ID_FIELD_TEXT, ""); |
|
536 |
|
|
537 |
if (entity instanceof DwgMText) { |
|
538 |
DwgMText mtext = (DwgMText) entity; |
|
539 |
featureProvider.set(ID_FIELD_HEIGHTTEXT, mtext.getHeight()); |
|
540 |
featureProvider.set(ID_FIELD_TEXT, mtext.getText()); |
|
541 |
} else if (entity instanceof DwgText) { |
|
542 |
DwgText text = (DwgText) entity; |
|
543 |
featureProvider |
|
544 |
.set(ID_FIELD_THICKNESS, text.getThickness()); |
|
545 |
featureProvider.set(ID_FIELD_HEIGHTTEXT, text.getHeight()); |
|
546 |
featureProvider.set(ID_FIELD_ROTATIONTEXT, text |
|
547 |
.getRotationAngle()); |
|
548 |
featureProvider.set(ID_FIELD_TEXT, text.getText()); |
|
549 |
}// if-else |
|
550 |
|
|
551 |
featureProvider.setDefaultGeometry(geometry); |
|
552 |
|
|
553 |
store.addFeatureProvider(featureProvider); |
|
554 |
if (this.leyendBuilder != null) { |
|
555 |
this.leyendBuilder.process(featureProvider); |
|
556 |
} |
|
557 |
|
|
558 |
} |
|
559 |
|
|
560 |
logger.info("Issues while loading DWG entities:+\n" |
|
561 |
+ " Entities not implementing IDwg2FMap interface: " + count_not_fmap_interface + "\n" |
|
562 |
+ " Entities with non-convertible geometry: " + count_null_geometry + "\n" |
|
563 |
+ " Entities without valid envelope: " + count_bad_envelope + "\n" |
|
564 |
+ " Entities with envelope out of global envelope: " + count_envelope_out_of_aoi); |
|
565 |
|
|
566 |
} catch (org.gvsig.fmap.geom.exception.CreateGeometryException e) { |
|
567 |
throw new CreateGeometryException(e); |
|
568 |
} catch (org.gvsig.fmap.geom.exception.CreateEnvelopeException e) { |
|
569 |
throw new CreateGeometryException(e); |
|
570 |
} |
|
571 |
} |
|
572 |
|
|
573 |
} |
|
574 |
|
|
575 |
public boolean closeResourceRequested(ResourceProvider resource) { |
|
576 |
return true; |
|
577 |
} |
|
578 |
|
|
579 |
public int getOIDType() { |
|
580 |
return DataTypes.LONG; |
|
581 |
} |
|
582 |
|
|
583 |
public boolean supportsAppendMode() { |
|
584 |
return false; |
|
585 |
} |
|
586 |
|
|
587 |
public void append(FeatureProvider featureProvider) { |
|
588 |
// FIXME Exception |
|
589 |
throw new UnsupportedOperationException(); |
|
590 |
} |
|
591 |
|
|
592 |
public void beginAppend() { |
|
593 |
// FIXME Exception |
|
594 |
throw new UnsupportedOperationException(); |
|
595 |
|
|
596 |
} |
|
597 |
|
|
598 |
public void endAppend() { |
|
599 |
// FIXME Exception |
|
600 |
throw new UnsupportedOperationException(); |
|
601 |
} |
|
602 |
|
|
603 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
604 |
// TODO Auto-generated method stub |
|
605 |
throw new NotYetImplemented(); |
|
606 |
} |
|
607 |
|
|
608 |
public void loadFromState(PersistentState state) throws PersistenceException { |
|
609 |
// TODO Auto-generated method stub |
|
610 |
throw new NotYetImplemented(); |
|
611 |
} |
|
612 |
|
|
613 |
public Object createNewOID() { |
|
614 |
return new Long(counterNewsOIDs++); |
|
615 |
} |
|
616 |
|
|
617 |
protected void initializeFeatureTypes() throws InitializeException { |
|
618 |
try { |
|
619 |
this.open(); |
|
620 |
} catch (OpenException e) { |
|
621 |
throw new InitializeException(this.getProviderName(), e); |
|
622 |
} |
|
623 |
} |
|
624 |
|
|
625 |
public Envelope getEnvelope() throws DataException { |
|
626 |
this.open(); |
|
627 |
return (Envelope) this.getDynValue("Envelope"); |
|
628 |
} |
|
629 |
|
|
630 |
|
|
631 |
/* |
|
632 |
* (non-Javadoc) |
|
633 |
* |
|
634 |
* @see |
|
635 |
* org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org. |
|
636 |
* gvsig.fmap.dal.resource.spi.ResourceProvider) |
|
637 |
*/ |
|
638 |
public void resourceChanged(ResourceProvider resource) { |
|
639 |
this.getStoreServices().notifyChange( |
|
640 |
DataStoreNotification.RESOURCE_CHANGED, |
|
641 |
resource); |
|
642 |
} |
|
643 |
|
|
644 |
public Object getSourceId() { |
|
645 |
return this.getDWGParameters().getFile(); |
|
646 |
} |
|
647 |
|
|
648 |
public String getName() { |
|
649 |
String name = this.getDWGParameters().getFile().getName(); |
|
650 |
int n = name.lastIndexOf("."); |
|
651 |
if (n < 1) { |
|
652 |
return name; |
|
653 |
} |
|
654 |
return name.substring(0, n); |
|
655 |
} |
|
656 |
|
|
657 |
public String getFullName() { |
|
658 |
return this.getDWGParameters().getFile().getAbsolutePath(); |
|
659 |
} |
|
660 |
|
|
661 |
public ResourceProvider getResource() { |
|
662 |
return resource; |
|
663 |
} |
|
664 |
|
|
665 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/java/org/gvsig/dwg/fmap/dal/store/dwg/UnsupportedDWGVersionException.java | ||
---|---|---|
1 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
2 |
|
|
3 |
import org.gvsig.dwg.lib.DwgVersionNotSupportedException; |
|
4 |
import org.gvsig.fmap.dal.exception.DataException; |
|
5 |
|
|
6 |
public class UnsupportedDWGVersionException extends DataException { |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
*/ |
|
11 |
private static final long serialVersionUID = -7335241420683266251L; |
|
12 |
private final static String MESSAGE_FORMAT = "Unssuported version of DWG of file '%(file)'. Try to convert using Autodesk convertor from '%(autodeskurl)'"; |
|
13 |
private final static String MESSAGE_KEY = "_UnsupportedDWGVersionException"; |
|
14 |
|
|
15 |
public final static String AUTODESK_URL = "http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151"; |
|
16 |
|
|
17 |
public UnsupportedDWGVersionException(String file, |
|
18 |
DwgVersionNotSupportedException cause) { |
|
19 |
super(MESSAGE_FORMAT, cause, MESSAGE_KEY, serialVersionUID); |
|
20 |
setValue("file", file); |
|
21 |
setValue("autodeskurl", AUTODESK_URL); |
|
22 |
} |
|
23 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/java/org/gvsig/dwg/fmap/dal/store/dwg/DWGStoreProviderFactory.java | ||
---|---|---|
1 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
2 |
|
|
3 |
|
|
4 |
import org.gvsig.fmap.dal.DataParameters; |
|
5 |
import org.gvsig.fmap.dal.DataStoreProvider; |
|
6 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
7 |
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory; |
|
8 |
import org.gvsig.fmap.dal.feature.spi.AbstractFeatureStoreProviderFactory; |
|
9 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
10 |
import org.gvsig.tools.dynobject.DynObject; |
|
11 |
|
|
12 |
public class DWGStoreProviderFactory extends AbstractFeatureStoreProviderFactory implements FeatureStoreProviderFactory{ |
|
13 |
|
|
14 |
protected DWGStoreProviderFactory(String name, String description) { |
|
15 |
super(name, description); |
|
16 |
} |
|
17 |
|
|
18 |
public DataStoreProvider createProvider(DataParameters parameters, |
|
19 |
DataStoreProviderServices providerServices) |
|
20 |
throws InitializeException { |
|
21 |
return new DWGStoreProvider((DWGOpenStoreParameters) parameters, providerServices); |
|
22 |
} |
|
23 |
|
|
24 |
public DynObject createParameters() { |
|
25 |
return new DWGOpenStoreParameters(); |
|
26 |
} |
|
27 |
|
|
28 |
public int allowCreate() { |
|
29 |
return NO; |
|
30 |
} |
|
31 |
|
|
32 |
public int allowWrite() { |
|
33 |
return NO; |
|
34 |
} |
|
35 |
|
|
36 |
public int allowRead() { |
|
37 |
return YES; |
|
38 |
} |
|
39 |
|
|
40 |
public int hasRasterSupport() { |
|
41 |
return NO; |
|
42 |
} |
|
43 |
|
|
44 |
public int hasTabularSupport() { |
|
45 |
return YES; |
|
46 |
} |
|
47 |
|
|
48 |
public int hasVectorialSupport() { |
|
49 |
return YES; |
|
50 |
} |
|
51 |
|
|
52 |
public int allowMultipleGeometryTypes() { |
|
53 |
return YES; |
|
54 |
} |
|
55 |
|
|
56 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/java/org/gvsig/dwg/fmap/dal/store/dwg/DWGOpenStoreParameters.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.FileHelper; |
|
7 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
8 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
9 |
import org.gvsig.fmap.dal.feature.OpenFeatureStoreParameters; |
|
10 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters; |
|
11 |
import org.gvsig.fmap.dal.spi.AbstractDataStoreParameters; |
|
12 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
13 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
14 |
|
|
15 |
public class DWGOpenStoreParameters extends AbstractDataStoreParameters implements |
|
16 |
FilesystemStoreParameters, |
|
17 |
OpenFeatureStoreParameters { |
|
18 |
|
|
19 |
public static final String PARAMETERS_DEFINITION_NAME = "DWGStoreParameters"; |
|
20 |
|
|
21 |
private static final String FIELD_FILE = "file"; |
|
22 |
private static final String FIELD_CRS = "CRS"; |
|
23 |
|
|
24 |
private DelegatedDynObject parameters; |
|
25 |
|
|
26 |
public DWGOpenStoreParameters() { |
|
27 |
this(PARAMETERS_DEFINITION_NAME); |
|
28 |
} |
|
29 |
|
|
30 |
protected DWGOpenStoreParameters(String parametersDefinitionName) { |
|
31 |
this(parametersDefinitionName, DWGStoreProvider.NAME); |
|
32 |
} |
|
33 |
|
|
34 |
public DWGOpenStoreParameters(String parametersDefinitionName, String name) { |
|
35 |
super(); |
|
36 |
this.parameters = (DelegatedDynObject) FileHelper |
|
37 |
.newParameters(parametersDefinitionName); |
|
38 |
this |
|
39 |
.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, |
|
40 |
name); |
|
41 |
} |
|
42 |
|
|
43 |
protected DelegatedDynObject getDelegatedDynObject() { |
|
44 |
return parameters; |
|
45 |
} |
|
46 |
|
|
47 |
public String getDataStoreName() { |
|
48 |
return (String) this |
|
49 |
.getDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME); |
|
50 |
} |
|
51 |
|
|
52 |
public String getDescription() { |
|
53 |
return this.getDynClass().getDescription(); |
|
54 |
} |
|
55 |
|
|
56 |
public void setCRS(IProjection crs) { |
|
57 |
setDynValue(FIELD_CRS, crs); |
|
58 |
} |
|
59 |
|
|
60 |
public void setCRS(String crs) { |
|
61 |
setDynValue(FIELD_CRS, crs); |
|
62 |
} |
|
63 |
|
|
64 |
public IProjection getCRS() { |
|
65 |
return (IProjection) getDynValue(FIELD_CRS); |
|
66 |
} |
|
67 |
|
|
68 |
public String getFileName() { |
|
69 |
return this.getFile().getPath(); |
|
70 |
} |
|
71 |
|
|
72 |
public void setFileName(String file) { |
|
73 |
setDynValue(FIELD_FILE, file); |
|
74 |
} |
|
75 |
|
|
76 |
public boolean isValid() { |
|
77 |
if (getCRS() == null) { |
|
78 |
return false; |
|
79 |
} |
|
80 |
if (getFile() == null) { |
|
81 |
return false; |
|
82 |
} |
|
83 |
return true; |
|
84 |
} |
|
85 |
|
|
86 |
public File getFile() { |
|
87 |
return (File) this.getDynValue(FIELD_FILE); |
|
88 |
} |
|
89 |
|
|
90 |
public void setFile(File file) { |
|
91 |
this.setDynValue(FIELD_FILE, file); |
|
92 |
} |
|
93 |
|
|
94 |
public EditableFeatureType getDefaultFeatureType() { |
|
95 |
return null; //TODO ???? |
|
96 |
} |
|
97 |
|
|
98 |
public void setDefaultFeatureType(FeatureType defaultFeatureType) { |
|
99 |
throw new UnsupportedOperationException(); |
|
100 |
} |
|
101 |
|
|
102 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/java/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 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/src/main/java/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 |
DWGOpenStoreParameters.PARAMETERS_DEFINITION_NAME, |
|
63 |
DWGOpenStoreParameters.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.registerStoreProviderFactory(new DWGStoreProviderFactory( |
|
81 |
DWGStoreProvider.NAME, |
|
82 |
DWGStoreProvider.DESCRIPTION |
|
83 |
)); |
|
84 |
} |
|
85 |
|
|
86 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
87 |
DWGStoreProvider.NAME, DWGStoreProvider.DESCRIPTION, |
|
88 |
DWGFilesystemServerProvider.class); |
|
89 |
|
|
90 |
DynObjectManager dynMan = ToolsLocator.getDynObjectManager(); |
|
91 |
DynClass dynClass = dynMan.get( |
|
92 |
DWGStoreProvider.METADATA_DEFINITION_NAME); |
|
93 |
DynField field; |
|
94 |
if (dynClass == null) { |
|
95 |
dynClass = dynMan.add( |
|
96 |
DWGStoreProvider.METADATA_DEFINITION_NAME); |
|
97 |
|
|
98 |
} |
|
99 |
} |
|
100 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.provider/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
|
|
5 |
<modelVersion>4.0.0</modelVersion> |
|
6 |
<artifactId>org.gvsig.dwg.provider</artifactId> |
|
7 |
<packaging>jar</packaging> |
|
8 |
<name>${project.artifactId}</name> |
|
9 |
<description>DAL provider for DWG files</description> |
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>org.gvsig.dwg</artifactId> |
|
13 |
<version>2.0.273</version> |
|
14 |
</parent> |
|
15 |
|
|
16 |
<dependencies> |
|
17 |
|
|
18 |
<dependency> |
|
19 |
<groupId>commons-io</groupId> |
|
20 |
<artifactId>commons-io</artifactId> |
|
21 |
<scope>compile</scope> |
|
22 |
</dependency> |
|
23 |
|
|
24 |
<dependency> |
|
25 |
<groupId>org.gvsig</groupId> |
|
26 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
27 |
<scope>compile</scope> |
|
28 |
</dependency> |
|
29 |
<dependency> |
|
30 |
<groupId>org.gvsig</groupId> |
|
31 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
32 |
<scope>compile</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
37 |
<scope>compile</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>org.gvsig</groupId> |
|
41 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
42 |
<scope>compile</scope> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>org.gvsig</groupId> |
|
46 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
47 |
<scope>compile</scope> |
|
48 |
</dependency> |
|
49 |
<dependency> |
|
50 |
<groupId>org.gvsig</groupId> |
|
51 |
<artifactId>org.gvsig.dwg.lib</artifactId> |
|
52 |
<scope>compile</scope> |
|
53 |
</dependency> |
|
54 |
<dependency> |
|
55 |
<groupId>org.gvsig</groupId> |
|
56 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
57 |
<scope>compile</scope> |
|
58 |
</dependency> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.timesupport.lib.api</artifactId> |
|
62 |
<scope>compile</scope> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.utils</artifactId> |
|
67 |
<scope>compile</scope> |
|
68 |
</dependency> |
|
69 |
<dependency> |
|
70 |
<groupId>org.gvsig</groupId> |
|
71 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
72 |
<scope>compile</scope> |
|
73 |
</dependency> |
|
74 |
|
|
75 |
|
|
76 |
<!-- TESTS --> |
|
77 |
<dependency> |
|
78 |
<groupId>org.gvsig</groupId> |
|
79 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
80 |
<type>test-jar</type> |
|
81 |
<scope>test</scope> |
|
82 |
</dependency> |
|
83 |
<dependency> |
|
84 |
<groupId>org.gvsig</groupId> |
|
85 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
86 |
<scope>test</scope> |
|
87 |
</dependency> |
|
88 |
<dependency> |
|
89 |
<groupId>org.gvsig</groupId> |
|
90 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
91 |
<type>test-jar</type> |
|
92 |
<scope>test</scope> |
|
93 |
</dependency> |
|
94 |
|
|
95 |
<!-- |
|
96 |
<dependency> |
|
97 |
<groupId>org.gvsig</groupId> |
|
98 |
<artifactId>org.gvsig.fmap.dal.index.spatial.jts</artifactId> |
|
99 |
<scope>test</scope> |
|
100 |
</dependency> |
|
101 |
--> |
|
102 |
|
|
103 |
<dependency> |
|
104 |
<groupId>org.gvsig</groupId> |
|
105 |
<artifactId>org.gvsig.fmap.geometry.impl</artifactId> |
|
106 |
<scope>test</scope> |
|
107 |
</dependency> |
|
108 |
<dependency> |
|
109 |
<groupId>org.gvsig</groupId> |
|
110 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
111 |
<scope>test</scope> |
|
112 |
</dependency> |
|
113 |
<dependency> |
|
114 |
<groupId>org.gvsig</groupId> |
|
115 |
<artifactId>org.gvsig.timesupport.lib.impl</artifactId> |
|
116 |
<scope>test</scope> |
|
117 |
</dependency> |
|
118 |
<!-- |
|
119 |
<dependency> |
|
120 |
<groupId>org.gvsig</groupId> |
|
121 |
<artifactId>org.gvsig.fmap.dal</artifactId> |
|
122 |
<type>test-jar</type> |
|
123 |
<scope>test</scope> |
|
124 |
</dependency> |
|
125 |
--> |
|
126 |
|
|
127 |
|
|
128 |
</dependencies> |
|
129 |
|
|
130 |
</project> |
|
0 | 131 |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/test/java/org/gvsig/dwg/fmap/dal/store/dwg/TestDWG.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 java.io.File; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.DataStoreParameters; |
|
33 |
import org.gvsig.fmap.dal.exception.DataException; |
|
34 |
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore; |
|
35 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
36 |
|
|
37 |
public class TestDWG extends BaseTestFeatureStore { |
|
38 |
|
|
39 |
|
|
40 |
protected boolean testDXFInitialized = false; |
|
41 |
|
|
42 |
public static File file_prueba = new File(TestDWG.class.getResource( |
|
43 |
"data/V2000.dwg").getFile()); |
|
44 |
|
|
45 |
/* |
|
46 |
* (non-Javadoc) |
|
47 |
* |
|
48 |
* @see |
|
49 |
* org.gvsig.fmap.dal.feature.BaseTestFeatureStore#getDefaultDataStoreParameters |
|
50 |
* () |
|
51 |
*/ |
|
52 |
public DataStoreParameters getDefaultDataStoreParameters() |
|
53 |
throws DataException { |
|
54 |
DWGStoreParameters dwgParameters = null; |
|
55 |
|
|
56 |
dwgParameters = (DWGStoreParameters) dataManager |
|
57 |
.createStoreParameters(DWGStoreProvider.NAME); |
|
58 |
|
|
59 |
dwgParameters.setFile(file_prueba); |
|
60 |
dwgParameters.setCRS("EPSG:23030"); |
|
61 |
return dwgParameters; |
|
62 |
} |
|
63 |
|
|
64 |
/* |
|
65 |
* (non-Javadoc) |
|
66 |
* |
|
67 |
* @see org.gvsig.fmap.dal.feature.BaseTestFeatureStore#hasExplorer() |
|
68 |
*/ |
|
69 |
public boolean hasExplorer() { |
|
70 |
// TODO Auto-generated method stub |
|
71 |
return false; |
|
72 |
} |
|
73 |
|
|
74 |
public boolean usesResources() { |
|
75 |
return true; |
|
76 |
} |
|
77 |
|
|
78 |
|
|
79 |
public void testLegendAndLabeling() throws Exception { |
|
80 |
DataStoreParameters params = getDefaultDataStoreParameters(); |
|
81 |
FeatureStore store = (FeatureStore) dataManager.openStore(params |
|
82 |
.getDataStoreName(), params); |
|
83 |
|
|
84 |
assertNotNull(store.invokeDynMethod("getLegend", null)); |
|
85 |
assertNotNull(store.invokeDynMethod("getLabeling", null)); |
|
86 |
store.dispose(); |
|
87 |
} |
|
88 |
} |
tags/org.gvsig.dwg-2.0.273/org.gvsig.dwg.app/org.gvsig.dwg.app.mainplugin/src/test/java/org/gvsig/dwg/fmap/dal/store/dwg/TestDWG2004.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 |
* 2009 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.dwg.fmap.dal.store.dwg; |
|
29 |
|
|
30 |
import java.io.File; |
|
31 |
|
|
32 |
public class TestDWG2004 extends TestDWG { |
|
33 |
public static File file_prueba = new File(TestDWG.class.getResource( |
|
34 |
"data/V2004.dwg").getFile()); |
|
35 |
} |
Also available in: Unified diff