Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / fmap / data / feature / file / dxf / DXFResource.java @ 22373

History | View | Annotate | Download (30.9 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.fmap.data.feature.file.dxf;
32

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

    
38
import org.cresques.geo.Point3D;
39
import org.cresques.io.DxfFile;
40
import org.cresques.px.IObjList;
41
import org.cresques.px.dxf.DxfFeatureMaker;
42
import org.cresques.px.dxf.DxfHeaderManager;
43
import org.cresques.px.gml.Feature;
44
import org.cresques.px.gml.LineString;
45
import org.cresques.px.gml.LineString3D;
46
import org.cresques.px.gml.Point;
47
import org.cresques.px.gml.Polygon;
48
import org.cresques.px.gml.Polygon3D;
49
import org.gvsig.fmap.data.DataException;
50
import org.gvsig.fmap.data.OpenException;
51
import org.gvsig.fmap.data.ReadException;
52
import org.gvsig.fmap.data.feature.AttributeDescriptor;
53
import org.gvsig.fmap.data.feature.DefaultFeatureType;
54
import org.gvsig.fmap.data.feature.FeatureAttributeDescriptor;
55
import org.gvsig.fmap.data.feature.FeatureType;
56
import org.gvsig.fmap.data.feature.IsNotAttributeSettingException;
57
import org.gvsig.fmap.data.feature.IsNotFeatureSettingException;
58
import org.gvsig.fmap.data.feature.MemoryFeature;
59
import org.gvsig.fmap.data.feature.file.FileMemoryResource;
60
import org.gvsig.fmap.data.feature.file.dgn.DGNFeature;
61
import org.gvsig.fmap.geom.Geometry;
62
import org.gvsig.fmap.geom.GeometryFactory;
63
import org.gvsig.fmap.geom.GeometryManager;
64
import org.gvsig.fmap.geom.primitive.Envelope;
65
import org.gvsig.fmap.geom.primitive.GeneralPathX;
66
import org.gvsig.fmap.mapcontext.rendering.legend.LegendFactory;
67
import org.gvsig.fmap.mapcontext.rendering.legend.VectorialUniqueValueLegend;
68
import org.gvsig.fmap.mapcontext.rendering.legend.styling.AttrInTableLabelingStrategy;
69
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
70
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
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.fmap.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.fmap.data.feature.file.FileMemoryResource#getFeature(int)
127
         */
128
        protected org.gvsig.fmap.data.feature.Feature getFeature(int index) throws ReadException {
129
                return super.getFeature(index);
130
        }
131

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

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

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

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

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

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

    
224
                // Campos de las MemoryLayer:
225

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

    
240

    
241

    
242

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

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

    
259

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

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

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

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

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

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

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

    
717
                defaultLegend = LegendFactory
718
                                .createVectorialUniqueValueLegend(Geometry.TYPES.GEOMETRY);
719
                defaultLegend.setClassifyingFieldNames(new String[] {"Color"});
720
                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});
721

    
722
                Logger.getAnonymousLogger().info("DXFStore: should check if this is a text symbol");
723
                ISymbol myDefaultSymbol = SymbologyFactory.
724
                        createDefaultSymbolByShapeType(Geometry.TYPES.GEOMETRY, Color.BLACK);
725

    
726
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
727

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

    
754
        private void addDXFFeature(org.gvsig.fmap.data.feature.Feature feature) throws DataException{
755
                this.addFeature(new DXFFeature(feature));
756
        }
757

    
758
        /* (non-Javadoc)
759
         * @see org.gvsig.fmap.data.feature.file.IFileResource#getTotalFiles()
760
         */
761
        public int getTotalFiles() {
762
                return 1;
763
        }
764

    
765
        /* (non-Javadoc)
766
         * @see org.gvsig.fmap.data.feature.file.FileResource#editing()
767
         */
768
        protected void editing() {
769
                super.editing();
770
        }
771

    
772
        /* (non-Javadoc)
773
         * @see org.gvsig.fmap.data.feature.file.FileResource#isEditing()
774
         */
775
        protected boolean isEditing() {
776
                return super.isEditing();
777
        }
778

    
779
        /* (non-Javadoc)
780
         * @see org.gvsig.fmap.data.feature.file.FileResource#stopEditing()
781
         */
782
        protected void stopEditing() {
783
                super.stopEditing();
784
        }
785

    
786
        protected VectorialUniqueValueLegend getDefaultLegend() throws ReadException{
787
                this.checkOpen();
788
                return defaultLegend;
789
        }
790

    
791
        protected AttrInTableLabelingStrategy getDefaultLabelingStrategy()  throws ReadException {
792
                this.checkOpen();
793
                return labeling;
794
        }
795

    
796
}
797