Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extDwg / src / es / iver / gvsig / drivers / dwg / DwgMemoryDriver.java @ 7192

History | View | Annotate | Download (46.5 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 org.gvsig.i18n.Messages;
56

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

    
105
/**
106
 * Driver that allows gvSIG to read files in DWG format
107
 * Using this driver, a gvSIG user can manipulate part of the information contained in
108
 * a DWG file
109
 * This driver load the Dwg file in memory
110
 * This driver uses jdwglib
111
 *
112
 * @author jmorell
113
 */
114
public class DwgMemoryDriver extends MemoryDriver implements VectorialFileDriver, WithDefaultLegend {
115
        
116
        static{
117
                Messages.addResourceFamily("org.gvsig.translations.text",
118
                                DwgMemoryDriver.class.getClassLoader(), 
119
                                "com.iver.cit.gvsig.dwg");
120
        }
121
        
122
        private final int ID_FIELD_ID=0;
123
        private final int ID_FIELD_FSHAPE=1;
124
        private final int ID_FIELD_ENTITY=2;
125
        private final int ID_FIELD_LAYER=3;
126
        private final int ID_FIELD_COLOR=4;
127
        private final int ID_FIELD_ELEVATION=5;
128
        private final int ID_FIELD_THICKNESS=6;
129
        private final int ID_FIELD_TEXT=7;
130
        private final int ID_FIELD_HEIGHTTEXT=8;
131
        private final int ID_FIELD_ROTATIONTEXT=9;
132

    
133
        VectorialUniqueValueLegend defaultLegend;
134

    
135
        private File m_Fich;
136

    
137
        private DwgFile dwg;
138
        private ArrayList dwgObjects;
139
        private DriverAttributes attr = new DriverAttributes();
140
        
141
        private boolean isInitialized = false;
142

    
143
        /* (non-Javadoc)
144
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
145
         */
146
        public void open(File f) throws IOException {
147
            m_Fich = f;
148
        }
149

    
150
        /**
151
         * This method load the DWG file in memory.
152
         * First, it will be necessary to create a DwgFile object with the DWG file path
153
         * as the argument.
154
         * Second, the method read of DwgFile allows to read the objects inside the DWG
155
         * file.
156
         * Third, it will be necessary to process some DWG objects like Layers or Polylines
157
         * Fourth, applyExtrusions() can change the location of the DWG objects through the
158
     * extrusion parameters.
159
     * Fifth, the testDwg3D method test if this DWG has elevation informacion.
160
         * Sixth, we can extract the objects contained inside the blocks through the
161
     * blockManagement method.
162
     * And finally, we can read the objects Vector, and convert this objects to the FMap
163
     * object model.
164
         */
165
        public void initialize() throws IOException {
166
                if(isInitialized)
167
                        return;
168
                else
169
                        isInitialized = true;
170
        //System.out.println("Driver actualizado");
171
                float heightText = 10;
172

    
173
                attr.setLoadedInMemory(true);
174

    
175
                dwg = new DwgFile(m_Fich.getAbsolutePath());
176
                long t1 = System.currentTimeMillis();
177
                try {
178
                        dwg.read();
179
                } catch (DwgVersionNotSupportedException e1) {
180
                        String autodeskUrl = "<a href=\"http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151\">"+
181
                                        "http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=7024151</a>";
182
                        String userText = "<html><p>"+PluginServices.getText(this, "The_version_of")+" ";
183
                        userText += m_Fich.getName() + " (";
184
                        userText += e1.getDwgVersion() + " ) ";
185
                        userText += PluginServices.getText(this, "Is_not_supported");
186
                        userText += "<br>";
187
                        userText += PluginServices.getText(this, "Probe_to_convert") + "<br>";
188
                        userText += PluginServices.getText(this, "Autodesk_converter") + "<br>";
189
                        userText += " " + autodeskUrl + "<br>";
190
                        userText += "</p></hml>";
191
                         javax.swing.JLabel label = 
192
                                 new  javax.swing.JLabel(userText);
193
                        String dialogTitle = PluginServices.getText(this, "Not_supported_version");
194
                        javax.swing.JOptionPane.
195
                                showMessageDialog((Component)PluginServices.getMainFrame(),
196
                                                label,
197
                                                dialogTitle,
198
                                                javax.swing.JOptionPane.ERROR_MESSAGE);
199
                        throw new IOException("Version de DWG no soportada por gvSIG");
200
                        
201
                        
202
                }
203
                long t2 = System.currentTimeMillis();
204
                System.out.println("Tiempo empleado por la librer?a en leer el fichero dwg = " + (t2-t1));
205
                t1 = System.currentTimeMillis();
206
                dwg.initializeLayerTable();
207
        dwg.calculateGisModelDwgPolylines();
208
        dwg.applyExtrusions();
209
                dwg.testDwg3D();
210
                dwg.blockManagement();
211
        t2 = System.currentTimeMillis();
212
                System.out.println("Tiempo empleado por la librer?a en tratar el fichero dwg = " + (t2-t1));
213
                dwgObjects = dwg.getDwgObjects();
214

    
215
                // TODO: Atributos extra de los objectos
216
                //int nAtt = featureMaker.getAttributes().size();
217

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

    
238
            getTableModel().setColumnIdentifiers(arrayFields.toArray());
239

    
240
                t1 = System.currentTimeMillis();
241

    
242
            //boolean addingToBlock = false;
243

    
244
                for (int i=0;i<dwgObjects.size();i++) {
245

    
246
            auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0.0);
247
            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
248
            auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
249

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

    
864
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
865
                defaultLegend.setFieldName("Color");
866
                defaultLegend.setLabelField("Text");
867
                defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
868
                defaultLegend.getDefaultSymbol().setShapeVisible(false);
869
                defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
870
                defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9));
871
                defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
872
                defaultLegend.getDefaultSymbol().setFontSize(heightText);
873
                defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
874
                defaultLegend.getDefaultSymbol().setSize(3);
875
                defaultLegend.getDefaultSymbol().setSizeInPixels(true);
876

    
877
                defaultLegend.setLabelHeightField("HeightText");
878
                defaultLegend.setLabelRotationField("RotationText");
879

    
880
        ObjectDriver rs = this;
881
                IntValue clave;
882
                FSymbol theSymbol = null;
883

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

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

    
909
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
910
                                        theSymbol.setSize(3);
911
                                        theSymbol.setSizeInPixels(true);
912

    
913
                                        defaultLegend.addSymbol(clave, theSymbol);
914
                                }
