Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / DXFMemoryDriver.java @ 2196

History | View | Annotate | Download (28.9 KB)

1
/*
2
 * @(#)DXFMemoryDriver    29-dic-2004
3
 * 
4
 * @author jmorell (jose.morell@gmail.com)
5
 */
6
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
7
 *
8
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
23
 *
24
 * For more information, contact:
25
 *
26
 *  Generalitat Valenciana
27
 *   Conselleria d'Infraestructures i Transport
28
 *   Av. Blasco Ib??ez, 50
29
 *   46010 VALENCIA
30
 *   SPAIN
31
 *
32
 *      +34 963862235
33
 *   gvsig@gva.es
34
 *      www.gvsig.gva.es
35
 *
36
 *    or
37
 *
38
 *   IVER T.I. S.A
39
 *   Salamanca 50
40
 *   46005 Valencia
41
 *   Spain
42
 *
43
 *   +34 963163400
44
 *   dac@iver.es
45
 */
46
package com.iver.cit.gvsig.fmap.drivers.dxf;
47

    
48
import java.awt.Color;
49
import java.awt.Font;
50
import java.awt.geom.Point2D;
51
import java.io.File;
52
import java.io.IOException;
53
import java.util.ArrayList;
54

    
55
import org.cresques.cts.IProjection;
56
import org.cresques.cts.ProjectionPool;
57
import org.cresques.geo.Point3D;
58
import org.cresques.io.DxfFile;
59
import org.cresques.px.IObjList;
60
import org.cresques.px.dxf.AcadColor;
61
import org.cresques.px.dxf.DxfFeatureMaker;
62
import org.cresques.px.gml.Feature;
63
import org.cresques.px.gml.InsPoint;
64
import org.cresques.px.gml.InsPoint3D;
65
import org.cresques.px.gml.LineString;
66
import org.cresques.px.gml.LineString3D;
67
import org.cresques.px.gml.Point;
68
import org.cresques.px.gml.Polygon;
69
import org.cresques.px.gml.Polygon3D;
70

    
71
import com.hardcode.gdbms.engine.data.driver.DriverException;
72
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
73
import com.hardcode.gdbms.engine.values.IntValue;
74
import com.hardcode.gdbms.engine.values.Value;
75
import com.hardcode.gdbms.engine.values.ValueFactory;
76
import com.iver.cit.gvsig.fmap.core.FPoint2D;
77
import com.iver.cit.gvsig.fmap.core.FPoint3D;
78
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
79
import com.iver.cit.gvsig.fmap.core.FPolygon3D;
80
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
81
import com.iver.cit.gvsig.fmap.core.FPolyline3D;
82
import com.iver.cit.gvsig.fmap.core.FShape;
83
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
84
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
85
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
86
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
87
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver;
88
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
89
import com.iver.cit.gvsig.fmap.rendering.Legend;
90
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
91
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
92

    
93
/**
94
 * @author jmorell (jose.morell@gmail.com)
95
 * @version 29-dic-2004
96
 */
