Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dwg / DwgMemoryDriver.java @ 1922

History | View | Annotate | Download (61.4 KB)

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

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

    
54
import net.jmorell.javacad.util.AcadColor;
55
import net.jmorell.javacad.util.ArcFromBulgeCalculator;
56
import net.jmorell.javacad.util.GisModelCurveCalculator;
57
import net.jmorell.jdwglib.dwg.DwgFile;
58
import net.jmorell.jdwglib.dwg.DwgObject;
59
import net.jmorell.jdwglib.dwg.DwgObjectSpecificDataItem;
60
import net.jmorell.jdwglib.dwg.DxfName;
61
import net.jmorell.jdwglib.dwg.objects.DwgArc;
62
import net.jmorell.jdwglib.dwg.objects.DwgBlock;
63
import net.jmorell.jdwglib.dwg.objects.DwgBlockHeader;
64
import net.jmorell.jdwglib.dwg.objects.DwgCircle;
65
import net.jmorell.jdwglib.dwg.objects.DwgInsert;
66
import net.jmorell.jdwglib.dwg.objects.DwgLayer;
67
import net.jmorell.jdwglib.dwg.objects.DwgLine;
68
import net.jmorell.jdwglib.dwg.objects.DwgLwPolyline;
69
import net.jmorell.jdwglib.dwg.objects.DwgMText;
70
import net.jmorell.jdwglib.dwg.objects.DwgPoint;
71
import net.jmorell.jdwglib.dwg.objects.DwgPolyline2D;
72
import net.jmorell.jdwglib.dwg.objects.DwgPolyline3D;
73
import net.jmorell.jdwglib.dwg.objects.DwgSolid;
74
import net.jmorell.jdwglib.dwg.objects.DwgText;
75
import net.jmorell.jdwglib.dwg.objects.DwgVertex2D;
76

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

    
96
import com.iver.cit.gvsig.fmap.drivers.dgn.ByteUtils;
97

    
98
public class DwgMemoryDriver extends MemoryDriver implements WithDefaultLegend {
99
        private final int ID_FIELD_ID=0;
100
        private final int ID_FIELD_ENTITY=1;
101
        private final int ID_FIELD_LAYER=2;
102
        private final int ID_FIELD_COLOR=3;
103
        private final int ID_FIELD_ELEVATION=4;
104
        private final int ID_FIELD_THICKNESS=5;
105
        private final int ID_FIELD_TEXT=6;
106
        private final int ID_FIELD_HEIGHTTEXT=7;
107
        private final int ID_FIELD_ROTATIONTEXT=8;
108

    
109
        VectorialUniqueValueLegend defaultLegend;
110
        private String path;
111
        private File m_Fich;
112
        
113
        private DwgFile dwg;
114
        private Vector dwgObjects;
115
        private DriverAttributes attr = new DriverAttributes();
116

    
117
        /* (non-Javadoc)
118
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
119
         */
120
        public void open(File f) throws IOException {
121
            m_Fich = f;
122
        }
123
        
124
        public void initialize() throws IOException {
125
                float heightText = 10;
126
                
127
                attr.setLoadedInMemory(true);
128
                
129
                dwg = new DwgFile();
130
                long time = System.currentTimeMillis();
131
                dwg.read(m_Fich.getAbsolutePath());
132
                dwg.calculateDwgPolylines();
133
                //dwg.initializeLayerTable();
134
                dwg.manageInserts();
135
                long timeElapsed = System.currentTimeMillis()-time;
136
                System.out.println("Tiempo empleado en leer el fichero dwg = " + timeElapsed);
137
                dwgObjects = dwg.getDwgObjects();
138
                
139
                //int nAtt = featureMaker.getAttributes().size();
140
                
141
                // Campos de las MemoryLayer:
142
            //Value[] auxRow = new Value[9+nAtt];
143
            Value[] auxRow = new Value[9];
144
                ArrayList arrayFields = new ArrayList();
145
                arrayFields.add("ID");
146
                arrayFields.add("Entity");
147
                arrayFields.add("Layer");
148
                arrayFields.add("Color");
149
                arrayFields.add("Elevation");
150
                arrayFields.add("Thickness");
151
                arrayFields.add("Text");
152
                arrayFields.add("HeightText");
153
                arrayFields.add("RotationText");
154
                /*for (int i=0;i<nAtt;i++) {
155
                        String att[] = new String[2];
156
                        att = (String[])featureMaker.getAttributes().get(i);
157
                        arrayFields.add(att[0]);
158
                }*/
159
                
160
            getTableModel().setColumnIdentifiers(arrayFields.toArray());
161
                
162
            //boolean addingToBlock = false;
163
            
164
                time = System.currentTimeMillis();
165
                
166
                // Para intentar entender la manera de asignar la layer a cada elemento ...
167
                /*for (int i=0;i<dwgObjects.size();i++) {
168
                        DwgObject obj = (DwgObject)dwgObjects.get(i);
169
                        if (obj.getType()==0x33) {
170
                                System.out.println("obj.getHandle().get(0) = " + obj.getHandle().get(0));
171
                                System.out.println("obj.getHandle().get(1) = " + obj.getHandle().get(1));
172
                                if (obj.getHandle().size()>2) System.out.println("obj.getHandle().get(2) = " + obj.getHandle().get(2));
173
                                if (obj.getHandle().size()>3) System.out.println("obj.getHandle().get(3) = " + obj.getHandle().get(3));
174
                        }
175
                }*/
176
                
177
                Vector layerTable = createLayerTable(dwgObjects);
178
                
179
                for (int i=0;i<dwgObjects.size();i++) {
180
                        
181
            auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
182
            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
183
            auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
184
                        
185
                        DwgObject entity = (DwgObject)dwgObjects.get(i);
186
                        //if (entity.getType()==0x11 && !addingToBlock) {
187
                        if (entity.getType()==0x11) {
188
                                double[] c = ((DwgArc)entity).getCenter();
189
                                Point2D center = new Point2D.Double(c[0], c[1]);
190
                                double radius = ((DwgArc)entity).getRadius();
191
                                double initAngle = Math.toDegrees(((DwgArc)entity).getInitAngle());
192
                                double endAngle = Math.toDegrees(((DwgArc)entity).getEndAngle());
193
                                //Point2D[] arc = createArc(center, radius, startAngle, endAngle);
194
                                Point2D[] arc = GisModelCurveCalculator.calculateGisModelArc(center, radius, initAngle, endAngle);
195
                                FPolyline2D arcc = points2DToFPolyline2D(arc);
196
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
197
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc"));
198
                                //int[] layerHandle = (int[])entity.getLayer();
199
                                String layerName = getLayerName(entity, layerTable);
200
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
201
                                int color = entity.getColor();
202
                                int colorByLayer = getColorByLayer(entity, layerTable);
203
                                //if (color==0) color ByBlock
204
                                if (color==256) color = colorByLayer;
205
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
206
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
207
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
208
                    // Attributes
209
                    /*for (int j=0;j<nAtt;j++) {
210
                                    String[] attributes = new String[2];
211
                                    attributes = (String[])featureMaker.getAttributes().get(j);
212
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
213
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
214
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
215
                        }
216
                    }*/
217
                                addShape(arcc, auxRow);
218
                        //} else if (entity.getType()==0x12 && !addingToBlock) {
219
                        } else if (entity.getType()==0x12) {
220
                                //System.out.println("Encuentra un Circle ...");
221
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
222
                                //double[] coord = (double[])data.getValue();
223
                                //Point2D center = new Point2D.Double(coord[0], coord[1]);
224
                                double[] center = ((DwgCircle)entity).getCenter();
225
                                //data = entity.getDwgObjectSpecificDataItem("RADIUS");
226
                                //double radius = ((Double)data.getValue()).doubleValue();
227
                                double radius = ((DwgCircle)entity).getRadius();
228
                                Point2D[] c = GisModelCurveCalculator.calculateGisModelCircle(new Point2D.Double(center[0], center[1]), radius);
229
                                FPolyline2D circle = points2DToFPolyline2D(c);
230
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
231
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle"));
232
                                //int[] layerHandle = (int[])entity.getLayer();
233
                                String layerName = getLayerName(entity, layerTable);
234
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
235
                                int color = entity.getColor();
236
                                int colorByLayer = getColorByLayer(entity, layerTable);
237
                                //if (color==0) color ByBlock
238
                                if (color==256) color = colorByLayer;
239
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
240
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
241
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
242
                    // Attributes
243
                    /*for (int j=0;j<nAtt;j++) {
244
                                    String[] attributes = new String[2];
245
                                    attributes = (String[])featureMaker.getAttributes().get(j);
246
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
247
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
248
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
249
                        }
250
                    }*/
251
                                addShape(circle, auxRow);
252
                        //} else if (entity.getType()==0x13 && !addingToBlock) {
253
                        } else if (entity.getType()==0x13) {
254
                                //System.out.println("Encuentra una Line ...");
255
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1");
256
                                //double[] coord = (double[])data.getValue();
257
                                //Point2D p1 = new Point2D.Double(coord[0], coord[1]);
258
                                double[] p1 = ((DwgLine)entity).getP1();
259
                                //data = entity.getDwgObjectSpecificDataItem("P2");
260
                                //coord = (double[])data.getValue();
261
                                //Point2D p2 = new Point2D.Double(coord[0], coord[1]);
262
                                double[] p2 = ((DwgLine)entity).getP2();
263
                                Point2D[] l = new Point2D[]{new Point2D.Double(p1[0], p1[1]), new Point2D.Double(p2[0], p2[1])};
264
                                FPolyline2D line = points2DToFPolyline2D(l);
265
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
266
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line"));
267
                                //int[] layerHandle = (int[])entity.getLayer();
268
                                String layerName = getLayerName(entity, layerTable);
269
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
270
                                int color = entity.getColor();
271
                                int colorByLayer = getColorByLayer(entity, layerTable);
272
                                //if (color==0) color ByBlock
273
                                if (color==256) color = colorByLayer;
274
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
275
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
276
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
277
                    // Attributes
278
                    /*for (int j=0;j<nAtt;j++) {
279
                                    String[] attributes = new String[2];
280
                                    attributes = (String[])featureMaker.getAttributes().get(j);
281
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
282
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
283
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
284
                        }
285
                    }*/
286
                                addShape(line, auxRow);
287
                        //} else if (entity.getType()==0x1B && !addingToBlock) {
288
                        } else if (entity.getType()==0x1B) {
289
                                //System.out.println("Encuentra un Point ...");
290
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("POINT");
291
                                //double[] coord = (double[])data.getValue();
292
                                //Point2D p = new Point2D.Double(coord[0], coord[1]);
293
                                double[] p = ((DwgPoint)entity).getPoint();
294
                                FPoint2D point = new FPoint2D(p[0], p[1]);
295
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
296
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Point"));
297
                                //int[] layerHandle = (int[])entity.getLayer();
298
                                String layerName = getLayerName(entity, layerTable);
299
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
300
                                int color = entity.getColor();
301
                                int colorByLayer = getColorByLayer(entity, layerTable);
302
                                //if (color==0) color ByBlock
303
                                if (color==256) color = colorByLayer;
304
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
305
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
306
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
307
                    // Attributes
308
                    /*for (int j=0;j<nAtt;j++) {
309
                                    String[] attributes = new String[2];
310
                                    attributes = (String[])featureMaker.getAttributes().get(j);
311
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
312
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
313
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
314
                        }
315
                    }*/
316
                                addShape(point, auxRow);
317
                        //} else if (entity.getType()==0x0F && !addingToBlock) {
318
                        } else if (entity.getType()==0x0F) {
319
                                Point2D[] points = ((DwgPolyline2D)entity).getPts();
320
                                FPolyline2D pline = points2DToFPolyline2D(points);
321
                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
322
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D"));
323
                                //int[] layerHandle = (int[])entity.getLayer();
324
                                String layerName = getLayerName(entity, layerTable);
325
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
326
                                int color = entity.getColor();
327
                                int colorByLayer = getColorByLayer(entity, layerTable);
328
                                //if (color==0) color ByBlock
329
                                if (color==256) color = colorByLayer;
330
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
331
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
332
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
333
                    // Attributes
334
                    /*for (int j=0;j<nAtt;j++) {
335
                                    String[] attributes = new String[2];
336
                                    attributes = (String[])featureMaker.getAttributes().get(j);
337
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
338
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
339
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
340
                        }
341
                    }*/
342
                                addShape(pline, auxRow);
343
                        // Implementaci?n parcial ...
344
                        //} else if (entity.getType()==0x10 && !addingToBlock) {
345
                        } else if (entity.getType()==0x10) {
346
                                //System.out.println("Encuentra una Polyline3D ...");
347
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CLOSED_FLAGS");
348
                                //int flags = ((Integer)data.getValue()).intValue();
349
                                int flags = ((DwgPolyline3D)entity).getClosedFlags();
350
                        //} else if (entity.getType()==0x1 && !addingToBlock) {
351
                        } else if (entity.getType()==0x1) {
352
                                //System.out.println("Encuentra un Text ...");
353
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
354
                                //Point2D p = (Point2D)data.getValue();
355
                                Point2D p = ((DwgText)entity).getInsertionPoint();
356
                                FPoint2D point = new FPoint2D(p.getX(), p.getY());
357
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
358
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Text"));
359
                                //int[] layerHandle = (int[])entity.getLayer();
360
                                String layerName = getLayerName(entity, layerTable);
361
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
362
                                int color = entity.getColor();
363
                                int colorByLayer = getColorByLayer(entity, layerTable);
364
                                //if (color==0) color ByBlock
365
                                if (color==256) color = colorByLayer;
366
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
367
                                //data = entity.getDwgObjectSpecificDataItem("TEXT");
368
                                //String text = (String)data.getValue();
369
                String text = ((DwgText)entity).getText();
370
                auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(text));
371
                                //data = entity.getDwgObjectSpecificDataItem("HEIGHT");
372
                                //heightText = ((Float)data.getValue()).floatValue();
373
                heightText = (float)((DwgText)entity).getHeight();
374
                auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
375
                                //data = entity.getDwgObjectSpecificDataItem("DATA_FLAG");
376
                                //int dflag = ((Integer)data.getValue()).intValue();
377
                                int dflag = ((DwgText)entity).getDataFlag();
378
                if ((dflag & 0x8) == 0) {
379
                                        //data = entity.getDwgObjectSpecificDataItem("ROTATION_ANGLE");
380
                                        //double textRot = ((Double)data.getValue()).doubleValue();
381
                            double textRot = ((DwgText)entity).getRotationAngle();
382
                        auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(Math.toDegrees(textRot));
383
                                } else {
384
                            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
385
                                }
386
                                if ((dflag & 0x1)==0) {
387
                                        //data = entity.getDwgObjectSpecificDataItem("ELEVATION");
388
                                        //double elev = ((Double)data.getValue()).doubleValue();
389
                                        double elev = ((DwgText)entity).getElevation();
390
                            auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev);
391
                                }
392
                                //data = entity.getDwgObjectSpecificDataItem("THICKNESS");
393
                                //double thickness = ((Double)data.getValue()).doubleValue();
394
                    double thickness = ((DwgText)entity).getThickness();
395
                                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(thickness);
396
                    // Attributes
397
                    /*for (int j=0;j<nAtt;j++) {
398
                                    String[] attributes = new String[2];
399
                                    attributes = (String[])featureMaker.getAttributes().get(j);
400
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
401
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
402
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
403
                        }
404
                    }*/
405
                                addShape(point, auxRow);
406
                        } else if (entity.getType()==0x4) {
407
                                //System.out.println("Encuentra un Block ...");
408
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("NAME");
409
                                //String blockName = (String)data.getValue();
410
                                String blockName = ((DwgBlock)entity).getName();
411
                                //addingToBlock = true;
412
                                //pto = (Point2D.Double)point.get(0);
413
                                //FShape nuevoShp;
414
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
415
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block"));
416
                                //int[] layerHandle = (int[])entity.getLayer();
417
                                String layerName = getLayerName(entity, layerTable);
418
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
419
                                int color = entity.getColor();
420
                                int colorByLayer = getColorByLayer(entity, layerTable);
421
                                //if (color==0) color ByBlock
422
                                if (color==256) color = colorByLayer;
423
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
424
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
425
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
426
                    // Attributes
427
                    /*for (int j=0;j<nAtt;j++) {
428
                                    String[] attributes = new String[2];
429
                                    attributes = (String[])featureMaker.getAttributes().get(j);
430
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
431
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
432
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
433
                        }
434
                    }*/
435
                                //addShape(point, auxRow);
436
                        } else if (entity.getType()==0x5) {
437
                                //System.out.println("Encuentra un Endblk ...");
438
                                //addingToBlock = false;
439
                                //pto = (Point2D.Double)point.get(0);
440
                                //FShape nuevoShp;
441
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
442
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("EndBlk"));
443
                                //int[] layerHandle = (int[])entity.getLayer();
444
                                String layerName = getLayerName(entity, layerTable);
445
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
446
                                int color = entity.getColor();
447
                                int colorByLayer = getColorByLayer(entity, layerTable);
448
                                //if (color==0) color ByBlock
449
                                if (color==256) color = colorByLayer;
450
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
451
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
452
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
453
                    // Attributes
454
                    /*for (int j=0;j<nAtt;j++) {
455
                                    String[] attributes = new String[2];
456
                                    attributes = (String[])featureMaker.getAttributes().get(j);
457
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
458
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
459
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
460
                        }
461
                    }*/
462
                                //addShape(point, auxRow);
463
                        } else if (entity.getType()==0x30) {
464
                                //System.out.println("Encuentra un Block Control Object ...");
465
                                //addingToBlock = false;
466
                                //pto = (Point2D.Double)point.get(0);
467
                                //FShape nuevoShp;
468
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
469
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Control Object"));
470
                                //int[] layerHandle = (int[])entity.getLayer();
471
                                String layerName = getLayerName(entity, layerTable);
472
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
473
                                int color = entity.getColor();
474
                                int colorByLayer = getColorByLayer(entity, layerTable);
475
                                //if (color==0) color ByBlock
476
                                if (color==256) color = colorByLayer;
477
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
478
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
479
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
480
                    // Attributes
481
                    /*for (int j=0;j<nAtt;j++) {
482
                                    String[] attributes = new String[2];
483
                                    attributes = (String[])featureMaker.getAttributes().get(j);
484
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
485
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
486
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
487
                        }
488
                    }*/
489
                                //addShape(point, auxRow);
490
                        } else if (entity.getType()==0x31) {
491
                                //System.out.println("Encuentra un Block Header ...");
492
                                //addingToBlock = true;
493
                                //pto = (Point2D.Double)point.get(0);
494
                                //FShape nuevoShp;
495
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
496
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Header"));
497
                                //int[] layerHandle = (int[])entity.getLayer();
498
                                String layerName = getLayerName(entity, layerTable);
499
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
500
                                int color = entity.getColor();
501
                                int colorByLayer = getColorByLayer(entity, layerTable);
502
                                //if (color==0) color ByBlock
503
                                if (color==256) color = colorByLayer;
504
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
505
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
506
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
507
                    // Attributes
508
                    /*for (int j=0;j<nAtt;j++) {
509
                                    String[] attributes = new String[2];
510
                                    attributes = (String[])featureMaker.getAttributes().get(j);
511
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
512
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
513
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
514
                        }
515
                    }*/
516
                                //addShape(point, auxRow);
517
                        //} else if (entity.getType()==0x7 && !addingToBlock) {
518
                        } else if (entity.getType()==0x7) {
519
                                //System.out.println("Encuentra un Insert ...");
520
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
521
                                //double[] p = (double[])data.getValue();
522
                                double[] p = ((DwgInsert)entity).getInsertionPoint();
523
                                Point2D point = new Point2D.Double(p[0], p[1]);
524
                                //data = entity.getDwgObjectSpecificDataItem("SCALE");
525
                                //double[] scale = (double[])data.getValue();
526
                                double[] scale = ((DwgInsert)entity).getScale();
527
                                //data = entity.getDwgObjectSpecificDataItem("ROTATION");
528
                //double rot = ((Double)data.getValue()).doubleValue();
529
                                double rot = ((DwgInsert)entity).getRotation();
530
                                //data = entity.getDwgObjectSpecificDataItem("BLOCK_HEADER_HANDLE");
531
                                //int[] blockHandle = (int[])data.getValue();
532
                                int blockHandle = ((DwgInsert)entity).getBlockHeaderHandle();
533
                                
534
                                //manageInsert(dwgObjects, layerTable, point, scale, rot, blockHandle, i, auxRow);
535
                                
536
                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
537
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Insert"));
538
                                //int[] layerHandle = (int[])entity.getLayer();
539
                                String layerName = getLayerName(entity, layerTable);
540
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
541
                                int color = entity.getColor();
542
                                int colorByLayer = getColorByLayer(entity, layerTable);
543
                                //if (color==0) color ByBlock
544
                                if (color==256) color = colorByLayer;
545
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
546
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
547
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
548
                    // Attributes
549
                    /*for (int j=0;j<nAtt;j++) {
550
                                    String[] attributes = new String[2];
551
                                    attributes = (String[])featureMaker.getAttributes().get(j);
552
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
553
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
554
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
555
                        }
556
                    }*/
557
                    FPoint2D fPoint = new FPoint2D(point.getX(), point.getY());
558
                                addShape(fPoint, auxRow);
559
                        //} else if (entity.getType()==0x2C && !addingToBlock) {
560
                        } else if (entity.getType()==0x2C) {
561
                                //System.out.println("Encuentra un MText ...");
562
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
563
                                //double[] coord = (double[])data.getValue();
564
                                //Point2D p = new Point2D.Double(coord[0], coord[1]);
565
                                double[] p = ((DwgMText)entity).getInsertionPoint();
566
                                FPoint2D point = new FPoint2D(p[0], p[1]);
567
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
568
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("MText"));
569
                                //int[] layerHandle = (int[])entity.getLayer();
