Statistics
| Revision:

root / trunk / extensions / extDwg / src / es / iver / gvsig / drivers / dwg / DwgMemoryDriver.java @ 9304

History | View | Annotate | Download (46.4 KB)

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

    
47
import java.awt.Color;
48
import java.awt.Component;
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 com.hardcode.gdbms.engine.data.DataSourceFactory;
56
import com.hardcode.gdbms.engine.data.driver.DriverException;
57
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
58
import com.hardcode.gdbms.engine.data.edition.DataWare;
59
import com.hardcode.gdbms.engine.values.IntValue;
60
import com.hardcode.gdbms.engine.values.Value;
61
import com.hardcode.gdbms.engine.values.ValueFactory;
62
import com.iver.andami.PluginServices;
63
import com.iver.cit.gvsig.fmap.core.FPoint2D;
64
import com.iver.cit.gvsig.fmap.core.FPoint3D;
65
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
66
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
67
import com.iver.cit.gvsig.fmap.core.FPolyline3D;
68
import com.iver.cit.gvsig.fmap.core.FShape;
69
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
70
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
71
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
72
import com.iver.cit.gvsig.fmap.drivers.AbstractCadMemoryDriver;
73
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
74
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
75
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
76
import com.iver.cit.gvsig.fmap.rendering.Legend;
77
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
78
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
79
import com.iver.cit.javacad.util.AcadColor;
80
import com.iver.cit.javacad.util.GisModelCurveCalculator;
81
import com.iver.cit.jdwglib.dwg.DwgFile;
82
import com.iver.cit.jdwglib.dwg.DwgObject;
83
import com.iver.cit.jdwglib.dwg.DwgVersionNotSupportedException;
84
import com.iver.cit.jdwglib.dwg.objects.DwgArc;
85
import com.iver.cit.jdwglib.dwg.objects.DwgAttdef;
86
import com.iver.cit.jdwglib.dwg.objects.DwgAttrib;
87
import com.iver.cit.jdwglib.dwg.objects.DwgBlock;
88
import com.iver.cit.jdwglib.dwg.objects.DwgBlockControl;
89
import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader;
90
import com.iver.cit.jdwglib.dwg.objects.DwgCircle;
91
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse;
92
import com.iver.cit.jdwglib.dwg.objects.DwgEndblk;
93
import com.iver.cit.jdwglib.dwg.objects.DwgInsert;
94
import com.iver.cit.jdwglib.dwg.objects.DwgLine;
95
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
96
import com.iver.cit.jdwglib.dwg.objects.DwgMText;
97
import com.iver.cit.jdwglib.dwg.objects.DwgPoint;
98
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D;
99
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D;
100
import com.iver.cit.jdwglib.dwg.objects.DwgSolid;
101
import com.iver.cit.jdwglib.dwg.objects.DwgText;
102

    
103
/**
104
 * Driver that allows gvSIG to read files in DWG format
105
 * Using this driver, a gvSIG user can manipulate part of the information contained in
106
 * a DWG file
107
 * This driver load the Dwg file in memory
108
 * This driver uses jdwglib
109
 *
110
 * @author jmorell
111
 */
