Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dwg / DwgMemoryDriver.java @ 1883

History | View | Annotate | Download (74 KB)

1 1843 jmorell
/*
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 1869 jmorell
import net.jmorell.javacad.util.ArcFromBulgeCalculator;
55 1843 jmorell
import net.jmorell.jdwglib.dwg.DwgFile;
56
import net.jmorell.jdwglib.dwg.DwgObject;
57
import net.jmorell.jdwglib.dwg.DwgObjectSpecificDataItem;
58
import net.jmorell.jdwglib.dwg.DxfName;
59
60
import org.cresques.px.dxf.AcadColor;
61 1869 jmorell
import org.cresques.px.dxf.DxfCalArcs;
62 1867 jmorell
import org.cresques.px.dxf.DxfInsert;
63 1843 jmorell
64
import com.hardcode.gdbms.engine.data.driver.DriverException;
65
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
66
import com.hardcode.gdbms.engine.values.IntValue;
67
import com.hardcode.gdbms.engine.values.Value;
68
import com.hardcode.gdbms.engine.values.ValueFactory;
69
import com.iver.cit.gvsig.fmap.core.FPoint2D;
70
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
71
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
72
import com.iver.cit.gvsig.fmap.core.FShape;
73
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
74
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
75
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
76
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
77
import com.iver.cit.gvsig.fmap.drivers.MemoryDriver;
78
import com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend;
79
import com.iver.cit.gvsig.fmap.rendering.Legend;
80
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
81
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
82
83 1858 jmorell
import com.iver.cit.gvsig.fmap.drivers.dgn.ByteUtils;
84
85 1843 jmorell
public class DwgMemoryDriver extends MemoryDriver implements WithDefaultLegend {
86
        private final int ID_FIELD_ID=0;
87
        private final int ID_FIELD_ENTITY=1;
88
        private final int ID_FIELD_LAYER=2;
89
        private final int ID_FIELD_COLOR=3;
90
        private final int ID_FIELD_ELEVATION=4;
91
        private final int ID_FIELD_THICKNESS=5;
92
        private final int ID_FIELD_TEXT=6;
93
        private final int ID_FIELD_HEIGHTTEXT=7;
94
        private final int ID_FIELD_ROTATIONTEXT=8;
95
96
        VectorialUniqueValueLegend defaultLegend;
97
        private String path;
98
        private File m_Fich;
99
100
        private DwgFile dwg;
101
        private Vector dwgObjects;
102
        private DriverAttributes attr = new DriverAttributes();
103
104
        /* (non-Javadoc)
105
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#open(java.io.File)
106
         */
107
        public void open(File f) throws IOException {
108
            m_Fich = f;
109
        }
110
111
        public void initialize() throws IOException {
112
                float heightText = 10;
113
114
                attr.setLoadedInMemory(true);
115
116
                dwg = new DwgFile();
117 1858 jmorell
                long time = System.currentTimeMillis();
118 1843 jmorell
                dwg.read(m_Fich.getAbsolutePath());
119 1858 jmorell
                long timeElapsed = System.currentTimeMillis()-time;
120
                System.out.println("Tiempo empleado en leer el fichero dwg = " + timeElapsed);
121 1843 jmorell
                dwgObjects = dwg.getDwgObjects();
122
123
                //int nAtt = featureMaker.getAttributes().size();
124
125
                // Campos de las MemoryLayer:
126
            //Value[] auxRow = new Value[9+nAtt];
127
            Value[] auxRow = new Value[9];
128
                ArrayList arrayFields = new ArrayList();
129
                arrayFields.add("ID");
130
                arrayFields.add("Entity");
131
                arrayFields.add("Layer");
132
                arrayFields.add("Color");
133
                arrayFields.add("Elevation");
134
                arrayFields.add("Thickness");
135
                arrayFields.add("Text");
136
                arrayFields.add("HeightText");
137
                arrayFields.add("RotationText");
138
                /*for (int i=0;i<nAtt;i++) {
139
                        String att[] = new String[2];
140
                        att = (String[])featureMaker.getAttributes().get(i);
141
                        arrayFields.add(att[0]);
142
                }*/
143
144
            getTableModel().setColumnIdentifiers(arrayFields.toArray());
145
146 1867 jmorell
            boolean addingToBlock = false;
147
148 1858 jmorell
                time = System.currentTimeMillis();
149 1880 jmorell
150
                // Para intentar entender la manera de asignar la layer a cada elemento ...
151
                /*for (int i=0;i<dwgObjects.size();i++) {
152
                        DwgObject obj = (DwgObject)dwgObjects.get(i);
153
                        if (obj.getType()==0x33) {
154
                                System.out.println("obj.getHandle().get(0) = " + obj.getHandle().get(0));
155
                                System.out.println("obj.getHandle().get(1) = " + obj.getHandle().get(1));
156
                                if (obj.getHandle().size()>2) System.out.println("obj.getHandle().get(2) = " + obj.getHandle().get(2));
157
                                if (obj.getHandle().size()>3) System.out.println("obj.getHandle().get(3) = " + obj.getHandle().get(3));
158
                        }
159
                }*/
160
161
                Vector layerTable = createLayerTable(dwgObjects);
162
163 1843 jmorell
                for (int i=0;i<dwgObjects.size();i++) {
164
165
            auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(0);
166
            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0);
167
            auxRow[ID_FIELD_TEXT] = ValueFactory.createNullValue();
168
169
                        DwgObject entity = (DwgObject)dwgObjects.get(i);
170 1867 jmorell
                        if (entity.getType()==0x11 && !addingToBlock) {
171 1870 jmorell
                                System.out.println("Encuentra un Arc ...");
172 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
173
                                double[] coord = (double[])data.getValue();
174
                                Point2D center = new Point2D.Double(coord[0], coord[1]);
175
                                data = entity.getDwgObjectSpecificDataItem("RADIUS");
176
                                double radius = ((Double)data.getValue()).doubleValue();
177
                                data = entity.getDwgObjectSpecificDataItem("START_ANGLE");
178
                                double startAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
179
                                data = entity.getDwgObjectSpecificDataItem("END_ANGLE");
180
                                double endAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
181 1870 jmorell
                                Point2D[] arc = createArc(center, radius, startAngle, endAngle);
182
                                FPolyline2D arcc = createPolyline3D(arc);
183 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
184 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc"));
185 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
186 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
187
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
188
                                int color = entity.getColor();
189 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
190 1880 jmorell
                                //if (color==0) color ByBlock
191
                                if (color==256) color = colorByLayer;
192
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
193 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
194
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
195
                    // Attributes
196
                    /*for (int j=0;j<nAtt;j++) {
197
                                    String[] attributes = new String[2];
198
                                    attributes = (String[])featureMaker.getAttributes().get(j);
199
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
200
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
201
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
202
                        }
203
                    }*/
204 1870 jmorell
                                addShape(arcc, auxRow);
205 1867 jmorell
                        } else if (entity.getType()==0x12 && !addingToBlock) {
206 1870 jmorell
                                System.out.println("Encuentra un Circle ...");
207 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
208
                                double[] coord = (double[])data.getValue();
209
                                Point2D center = new Point2D.Double(coord[0], coord[1]);
210
                                data = entity.getDwgObjectSpecificDataItem("RADIUS");
211
                                double radius = ((Double)data.getValue()).doubleValue();
212
                                FPolyline2D circle = createCircle(center, radius);
213 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
214 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle"));
215 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
216 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
217
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
218
                                int color = entity.getColor();
219 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
220 1880 jmorell
                                //if (color==0) color ByBlock
221
                                if (color==256) color = colorByLayer;
222
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
223 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
224
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
225
                    // Attributes
226
                    /*for (int j=0;j<nAtt;j++) {
227
                                    String[] attributes = new String[2];
228
                                    attributes = (String[])featureMaker.getAttributes().get(j);
229
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
230
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
231
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
232
                        }
233
                    }*/
234
                                addShape(circle, auxRow);
235 1867 jmorell
                        } else if (entity.getType()==0x13 && !addingToBlock) {
236 1870 jmorell
                                System.out.println("Encuentra una Line ...");
237 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1");
238
                                double[] coord = (double[])data.getValue();
239
                                Point2D p1 = new Point2D.Double(coord[0], coord[1]);
240
                                data = entity.getDwgObjectSpecificDataItem("P2");
241
                                coord = (double[])data.getValue();
242
                                Point2D p2 = new Point2D.Double(coord[0], coord[1]);
243
                                FPolyline2D line = createLine(p1, p2);
244 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
245 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line"));
246 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
247 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
248
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
249
                                int color = entity.getColor();
250 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
251 1880 jmorell
                                //if (color==0) color ByBlock
252
                                if (color==256) color = colorByLayer;
253
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
254 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
255
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
256
                    // Attributes
257
                    /*for (int j=0;j<nAtt;j++) {
258
                                    String[] attributes = new String[2];
259
                                    attributes = (String[])featureMaker.getAttributes().get(j);
260
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
261
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
262
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
263
                        }
264
                    }*/
265
                                addShape(line, auxRow);
266 1867 jmorell
                        } else if (entity.getType()==0x1B && !addingToBlock) {
267 1870 jmorell
                                System.out.println("Encuentra un Point ...");
268 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("POINT");
269
                                double[] coord = (double[])data.getValue();
270
                                Point2D p = new Point2D.Double(coord[0], coord[1]);
271
                                FPoint2D point = createPoint(p);
272 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
273 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Point"));
274 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
275 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
276
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
277
                                int color = entity.getColor();
278 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
279 1880 jmorell
                                //if (color==0) color ByBlock
280
                                if (color==256) color = colorByLayer;
281
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
282 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
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(point, auxRow);
294 1867 jmorell
                        } else if (entity.getType()==0x0F && !addingToBlock) {
295 1870 jmorell
                                System.out.println("Encuentra una Polyline2D ...");
296 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("FLAGS");
297
                                int flags = ((Integer)data.getValue()).intValue();
298
                                data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE");
299
                                int[] firstVertexHandle = (int[])data.getValue();
300 1858 jmorell
                                byte[] firstHandleBytes = new byte[]{0,0,0,0};
301
                                if (firstVertexHandle.length>2) firstHandleBytes[3] = (byte)firstVertexHandle[2];
302
                                if (firstVertexHandle.length>3) firstHandleBytes[2] = (byte)firstVertexHandle[3];
303
                                if (firstVertexHandle.length>4) firstHandleBytes[1] = (byte)firstVertexHandle[4];
304
                                if (firstVertexHandle.length>5) firstHandleBytes[0] = (byte)firstVertexHandle[5];
305
                                int firstHandle = ByteUtils.bytesToInt(firstHandleBytes, new int[]{0});
306 1843 jmorell
                                data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE");
307
                                int[] lastVertexHandle = (int[])data.getValue();
308 1858 jmorell
                                byte[] lastHandleBytes = new byte[]{0,0,0,0};
309
                                if (lastVertexHandle.length>2) lastHandleBytes[3] = (byte)lastVertexHandle[2];
310
                                if (lastVertexHandle.length>3) lastHandleBytes[2] = (byte)lastVertexHandle[3];
311
                                if (lastVertexHandle.length>4) lastHandleBytes[1] = (byte)lastVertexHandle[4];
312
                                if (lastVertexHandle.length>5) lastHandleBytes[0] = (byte)lastVertexHandle[5];
313
                                int lastHandle = ByteUtils.bytesToInt(lastHandleBytes, new int[]{0});
314 1859 jmorell
                                Vector pts = new Vector();
315 1869 jmorell
                                Vector bulges = new Vector();
316 1853 jmorell
                                double[] pt = new double[2];
317
318 1858 jmorell
                                for (int j=0;j<dwgObjects.size();j++) {
319
                                        DwgObject obj = (DwgObject)dwgObjects.get(j);
320
                                        Vector handle = obj.getHandle();
321
                                        byte[] handleBytes = new byte[]{0,0,0,0};
322
                                        if (handle.size()>2) handleBytes[3] = ((Integer)handle.get(2)).byteValue();
323
                                        if (handle.size()>3) handleBytes[2] = ((Integer)handle.get(3)).byteValue();
324
                                        if (handle.size()>4) handleBytes[1] = ((Integer)handle.get(4)).byteValue();
325
                                        if (handle.size()>5) handleBytes[0] = ((Integer)handle.get(5)).byteValue();
326
                                        int objHandle = ByteUtils.bytesToInt(handleBytes, new int[]{0});
327 1861 jmorell
                                        if (objHandle==firstHandle && ((Integer)handle.get(1)).intValue()==firstVertexHandle[1]) {
328 1859 jmorell
                                                int k=0;
329
                                                while (true) {
330
                                                        DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
331
                                                        Vector vertexHandle = vertex.getHandle();
332
                                                        byte[] vHandleBytes = new byte[]{0,0,0,0};
333
                                                        if (vertexHandle.size()>2) vHandleBytes[3] = ((Integer)vertexHandle.get(2)).byteValue();
334
                                                        if (vertexHandle.size()>3) vHandleBytes[2] = ((Integer)vertexHandle.get(3)).byteValue();
335
                                                        if (vertexHandle.size()>4) vHandleBytes[1] = ((Integer)vertexHandle.get(4)).byteValue();
336
                                                        if (vertexHandle.size()>5) vHandleBytes[0] = ((Integer)vertexHandle.get(5)).byteValue();
337
                                                        int vHandle = ByteUtils.bytesToInt(vHandleBytes, new int[]{0});
338
                                                        data = vertex.getDwgObjectSpecificDataItem("POINT");
339
                                                        pt = (double[])data.getValue();
340
                                                        pts.add(new Point2D.Double(pt[0], pt[1]));
341 1869 jmorell
                                                        data = vertex.getDwgObjectSpecificDataItem("BULGE");
342
                                                        double bulge = ((Double)data.getValue()).doubleValue();
343
                                                        bulges.add(new Double(bulge));
344 1859 jmorell
                                                        k++;
345 1861 jmorell
                                                        if (vHandle==lastHandle && ((Integer)vertexHandle.get(1)).intValue()==lastVertexHandle[1]) {
346 1859 jmorell
                                                                break;
347
                                                        }
348 1853 jmorell
                                                }
349
                                        }
350
                                }
351 1859 jmorell
352
                                Point2D[] newPts = new Point2D[pts.size()];
353 1853 jmorell
                                if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
354 1859 jmorell
                                        for (int j=0;j<pts.size();j++) {
355 1858 jmorell
                                                newPts[j] = (Point2D)pts.get(j);
356 1859 jmorell
                                        }
357 1853 jmorell
                                } else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
358 1859 jmorell
                                        newPts = new Point2D[pts.size()+1];
359
                                        for (int j=0;j<pts.size();j++) {
360
                                                newPts[j] = (Point2D)pts.get(j);
361 1843 jmorell
                                        }
362 1859 jmorell
                                        newPts[pts.size()] = (Point2D)pts.get(0);
363 1869 jmorell
                                        bulges.add(new Double(0));
364 1843 jmorell
                                }