570
                                String layerName = getLayerName(entity, layerTable);
571
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
572
                                int color = entity.getColor();
573
                                int colorByLayer = getColorByLayer(entity, layerTable);
574
                                //if (color==0) color ByBlock
575
                                if (color==256) color = colorByLayer;
576
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
577
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
578
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
579
                    // Attributes
580
                    /*for (int j=0;j<nAtt;j++) {
581
                                    String[] attributes = new String[2];
582
                                    attributes = (String[])featureMaker.getAttributes().get(j);
583
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
584
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
585
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
586
                        }
587
                    }*/
588
                                addShape(point, auxRow);
589
                        //} else if (entity.getType()==0x1F && !addingToBlock) {
590
                        } else if (entity.getType()==0x1F) {
591
                                //System.out.println("Encuentra un Solid ...");
592
                                //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CORNER1");
593
                                //double[] coord = (double[])data.getValue();
594
                                //Point2D p1 = new Point2D.Double(coord[0], coord[1]);
595
                                double[] p1 = ((DwgSolid)entity).getCorner1();
596
                                //data = entity.getDwgObjectSpecificDataItem("CORNER2");
597
                                //coord = (double[])data.getValue();
598
                                //Point2D p2 = new Point2D.Double(coord[0], coord[1]);
599
                                double[] p2 = ((DwgSolid)entity).getCorner2();
600
                                //data = entity.getDwgObjectSpecificDataItem("CORNER3");
601
                                //coord = (double[])data.getValue();
602
                                //Point2D p3 = new Point2D.Double(coord[0], coord[1]);
603
                                double[] p3 = ((DwgSolid)entity).getCorner3();
604
                                //data = entity.getDwgObjectSpecificDataItem("CORNER4");
605
                                //coord = (double[])data.getValue();
606
                                //Point2D p4 = new Point2D.Double(coord[0], coord[1]);
607
                                double[] p4 = ((DwgSolid)entity).getCorner4();
608
                                FPolygon2D solid = points2DToFPolygon2D(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])});