112
public class DwgMemoryDriver extends AbstractCadMemoryDriver implements VectorialFileDriver, WithDefaultLegend {
113
        
114
        VectorialUniqueValueLegend defaultLegend;
115

    
116
        private File m_Fich;
117

    
118
        private DwgFile dwg;
119
        private ArrayList dwgObjects;
120
        private DriverAttributes attr = new DriverAttributes();
121
        
122
        private boolean isInitialized = false;
123

    
124
        /* (non-Javadoc)
125
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
126
         */
127
        public void open(File f) throws IOException {
128
            m_Fich = f;
129
        }
130

    
131
        /**
132
         * This method load the DWG file in memory.
133
         * First, it will be necessary to create a DwgFile object with the DWG file path
134
         * as the argument.
135
         * Second, the method read of DwgFile allows to read the objects inside the DWG
136
         * file.
137
         * Third, it will be necessary to process some DWG objects like Layers or Polylines
138
         * Fourth, applyExtrusions() can change the location of the DWG objects through the
139
     * extrusion parameters.
140
     * Fifth, the testDwg3D method test if this DWG has elevation informacion.
141
         * Sixth, we can extract the objects contained inside the blocks through the
142
     * blockManagement method.
143
     * And finally, we can read the objects Vector, and convert this objects to the FMap
144
     * object model.
145
         */
146
        public void initialize() throws IOException {
147
                if(isInitialized)
148
                        return;
149
                else
150
                        isInitialized = true;
151
        //System.out.println("Driver actualizado");
152
                float heightText = 10;
153

    
154
                attr.setLoadedInMemory(true);
155

    
156
                dwg = new DwgFile(m_Fich.getAbsolutePath());
157
                long t1 = System.currentTimeMillis();
158
                try {
159
                        dwg.read();
160
                } catch (DwgVersionNotSupportedException e1) {
161
                        String autodeskUrl = "<a href=\"http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151\">"+
162
                                        "http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151</a>";
163
                        /*
164
                        String userText = "<html><p>"+Messages.getText("The_version_of")+" ";
165
                        userText += m_Fich.getName() + " (";
166
                        userText += e1.getDwgVersion() + " ) ";
167
                        userText += Messages.getText("Is_not_supported");
168
                        userText += "<br>";
169
                        userText += Messages.getText("Probe_to_convert") + "<br>";
170
                        userText += Messages.getText("Autodesk_converter") + "<br>";
171
                        userText += " " + autodeskUrl + "<br>";
172
                        userText += "</p></hml>";
173
                         javax.swing.JLabel label = 
174
                                 new  javax.swing.JLabel(userText);
175
                        String dialogTitle = Messages.getText("Not_supported_version");
176
                        javax.swing.JOptionPane.
177
                                showMessageDialog((Component)PluginServices.getMainFrame(),
178
                                                label,
179
                                                dialogTitle,
180
                                                javax.swing.JOptionPane.ERROR_MESSAGE);
181
                        */
182
                        throw new IOException( 
183
                                        formatString(
184
                                                "La version (%s) del fichero DWG '%s' no esta soportada por gvSIG.\n%s\n%s\n%s",
185
                                                new String[] {
186
                                                        e1.getDwgVersion().toString(),
187
                                                        m_Fich.getName(),
188
                                                        Messages.getText("Probe_to_convert"),
189
                                                        Messages.getText("Autodesk_converter"),
190
                                                        autodeskUrl
191
                                                }
192
                                        )
193
                        );
194
                        
195
                }
196
                
197
                long t2 = System.currentTimeMillis();
198
                System.out.println("Tiempo empleado por la librer?a en leer el fichero dwg = " + (t2-t1));
199
                t1 = System.currentTimeMillis();
200
                dwg.initializeLayerTable();
201
        dwg.calculateGisModelDwgPolylines();
202
        dwg.applyExtrusions();
203
                dwg.testDwg3D();
204
                dwg.blockManagement();
205
        t2 = System.currentTimeMillis();
206
                System.out.println("Tiempo empleado por la librer?a en tratar el fichero dwg = " + (t2-t1));
207
                dwgObjects = dwg.getDwgObjects();
208

    
209
                // TODO: Atributos extra de los objectos
210
                //int nAtt = featureMaker.getAttributes().size();
211

    
212
                // Campos de las MemoryLayer:
213
            //Value[] auxRow = new Value[9+nAtt];
214
            Value[] auxRow = new Value[10];
215
                ArrayList arrayFields = new ArrayList();
216
                arrayFields.add("ID");
217
                arrayFields.add("FShape");
218
                arrayFields.add("Entity");
219
                arrayFields.add("Layer");
220
                arrayFields.add("Color");
221
                arrayFields.add("Elevation");
222
                arrayFields.add("Thickness");
223
                arrayFields.add("Text");
224
                arrayFields.add("HeightText");
225
                arrayFields.add("RotationText");
226
                /*for (int i=0;i<nAtt;i++) {
227
                        String att[] = new String[2];
228
                        att = (String[])featureMaker.getAttributes().get(i);
229
                        arrayFields.add(att[0]);
230
                }*/
231

    
232
            getTableModel().setColumnIdentifiers(arrayFields.toArray());
233

    
234
                t1 = System.currentTimeMillis();
235

    
236
            //boolean addingToBlock = false;
237

    
238
                for (int i=0;i<dwgObjects.size();i++) {
239

    
240
            auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
241
            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
242
            auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
243

    
244
                        DwgObject entity = (DwgObject)dwgObjects.get(i);
245
                        if (entity instanceof DwgArc) {// && !addingToBlock) {
246
                                //System.out.println("Encuentra un Arc ...");
247
                                double[] c = ((DwgArc)entity).getCenter();
248
                                Point2D center = new Point2D.Double(c[0], c[1]);
249
                                double radius = ((DwgArc)entity).getRadius();
250
                                double initAngle = Math.toDegrees(((DwgArc)entity).getInitAngle());
251
                                double endAngle = Math.toDegrees(((DwgArc)entity).getEndAngle());
252
                                Point2D[] arc = GisModelCurveCalculator.calculateGisModelArc(center, radius, initAngle, endAngle);
253
                                FPolyline2D arcc;
254
                                if (dwg.isDwg3DFile()) {
255
                                    double[][] arc3D = new double[arc.length][3];
256
                                    for (int j=0;j<arc.length;j++) {
257
                                        arc3D[j][0] = arc[j].getX();
258
                                        arc3D[j][1] = arc[j].getY();
259
                                        arc3D[j][2] = c[2];
260
                                    }
261
                                    arcc = points3DToFPolyline3D(arc3D);
262
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
263
                                } else {
264
                                    arcc = points2DToFPolyline2D(arc);
265
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
266
                                }
267
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
268
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc"));
269
                                String layerName = dwg.getLayerName(entity);
270
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
271
                                int color = entity.getColor();
272
                                int colorByLayer = dwg.getColorByLayer(entity);
273
                                // TODO: if (color==0) color ByBlock
274
                                if (color==256) color = colorByLayer;
275
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
276
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
277
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
278
                    // Attributes
279
                    /*for (int j=0;j<nAtt;j++) {
280
                                    String[] attributes = new String[2];
281
                                    attributes = (String[])featureMaker.getAttributes().get(j);
282
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
283
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
284
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
285
                        }
286
                    }*/
287
                                addShape(arcc, auxRow);
288
                        } else if (entity instanceof DwgEllipse) {// && !addingToBlock) {
289
                                //System.out.println("Encuentra una Ellipse ...");
290
                                double[] c = ((DwgEllipse)entity).getCenter();
291
                Point2D center = new Point2D.Double(c[0], c[1]);
292
                                double[] majorAxisVector = ((DwgEllipse)entity).getMajorAxisVector();
293
                                Point2D mav = new Point2D.Double(majorAxisVector[0], majorAxisVector[1]);
294
                                double axisRatio = ((DwgEllipse)entity).getAxisRatio();
295
                                double initAngle = Math.toDegrees(((DwgEllipse)entity).getInitAngle());
296
                                double endAngle = Math.toDegrees(((DwgEllipse)entity).getEndAngle());
297
                                Point2D[] arc = GisModelCurveCalculator.calculateGisModelEllipse(center, mav, axisRatio, initAngle, endAngle);
298
                                FPolyline2D arcc;
299
                                if (dwg.isDwg3DFile()) {
300
                                    double[][] arc3D = new double[arc.length][3];
301
                                    for (int j=0;j<arc.length;j++) {
302
                                        arc3D[j][0] = arc[j].getX();
303
                                        arc3D[j][1] = arc[j].getY();
304
                                        arc3D[j][2] = c[2];
305
                                    }
306
                                    arcc = points3DToFPolyline3D(arc3D);
307
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
308
                                } else {
309
                                    arcc = points2DToFPolyline2D(arc);
310
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
311
                                }
312
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
313
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Ellipse"));
314
                                String layerName = dwg.getLayerName(entity);
315
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
316
                                int color = entity.getColor();
317
                                int colorByLayer = dwg.getColorByLayer(entity);
318
                                // TODO: if (color==0) color ByBlock
319
                                if (color==256) color = colorByLayer;
320
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
321
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
322
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
323
                    // Attributes
324
                    /*for (int j=0;j<nAtt;j++) {
325
                                    String[] attributes = new String[2];
326
                                    attributes = (String[])featureMaker.getAttributes().get(j);
327
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
328
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
329
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
330
                        }
331
                    }*/
332
                                addShape(arcc, auxRow);
333
                        } else if (entity instanceof DwgCircle) {// && !addingToBlock) {
334
                                //System.out.println("Encuentra un Circle ...");
335
                                double[] c = ((DwgCircle)entity).getCenter();
336
                                Point2D center = new Point2D.Double(c[0], c[1]);
337
                                double radius = ((DwgCircle)entity).getRadius();
338
                                Point2D[] arc = GisModelCurveCalculator.calculateGisModelCircle(center, radius);
339
                                FPolyline2D arcc;
340
                                if (dwg.isDwg3DFile()) {
341
                                    double[][] arc3D = new double[arc.length][3];
342
                                    for (int j=0;j<arc.length;j++) {
343
                                        arc3D[j][0] = arc[j].getX();
344
                                        arc3D[j][1] = arc[j].getY();
345
                                        arc3D[j][2] = c[2];
346
                                    }
347
                                    arcc = points3DToFPolyline3D(arc3D);
348
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
349
                                } else {
350
                                    arcc = points2DToFPolyline2D(arc);
351
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
352
                                }
353
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
354
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle"));
355
                                String layerName = dwg.getLayerName(entity);
356
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
357
                                int color = entity.getColor();
358
                                int colorByLayer = dwg.getColorByLayer(entity);
359
                                //if (color==0) color ByBlock
360
                                if (color==256) color = colorByLayer;
361
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
362
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(c[2]);
363
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
364
                    // Attributes
365
                    /*for (int j=0;j<nAtt;j++) {
366
                                    String[] attributes = new String[2];
367
                                    attributes = (String[])featureMaker.getAttributes().get(j);
368
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
369
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
370
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
371
                        }
372
                    }*/
373
                                addShape(arcc, auxRow);
374
                        } else if (entity instanceof DwgPolyline2D) {// && !addingToBlock) {
375
                                //System.out.println("Encuentra una Polyline2D ...");
376
                                Point2D[] points = ((DwgPolyline2D)entity).getPts();
377
                                double elev = ((DwgPolyline2D)entity).getElevation();
378
                                FPolyline2D pline;
379
                                if (points!=null) {
380
                                        if (dwg.isDwg3DFile()) {
381
                                            double[][] pline3D = new double[points.length][3];
382
                                            for (int j=0;j<points.length;j++) {
383
                                                pline3D[j][0] = points[j].getX();
384
                                                pline3D[j][1] = points[j].getY();
385
                                                pline3D[j][2] = elev;
386
                                            }
387
                                            pline = points3DToFPolyline3D(pline3D);
388
                                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
389
                                        } else {
390
                                            pline = points2DToFPolyline2D(points);
391
                                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
392
                                        }
393
                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
394
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D"));
395
                                        String layerName = dwg.getLayerName(entity);
396
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
397
                                        int color = entity.getColor();
398
                                        int colorByLayer = dwg.getColorByLayer(entity);
399
                                        //if (color==0) color ByBlock
400
                                        if (color==256) color = colorByLayer;
401
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
402
                            auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev);
403
                            auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
404
                            // Attributes
405
                            /*for (int j=0;j<nAtt;j++) {
406
                                            String[] attributes = new String[2];
407
                                            attributes = (String[])featureMaker.getAttributes().get(j);
408
                                auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
409
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
410
                                        auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
411
                                }
412
                            }*/
413
                            addShape(pline, auxRow);
414
                                }
415
                        } else if (entity instanceof DwgPolyline3D) {// && !addingToBlock) {
416
                                //System.out.println("Encuentra una Polyline3D ...");
417
                                double[][] points3D = ((DwgPolyline3D)entity).getPts();
418
                                FPolyline2D pline;
419
                                if (points3D!=null) {
420
                                        if (dwg.isDwg3DFile()) {
421
                                            double[][] pline3D = new double[points3D.length][3];
422
                                            pline = points3DToFPolyline3D(points3D);
423
                                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
424
                                        } else {
425
                                                Point2D[] points2D = new Point2D[points3D.length];
426
                                            for (int j=0;j<points3D.length;j++) {
427
                                                points2D[j] = new Point2D.Double(points3D[j][0], points3D[j][1]);
428
                                            }
429
                                            pline = points2DToFPolyline2D(points2D);
430
                                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
431
                                        }
432
                                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
433
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline3D"));
434
                                        String layerName = dwg.getLayerName(entity);
435
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
436
                                        int color = entity.getColor();
437
                                        int colorByLayer = dwg.getColorByLayer(entity);
438
                                        //if (color==0) color ByBlock
439
                                        if (color==256) color = colorByLayer;
440
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
441
                        boolean constantElevation = true;
442
                        for (int j=0;j<points3D.length;j++) {
443
                            if (points3D[j][2]!=points3D[0][2]) {
444
                                constantElevation = false;
445
                                break;
446
                            }
447
                        }
448
                            if (constantElevation) auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(points3D[0][2]);
449
                            else auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
450
                            auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
451
                            // Attributes
452
                            /*for (int j=0;j<nAtt;j++) {
453
                                            String[] attributes = new String[2];
454
                                            attributes = (String[])featureMaker.getAttributes().get(j);
455
                                auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
456
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
457
                                        auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
458
                                }
459
                            }*/
460
                            addShape(pline, auxRow);
461
                                }
462
                        } else if (entity instanceof DwgLwPolyline) {// && !addingToBlock) {
463
                                //System.out.println("Encuentra una Lwpolyline ...");
464
                                Point2D[] pts = ((DwgLwPolyline)entity).getVertices();
465
                                double elev = ((DwgLwPolyline)entity).getElevation();
466
                                if (pts!=null) {
467
                                        FPolyline2D lwpline;
468
                                        if (dwg.isDwg3DFile()) {
469
                                            double[][] pline3D = new double[pts.length][3];
470
                                            for (int j=0;j<pts.length;j++) {
471
                                                pline3D[j][0] = pts[j].getX();
472
                                                pline3D[j][1] = pts[j].getY();
473
                                                pline3D[j][2] = elev;
474
                                            }
475
                                            lwpline = points3DToFPolyline3D(pline3D);
476
                                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
477
                                        } else {
478
                                            lwpline = points2DToFPolyline2D(pts);
479
                                auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
480
                                        }
481
                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
482
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("LwPolyline"));
483
                                        String layerName = dwg.getLayerName(entity);
484
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
485
                                        int color = entity.getColor();
486
                                        int colorByLayer = dwg.getColorByLayer(entity);
487
                                        //if (color==0) color ByBlock
488
                                        if (color==256) color = colorByLayer;
489
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
490
                            auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev);
491
                            auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
492
                            // Attributes
493
                            /*for (int j=0;j<nAtt;j++) {
494
                                            String[] attributes = new String[2];
495
                                            attributes = (String[])featureMaker.getAttributes().get(j);
496
                                auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
497
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
498
                                        auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
499
                                }
500
                            }*/
501
                                        addShape(lwpline, auxRow);
502
                                }
503
                        } else if (entity instanceof DwgSolid) {// && !addingToBlock) {
504
                                //System.out.println("Encuentra un Solid ...");
505
                                double[] p1 = ((DwgSolid)entity).getCorner1();
506
                                double[] p2 = ((DwgSolid)entity).getCorner2();
507
                                double[] p3 = ((DwgSolid)entity).getCorner3();
508
                                double[] p4 = ((DwgSolid)entity).getCorner4();
509
                                double elev = ((DwgSolid)entity).getElevation();
510
                                Point2D[] pts = new Point2D[]{new Point2D.Double(p1[0], p1[1]), new Point2D.Double(p2[0], p2[1]), new Point2D.Double(p4[0], p4[1]), new Point2D.Double(p3[0], p3[1]), new Point2D.Double(p1[0], p1[1])};
511
                                FPolyline2D solid;
512
                                if (dwg.isDwg3DFile()) {
513
                                    double[][] pline3D = new double[pts.length][3];
514
                                    for (int j=0;j<pts.length;j++) {
515
                                        pline3D[j][0] = pts[j].getX();
516
                                        pline3D[j][1] = pts[j].getY();
517
                                        pline3D[j][2] = elev;
518
                                    }
519
                                    solid = points3DToFPolyline3D(pline3D);
520
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
521
                                } else {
522
                                    solid = points2DToFPolyline2D(pts);
523
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
524
                                }
525
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
526
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Solid"));
527
                                String layerName = dwg.getLayerName(entity);
528
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
529
                                int color = entity.getColor();
530
                                int colorByLayer = dwg.getColorByLayer(entity);
531
                                //if (color==0) color ByBlock
532
                                if (color==256) color = colorByLayer;
533
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
534
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev);
535
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
536
                    // Attributes
