Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_dataFile / src / org / gvsig / data / datastores / vectorial / file / dxf / DXFResource.java @ 22125

History | View | Annotate | Download (30.4 KB)

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   {{Task}}
26
*/
27

    
28
/**
29
 *
30
 */
31
package org.gvsig.data.datastores.vectorial.file.dxf;
32

    
33
import java.awt.Color;
34
import java.awt.geom.Point2D;
35
import java.util.logging.Logger;
36

    
37
import org.cresques.geo.Point2DZ;
38
import org.cresques.io.DxfFile;
39
import org.cresques.px.dxf.DxfFeatureMaker;
40
import org.cresques.px.dxf.DxfHeaderManager;
41
import org.cresques.px.gml.Feature;
42
import org.cresques.px.gml.LineString;
43
import org.cresques.px.gml.LineString3D;
44
import org.cresques.px.gml.Point;
45
import org.cresques.px.gml.Point3D;
46
import org.cresques.px.gml.Polygon;
47
import org.cresques.px.gml.Polygon3D;
48
import org.gvsig.data.DataException;
49
import org.gvsig.data.OpenException;
50
import org.gvsig.data.ReadException;
51
import org.gvsig.data.datastores.vectorial.file.FileMemoryResource;
52
import org.gvsig.data.vectorial.AttributeDescriptor;
53
import org.gvsig.data.vectorial.DefaultFeatureType;
54
import org.gvsig.data.vectorial.FeatureAttributeDescriptor;
55
import org.gvsig.data.vectorial.FeatureType;
56
import org.gvsig.data.vectorial.IsNotAttributeSettingException;
57
import org.gvsig.data.vectorial.IsNotFeatureSettingException;
58
import org.gvsig.data.vectorial.MemoryFeature;
59
import org.gvsig.fmap.geom.Geometry;
60
import org.gvsig.fmap.geom.GeometryFactory;
61
import org.gvsig.fmap.geom.GeometryManager;
62
import org.gvsig.fmap.geom.primitive.Envelope;
63
import org.gvsig.fmap.geom.primitive.GeneralPathX;
64
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
65
import org.gvsig.fmap.mapcontext.rendering.legend.VectorialUniqueValueLegend;
66
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
67
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
68
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
69
import org.gvsig.projection.cts.IProjection;
70
import org.gvsig.projection.px.IObjList;
71

    
72
/**
73
 * @author jmvivo
74
 *
75
 */