609
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
610
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Solid"));
611
                                //int[] layerHandle = (int[])entity.getLayer();
612
                                String layerName = getLayerName(entity, layerTable);
613
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
614
                                int color = entity.getColor();
615
                                int colorByLayer = getColorByLayer(entity, layerTable);
616
                                //if (color==0) color ByBlock
617
                                if (color==256) color = colorByLayer;
618
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
619
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
620
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
621
                    // Attributes
622
                    /*for (int j=0;j<nAtt;j++) {
623
                                    String[] attributes = new String[2];
624
                                    attributes = (String[])featureMaker.getAttributes().get(j);
625
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
626
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
627
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
628
                        }
629
                    }*/
630
                                addShape(solid, auxRow);
631
                        //} else if (entity.getType()==0x2 && !addingToBlock) {
632
                        } else if (entity.getType()==0x2) {
633
                                //System.out.println("Encuentra un Attrib ...");
634
                        /*} else if (entity.getType()==0x3 && !addingToBlock) {
635
                                System.out.println("Encuentra un Attdef ...");*/
636
                        } else if (dwg.getDxfNames().size()>0) {
637
                                int type = 0;
638
                                for (int j=0; j<dwg.getDxfNames().size(); j++) {
639
                                        String dxfName = ((DxfName)dwg.getDxfNames().get(j)).getDxfName();
640
                                        if (dxfName.equals("LWPOLYLINE")) {
641
                                                type = ((DxfName)dwg.getDxfNames().get(j)).getKey();
642
                                                break;
643
                                        }
644
                                }
645
                                if (entity.getType()==type) {
646
                                        //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("VERTICES");
647
                                        //Vector vertices = (Vector)data.getValue();
648
                                        //Point2D[] pts = new Point2D[vertices.size()];
649
                                        Point2D[] pts = ((DwgLwPolyline)entity).getVertices();
650
                                        /*double[] pt = new double[2];
651
                                        for (int j=0; j<vertices.size(); j++) {
652
                                                 pt = (double[])vertices.get(j);
653
                                                 pts[j] = new Point2D.Double(pt[0], pt[1]);
654
                                        }*/
655
                                        FPolyline2D lwpline = points2DToFPolyline2D(pts);
656
                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
657
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("LwPolyline"));
658
                                        //int[] layerHandle = (int[])entity.getLayer();
659
                                        String layerName = getLayerName(entity, layerTable);
660
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
661
                                        int color = entity.getColor();
662
                                        int colorByLayer = getColorByLayer(entity, layerTable);
663
                                        //if (color==0) color ByBlock
664
                                        if (color==256) color = colorByLayer;
665
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
666
                            auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
667
                            auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
668
                            // Attributes
669
                            /*for (int j=0;j<nAtt;j++) {
670
                                            String[] attributes = new String[2];
671
                                            attributes = (String[])featureMaker.getAttributes().get(j);
672
                                auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
673
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
674
                                        auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
675
                                }
676
                            }*/
677
                                        addShape(lwpline, auxRow);
678
                                }