537
                    /*for (int j=0;j<nAtt;j++) {
538
                                    String[] attributes = new String[2];
539
                                    attributes = (String[])featureMaker.getAttributes().get(j);
540
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
541
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
542
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
543
                        }
544
                    }*/
545
                                addShape(solid, auxRow);
546
                        } else if (entity instanceof DwgLine) {// && !addingToBlock) {
547
                                //System.out.println("Encuentra una Line ...");
548
                                double[] p1 = ((DwgLine)entity).getP1();
549
                                Point2D point1 = new Point2D.Double(p1[0], p1[1]);
550
                                double[] p2 = ((DwgLine)entity).getP2();
551
                                Point2D point2 = new Point2D.Double(p2[0], p2[1]);
552
                                Point2D[] lin = new Point2D[]{point1, point2};
553
                                FPolyline2D line;
554
                                if (dwg.isDwg3DFile() && ((DwgLine)entity).isZflag()) {
555
                                    double[][] lin3D = new double[2][3];
556
                                lin3D[0][0] = lin[0].getX();
557
                                lin3D[0][1] = lin[0].getY();
558
                                lin3D[0][2] = p1[2];
559
                                lin3D[1][0] = lin[1].getX();
560
                                lin3D[1][1] = lin[1].getY();
561
                                lin3D[1][2] = p2[2];
562
                                    line = points3DToFPolyline3D(lin3D);
563
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
564
                                } else if (dwg.isDwg3DFile() && !((DwgLine)entity).isZflag()) {
565
                                    double[][] lin3D = new double[2][3];
566
                                lin3D[0][0] = lin[0].getX();
567
                                lin3D[0][1] = lin[0].getY();
568
                                lin3D[0][2] = 0.0;
569
                                lin3D[1][0] = lin[1].getX();
570
                                lin3D[1][1] = lin[1].getY();
571
                                lin3D[1][2] = 0.0;
572
                                    line = points3DToFPolyline3D(lin3D);
573
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline3D"));
574
                                } else {
575
                                    line = points2DToFPolyline2D(lin);
576
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPolyline2D"));
577
                                }
578
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
579
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line"));
580
                                String layerName = dwg.getLayerName(entity);
581
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
582
                                int color = entity.getColor();
583
                                int colorByLayer = dwg.getColorByLayer(entity);
584
                                //if (color==0) color ByBlock
585
                                if (color==256) color = colorByLayer;
586
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
587
                    if (((DwgLine)entity).isZflag()) {
588
                    if (p1[2]==p2[2]) auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p1[2]);
589
                        else auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
590
                    } else {
591
                        auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
592
                    }