76
public class DXFResource extends FileMemoryResource {
77
        protected final static int ID_FIELD_ID = 0;
78

    
79
        protected final static int ID_FIELD_FSHAPE = 1;
80

    
81
        protected final static int ID_FIELD_ENTITY = 2;
82

    
83
        protected final static int ID_FIELD_LAYER = 3;
84

    
85
        protected final static int ID_FIELD_COLOR = 4;
86

    
87
        protected final static int ID_FIELD_ELEVATION = 5;
88

    
89
        protected final static int ID_FIELD_THICKNESS = 6;
90

    
91
        protected final static int ID_FIELD_TEXT = 7;
92

    
93
        protected final static int ID_FIELD_HEIGHTTEXT = 8;
94

    
95
        protected final static int ID_FIELD_ROTATIONTEXT = 9;
96

    
97
        private AttrInTableLabelingStrategy labeling;
98

    
99
        private VectorialUniqueValueLegend defaultLegend;
100

    
101
        private FeatureType featureType;
102

    
103

    
104
        DXFResource(DXFStoreParameters params) {
105
                super(params);
106
        }
107

    
108
        /* (non-Javadoc)
109
         * @see org.gvsig.data.Resource#getName()
110
         */
111
        public String getName() {
112
                return "DXF";
113
        }
114

    
115
         private void initializeFeatureType() {
116
                this.featureType= DXFStore.newFeatureType();
117
         }
118

    
119
         protected FeatureType getFeatureType() throws ReadException{
120
                 this.checkOpen();
121
                 return this.featureType;
122
         }
123

    
124

    
125
        /* (non-Javadoc)
126
         * @see org.gvsig.data.datastores.vectorial.file.FileMemoryResource#getFeature(int)
127
         */
128
        protected org.gvsig.data.vectorial.Feature getFeature(int index) throws ReadException {
129
                return super.getFeature(index);
130
        }
131

    
132
        /* (non-Javadoc)
133
         * @see org.gvsig.data.datastores.vectorial.file.FileMemoryResource#getFeatureCount()
134
         */
135
        protected int getFeatureCount() throws ReadException {
136
                return super.getFeatureCount();
137
        }
138

    
139
        /* (non-Javadoc)
140
         * @see org.gvsig.data.datastores.vectorial.file.FileMemoryResource#getFullExtent()
141
         */
142
        protected Envelope getFullExtent() throws ReadException {
143
                return super.getFullExtent();
144
        }
145

    
146
        /* (non-Javadoc)
147
         * @see org.gvsig.data.datastores.vectorial.file.FileMemoryResource#load()
148
         */
149
        protected void load() throws DataException {
150
                float heightText = 10;
151
                DxfFile dxfFeatureFile;
152
                DxfFile.EntityFactory featureMaker = new DxfFeatureMaker((IProjection)((DXFStoreParameters)this.params).getProjection());
153
                DxfFile.VarSettings headerManager = new DxfHeaderManager();
154
                dxfFeatureFile = new DxfFile(((DXFStoreParameters)this.params).getProjection(), this.getFile().getAbsolutePath(),
155
                                featureMaker, headerManager);
156
                try {
157
                        dxfFeatureFile.load();
158
                } catch (Exception e1) {
159
                        throw new OpenException(description(),e1);
160
                }
161
                IObjList.vector features = (IObjList.vector) ((DxfFeatureMaker) featureMaker)
162
                                .getObjects();
163
                String acadVersion = (String) ((DxfHeaderManager) headerManager)
164
                                .getAcadVersion();
165
                System.out.println("initialize(): acadVersion = " + acadVersion);
166

    
167
                GeometryFactory gFactory = GeometryManager.getInstance().getGeometryFactory();
168

    
169
                if (!featureMaker.isDxf3DFile() && !headerManager.isWritedDxf3D()) { // y no
170
                                                                                                                                                                // est?n
171
                                                                                                                                                                // todos
172
                                                                                                                                                                // a
173
                                                                                                                                                                // 9999
174
                        Feature[] features2D = new Feature[features.size()];
175
                        for (int i = 0; i < features.size(); i++) {
176
                                Feature fea = (Feature) features.get(i);
177
                                if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) {
178
                                        Point point = (Point) fea.getGeometry();
179
                                        Point point2 = new Point();
180
                                        for (int j = 0; j < point.pointNr(); j++) {
181
                                                point2.add(point.get(j));
182
                                        }
183
                                        point2.setTextPoint(point.isTextPoint());
184
                                        fea.setGeometry(point2);
185
                                        features2D[i] = fea;
186
                                        // } else if (fea.getGeometry() instanceof InsPoint3D) {
187
                                        // InsPoint insPoint = (InsPoint)fea.getGeometry();
188
                                        // InsPoint insPoint2 = new InsPoint();
189
                                        // for (int j=0;j<insPoint.pointNr();j++) {
190
                                        // insPoint2.add(insPoint.get(j));
191
                                        // }
192
                                        // fea.setGeometry(insPoint2);
193
                                        // features2D[i] = fea;
194
                                } else if (fea.getGeometry() instanceof LineString3D) {
195
                                        LineString lineString = (LineString) fea.getGeometry();
196
                                        LineString lineString2 = new LineString();
197
                                        for (int j = 0; j < lineString.pointNr(); j++) {
198
                                                lineString2.add(lineString.get(j));
199
                                        }
200
                                        fea.setGeometry(lineString2);
201
                                        features2D[i] = fea;
202
                                } else if (fea.getGeometry() instanceof Polygon3D) {
203
                                        Polygon polygon = (Polygon) fea.getGeometry();
204
                                        Polygon polygon2 = new Polygon();
205
                                        for (int j = 0; j < polygon.pointNr(); j++) {
206
                                                polygon2.add(polygon.get(j));
207
                                        }
208
                                        fea.setGeometry(polygon2);
209
                                        features2D[i] = fea;
210
                                }
211
                        }
212
                        features.clear();
213
                        for (int i = 0; i < features2D.length; i++) {
214
                                features.add(features2D[i]);
215
                        }
216
                }
217
                // String acadVersion =
218
                // (String)((DxfHeaderManager)headerManager).getAcadVersion();
219
                // System.out.println("initialize(): acadVersion = " + acadVersion);
220

    
221
                int nAtt = featureMaker.getAttributes().size();
222

    
223
                // Campos de las MemoryLayer:
224

    
225
//                Object[] auxRow = new Object[10 + nAtt];
226
//                ArrayList arrayFields = new ArrayList();
227
//                arrayFields.add("ID");
228
//                arrayFields.add("FShape");
229
//                arrayFields.add("Entity");
230
//                arrayFields.add("Layer");
231
//                arrayFields.add("Color");
232
//                arrayFields.add("Elevation");
233
//                arrayFields.add("Thickness");
234
//                arrayFields.add("Text");
235
//                arrayFields.add("HeightText");
236
//                arrayFields.add("RotationText");
237
                initializeFeatureType();
238

    
239

    
240

    
241

    
242
                for (int i = 0; i < nAtt; i++) {
243
                        String att[] = new String[2];
244
                        att = (String[]) featureMaker.getAttributes().get(i);
245

    
246
                        AttributeDescriptor descriptorAux = (AttributeDescriptor) ((DefaultFeatureType)featureType).createAttributeDescriptor();
247
                        try {
248
                                descriptorAux.loading();
249
                                descriptorAux.setType(FeatureAttributeDescriptor.TYPE_STRING);
250
                                descriptorAux.setName(att[0]);
251
                                descriptorAux.setDefaultValue("");
252
                                descriptorAux.stopLoading();
253
                        } catch (IsNotAttributeSettingException e) {
254
                                e.printStackTrace();
255
                        }
256
                        featureType.add(descriptorAux);
257

    
258

    
259
//                        arrayFields.add(att[0]);
260
                }
261

    
262
                labeling = new AttrInTableLabelingStrategy();
263
                ((AttrInTableLabelingStrategy) labeling).setTextFieldId(ID_FIELD_TEXT);
264
                ((AttrInTableLabelingStrategy) labeling).setRotationFieldId(ID_FIELD_ROTATIONTEXT);
265
                ((AttrInTableLabelingStrategy) labeling).setHeightFieldId(ID_FIELD_HEIGHTTEXT);
266
                ((AttrInTableLabelingStrategy) labeling).setUnit(1); //MapContext.NAMES[1] (meters)
267

    
268
//                getTableModel().setColumnIdentifiers(arrayFields.toArray());
269

    
270
                for (int i = 0; i < features.size(); i++) {
271

    
272
                        MemoryFeature feature;
273
                        try {
274
                                feature = new DXFFeature(featureType,true);
275
                        } catch (ReadException e1) {
276
                                throw new OpenException(this.description(),e1);
277
                        }
278
//                        auxRow[ID_FIELD_HEIGHTTEXT] = new Double(0.0);
279
//                        auxRow[ID_FIELD_ROTATIONTEXT] = new Double(0.0);
280
//                        auxRow[ID_FIELD_TEXT] = null;
281
                        try{
282
                                feature.loading();
283
                                Feature fea = (Feature) features.get(i);
284
                                if (fea.getGeometry() instanceof Point
285
                                                && !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
286
                                        Point point = (Point) fea.getGeometry();
287
                                        Point2D pto = new Point2D.Double();
288
                                        pto = point.get(0);
289
//                                        FShape nuevoShp;
290
                                        if (point.isTextPoint()) {
291
                                                feature.set(ID_FIELD_ID,i);
292
//                                                auxRow[ID_FIELD_ID] = new Integer(i);
293
//                                                feature.set(ID_FIELD_FSHAPE,"Point2D");
294
//                                                auxRow[ID_FIELD_FSHAPE] = new String("FPoint2D");
295
                                                feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
296
//                                                auxRow[ID_FIELD_ENTITY] = new String(fea.getProp("dxfEntity"));
297
                                                feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
298
//                                                auxRow[ID_FIELD_LAYER] = new String(fea.getProp("layer"));
299
                                                int auxInt = Integer.parseInt(fea.getProp("color"));
300
                                                feature.set(ID_FIELD_COLOR,auxInt);
301
//                                                auxRow[ID_FIELD_COLOR] = new Integer(auxInt);
302
                                                feature.set(ID_FIELD_TEXT,fea.getProp("text"));
303
//                                                auxRow[ID_FIELD_TEXT] = ValueFactory
304
//                                                .createValue(new String(fea.getProp("text")));
305
                                                heightText = Float.parseFloat(fea.getProp("textHeight"));
306
                                                feature.set(ID_FIELD_HEIGHTTEXT,heightText);
307
//                                                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
308
//                                                .createValue(heightText);
309
                                                double auxR = Double.parseDouble(fea
310
                                                                .getProp("textRotation"));
311
                                                feature.set(ID_FIELD_ROTATIONTEXT,auxR);
312
//                                                auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
313
//                                                .createValue(auxR);
314
                                                double auxE = Double.parseDouble(fea.getProp("elevation"));
315
                                                feature.set(ID_FIELD_ELEVATION,auxE);
316
//                                                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
317
                                                double auxT = Double.parseDouble(fea.getProp("thickness"));
318
                                                feature.set(ID_FIELD_THICKNESS,auxT);
319
//                                                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
320
                                                // Attributes
321
                                                for (int j = 0; j < nAtt; j++) {
322
                                                        String[] attributes = new String[2];
323
                                                        attributes = (String[]) featureMaker.getAttributes()
324
                                                        .get(j);
325
                                                        feature.set(10+j,attributes[1]);
326
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
327
//                                                        attributes[1]));
328
                                                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
329
                                                                feature.set(10+j,fea.getProp(attributes[0]));
330
//                                                                auxRow[10 + j] = ValueFactory
331
//                                                                .createValue(new String(fea
332
//                                                                .getProp(attributes[0])));
333
                                                        }
334
                                                }
335
                                                Geometry geom=gFactory.createPoint2D(new org.gvsig.fmap.geom.primitive.Point2D(pto.getX(), pto.getY()));
336
                                                feature.set(ID_FIELD_FSHAPE,geom);
337
//                                                feature.setDefaultGeometry(geom);
338
                                                addFeature(feature);
339

    
340
//                                                addShape(nuevoShp, auxRow);
341
                                        } else {
342
                                                feature.set(ID_FIELD_ID,i);
343
//                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
344
//                                                feature.set(ID_FIELD_FSHAPE,"Point2D");
345
//                                                auxRow[ID_FIELD_FSHAPE] = ValueFactory
346
//                                                .createValue(new String("FPoint2D"));
347
                                                feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
348
//                                                auxRow[ID_FIELD_ENTITY] = ValueFactory
349
//                                                .createValue(new String(fea.getProp("dxfEntity")));
350
                                                feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
351
//                                                auxRow[ID_FIELD_LAYER] = ValueFactory
352
//                                                .createValue(new String(fea.getProp("layer")));
353
                                                int auxInt = Integer.parseInt(fea.getProp("color"));
354
                                                feature.set(ID_FIELD_COLOR,auxInt);
355
//                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
356
                                                double auxE = Double.parseDouble(fea.getProp("elevation"));
357
                                                feature.set(ID_FIELD_ELEVATION,auxE);
358
//                                                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
359
                                                double auxT = Double.parseDouble(fea.getProp("thickness"));
360
                                                feature.set(ID_FIELD_THICKNESS,auxT);
361
//                                                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
362
                                                // Attributes
363
                                                for (int j = 0; j < nAtt; j++) {
364
                                                        String[] attributes = new String[2];
365
                                                        attributes = (String[]) featureMaker.getAttributes()
366
                                                        .get(j);
367
                                                        feature.set(10+j,attributes[1]);
368
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
369
//                                                        attributes[1]));
370
                                                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
371
                                                                feature.set(10+j,fea.getProp(attributes[0]));
372
//                                                                auxRow[10 + j] = ValueFactory
373
//                                                                .createValue(new String(fea
374
//                                                                .getProp(attributes[0])));
375
                                                        }
376
                                                }
377
                                                Geometry geom=gFactory.createPoint2D(new org.gvsig.fmap.geom.primitive.Point2D(pto.getX(), pto.getY()));
378
                                                feature.set(ID_FIELD_FSHAPE,geom);
379
//                                                feature.setDefaultGeometry(geom);
380
                                                addFeature(feature);
381
//                                                addShape(nuevoShp, auxRow);
382
                                        }
383
                                } else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) {
384
                                        org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D) fea