679
                        } else {
680
                                System.out.println("Detectado dwgObject pendiente de implementar");
681
                        }
682
                }
683
                timeElapsed = System.currentTimeMillis()-time;
684
                System.out.println("Tiempo empleado por el driver en importar el contenido del dwg = " + timeElapsed);
685
                
686
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
687
                defaultLegend.setFieldName("Color");
688
                defaultLegend.setLabelField("Text");
689
                defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
690
                defaultLegend.getDefaultSymbol().setShapeVisible(false);
691
                defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
692
                defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9));
693
                defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
694
                defaultLegend.getDefaultSymbol().setFontSize(heightText);
695
                defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
696
                defaultLegend.getDefaultSymbol().setSize(3);
697
                defaultLegend.getDefaultSymbol().setSizeInPixels(true);
698
                
699
                defaultLegend.setLabelHeightField("HeightText");
700
                defaultLegend.setLabelRotationField("RotationText");
701
                
702
        ObjectDriver rs = this;
703
                IntValue clave;
704
                FSymbol theSymbol = null;
705
                
706
                try {
707
                    // Provisional hasta que cambiemos los s?mbolos.
708
                   /*  BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
709
                   Graphics2D big = bi.createGraphics();
710
                   Color color=new Color(0,0,0,0);
711
                   big.setBackground(color);
712
                   big.clearRect(0, 0, 5, 5);
713
                   Paint fillProv = null; 
714
                   Rectangle2D rProv = new Rectangle();
715
                   rProv.setFrame(0, 0,5,5);
716
                   fillProv = new TexturePaint(bi,rProv); */                    
717
                    
718
                        for (long j = 0; j < rs.getRowCount(); j++)
719
                        {
720
                                clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR);
721
                                if (defaultLegend.getSymbolByValue(clave) == null)
722
                                {
723
                                        theSymbol = new FSymbol(getShapeType());
724
                                        theSymbol.setDescription(clave.toString());
725
                                        theSymbol.setColor(AcadColor.getColor(clave.getValue()));
726
                                        // theSymbol.setFill(fillProv);
727
                                        // 050202, jmorell: Asigna los colores de Autocad a los bordes
728
                                        //                                        de los pol?gonos.
729
                                        theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue()));
730
                                        
731
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
732
                                        theSymbol.setSize(3);
733
                                        theSymbol.setSizeInPixels(true);
734
                                        
735
                                        defaultLegend.addSymbol(clave, theSymbol);
736
                                }
737
                        } // for