593
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
594
                    // Attributes
595
                    /*for (int j=0;j<nAtt;j++) {
596
                                    String[] attributes = new String[2];
597
                                    attributes = (String[])featureMaker.getAttributes().get(j);
598
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
599
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
600
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
601
                        }
602
                    }*/
603
                                addShape(line, auxRow);
604
                        } else if (entity instanceof DwgPoint) {// && !addingToBlock) {
605
                                //System.out.println("Encuentra un Point ...");
606
                                double[] p = ((DwgPoint)entity).getPoint();
607
                                FPoint2D point;
608
                                if (dwg.isDwg3DFile()) {
609
                                    point = new FPoint3D(p[0], p[1], p[2]);
610
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D"));
611
                                } else {
612
                                    point = new FPoint2D(p[0], p[1]);
613
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D"));
614
                                }
615
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
616
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Point"));
617
                                String layerName = dwg.getLayerName(entity);
618
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
619
                                int color = entity.getColor();
620
                                int colorByLayer = dwg.getColorByLayer(entity);
621
                                //if (color==0) color ByBlock
622
                                if (color==256) color = colorByLayer;
623
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
624
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
625
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
626
                    // Attributes
627
                    /*for (int j=0;j<nAtt;j++) {
628
                                    String[] attributes = new String[2];
629
                                    attributes = (String[])featureMaker.getAttributes().get(j);
630
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
631
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
632
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
633
                        }
634
                    }*/
635
                                addShape(point, auxRow);
636
                        } else if (entity instanceof DwgInsert) {// && !addingToBlock) {
637
                                //System.out.println("Encuentra un Insert ...");
638
                                double[] p = ((DwgInsert)entity).getInsertionPoint();
639
                                Point2D point = new Point2D.Double(p[0], p[1]);
640
                                FPoint2D fPoint;
641
                                /*double[] scale = ((DwgInsert)entity).getScale();
642
                                double rot = ((DwgInsert)entity).getRotation();
643
                                int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle();*/
644
                                //manageInsert(dwgObjects, point, scale, rot, blockHandle, i, auxRow);
645
                                if (dwg.isDwg3DFile()) {
646
                                    fPoint = new FPoint3D(p[0], p[1], p[2]);
647
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D"));
648
                                } else {
649
                                    fPoint = new FPoint2D(p[0], p[1]);
650
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D"));
651
                                }
652
                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
653
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Insert"));
654
                                String layerName = dwg.getLayerName(entity);
655
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
656
                                int color = entity.getColor();
657
                                int colorByLayer = dwg.getColorByLayer(entity);
658
                                //if (color==0) color ByBlock
659
                                if (color==256) color = colorByLayer;
660
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
661
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
662
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
663
                    // Attributes
664
                    /*for (int j=0;j<nAtt;j++) {
665
                                    String[] attributes = new String[2];
666
                                    attributes = (String[])featureMaker.getAttributes().get(j);
667
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
668
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
669
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
670
                        }
671
                    }*/
672
                                addShape(fPoint, auxRow);
673
                        } else if (entity instanceof DwgMText) {//) && !addingToBlock) {
674
                                //System.out.println("Encuentra un MText ...");
675
                                double[] p = ((DwgMText)entity).getInsertionPoint();
676
                                FPoint2D fPoint;
677
                                if (dwg.isDwg3DFile()) {
678
                                    fPoint = new FPoint3D(p[0], p[1], p[2]);
679
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D"));
680
                                } else {
681
                                    fPoint = new FPoint2D(p[0], p[1]);
682
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D"));
683
                                }
684
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
685
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("MText"));
686
                                String layerName = dwg.getLayerName(entity);