365 1869 jmorell
                                FPolyline2D pline = createPolyline2D(newPts, bulges);
366 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
367 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D"));
368 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
369 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
370
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
371
                                int color = entity.getColor();
372 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
373 1880 jmorell
                                //if (color==0) color ByBlock
374
                                if (color==256) color = colorByLayer;
375
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
376 1853 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
377
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
378
                    // Attributes
379
                    /*for (int j=0;j<nAtt;j++) {
380
                                    String[] attributes = new String[2];
381
                                    attributes = (String[])featureMaker.getAttributes().get(j);
382
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
383
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
384
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
385
                        }
386
                    }*/
387
                                addShape(pline, auxRow);
388 1869 jmorell
                        // Implementaci?n parcial ...
389 1867 jmorell
                        } else if (entity.getType()==0x10 && !addingToBlock) {
390 1870 jmorell
                                System.out.println("Encuentra una Polyline3D ...");
391 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CLOSED_FLAGS");
392
                                int flags = ((Integer)data.getValue()).intValue();
393
                                data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE");
394
                                int[] firstVertexHandle = (int[])data.getValue();
395
                                data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE");
396
                                int[] lastVertexHandle = (int[])data.getValue();
397
                                data = entity.getDwgObjectSpecificDataItem("SEQEND_HANDLE");
398
                                int[] seqendHandle = (int[])data.getValue();
399
                                int vertexNumber = calculateVertexNumber(firstVertexHandle, lastVertexHandle);
400
                                Point2D[] pts = new Point2D[vertexNumber];
401
                                double[] pt = new double[2];
402
403
                                for (int j=0;j<dwgObjects.size();j++) {
404
                                        DwgObject v = (DwgObject)dwgObjects.get(j);
405
                                        Vector handle = v.getHandle();
406 1853 jmorell
                                        if (((Integer)handle.get(handle.size()-2)).intValue()==firstVertexHandle[handle.size()-2] && ((Integer)handle.get(handle.size()-1)).intValue()==firstVertexHandle[handle.size()-1]) {
407
                                                for (int k=0; k<vertexNumber; k++) {
408
                                                        DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
409
                                                        data = vertex.getDwgObjectSpecificDataItem("POINT");
410
                                                        pt = (double[])data.getValue();
411
                                                        pts[k] = new Point2D.Double(pt[0], pt[1]);
412
                                                }
413
                                        }
414 1843 jmorell
                                }
415
                                Point2D[] newPts = new Point2D[pts.length];
416
                                if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
417
                                        newPts = pts;
418
                                } else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
419
                                        newPts = new Point2D[pts.length+1];
420
                                        for (int j=0;j<pts.length;j++) {
421
                                                newPts[j] = pts[j];
422
                                        }
423
                                        newPts[pts.length] = pts[0];
424
                                }
425 1869 jmorell
                                FPolyline2D pline3d = createPolyline3D(newPts);
426 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
427 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline3D"));
428 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
429 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
430
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
431
                                int color = entity.getColor();
432 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
433 1880 jmorell
                                //if (color==0) color ByBlock
434
                                if (color==256) color = colorByLayer;
435
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
436 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
437
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
438
                    // Attributes
439
                    /*for (int j=0;j<nAtt;j++) {
440
                                    String[] attributes = new String[2];
441
                                    attributes = (String[])featureMaker.getAttributes().get(j);
442
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
443
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
444
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
445
                        }
446
                    }*/
447
                                addShape(pline3d, auxRow);