738
                } catch (DriverException e) {
739
                        e.printStackTrace();
740
                        throw new IOException("Error al poner la leyenda por defecto en el Dwg");
741
                }
742
        }
743
        
744
        /**
745
         * En principio exportamos a FPolyline2D, despues estudiaremos la conveniencia
746
         * de exportar a FPolygon2D, o a las dos cosas ...
747
         * Esta clase construye el circle del mismo modo que en DxfFeatureMaker.
748
         * Se podr?a renombrar esta clase a createCircleFeature y a?adir otra
749
         * createCircleEntity ...
750
         * La parte de creaci?n de la FPolyline2D est? sacada del DxfMemoryDriver ...
751
         * @param center
752
         * @param radius
753
         * @return
754
         */
755
        /*private FPolyline2D createCircle(Point2D c, double r) {
756
                Point2D[] pts = new Point2D[360];
757
                int angulo = 0;
758
                for (angulo=0; angulo<360; angulo++) {
759
                        pts[angulo] = new Point2D.Double(c.getX(), c.getY());
760
                        pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0));
761
                }
762
                GeneralPathX genPathX = new GeneralPathX();
763
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
764
                for (int i=1; i<pts.length; i++) {
765
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
766
                }
767
                return new FPolyline2D(genPathX);
768
        }*/
769
        
770
        /**
771
         * Como createCircle ...
772
         * @param c
773
         * @param r
774
         * @param sa
775
         * @param ea
776
         * @return
777
         */
778
        /*private Point2D[] createArc(Point2D c, double r, double sa, double ea) {
779
                int isa = (int)sa;
780
                int iea = (int)ea;
781
                double angulo;
782
                Point2D[] pts;
783
                if (sa <= ea) {
784
                        pts = new Point2D[(iea-isa)+2];
785
                        angulo = sa;
786
                        pts[0] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
787
                        for (int i=1; i<=(iea-isa)+1; i++) {
788
                                angulo = (double)(isa+i);
789
                                pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
790
                        }
791
                        angulo = ea;
792
                        pts[(iea-isa)+1] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
793
                } else {
794
                        pts = new Point2D[(360-isa)+iea+2];
795
                        angulo = sa;
796
                        pts[0] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
797
                        for (int i=1; i<=(360-isa); i++) {
798
                                angulo = (double)(isa+i);
799
                                pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
800
                        }
801
                        for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) {
802
                                angulo = (double)(i-(360-isa));
803
                                pts[i] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
804
                        }
805
                        angulo = ea;
806
                        pts[(360-isa)+iea+1] = new Point2D.Double(c.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), c.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
807
                }
808
                return pts;*/
809
                /*GeneralPathX genPathX = new GeneralPathX();
810
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
811
                for (int i=1; i<pts.length; i++) {
812
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
813
                }
814
                return new FPolyline2D(genPathX);*/
815
        //}
816
        
817
        /**
818
         * Los nombres de estos m?todos pueden cambiarse por otros m?s apropiados, por
819
         * ejemplo:
820
         * createLine --> dwgLineToFPolyline2D ... ?mejor as?? ...
821
         * @param p1
822
         * @param p2
823
         * @return
824
         */
825
        /*private FPolyline2D createLine(Point2D p1, Point2D p2) {
826
                Point2D[] pts = new Point2D[]{p1, p2};
827
                GeneralPathX genPathX = new GeneralPathX();
828
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
829
                for (int i=1; i<pts.length; i++) {
830
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
831
                }
832
                return new FPolyline2D(genPathX);
833
        }*/
834
        
835
        /*private FPoint2D createPoint(Point2D p) {
836
                return new FPoint2D(p.getX(), p.getY());
837
        }*/
838
        
839
        /*private FPolyline2D createLwPolyline(Point2D[] pts) {
840
                GeneralPathX genPathX = new GeneralPathX();
841
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
842
                for (int i=1; i<pts.length; i++) {
843
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
844
                }
845
                return new FPolyline2D(genPathX);
846
        }*/
847
        
848
        //private FPolyline2D createPolyline3D(Point2D[] pts) {
849
        private FPolyline2D points2DToFPolyline2D(Point2D[] pts) {
850
                GeneralPathX genPathX = new GeneralPathX();
851
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
852
                for (int i=1; i<pts.length; i++) {
853
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
854
                }
855
                return new FPolyline2D(genPathX);
856
        }
857
        
858
        private FPolygon2D points2DToFPolygon2D(Point2D[] pts) {
859
                GeneralPathX genPathX = new GeneralPathX();
860
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
861
                for (int i=1; i<pts.length; i++) {
862
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
863
                }
864
                genPathX.closePath();
865
                return new FPolygon2D(genPathX);
866
        }
867
        
868
        /*private FPolyline2D createPolyline2D(Point2D[] inPts, Vector bulges) {
869
                Vector pts = new Vector();
870
                Point2D init = new Point2D.Double();
871
                Point2D end = new Point2D.Double();
872
                for (int i=0; i<inPts.length; i++) {
873
                        init = inPts[i];
874
                        if (i!=inPts.length-1) end = inPts[i+1];
875
                        if (((Double)bulges.get(i)).doubleValue()==0 || i==inPts.length-1) {
876
                                pts.add(init);
877
                        } else {
878
                                ArcFromBulgeCalculator arcCalculator = new ArcFromBulgeCalculator(init, end, ((Double)bulges.get(i)).doubleValue());
879
                                Vector arc = arcCalculator.getPoints(1);
880
                                for (int j=0;j<arc.size();j++) {
881
                                        pts.add(arc.get(j));
882
                                }
883
                                pts.remove(pts.size()-1);
884
                        }
885
                }
886
                GeneralPathX genPathX = new GeneralPathX();
887
                genPathX.moveTo(((Point2D)pts.get(0)).getX(), ((Point2D)pts.get(0)).getY());
888
                for (int i=1; i<pts.size(); i++) {
889
                        genPathX.lineTo(((Point2D)pts.get(i)).getX(), ((Point2D)pts.get(i)).getY());
890
                }
891
                return new FPolyline2D(genPathX);
892
        }*/
893
                
894
        /*private int calculateVertexNumber(int[] firstVertexHandle, int[] lastVertexHandle) {
895
                if (firstVertexHandle.length==lastVertexHandle.length) {
896
                        if (firstVertexHandle[firstVertexHandle.length-2]==lastVertexHandle[firstVertexHandle.length-2]) {
897
                                return (lastVertexHandle[firstVertexHandle.length-1]-firstVertexHandle[firstVertexHandle.length-1]+1);
898
                        } else {
899
                                int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1;
900
                                int aux2 = lastVertexHandle[firstVertexHandle.length-1]+1;
901
                                int aux3 = (lastVertexHandle[firstVertexHandle.length-2]-firstVertexHandle[firstVertexHandle.length-2]-1)*255;
902
                                int vn = aux + aux2 + aux3;
903
                                return vn;
904
                        }
905
                } else if (firstVertexHandle.length==(lastVertexHandle.length-1)) {
906
                        int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1;
907
                        int aux2 = lastVertexHandle[firstVertexHandle.length]+1;
908
                        int aux3 = (lastVertexHandle[lastVertexHandle.length-2]-1)*255;
909
                        int vn = aux + aux2 + aux3;
910
                        return vn;
911
                } else {
912
                        System.out.println("ERROR: firstVertexHandle y lastVertexHandle tienen tama?os inesperados");
913
                        return 0;
914
                }
915
        }*/