687
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
688
                                int color = entity.getColor();
689
                                int colorByLayer = dwg.getColorByLayer(entity);
690
                                //if (color==0) color ByBlock
691
                                if (color==256) color = colorByLayer;
692
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
693
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(p[2]);
694
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
695
                    // Attributes
696
                    /*for (int j=0;j<nAtt;j++) {
697
                                    String[] attributes = new String[2];
698
                                    attributes = (String[])featureMaker.getAttributes().get(j);
699
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
700
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
701
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
702
                        }
703
                    }*/
704
                                addShape(fPoint, auxRow);
705
                        } else if (entity instanceof DwgAttrib) {// && !addingToBlock) {
706
                                //System.out.println("Encuentra un Attrib ...");
707
                        } else if (entity instanceof DwgText) {// && !addingToBlock) {
708
                                //System.out.println("Encuentra un Text ...");
709
                                Point2D p = ((DwgText)entity).getInsertionPoint();
710
                                int dflag = ((DwgText)entity).getDataFlag();
711
                                double elev = 0.0;
712
                                if ((dflag & 0x1)==0) elev = ((DwgText)entity).getElevation();
713
                                FPoint2D point;
714
                                if (dwg.isDwg3DFile()) {
715
                                    point = new FPoint3D(p.getX(), p.getY(), elev);
716
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint3D"));
717
                                } else {
718
                                    point = new FPoint2D(p.getX(), p.getY());
719
                        auxRow[ID_FIELD_FSHAPE] = ValueFactory.createValue(new String("FPoint2D"));
720
                                }
721
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
722
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Text"));
723
                                String layerName = dwg.getLayerName(entity);
724
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
725
                                int color = entity.getColor();
726
                                int colorByLayer = dwg.getColorByLayer(entity);
727
                                //if (color==0) color ByBlock
728
                                if (color==256) color = colorByLayer;
729
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
730
                String text = ((DwgText)entity).getText();
731
                auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(text));