97
public class DXFMemoryDriver extends MemoryDriver implements WithDefaultLegend {
98
        private final int ID_FIELD_ID=0;
99
        private final int ID_FIELD_FSHAPE=1;
100
        private final int ID_FIELD_ENTITY=2;
101
        private final int ID_FIELD_LAYER=3;
102
        private final int ID_FIELD_COLOR=4;
103
        private final int ID_FIELD_ELEVATION=5;
104
        private final int ID_FIELD_THICKNESS=6;
105
        private final int ID_FIELD_TEXT=7;
106
        private final int ID_FIELD_HEIGHTTEXT=8;
107
        private final int ID_FIELD_ROTATIONTEXT=9;
108

    
109
        VectorialUniqueValueLegend defaultLegend;
110
        private String path;
111
        private File m_Fich;
112
        
113
        private DxfFile.EntityFactory featureMaker;
114
        private DxfFile dxfFeatureFile;
115
        private IObjList.vector features;
116
        private DriverAttributes attr = new DriverAttributes();
117
        
118
        /**
119
         * Habilita la utilizaci?n del lector del HEADER del DXF.
120
         */
121
        private DxfFile.VarSettings headerManager;
122

    
123
        /* (non-Javadoc)
124
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
125
         */
126
        public void open(File f) throws IOException {
127
            m_Fich = f;
128
        }
129
        
130
        public void initialize() throws IOException {
131
                float heightText = 10;
132
                
133
                attr.setLoadedInMemory(true);
134
                
135
                IProjection proj = ProjectionPool.get("EPSG:23030");
136
                featureMaker = new DxfFeatureMaker(proj);
137
                dxfFeatureFile = new DxfFile(proj, m_Fich.getAbsolutePath(), featureMaker);
138
                dxfFeatureFile.load();
139
                features = (IObjList.vector)((DxfFeatureMaker)featureMaker).getObjects();
140
                if (!featureMaker.isDxf3DFile()) {
141
                    Feature[] features2D = new Feature[features.size()];
142
                        for (int i=0;i<features.size();i++) {
143
                                Feature fea = (Feature)features.get(i);
144
                                if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) {
145
                                        Point point = (Point)fea.getGeometry();
146
                                        Point point2 = new Point();
147
                                        for (int j=0;j<point.pointNr();j++) {
148
                                            point2.add(point.get(j));
149
                                        }
150
                                        point2.setTextPoint(point.isTextPoint());
151
                                        fea.setGeometry(point2);
152
                                        features2D[i] = fea;
153
                                //} else if (fea.getGeometry() instanceof InsPoint3D) {
154
                                //        InsPoint insPoint = (InsPoint)fea.getGeometry();
155
                                //        InsPoint insPoint2 = new InsPoint();
156
                                //        for (int j=0;j<insPoint.pointNr();j++) {
157
                                //            insPoint2.add(insPoint.get(j));
158
                                //        }
159
                                //        fea.setGeometry(insPoint2);
160
                                //        features2D[i] = fea;
161
                                } else if (fea.getGeometry() instanceof LineString3D) {
162
                                        LineString lineString = (LineString)fea.getGeometry();
163
                                        LineString lineString2 = new LineString();
164
                                        for (int j=0;j<lineString.pointNr();j++) {
165
                                            lineString2.add(lineString.get(j));
166
                                        }
167
                                        fea.setGeometry(lineString2);
168
                                        features2D[i] = fea;
169
                                } else if (fea.getGeometry() instanceof Polygon3D) {
170
                                        Polygon polygon = (Polygon)fea.getGeometry();
171
                                        Polygon polygon2 = new Polygon();
172
                                        for (int j=0;j<polygon.pointNr();j++) {
173
                                            polygon2.add(polygon.get(j));
174
                                        }
175
                                        fea.setGeometry(polygon2);
176
                                        features2D[i] = fea;
177
                                }
178
                        }
179
                    features.clear();
180
                        for (int i=0;i<features2D.length;i++) {
181
                            features.add(features2D[i]);
182
                        }
183
                }
184
                //String acadVersion = (String)((DxfHeaderManager)headerManager).getAcadVersion();
185
                //System.out.println("initialize(): acadVersion = " + acadVersion);
186
                
187
                int nAtt = featureMaker.getAttributes().size();
188
                
189
                // Campos de las MemoryLayer:
190
            Value[] auxRow = new Value[10+nAtt];
191
                ArrayList arrayFields = new ArrayList();
192
                arrayFields.add("ID");
193
                arrayFields.add("FShape");
194
                arrayFields.add("Entity");
195
                arrayFields.add("Layer");
196
                arrayFields.add("Color");
197
                arrayFields.add("Elevation");
198
                arrayFields.add("Thickness");
199
                arrayFields.add("Text");
200
                arrayFields.add("HeightText");
201
                arrayFields.add("RotationText");
202
                for (int i=0;i<nAtt;i++) {
203
                        String att[] = new String[2];
204
                        att = (String[])featureMaker.getAttributes().get(i);
205
                        arrayFields.add(att[0]);
206
                }
207
                
208
            getTableModel().setColumnIdentifiers(arrayFields.toArray());
209
                
210
                for (int i=0;i<features.size();i++) {
211
                        
212
            auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
213
            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
214
            auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
215
                        
216
                        Feature fea = (Feature)features.get(i);
217
                        if (fea.getGeometry() instanceof Point && !(fea.getGeometry() instanceof org.cresques.px.gml.Point3D)) {
218
                            Point point = (Point)fea.getGeometry();
219
                                Point2D pto = new Point2D.Double();
220
                                pto = (Point2D)point.get(0);
221
                                FShape nuevoShp;
222
                if (point.isTextPoint()) {
223
                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
224
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D"));
225
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
226
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
227
                        int auxInt = Integer.parseInt(fea.getProp("color"));
228
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
229
                        auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(fea.getProp("text")));
230
                        heightText = Float.parseFloat(fea.getProp("textHeight"));
231
                        auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
232
                        double auxR = Double.parseDouble(fea.getProp("textRotation"));
233
                        auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(auxR);
234
                        double auxE = Double.parseDouble(fea.getProp("elevation"));
235
                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
236
                        double auxT = Double.parseDouble(fea.getProp("thickness"));
237
                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
238
                        // Attributes
239
                        for (int j=0;j<nAtt;j++) {
240
                                            String[] attributes = new String[2];
241
                                            attributes = (String[])featureMaker.getAttributes().get(j);
242
                                auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
243
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
244
                                        auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
245
                                }
246
                        }
247
                                        nuevoShp = new FPoint2D(pto.getX(),pto.getY());
248
                                        addShape(nuevoShp, auxRow);
249
                } else {
250
                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
251
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D"));
252
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
253
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
254
                        int auxInt = Integer.parseInt(fea.getProp("color"));
255
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
256
                        double auxE = Double.parseDouble(fea.getProp("elevation"));
257
                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
258
                        double auxT = Double.parseDouble(fea.getProp("thickness"));
259
                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
260
                        // Attributes
261
                        for (int j=0;j<nAtt;j++) {
262
                                            String[] attributes = new String[2];
263
                                            attributes = (String[])featureMaker.getAttributes().get(j);
264
                                auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
265
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
266
                                        auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
267
                                }
268
                        }
269
                        nuevoShp = new FPoint2D(pto.getX(),pto.getY());                                
270
                                        addShape(nuevoShp, auxRow);
271
                }