916
        
917
        /*private void manageInsert(Vector dwgObjects, Vector layerTable, Point2D insPoint, double[] scale, double rot, int bHandle, int id, Value[] auxRow) {
918
                for (int j=0;j<dwgObjects.size();j++) {
919
                        DwgObject obj = (DwgObject)dwgObjects.get(j);
920
                        //DwgObjectSpecificDataItem dataa = obj.getDwgObjectSpecificDataItem("BLOCK_ENTITY_HANDLE");
921
                        //System.out.println("obj.getType() = " + obj.getType());
922
                        //System.out.println("dataa = " + dataa);
923
                        //if (dataa!=null) {
924
                        if (obj instanceof DwgBlockHeader) {
925
                                int objHandle = ((DwgBlockHeader)obj).getBlockEntityHandle();
926
                                //System.out.println("objHandle = " + objHandle);
927
                                //System.out.println("bHandle = " + bHandle);
928
                                //if (objHandle==bHandle+1 && handle[1]==blockHandle[1]) {
929
                                if (objHandle==bHandle+1) {
930
                                        //obj = (DwgObject)dwgObjects.get(j+1);
931
                                        //System.out.println("Hemos encontrado el bloque");
932
                                        //System.out.println("obj.getType() = " + obj.getType());
933
                                        //DwgObjectSpecificDataItem data = obj.getDwgObjectSpecificDataItem("BASE_POINT");
934
                                        //double[] bPoint = (double[])data.getValue();
935
                                        double[] bPoint = ((DwgBlockHeader)obj).getBasePoint();
936
                                        //System.out.println("bPoint[0] = " + bPoint[0]);
937
                                        //System.out.println("bPoint[1] = " + bPoint[1]);
938
                                        //data = obj.getDwgObjectSpecificDataItem("FIRST_ENTITY_HANDLE");
939
                                        //System.out.println("firstHandle = " + firstHandle);
940
                                        int firstHandle = ((DwgBlockHeader)obj).getFirstEntityHandle();
941
                                        int lastHandle = ((DwgBlockHeader)obj).getLastEntityHandle();
942
                                        // Buscando la capa y el color del bloque ...
943
                                        //String bname = (String)obj.getDwgObjectSpecificDataItem("NAME").getValue();
944
                                        String bname = ((DwgBlockHeader)obj).getName();
945
                                        //int[] blockHandleLayer = null;
946
                                        //int blockColor = 0;
947
                                        DwgObject block = null;
948
                                        for (int k=0;k<dwgObjects.size();k++) {
949
                                                DwgObject ent = (DwgObject)dwgObjects.get(k);
950
                                                if (ent.getType()==0x4) {
951
                                                        //String name = (String)obj.getDwgObjectSpecificDataItem("NAME").getValue();
952
                                                        String name = ((DwgBlockHeader)obj).getName();
953
                                                        if (bname.equals(name)) {
954
                                                                //blockHandleLayer = ent.getLayer();
955
                                                                //blockColor = ent.getColor();
956
                                                                block = ent;
957
                                                        }
958
                                                }
959
                                        }
960
                                        
961
                                        for (int k=0;k<dwgObjects.size();k++) {
962
                                                DwgObject ent = (DwgObject)dwgObjects.get(k);
963
                                                int eHandle = ent.getHandle();
964
                                                //System.out.println("eHandle = " + eHandle);
965
                                                //if (eHandle==firstHandle && ((Integer)entHandle.get(1)).intValue()==firstEntityHandle[1]) {
966
                                                if (eHandle==firstHandle) {
967
                                                        //System.out.println("Hemos encontrado el primer elemento");
968
                                                        int l=0;
969
                                                        while (true) {
970
                                                                DwgObject blockEntity = (DwgObject)dwgObjects.get(k+l);
971
                                                                int bEntityHandle = blockEntity.getHandle();
972
                                                                manageBlockEntity(blockEntity, layerTable, bPoint, insPoint, scale, rot, block, id, auxRow);
973
                                                                l++;
974
                                                                //if (bEntityHandle==lastHandle && ((Integer)entHandle.get(1)).intValue()==lastEntityHandle[1]) {
975
                                                                if (bEntityHandle==lastHandle) {
976
                                                                        break;
977
                                                                }
978
                                                        }
979
                                                }
980
                                        }
981
                                }
982
                        }
983
                }
984
        }*/
985
        