448 1867 jmorell
                        } else if (entity.getType()==0x1 && !addingToBlock) {
449 1870 jmorell
                                System.out.println("Encuentra un Text ...");
450 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
451
                                Point2D p = (Point2D)data.getValue();
452
                                FPoint2D point = createPoint(p);
453 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
454 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Text"));
455 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
456 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
457
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
458
                                int color = entity.getColor();
459 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
460 1880 jmorell
                                //if (color==0) color ByBlock
461
                                if (color==256) color = colorByLayer;
462
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
463
                                data = entity.getDwgObjectSpecificDataItem("TEXT");
464
                                String text = (String)data.getValue();
465
                auxRow[ID_FIELD_TEXT] = ValueFactory.createValue(new String(text));
466
                                data = entity.getDwgObjectSpecificDataItem("HEIGHT");
467
                                heightText = ((Float)data.getValue()).floatValue();
468
                    auxRow[ID_FIELD_HEIGHTTEXT] = ValueFactory.createValue(heightText);
469
                                data = entity.getDwgObjectSpecificDataItem("DATA_FLAG");
470
                                int dflag = ((Integer)data.getValue()).intValue();
471
                                if ((dflag & 0x8) == 0) {
472
                                        data = entity.getDwgObjectSpecificDataItem("ROTATION_ANGLE");
473
                                        double textRot = ((Double)data.getValue()).doubleValue();
474
                            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(Math.toDegrees(textRot));
475
                                } else {
476
                            auxRow[ID_FIELD_ROTATIONTEXT] = ValueFactory.createValue(0.0);
477
                                }
478
                                if ((dflag & 0x1)==0) {
479
                                        data = entity.getDwgObjectSpecificDataItem("ELEVATION");
480
                                        double elev = ((Double)data.getValue()).doubleValue();
481
                            auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(elev);
482
                                }
483
                                data = entity.getDwgObjectSpecificDataItem("THICKNESS");
484
                                double thickness = ((Double)data.getValue()).doubleValue();
485
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(thickness);
486 1843 jmorell
                    // Attributes
487
                    /*for (int j=0;j<nAtt;j++) {
488
                                    String[] attributes = new String[2];
489
                                    attributes = (String[])featureMaker.getAttributes().get(j);
490
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
491
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
492
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
493
                        }
494
                    }*/
495
                                addShape(point, auxRow);
496
                        } else if (entity.getType()==0x4) {
497 1870 jmorell
                                System.out.println("Encuentra un Block ...");
498 1867 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("NAME");
499
                                String blockName = (String)data.getValue();
500
                                addingToBlock = true;
501 1843 jmorell
                                //pto = (Point2D.Double)point.get(0);
502
                                //FShape nuevoShp;
503 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
504 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block"));
505 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
506 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
507
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
508
                                int color = entity.getColor();
509 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
510 1880 jmorell
                                //if (color==0) color ByBlock
511
                                if (color==256) color = colorByLayer;
512
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
513 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
514
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
515
                    // Attributes
516
                    /*for (int j=0;j<nAtt;j++) {
517
                                    String[] attributes = new String[2];
518
                                    attributes = (String[])featureMaker.getAttributes().get(j);
519
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
520
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
521
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
522
                        }
523
                    }*/
524
                                //addShape(point, auxRow);
525
                        } else if (entity.getType()==0x5) {
526 1870 jmorell
                                System.out.println("Encuentra un Endblk ...");
527 1867 jmorell
                                addingToBlock = false;
528 1843 jmorell
                                //pto = (Point2D.Double)point.get(0);
529
                                //FShape nuevoShp;
530 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
531 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("EndBlk"));
532 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
533 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
534
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
535
                                int color = entity.getColor();
536 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
537 1880 jmorell
                                //if (color==0) color ByBlock
538
                                if (color==256) color = colorByLayer;
539
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
540 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
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(point, auxRow);
552 1865 jmorell
                        } else if (entity.getType()==0x30) {
553 1870 jmorell
                                System.out.println("Encuentra un Block Control Object ...");
554 1843 jmorell
                                //addingToBlock = false;
555
                                //pto = (Point2D.Double)point.get(0);
556
                                //FShape nuevoShp;
557 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
558 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Control Object"));
559 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
560 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
561
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
562
                                int color = entity.getColor();
563 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
564 1880 jmorell
                                //if (color==0) color ByBlock
565
                                if (color==256) color = colorByLayer;
566
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
567 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
568 1865 jmorell
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
569 1843 jmorell
                    // Attributes
570
                    /*for (int j=0;j<nAtt;j++) {
571
                                    String[] attributes = new String[2];
572
                                    attributes = (String[])featureMaker.getAttributes().get(j);
573
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
574
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
575
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
576
                        }
577
                    }*/
578
                                //addShape(point, auxRow);
579 1865 jmorell
                        } else if (entity.getType()==0x31) {
580 1870 jmorell
                                System.out.println("Encuentra un Block Header ...");
581
                                addingToBlock = true;
582 1843 jmorell
                                //pto = (Point2D.Double)point.get(0);
583
                                //FShape nuevoShp;
584 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
585 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Block Header"));
586 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
587 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
588
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
589
                                int color = entity.getColor();
590 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
591 1880 jmorell
                                //if (color==0) color ByBlock
592
                                if (color==256) color = colorByLayer;
593
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
594 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
595 1865 jmorell
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
596 1843 jmorell
                    // Attributes
597
                    /*for (int j=0;j<nAtt;j++) {
598
                                    String[] attributes = new String[2];
599
                                    attributes = (String[])featureMaker.getAttributes().get(j);
600
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
601
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
602
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
603
                        }
604
                    }*/
605
                                //addShape(point, auxRow);
606 1867 jmorell
                        } else if (entity.getType()==0x7 && !addingToBlock) {
607 1870 jmorell
                                System.out.println("Encuentra un Insert ...");
608 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
609 1865 jmorell
                                double[] p = (double[])data.getValue();
610
                                Point2D point = new Point2D.Double(p[0], p[1]);
611
                                data = entity.getDwgObjectSpecificDataItem("SCALE");
612
                                double[] scale = (double[])data.getValue();
613
                                data = entity.getDwgObjectSpecificDataItem("ROTATION");
614
                double rot = ((Double)data.getValue()).doubleValue();
615
                                data = entity.getDwgObjectSpecificDataItem("BLOCK_HEADER_HANDLE");
616
                                int[] blockHandle = (int[])data.getValue();
617 1867 jmorell
618 1883 jmorell
                                manageInsert(dwgObjects, layerTable, point, scale, rot, blockHandle, i, auxRow);
619 1867 jmorell
620 1883 jmorell
                                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
621 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Insert"));
622 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
623 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
624
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
625
                                int color = entity.getColor();
626 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
627 1880 jmorell
                                //if (color==0) color ByBlock
628
                                if (color==256) color = colorByLayer;
629
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
630 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
631 1867 jmorell
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
632 1843 jmorell
                    // 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 1867 jmorell
                    FPoint2D fPoint = createPoint(point);
642
                                addShape(fPoint, auxRow);
643
                        } else if (entity.getType()==0x2C && !addingToBlock) {
644 1870 jmorell
                                System.out.println("Encuentra un MText ...");
645 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
646
                                double[] coord = (double[])data.getValue();
647
                                Point2D p = new Point2D.Double(coord[0], coord[1]);
648
                                FPoint2D point = createPoint(p);
649 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
650 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("MText"));
651 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
652 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
653
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
654
                                int color = entity.getColor();
655 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
656 1880 jmorell
                                //if (color==0) color ByBlock
657
                                if (color==256) color = colorByLayer;
658
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
659 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
660
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
661
                    // Attributes
662
                    /*for (int j=0;j<nAtt;j++) {
663
                                    String[] attributes = new String[2];
664
                                    attributes = (String[])featureMaker.getAttributes().get(j);
665
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
666
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
667
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
668
                        }
669
                    }*/
670
                                addShape(point, auxRow);