272
                        } else if (fea.getGeometry() instanceof org.cresques.px.gml.Point3D) {
273
                            org.cresques.px.gml.Point3D point = (org.cresques.px.gml.Point3D)fea.getGeometry();
274
                                Point3D pto = new Point3D();
275
                                pto = (Point3D)point.getPoint3D(0);
276
                                FShape nuevoShp;
277
                if (point.isTextPoint()) {
278
                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
279
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D"));
280
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
281
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
282
                        int auxInt = Integer.parseInt(fea.getProp("color"));
283
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
284
                        auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(fea.getProp("text")));
285
                        heightText = Float.parseFloat(fea.getProp("textHeight"));
286
                        auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
287
                        double auxR = Double.parseDouble(fea.getProp("textRotation"));
288
                        auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(auxR);
289
                        double auxE = Double.parseDouble(fea.getProp("elevation"));
290
                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
291
                        double auxT = Double.parseDouble(fea.getProp("thickness"));
292
                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
293
                        // Attributes
294
                        for (int j=0;j<nAtt;j++) {
295
                                            String[] attributes = new String[2];
296
                                            attributes = (String[])featureMaker.getAttributes().get(j);
297
                                auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
298
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
299
                                        auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
300
                                }
301
                        }
302
                                        nuevoShp = new FPoint3D(pto.getX(),pto.getY(),pto.getZ());
303
                                        addShape(nuevoShp, auxRow);
304
                } else {
305
                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
306
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D"));
307
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
308
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
309
                        int auxInt = Integer.parseInt(fea.getProp("color"));
310
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
311
                        double auxE = Double.parseDouble(fea.getProp("elevation"));
312
                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
313
                        double auxT = Double.parseDouble(fea.getProp("thickness"));
314
                        auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
315
                        // Attributes
316
                        for (int j=0;j<nAtt;j++) {
317
                                            String[] attributes = new String[2];
318
                                            attributes = (String[])featureMaker.getAttributes().get(j);
319
                                auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
320
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
321
                                        auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
322
                                }
323
                        }
324
                        nuevoShp = new FPoint3D(pto.getX(),pto.getY(),pto.getZ());                                
325
                                        addShape(nuevoShp, auxRow);
326
                }