385
                                        .getGeometry();
386
                                        Point2DZ pto = new Point2DZ();
387
                                        pto = ((Point3D) point).getPoint2DZ(0);
388
//                                        FShape nuevoShp;
389
                                        if (point.isTextPoint()) {
390
                                                feature.set(ID_FIELD_ID,i);
391
//                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
392
                                                feature.set(ID_FIELD_FSHAPE,"Point3D");
393
//                                                auxRow[ID_FIELD_FSHAPE] = ValueFactory
394
//                                                .createValue(new String("FPoint3D"));
395
                                                feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
396
//                                                auxRow[ID_FIELD_ENTITY] = ValueFactory
397
//                                                .createValue(new String(fea.getProp("dxfEntity")));
398
                                                feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
399
//                                                auxRow[ID_FIELD_LAYER] = ValueFactory
400
//                                                .createValue(new String(fea.getProp("layer")));
401
                                                int auxInt = Integer.parseInt(fea.getProp("color"));
402
                                                feature.set(ID_FIELD_COLOR,auxInt);
403
//                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
404
                                                feature.set(ID_FIELD_TEXT,fea.getProp("text"));
405
//                                                auxRow[ID_FIELD_TEXT] = ValueFactory
406
//                                                .createValue(new String(fea.getProp("text")));
407
                                                heightText = Float.parseFloat(fea.getProp("textHeight"));
408
                                                feature.set(ID_FIELD_HEIGHTTEXT,heightText);
409
//                                                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory
410
//                                                .createValue(heightText);
411
                                                double auxR = Double.parseDouble(fea
412
                                                                .getProp("textRotation"));
413
                                                feature.set(ID_FIELD_ROTATIONTEXT,auxR);
414
//                                                auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory
415
//                                                .createValue(auxR);
416
                                                double auxE = Double.parseDouble(fea.getProp("elevation"));
417
                                                feature.set(ID_FIELD_ELEVATION,auxE);
418
//                                                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
419
                                                double auxT = Double.parseDouble(fea.getProp("thickness"));
420
                                                feature.set(ID_FIELD_THICKNESS,auxT);
421
//                                                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
422
                                                // Attributes
423
                                                for (int j = 0; j < nAtt; j++) {
424
                                                        String[] attributes = new String[2];
425
                                                        attributes = (String[]) featureMaker.getAttributes()
426
                                                        .get(j);
427
                                                        feature.set(10+j,attributes[1]);
428
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
429
//                                                        attributes[1]));
430
                                                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
431
                                                                feature.set(10+j,fea.getProp(attributes[0]));
432
//                                                                auxRow[10 + j] = ValueFactory
433
//                                                                .createValue(new String(fea
434
//                                                                .getProp(attributes[0])));
435
                                                        }
436
                                                }