671 1867 jmorell
                        } else if (entity.getType()==0x1F && !addingToBlock) {
672 1870 jmorell
                                System.out.println("Encuentra un Solid ...");
673 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CORNER1");
674
                                double[] coord = (double[])data.getValue();
675
                                Point2D p1 = new Point2D.Double(coord[0], coord[1]);
676
                                data = entity.getDwgObjectSpecificDataItem("CORNER2");
677
                                coord = (double[])data.getValue();
678
                                Point2D p2 = new Point2D.Double(coord[0], coord[1]);
679
                                data = entity.getDwgObjectSpecificDataItem("CORNER3");
680
                                coord = (double[])data.getValue();
681
                                Point2D p3 = new Point2D.Double(coord[0], coord[1]);
682
                                data = entity.getDwgObjectSpecificDataItem("CORNER4");
683
                                coord = (double[])data.getValue();
684
                                Point2D p4 = new Point2D.Double(coord[0], coord[1]);
685
                                FPolygon2D solid = createSolid(new Point2D[]{p1, p2, p4, p3});
686 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
687 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Solid"));
688 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
689 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
690
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
691
                                int color = entity.getColor();
692 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
693 1880 jmorell
                                //if (color==0) color ByBlock
694
                                if (color==256) color = colorByLayer;
695
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
696 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
697
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
698
                    // Attributes
699
                    /*for (int j=0;j<nAtt;j++) {
700
                                    String[] attributes = new String[2];
701
                                    attributes = (String[])featureMaker.getAttributes().get(j);
702
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
703
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
704
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
705
                        }
706
                    }*/
707
                                addShape(solid, auxRow);
708 1867 jmorell
                        } else if (entity.getType()==0x24 && !addingToBlock) {
709 1870 jmorell
                                System.out.println("Encuentra un Spline ...");
710 1843 jmorell
                                DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("SCENARIO");
711
                                int sc = ((Integer)data.getValue()).intValue();
712
                                if (sc==1) {
713
                                        data = entity.getDwgObjectSpecificDataItem("CONTROL_POINTS");
714
                                } else if (sc==2) {
715
                                        data = entity.getDwgObjectSpecificDataItem("FIT_POINTS");
716
                                }
717
                                double[][] vertices = (double[][])data.getValue();
718
                                Point2D[] pts = new Point2D[vertices.length];
719
                                double[] pt = new double[2];
720
                                for (int j=0; j<vertices.length; j++) {
721
                                         pt = (double[])vertices[j];
722
                                         pts[j] = new Point2D.Double(pt[0], pt[1]);
723
                                }
724
                                FPolyline2D spline = createLwPolyline(pts);
725 1883 jmorell
                auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
726 1880 jmorell
                auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Spline"));
727 1881 jmorell
                                //int[] layerHandle = (int[])entity.getLayer();
728 1880 jmorell
                                String layerName = getLayerName(entity, layerTable);
729
                auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
730
                                int color = entity.getColor();
731 1881 jmorell
                                int colorByLayer = getColorByLayer(entity, layerTable);
732 1880 jmorell
                                //if (color==0) color ByBlock
733
                                if (color==256) color = colorByLayer;
734
                auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
735 1843 jmorell
                    auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
736
                    auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
737
                    // Attributes
738
                    /*for (int j=0;j<nAtt;j++) {
739
                                    String[] attributes = new String[2];
740
                                    attributes = (String[])featureMaker.getAttributes().get(j);
741
                        auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
742
                        if (!fea.getProp(attributes[0]).equals(attributes[1])) {
743
                                auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
744
                        }
745
                    }*/
746
                                addShape(spline, auxRow);
747
                        } else if (dwg.getDxfNames().size()>0) {
748
                                int type = 0;
749
                                for (int j=0; j<dwg.getDxfNames().size(); j++) {
750
                                        String dxfName = ((DxfName)dwg.getDxfNames().get(j)).getDxfName();
751
                                        if (dxfName.equals("LWPOLYLINE")) {
752
                                                type = ((DxfName)dwg.getDxfNames().get(j)).getKey();
753
                                                break;
754
                                        }
755
                                }
756
                                if (entity.getType()==type) {
757
                                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("VERTICES");
758
                                        Vector vertices = (Vector)data.getValue();
759
                                        Point2D[] pts = new Point2D[vertices.size()];
760
                                        double[] pt = new double[2];
761
                                        for (int j=0; j<vertices.size(); j++) {
762
                                                 pt = (double[])vertices.get(j);
763
                                                 pts[j] = new Point2D.Double(pt[0], pt[1]);
764
                                        }
765
                                        FPolyline2D lwpline = createLwPolyline(pts);
766 1883 jmorell
                        auxRow[ID_FIELD_ID] = ValueFactory.createValue(i);
767 1880 jmorell
                        auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("LwPolyline"));
768 1881 jmorell
                                        //int[] layerHandle = (int[])entity.getLayer();
769 1880 jmorell
                                        String layerName = getLayerName(entity, layerTable);
770
                        auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
771
                                        int color = entity.getColor();
772 1881 jmorell
                                        int colorByLayer = getColorByLayer(entity, layerTable);
773 1880 jmorell
                                        //if (color==0) color ByBlock
774
                                        if (color==256) color = colorByLayer;
775
                        auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
776 1843 jmorell
                            auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
777
                            auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
778
                            // Attributes
779
                            /*for (int j=0;j<nAtt;j++) {
780
                                            String[] attributes = new String[2];
781
                                            attributes = (String[])featureMaker.getAttributes().get(j);
782
                                auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
783
                                if (!fea.getProp(attributes[0]).equals(attributes[1])) {
784
                                        auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
785
                                }
786
                            }*/
787
                                        addShape(lwpline, auxRow);
788
                                }
789
                        } else {
790
                                System.out.println("Detectado dwgObject pendiente de implementar");
791
                        }
792
                }
793 1858 jmorell
                timeElapsed = System.currentTimeMillis()-time;
794
                System.out.println("Tiempo empleado por el driver en importar el contenido del dwg = " + timeElapsed);
795 1843 jmorell
796
                defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType());
797
                defaultLegend.setFieldName("Color");
798
                defaultLegend.setLabelField("Text");
799
                defaultLegend.setDefaultSymbol(new FSymbol(getShapeType()));
800
                defaultLegend.getDefaultSymbol().setShapeVisible(false);
801
                defaultLegend.getDefaultSymbol().setFontSizeInPixels(false);
802
                defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", Font.PLAIN, 9));
803
                defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK);
804
                defaultLegend.getDefaultSymbol().setFontSize(heightText);
805
                defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
806
                defaultLegend.getDefaultSymbol().setSize(3);
807
                defaultLegend.getDefaultSymbol().setSizeInPixels(true);
808
809
                defaultLegend.setLabelHeightField("HeightText");
810
                defaultLegend.setLabelRotationField("RotationText");
811
812
        ObjectDriver rs = this;
813
                IntValue clave;
814
                FSymbol theSymbol = null;
815
816
                try {
817
                    // TODO: Provisional hasta que cambiemos los s?mbolos.
818
                   /*  BufferedImage bi= new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
819
                   Graphics2D big = bi.createGraphics();
820
                   Color color=new Color(0,0,0,0);
821
                   big.setBackground(color);
822
                   big.clearRect(0, 0, 5, 5);
823
                   Paint fillProv = null;
824
                   Rectangle2D rProv = new Rectangle();
825
                   rProv.setFrame(0, 0,5,5);
826
                   fillProv = new TexturePaint(bi,rProv); */
827
828
                        for (long j = 0; j < rs.getRowCount(); j++)
829
                        {
830
                                clave = (IntValue)rs.getFieldValue(j,ID_FIELD_COLOR);
831
                                if (defaultLegend.getSymbolByValue(clave) == null)
832
                                {
833
                                        theSymbol = new FSymbol(getShapeType());
834
                                        theSymbol.setDescription(clave.toString());
835
                                        theSymbol.setColor(AcadColor.getColor(clave.getValue()));
836
                                        // theSymbol.setFill(fillProv);
837
                                        // 050202, jmorell: Asigna los colores de Autocad a los bordes
838
                                        //                                        de los pol?gonos.
839
                                        theSymbol.setOutlineColor(AcadColor.getColor(clave.getValue()));
840
841
                                        theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL);
842
                                        theSymbol.setSize(3);
843
                                        theSymbol.setSizeInPixels(true);
844
845
                                        defaultLegend.addSymbol(clave, theSymbol);
846
                                }
847
                        } // for
848
                } catch (DriverException e) {
849
                        e.printStackTrace();
850
                        throw new IOException("Error al poner la leyenda por defecto en el Dwg");
851
                }
852
        }
853
854
        /**
855
         * En principio exportamos a FPolyline2D, despues estudiaremos la conveniencia
856
         * de exportar a FPolygon2D, o a las dos cosas ...
857
         * Esta clase construye el circle del mismo modo que en DxfFeatureMaker.
858
         * Se podr?a renombrar esta clase a createCircleFeature y a?adir otra
859
         * createCircleEntity ...
860
         * La parte de creaci?n de la FPolyline2D est? sacada del DxfMemoryDriver ...
861
         * @param center
862
         * @param radius
863
         * @return
864
         */
865
        private FPolyline2D createCircle(Point2D c, double r) {
866
                Point2D[] pts = new Point2D[360];
867
                int angulo = 0;
868
                for (angulo=0; angulo<360; angulo++) {
869
                        pts[angulo] = new Point2D.Double(c.getX(), c.getY());
870
                        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));
871
                }
872
                GeneralPathX genPathX = new GeneralPathX();
873
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
874
                for (int i=1; i<pts.length; i++) {
875
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
876
                }
877
                return new FPolyline2D(genPathX);
878
        }
879
880
        /**
881
         * Como createCircle ...
882
         * @param c
883
         * @param r
884
         * @param sa
885
         * @param ea
886
         * @return
887
         */
888 1870 jmorell
        private Point2D[] createArc(Point2D c, double r, double sa, double ea) {
889 1843 jmorell
                int isa = (int)sa;
890
                int iea = (int)ea;
891
                double angulo;
892
                Point2D[] pts;
893
                if (sa <= ea) {
894
                        pts = new Point2D[(iea-isa)+2];
895
                        angulo = sa;
896
                        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));
897
                        for (int i=1; i<=(iea-isa)+1; i++) {
898
                                angulo = (double)(isa+i);
899
                                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));
900
                        }
901
                        angulo = ea;
902
                        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));
903
                } else {
904
                        pts = new Point2D[(360-isa)+iea+2];
905
                        angulo = sa;
906
                        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));
907
                        for (int i=1; i<=(360-isa); i++) {
908
                                angulo = (double)(isa+i);
909
                                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));
910
                        }
911
                        for (int i=(360-isa)+1; i<=(360-isa)+iea; i++) {
912
                                angulo = (double)(i-(360-isa));
913
                                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));
914
                        }
915
                        angulo = ea;
916
                        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));
917
                }
918 1870 jmorell
                return pts;
919
                /*GeneralPathX genPathX = new GeneralPathX();
920 1843 jmorell
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
921
                for (int i=1; i<pts.length; i++) {
922
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
923
                }
924 1870 jmorell
                return new FPolyline2D(genPathX);*/
925 1843 jmorell
        }
926
927
        /**
928
         * Los nombres de estos m?todos pueden cambiarse por otros m?s apropiados, por
929
         * ejemplo:
930
         * createLine --> dwgLineToFPolyline2D ... ?mejor as?? ...
931
         * @param p1
932
         * @param p2
933
         * @return
934
         */