986
        /*private void manageBlockEntity(DwgObject entity, Vector layerTable, double[] bPoint, Point2D insPoint, double[] scale, double rot, DwgObject block, int id, Value[] auxRow) {
987
                if (entity.getType()==0x11) {
988
                        //System.out.println("Encuentra un arco dentro de un bloque ...");
989
                        //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
990
                        //double[] coord = (double[])data.getValue();
991
                        //Point2D center = new Point2D.Double(coord[0], coord[1]);
992
                        double[] center = ((DwgArc)entity).getCenter();
993
                        //data = entity.getDwgObjectSpecificDataItem("RADIUS");
994
                        //double radius = ((Double)data.getValue()).doubleValue();
995
                        double radius = ((DwgArc)entity).getRadius();
996
                        //data = entity.getDwgObjectSpecificDataItem("START_ANGLE");
997
                        //double startAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
998
                        double initAngle = ((DwgArc)entity).getInitAngle();
999
                        //data = entity.getDwgObjectSpecificDataItem("END_ANGLE");
1000
                        //double endAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
1001
                        double endAngle = ((DwgArc)entity).getEndAngle();
1002
                        //FPolyline2D arc = createArc(center, radius, startAngle, endAngle);
1003
                        Point2D[] arc = GisModelCurveCalculator.calculateGisModelArc(new Point2D.Double(center[0], center[1]), radius, initAngle, endAngle);
1004
                        for (int i=0;i<arc.length;i++) {
1005
                                Point2D pointAux = new Point2D.Double(arc[i].getX() - bPoint[0], arc[i].getY() - bPoint[1]);
1006
                                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1007
                                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1008
                                arc[i] = new Point2D.Double(laX, laY);
1009
                        }
1010
                        FPolyline2D arcc = points2DToFPolyline2D(arc);
1011
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1012
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc"));
1013
                        String layerName = getLayerName(block, layerTable);
1014
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1015
                        int color = entity.getColor();
1016
                        int colorByLayer = getColorByLayer(entity, layerTable);
1017
                        int colorByBlock = getColorByLayer(block, layerTable);
1018
                        if (color==0) color = colorByBlock;
1019
                        if (color==256) color = colorByLayer;
1020
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1021
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1022
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1023
                        addShape(arcc, auxRow);
1024
                } else if (entity.getType()==0x12) {
1025
                        //System.out.println("Encuentra un c?rculo dentro de un bloque ...");
1026
                        //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
1027
                        //double[] coord = (double[])data.getValue();
1028
                        //Point2D center = new Point2D.Double(coord[0], coord[1]);
1029
                        double[] c = ((DwgCircle)entity).getCenter();
1030
                        //data = entity.getDwgObjectSpecificDataItem("RADIUS");
1031
                        //double radius = ((Double)data.getValue()).doubleValue();
1032
                        double radius = ((DwgCircle)entity).getRadius();
1033
                        Point2D center = new Point2D.Double(c[0], c[1]);
1034
                        Point2D pointAux = new Point2D.Double(center.getX() - bPoint[0], center.getY() - bPoint[1]);
1035
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*(-1)*Math.sin(Math.toRadians(rot)));
1036
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*Math.cos(Math.toRadians(rot)));
1037
                        center = new Point2D.Double(laX, laY);
1038
                        // Escala en X = escala en Y ...
1039
                        radius = radius * scale[0];
1040
                        
1041
                        Point2D[] circlePts = GisModelCurveCalculator.calculateGisModelCircle(center, radius);
1042
            FPolyline2D circle = points2DToFPolyline2D(circlePts);
1043
                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1044
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle"));
1045
                        String layerName = getLayerName(block, layerTable);
1046
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1047
                        int color = entity.getColor();
1048
                        int colorByLayer = getColorByLayer(entity, layerTable);
1049
                        int colorByBlock = getColorByLayer(block, layerTable);
1050
                        if (color==0) color = colorByBlock;
1051
                        if (color==256) color = colorByLayer;
1052
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1053
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1054
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1055
                        addShape(circle, auxRow);
1056
                } else if (entity.getType()==0x13) {
1057
                        //System.out.println("Encuentra una l?nea dentro de un bloque ...");
1058
                        //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1");
1059
                        //double[] coord = (double[])data.getValue();
1060
                        //Point2D p1 = new Point2D.Double(coord[0], coord[1]);
1061
                        double[] p1d = ((DwgLine)entity).getP1();
1062
                        Point2D p1 = new Point2D.Double(p1d[0], p1d[1]);
1063
                        //data = entity.getDwgObjectSpecificDataItem("P2");
1064
                        //coord = (double[])data.getValue();
1065
                        //Point2D p2 = new Point2D.Double(coord[0], coord[1]);
1066
                        double[] p2d = ((DwgLine)entity).getP2();
1067
                        Point2D p2 = new Point2D.Double(p2d[0], p2d[1]);
1068
                        Point2D pointAux = new Point2D.Double(p1.getX() - bPoint[0], p1.getY() - bPoint[1]);
1069
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1070
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1071
                        p1 = new Point2D.Double(laX, laY);
1072
                        pointAux = new Point2D.Double(p2.getX() - bPoint[0], p2.getY() - bPoint[1]);
1073
                        laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1074
                        laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1075
                        p2 = new Point2D.Double(laX, laY);
1076
                        //FPolyline2D line = createLine(p1, p2);
1077
                        Point2D[] l = new Point2D[]{p1, p2};
1078
                        FPolyline2D line = points2DToFPolyline2D(l);
1079
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1080
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line"));
1081
                        String layerName = getLayerName(block, layerTable);
1082
                        //System.out.println("layerName = " + layerName);
1083
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1084
                        int color = entity.getColor();
1085
                        int colorByLayer = getColorByLayer(entity, layerTable);
1086
                        int colorByBlock = getColorByLayer(block, layerTable);
1087
                        if (color==0) color = colorByBlock;
1088
                        if (color==256) color = colorByLayer;
1089
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1090
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1091
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1092
                        addShape(line, auxRow);
1093
                } else if (entity.getType()==0x7) {
1094
                        //System.out.println("Encuentra un insert dentro de un bloque ...");
1095
                        //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
1096
                        //double[] p = (double[])data.getValue();
1097
                        //Point2D newInsPoint = new Point2D.Double(p[0], p[1]);
1098
                        double[] p = ((DwgInsert)entity).getInsertionPoint();
1099
                        Point2D newInsPoint = new Point2D.Double(p[0], p[1]);
1100
                        //data = entity.getDwgObjectSpecificDataItem("SCALE");
1101
                        //double[] newScale = (double[])data.getValue();
1102
                        double[] newScale = ((DwgInsert)entity).getScale();
1103
                        //data = entity.getDwgObjectSpecificDataItem("ROTATION");
1104
            //double newRot = ((Double)data.getValue()).doubleValue();
1105
                        double newRot = ((DwgInsert)entity).getRotation();
1106
                        //data = entity.getDwgObjectSpecificDataItem("BLOCK_HEADER_HANDLE");
1107
                        //int[] newBlockHandle = (int[])data.getValue();
1108
                        int newBlockHandle = ((DwgInsert)entity).getBlockHeaderHandle();
1109
                        Point2D pointAux = new Point2D.Double(newInsPoint.getX() - bPoint[0], newInsPoint.getY() - bPoint[1]);
1110
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1111
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1112
                        newInsPoint = new Point2D.Double(laX, laY);
1113
                        
1114
                        newScale = new double[]{scale[0]*newScale[0], scale[1]*newScale[1], scale[2]*newScale[2]};
1115
                        
1116
                        manageInsert(dwgObjects, layerTable, newInsPoint, newScale, newRot, newBlockHandle, id, auxRow);
1117
                } else if (entity.getType()==0x0F) {*/
1118
                        //System.out.println("Encuentra una polil?nea dentro de un bloque ...");
1119
                        //DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("FLAGS");
1120
                        //int flags = ((Integer)data.getValue()).intValue();
1121
                        /*int flags = ((DwgPolyline2D)entity).getFlags();
1122
                        int firstHandle = ((DwgPolyline2D)entity).getFirstVertexHandle();
1123
                        int lastHandle = ((DwgPolyline2D)entity).getLastVertexHandle();
1124
                        Vector pts = new Vector();
1125
                        Vector bulges = new Vector();
1126
                        double[] pt = new double[2];
1127
                        
1128
                        for (int j=0;j<dwgObjects.size();j++) {
1129
                                DwgObject obj = (DwgObject)dwgObjects.get(j);
1130
                                int objHandle = obj.getHandle();
1131
                                //if (objHandle==firstHandle && ((Integer)handle.get(1)).intValue()==firstVertexHandle[1]) {
1132
                                if (objHandle==firstHandle) {
1133
                                        int k=0;
1134
                                        while (true) {
1135
                                                DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
1136
                                                int vHandle = vertex.getHandle();
1137
                                                pt = ((DwgVertex2D)vertex).getPoint();
1138
                                                pts.add(new Point2D.Double(pt[0], pt[1]));
1139
                                                double bulge = ((DwgVertex2D)vertex).getBulge();
1140
                                                bulges.add(new Double(bulge));
1141
                                                k++;
1142
                                                //if (vHandle==lastHandle && ((Integer)vertexHandle.get(1)).intValue()==lastVertexHandle[1]) {
1143
                                                if (vHandle==lastHandle) {
1144
                                                        break;
1145
                                                }
1146
                                        }
1147
                                }
1148
                        }
1149
                        
1150
                        Point2D[] newPts = new Point2D[pts.size()];
1151
                        if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
1152
                                for (int j=0;j<pts.size();j++) {
1153
                                        newPts[j] = (Point2D)pts.get(j);
1154
                                }
1155
                        } else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
1156
                                newPts = new Point2D[pts.size()+1];
1157
                                for (int j=0;j<pts.size();j++) {
1158
                                        newPts[j] = (Point2D)pts.get(j);
1159
                                }
1160
                                newPts[pts.size()] = (Point2D)pts.get(0);
1161
                                bulges.add(new Double(0));
1162
                        }*/