327
                        /*} else if (fea.getGeometry() instanceof InsPoint && !(fea.getGeometry() instanceof InsPoint3D)) {
328
                                InsPoint insPoint = (InsPoint)fea.getGeometry();
329
                                Point2D pto = new Point2D.Double();
330
                                pto = (Point2D)insPoint.get(0);
331
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
332
                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("PointZ"));
333
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
334
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
335
                int auxInt = Integer.parseInt(fea.getProp("color"));
336
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
337
                    double auxE = Double.parseDouble(fea.getProp("elevation"));
338
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
339
                    // Attributes
340
                    for (int j=0;j<nAtt;j++) {
341
                                    String[] attributes = new String[2];
342
                                    attributes = (String[])featureMaker.getAttributes().get(j);
343
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
344
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
345
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
346
                        }
347
                    }
348
                                FShape nuevoShp = new FPoint2D(pto.getX(),pto.getY());
349
                                addShape(nuevoShp, auxRow);
350
                        } else if (fea.getGeometry() instanceof InsPoint3D) {
351
                                InsPoint3D insPoint = (InsPoint3D)fea.getGeometry();
352
                                Point3D pto = new Point3D();
353
                                pto = (Point3D)insPoint.getPoint3D(0);
354
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
355
                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("PointZ"));
356
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
357
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
358
                int auxInt = Integer.parseInt(fea.getProp("color"));
359
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
360
                    double auxE = Double.parseDouble(fea.getProp("elevation"));
361
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
362
                    // Attributes
363
                    for (int j=0;j<nAtt;j++) {
364
                                    String[] attributes = new String[2];
365
                                    attributes = (String[])featureMaker.getAttributes().get(j);
366
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
367
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
368
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
369
                        }
370
                    }
371
                                FShape nuevoShp = new FPoint3D(pto.getX(),pto.getY(),pto.getZ());
372
                                addShape(nuevoShp, auxRow);*/
373
                        } else if (fea.getGeometry() instanceof LineString && !(fea.getGeometry() instanceof LineString3D)) {
374
                                GeneralPathX genPathX = new GeneralPathX();
375
                                Point2D[] pts = new Point2D[fea.getGeometry().pointNr()];
376
                                for (int j=0; j<fea.getGeometry().pointNr(); j++) {
377
                                        pts[j] = (Point2D)fea.getGeometry().get(j);
378
                                }
379
                                genPathX.moveTo(pts[0].getX(), pts[0].getY());
380
                                for (int j=1;j<pts.length;j++) {
381
                                        genPathX.lineTo(pts[j].getX(), pts[j].getY());
382
                                }
383
                    //double[] elevations = new double[pts.length];
384
                    //for (int j=0;j<pts.length;j++) {
385
                    //    elevations[j]=pts[j].getZ();
386
                    //}
387
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
388
                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
389
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
390
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
391
                int auxInt = Integer.parseInt(fea.getProp("color"));
392
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
393
                    double auxE = Double.parseDouble(fea.getProp("elevation"));
394
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
395
                    double auxT = Double.parseDouble(fea.getProp("thickness"));
396
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
397
                    // Attributes
398
                    for (int j=0;j<nAtt;j++) {
399
                                    String[] attributes = new String[2];
400
                                    attributes = (String[])featureMaker.getAttributes().get(j);
401
                        auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
402
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
403
                                auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
404
                        }
405
                    }
406
                                FShape nuevoShp = new FPolyline2D(genPathX);
407
                                addShape(nuevoShp, auxRow);
408
                        } else if (fea.getGeometry() instanceof LineString3D) {
409
                                GeneralPathX genPathX = new GeneralPathX();
410
                                Point3D[] pts = new Point3D[fea.getGeometry().pointNr()];
411
                                for (int j=0; j<fea.getGeometry().pointNr(); j++) {
412
                                        pts[j] = ((LineString3D)fea.getGeometry()).getPoint3D(j);
413
                                }
414
                                genPathX.moveTo(pts[0].getX(), pts[0].getY());
415
                                for (int j=1;j<pts.length;j++) {
416
                                        genPathX.lineTo(pts[j].getX(), pts[j].getY());
417
                                }
418
                    double[] elevations = new double[pts.length];
419
                    for (int j=0;j<pts.length;j++) {
420
                        elevations[j]=pts[j].getZ();
421
                    }
422
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
423
                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
424
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
425
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
426
                int auxInt = Integer.parseInt(fea.getProp("color"));
427
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
428
                    if (fea.getProp("elevation")!=null) {
429
                        double auxE = Double.parseDouble(fea.getProp("elevation"));
430
                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
431
                    }
432
                    double auxT = Double.parseDouble(fea.getProp("thickness"));
433
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
434
                    // Attributes
435
                    for (int j=0;j<nAtt;j++) {
436
                                    String[] attributes = new String[2];
437
                                    attributes = (String[])featureMaker.getAttributes().get(j);
438
                        auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
439
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
440
                                auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
441
                        }
442
                    }