935
        private FPolyline2D createLine(Point2D p1, Point2D p2) {
936
                Point2D[] pts = new Point2D[]{p1, p2};
937
                GeneralPathX genPathX = new GeneralPathX();
938
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
939
                for (int i=1; i<pts.length; i++) {
940
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
941
                }
942
                return new FPolyline2D(genPathX);
943
        }
944
945
        private FPoint2D createPoint(Point2D p) {
946
                return new FPoint2D(p.getX(), p.getY());
947
        }
948
949
        private FPolyline2D createLwPolyline(Point2D[] pts) {
950
                GeneralPathX genPathX = new GeneralPathX();
951
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
952
                for (int i=1; i<pts.length; i++) {
953
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
954
                }
955
                return new FPolyline2D(genPathX);
956
        }
957
958 1869 jmorell
        private FPolyline2D createPolyline3D(Point2D[] pts) {
959 1843 jmorell
                GeneralPathX genPathX = new GeneralPathX();
960
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
961
                for (int i=1; i<pts.length; i++) {
962
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
963
                }
964
                return new FPolyline2D(genPathX);
965
        }
966
967 1869 jmorell
        private FPolyline2D createPolyline2D(Point2D[] inPts, Vector bulges) {
968
                Vector pts = new Vector();
969
                Point2D init = new Point2D.Double();
970
                Point2D end = new Point2D.Double();
971
                for (int i=0; i<inPts.length; i++) {
972
                        init = inPts[i];
973
                        if (i!=inPts.length-1) end = inPts[i+1];
974
                        if (((Double)bulges.get(i)).doubleValue()==0 || i==inPts.length-1) {
975
                                pts.add(init);
976
                        } else {
977
                                ArcFromBulgeCalculator arcCalculator = new ArcFromBulgeCalculator(init, end, ((Double)bulges.get(i)).doubleValue());
978
                                Vector arc = arcCalculator.getPoints(1);
979
                                for (int j=0;j<arc.size();j++) {
980
                                        pts.add(arc.get(j));
981
                                }
982
                                pts.remove(pts.size()-1);
983
                        }
984
                }
985
                GeneralPathX genPathX = new GeneralPathX();
986
                genPathX.moveTo(((Point2D)pts.get(0)).getX(), ((Point2D)pts.get(0)).getY());
987
                for (int i=1; i<pts.size(); i++) {
988
                        genPathX.lineTo(((Point2D)pts.get(i)).getX(), ((Point2D)pts.get(i)).getY());
989
                }
990
                return new FPolyline2D(genPathX);
991
        }
992
993 1843 jmorell
        private FPolygon2D createSolid(Point2D[] pts) {
994
                GeneralPathX genPathX = new GeneralPathX();
995
                genPathX.moveTo(pts[0].getX(), pts[0].getY());
996
                for (int i=1; i<pts.length; i++) {
997
                        genPathX.lineTo(pts[i].getX(), pts[i].getY());
998
                }
999
                genPathX.closePath();
1000
                return new FPolygon2D(genPathX);
1001
        }
1002
1003
        private int calculateVertexNumber(int[] firstVertexHandle, int[] lastVertexHandle) {
1004 1853 jmorell
                if (firstVertexHandle.length==lastVertexHandle.length) {
1005
                        if (firstVertexHandle[firstVertexHandle.length-2]==lastVertexHandle[firstVertexHandle.length-2]) {
1006
                                return (lastVertexHandle[firstVertexHandle.length-1]-firstVertexHandle[firstVertexHandle.length-1]+1);
1007
                        } else {
1008
                                int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1;
1009
                                int aux2 = lastVertexHandle[firstVertexHandle.length-1]+1;
1010
                                int aux3 = (lastVertexHandle[firstVertexHandle.length-2]-firstVertexHandle[firstVertexHandle.length-2]-1)*255;
1011
                                int vn = aux + aux2 + aux3;
1012
                                return vn;
1013
                        }
1014
                } else if (firstVertexHandle.length==(lastVertexHandle.length-1)) {
1015
                        int aux = 255-firstVertexHandle[firstVertexHandle.length-1]+1;
1016
                        int aux2 = lastVertexHandle[firstVertexHandle.length]+1;
1017 1858 jmorell
                        int aux3 = (lastVertexHandle[lastVertexHandle.length-2]-1)*255;
1018
                        int vn = aux + aux2 + aux3;
1019 1853 jmorell
                        return vn;
1020
                } else {
1021
                        System.out.println("ERROR: firstVertexHandle y lastVertexHandle tienen tama?os inesperados");
1022
                        return 0;
1023
                }
1024 1843 jmorell
        }
1025 1865 jmorell
1026 1883 jmorell
        private void manageInsert(Vector dwgObjects, Vector layerTable, Point2D insPoint, double[] scale, double rot, int[] blockHandle, int id, Value[] auxRow) {
1027 1870 jmorell
                byte[] blockHandleBytes = new byte[]{0,0,0,0};
1028
                if (blockHandle.length>2) blockHandleBytes[3] = (byte)blockHandle[2];
1029
                if (blockHandle.length>3) blockHandleBytes[2] = (byte)blockHandle[3];
1030
                if (blockHandle.length>4) blockHandleBytes[1] = (byte)blockHandle[4];
1031
                if (blockHandle.length>5) blockHandleBytes[0] = (byte)blockHandle[5];
1032
                int bHandle = ByteUtils.bytesToInt(blockHandleBytes, new int[]{0});
1033
                for (int j=0;j<dwgObjects.size();j++) {
1034
                        DwgObject obj = (DwgObject)dwgObjects.get(j);
1035
                        DwgObjectSpecificDataItem dataa = obj.getDwgObjectSpecificDataItem("BLOCK_ENTITY_HANDLE");
1036
                        //System.out.println("obj.getType() = " + obj.getType());
1037
                        //System.out.println("dataa = " + dataa);
1038
                        if (dataa!=null) {
1039
                                int[] handle = (int[])dataa.getValue();
1040
                                byte[] handleBytes = new byte[]{0,0,0,0};
1041
                                if (handle.length>2) handleBytes[3] = (byte)handle[2];
1042
                                if (handle.length>3) handleBytes[2] = (byte)handle[3];
1043
                                if (handle.length>4) handleBytes[1] = (byte)handle[4];
1044
                                if (handle.length>5) handleBytes[0] = (byte)handle[5];
1045
                                int objHandle = ByteUtils.bytesToInt(handleBytes, new int[]{0});
1046
                                //System.out.println("objHandle = " + objHandle);
1047
                                //System.out.println("bHandle = " + bHandle);
1048
                                if (objHandle==bHandle+1 && handle[1]==blockHandle[1]) {
1049
                                        //obj = (DwgObject)dwgObjects.get(j+1);
1050
                                        //System.out.println("Hemos encontrado el bloque");
1051
                                        //System.out.println("obj.getType() = " + obj.getType());
1052
                                        DwgObjectSpecificDataItem data = obj.getDwgObjectSpecificDataItem("BASE_POINT");
1053
                                        double[] bPoint = (double[])data.getValue();
1054
                                        //System.out.println("bPoint[0] = " + bPoint[0]);
1055
                                        //System.out.println("bPoint[1] = " + bPoint[1]);
1056
                                        data = obj.getDwgObjectSpecificDataItem("FIRST_ENTITY_HANDLE");
1057
                                        int[] firstEntityHandle = (int[])data.getValue();
1058
                                        //System.out.println("firstEntityHandle[0] = " + firstEntityHandle[0]);
1059
                                        //System.out.println("firstEntityHandle[1] = " + firstEntityHandle[1]);
1060
                                        //if (firstEntityHandle.length>2) System.out.println("firstEntityHandle[2] = " + firstEntityHandle[2]);
1061
                                        //if (firstEntityHandle.length>3) System.out.println("firstEntityHandle[3] = " + firstEntityHandle[3]);
1062
                                        byte[] firstEntityBytes = new byte[]{0,0,0,0};
1063
                                        if (firstEntityHandle.length>2) firstEntityBytes[3] = (byte)firstEntityHandle[2];
1064
                                        if (firstEntityHandle.length>3) firstEntityBytes[2] = (byte)firstEntityHandle[3];
1065
                                        if (firstEntityHandle.length>4) firstEntityBytes[1] = (byte)firstEntityHandle[4];
1066
                                        if (firstEntityHandle.length>5) firstEntityBytes[0] = (byte)firstEntityHandle[5];
1067
                                        int firstHandle = ByteUtils.bytesToInt(firstEntityBytes, new int[]{0});
1068
                                        //System.out.println("firstHandle = " + firstHandle);
1069
                                        data = obj.getDwgObjectSpecificDataItem("LAST_ENTITY_HANDLE");
1070
                                        int[] lastEntityHandle = (int[])data.getValue();
1071
                                        byte[] lastEntityBytes = new byte[]{0,0,0,0};
1072
                                        if (lastEntityHandle.length>2) lastEntityBytes[3] = (byte)lastEntityHandle[2];
1073
                                        if (lastEntityHandle.length>3) lastEntityBytes[2] = (byte)lastEntityHandle[3];
1074
                                        if (lastEntityHandle.length>4) lastEntityBytes[1] = (byte)lastEntityHandle[4];
1075
                                        if (lastEntityHandle.length>5) lastEntityBytes[0] = (byte)lastEntityHandle[5];
1076
                                        int lastHandle = ByteUtils.bytesToInt(lastEntityBytes, new int[]{0});
1077
                                        //System.out.println("lastHandle = " + lastHandle);
1078 1881 jmorell
                                        // Buscando la capa y el color del bloque ...
1079
                                        String bname = (String)obj.getDwgObjectSpecificDataItem("NAME").getValue();
1080
                                        //int[] blockHandleLayer = null;
1081
                                        //int blockColor = 0;
1082
                                        DwgObject block = null;
1083
                                        for (int k=0;k<dwgObjects.size();k++) {
1084
                                                DwgObject ent = (DwgObject)dwgObjects.get(k);
1085
                                                if (ent.getType()==0x4) {
1086
                                                        String name = (String)obj.getDwgObjectSpecificDataItem("NAME").getValue();
1087
                                                        if (bname.equals(name)) {
1088
                                                                //blockHandleLayer = ent.getLayer();
1089
                                                                //blockColor = ent.getColor();
1090
                                                                block = ent;
1091
                                                        }
1092
                                                }
1093
                                        }
1094 1870 jmorell
1095
                                        for (int k=0;k<dwgObjects.size();k++) {
1096
                                                DwgObject ent = (DwgObject)dwgObjects.get(k);
1097
                                                Vector entHandle = ent.getHandle();
1098
                                                byte[] entHandleBytes = new byte[]{0,0,0,0};
1099
                                                if (entHandle.size()>2) entHandleBytes[3] = ((Integer)entHandle.get(2)).byteValue();
1100
                                                if (entHandle.size()>3) entHandleBytes[2] = ((Integer)entHandle.get(3)).byteValue();
1101
                                                if (entHandle.size()>4) entHandleBytes[1] = ((Integer)entHandle.get(4)).byteValue();
1102
                                                if (entHandle.size()>5) entHandleBytes[0] = ((Integer)entHandle.get(5)).byteValue();
1103
                                                int eHandle = ByteUtils.bytesToInt(entHandleBytes, new int[]{0});
1104
                                                //System.out.println("eHandle = " + eHandle);
1105
                                                if (eHandle==firstHandle && ((Integer)entHandle.get(1)).intValue()==firstEntityHandle[1]) {
1106
                                                        //System.out.println("Hemos encontrado el primer elemento");
1107
                                                        int l=0;
1108
                                                        while (true) {
1109
                                                                DwgObject blockEntity = (DwgObject)dwgObjects.get(k+l);
1110
                                                                Vector blockEntityHandle = blockEntity.getHandle();
1111
                                                                byte[] blockEntityHandleBytes = new byte[]{0,0,0,0};
1112
                                                                if (blockEntityHandle.size()>2) blockEntityHandleBytes[3] = ((Integer)blockEntityHandle.get(2)).byteValue();
1113
                                                                if (blockEntityHandle.size()>3) blockEntityHandleBytes[2] = ((Integer)blockEntityHandle.get(3)).byteValue();
1114
                                                                if (blockEntityHandle.size()>4) blockEntityHandleBytes[1] = ((Integer)blockEntityHandle.get(4)).byteValue();
1115
                                                                if (blockEntityHandle.size()>5) blockEntityHandleBytes[0] = ((Integer)blockEntityHandle.get(5)).byteValue();
1116
                                                                int bEntityHandle = ByteUtils.bytesToInt(blockEntityHandleBytes, new int[]{0});
1117 1883 jmorell
                                                                manageBlockEntity(blockEntity, layerTable, bPoint, insPoint, scale, rot, block, id, auxRow);
1118 1870 jmorell
                                                                l++;
1119
                                                                if (bEntityHandle==lastHandle && ((Integer)entHandle.get(1)).intValue()==lastEntityHandle[1]) {
1120
                                                                        break;
1121
                                                                }
1122
                                                        }
1123
                                                }
1124
                                        }
1125
                                }
1126
                        }
1127
                }
1128
        }