437
                                                Geometry geom=gFactory.createPoint3D(pto.getX(), pto.getY(), pto.getZ());
438
                                                feature.set(ID_FIELD_FSHAPE,geom);
439
//                                                feature.setDefaultGeometry(geom);
440
                                                addFeature(feature);
441
//                                                addShape(nuevoShp, auxRow);
442
                                        } else {
443
                                                feature.set(ID_FIELD_ID,i);
444
//                                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
445
                                                feature.set(ID_FIELD_FSHAPE,"Point3D");
446
//                                                auxRow[ID_FIELD_FSHAPE] = ValueFactory
447
//                                                .createValue(new String("FPoint3D"));
448
                                                feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
449
//                                                auxRow[ID_FIELD_ENTITY] = ValueFactory
450
//                                                .createValue(new String(fea.getProp("dxfEntity")));
451
                                                feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
452
//                                                auxRow[ID_FIELD_LAYER] = ValueFactory
453
//                                                .createValue(new String(fea.getProp("layer")));
454
                                                int auxInt = Integer.parseInt(fea.getProp("color"));
455
                                                feature.set(ID_FIELD_COLOR,auxInt);
456
//                                                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
457

    
458
                                                double auxE = Double.parseDouble(fea.getProp("elevation"));
459
                                                feature.set(ID_FIELD_ELEVATION,auxE);
460
//                                                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
461
                                                double auxT = Double.parseDouble(fea.getProp("thickness"));
462
                                                feature.set(ID_FIELD_THICKNESS,auxT);
463
//                                                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
464
                                                // Attributes
465
                                                for (int j = 0; j < nAtt; j++) {
466
                                                        String[] attributes = new String[2];
467
                                                        attributes = (String[]) featureMaker.getAttributes()
468
                                                        .get(j);
469
                                                        feature.set(10+j,attributes[1]);
470
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
471
//                                                        attributes[1]));
472
                                                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
473
                                                                feature.set(10+j,fea.getProp(attributes[0]));
474
//                                                                auxRow[10 + j] = ValueFactory
475
//                                                                .createValue(new String(fea
476
//                                                                .getProp(attributes[0])));
477
                                                        }
478
                                                }