443
                                FShape nuevoShp = new FPolyline3D(genPathX, elevations);
444
                                addShape(nuevoShp, auxRow);
445
                        } else if (fea.getGeometry() instanceof Polygon && !(fea.getGeometry() instanceof Polygon3D)) {
446
                                GeneralPathX genPathX = new GeneralPathX();
447
                                // 050112: A?ado una posici?n m?s para el punto que cierra y 
448
                                //                   creo el objeto firstPt.
449
                                Point2D firstPt = new Point2D.Double();
450
                                firstPt = (Point2D)fea.getGeometry().get(0);
451
                                Point2D[] pts = new Point2D[fea.getGeometry().pointNr()+1];
452
                                for (int j=0; j<fea.getGeometry().pointNr(); j++) {
453
                                        pts[j] = (Point2D)fea.getGeometry().get(j);
454
                                }
455
                                // 050112: A?ado el primer punto al final para cerrar los pol?gonos.
456
                                pts[fea.getGeometry().pointNr()] = firstPt;
457
                                genPathX.moveTo(pts[0].getX(), pts[0].getY());
458
                                for (int j=1; j < pts.length; j++) {
459
                                        genPathX.lineTo(pts[j].getX(), pts[j].getY());
460
                                }
461
                    //double[] elevations = new double[pts.length];
462
                    //for (int j=0;j<pts.length;j++) {
463
                    //    elevations[j]=pts[j].getZ();
464
                    //}
465
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
466
                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolygon2D"));
467
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
468
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
469
                int auxInt = Integer.parseInt(fea.getProp("color"));
470
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
471
                    double auxE = Double.parseDouble(fea.getProp("elevation"));
472
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
473
                    double auxT = Double.parseDouble(fea.getProp("thickness"));
474
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
475
                    // Attributes
476
                    for (int j=0;j<nAtt;j++) {
477
                                    String[] attributes = new String[2];
478
                                    attributes = (String[])featureMaker.getAttributes().get(j);
479
                        auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
480
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
481
                                auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
482
                        }
483
                    }
484
                                FShape nuevoShp = new FPolygon2D(genPathX);
485
                                addShape(nuevoShp, auxRow);
486
                        } else if (fea.getGeometry() instanceof Polygon3D) {
487
                                GeneralPathX genPathX = new GeneralPathX();
488
                                // 050112: A?ado una posici?n m?s para el punto que cierra y 
489
                                //                   creo el objeto firstPt.
490
                                Point3D firstPt = new Point3D();
491
                                firstPt = (Point3D)((Polygon3D)fea.getGeometry()).getPoint3D(0);
492
                                Point3D[] pts = new Point3D[fea.getGeometry().pointNr()+1];
493
                                for (int j=0; j<fea.getGeometry().pointNr(); j++) {
494
                                        pts[j] = (Point3D)((Polygon3D)fea.getGeometry()).getPoint3D(j);
495
                                }
496
                                // 050112: A?ado el primer punto al final para cerrar los pol?gonos.
497
                                pts[fea.getGeometry().pointNr()] = firstPt;
498
                                genPathX.moveTo(pts[0].getX(), pts[0].getY());
499
                                for (int j=1; j < pts.length; j++) {
500
                                        genPathX.lineTo(pts[j].getX(), pts[j].getY());
501
                                }
502
                    double[] elevations = new double[pts.length];
503
                    for (int j=0;j<pts.length;j++) {
504
                        elevations[j]=pts[j].getZ();
505
                    }
506
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
507
                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolygon3D"));
508
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String(fea.getProp("dxfEntity")));
509
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String(fea.getProp("layer")));
510
                int auxInt = Integer.parseInt(fea.getProp("color"));