732
                heightText = (float)((DwgText)entity).getHeight();
733
                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
734
                if ((dflag & 0x8) == 0) {
735
                            double textRot = ((DwgText)entity).getRotationAngle();
736
                        auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(Math.toDegrees(textRot));
737
                                } else {
738
                            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
739
                                }
740
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev);
741
                    double thickness = ((DwgText)entity).getThickness();
742
                                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(thickness);
743
                    // Attributes
744
                    /*for (int j=0;j<nAtt;j++) {
745
                                    String[] attributes = new String[2];
746
                                    attributes = (String[])featureMaker.getAttributes().get(j);
747
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
748
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
749
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
750
                        }
751
                    }*/
752
                                addShape(point, auxRow);
753
                        } else if (entity instanceof DwgBlock) {
754
                                //System.out.println("Encuentra un Block ...");
755
                                //addingToBlock = true;
756
                                String blockName = ((DwgBlock)entity).getName();
757
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
758
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block"));
759
                                String layerName = dwg.getLayerName(entity);
760
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
761
                                int color = entity.getColor();
762
                                int colorByLayer = dwg.getColorByLayer(entity);
763
                                //if (color==0) color ByBlock
764
                                if (color==256) color = colorByLayer;
765
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
766
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
767
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
768
                    // Attributes
769
                    /*for (int j=0;j<nAtt;j++) {
770
                                    String[] attributes = new String[2];
771
                                    attributes = (String[])featureMaker.getAttributes().get(j);
772
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
773
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
774
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
775
                        }
776
                    }*/
777
                                //addShape(point, auxRow);
778
                        } else if (entity instanceof DwgEndblk) {
779
                                //System.out.println("Encuentra un Endblk ...");
780
                                //addingToBlock = false;
781
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
782
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("EndBlk"));
783
                                String layerName = dwg.getLayerName(entity);