479
                                                Geometry geom=gFactory.createPoint3D(pto.getX(), pto.getY(), pto.getZ());
480
                                                feature.set(ID_FIELD_FSHAPE,geom);
481
//                                                feature.setDefaultGeometry(geom);
482
                                                addFeature(feature);
483
//                                                addShape(nuevoShp, auxRow);
484
                                        }
485
                                } else if (fea.getGeometry() instanceof LineString
486
                                                && !(fea.getGeometry() instanceof LineString3D)) {
487
                                        GeneralPathX genPathX = new GeneralPathX();
488
                                        Point2D[] pts = new Point2D[fea.getGeometry().pointNr()];
489
                                        for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
490
                                                pts[j] = fea.getGeometry().get(j);
491
                                        }
492
                                        genPathX.moveTo(pts[0].getX(), pts[0].getY());
493
                                        for (int j = 1; j < pts.length; j++) {
494
                                                genPathX.lineTo(pts[j].getX(), pts[j].getY());
495
                                        }
496
                                        feature.set(ID_FIELD_ID,i);
497
//                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
498
                                        feature.set(ID_FIELD_FSHAPE,"Polyline2D");
499
//                                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
500
//                                        "FPolyline2D"));
501
                                        feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
502
//                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
503
//                                        fea.getProp("dxfEntity")));
504
                                        feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