1129
1130 1883 jmorell
        private void manageBlockEntity(DwgObject entity, Vector layerTable, double[] bPoint, Point2D insPoint, double[] scale, double rot, DwgObject block, int id, Value[] auxRow) {
1131 1865 jmorell
                if (entity.getType()==0x11) {
1132 1870 jmorell
                        System.out.println("Encuentra un arco dentro de un bloque ...");
1133
                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
1134 1865 jmorell
                        double[] coord = (double[])data.getValue();
1135
                        Point2D center = new Point2D.Double(coord[0], coord[1]);
1136
                        data = entity.getDwgObjectSpecificDataItem("RADIUS");
1137
                        double radius = ((Double)data.getValue()).doubleValue();
1138
                        data = entity.getDwgObjectSpecificDataItem("START_ANGLE");
1139
                        double startAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
1140
                        data = entity.getDwgObjectSpecificDataItem("END_ANGLE");
1141
                        double endAngle = Math.toDegrees(((Double)data.getValue()).doubleValue());
1142 1870 jmorell
                        //FPolyline2D arc = createArc(center, radius, startAngle, endAngle);
1143
                        Point2D[] arc = createArc(center, radius, startAngle, endAngle);
1144
                        for (int i=0;i<arc.length;i++) {
1145
                                Point2D pointAux = new Point2D.Double(arc[i].getX() - bPoint[0], arc[i].getY() - bPoint[1]);
1146
                                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1147
                                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1148
                                arc[i] = new Point2D.Double(laX, laY);
1149
                        }
1150
                        FPolyline2D arcc = createPolyline3D(arc);
1151 1883 jmorell
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1152 1881 jmorell
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Arc"));
1153
                        String layerName = getLayerName(block, layerTable);
1154
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1155
                        int color = entity.getColor();
1156
                        int colorByLayer = getColorByLayer(entity, layerTable);
1157
                        int colorByBlock = getColorByLayer(block, layerTable);
1158
                        if (color==0) color = colorByBlock;
1159
                        if (color==256) color = colorByLayer;
1160
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1161 1865 jmorell
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1162 1870 jmorell
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1163 1865 jmorell
                // Attributes
1164
                /*for (int j=0;j<nAtt;j++) {
1165
                                String[] attributes = new String[2];
1166
                                attributes = (String[])featureMaker.getAttributes().get(j);
1167
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1168
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1169
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1170
                    }
1171
                }*/
1172 1870 jmorell
                        addShape(arcc, auxRow);
1173 1865 jmorell
                } else if (entity.getType()==0x12) {
1174 1870 jmorell
                        System.out.println("Encuentra un c?rculo dentro de un bloque ...");
1175 1865 jmorell
                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("CENTER");
1176
                        double[] coord = (double[])data.getValue();
1177
                        Point2D center = new Point2D.Double(coord[0], coord[1]);
1178
                        data = entity.getDwgObjectSpecificDataItem("RADIUS");
1179
                        double radius = ((Double)data.getValue()).doubleValue();
1180
1181
                        Point2D pointAux = new Point2D.Double(center.getX() - bPoint[0], center.getY() - bPoint[1]);
1182
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*(-1)*Math.sin(Math.toRadians(rot)));
1183
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(Math.toRadians(rot)) + (pointAux.getY()*scale[1])*Math.cos(Math.toRadians(rot)));
1184
                        center = new Point2D.Double(laX, laY);
1185
                        // Escala en X = escala en Y ...
1186
                        radius = radius * scale[0];
1187
1188
                        FPolyline2D circle = createCircle(center, radius);
1189 1883 jmorell
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1190 1881 jmorell
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Circle"));
1191
                        String layerName = getLayerName(block, layerTable);
1192
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1193
                        int color = entity.getColor();
1194
                        int colorByLayer = getColorByLayer(entity, layerTable);
1195
                        int colorByBlock = getColorByLayer(block, layerTable);
1196
                        if (color==0) color = colorByBlock;
1197
                        if (color==256) color = colorByLayer;
1198
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1199 1865 jmorell
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1200
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1201
                // Attributes
1202
                /*for (int j=0;j<nAtt;j++) {
1203
                                String[] attributes = new String[2];
1204
                                attributes = (String[])featureMaker.getAttributes().get(j);
1205
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1206
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1207
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1208
                    }
1209
                }*/
1210
                        addShape(circle, auxRow);