784
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
785
                                int color = entity.getColor();
786
                                int colorByLayer = dwg.getColorByLayer(entity);
787
                                //if (color==0) color ByBlock
788
                                if (color==256) color = colorByLayer;
789
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
790
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
791
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
792
                    // Attributes
793
                    /*for (int j=0;j<nAtt;j++) {
794
                                    String[] attributes = new String[2];
795
                                    attributes = (String[])featureMaker.getAttributes().get(j);
796
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
797
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
798
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
799
                        }
800
                    }*/
801
                                //addShape(point, auxRow);
802
                        } else if (entity instanceof DwgBlockControl) {
803
                                //System.out.println("Encuentra un Block Control Object ...");
804
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
805
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Control Object"));
806
                                String layerName = dwg.getLayerName(entity);
807
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
808
                                int color = entity.getColor();
809
                                int colorByLayer = dwg.getColorByLayer(entity);
810
                                //if (color==0) color ByBlock
811
                                if (color==256) color = colorByLayer;
812
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
813
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
814
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
815
                    // Attributes
816
                    /*for (int j=0;j<nAtt;j++) {
817
                                    String[] attributes = new String[2];
818
                                    attributes = (String[])featureMaker.getAttributes().get(j);
819
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
820
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
821
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
822
                        }
823
                    }*/
824
                                //addShape(point, auxRow);
825
                        } else if (entity instanceof DwgBlockHeader) {
826
                                //System.out.println("Encuentra un Block Header ...");
827
                                //addingToBlock = true;
828
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
829
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Header"));
830
                                String layerName = dwg.getLayerName(entity);
831
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
832
                                int color = entity.getColor();
833
                                int colorByLayer = dwg.getColorByLayer(entity);
834
                                //if (color==0) color ByBlock
835
                                if (color==256) color = colorByLayer;
836
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
837
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
838
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
839
                    // Attributes
840
                    /*for (int j=0;j<nAtt;j++) {
841
                                    String[] attributes = new String[2];
842
                                    attributes = (String[])featureMaker.getAttributes().get(j);
843
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
844
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
845
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
846
                        }
847
                    }*/
848
                                //addShape(point, auxRow);
849
                        } else if (entity instanceof DwgAttdef) {// && !addingToBlock) {
850
                                //System.out.println("Encuentra un Attdef ...");
851
                        } else {
852
                                //System.out.println("Detectado dwgObject pendiente de implementar");
853
                        }
854
                }
855
                t2 = System.currentTimeMillis();
856
                System.out.println("Tiempo empleado por el driver en importar el contenido del dwg = " + (t2-t1));
857

    
858
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
859
                defaultLegend.setFieldName("Color");
860
                defaultLegend.setLabelField("Text");
861
                FSymbol myDefaultSymbol = new FSymbol(getShapeType());                
862
                myDefaultSymbol.setShapeVisible(false);
863
                myDefaultSymbol.setFontSizeInPixels(false);
864
                myDefaultSymbol.setFont(new Font("SansSerif",Font.PLAIN, 9));
865
                myDefaultSymbol.setFontColor(Color.BLACK);
866
                myDefaultSymbol.setFontSize(heightText);
867
                myDefaultSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
868
                myDefaultSymbol.setSize(3);
869
                myDefaultSymbol.setSizeInPixels(true);
870
                
871
                defaultLegend.setDefaultSymbol(myDefaultSymbol);
872

    
873
                defaultLegend.setLabelHeightField("HeightText");
874
                defaultLegend.setLabelRotationField("RotationText");
875

    
876
        ObjectDriver rs = this;
877
                IntValue clave;
878
                FSymbol theSymbol = null;
879

    
880
                try {
881
                    // Provisional hasta que cambiemos los s?mbolos.
882
                   /*  BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
883
                   Graphics2D big = bi.createGraphics();
884
                   Color color=new Color(0,0,0,0);
885
                   big.setBackground(color);
886
                   big.clearRect(0, 0, 5, 5);
887
                   Paint fillProv = null;
888
                   Rectangle2D rProv = new Rectangle();
889
                   rProv.setFrame(0, 0,5,5);
890
                   fillProv = new TexturePaint(bi,rProv); */
891

    
892
                        for (long j = 0; j < rs.getRowCount(); j++)
893
                        {
894
                                clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR);
895
                                if (defaultLegend.getSymbolByValue(clave) == null)
896
                                {
897
                                        theSymbol = new FSymbol(getShapeType());
898
                                        theSymbol.setDescription(clave.toString());
899
                                        theSymbol.setColor(AcadColor.getColor(clave.getValue()));
900
                                        // theSymbol.setFill(fillProv);
901
                                        // 050202, jmorell: Asigna los colores de Autocad a los bordes
902
                                        //                                        de los pol?gonos.
903
                                        theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue()));
904

    
905
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
906
                                        theSymbol.setSize(3);
