svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dalfile / src / org / gvsig / fmap / dal / store / dxf / DXFStoreProvider.java @ 28076
History | View | Annotate | Download (47.3 KB)
1 | 24498 | jmvivo | package org.gvsig.fmap.dal.store.dxf; |
---|---|---|---|
2 | 23894 | jjdelcerro | |
3 | import java.awt.geom.PathIterator; |
||
4 | import java.awt.geom.Point2D; |
||
5 | import java.io.File; |
||
6 | import java.text.MessageFormat; |
||
7 | import java.util.ArrayList; |
||
8 | 27301 | jmvivo | import java.util.HashMap; |
9 | 23894 | jjdelcerro | import java.util.Iterator; |
10 | import java.util.List; |
||
11 | 27301 | jmvivo | import java.util.Map; |
12 | 23894 | jjdelcerro | import java.util.Vector; |
13 | |||
14 | import org.cresques.cts.IProjection; |
||
15 | import org.cresques.geo.Point3D; |
||
16 | import org.cresques.io.DxfFile; |
||
17 | import org.cresques.io.DxfGroup; |
||
18 | import org.cresques.io.DxfGroupVector; |
||
19 | import org.cresques.px.IObjList; |
||
20 | import org.cresques.px.dxf.DxfEntityMaker; |
||
21 | import org.cresques.px.dxf.DxfFeatureMaker; |
||
22 | import org.cresques.px.dxf.DxfHeaderManager; |
||
23 | import org.cresques.px.gml.Feature; |
||
24 | import org.cresques.px.gml.LineString; |
||
25 | import org.cresques.px.gml.LineString3D; |
||
26 | import org.cresques.px.gml.Point; |
||
27 | import org.cresques.px.gml.Polygon; |
||
28 | import org.cresques.px.gml.Polygon3D; |
||
29 | 24569 | jmvivo | import org.gvsig.fmap.dal.DALLocator; |
30 | import org.gvsig.fmap.dal.DataManager; |
||
31 | 24916 | jmvivo | import org.gvsig.fmap.dal.DataServerExplorer; |
32 | 25789 | jmvivo | import org.gvsig.fmap.dal.DataStoreNotification; |
33 | 24498 | jmvivo | import org.gvsig.fmap.dal.DataTypes; |
34 | 24502 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
35 | import org.gvsig.fmap.dal.exception.InitializeException; |
||
36 | import org.gvsig.fmap.dal.exception.LoadException; |
||
37 | import org.gvsig.fmap.dal.exception.OpenException; |
||
38 | import org.gvsig.fmap.dal.exception.ReadException; |
||
39 | 27723 | jmvivo | import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
40 | 24502 | jmvivo | import org.gvsig.fmap.dal.exception.WriteException; |
41 | 27525 | jmvivo | import org.gvsig.fmap.dal.feature.DisposableIterator; |
42 | 25924 | jmvivo | import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
43 | 24498 | jmvivo | import org.gvsig.fmap.dal.feature.EditableFeatureType; |
44 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
45 | 25924 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureStore; |
46 | 27301 | jmvivo | import org.gvsig.fmap.dal.feature.FeatureType; |
47 | 24502 | jmvivo | import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
48 | 24498 | jmvivo | import org.gvsig.fmap.dal.feature.spi.FeatureData; |
49 | import org.gvsig.fmap.dal.feature.spi.FeatureStoreProvider; |
||
50 | import org.gvsig.fmap.dal.feature.spi.FeatureStoreProviderServices; |
||
51 | import org.gvsig.fmap.dal.feature.spi.LegendBuilder; |
||
52 | import org.gvsig.fmap.dal.feature.spi.memory.AbstractMemoryStoreProvider; |
||
53 | import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
||
54 | 28030 | jmvivo | import org.gvsig.fmap.dal.resource.exception.ResourceBeginException; |
55 | 25752 | vcaballero | import org.gvsig.fmap.dal.resource.exception.ResourceNotifyCloseException; |
56 | import org.gvsig.fmap.dal.resource.exception.ResourceNotifyOpenException; |
||
57 | 24498 | jmvivo | import org.gvsig.fmap.dal.resource.file.FileResource; |
58 | import org.gvsig.fmap.dal.resource.spi.ResourceConsumer; |
||
59 | import org.gvsig.fmap.dal.resource.spi.ResourceProvider; |
||
60 | 24893 | jmvivo | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
61 | import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters; |
||
62 | 23894 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
63 | 26332 | jpiera | import org.gvsig.fmap.geom.GeometryLocator; |
64 | 26904 | jpiera | import org.gvsig.fmap.geom.GeometryManager; |
65 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
66 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
67 | 27413 | jpiera | import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
68 | 27013 | jpiera | import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
69 | import org.gvsig.fmap.geom.operation.distance.PointDistance; |
||
70 | import org.gvsig.fmap.geom.operation.utils.PointGetAngle; |
||
71 | import org.gvsig.fmap.geom.primitive.Arc; |
||
72 | import org.gvsig.fmap.geom.primitive.Circle; |
||
73 | 26904 | jpiera | import org.gvsig.fmap.geom.primitive.Curve; |
74 | 27013 | jpiera | import org.gvsig.fmap.geom.primitive.Ellipse; |
75 | 25216 | jmvivo | import org.gvsig.fmap.geom.primitive.Envelope; |
76 | 23894 | jjdelcerro | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
77 | 26904 | jpiera | import org.gvsig.fmap.geom.primitive.Surface; |
78 | 27013 | jpiera | import org.gvsig.fmap.geom.type.GeometryType; |
79 | 23894 | jjdelcerro | import org.gvsig.fmap.geom.util.Converter; |
80 | 25924 | jmvivo | import org.gvsig.tools.ToolsLocator; |
81 | import org.gvsig.tools.dynobject.DelegatedDynObject; |
||
82 | import org.gvsig.tools.dynobject.DynClass; |
||
83 | import org.gvsig.tools.dynobject.DynField; |
||
84 | import org.gvsig.tools.dynobject.DynObjectManager; |
||
85 | 25789 | jmvivo | import org.gvsig.tools.dynobject.exception.DynMethodException; |
86 | 24248 | jjdelcerro | import org.gvsig.tools.exception.NotYetImplemented; |
87 | 24167 | jmvivo | import org.gvsig.tools.persistence.PersistenceException; |
88 | import org.gvsig.tools.persistence.PersistentState; |
||
89 | 27413 | jpiera | import org.slf4j.Logger; |
90 | import org.slf4j.LoggerFactory; |
||
91 | 23894 | jjdelcerro | |
92 | public class DXFStoreProvider extends AbstractMemoryStoreProvider implements |
||
93 | ResourceConsumer { |
||
94 | 27413 | jpiera | private static final Logger logger = LoggerFactory.getLogger(DXFStoreProvider.class); |
95 | 27525 | jmvivo | |
96 | 25789 | jmvivo | public static final String NAME = "DXF"; |
97 | public static final String DESCRIPTION = "DXF file"; |
||
98 | public static final String DYNCLASS_NAME = "DXFFile"; |
||
99 | 25924 | jmvivo | protected static DynClass DYNCLASS = null; |
100 | 23894 | jjdelcerro | |
101 | private int ID_FIELD_ID = 0; |
||
102 | private int ID_FIELD_GEOMETRY = 1; |
||
103 | private int ID_FIELD_ENTITY = 2; |
||
104 | private int ID_FIELD_LAYER = 3; |
||
105 | private int ID_FIELD_COLOR = 4; |
||
106 | private int ID_FIELD_ELEVATION = 5; |
||
107 | private int ID_FIELD_THICKNESS = 6; |
||
108 | private int ID_FIELD_TEXT = 7; |
||
109 | private int ID_FIELD_HEIGHTTEXT = 8; |
||
110 | private int ID_FIELD_ROTATIONTEXT = 9; |
||
111 | |||
112 | private IProjection projection;
|
||
113 | private ResourceProvider resource;
|
||
114 | 23961 | vcaballero | private LegendBuilder leyendBuilder;
|
115 | 23894 | jjdelcerro | |
116 | 26233 | vcaballero | private long counterNewsOIDs = 0; |
117 | 25924 | jmvivo | // private Envelope envelope;
|
118 | 25752 | vcaballero | private Writer writer; |
119 | 27013 | jpiera | protected GeometryManager geomManager = GeometryLocator.getGeometryManager();
|
120 | 27301 | jmvivo | |
121 | 23894 | jjdelcerro | private DXFStoreParameters getParameters() {
|
122 | 24456 | jmvivo | return (DXFStoreParameters) this.parameters; |
123 | 23894 | jjdelcerro | } |
124 | |||
125 | 24456 | jmvivo | public DXFStoreProvider(DXFStoreParameters parameters) {
|
126 | super(parameters);
|
||
127 | } |
||
128 | |||
129 | 23894 | jjdelcerro | public FeatureStoreProvider initialize(FeatureStoreProviderServices store)
|
130 | throws InitializeException {
|
||
131 | super.initialize(store);
|
||
132 | |||
133 | 25924 | jmvivo | this.dynObject = (DelegatedDynObject) ToolsLocator
|
134 | .getDynObjectManager().createDynObject(DYNCLASS); |
||
135 | |||
136 | 24248 | jjdelcerro | counterNewsOIDs = 0;
|
137 | 24199 | jmvivo | // projection = CRSFactory.getCRS(getParameters().getSRSID());
|
138 | 23894 | jjdelcerro | |
139 | 24710 | jmvivo | File file = getParameters().getFile();
|
140 | 23894 | jjdelcerro | resource = this.createResource(
|
141 | 24167 | jmvivo | FileResource.NAME, |
142 | 24710 | jmvivo | new Object[] { file.getAbsolutePath() } |
143 | 23894 | jjdelcerro | ); |
144 | 27301 | jmvivo | |
145 | 23894 | jjdelcerro | resource.addConsumer(this);
|
146 | |||
147 | 26717 | jmvivo | this.projection = this.getParameters().getSRS(); |
148 | 24456 | jmvivo | |
149 | 27301 | jmvivo | |
150 | 23894 | jjdelcerro | try {
|
151 | 25789 | jmvivo | leyendBuilder = (LegendBuilder) store.invokeDynMethod( |
152 | LegendBuilder.DYNMETHOD_BUILDER_NAME, null);
|
||
153 | } catch (DynMethodException e) {
|
||
154 | 23894 | jjdelcerro | leyendBuilder = null;
|
155 | } catch (Exception e) { |
||
156 | throw new InitializeException(e); |
||
157 | } |
||
158 | 24512 | jmvivo | this.initializeFeatureTypes();
|
159 | 23894 | jjdelcerro | return this; |
160 | } |
||
161 | |||
162 | public String getName() { |
||
163 | 24167 | jmvivo | return NAME;
|
164 | 23894 | jjdelcerro | } |
165 | |||
166 | public boolean allowWrite() { |
||
167 | return true; |
||
168 | } |
||
169 | |||
170 | public Object getLeyend() throws OpenException { |
||
171 | this.open();
|
||
172 | if (leyendBuilder == null) { |
||
173 | return null; |
||
174 | } |
||
175 | 23961 | vcaballero | return leyendBuilder.getLegend();
|
176 | 23894 | jjdelcerro | } |
177 | |||
178 | 27301 | jmvivo | private class DXFData { |
179 | public ArrayList data = null; |
||
180 | public FeatureType defaultFType = null; |
||
181 | public List fTypes = null; |
||
182 | public Envelope envelope = null; |
||
183 | public IProjection projection;
|
||
184 | 27413 | jpiera | public Envelope getEnvelopeCopy() throws CreateEnvelopeException { |
185 | 27301 | jmvivo | if (envelope == null) { |
186 | return null; |
||
187 | } |
||
188 | 27303 | jmvivo | Envelope newEnvelope; |
189 | if (envelope.getDimension() == 2) { |
||
190 | 27413 | jpiera | newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM2D); |
191 | 27303 | jmvivo | } else {
|
192 | 27413 | jpiera | newEnvelope = geomManager.createEnvelope(SUBTYPES.GEOM3D); |
193 | 27303 | jmvivo | |
194 | } |
||
195 | 27301 | jmvivo | newEnvelope.setLowerCorner(envelope.getLowerCorner()); |
196 | newEnvelope.setUpperCorner(envelope.getUpperCorner()); |
||
197 | return newEnvelope;
|
||
198 | } |
||
199 | } |
||
200 | |||
201 | 23894 | jjdelcerro | public void open() throws OpenException { |
202 | if (this.data != null) { |
||
203 | return;
|
||
204 | } |
||
205 | try {
|
||
206 | this.resource.begin();
|
||
207 | 28030 | jmvivo | } catch (ResourceBeginException e2) {
|
208 | try {
|
||
209 | throw new OpenException(resource.getName(), e2); |
||
210 | } catch (AccessResourceException e1) {
|
||
211 | throw new OpenException(this.getName(), e2); |
||
212 | } |
||
213 | |||
214 | } |
||
215 | try {
|
||
216 | 27301 | jmvivo | DXFData dxfData = null;
|
217 | 23894 | jjdelcerro | if (this.resource.getData() != null) { |
218 | 27301 | jmvivo | dxfData = (DXFData) ((Map) this.resource.getData()) |
219 | .get(this.projection
|
||
220 | .getAbrev()); // OJO no es del todo correcto (puede
|
||
221 | // llevar reproyeccion)
|
||
222 | 23894 | jjdelcerro | } else {
|
223 | 27301 | jmvivo | this.resource.setData(new HashMap()); |
224 | } |
||
225 | if (dxfData == null) { |
||
226 | dxfData = new DXFData();
|
||
227 | dxfData.data = new ArrayList(); |
||
228 | this.data = dxfData.data;
|
||
229 | 24512 | jmvivo | this.counterNewsOIDs = 0; |
230 | 23894 | jjdelcerro | Reader reader = new Reader().initialice( |
231 | 24248 | jjdelcerro | this,
|
232 | 24456 | jmvivo | new File((String) this.resource.get()), |
233 | 24248 | jjdelcerro | projection, |
234 | this.leyendBuilder
|
||
235 | 23894 | jjdelcerro | ); |
236 | reader.begin(this.store);
|
||
237 | 27309 | jmvivo | dxfData.defaultFType = reader.getDefaultType() |
238 | .getNotEditableCopy(); |
||
239 | 24512 | jmvivo | ArrayList types = new ArrayList(); |
240 | Iterator it = reader.getTypes().iterator();
|
||
241 | 27309 | jmvivo | EditableFeatureType fType; |
242 | 24512 | jmvivo | while (it.hasNext()) {
|
243 | 27309 | jmvivo | fType = (EditableFeatureType) it.next(); |
244 | if (fType.getId().equals(dxfData.defaultFType.getId())) {
|
||
245 | types.add(dxfData.defaultFType); |
||
246 | } else {
|
||
247 | types.add(fType.getNotEditableCopy()); |
||
248 | } |
||
249 | 24512 | jmvivo | } |
250 | 27301 | jmvivo | dxfData.fTypes = types; |
251 | 27309 | jmvivo | |
252 | 23894 | jjdelcerro | resource.notifyOpen(); |
253 | 27301 | jmvivo | this.store
|
254 | .setFeatureTypes(dxfData.fTypes, dxfData.defaultFType); |
||
255 | 24512 | jmvivo | reader.load(); |
256 | 25924 | jmvivo | // this.envelope = reader.getEnvelope();
|
257 | |||
258 | 27301 | jmvivo | dxfData.envelope = reader.getEnvelope(); |
259 | 25924 | jmvivo | |
260 | 27301 | jmvivo | |
261 | dxfData.projection = this.projection;
|
||
262 | |||
263 | 23894 | jjdelcerro | reader.end(); |
264 | resource.notifyClose(); |
||
265 | 27301 | jmvivo | ((Map) this.resource.getData()).put(this.projection.getAbrev(), |
266 | dxfData); // OJO la reproyeccion
|
||
267 | 23894 | jjdelcerro | } |
268 | 27301 | jmvivo | |
269 | this.data = dxfData.data;
|
||
270 | this.store.setFeatureTypes(dxfData.fTypes, dxfData.defaultFType);
|
||
271 | this.dynObject.setDynValue("Envelope", dxfData.getEnvelopeCopy()); |
||
272 | this.dynObject
|
||
273 | .setDynValue("DefaultSRS", this.projection.getAbrev()); |
||
274 | this.counterNewsOIDs = this.data.size(); |
||
275 | 23894 | jjdelcerro | } catch (Exception e) { |
276 | 24512 | jmvivo | this.data = null; |
277 | 23912 | jmvivo | try {
|
278 | throw new OpenException(resource.getName(), e); |
||
279 | } catch (AccessResourceException e1) {
|
||
280 | throw new OpenException(this.getName(), e); |
||
281 | } |
||
282 | 23894 | jjdelcerro | } finally {
|
283 | this.resource.end();
|
||
284 | } |
||
285 | } |
||
286 | |||
287 | |||
288 | 24876 | jmvivo | public DataServerExplorer getExplorer() throws ReadException { |
289 | 24569 | jmvivo | DataManager manager = DALLocator.getDataManager(); |
290 | 24893 | jmvivo | FilesystemServerExplorerParameters params; |
291 | 24569 | jmvivo | try {
|
292 | 24893 | jmvivo | params = (FilesystemServerExplorerParameters) manager |
293 | .createServerExplorerParameters(FilesystemServerExplorer.NAME); |
||
294 | 24710 | jmvivo | params.setRoot(this.getParameters().getFile().getParent());
|
295 | 24876 | jmvivo | return manager.createServerExplorer(params);
|
296 | 24569 | jmvivo | } catch (DataException e) {
|
297 | throw new ReadException(this.getName(), e); |
||
298 | 27723 | jmvivo | } catch (ValidateDataParametersException e) {
|
299 | throw new ReadException(this.getName(), e); |
||
300 | 24569 | jmvivo | } |
301 | |||
302 | 23894 | jjdelcerro | } |
303 | |||
304 | |||
305 | 23996 | jmvivo | private FeatureData getFeatureDataFormFeature(Object feature) { |
306 | 24498 | jmvivo | org.gvsig.fmap.dal.feature.impl.DefaultFeature f = (org.gvsig.fmap.dal.feature.impl.DefaultFeature) feature; |
307 | 23894 | jjdelcerro | return f.getData();
|
308 | } |
||
309 | |||
310 | 24147 | vcaballero | public void performEditing(Iterator deleteds, Iterator inserteds, Iterator updateds) throws PerformEditingException { |
311 | 23894 | jjdelcerro | |
312 | String fileName = ""; |
||
313 | 28030 | jmvivo | |
314 | 23894 | jjdelcerro | try {
|
315 | resource.begin(); |
||
316 | 28030 | jmvivo | } catch (ResourceBeginException e1) {
|
317 | throw new PerformEditingException(this.getName(), e1); |
||
318 | } |
||
319 | try {
|
||
320 | 23894 | jjdelcerro | |
321 | 28030 | jmvivo | |
322 | 23894 | jjdelcerro | File file = (File) resource.get(); |
323 | fileName = file.getAbsolutePath(); |
||
324 | 25752 | vcaballero | writer = new Writer().initialice(file, projection); |
325 | 23894 | jjdelcerro | FeatureSet features = this.getStoreServices().getFeatureSet();
|
326 | |||
327 | writer.begin(); |
||
328 | 27525 | jmvivo | DisposableIterator it = features.fastIterator(); |
329 | 23894 | jjdelcerro | while (it.hasNext()) {
|
330 | 23996 | jmvivo | writer.add(getFeatureDataFormFeature(it.next())); |
331 | 23894 | jjdelcerro | } |
332 | 27525 | jmvivo | it.dispose(); |
333 | 23894 | jjdelcerro | writer.end(); |
334 | 25789 | jmvivo | resource.notifyChanges(); |
335 | 23894 | jjdelcerro | features.dispose(); |
336 | 24248 | jjdelcerro | counterNewsOIDs = 0;
|
337 | 23894 | jjdelcerro | |
338 | } catch (Exception e) { |
||
339 | throw new PerformEditingException(fileName, e); |
||
340 | } finally {
|
||
341 | resource.end(); |
||
342 | } |
||
343 | } |
||
344 | |||
345 | public class Reader { |
||
346 | private File file; |
||
347 | private String fileName; |
||
348 | private IProjection projection;
|
||
349 | private List types; |
||
350 | 23961 | vcaballero | private LegendBuilder leyendBuilder;
|
351 | 24248 | jjdelcerro | private AbstractMemoryStoreProvider store;
|
352 | 25216 | jmvivo | private Envelope envelope;
|
353 | 23894 | jjdelcerro | |
354 | 24248 | jjdelcerro | public Reader initialice(AbstractMemoryStoreProvider store, File file, |
355 | IProjection projection, |
||
356 | 23961 | vcaballero | LegendBuilder leyendBuilder) { |
357 | 24248 | jjdelcerro | this.store = store;
|
358 | 23894 | jjdelcerro | this.file = file;
|
359 | this.fileName = file.getAbsolutePath();
|
||
360 | this.projection = projection;
|
||
361 | this.leyendBuilder = leyendBuilder;
|
||
362 | return this; |
||
363 | } |
||
364 | |||
365 | 25216 | jmvivo | public Envelope getEnvelope() {
|
366 | return this.envelope; |
||
367 | } |
||
368 | |||
369 | 23894 | jjdelcerro | public void begin(FeatureStoreProviderServices store) { |
370 | |||
371 | EditableFeatureType featureType = store.createFeatureType(); |
||
372 | |||
373 | 25924 | jmvivo | featureType.setHasOID(true);
|
374 | |||
375 | 23894 | jjdelcerro | ID_FIELD_ID = featureType.add("ID", DataTypes.INT)
|
376 | .setDefaultValue(Integer.valueOf(0)) |
||
377 | .getIndex(); |
||
378 | |||
379 | 25924 | jmvivo | EditableFeatureAttributeDescriptor attr = featureType.add( |
380 | "Geometry", DataTypes.GEOMETRY);
|
||
381 | 26717 | jmvivo | attr.setSRS(this.projection);
|
382 | 25924 | jmvivo | attr.setGeometryType(Geometry.TYPES.GEOMETRY); |
383 | ID_FIELD_GEOMETRY = attr.getIndex(); |
||
384 | |||
385 | 24512 | jmvivo | featureType.setDefaultGeometryAttributeName("Geometry");
|
386 | 23894 | jjdelcerro | |
387 | // FIXME: Cual es el size y el valor por defecto para Entity ?
|
||
388 | ID_FIELD_ENTITY = featureType.add("Entity",
|
||
389 | DataTypes.STRING, 100)
|
||
390 | .setDefaultValue("")
|
||
391 | .getIndex(); |
||
392 | |||
393 | // FIXME: Cual es el size de Layer ?
|
||
394 | ID_FIELD_LAYER = featureType.add("Layer",
|
||
395 | DataTypes.STRING, 100)
|
||
396 | .setDefaultValue( |
||
397 | "default").getIndex();
|
||
398 | |||
399 | ID_FIELD_COLOR = featureType.add("Color",
|
||
400 | DataTypes.INT) |
||
401 | .setDefaultValue( |
||
402 | Integer.valueOf(0)).getIndex(); |
||
403 | |||
404 | ID_FIELD_ELEVATION = featureType.add("Elevation",
|
||
405 | DataTypes.DOUBLE) |
||
406 | .setDefaultValue( |
||
407 | Double.valueOf(0)).getIndex(); |
||
408 | |||
409 | ID_FIELD_THICKNESS = featureType.add("Thickness",
|
||
410 | DataTypes.DOUBLE) |
||
411 | .setDefaultValue( |
||
412 | Double.valueOf(0)).getIndex(); |
||
413 | |||
414 | // FIXME: Cual es el size de Text ?
|
||
415 | ID_FIELD_TEXT = featureType.add("Text",
|
||
416 | DataTypes.STRING, 100)
|
||
417 | .setDefaultValue("")
|
||
418 | .getIndex(); |
||
419 | |||
420 | ID_FIELD_HEIGHTTEXT = featureType.add("HeightText",
|
||
421 | DataTypes.DOUBLE).setDefaultValue( |
||
422 | Double.valueOf(10)).getIndex(); |
||
423 | |||
424 | ID_FIELD_ROTATIONTEXT = featureType.add("Rotation",
|
||
425 | DataTypes.DOUBLE).setDefaultValue( |
||
426 | Double.valueOf(0)).getIndex(); |
||
427 | |||
428 | |||
429 | 24512 | jmvivo | |
430 | 23894 | jjdelcerro | // FIXME: Parece que el DXF puede tener mas atributos opcionales.
|
431 | // Habria que ver de pillarlos ?
|
||
432 | |||
433 | types = new ArrayList(); |
||
434 | 24456 | jmvivo | types.add(featureType); |
435 | 23894 | jjdelcerro | |
436 | if (leyendBuilder != null) { |
||
437 | leyendBuilder.begin(); |
||
438 | } |
||
439 | |||
440 | } |
||
441 | |||
442 | public void end() { |
||
443 | if (leyendBuilder != null) { |
||
444 | leyendBuilder.end(); |
||
445 | } |
||
446 | } |
||
447 | |||
448 | public List getTypes() { |
||
449 | return types;
|
||
450 | } |
||
451 | |||
452 | public EditableFeatureType getDefaultType() {
|
||
453 | return (EditableFeatureType) types.get(0); |
||
454 | } |
||
455 | |||
456 | 24512 | jmvivo | private Double toDouble(String value) { |
457 | if (value == null) { |
||
458 | return Double.valueOf(0); |
||
459 | } |
||
460 | return Double.valueOf(value); |
||
461 | } |
||
462 | 23894 | jjdelcerro | |
463 | 24512 | jmvivo | public void load() throws DataException { |
464 | 23894 | jjdelcerro | |
465 | 25927 | jmvivo | this.envelope = null; |
466 | 24512 | jmvivo | |
467 | 23894 | jjdelcerro | DxfFile.EntityFactory featureMaker = new DxfFeatureMaker(projection);
|
468 | DxfFile.VarSettings headerManager = new DxfHeaderManager();
|
||
469 | DxfFile dxfFeatureFile = new DxfFile(projection, file
|
||
470 | .getAbsolutePath(), featureMaker, headerManager); |
||
471 | |||
472 | try {
|
||
473 | dxfFeatureFile.load(); |
||
474 | } catch (Exception e1) { |
||
475 | throw new LoadException(e1, fileName); |
||
476 | } |
||
477 | |||
478 | IObjList.vector features = (IObjList.vector) ((DxfFeatureMaker) featureMaker) |
||
479 | .getObjects(); |
||
480 | String acadVersion = ((DxfHeaderManager) headerManager)
|
||
481 | .getAcadVersion(); |
||
482 | |||
483 | |||
484 | getLogger().info("load: acadVersion = '" + acadVersion + "'"); |
||
485 | |||
486 | 26904 | jpiera | GeometryManager gManager = GeometryLocator.getGeometryManager(); |
487 | 27301 | jmvivo | |
488 | 23894 | jjdelcerro | if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) {
|
489 | // y no est?n todos a 9999
|
||
490 | Feature[] features2D = new Feature[features.size()]; |
||
491 | for (int i = 0; i < features.size(); i++) { |
||
492 | Feature fea = (Feature) features.get(i); |
||
493 | if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
||
494 | Point point = (Point) fea.getGeometry(); |
||
495 | Point point2 = new Point(); |
||
496 | for (int j = 0; j < point.pointNr(); j++) { |
||
497 | point2.add(point.get(j)); |
||
498 | } |
||
499 | point2.setTextPoint(point.isTextPoint()); |
||
500 | fea.setGeometry(point2); |
||
501 | features2D[i] = fea; |
||
502 | |||
503 | } else if (fea.getGeometry() instanceof LineString3D) { |
||
504 | LineString lineString = (LineString) fea.getGeometry(); |
||
505 | LineString lineString2 = new LineString();
|
||
506 | for (int j = 0; j < lineString.pointNr(); j++) { |
||
507 | lineString2.add(lineString.get(j)); |
||
508 | } |
||
509 | fea.setGeometry(lineString2); |
||
510 | features2D[i] = fea; |
||
511 | } else if (fea.getGeometry() instanceof Polygon3D) { |
||
512 | Polygon polygon = (Polygon) fea.getGeometry(); |
||
513 | Polygon polygon2 = new Polygon(); |
||
514 | for (int j = 0; j < polygon.pointNr(); j++) { |
||
515 | polygon2.add(polygon.get(j)); |
||
516 | } |
||
517 | fea.setGeometry(polygon2); |
||
518 | features2D[i] = fea; |
||
519 | } |
||
520 | } |
||
521 | features.clear(); |
||
522 | for (int i = 0; i < features2D.length; i++) { |
||
523 | features.add(features2D[i]); |
||
524 | } |
||
525 | } |
||
526 | |||
527 | 25927 | jmvivo | |
528 | |||
529 | 23894 | jjdelcerro | for (int i = 0; i < features.size(); i++) { |
530 | |||
531 | 24248 | jjdelcerro | FeatureData feature = store.createFeatureData(store |
532 | .getStoreServices().getDefaultFeatureType()); |
||
533 | 23894 | jjdelcerro | |
534 | try {
|
||
535 | Feature fea = (Feature) features.get(i); |
||
536 | |||
537 | 26233 | vcaballero | feature.setOID(new Long(i)); |
538 | 23894 | jjdelcerro | feature.set(ID_FIELD_ID, Integer.valueOf(i));
|
539 | feature.set(ID_FIELD_ENTITY, fea.getProp("dxfEntity"));
|
||
540 | feature.set(ID_FIELD_LAYER, fea.getProp("layer"));
|
||
541 | feature.set(ID_FIELD_COLOR, Integer.valueOf(fea
|
||
542 | .getProp("color")));
|
||
543 | feature.set(ID_FIELD_TEXT, fea.getProp("text"));
|
||
544 | 24512 | jmvivo | feature.set(ID_FIELD_HEIGHTTEXT, toDouble(fea |
545 | 23894 | jjdelcerro | .getProp("textHeight")));
|
546 | 24512 | jmvivo | feature.set(ID_FIELD_ROTATIONTEXT, toDouble(fea |
547 | 23894 | jjdelcerro | .getProp("textRotation")));
|
548 | 24512 | jmvivo | feature.set(ID_FIELD_ELEVATION, toDouble(fea |
549 | 23894 | jjdelcerro | .getProp("elevation")));
|
550 | 24512 | jmvivo | feature.set(ID_FIELD_THICKNESS, toDouble(fea |
551 | 23894 | jjdelcerro | .getProp("thickness")));
|
552 | // FIXME: Abria que pillar el resto de atributos del DXF.
|
||
553 | |||
554 | 24248 | jjdelcerro | store.addFeatureData(feature); |
555 | 23894 | jjdelcerro | |
556 | 23996 | jmvivo | |
557 | 23894 | jjdelcerro | // FIXME: Habia una incongruencia en el codigo ya que al
|
558 | // campo
|
||
559 | // ID_FIELD_GEOMETRY igual le asignaba una geometria que un
|
||
560 | // valor de cadena como 'Point3D', 'Polyline2D' o
|
||
561 | // 'Polyline3D'
|
||
562 | // Faltaria un atributo ID_FIELD_FSHAPE ?
|
||
563 | //
|
||
564 | |||
565 | if (fea.getGeometry() instanceof Point |
||
566 | && !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
|
||
567 | Point point = (Point) fea.getGeometry(); |
||
568 | Point2D pto = new Point2D.Double(); |
||
569 | pto = point.get(0);
|
||
570 | 27301 | jmvivo | |
571 | 26904 | jpiera | org.gvsig.fmap.geom.primitive.Point geom = (org.gvsig.fmap.geom.primitive.Point)gManager.create(TYPES.POINT , SUBTYPES.GEOM2D); |
572 | geom.setX(pto.getX()); |
||
573 | geom.setY(pto.getY()); |
||
574 | 25927 | jmvivo | feature.set(ID_FIELD_GEOMETRY, geom); |
575 | if (this.envelope == null) { |
||
576 | this.envelope = geom.getEnvelope();
|
||
577 | 23894 | jjdelcerro | } else {
|
578 | 25216 | jmvivo | this.envelope.add(geom.getEnvelope());
|
579 | 23894 | jjdelcerro | } |
580 | 25927 | jmvivo | |
581 | if (point.isTextPoint()) {
|
||
582 | /// TODO labeling
|
||
583 | } |
||
584 | 23894 | jjdelcerro | } else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
585 | org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D) fea |
||
586 | .getGeometry(); |
||
587 | Point3D pto = new Point3D();
|
||
588 | pto = point.getPoint3D(0);
|
||
589 | 26904 | jpiera | org.gvsig.fmap.geom.primitive.Point geom = (org.gvsig.fmap.geom.primitive.Point)gManager.create(TYPES.POINT , SUBTYPES.GEOM2DZ); |
590 | geom.setX(pto.getX()); |
||
591 | geom.setY(pto.getY()); |
||
592 | geom.setCoordinateAt(2, pto.getZ());
|
||
593 | 27301 | jmvivo | |
594 | 25927 | jmvivo | feature.set(ID_FIELD_GEOMETRY, geom); |
595 | if (this.envelope == null) { |
||
596 | this.envelope = geom.getEnvelope();
|
||
597 | 23894 | jjdelcerro | } else {
|
598 | 25216 | jmvivo | this.envelope.add(geom.getEnvelope());
|
599 | 23894 | jjdelcerro | } |
600 | 25927 | jmvivo | |
601 | if (point.isTextPoint()) {
|
||
602 | /// TODO labeling
|
||
603 | } |
||
604 | 23894 | jjdelcerro | } else if (fea.getGeometry() instanceof LineString |
605 | && !(fea.getGeometry() instanceof LineString3D)) {
|
||
606 | GeneralPathX genPathX = new GeneralPathX();
|
||
607 | Point2D[] pts = new Point2D[fea.getGeometry().pointNr()]; |
||
608 | for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
||
609 | pts[j] = fea.getGeometry().get(j); |
||
610 | } |
||
611 | genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
||
612 | for (int j = 1; j < pts.length; j++) { |
||
613 | genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
||
614 | } |
||
615 | 26904 | jpiera | Curve geom = (Curve)gManager.create(TYPES.CURVE , SUBTYPES.GEOM2D); |
616 | 27301 | jmvivo | geom.setGeneralPath(genPathX); |
617 | 23894 | jjdelcerro | feature.set(ID_FIELD_GEOMETRY, geom); |
618 | 25927 | jmvivo | if (this.envelope == null) { |
619 | this.envelope = geom.getEnvelope();
|
||
620 | } else {
|
||
621 | this.envelope.add(geom.getEnvelope());
|
||
622 | } |
||
623 | 23894 | jjdelcerro | |
624 | } else if (fea.getGeometry() instanceof LineString3D) { |
||
625 | GeneralPathX genPathX = new GeneralPathX();
|
||
626 | Point3D[] pts = new Point3D[fea.getGeometry().pointNr()]; |
||
627 | for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
||
628 | pts[j] = ((LineString3D) fea.getGeometry()) |
||
629 | .getPoint3D(j); |
||
630 | } |
||
631 | genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
||
632 | for (int j = 1; j < pts.length; j++) { |
||
633 | genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
||
634 | } |
||
635 | double[] elevations = new double[pts.length]; |
||
636 | for (int j = 0; j < pts.length; j++) { |
||
637 | elevations[j] = pts[j].getZ(); |
||
638 | } |
||
639 | 26904 | jpiera | Curve geom = (Curve)gManager.create(TYPES.CURVE , SUBTYPES.GEOM2DZ); |
640 | geom.setGeneralPath(genPathX); |
||
641 | for (int j=0 ; j<elevations.length ; j++){ |
||
642 | geom.setCoordinateAt(j, 2, elevations[j]);
|
||
643 | 27301 | jmvivo | } |
644 | 23894 | jjdelcerro | feature.set(ID_FIELD_GEOMETRY, geom); |
645 | 25927 | jmvivo | if (this.envelope == null) { |
646 | this.envelope = geom.getEnvelope();
|
||
647 | } else {
|
||
648 | this.envelope.add(geom.getEnvelope());
|
||
649 | } |
||
650 | 23894 | jjdelcerro | |
651 | } else if (fea.getGeometry() instanceof Polygon |
||
652 | && !(fea.getGeometry() instanceof Polygon3D)) {
|
||
653 | GeneralPathX genPathX = new GeneralPathX();
|
||
654 | Point2D firstPt = new Point2D.Double(); |
||
655 | firstPt = fea.getGeometry().get(0);
|
||
656 | Point2D[] pts = new Point2D[fea.getGeometry().pointNr() + 1]; |
||
657 | for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
||
658 | pts[j] = fea.getGeometry().get(j); |
||
659 | } |
||
660 | pts[fea.getGeometry().pointNr()] = firstPt; |
||
661 | genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
||
662 | for (int j = 1; j < pts.length; j++) { |
||
663 | genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
||
664 | } |
||
665 | 26904 | jpiera | Surface geom = (Surface)gManager.create(TYPES.SURFACE , SUBTYPES.GEOM2D); |
666 | geom.setGeneralPath(genPathX); |
||
667 | 23894 | jjdelcerro | feature.set(ID_FIELD_GEOMETRY, geom); |
668 | 25927 | jmvivo | if (this.envelope == null) { |
669 | this.envelope = geom.getEnvelope();
|
||
670 | } else {
|
||
671 | this.envelope.add(geom.getEnvelope());
|
||
672 | } |
||
673 | 23894 | jjdelcerro | |
674 | } else if (fea.getGeometry() instanceof Polygon3D) { |
||
675 | GeneralPathX genPathX = new GeneralPathX();
|
||
676 | Point3D firstPt = new Point3D();
|
||
677 | firstPt = ((Polygon3D) fea.getGeometry()).getPoint3D(0);
|
||
678 | Point3D[] pts = new Point3D[fea.getGeometry().pointNr() + 1]; |
||
679 | for (int j = 0; j < fea.getGeometry().pointNr(); j++) { |
||
680 | pts[j] = ((Polygon3D) fea.getGeometry()) |
||
681 | .getPoint3D(j); |
||
682 | } |
||
683 | pts[fea.getGeometry().pointNr()] = firstPt; |
||
684 | genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
||
685 | for (int j = 1; j < pts.length; j++) { |
||
686 | genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
||
687 | } |
||
688 | double[] elevations = new double[pts.length]; |
||
689 | for (int j = 0; j < pts.length; j++) { |
||
690 | elevations[j] = pts[j].getZ(); |
||
691 | } |
||
692 | 26904 | jpiera | Surface geom = (Surface)gManager.create(TYPES.SURFACE , SUBTYPES.GEOM2DZ); |
693 | geom.setGeneralPath(genPathX); |
||
694 | for (int j=0 ; j<elevations.length ; j++){ |
||
695 | geom.setCoordinateAt(j, 2, elevations[j]);
|
||
696 | } |
||
697 | 23894 | jjdelcerro | feature.set(ID_FIELD_GEOMETRY, geom); |
698 | 25927 | jmvivo | if (this.envelope == null) { |
699 | this.envelope = geom.getEnvelope();
|
||
700 | } else {
|
||
701 | this.envelope.add(geom.getEnvelope());
|
||
702 | } |
||
703 | 23894 | jjdelcerro | } else {
|
704 | getLogger().warn( |
||
705 | MessageFormat.format(
|
||
706 | "load: geometry type {1} not supported",
|
||
707 | new Object[] { fea.getGeometry().getClass().getName() } |
||
708 | ) |
||
709 | ); |
||
710 | } |
||
711 | } catch (Exception e) { |
||
712 | throw new LoadException(e, fileName); |
||
713 | } |
||
714 | if (leyendBuilder != null) { |
||
715 | leyendBuilder.process(feature); |
||
716 | } |
||
717 | |||
718 | } |
||
719 | } |
||
720 | |||
721 | } |
||
722 | |||
723 | public class Writer { |
||
724 | private Double DEFAULT_ELEVATION = new Double(0); |
||
725 | |||
726 | private DxfFile.EntityFactory entityMaker;
|
||
727 | |||
728 | private IProjection proj = null; |
||
729 | |||
730 | private int handle = 40; // Revisar porqu? es 40. |
||
731 | |||
732 | private int k = 0; |
||
733 | |||
734 | private boolean dxf3DFile = false; |
||
735 | private String fileName; |
||
736 | |||
737 | public Writer initialice(File file, IProjection projection) { |
||
738 | this.proj = projection;
|
||
739 | this.fileName = file.getAbsolutePath();
|
||
740 | entityMaker = new DxfEntityMaker(proj);
|
||
741 | |||
742 | return this; |
||
743 | } |
||
744 | |||
745 | public void begin() { |
||
746 | entityMaker = new DxfEntityMaker(proj);
|
||
747 | } |
||
748 | |||
749 | public void end() throws WriteException { |
||
750 | try {
|
||
751 | DxfFile dxfFile = new DxfFile(null, fileName, entityMaker); |
||
752 | dxfFile.setCadFlag(true);
|
||
753 | if (dxf3DFile) {
|
||
754 | dxfFile.setDxf3DFlag(true);
|
||
755 | } |
||
756 | dxfFile.save(fileName); |
||
757 | dxfFile.close(); |
||
758 | } catch (Exception e) { |
||
759 | throw new WriteException(fileName, e); |
||
760 | } |
||
761 | } |
||
762 | |||
763 | public void add(FeatureData feature) throws WriteException { |
||
764 | try {
|
||
765 | Geometry geom = feature.getDefaultGeometry(); |
||
766 | 27013 | jpiera | GeometryType type = geom.getGeometryType(); |
767 | 27301 | jmvivo | |
768 | 27013 | jpiera | if ((TYPES.POINT == type.getType()) && (SUBTYPES.GEOM2DZ == type.getSubType())) {
|
769 | 23894 | jjdelcerro | dxf3DFile = true;
|
770 | k = createPoint3D(handle, k, feature); |
||
771 | |||
772 | 27013 | jpiera | } else if ((TYPES.POINT == type.getType()) && (SUBTYPES.GEOM2D == type.getSubType())) { |
773 | 23894 | jjdelcerro | k = createPoint2D(handle, k, feature); |
774 | |||
775 | 27013 | jpiera | } else if ((TYPES.CURVE == type.getType()) && (SUBTYPES.GEOM2DZ == type.getSubType())) { |
776 | 23894 | jjdelcerro | dxf3DFile = true;
|
777 | k = createPolyline3D(handle, k, feature); |
||
778 | |||
779 | 27013 | jpiera | } else if ((TYPES.ARC == type.getType()) && (SUBTYPES.GEOM2D == type.getSubType())) { |
780 | 23894 | jjdelcerro | k = createArc2D(handle, k, feature); |
781 | |||
782 | 27013 | jpiera | } else if ((TYPES.CURVE == type.getType()) && (SUBTYPES.GEOM2D == type.getSubType())) { |
783 | 23894 | jjdelcerro | k = createLwPolyline2D(handle, k, feature, false);
|
784 | |||
785 | 27013 | jpiera | } else if ((TYPES.SURFACE == type.getType()) && (SUBTYPES.GEOM2DZ == type.getSubType())) { |
786 | 23894 | jjdelcerro | dxf3DFile = true;
|
787 | k = createPolyline3D(handle, k, feature); |
||
788 | |||
789 | 27013 | jpiera | } else if ((TYPES.CIRCLE == type.getType()) && (SUBTYPES.GEOM2D == type.getSubType())) { |
790 | 23894 | jjdelcerro | k = createCircle2D(handle, k, feature); |
791 | |||
792 | 27013 | jpiera | } else if ((TYPES.ELLIPSE == type.getType()) && (SUBTYPES.GEOM2D == type.getSubType())) { |
793 | 23894 | jjdelcerro | k = createEllipse2D(handle, k, feature); |
794 | |||
795 | 27013 | jpiera | } else if ((TYPES.SURFACE == type.getType()) && (SUBTYPES.GEOM2D == type.getSubType())) { |
796 | 23894 | jjdelcerro | k = createLwPolyline2D(handle, k, feature, true);
|
797 | |||
798 | } else {
|
||
799 | getLogger().warn( |
||
800 | MessageFormat.format(
|
||
801 | "Geometry '{1}' not yet supported",
|
||
802 | new Object[] {geom.getClass().getName()} |
||
803 | ) |
||
804 | ); |
||
805 | k++; |
||
806 | } |
||
807 | } catch (Exception e) { |
||
808 | throw new WriteException(fileName, e); |
||
809 | } |
||
810 | |||
811 | } |
||
812 | |||
813 | private boolean hasText(FeatureData feature) { |
||
814 | if (feature.isNull(ID_FIELD_TEXT)) {
|
||
815 | return false; |
||
816 | } |
||
817 | if (feature.get(ID_FIELD_TEXT).equals("")) { |
||
818 | return false; |
||
819 | } |
||
820 | return true; |
||
821 | } |
||
822 | |||
823 | private DxfGroupVector updateProperties(FeatureData feature, int k) { |
||
824 | DxfGroupVector polv = new DxfGroupVector();
|
||
825 | |||
826 | String layer = (String) feature.get(ID_FIELD_LAYER); |
||
827 | Integer color = (Integer) feature.get(ID_FIELD_COLOR); |
||
828 | Double thickness = (Double) feature.get(ID_FIELD_THICKNESS); |
||
829 | |||
830 | DxfGroup geometryLayer = new DxfGroup(8, layer); |
||
831 | |||
832 | DxfGroup handleGroup = new DxfGroup();
|
||
833 | handleGroup.setCode(5);
|
||
834 | handleGroup.setData(new Integer(handle + k).toString()); |
||
835 | |||
836 | DxfGroup handleColor = new DxfGroup();
|
||
837 | handleColor.setCode(62);
|
||
838 | handleColor.setData(color); |
||
839 | |||
840 | DxfGroup handleThickness = new DxfGroup();
|
||
841 | handleThickness.setCode(39);
|
||
842 | handleThickness.setData(thickness); |
||
843 | |||
844 | polv.add(geometryLayer); |
||
845 | polv.add(handleGroup); |
||
846 | polv.add(handleColor); |
||
847 | return polv;
|
||
848 | } |
||
849 | |||
850 | private int createPoint2D(int handle, int k, FeatureData feature) |
||
851 | throws Exception { |
||
852 | |||
853 | if (hasText(feature)) {
|
||
854 | return createText2D(handle, k, feature);
|
||
855 | } |
||
856 | 27413 | jpiera | org.gvsig.fmap.geom.primitive.Point point = geomManager.createPoint(0, 0, SUBTYPES.GEOM2D); |
857 | 23894 | jjdelcerro | double[] pointCoords = new double[6]; |
858 | PathIterator pointIt = (feature.getDefaultGeometry())
|
||
859 | .getPathIterator(null);
|
||
860 | while (!pointIt.isDone()) {
|
||
861 | pointIt.currentSegment(pointCoords); |
||
862 | 27413 | jpiera | point = geomManager.createPoint(pointCoords[0], pointCoords[1], SUBTYPES.GEOM2D); |
863 | 23894 | jjdelcerro | pointIt.next(); |
864 | } |
||
865 | Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
||
866 | |||
867 | DxfGroup px = new DxfGroup();
|
||
868 | DxfGroup py = new DxfGroup();
|
||
869 | DxfGroup pz = new DxfGroup();
|
||
870 | px.setCode(10);
|
||
871 | px.setData(new Double(pto.getX())); |
||
872 | py.setCode(20);
|
||
873 | py.setData(new Double(pto.getY())); |
||
874 | pz.setCode(30);
|
||
875 | // FIXME: POINT del DXF tiene cota. Le asigno cero arbitrariamente.
|
||
876 | pz.setData(new Double(0.0)); |
||
877 | DxfGroupVector pv = updateProperties(feature, k); |
||
878 | pv.add(px); |
||
879 | pv.add(py); |
||
880 | pv.add(pz); |
||
881 | entityMaker.createPoint(pv); |
||
882 | k++; |
||
883 | return k;
|
||
884 | } |
||
885 | |||
886 | private int createText2D(int handle, int k, FeatureData feature) |
||
887 | throws Exception { |
||
888 | |||
889 | String text = feature.get(ID_FIELD_TEXT).toString();
|
||
890 | Double heightText = (Double) feature.get(ID_FIELD_HEIGHTTEXT); |
||
891 | Double rotationText = (Double) feature.get(ID_FIELD_ROTATIONTEXT); |
||
892 | |||
893 | DxfGroup handleText = new DxfGroup();
|
||
894 | handleText.setCode(1);
|
||
895 | handleText.setData(text); |
||
896 | |||
897 | DxfGroup handleHeightText = new DxfGroup();
|
||
898 | handleHeightText.setCode(40);
|
||
899 | handleHeightText.setData(heightText); |
||
900 | |||
901 | DxfGroup handleRotationText = new DxfGroup();
|
||
902 | handleRotationText.setCode(50);
|
||
903 | handleRotationText.setData(rotationText); |
||
904 | |||
905 | 27413 | jpiera | org.gvsig.fmap.geom.primitive.Point point = geomManager.createPoint(0, 0, SUBTYPES.GEOM2D); |
906 | 23894 | jjdelcerro | double[] pointCoords = new double[6]; |
907 | PathIterator pointIt = (feature.getDefaultGeometry())
|
||
908 | .getPathIterator(null);
|
||
909 | while (!pointIt.isDone()) {
|
||
910 | pointIt.currentSegment(pointCoords); |
||
911 | 27413 | jpiera | point = geomManager.createPoint(pointCoords[0], pointCoords[1], SUBTYPES.GEOM2D); |
912 | 23894 | jjdelcerro | pointIt.next(); |
913 | } |
||
914 | Point2D pto = new Point2D.Double(point.getX(), point.getY()); |
||
915 | DxfGroup handleGroup = new DxfGroup();
|
||
916 | handleGroup.setCode(5);
|
||
917 | handleGroup.setData(new Integer(handle + k).toString()); |
||
918 | DxfGroup px = new DxfGroup();
|
||
919 | DxfGroup py = new DxfGroup();
|
||
920 | DxfGroup pz = new DxfGroup();
|
||
921 | px.setCode(10);
|
||
922 | px.setData(new Double(pto.getX())); |
||
923 | py.setCode(20);
|
||
924 | py.setData(new Double(pto.getY())); |
||
925 | pz.setCode(30);
|
||
926 | // FIXME: POINT del DXF tiene cota. Le asigno cero arbitrariamente.
|
||
927 | pz.setData(new Double(0.0)); |
||
928 | DxfGroupVector pv = updateProperties(feature, k); |
||
929 | pv.add(handleText); |
||
930 | pv.add(handleHeightText); |
||
931 | pv.add(handleRotationText); |
||
932 | pv.add(handleGroup); |
||
933 | pv.add(px); |
||
934 | pv.add(py); |
||
935 | pv.add(pz); |
||
936 | entityMaker.createText(pv); |
||
937 | k++; |
||
938 | return k;
|
||
939 | } |
||
940 | |||
941 | private int createPoint3D(int handle, int k, FeatureData feature) |
||
942 | throws Exception { |
||
943 | if (hasText(feature)) {
|
||
944 | return createText3D(handle, k, feature);
|
||
945 | } |
||
946 | 27013 | jpiera | org.gvsig.fmap.geom.primitive.Point point = (org.gvsig.fmap.geom.primitive.Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2DZ); |
947 | 23894 | jjdelcerro | double[] pointCoords = new double[6]; |
948 | PathIterator pointIt = (feature.getDefaultGeometry())
|
||
949 | .getPathIterator(null);
|
||
950 | while (!pointIt.isDone()) {
|
||
951 | pointIt.currentSegment(pointCoords); |
||
952 | 27013 | jpiera | point = (org.gvsig.fmap.geom.primitive.Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2DZ); |
953 | point.setCoordinateAt(0, pointCoords[0]); |
||
954 | point.setCoordinateAt(1, pointCoords[1]); |
||
955 | 27301 | jmvivo | point.setCoordinateAt(2, pointCoords[2]); |
956 | 23894 | jjdelcerro | pointIt.next(); |
957 | } |
||
958 | 27013 | jpiera | org.gvsig.fmap.geom.primitive.Point pto = (org.gvsig.fmap.geom.primitive.Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2DZ); |
959 | pto.setCoordinateAt(0, point.getCoordinateAt(0)); |
||
960 | pto.setCoordinateAt(1, point.getCoordinateAt(1)); |
||
961 | 27301 | jmvivo | pto.setCoordinateAt(2, point.getCoordinateAt(2)); |
962 | 23894 | jjdelcerro | DxfGroup px = new DxfGroup();
|
963 | DxfGroup py = new DxfGroup();
|
||
964 | DxfGroup pz = new DxfGroup();
|
||
965 | px.setCode(10);
|
||
966 | px.setData(new Double(pto.getX())); |
||
967 | py.setCode(20);
|
||
968 | py.setData(new Double(pto.getY())); |
||
969 | pz.setCode(30);
|
||
970 | 27013 | jpiera | pz.setData(new Double(pto.getCoordinateAt(2))); |
971 | 27027 | jpiera | double velev = ((org.gvsig.fmap.geom.primitive.Point) feature.getDefaultGeometry())
|
972 | .getCoordinateAt(2);
|
||
973 | 23894 | jjdelcerro | Double elevation = DEFAULT_ELEVATION;
|
974 | 27027 | jpiera | elevation = new Double(velev); |
975 | 23894 | jjdelcerro | DxfGroup handleElevation = new DxfGroup();
|
976 | handleElevation.setCode(38);
|
||
977 | handleElevation.setData(elevation); |
||
978 | |||
979 | DxfGroupVector pv = updateProperties(feature, k); |
||
980 | pv.add(handleElevation); |
||
981 | pv.add(px); |
||
982 | pv.add(py); |
||
983 | pv.add(pz); |
||
984 | entityMaker.createPoint(pv); |
||
985 | k++; |
||
986 | return k;
|
||
987 | } |
||
988 | |||
989 | private int createText3D(int handle, int k, FeatureData feature) |
||
990 | throws Exception { |
||
991 | |||
992 | 27032 | jpiera | double velev = ((org.gvsig.fmap.geom.primitive.Point) feature.getDefaultGeometry())
|
993 | .getCoordinateAt(0);
|
||
994 | 23894 | jjdelcerro | |
995 | 27032 | jpiera | Double elevation = new Double(velev); |
996 | 23894 | jjdelcerro | String text = feature.get(ID_FIELD_TEXT).toString();
|
997 | Double heightText = (Double) feature.get(ID_FIELD_HEIGHTTEXT); |
||
998 | Double rotationText = (Double) feature.get(ID_FIELD_ROTATIONTEXT); |
||
999 | |||
1000 | DxfGroup handleText = new DxfGroup();
|
||
1001 | handleText.setCode(1);
|
||
1002 | handleText.setData(text); |
||
1003 | |||
1004 | DxfGroup handleHeightText = new DxfGroup();
|
||
1005 | handleHeightText.setCode(40);
|
||
1006 | handleHeightText.setData(heightText); |
||
1007 | |||
1008 | DxfGroup handleRotationText = new DxfGroup();
|
||
1009 | handleRotationText.setCode(50);
|
||
1010 | handleRotationText.setData(rotationText); |
||
1011 | |||
1012 | DxfGroup handleElevation = new DxfGroup();
|
||
1013 | handleElevation.setCode(38);
|
||
1014 | handleElevation.setData(elevation); |
||
1015 | |||
1016 | 27301 | jmvivo | org.gvsig.fmap.geom.primitive.Point point = |
1017 | 27013 | jpiera | (org.gvsig.fmap.geom.primitive.Point) (feature |
1018 | 23894 | jjdelcerro | .getDefaultGeometry()).getInternalShape(); |
1019 | |||
1020 | DxfGroup handleGroup = new DxfGroup();
|
||
1021 | handleGroup.setCode(5);
|
||
1022 | handleGroup.setData(new Integer(handle + k).toString()); |
||
1023 | DxfGroup px = new DxfGroup();
|
||
1024 | DxfGroup py = new DxfGroup();
|
||
1025 | DxfGroup pz = new DxfGroup();
|
||
1026 | px.setCode(10);
|
||
1027 | px.setData(new Double(point.getX())); |
||
1028 | py.setCode(20);
|
||
1029 | py.setData(new Double(point.getY())); |
||
1030 | pz.setCode(30);
|
||
1031 | 27013 | jpiera | pz.setData(new Double(point.getCoordinateAt(2))); |
1032 | 23894 | jjdelcerro | DxfGroupVector pv = updateProperties(feature, k); |
1033 | pv.add(handleElevation); |
||
1034 | pv.add(handleText); |
||
1035 | pv.add(handleHeightText); |
||
1036 | pv.add(handleRotationText); |
||
1037 | pv.add(handleGroup); |
||
1038 | pv.add(px); |
||
1039 | pv.add(py); |
||
1040 | pv.add(pz); |
||
1041 | entityMaker.createText(pv); |
||
1042 | k++; |
||
1043 | return k;
|
||
1044 | } |
||
1045 | |||
1046 | private int createLwPolyline2D(int handle, int k, FeatureData feature, |
||
1047 | boolean isPolygon) throws Exception { |
||
1048 | boolean first = true; |
||
1049 | DxfGroupVector polv = updateProperties(feature, k); |
||
1050 | Vector vpoints = new Vector(); |
||
1051 | |||
1052 | DxfGroup polylineFlag = new DxfGroup();
|
||
1053 | polylineFlag.setCode(70);
|
||
1054 | if (isPolygon) {
|
||
1055 | polylineFlag.setData(new Integer(1)); // cerrada |
||
1056 | } else {
|
||
1057 | polylineFlag.setData(new Integer(0)); // abierta |
||
1058 | } |
||
1059 | |||
1060 | PathIterator theIterator = (feature.getDefaultGeometry())
|
||
1061 | .getPathIterator(null, Converter.FLATNESS); // polyLine. |
||
1062 | // getPathIterator
|
||
1063 | // (null,
|
||
1064 | // flatness);
|
||
1065 | |||
1066 | double[] theData = new double[6]; |
||
1067 | while (!theIterator.isDone()) {
|
||
1068 | int theType = theIterator.currentSegment(theData);
|
||
1069 | switch (theType) {
|
||
1070 | case PathIterator.SEG_MOVETO: |
||
1071 | if (!first) {
|
||
1072 | for (int j = 0; j < vpoints.size(); j++) { |
||
1073 | DxfGroup xvertex = new DxfGroup();
|
||
1074 | xvertex.setCode(10);
|
||
1075 | xvertex |
||
1076 | .setData(new Double( |
||
1077 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1078 | 23894 | jjdelcerro | .get(j)).getX())); |
1079 | DxfGroup yvertex = new DxfGroup();
|
||
1080 | yvertex.setCode(20);
|
||
1081 | yvertex |
||
1082 | .setData(new Double( |
||
1083 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1084 | 23894 | jjdelcerro | .get(j)).getY())); |
1085 | polv.add(xvertex); |
||
1086 | polv.add(yvertex); |
||
1087 | } |
||
1088 | |||
1089 | entityMaker.createLwPolyline(polv); |
||
1090 | k++; |
||
1091 | polv = updateProperties(feature, k); |
||
1092 | |||
1093 | } |
||
1094 | first = false;
|
||
1095 | polv.add(polylineFlag); |
||
1096 | vpoints.clear(); |
||
1097 | 27413 | jpiera | vpoints.add(geomManager.createPoint(theData[0], theData[1], SUBTYPES.GEOM2D)); |
1098 | 23894 | jjdelcerro | break;
|
1099 | case PathIterator.SEG_LINETO: |
||
1100 | 27413 | jpiera | vpoints.add(geomManager.createPoint(theData[0], theData[1], SUBTYPES.GEOM2D)); |
1101 | 23894 | jjdelcerro | break;
|
1102 | case PathIterator.SEG_QUADTO: |
||
1103 | break;
|
||
1104 | case PathIterator.SEG_CUBICTO: |
||
1105 | break;
|
||
1106 | case PathIterator.SEG_CLOSE: |
||
1107 | polylineFlag.setData(new Integer(1)); // cerrada |
||
1108 | break;
|
||
1109 | |||
1110 | } |
||
1111 | theIterator.next(); |
||
1112 | } |
||
1113 | |||
1114 | for (int j = 0; j < vpoints.size(); j++) { |
||
1115 | DxfGroup xvertex = new DxfGroup();
|
||
1116 | xvertex.setCode(10);
|
||
1117 | xvertex |
||
1118 | .setData(new Double( |
||
1119 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1120 | 23894 | jjdelcerro | .get(j)).getX())); |
1121 | DxfGroup yvertex = new DxfGroup();
|
||
1122 | yvertex.setCode(20);
|
||
1123 | yvertex |
||
1124 | .setData(new Double( |
||
1125 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1126 | 23894 | jjdelcerro | .get(j)).getY())); |
1127 | polv.add(xvertex); |
||
1128 | polv.add(yvertex); |
||
1129 | } |
||
1130 | |||
1131 | entityMaker.createLwPolyline(polv); |
||
1132 | k++; |
||
1133 | return k;
|
||
1134 | } |
||
1135 | |||
1136 | private int createPolyline3D(int handle, int k, FeatureData feature) |
||
1137 | throws Exception { |
||
1138 | DxfGroupVector polv = updateProperties(feature, k); |
||
1139 | Vector vpoints = new Vector(); |
||
1140 | PathIterator theIterator = (feature.getDefaultGeometry())
|
||
1141 | .getPathIterator(null, Converter.FLATNESS); // polyLine. |
||
1142 | // getPathIterator
|
||
1143 | // (null,
|
||
1144 | // flatness);
|
||
1145 | double[] theData = new double[6]; |
||
1146 | 27032 | jpiera | Curve curve = (Curve) feature.getDefaultGeometry(); |
1147 | double[] velev = new double[curve.getNumVertex()]; |
||
1148 | for (int i=0 ; i<curve.getNumVertex() ; i++){ |
||
1149 | velev[i] = curve.getCoordinateAt(i, 2);
|
||
1150 | 27301 | jmvivo | } |
1151 | |||
1152 | 23894 | jjdelcerro | while (!theIterator.isDone()) {
|
1153 | int theType = theIterator.currentSegment(theData);
|
||
1154 | switch (theType) {
|
||
1155 | case PathIterator.SEG_MOVETO: |
||
1156 | 27413 | jpiera | vpoints.add(geomManager.createPoint(theData[0], theData[1], SUBTYPES.GEOM2D)); |
1157 | 23894 | jjdelcerro | break;
|
1158 | case PathIterator.SEG_LINETO: |
||
1159 | 27413 | jpiera | vpoints.add(geomManager.createPoint(theData[0], theData[1], SUBTYPES.GEOM2D)); |
1160 | 23894 | jjdelcerro | break;
|
1161 | } |
||
1162 | theIterator.next(); |
||
1163 | } |
||
1164 | if (constantElevation(velev)) {
|
||
1165 | DxfGroup polylineFlag = new DxfGroup();
|
||
1166 | polylineFlag.setCode(70);
|
||
1167 | polylineFlag.setData(new Integer(0)); |
||
1168 | polv.add(polylineFlag); |
||
1169 | DxfGroup elevation = new DxfGroup();
|
||
1170 | elevation.setCode(38);
|
||
1171 | elevation.setData(new Double(velev[0])); |
||
1172 | polv.add(elevation); |
||
1173 | for (int j = 0; j < vpoints.size(); j++) { |
||
1174 | DxfGroup xvertex = new DxfGroup();
|
||
1175 | xvertex.setCode(10);
|
||
1176 | xvertex.setData(new Double( |
||
1177 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1178 | 23894 | jjdelcerro | .get(j)).getX())); |
1179 | DxfGroup yvertex = new DxfGroup();
|
||
1180 | yvertex.setCode(20);
|
||
1181 | yvertex.setData(new Double( |
||
1182 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1183 | 23894 | jjdelcerro | .get(j)).getY())); |
1184 | polv.add(xvertex); |
||
1185 | polv.add(yvertex); |
||
1186 | } |
||
1187 | entityMaker.createLwPolyline(polv); |
||
1188 | k++; |
||
1189 | } else {
|
||
1190 | DxfGroup polylineFlag = new DxfGroup();
|
||
1191 | polylineFlag.setCode(70);
|
||
1192 | polylineFlag.setData(new Integer(8)); |
||
1193 | polv.add(polylineFlag); |
||
1194 | DxfGroup xgroup = new DxfGroup();
|
||
1195 | xgroup.setCode(10);
|
||
1196 | xgroup.setData(new Double(0.0)); |
||
1197 | polv.add(xgroup); |
||
1198 | DxfGroup ygroup = new DxfGroup();
|
||
1199 | ygroup.setCode(20);
|
||
1200 | ygroup.setData(new Double(0.0)); |
||
1201 | polv.add(ygroup); |
||
1202 | DxfGroup elevation = new DxfGroup();
|
||
1203 | elevation.setCode(30);
|
||
1204 | elevation.setData(new Double(0.0)); |
||
1205 | polv.add(elevation); |
||
1206 | DxfGroup subclassMarker = new DxfGroup(100, "AcDb3dPolyline"); |
||
1207 | polv.add(subclassMarker); |
||
1208 | entityMaker.createPolyline(polv); |
||
1209 | k++; |
||
1210 | for (int j = 0; j < vpoints.size(); j++) { |
||
1211 | DxfGroupVector verv = new DxfGroupVector();
|
||
1212 | DxfGroup entityType = new DxfGroup(0, "VERTEX"); |
||
1213 | verv.add(entityType); |
||
1214 | DxfGroup generalSubclassMarker = new DxfGroup(100, |
||
1215 | "AcDbEntity");
|
||
1216 | verv.add(generalSubclassMarker); |
||
1217 | DxfGroup layerName = new DxfGroup(8, "default"); |
||
1218 | verv.add(layerName); |
||
1219 | DxfGroup vertexSubclassMarker = new DxfGroup(100, |
||
1220 | "AcDbVertex");
|
||
1221 | verv.add(vertexSubclassMarker); |
||
1222 | DxfGroup xvertex = new DxfGroup();
|
||
1223 | xvertex.setCode(10);
|
||
1224 | xvertex.setData(new Double( |
||
1225 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1226 | 23894 | jjdelcerro | .get(j)).getX())); |
1227 | DxfGroup yvertex = new DxfGroup();
|
||
1228 | yvertex.setCode(20);
|
||
1229 | yvertex.setData(new Double( |
||
1230 | 27024 | jpiera | ((org.gvsig.fmap.geom.primitive.Point) vpoints |
1231 | 23894 | jjdelcerro | .get(j)).getY())); |
1232 | DxfGroup zvertex = new DxfGroup();
|
||
1233 | zvertex.setCode(30);
|
||
1234 | zvertex.setData(new Double(velev[j])); |
||
1235 | verv.add(xvertex); |
||
1236 | verv.add(yvertex); |
||
1237 | verv.add(zvertex); |
||
1238 | entityMaker.addVertex(verv); |
||
1239 | k++; |
||
1240 | } |
||
1241 | DxfGroupVector seqv = new DxfGroupVector();
|
||
1242 | DxfGroup entityType = new DxfGroup(0, "SEQEND"); |
||
1243 | seqv.add(entityType); |
||
1244 | DxfGroup generalSubclassMarker = new DxfGroup(100, "AcDbEntity"); |
||
1245 | seqv.add(generalSubclassMarker); |
||
1246 | DxfGroup layerName = new DxfGroup(8, "default"); |
||
1247 | seqv.add(layerName); |
||
1248 | DxfGroup handleSeqGroup = new DxfGroup();
|
||
1249 | handleSeqGroup.setCode(5);
|
||
1250 | handleSeqGroup.setData(new Integer(handle + k).toString()); |
||
1251 | seqv.add(handleSeqGroup); |
||
1252 | entityMaker.endSeq(); |
||
1253 | k++; |
||
1254 | } |
||
1255 | return k;
|
||
1256 | } |
||
1257 | |||
1258 | private boolean constantElevation(double[] velev) { |
||
1259 | boolean constant = true; |
||
1260 | for (int i = 0; i < velev.length; i++) { |
||
1261 | for (int j = 0; j < velev.length; j++) { |
||
1262 | if (j > i) {
|
||
1263 | if (velev[i] != velev[j]) {
|
||
1264 | constant = false;
|
||
1265 | break;
|
||
1266 | } |
||
1267 | } |
||
1268 | } |
||
1269 | break;
|
||
1270 | } |
||
1271 | return constant;
|
||
1272 | } |
||
1273 | |||
1274 | private int createCircle2D(int handle, int k, FeatureData feature) |
||
1275 | throws Exception { |
||
1276 | DxfGroupVector polv = updateProperties(feature, k); |
||
1277 | DxfGroup circleFlag = new DxfGroup();
|
||
1278 | circleFlag.setCode(100);
|
||
1279 | polv.add(circleFlag); |
||
1280 | |||
1281 | DxfGroup xvertex = new DxfGroup();
|
||
1282 | xvertex.setCode(10);
|
||
1283 | 27013 | jpiera | Circle circle = (Circle) (feature |
1284 | 23894 | jjdelcerro | .getDefaultGeometry()).getInternalShape(); |
1285 | xvertex.setData(new Double(circle.getCenter().getX())); |
||
1286 | DxfGroup yvertex = new DxfGroup();
|
||
1287 | yvertex.setCode(20);
|
||
1288 | yvertex.setData(new Double(circle.getCenter().getY())); |
||
1289 | DxfGroup zvertex = new DxfGroup();
|
||
1290 | zvertex.setCode(30);
|
||
1291 | // TODO: COORDENADA Z. REVISAR ESTO PARA ENTIDADES 3D
|
||
1292 | zvertex.setData(new Double(0)); |
||
1293 | |||
1294 | DxfGroup radius = new DxfGroup();
|
||
1295 | radius.setCode(40);
|
||
1296 | 27013 | jpiera | radius.setData(new Double(circle.getRadious())); |
1297 | 23894 | jjdelcerro | |
1298 | polv.add(xvertex); |
||
1299 | polv.add(yvertex); |
||
1300 | polv.add(zvertex); |
||
1301 | polv.add(radius); |
||
1302 | |||
1303 | entityMaker.createCircle(polv); |
||
1304 | k++; |
||
1305 | return k;
|
||
1306 | } |
||
1307 | |||
1308 | private int createArc2D(int handle, int k, FeatureData feature) |
||
1309 | throws Exception { |
||
1310 | 27013 | jpiera | Arc arc = (Arc) (feature.getDefaultGeometry()) |
1311 | 23894 | jjdelcerro | .getInternalShape(); |
1312 | 27013 | jpiera | org.gvsig.fmap.geom.primitive.Point[] pts = new org.gvsig.fmap.geom.primitive.Point[3]; |
1313 | pts[0] = arc.getInitPoint();
|
||
1314 | pts[1] = arc.getCenterPoint();
|
||
1315 | pts[2] = arc.getEndPoint();
|
||
1316 | org.gvsig.fmap.geom.primitive.Point center = arc.getCenterPoint(); |
||
1317 | GeometryOperationContext ctx = new GeometryOperationContext();
|
||
1318 | ctx.setAttribute("geom", pts[0]); |
||
1319 | 27301 | jmvivo | double radius = ((Double)geomManager.invokeOperation(PointDistance.CODE, center, ctx)).doubleValue(); |
1320 | |||
1321 | 27013 | jpiera | double initAngle = ((Double)geomManager.invokeOperation(PointGetAngle.CODE, center, ctx)).doubleValue(); |
1322 | 23894 | jjdelcerro | initAngle = Math.toDegrees(initAngle);
|
1323 | 27013 | jpiera | ctx.setAttribute("geom", pts[1]); |
1324 | double midAngle = ((Double)geomManager.invokeOperation(PointGetAngle.CODE, center, ctx)).doubleValue(); |
||
1325 | 23894 | jjdelcerro | midAngle = Math.toDegrees(midAngle);
|
1326 | 27013 | jpiera | ctx.setAttribute("geom", pts[2]); |
1327 | double endAngle = ((Double)geomManager.invokeOperation(PointGetAngle.CODE, center, ctx)).doubleValue(); |
||
1328 | 23894 | jjdelcerro | endAngle = Math.toDegrees(endAngle);
|
1329 | |||
1330 | DxfGroup ax = new DxfGroup();
|
||
1331 | DxfGroup ay = new DxfGroup();
|
||
1332 | DxfGroup ac = new DxfGroup();
|
||
1333 | DxfGroup ai = new DxfGroup();
|
||
1334 | DxfGroup ae = new DxfGroup();
|
||
1335 | ax.setCode(10);
|
||
1336 | ax.setData(new Double(center.getX())); |
||
1337 | ay.setCode(20);
|
||
1338 | ay.setData(new Double(center.getY())); |
||
1339 | ac.setCode(40);
|
||
1340 | ac.setData(new Double(radius)); |
||
1341 | ai.setCode(50);
|
||
1342 | ai.setData(new Double(initAngle)); |
||
1343 | ae.setCode(51);
|
||
1344 | ae.setData(new Double(endAngle)); |
||
1345 | DxfGroupVector av = updateProperties(feature, k); |
||
1346 | av.add(ax); |
||
1347 | av.add(ay); |
||
1348 | av.add(ac); |
||
1349 | av.add(ai); |
||
1350 | av.add(ae); |
||
1351 | entityMaker.createArc(av); |
||
1352 | k++; |
||
1353 | return k;
|
||
1354 | } |
||
1355 | |||
1356 | private int createEllipse2D(int handle, int k, FeatureData feature) |
||
1357 | throws Exception { |
||
1358 | 27013 | jpiera | Ellipse ellipse = (Ellipse) (feature |
1359 | 23894 | jjdelcerro | .getDefaultGeometry()).getInternalShape(); |
1360 | |||
1361 | 27013 | jpiera | org.gvsig.fmap.geom.primitive.Point center = (org.gvsig.fmap.geom.primitive.Point)geomManager.create(TYPES.POINT, SUBTYPES.GEOM2D); |
1362 | center.setCoordinateAt(0, (ellipse.getAxis1Start().getX() + ellipse.getAxis1End().getX()) / 2); |
||
1363 | center.setCoordinateAt(1, (ellipse.getAxis1Start().getY() + ellipse.getAxis1End().getY()) / 2); |
||
1364 | 23894 | jjdelcerro | |
1365 | 27013 | jpiera | double mAxisL = ellipse.getAxis2Dist() * 2; |
1366 | GeometryOperationContext ctx = new GeometryOperationContext();
|
||
1367 | ctx.setAttribute("geom", ellipse.getAxis1End());
|
||
1368 | double maAxisL = ((Double)geomManager.invokeOperation(PointDistance.CODE, ellipse.getAxis1Start(), ctx)).doubleValue(); |
||
1369 | 27301 | jmvivo | |
1370 | 27013 | jpiera | Point2D endPointOfMajorAxis = new Point2D.Double(ellipse.getAxis1End().getX(), ellipse.getAxis1End().getY()); |
1371 | 23894 | jjdelcerro | double azimut = Math |
1372 | .atan2(endPointOfMajorAxis.getX() - center.getX(), |
||
1373 | endPointOfMajorAxis.getY() - center.getY()); |
||
1374 | double azimut2 = azimut + Math.PI / 2.0; |
||
1375 | if (azimut2 >= Math.PI * 2) { |
||
1376 | azimut2 = azimut2 - Math.PI * 2; |
||
1377 | } |
||
1378 | Point2D endPointOfMinorAxis = new Point2D.Double(center.getX() |
||
1379 | 27013 | jpiera | + (ellipse.getAxis2Dist() * Math.sin(azimut2)), center.getY()
|
1380 | + (ellipse.getAxis2Dist() * Math.cos(azimut2)));
|
||
1381 | 23894 | jjdelcerro | |
1382 | if (mAxisL >= maAxisL) {
|
||
1383 | // El menor debe ser menor que el mayor. Los cambiamos.
|
||
1384 | double aux = mAxisL;
|
||
1385 | mAxisL = maAxisL; |
||
1386 | maAxisL = aux; |
||
1387 | // Tambi?n cambiamos los puntos finales de los ejes.
|
||
1388 | Point2D pAux = endPointOfMinorAxis;
|
||
1389 | endPointOfMinorAxis = endPointOfMajorAxis; |
||
1390 | endPointOfMajorAxis = pAux; |
||
1391 | } |
||
1392 | double mToMAR = mAxisL / maAxisL;
|
||
1393 | DxfGroup x = new DxfGroup();
|
||
1394 | DxfGroup y = new DxfGroup();
|
||
1395 | DxfGroup xc = new DxfGroup();
|
||
1396 | DxfGroup yc = new DxfGroup();
|
||
1397 | DxfGroup minToMaj = new DxfGroup();
|
||
1398 | x.setCode(10);
|
||
1399 | x.setData(new Double(center.getX())); |
||
1400 | y.setCode(20);
|
||
1401 | y.setData(new Double(center.getY())); |
||
1402 | xc.setCode(11);
|
||
1403 | xc.setData(new Double(endPointOfMajorAxis.getX() - center.getX())); |
||
1404 | yc.setCode(21);
|
||
1405 | yc.setData(new Double(endPointOfMajorAxis.getY() - center.getY())); |
||
1406 | minToMaj.setCode(40);
|
||
1407 | minToMaj.setData(new Double(mToMAR)); |
||
1408 | DxfGroupVector av = updateProperties(feature, k); |
||
1409 | av.add(x); |
||
1410 | av.add(y); |
||
1411 | av.add(xc); |
||
1412 | av.add(yc); |
||
1413 | av.add(minToMaj); |
||
1414 | entityMaker.createEllipse(av); |
||
1415 | k++; |
||
1416 | return k;
|
||
1417 | } |
||
1418 | |||
1419 | } |
||
1420 | |||
1421 | public boolean closeResourceRequested(ResourceProvider resource) { |
||
1422 | return true; |
||
1423 | } |
||
1424 | |||
1425 | 24248 | jjdelcerro | public int getFeatureReferenceOIDType() { |
1426 | 23996 | jmvivo | return DataTypes.LONG;
|
1427 | } |
||
1428 | |||
1429 | 24248 | jjdelcerro | public boolean supportsAppendMode() { |
1430 | return false; |
||
1431 | 23996 | jmvivo | } |
1432 | |||
1433 | 24498 | jmvivo | public void append(org.gvsig.fmap.dal.feature.Feature feature) { |
1434 | 25752 | vcaballero | try {
|
1435 | writer.add(getFeatureDataFormFeature(feature)); |
||
1436 | } catch (WriteException e) {
|
||
1437 | // TODO Auto-generated catch block
|
||
1438 | e.printStackTrace(); |
||
1439 | } |
||
1440 | 24167 | jmvivo | } |
1441 | |||
1442 | public void beginAppend() { |
||
1443 | 25752 | vcaballero | try {
|
1444 | writer = new Writer().initialice((File) resource.get(), projection); |
||
1445 | writer.begin(); |
||
1446 | } catch (AccessResourceException e) {
|
||
1447 | // TODO Auto-generated catch block
|
||
1448 | e.printStackTrace(); |
||
1449 | } |
||
1450 | 24167 | jmvivo | } |
1451 | |||
1452 | public void endAppend() { |
||
1453 | 25752 | vcaballero | try {
|
1454 | resource.notifyOpen(); |
||
1455 | writer.end(); |
||
1456 | resource.notifyClose(); |
||
1457 | counterNewsOIDs = 0;
|
||
1458 | resource.end(); |
||
1459 | } catch (ResourceNotifyOpenException e) {
|
||
1460 | // TODO Auto-generated catch block
|
||
1461 | e.printStackTrace(); |
||
1462 | } catch (ResourceNotifyCloseException e) {
|
||
1463 | // TODO Auto-generated catch block
|
||
1464 | e.printStackTrace(); |
||
1465 | } catch (WriteException e) {
|
||
1466 | // TODO Auto-generated catch block
|
||
1467 | e.printStackTrace(); |
||
1468 | } |
||
1469 | 24167 | jmvivo | } |
1470 | |||
1471 | 28076 | cmartinez | public void saveToState(PersistentState state) throws PersistenceException { |
1472 | 24167 | jmvivo | // TODO Auto-generated method stub
|
1473 | 24248 | jjdelcerro | throw new NotYetImplemented(); |
1474 | 24167 | jmvivo | } |
1475 | |||
1476 | public void setState(PersistentState state) throws PersistenceException { |
||
1477 | // TODO Auto-generated method stub
|
||
1478 | 24248 | jjdelcerro | throw new NotYetImplemented(); |
1479 | 24167 | jmvivo | } |
1480 | |||
1481 | 24248 | jjdelcerro | public Object createNewOID() { |
1482 | 26233 | vcaballero | return new Long(counterNewsOIDs++); |
1483 | 24177 | jmvivo | } |
1484 | |||
1485 | 24512 | jmvivo | protected void initializeFeatureTypes() throws InitializeException { |
1486 | try {
|
||
1487 | this.open();
|
||
1488 | } catch (OpenException e) {
|
||
1489 | throw new InitializeException(this.getName(), e); |
||
1490 | } |
||
1491 | } |
||
1492 | 24248 | jjdelcerro | |
1493 | 25216 | jmvivo | public Envelope getEnvelope() throws DataException { |
1494 | 25924 | jmvivo | this.open();
|
1495 | return (Envelope) this.dynObject.getDynValue("Envelope"); |
||
1496 | 25216 | jmvivo | } |
1497 | 24512 | jmvivo | |
1498 | 25789 | jmvivo | public Iterator getChilds() { |
1499 | // TODO Auto-generated method stub
|
||
1500 | return null; |
||
1501 | } |
||
1502 | 25216 | jmvivo | |
1503 | 25789 | jmvivo | |
1504 | /*
|
||
1505 | * (non-Javadoc)
|
||
1506 | 25927 | jmvivo | *
|
1507 | 25789 | jmvivo | * @see
|
1508 | * org.gvsig.fmap.dal.resource.spi.ResourceConsumer#resourceChanged(org.
|
||
1509 | * gvsig.fmap.dal.resource.spi.ResourceProvider)
|
||
1510 | */
|
||
1511 | public void resourceChanged(ResourceProvider resource) { |
||
1512 | this.store.notifyChange(DataStoreNotification.RESOURCE_CHANGED,
|
||
1513 | resource); |
||
1514 | } |
||
1515 | 25924 | jmvivo | |
1516 | protected static void registerDynClass() { |
||
1517 | DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
||
1518 | DynClass dynClass; |
||
1519 | DynField field; |
||
1520 | if (DYNCLASS == null) { |
||
1521 | dynClass = dynman.add(DYNCLASS_NAME, "DXF File Store");
|
||
1522 | dynClass.extend(dynman.get(FeatureStore.DYNCLASS_NAME)); |
||
1523 | |||
1524 | DYNCLASS = dynClass; |
||
1525 | } |
||
1526 | |||
1527 | } |
||
1528 | 26837 | jmvivo | |
1529 | public Object getSourceId() { |
||
1530 | return this.getParameters().getFile(); |
||
1531 | } |
||
1532 | |||
1533 | 23894 | jjdelcerro | } |