505
//                                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
506
//                                        fea.getProp("layer")));
507
                                        int auxInt = Integer.parseInt(fea.getProp("color"));
508
                                        feature.set(ID_FIELD_COLOR,auxInt);
509
//                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
510
                                        double auxE = Double.parseDouble(fea.getProp("elevation"));
511
                                        feature.set(ID_FIELD_ELEVATION,auxE);
512
//                                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
513
                                        double auxT = Double.parseDouble(fea.getProp("thickness"));
514
                                        feature.set(ID_FIELD_THICKNESS,auxT);
515
//                                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
516
                                        // Attributes
517
                                        for (int j = 0; j < nAtt; j++) {
518
                                                String[] attributes = new String[2];
519
                                                attributes = (String[]) featureMaker.getAttributes().get(j);
520
                                                feature.set(10+j,attributes[1]);
521
//                                                auxRow[10 + j] = ValueFactory.createValue(new String(
522
//                                                attributes[1]));
523
                                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
524
                                                        feature.set(10+j,fea.getProp(attributes[0]));
525
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
526
//                                                        fea.getProp(attributes[0])));
527
                                                }
528
                                        }
529
                                        Geometry geom=gFactory.createPolyline2D(genPathX);
530
                                        feature.set(ID_FIELD_FSHAPE,geom);
531
//                                        feature.setDefaultGeometry(geom);
532
                                        addFeature(feature);
533
//                                        addShape(nuevoShp, auxRow);
534
                                } else if (fea.getGeometry() instanceof LineString3D) {
535
                                        GeneralPathX genPathX = new GeneralPathX();
536
                                        Point2DZ[] pts = new Point2DZ[fea.getGeometry().pointNr()];
537
                                        for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
538
                                                pts[j] = ((LineString3D) fea.getGeometry()).getPoint3D(j);
539
                                        }
540
                                        genPathX.moveTo(pts[0].getX(), pts[0].getY());
541
                                        for (int j = 1; j < pts.length; j++) {
542
                                                genPathX.lineTo(pts[j].getX(), pts[j].getY());
543
                                        }
544
                                        double[] elevations = new double[pts.length];
545
                                        for (int j = 0; j < pts.length; j++) {
546
                                                elevations[j] = pts[j].getZ();
547
                                        }
548
                                        feature.set(ID_FIELD_ID,i);
549
//                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
550
                                        feature.set(ID_FIELD_FSHAPE,"Polyline3D");
551
//                                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
552
//                                        "FPolyline3D"));
553
                                        feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
554
//                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
555
//                                        fea.getProp("dxfEntity")));
556
                                        feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
557
//                                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
558
//                                        fea.getProp("layer")));
559
                                        int auxInt = Integer.parseInt(fea.getProp("color"));
560
                                        feature.set(ID_FIELD_COLOR,auxInt);
561
//                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
562
                                        if (fea.getProp("elevation") != null) {
563
                                                double auxE = Double.parseDouble(fea.getProp("elevation"));
564
                                                feature.set(ID_FIELD_ELEVATION,auxE);
565
//                                                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
566
                                        }
567
                                        double auxT = Double.parseDouble(fea.getProp("thickness"));
568
                                        feature.set(ID_FIELD_THICKNESS,auxT);
569
//                                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
570
                                        // Attributes
571
                                        for (int j = 0; j < nAtt; j++) {
572
                                                String[] attributes = new String[2];
573
                                                attributes = (String[]) featureMaker.getAttributes().get(j);
574
                                                feature.set(10+j,attributes[1]);
575
//                                                auxRow[10 + j] = ValueFactory.createValue(new String(
576
//                                                attributes[1]));
577
                                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
578
                                                        feature.set(10+j,fea.getProp(attributes[0]));
579
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
580
//                                                        fea.getProp(attributes[0])));
581
                                                }
582
                                        }
583
                                        Geometry geom=gFactory.createPolyline3D(genPathX,elevations);
584
                                        feature.set(ID_FIELD_FSHAPE,geom);
585
//                                        feature.setDefaultGeometry(geom);
586
                                        addFeature(feature);
587
//                                        addShape(nuevoShp, auxRow);
588
                                } else if (fea.getGeometry() instanceof Polygon
589
                                                && !(fea.getGeometry() instanceof Polygon3D)) {
590
                                        GeneralPathX genPathX = new GeneralPathX();
591
                                        // 050112: A?ado una posici?n m?s para el punto que cierra y
592
                                        // creo el objeto firstPt.
593
                                        Point2D firstPt = new Point2D.Double();
594
                                        firstPt = fea.getGeometry().get(0);
595
                                        Point2D[] pts = new Point2D[fea.getGeometry().pointNr() + 1];
596
                                        for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
597
                                                pts[j] = fea.getGeometry().get(j);
598
                                        }