1163
                        /*Point2D[] points = ((DwgPolyline2D)entity).getPts();
1164
                        for (int i=0;i<points.length;i++) {
1165
                                Point2D pointAux = new Point2D.Double(points[i].getX() - bPoint[0], points[i].getY() - bPoint[1]);
1166
                                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1167
                                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1168
                                points[i] = new Point2D.Double(laX, laY);
1169
                        }
1170
                        //FPolyline2D pline = createPolyline2D(newPts, bulges);
1171
                        FPolyline2D pline = points2DToFPolyline2D(points);
1172
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1173
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D"));
1174
                        String layerName = getLayerName(block, layerTable);
1175
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1176
                        int color = entity.getColor();
1177
                        int colorByLayer = getColorByLayer(entity, layerTable);
1178
                        int colorByBlock = getColorByLayer(block, layerTable);
1179
                        if (color==0) color = colorByBlock;
1180
                        if (color==256) color = colorByLayer;
1181
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1182
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1183
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1184
                        addShape(pline, auxRow);
1185
                } else if (entity.getType()==0x2) {
1186
                        //System.out.println("Encuentra un Attrib dentro de un bloque ...");
1187
                } else if (entity.getType()==0x3) {
1188
                        //System.out.println("Encuentra un Attdef dentro de un bloque ...");
1189
                }
1190
        }*/
1191
        
1192
        /**
1193
         * LayerTable podr?a ser un objeto y LayerTableRecord tambi?n ...
1194
         * @param dwgObjects
1195
         * @return
1196
         */
1197
        private Vector createLayerTable(Vector dwgObjects) {
1198
                Vector layerTable = new Vector();
1199
                for (int i=0;i<dwgObjects.size();i++) {
1200
                        DwgObject obj = (DwgObject)dwgObjects.get(i);
1201
                        if (obj.getType()==0x33) {
1202
                                //System.out.println("Encuentra un objeto layer ...");
1203
                                Vector layerTableRecord = new Vector();
1204
                                layerTableRecord.add(new Integer(obj.getHandle()));
1205
                                //layerTableRecord.add(((String)obj.getDwgObjectSpecificDataItem("NAME").getValue()));
1206
                                //layerTableRecord.add(((Integer)obj.getDwgObjectSpecificDataItem("COLOR").getValue()));
1207
                                layerTableRecord.add(((DwgLayer)obj).getName());
1208
                                layerTableRecord.add(new Integer(((DwgLayer)obj).getColor()));
1209
                                layerTable.add(layerTableRecord);
1210
                        }
1211
                }
1212
                return layerTable;
1213
        }
1214
        
1215
        //private String setLayerName(int[] layerHandle, Vector layerTable) {
1216
        private String getLayerName(DwgObject entity, Vector layerTable) {
1217
                String layerName = "";
1218
                /*int[] layerHandle = (int[])entity.getLayer();
1219
                byte[] layerBytes = new byte[]{0,0,0,0};
1220
                if (layerHandle.length>2) layerBytes[3] = (byte)layerHandle[2];
1221
                if (layerHandle.length>3) layerBytes[2] = (byte)layerHandle[3];
1222
                if (layerHandle.length>4) layerBytes[1] = (byte)layerHandle[4];
1223
                if (layerHandle.length>5) layerBytes[0] = (byte)layerHandle[5];
1224
                int layer = ByteUtils.bytesToInt(layerBytes, new int[]{0});*/
1225
                int layer = entity.getLayerHandle();
1226
                for (int j=0;j<layerTable.size();j++) {
1227
                        Vector layerTableRecord = (Vector)layerTable.get(j);
1228
                        /*Vector layerHandleVect = (Vector)layerTableRecord.get(0);
1229
                        byte[] layerHandleBytes = new byte[]{0,0,0,0};
1230
                        if (layerHandleVect.size()>2) layerHandleBytes[3] = (byte)((Integer)layerHandleVect.get(2)).intValue();
1231
                        if (layerHandleVect.size()>3) layerHandleBytes[2] = (byte)((Integer)layerHandleVect.get(3)).intValue();
1232
                        if (layerHandleVect.size()>4) layerHandleBytes[1] = (byte)((Integer)layerHandleVect.get(4)).intValue();
1233
                        if (layerHandleVect.size()>5) layerHandleBytes[0] = (byte)((Integer)layerHandleVect.get(5)).intValue();
1234
                        int lHandle = ByteUtils.bytesToInt(layerHandleBytes, new int[]{0});*/
1235
                        int lHandle = ((Integer)layerTableRecord.get(0)).intValue();
1236
                        if (lHandle==layer) {
1237
                                layerName = (String)layerTableRecord.get(1);
1238
                                //System.out.println("layerName = " + layerName);
1239
                        }
1240
                }
1241
                return layerName;
1242
        }
1243
        
1244
        private int getColorByLayer(DwgObject entity, Vector layerTable) {
1245
                int colorByLayer = 0;
1246
                /*int[] layerHandle = (int[])entity.getLayer();
1247
                byte[] layerBytes = new byte[]{0,0,0,0};
1248
                if (layerHandle.length>2) layerBytes[3] = (byte)layerHandle[2];
1249
                if (layerHandle.length>3) layerBytes[2] = (byte)layerHandle[3];
1250
                if (layerHandle.length>4) layerBytes[1] = (byte)layerHandle[4];
1251
                if (layerHandle.length>5) layerBytes[0] = (byte)layerHandle[5];
1252
                int layer = ByteUtils.bytesToInt(layerBytes, new int[]{0});*/
1253
                int layer = entity.getLayerHandle();
1254
                for (int j=0;j<layerTable.size();j++) {
1255
                        Vector layerTableRecord = (Vector)layerTable.get(j);
1256
                        /*Vector layerHandleVect = (Vector)layerTableRecord.get(0);
1257
                        byte[] layerHandleBytes = new byte[]{0,0,0,0};
1258
                        if (layerHandleVect.size()>2) layerHandleBytes[3] = (byte)((Integer)layerHandleVect.get(2)).intValue();
1259
                        if (layerHandleVect.size()>3) layerHandleBytes[2] = (byte)((Integer)layerHandleVect.get(3)).intValue();
1260
                        if (layerHandleVect.size()>4) layerHandleBytes[1] = (byte)((Integer)layerHandleVect.get(4)).intValue();
1261
                        if (layerHandleVect.size()>5) layerHandleBytes[0] = (byte)((Integer)layerHandleVect.get(5)).intValue();
1262
                        int lHandle = ByteUtils.bytesToInt(layerHandleBytes, new int[]{0});*/
1263
                        int lHandle = ((Integer)layerTableRecord.get(0)).intValue();
1264
                        if (lHandle==layer) {
1265
                                colorByLayer = ((Integer)layerTableRecord.get(2)).intValue();
1266
                                //System.out.println("colorByLayer = " + colorByLayerObj.intValue());
1267
                        }
1268
                }
1269
                return colorByLayer;
1270
        }
1271
                
1272
        /* (non-Javadoc)
1273
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
1274
         */
1275
        public boolean accept(File f) {
1276
                return f.getName().toUpperCase().endsWith("DWG");
1277
        }
1278

    
1279
        /* (non-Javadoc)
1280
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
1281
         */
1282
        public int getShapeType() {
1283
                return FShape.MULTI;
1284
        }
1285

    
1286
        /* (non-Javadoc)
1287
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
1288
         */
1289
        public String getName() {
1290
                return "gvSIG DWG Memory Driver";
1291
        }
1292

    
1293
        /* (non-Javadoc)
1294
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
1295
         */
1296
        public Legend getDefaultLegend() {
1297
                return defaultLegend;
1298
        }
1299

    
1300
    /* (non-Javadoc)
1301
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
1302
     */
1303
    public DriverAttributes getDriverAttributes() {
1304
        return attr;
1305
    }
1306

    
1307
}