915
                        } // for
916
                } catch (DriverException e) {
917
                        e.printStackTrace();
918
                        throw new IOException("Error al poner la leyenda por defecto en el Dwg");
919
                }
920
        }
921

    
922
        /**
923
         * Method that changes a Point2D array to a FPolyline2D. Is useful to convert a
924
         * polyline given by it points to a FPolyline2D, a polyline in the FMap model
925
         * object
926
         *
927
         * @param pts Array of Point2D that defines the polyline that will be converted in
928
         *                   a FPolyline2D
929
         * @return FPolyline2D This FPolyline2D is build using the array of Point2D that
930
         *                   is the argument of the method
931
         */
932
        private FPolyline2D points2DToFPolyline2D(Point2D[] pts) {
933
                GeneralPathX genPathX = new GeneralPathX();
934
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
935
                for (int i=1; i<pts.length; i++) {
936
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
937
                }
938
                return new FPolyline2D(genPathX);
939
        }
940

    
941
        /**
942
         * Method that changes a Point3D array to a FPolyline3D. Is useful to convert a
943
         * polyline given by it points to a FPolyline3D, a polyline 3D in the FMap model
944
         * object
945
         *
946
         * @param pts Array of Point3D that defines the polyline 3D that will be converted in
947
         *                   a FPolyline3D
948
         * @return FPolyline3D This FPolyline3D is build using the array of Point3D that
949
         *                   is the argument of the method
950
         */
951
        private FPolyline3D points3DToFPolyline3D(double[][] pts) {
952
                GeneralPathX genPathX = new GeneralPathX();
953
                genPathX.moveTo(pts[0][0], pts[0][1]);
954
                for (int i=1; i<pts.length; i++) {
955
                        genPathX.lineTo(pts[i][0], pts[i][1]);
956
                }
957
                double[] elevations = new double[pts.length];
958
                for (int i=0;i<pts.length;i++) {
959
                    elevations[i] = pts[i][2];
960
                }
961
                return new FPolyline3D(genPathX, elevations);
962
        }
963

    
964
        /**
965
         * Method that changes a Point2D array to a FPolygon2D. Is useful to convert a
966
         * polygon given by it points to a FPolygon2D, a polygon in the FMap model
967
         * object
968
         *
969
         * @param pts Array of Point2D that defines the polygon that will be converted in
970
         *                   a FPolygon2D
971
         * @return FPolygon2D This FPolygon2D is build using the array of Point2D that
972
         *                   is the argument of the method
973
         */
974
        private FPolygon2D points2DToFPolygon2D(Point2D[] pts) {
975
                GeneralPathX genPathX = new GeneralPathX();
976
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
977
                for (int i=1; i<pts.length; i++) {
978
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
979
                }
980
                genPathX.closePath();
981
                return new FPolygon2D(genPathX);
982
        }
983

    
984
        /* (non-Javadoc)
985
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
986
         */
987
        public boolean accept(File f) {
988
                return f.getName().toUpperCase().endsWith("DWG");
989
        }
990

    
991
        /* (non-Javadoc)
992
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
993
         */
994
        public int getShapeType() {
995
                return FShape.MULTI;
996
        }
997

    
998
        /* (non-Javadoc)
999
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
1000
         */
1001
        public String getName() {
1002
                return "gvSIG DWG Memory Driver";
1003
        }
1004

    
1005
        /* (non-Javadoc)
1006
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
1007
         */
1008
        public Legend getDefaultLegend() {
1009
                return defaultLegend;
1010
        }
1011

    
1012
    /* (non-Javadoc)
1013
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
1014
     */
1015
    public DriverAttributes getDriverAttributes() {
1016
        return attr;
1017
    }
1018

    
1019
    /* (non-Javadoc)
1020
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#getPrimaryKeys()
1021
     */
1022
    public int[] getPrimaryKeys() throws DriverException {
1023
        // TODO Auto-generated method stub
1024
        return null;
1025
    }
1026

    
1027
    /* (non-Javadoc)
1028
     * @see com.hardcode.gdbms.engine.data.driver.ObjectDriver#write(com.hardcode.gdbms.engine.data.edition.DataWare)
1029
     */
1030
    public void write(DataWare arg0) throws DriverException {
1031
        // TODO Auto-generated method stub
1032

    
1033
    }
1034

    
1035
    public void setDataSourceFactory(DataSourceFactory arg0) {
1036
        // TODO Auto-generated method stub
1037

    
1038
    }
1039

    
1040
        public void close() throws IOException {
1041
                // TODO Auto-generated method stub
1042

    
1043
        }
1044

    
1045
        public File getFile() {
1046
                return m_Fich;
1047
        }
1048

    
1049
        public boolean isWritable() {
1050
                return m_Fich.canWrite();
1051
        }
1052
}