599
                                        // 050112: A?ado el primer punto al final para cerrar los
600
                                        // pol?gonos.
601
                                        pts[fea.getGeometry().pointNr()] = firstPt;
602
                                        genPathX.moveTo(pts[0].getX(), pts[0].getY());
603
                                        for (int j = 1; j < pts.length; j++) {
604
                                                genPathX.lineTo(pts[j].getX(), pts[j].getY());
605
                                        }
606
                                        feature.set(ID_FIELD_ID,i);
607
//                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
608
                                        feature.set(ID_FIELD_FSHAPE,"Polygon2D");
609
//                                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
610
//                                        "FPolygon2D"));
611
                                        feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
612
//                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
613
//                                        fea.getProp("dxfEntity")));
614
                                        feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
615
//                                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
616
//                                        fea.getProp("layer")));
617
                                        int auxInt = Integer.parseInt(fea.getProp("color"));
618
                                        feature.set(ID_FIELD_COLOR,auxInt);
619
//                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
620
                                        double auxE = Double.parseDouble(fea.getProp("elevation"));
621
                                        feature.set(ID_FIELD_ELEVATION,auxE);
622
//                                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
623
                                        double auxT = Double.parseDouble(fea.getProp("thickness"));
624
                                        feature.set(ID_FIELD_THICKNESS,auxT);
625
//                                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
626
                                        // Attributes
627
                                        for (int j = 0; j < nAtt; j++) {
628
                                                String[] attributes = new String[2];
629
                                                attributes = (String[]) featureMaker.getAttributes().get(j);
630
                                                feature.set(10+j,attributes[1]);
631
//                                                auxRow[10 + j] = ValueFactory.createValue(new String(
632
//                                                attributes[1]));
633
                                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
634
                                                        feature.set(10+j,fea.getProp(attributes[0]));
635
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
636
//                                                        fea.getProp(attributes[0])));
637
                                                }
638
                                        }
639
                                        Geometry geom=gFactory.createPolygon2D(genPathX);
640
                                        feature.set(ID_FIELD_FSHAPE,geom);
641
//                                        feature.setDefaultGeometry(geom);
642
                                        addFeature(feature);
643
//                                        addShape(nuevoShp, auxRow);
644
                                } else if (fea.getGeometry() instanceof Polygon3D) {
645
                                        GeneralPathX genPathX = new GeneralPathX();
646
                                        // 050112: A?ado una posici?n m?s para el punto que cierra y
647
                                        // creo el objeto firstPt.
648
                                        Point2DZ firstPt = new Point2DZ();
649
                                        firstPt = ((Polygon3D) fea.getGeometry()).getPoint2DZ(0);
650
                                        Point2DZ[] pts = new Point2DZ[fea.getGeometry().pointNr() + 1];
651
                                        for (int j = 0; j < fea.getGeometry().pointNr(); j++) {
652
                                                pts[j] = ((Polygon3D) fea.getGeometry()).getPoint2DZ(j);
653
                                        }
654
                                        // 050112: A?ado el primer punto al final para cerrar los
655
                                        // pol?gonos.
656
                                        pts[fea.getGeometry().pointNr()] = firstPt;
657
                                        genPathX.moveTo(pts[0].getX(), pts[0].getY());
658
                                        for (int j = 1; j < pts.length; j++) {
659
                                                genPathX.lineTo(pts[j].getX(), pts[j].getY());
660
                                        }
661
                                        double[] elevations = new double[pts.length];
662
                                        for (int j = 0; j < pts.length; j++) {
663
                                                elevations[j] = pts[j].getZ();
664
                                        }
665
                                        feature.set(ID_FIELD_ID,i);
666
//                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
667
                                        feature.set(ID_FIELD_FSHAPE,"Polygon3D");
668
//                                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String(
669
//                                        "FPolygon3D"));
670
                                        feature.set(ID_FIELD_ENTITY,fea.getProp("dxfEntity"));
671
//                                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(
672
//                                        fea.getProp("dxfEntity")));
673
                                        feature.set(ID_FIELD_LAYER,fea.getProp("layer"));
674
//                                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(
675
//                                        fea.getProp("layer")));
676
                                        int auxInt = Integer.parseInt(fea.getProp("color"));
677
                                        feature.set(ID_FIELD_COLOR,auxInt);
678
//                                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
679
                                        if (fea.getProp("elevation") != null) {
680
                                                double auxE = Double.parseDouble(fea.getProp("elevation"));
681
                                                feature.set(ID_FIELD_ELEVATION,auxE);
682
//                                                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
683
                                        }
684
                                        double auxT = Double.parseDouble(fea.getProp("thickness"));
685
                                        feature.set(ID_FIELD_THICKNESS,auxT);
686
//                                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
687
                                        // Attributes
688
                                        for (int j = 0; j < nAtt; j++) {
689
                                                String[] attributes = new String[2];
690
                                                attributes = (String[]) featureMaker.getAttributes().get(j);
691
                                                feature.set(10+j,attributes[1]);
692
//                                                auxRow[10 + j] = ValueFactory.createValue(new String(
693
//                                                attributes[1]));
694
                                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
695
                                                        feature.set(10+j,fea.getProp(attributes[0]));
696
//                                                        auxRow[10 + j] = ValueFactory.createValue(new String(
697
//                                                        fea.getProp(attributes[0])));
698
                                                }
699
                                        }