1211
                } else if (entity.getType()==0x13) {
1212 1870 jmorell
                        System.out.println("Encuentra una l?nea dentro de un bloque ...");
1213 1865 jmorell
                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("P1");
1214
                        double[] coord = (double[])data.getValue();
1215
                        Point2D p1 = new Point2D.Double(coord[0], coord[1]);
1216
                        data = entity.getDwgObjectSpecificDataItem("P2");
1217
                        coord = (double[])data.getValue();
1218
                        Point2D p2 = new Point2D.Double(coord[0], coord[1]);
1219
1220
                        Point2D pointAux = new Point2D.Double(p1.getX() - bPoint[0], p1.getY() - bPoint[1]);
1221 1867 jmorell
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1222
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1223 1865 jmorell
                        p1 = new Point2D.Double(laX, laY);
1224
                        pointAux = new Point2D.Double(p2.getX() - bPoint[0], p2.getY() - bPoint[1]);
1225 1867 jmorell
                        laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1226
                        laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1227 1865 jmorell
                        p2 = new Point2D.Double(laX, laY);
1228
1229
                        FPolyline2D line = createLine(p1, p2);
1230 1883 jmorell
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1231 1881 jmorell
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Line"));
1232
                        String layerName = getLayerName(block, layerTable);
1233 1883 jmorell
                        System.out.println("layerName = " + layerName);
1234 1881 jmorell
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1235
                        int color = entity.getColor();
1236
                        int colorByLayer = getColorByLayer(entity, layerTable);
1237
                        int colorByBlock = getColorByLayer(block, layerTable);
1238
                        if (color==0) color = colorByBlock;
1239
                        if (color==256) color = colorByLayer;
1240
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1241 1865 jmorell
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1242
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1243
                // Attributes
1244
                /*for (int j=0;j<nAtt;j++) {
1245
                                String[] attributes = new String[2];
1246
                                attributes = (String[])featureMaker.getAttributes().get(j);
1247
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1248
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1249
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1250
                    }
1251
                }*/
1252
                        addShape(line, auxRow);
1253 1867 jmorell
                } else if (entity.getType()==0x7) {
1254 1870 jmorell
                        System.out.println("Encuentra un insert dentro de un bloque ...");
1255 1867 jmorell
                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("INSERTION_POINT");
1256
                        double[] p = (double[])data.getValue();
1257
                        Point2D newInsPoint = new Point2D.Double(p[0], p[1]);
1258
                        data = entity.getDwgObjectSpecificDataItem("SCALE");
1259
                        double[] newScale = (double[])data.getValue();
1260
                        data = entity.getDwgObjectSpecificDataItem("ROTATION");
1261
            double newRot = ((Double)data.getValue()).doubleValue();
1262
                        data = entity.getDwgObjectSpecificDataItem("BLOCK_HEADER_HANDLE");
1263
                        int[] newBlockHandle = (int[])data.getValue();
1264
1265
                        Point2D pointAux = new Point2D.Double(newInsPoint.getX() - bPoint[0], newInsPoint.getY() - bPoint[1]);
1266
                        double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1267
                        double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1268
                        newInsPoint = new Point2D.Double(laX, laY);
1269
1270
                        newScale = new double[]{scale[0]*newScale[0], scale[1]*newScale[1], scale[2]*newScale[2]};
1271
1272 1883 jmorell
                        manageInsert(dwgObjects, layerTable, newInsPoint, newScale, newRot, newBlockHandle, id, auxRow);
1273 1867 jmorell
1274
                        /*auxRow[ID_FIELD_ID] = ValueFactory.createValue(0);
1275
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("dxfEntity"));
1276
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(new String("layer"));
1277
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(0);
1278
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1279
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);*/
1280
                // Attributes
1281
                /*for (int j=0;j<nAtt;j++) {
1282
                                String[] attributes = new String[2];
1283
                                attributes = (String[])featureMaker.getAttributes().get(j);
1284
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1285
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1286
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1287
                    }
1288
                }*/
1289
                /*FPoint2D fPoint = createPoint(newInsPoint);
1290
                        addShape(fPoint, auxRow);*/
1291 1870 jmorell
                } else if (entity.getType()==0x0F) {
1292
                        System.out.println("Encuentra una polil?nea dentro de un bloque ...");
1293
                        DwgObjectSpecificDataItem data = entity.getDwgObjectSpecificDataItem("FLAGS");
1294
                        int flags = ((Integer)data.getValue()).intValue();
1295
                        data = entity.getDwgObjectSpecificDataItem("FIRST_VERTEX_HANDLE");
1296
                        int[] firstVertexHandle = (int[])data.getValue();
1297
                        byte[] firstHandleBytes = new byte[]{0,0,0,0};
1298
                        if (firstVertexHandle.length>2) firstHandleBytes[3] = (byte)firstVertexHandle[2];
1299
                        if (firstVertexHandle.length>3) firstHandleBytes[2] = (byte)firstVertexHandle[3];
1300
                        if (firstVertexHandle.length>4) firstHandleBytes[1] = (byte)firstVertexHandle[4];
1301
                        if (firstVertexHandle.length>5) firstHandleBytes[0] = (byte)firstVertexHandle[5];
1302
                        int firstHandle = ByteUtils.bytesToInt(firstHandleBytes, new int[]{0});
1303
                        data = entity.getDwgObjectSpecificDataItem("LAST_VERTEX_HANDLE");
1304
                        int[] lastVertexHandle = (int[])data.getValue();
1305
                        byte[] lastHandleBytes = new byte[]{0,0,0,0};
1306
                        if (lastVertexHandle.length>2) lastHandleBytes[3] = (byte)lastVertexHandle[2];
1307
                        if (lastVertexHandle.length>3) lastHandleBytes[2] = (byte)lastVertexHandle[3];
1308
                        if (lastVertexHandle.length>4) lastHandleBytes[1] = (byte)lastVertexHandle[4];
1309
                        if (lastVertexHandle.length>5) lastHandleBytes[0] = (byte)lastVertexHandle[5];
1310
                        int lastHandle = ByteUtils.bytesToInt(lastHandleBytes, new int[]{0});
1311
                        Vector pts = new Vector();
1312
                        Vector bulges = new Vector();
1313
                        double[] pt = new double[2];
1314
1315
                        for (int j=0;j<dwgObjects.size();j++) {
1316
                                DwgObject obj = (DwgObject)dwgObjects.get(j);
1317
                                Vector handle = obj.getHandle();
1318 1867 jmorell
                                byte[] handleBytes = new byte[]{0,0,0,0};
1319 1870 jmorell
                                if (handle.size()>2) handleBytes[3] = ((Integer)handle.get(2)).byteValue();
1320
                                if (handle.size()>3) handleBytes[2] = ((Integer)handle.get(3)).byteValue();
1321
                                if (handle.size()>4) handleBytes[1] = ((Integer)handle.get(4)).byteValue();
1322
                                if (handle.size()>5) handleBytes[0] = ((Integer)handle.get(5)).byteValue();
1323 1867 jmorell
                                int objHandle = ByteUtils.bytesToInt(handleBytes, new int[]{0});
1324 1870 jmorell
                                if (objHandle==firstHandle && ((Integer)handle.get(1)).intValue()==firstVertexHandle[1]) {
1325
                                        int k=0;
1326
                                        while (true) {
1327
                                                DwgObject vertex = (DwgObject)dwgObjects.get(j+k);
1328
                                                Vector vertexHandle = vertex.getHandle();
1329
                                                byte[] vHandleBytes = new byte[]{0,0,0,0};
1330
                                                if (vertexHandle.size()>2) vHandleBytes[3] = ((Integer)vertexHandle.get(2)).byteValue();
1331
                                                if (vertexHandle.size()>3) vHandleBytes[2] = ((Integer)vertexHandle.get(3)).byteValue();
1332
                                                if (vertexHandle.size()>4) vHandleBytes[1] = ((Integer)vertexHandle.get(4)).byteValue();
1333
                                                if (vertexHandle.size()>5) vHandleBytes[0] = ((Integer)vertexHandle.get(5)).byteValue();
1334
                                                int vHandle = ByteUtils.bytesToInt(vHandleBytes, new int[]{0});
1335
                                                data = vertex.getDwgObjectSpecificDataItem("POINT");
1336
                                                pt = (double[])data.getValue();
1337
                                                pts.add(new Point2D.Double(pt[0], pt[1]));
1338
                                                data = vertex.getDwgObjectSpecificDataItem("BULGE");
1339
                                                double bulge = ((Double)data.getValue()).doubleValue();
1340
                                                bulges.add(new Double(bulge));
1341
                                                k++;
1342
                                                if (vHandle==lastHandle && ((Integer)vertexHandle.get(1)).intValue()==lastVertexHandle[1]) {
1343
                                                        break;
1344 1867 jmorell
                                                }
1345
                                        }
1346
                                }
1347
                        }
1348 1870 jmorell
1349
                        Point2D[] newPts = new Point2D[pts.size()];
1350
                        if (flags==0 || flags==2 || flags==4 || flags==8 || flags==16 || flags==32 || flags==64 || flags==128) {
1351
                                for (int j=0;j<pts.size();j++) {
1352
                                        newPts[j] = (Point2D)pts.get(j);
1353
                                }
1354
                        } else if (flags==1 || flags==3 || flags==5 || flags==9 || flags==17 || flags==33 || flags==65 || flags==129) {
1355
                                newPts = new Point2D[pts.size()+1];
1356
                                for (int j=0;j<pts.size();j++) {
1357
                                        newPts[j] = (Point2D)pts.get(j);
1358
                                }
1359
                                newPts[pts.size()] = (Point2D)pts.get(0);
1360
                                bulges.add(new Double(0));
1361
                        }
1362
1363
                        for (int i=0;i<newPts.length;i++) {
1364
                                Point2D pointAux = new Point2D.Double(newPts[i].getX() - bPoint[0], newPts[i].getY() - bPoint[1]);
1365
                                double laX = insPoint.getX() + ((pointAux.getX()*scale[0])*Math.cos(rot) + (pointAux.getY()*scale[1])*(-1)*Math.sin(rot));
1366
                                double laY = insPoint.getY() + ((pointAux.getX()*scale[0])*Math.sin(rot) + (pointAux.getY()*scale[1])*Math.cos(rot));
1367
                                newPts[i] = new Point2D.Double(laX, laY);
1368
                        }
1369
1370
                        FPolyline2D pline = createPolyline2D(newPts, bulges);
1371 1883 jmorell
            auxRow[ID_FIELD_ID] = ValueFactory.createValue(id);
1372 1881 jmorell
            auxRow[ID_FIELD_ENTITY] = ValueFactory.createValue(new String("Polyline2D"));
1373
                        String layerName = getLayerName(block, layerTable);
1374
            auxRow[ID_FIELD_LAYER] = ValueFactory.createValue(layerName);
1375
                        int color = entity.getColor();
1376
                        int colorByLayer = getColorByLayer(entity, layerTable);
1377
                        int colorByBlock = getColorByLayer(block, layerTable);
1378
                        if (color==0) color = colorByBlock;
1379
                        if (color==256) color = colorByLayer;
1380
            auxRow[ID_FIELD_COLOR] = ValueFactory.createValue(color);
1381 1870 jmorell
                auxRow[ID_FIELD_ELEVATION] = ValueFactory.createValue(0.0);
1382
                auxRow[ID_FIELD_THICKNESS] = ValueFactory.createValue(0.0);
1383
                // Attributes
1384
                /*for (int j=0;j<nAtt;j++) {
1385
                                String[] attributes = new String[2];
1386
                                attributes = (String[])featureMaker.getAttributes().get(j);
1387
                    auxRow[9+j] = ValueFactory.createValue(new String((String)attributes[1]));
1388
                    if (!fea.getProp(attributes[0]).equals(attributes[1])) {
1389
                            auxRow[9+j] = ValueFactory.createValue(new String(fea.getProp(attributes[0])));
1390
                    }
1391
                }*/
1392
                        addShape(pline, auxRow);
1393 1867 jmorell
                }