511
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(auxInt);
512
                    if (fea.getProp("elevation")!=null) {
513
                        double auxE = Double.parseDouble(fea.getProp("elevation"));
514
                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(auxE);
515
                    }
516
                    double auxT = Double.parseDouble(fea.getProp("thickness"));
517
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(auxT);
518
                    // Attributes
519
                    for (int j=0;j<nAtt;j++) {
520
                                    String[] attributes = new String[2];
521
                                    attributes = (String[])featureMaker.getAttributes().get(j);
522
                        auxRow[10+j] = ValueFactory.createValue(new String((String)attributes[1]));
523
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
524
                                auxRow[10+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
525
                        }
526
                    }
527
                                FShape nuevoShp = new FPolygon3D(genPathX, elevations);
528
                                addShape(nuevoShp, auxRow);
529
                        } else {
530
                                //System.out.println("Detectado feature desconocido");
531
                        }
532
                }
533
                
534
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
535
                defaultLegend.setFieldName("Color");
536
                defaultLegend.setLabelField("Text");
537
                defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
538
                defaultLegend.getDefaultSymbol().setShapeVisible(false);
539
                defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
540
                defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9));
541
                defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
542
                defaultLegend.getDefaultSymbol().setFontSize(heightText);
543
                defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
544
                defaultLegend.getDefaultSymbol().setSize(3);
545
                defaultLegend.getDefaultSymbol().setSizeInPixels(true);
546
                
547
                defaultLegend.setLabelHeightField("HeightText");
548
                defaultLegend.setLabelRotationField("RotationText");
549
                
550
                ObjectDriver rs = this;
551
                IntValue clave;
552
                FSymbol theSymbol = null;
553
                
554
                try {
555
                    // TODO: Provisional hasta que cambiemos los s?mbolos.
556
                   /*  BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
557
                   Graphics2D big = bi.createGraphics();
558
                   Color color=new Color(0,0,0,0);
559
                   big.setBackground(color);
560
                   big.clearRect(0, 0, 5, 5);
561
                   Paint fillProv = null; 
562
                   Rectangle2D rProv = new Rectangle();
563
                   rProv.setFrame(0, 0,5,5);
564
                   fillProv = new TexturePaint(bi,rProv); */                    
565
                    
566
                        for (long j = 0; j < rs.getRowCount(); j++)
567
                        {
568
                                clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR);
569
                                if (defaultLegend.getSymbolByValue(clave) == null)
570
                                {
571
                                        theSymbol = new FSymbol(getShapeType());
572
                                        theSymbol.setDescription(clave.toString());
573
                                        theSymbol.setColor(AcadColor.getColor(clave.getValue()));
574
                                        // theSymbol.setFill(fillProv);
575
                                        // 050202, jmorell: Asigna los colores de Autocad a los bordes
576
                                        //                                        de los pol?gonos.
577
                                        theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue()));
578
                                        
579
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
580
                                        theSymbol.setSize(3);
581
                                        theSymbol.setSizeInPixels(true);
582
                                        
583
                                        defaultLegend.addSymbol(clave, theSymbol);
584
                                }
585
                        } // for
586
                } catch (DriverException e) {
587
                        e.printStackTrace();
588
                        throw new IOException("Error al poner la leyenda por defecto en el DXF");
589
                }
590
        }
591

    
592
        /* (non-Javadoc)
593
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
594
         */
595
        public boolean accept(File f) {
596
                return f.getName().toUpperCase().endsWith("DXF");
597
        }
598

    
599
        /* (non-Javadoc)
600
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
601
         */
602
        public int getShapeType() {
603
                return FShape.MULTI;
604
        }
605

    
606
        /* (non-Javadoc)
607
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
608
         */
609
        public String getName() {
610
                return "gvSIG DXF Memory Driver";
611
        }
612

    
613
        /* (non-Javadoc)
614
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
615
         */
616
        public Legend getDefaultLegend() {
617
                return defaultLegend;
618
        }
619

    
620
    /* (non-Javadoc)
621
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
622
     */
623
    public DriverAttributes getDriverAttributes() {
624
        return attr;
625
    }
626
 /**
627
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
628
     */
629
    public int[] getPrimaryKeys() throws DriverException {
630
        return null;
631
    }
632

    
633
}