700
                                        Geometry geom=gFactory.createPolygon3D(genPathX,elevations);
701
                                        feature.set(ID_FIELD_FSHAPE,geom);
702
//                                        feature.setDefaultGeometry(geom);
703
                                        addFeature(feature);
704
//                                        addShape(nuevoShp, auxRow);
705
                                } else {
706
                                        // System.out.println("Detectado feature desconocido");
707
                                }
708
                                feature.stopLoading();
709
                        }catch (IsNotFeatureSettingException e) {
710
                                e.printStackTrace();
711
                        }
712
                }
713

    
714
                defaultLegend = LegendFactory
715
                                .createVectorialUniqueValueLegend(Geometry.TYPES.AGGREGATE);
716
                defaultLegend.setClassifyingFieldNames(new String[] {"Color"});
717
                defaultLegend.setClassifyingFieldTypes(new String[]{FeatureAttributeDescriptor.TYPE_INT,FeatureAttributeDescriptor.TYPE_STRING,FeatureAttributeDescriptor.TYPE_STRING,FeatureAttributeDescriptor.TYPE_STRING,FeatureAttributeDescriptor.TYPE_INT,FeatureAttributeDescriptor.TYPE_DOUBLE,FeatureAttributeDescriptor.TYPE_DOUBLE});
718

    
719
                Logger.getAnonymousLogger().info("DXFStore: should check if this is a text symbol");
720
                ISymbol myDefaultSymbol = SymbologyFactory.
721
                        createDefaultSymbolByShapeType(Geometry.TYPES.AGGREGATE, Color.BLACK);
722

    
723
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
724

    
725
//                ISymbol theSymbol = null;
726
//
727
//                        for (long j = 0; j < featuresAux.size(); j++) {
728
//                                Feature feat=(Feature)featuresAux.get((int)j);
729
//                                int clave=feat.getInt(ID_FIELD_COLOR);
730
////                                clave = (IntValue) rs.getFieldValue(j, ID_FIELD_COLOR);
731
//                                if (defaultLegend.getSymbolByValue(clave) == null) {
732
//                                        theSymbol = SymbologyFactory.
733
//                                                createDefaultSymbolByShapeType(
734
//                                                                FShape.MULTI,
735
//                                                                AcadColor.getColor(clave.getValue()));
736
//                                        theSymbol.setDescription(clave.toString());
737
//                                        // Asigna los colores de Autocad a los
738
//                                        // bordes
739
//                                        // de los pol?gonos.
740
//                                        if (theSymbol instanceof IFillSymbol) {
741
//                                                ((IFillSymbol) theSymbol).getOutline().setLineColor(AcadColor.getColor(clave
742
//                                                                .getValue()));
743
//
744
//                                        }
745
//                                        defaultLegend.addSymbol(clave, theSymbol);
746
//                                }
747
//                        } // for
748

    
749
        }
750

    
751

    
752

    
753
        /* (non-Javadoc)
754
         * @see org.gvsig.data.datastores.vectorial.file.IFileResource#getTotalFiles()
755
         */
756
        public int getTotalFiles() {
757
                return 1;
758
        }
759

    
760
        /* (non-Javadoc)
761
         * @see org.gvsig.data.datastores.vectorial.file.FileResource#editing()
762
         */
763
        protected void editing() {
764
                super.editing();
765
        }
766

    
767
        /* (non-Javadoc)
768
         * @see org.gvsig.data.datastores.vectorial.file.FileResource#isEditing()
769
         */
770
        protected boolean isEditing() {
771
                return super.isEditing();
772
        }
773

    
774
        /* (non-Javadoc)
775
         * @see org.gvsig.data.datastores.vectorial.file.FileResource#stopEditing()
776
         */
777
        protected void stopEditing() {
778
                super.stopEditing();
779
        }
780

    
781
}
782