1394
        }
1395 1870 jmorell
1396 1880 jmorell
        /**
1397
         * LayerTable podr?a ser un objeto y LayerTableRecord tambi?n ...
1398
         * @param dwgObjects
1399
         * @return
1400
         */
1401
        private Vector createLayerTable(Vector dwgObjects) {
1402
                Vector layerTable = new Vector();
1403
                for (int i=0;i<dwgObjects.size();i++) {
1404
                        DwgObject obj = (DwgObject)dwgObjects.get(i);
1405
                        if (obj.getType()==0x33) {
1406
                                //System.out.println("Encuentra un objeto layer ...");
1407
                                Vector layerTableRecord = new Vector();
1408
                                layerTableRecord.add(obj.getHandle());
1409
                                layerTableRecord.add(((String)obj.getDwgObjectSpecificDataItem("NAME").getValue()));
1410
                                //System.out.println("((Integer)obj.getDwgObjectSpecificDataItem(COLOR).getValue()).intValue() = " + ((Integer)obj.getDwgObjectSpecificDataItem("COLOR").getValue()).intValue());
1411
                                layerTableRecord.add(((Integer)obj.getDwgObjectSpecificDataItem("COLOR").getValue()));
1412
                                //layerTableRecord.add(obj.getDwgObjectSpecificDataItem("LAYER_CONTROL_HANDLE").getValue());
1413
                                layerTable.add(layerTableRecord);
1414
                        }
1415
                }
1416
                return layerTable;
1417
        }
1418
1419
        //private String setLayerName(int[] layerHandle, Vector layerTable) {
1420
        private String getLayerName(DwgObject entity, Vector layerTable) {
1421
                String layerName = "";
1422
                int[] layerHandle = (int[])entity.getLayer();
1423
                System.out.println("layerHandle[0] = " + layerHandle[0]);
1424
                if (layerHandle.length>1) System.out.println("layerHandle[1] = " + layerHandle[1]);
1425
                if (layerHandle.length>2) System.out.println("layerHandle[2] = " + layerHandle[2]);
1426
                if (layerHandle.length>3) System.out.println("layerHandle[3] = " + layerHandle[3]);
1427
                byte[] layerBytes = new byte[]{0,0,0,0};
1428
                if (layerHandle.length>2) layerBytes[3] = (byte)layerHandle[2];
1429
                if (layerHandle.length>3) layerBytes[2] = (byte)layerHandle[3];
1430
                if (layerHandle.length>4) layerBytes[1] = (byte)layerHandle[4];
1431
                if (layerHandle.length>5) layerBytes[0] = (byte)layerHandle[5];
1432
                int layer = ByteUtils.bytesToInt(layerBytes, new int[]{0});
1433
                for (int j=0;j<layerTable.size();j++) {
1434
                        Vector layerTableRecord = (Vector)layerTable.get(j);
1435
                        Vector layerHandleVect = (Vector)layerTableRecord.get(0);
1436
                        System.out.println("layerHandleVect.get(0) = " + layerHandleVect.get(0));
1437
                        if (layerHandleVect.size()>1) System.out.println("layerHandleVect.get(1) = " + layerHandleVect.get(1));
1438
                        if (layerHandleVect.size()>2) System.out.println("layerHandleVect.get(2) = " + layerHandleVect.get(2));
1439
                        if (layerHandleVect.size()>3) System.out.println("layerHandleVect.get(3) = " + layerHandleVect.get(3));
1440
                        byte[] layerHandleBytes = new byte[]{0,0,0,0};
1441
                        if (layerHandleVect.size()>2) layerHandleBytes[3] = (byte)((Integer)layerHandleVect.get(2)).intValue();
1442
                        if (layerHandleVect.size()>3) layerHandleBytes[2] = (byte)((Integer)layerHandleVect.get(3)).intValue();
1443
                        if (layerHandleVect.size()>4) layerHandleBytes[1] = (byte)((Integer)layerHandleVect.get(4)).intValue();
1444
                        if (layerHandleVect.size()>5) layerHandleBytes[0] = (byte)((Integer)layerHandleVect.get(5)).intValue();
1445
                        int lHandle = ByteUtils.bytesToInt(layerHandleBytes, new int[]{0});
1446
                        System.out.println("lHandle = " + lHandle);
1447
                        System.out.println("layer = " + layer);
1448
                        if (lHandle==layer) {
1449
                                layerName = (String)layerTableRecord.get(1);
1450
                                System.out.println("layerName = " + layerName);
1451
                        }
1452
                }
1453
                return layerName;
1454
        }
1455
1456 1881 jmorell
        private int getColorByLayer(DwgObject entity, Vector layerTable) {
1457
                int[] layerHandle = (int[])entity.getLayer();
1458 1880 jmorell
                int colorByLayer = 0;
1459
                byte[] layerBytes = new byte[]{0,0,0,0};
1460
                if (layerHandle.length>2) layerBytes[3] = (byte)layerHandle[2];
1461
                if (layerHandle.length>3) layerBytes[2] = (byte)layerHandle[3];
1462
                if (layerHandle.length>4) layerBytes[1] = (byte)layerHandle[4];
1463
                if (layerHandle.length>5) layerBytes[0] = (byte)layerHandle[5];
1464
                int layer = ByteUtils.bytesToInt(layerBytes, new int[]{0});
1465
                for (int j=0;j<layerTable.size();j++) {
1466
                        Vector layerTableRecord = (Vector)layerTable.get(j);
1467
                        Vector layerHandleVect = (Vector)layerTableRecord.get(0);
1468
                        byte[] layerHandleBytes = new byte[]{0,0,0,0};
1469
                        if (layerHandleVect.size()>2) layerHandleBytes[3] = (byte)((Integer)layerHandleVect.get(2)).intValue();
1470
                        if (layerHandleVect.size()>3) layerHandleBytes[2] = (byte)((Integer)layerHandleVect.get(3)).intValue();
1471
                        if (layerHandleVect.size()>4) layerHandleBytes[1] = (byte)((Integer)layerHandleVect.get(4)).intValue();
1472
                        if (layerHandleVect.size()>5) layerHandleBytes[0] = (byte)((Integer)layerHandleVect.get(5)).intValue();
1473
                        int lHandle = ByteUtils.bytesToInt(layerHandleBytes, new int[]{0});
1474
                        //System.out.println("layerHandle = " + layerHandle);
1475
                        //System.out.println("layer = " + layer);
1476
                        if (lHandle==layer) {
1477
                                colorByLayer = ((Integer)layerTableRecord.get(2)).intValue();
1478
                                //System.out.println("colorByLayer = " + colorByLayerObj.intValue());
1479
                        }
1480
                }
1481
                return colorByLayer;
1482
        }
1483
1484 1881 jmorell
        private int handleBinToHandleInt(Vector layerHandle) {
1485
                byte[] layerBytes = new byte[]{0,0,0,0};
1486
                if (layerHandle.size()>2) layerBytes[3] = (byte)((Integer)layerHandle.get(2)).intValue();
1487
                if (layerHandle.size()>3) layerBytes[2] = (byte)((Integer)layerHandle.get(3)).intValue();
1488
                if (layerHandle.size()>4) layerBytes[1] = (byte)((Integer)layerHandle.get(4)).intValue();;
1489
                if (layerHandle.size()>5) layerBytes[0] = (byte)((Integer)layerHandle.get(5)).intValue();
1490
                int layer = ByteUtils.bytesToInt(layerBytes, new int[]{0});
1491
                return layer;
1492
        }
1493
1494 1843 jmorell
        /* (non-Javadoc)
1495
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#accept(java.io.File)
1496
         */
1497
        public boolean accept(File f) {
1498
                return f.getName().toUpperCase().endsWith("DWG");
1499
        }
1500
1501
        /* (non-Javadoc)
1502
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getShapeType()
1503
         */
1504
        public int getShapeType() {
1505
                return FShape.MULTI;
1506
        }
1507
1508
        /* (non-Javadoc)
1509
         * @see com.iver.cit.gvsig.fmap.drivers.MemoryDriver#getName()
1510
         */
1511
        public String getName() {
1512
                return "gvSIG DWG Memory Driver";
1513
        }
1514
1515
        /* (non-Javadoc)
1516
         * @see com.iver.cit.gvsig.fmap.drivers.WithDefaultLegend#getDefaultLegend()
1517
         */
1518
        public Legend getDefaultLegend() {
1519
                return defaultLegend;
1520
        }
1521
1522
    /* (non-Javadoc)
1523
     * @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
1524
     */
1525
    public DriverAttributes getDriverAttributes() {
1526
        return attr;
1527
    }
1528
1529
}