907
                                        theSymbol.setSizeInPixels(true);
908

    
909
                                        defaultLegend.addSymbol(clave, theSymbol);
910
                                }
911
                        } // for
912
                } catch (DriverException e) {
913
                        e.printStackTrace();
914
                        throw new IOException("Error al poner la leyenda por defecto en el Dwg");
915
                }
916
        }
917
        
918
        public String getFileVersion() {
919
                return dwg.getDwgVersion();
920
        }
921
        
922
        
923
        private String formatString(String fmt,String[] params){
924
                String ret = fmt;
925
                for( int i = 0 ; i < params.length ; i++ ) {
926
                        ret=ret.replaceFirst("%s",params[i]);
927
                }
928
                return ret;
929
        }
930
        
931
        
932

    
933
        /**
934
         * Method that changes a Point2D array to a FPolyline2D. Is useful to convert a
935
         * polyline given by it points to a FPolyline2D, a polyline in the FMap model
936
         * object
937
         *
938
         * @param pts Array of Point2D that defines the polyline that will be converted in
939
         *                   a FPolyline2D
940
         * @return FPolyline2D This FPolyline2D is build using the array of Point2D that
941
         *                   is the argument of the method
942
         */
943
        private FPolyline2D points2DToFPolyline2D(Point2D[] pts) {
944
                GeneralPathX genPathX = new GeneralPathX();
945
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
946
                for (int i=1; i<pts.length; i++) {
947
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
948
                }
949
                return new FPolyline2D(genPathX);
950
        }
951

    
952
        /**
953
         * Method that changes a Point3D array to a FPolyline3D. Is useful to convert a
954
         * polyline given by it points to a FPolyline3D, a polyline 3D in the FMap model
955
         * object
956
         *
957
         * @param pts Array of Point3D that defines the polyline 3D that will be converted in
958
         *                   a FPolyline3D
959
         * @return FPolyline3D This FPolyline3D is build using the array of Point3D that
960
         *                   is the argument of the method
961
         */
962
        private FPolyline3D points3DToFPolyline3D(double[][] pts) {
963
                GeneralPathX genPathX = new GeneralPathX();
964
                genPathX.moveTo(pts[0][0], pts[0][1]);
965
                for (int i=1; i<pts.length; i++) {
966
                        genPathX.lineTo(pts[i][0], pts[i][1]);
967
                }
968
                double[] elevations = new double[pts.length];
969
                for (int i=0;i<pts.length;i++) {
970
                    elevations[i] = pts[i][2];
971
                }
972
                return new FPolyline3D(genPathX, elevations);
973
        }
974

    
975
        /**
976
         * Method that changes a Point2D array to a FPolygon2D. Is useful to convert a
977
         * polygon given by it points to a FPolygon2D, a polygon in the FMap model
978
         * object
979
         *
980
         * @param pts Array of Point2D that defines the polygon that will be converted in
981
         *                   a FPolygon2D
982
         * @return FPolygon2D This FPolygon2D is build using the array of Point2D that
983
         *                   is the argument of the method
984
         */
985
        private FPolygon2D points2DToFPolygon2D(Point2D[] pts) {
986
                GeneralPathX genPathX = new GeneralPathX();
987
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
988
                for (int i=1; i<pts.length; i++) {
989
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
990
                }
991
                genPathX.closePath();
992
                return new FPolygon2D(genPathX);
993
        }
994

    
995
        /* (non-Javadoc)
996
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
997
         */
998
        public boolean accept(File f) {
999
                return f.getName().toUpperCase().endsWith("DWG");
1000
        }
1001

    
1002
        /* (non-Javadoc)
1003
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
1004
         */
1005
        public int getShapeType() {
1006
                return FShape.MULTI;
1007
        }
1008

    
1009
        /* (non-Javadoc)
1010
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
1011
         */
1012
        public String getName() {
1013
                return "gvSIG DWG Memory Driver";
1014
        }
1015

    
1016
        /* (non-Javadoc)
1017
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
1018
         */
1019
        public Legend getDefaultLegend() {
1020
                return defaultLegend;
1021
        }
1022

    
1023
    /* (non-Javadoc)
1024
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
1025
     */
1026
    public DriverAttributes getDriverAttributes() {
1027
        return attr;
1028
    }
1029

    
1030
    /* (non-Javadoc)
1031
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
1032
     */
1033
    public int[] getPrimaryKeys() throws DriverException {
1034
        // TODO Auto-generated method stub
1035
        return null;
1036
    }
1037

    
1038
    /* (non-Javadoc)
1039
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
1040
     */
1041
    public void write(DataWare arg0) throws DriverException {
1042
        // TODO Auto-generated method stub
1043

    
1044
    }
1045

    
1046
    public void setDataSourceFactory(DataSourceFactory arg0) {
1047
        // TODO Auto-generated method stub
1048

    
1049
    }
1050

    
1051
        public void close() throws IOException {
1052
                // TODO Auto-generated method stub
1053

    
1054
        }
1055

    
1056
        public File getFile() {
1057
                return m_Fich;
1058
        }
1059

    
1060
        public boolean isWritable() {
1061
                return m_Fich.canWrite();
1062
        }
1063
}