Statistics
| Revision:

root / trunk / org.gvsig.dwg / org.gvsig.dwg.lib / src / main / java / org / gvsig / dwg / lib / readers / DwgFileVR2004Reader.java @ 76

History | View | Annotate | Download (104 KB)

1
/*
2
 * Created on 09-ene-2007
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

    
45
package org.gvsig.dwg.lib.readers;
46

    
47
import java.io.IOException;
48
import java.nio.ByteBuffer;
49
import java.nio.ByteOrder;
50
import java.util.ArrayList;
51
import java.util.Comparator;
52
import java.util.List;
53
import java.util.TreeSet;
54

    
55
import org.gvsig.dwg.lib.CorruptedDwgEntityException;
56
import org.gvsig.dwg.lib.DwgClass2004;
57
import org.gvsig.dwg.lib.DwgFile;
58
import org.gvsig.dwg.lib.DwgHandleReference;
59
import org.gvsig.dwg.lib.DwgObject;
60
import org.gvsig.dwg.lib.DwgObjectFactory;
61
import org.gvsig.dwg.lib.DwgObjectOffset;
62
import org.gvsig.dwg.lib.DwgUtil;
63
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65

    
66

    
67

    
68
/**
69
 * @author alzabord
70
 *
71
 * TODO To change the template for this generated type comment go to Window -
72
 * Preferences - Java - Code Style - Code Templates
73
 */
74
public class DwgFileVR2004Reader implements IDwgFileReader {
75

    
76
        protected DwgFile dwgFile;
77

    
78
        protected ByteBuffer bb;
79

    
80
        static byte[] magicNumber = null;
81

    
82
        private String version = "";
83

    
84
        private byte[] unknowSixBytes;
85

    
86
        private byte[] threeBytes0;
87

    
88
        private byte[] unknowTwoBytes;
89

    
90
        private byte[] eightyTwoBytes0;
91

    
92
        private byte[] encryptedData;
93

    
94
        private byte[] decryptedData;
95

    
96
        private String fileID = "";
97

    
98
        private int rootTreeNodeGap;
99

    
100
        private int lowermostLeftTreeNodeGap;
101

    
102
        private int lowermostRightTreeNodeGap;
103

    
104
        private int lastSectionId; // Last Section identifier
105

    
106
        private int lastSectionAddress; // Last Section Address
107

    
108
        private int SecondHeaderAddress; // Second Header Address
109

    
110
        private int gapAmount; // Number of Gaps
111

    
112
        private int sectionAmount; // Number of Sections
113

    
114
        private int sectionMapId; // Section Map identifier
115

    
116
        private int sectionMapAddress; // Section Map address
117

    
118
        private int sectionInfoId; // Section Info identifier
119

    
120
        private int sectionInfoIndex = 0; // Section Info identifier into the
121

    
122
        // Sections Array
123

    
124
        private int sectionArraySize;
125

    
126
        private int gapArraySize;
127

    
128
        private byte[] generatedSequence;
129

    
130
        private Section[] sections;
131

    
132
        private Gap[] gaps;
133

    
134
        static final int TYPE_SECTION_MAP = 1;
135

    
136
        static final int TYPE_SECTION_INFO = 2;
137

    
138
        private static Logger logger = LoggerFactory.getLogger(DwgFileVR2004Reader.class.getName());
139

    
140
        /**
141
         * Reads the DWG version 2004 format
142
         *
143
         * @param dwgFile
144
         *            Represents the DWG file that we want to read
145
         * @throws IOException
146
         *             When DWG file path is wrong
147
         */
148
        public void read(DwgFile dwgFile, ByteBuffer bb) throws IOException {
149

    
150
                this.dwgFile = dwgFile;
151
                this.bb = bb;
152

    
153
                readDwgR2004FileHeader(bb);
154
                readDwgR2004SectionMap(bb);
155
                readDwgR2004InfoSection(bb);
156
                readDwgR2004Headers(bb);
157
                readDwgR2004Classes(bb);
158
                readDwgR2004ObjectOffsets(bb);
159

    
160
                readDwgR2004Objects();
161

    
162
        }
163

    
164
        protected void readDwgR2004InfoSection(ByteBuffer bb) {
165
                int numDescriptions;
166

    
167
                int sizeOfSection;
168
                int numSections;
169
                int maxDecompressedSize;
170
                int compressed;
171
                int sectionType;
172
                int encrypted;
173
                String sectionName = "";
174

    
175
                int sectionNumber;
176
                int dataSize;
177
                int startOffset;
178

    
179
                char c;
180
                int pos;
181

    
182
                if (sectionInfoIndex == 0) {
183
                        logger.trace("No se ha encontrado la Section Info en el array de secciones.");
184
                }
185

    
186
                pos = sections[sectionInfoIndex].getAddress(); // we get the address for the Section Info
187

    
188
                bb.position(pos);
189

    
190
                ByteBuffer dData = readSystemSection(bb);
191
                dData.order(ByteOrder.LITTLE_ENDIAN);
192
                dData.position(0);
193

    
194
                /*
195
                 * We start reading the Section Info once decompressed We will find data
196
                 * blocks depending on numDescriptions value
197
                 */
198
                numDescriptions = dData.getInt();
199
                dData.getInt(); // 0x02
200
                dData.getInt(); // 0x00007400
201
                dData.getInt(); // 0x00
202
                dData.getInt(); // unknown
203

    
204
                for (int i = 0; i < numDescriptions; i++) {
205
                        sizeOfSection = dData.getInt();
206
                        dData.getInt(); // unknown
207
                        numSections = dData.getInt();
208
                        maxDecompressedSize = dData.getInt();
209
                        dData.getInt(); // unknown
210
                        compressed = dData.getInt();
211
                        sectionType = dData.getInt();
212
                        encrypted = dData.getInt();
213
                        sectionName = "";
214
                        for (int j = 0; j < 64; j++) {
215
                                c = (char) dData.get();
216
                                sectionName = sectionName + c;
217
                        }
218

    
219
                        for (int k = 0; k < numSections; k++) {
220
                                sectionNumber = dData.getInt(); // index into the Sections Array
221
                                dataSize = dData.getInt();
222
                                startOffset = dData.getInt();
223
                                dData.getInt(); // unknown
224

    
225

    
226
                                // We set the name for the Section, so we can localize it by the name
227
                                for (int j = 0; j < sectionAmount; j++) {
228
                                        Section section = sections[j];
229
                                        if (section.getNumber() == sectionNumber) {
230
                                                section.setName(sectionName);
231
                                                section.setSizeOfLogicalSection(sizeOfSection);
232
                                                section.setDataSize(dataSize);
233
                                                section.setMaxDecompressedSize(maxDecompressedSize);
234
                                                section.setCompressed(compressed);
235
                                                section.setType(sectionType);
236
                                                section.setEncrypted(encrypted);
237
                                                section.setStartOffset(startOffset);
238
                                        }
239
                                }
240

    
241
                        }
242
                }
243
        }
244

    
245
        /**
246
         * This function reads the header section of the file, with the encrypted
247
         * data
248
         *
249
         * @param bb
250
         *            ByteBuffer containing the opened DWG file
251
         */
252
        protected void readDwgR2004FileHeader(ByteBuffer bb) {
253

    
254
                logger.trace("STARTING TO READ DWG FILE.");
255
                bb.order(ByteOrder.LITTLE_ENDIAN);
256
                for (int i = 0; i < 6; i++) {
257
                        version = version + (char) bb.get();
258
                }
259
                if (!version.equalsIgnoreCase("AC1018")) {
260
                        logger.trace("Error en la version: " + version);
261
                }
262

    
263
                /*
264
                 * OpenAlliance documentation says we will read 6 0x00 bytes but the
265
                 * sixth one is always 0x4C
266
                 */
267
                unknowSixBytes = new byte[6];
268
                int pos = 6;
269
                for (int i = 0; i < 5; i++) {
270
                        unknowSixBytes[i] = bb.get();
271
                        if (unknowSixBytes[i] != 0) {
272
                                logger.trace("(unknowSixBytes) En la posicion 0x"
273
                                                + Integer.toHexString(pos + i)
274
                                                + " deber?a haber un 0, pero hay un 0x"
275
                                                + Integer.toHexString(unknowSixBytes[i]));
276
                        }
277
                }
278
                pos = 0xB;
279
                unknowSixBytes[5] = bb.get();
280
                if (unknowSixBytes[5] != 0x4C) {
281
                        logger.trace("(unknowSixBytes) En la posicion 0x"
282
                                        + Integer.toHexString(pos)
283
                                        + " deber?a haber un 0x4C, pero hay un 0x"
284
                                        + Integer.toHexString(unknowSixBytes[5]));
285
                }
286

    
287
                bb.get(); // Unknown Byte
288
                bb.getInt(); // previewAddress
289
                bb.get(); // dwgVer
290
                bb.get(); // maintReleaseVer
291
                bb.getShort(); // codepage
292

    
293
                /*
294
                 * OpenAlliance documentation says we will read 3 0x00 bytes but what we
295
                 * always find is 0x00, 0x19 and then 0x4C
296
                 */
297
                threeBytes0 = new byte[3];
298
                pos = 0x15;
299
                bb.get(threeBytes0);
300
                if (threeBytes0[0] != 0x0) {
301
                        logger.trace("Posible error leyendo la cabecera del archivo DWG: " +
302
                                        "En la posicion 0x" + Integer.toHexString(pos)
303
                                        + " deber?a haber un 0x0, pero hay un 0x"
304
                                        + Integer.toHexString(threeBytes0[0]));
305
                }
306
                pos = 0x16;
307
                if (threeBytes0[1] != 0x19) {
308
                        logger.trace("Posible error leyendo la cabecera del archivo DWG: " +
309
                                        "En la posicion 0x" + Integer.toHexString(pos)
310
                                        + " deber?a haber un 0x19, pero hay un 0x"
311
                                        + Integer.toHexString(threeBytes0[1]));
312
                }
313
                pos = 0x17;
314
                if (threeBytes0[2] != 0x4C) {
315
                        logger.trace("Posible error leyendo la cabecera del archivo DWG: " +
316
                                        "En la posicion 0x" + Integer.toHexString(pos)
317
                                        + " deber?a haber un 0x4C, pero hay un 0x"
318
                                        + Integer.toHexString(threeBytes0[2]));
319
                }
320

    
321
                bb.getInt(); // security Type
322
                bb.getInt(); // unknownLong
323
                bb.getInt(); // dwgPropertyAddr
324
                bb.getInt(); // vbaProjectAddr
325
                bb.getInt(); // 0x00000080
326

    
327
                pos = 0x2C;
328

    
329
                unknowTwoBytes = new byte[2];
330
                for (int i = 0; i < 2; i++) {
331
                        unknowTwoBytes[i] = bb.get();
332
                }
333
                pos = 0x2E;
334
                eightyTwoBytes0 = new byte[82];
335
                for (int i = 0; i < eightyTwoBytes0.length; i++) {
336
                        eightyTwoBytes0[i] = bb.get();
337
                        if (eightyTwoBytes0[i] != 0) {
338
                                logger.trace("Posible error leyendo la cabecera del archivo DWG: " +
339
                                                "(eightyTwoBytes0) En la posicion 0x"
340
                                                + Integer.toHexString(pos + i)
341
                                                + " deber?a haber un 0, pero hay un 0x"
342
                                                + Integer.toHexString(eightyTwoBytes0[i]));
343
                        }
344
                }
345

    
346
                int len = 0x6C;
347
                encryptedData = new byte[len];
348
                decryptedData = new byte[len];
349
                if (magicNumber == null) {
350
                        DwgFileVR2004Reader.setMagicNumber();
351
                }
352

    
353
                // decryptedData will contain the decrypted sequence after xor'ing the
354
                // encrypted data
355
                for (int i = 0; i < len; i++) {
356
                        encryptedData[i] = bb.get();
357
                        decryptedData[i] = (byte) (encryptedData[i] ^ magicNumber[i]);
358
                }
359

    
360
                ByteBuffer decryptedDataBB = ByteBuffer.allocate(len);
361
                decryptedDataBB.put(decryptedData);
362
                decryptedDataBB.position(0);
363
                decryptedDataBB.order(ByteOrder.LITTLE_ENDIAN);
364

    
365
                // we start intercepting the decrypted variables
366
                for (int i = 0; i < 12; i++) {
367
                        fileID = fileID + (char) decryptedDataBB.get();
368
                }
369
                decryptedDataBB.getInt(); // 0x00
370

    
371
                decryptedDataBB.getInt(); // 0x6C
372

    
373
                decryptedDataBB.getInt(); // 0x04
374

    
375
                rootTreeNodeGap = decryptedDataBB.getInt();
376
                lowermostLeftTreeNodeGap = decryptedDataBB.getInt();
377
                lowermostRightTreeNodeGap = decryptedDataBB.getInt();
378
                decryptedDataBB.getInt(); // unknown
379
                lastSectionId = decryptedDataBB.getInt();
380

    
381
                lastSectionAddress = decryptedDataBB.getInt();
382
                decryptedDataBB.getInt(); // 0x00
383

    
384
                SecondHeaderAddress = decryptedDataBB.getInt();
385
                decryptedDataBB.getInt(); // 0x00
386

    
387
                gapAmount = decryptedDataBB.getInt();
388
                sectionAmount = decryptedDataBB.getInt(); // Very important: this is
389
                // the number of sections in the file
390
                decryptedDataBB.getInt(); // 0x20
391
                decryptedDataBB.getInt(); // 0x80
392
                decryptedDataBB.getInt(); // 0x40
393

    
394
                sectionMapId = decryptedDataBB.getInt();
395
                sectionMapAddress = decryptedDataBB.getInt() + 0x100; // the Section Map Address
396
                decryptedDataBB.getInt(); // 0x00
397
                sectionInfoId = decryptedDataBB.getInt(); // Very important: the id of the Section Info
398
                sectionArraySize = decryptedDataBB.getInt();
399
                gapArraySize = decryptedDataBB.getInt();
400
                decryptedDataBB.getInt(); // CRC
401
                len = 0x14;
402
                generatedSequence = new byte[len];
403
                bb.get(generatedSequence);
404
                // Done reading the encrypted variables
405

    
406
        }
407

    
408
        /*************************************************************************************
409
         * **********************************************************************/
410

    
411
        /**
412
         * Read and store all the header variables into the
413
         * <code> HeaderVars </code> Map
414
         *
415
         * @param bb
416
         *            ByteBuffer containing the opened DWG file
417
         */
418
        private void readDwgR2004Headers(ByteBuffer bb) {
419

    
420
                /*
421
                 * NOTA (Paco) He encontrado un sitio web con explicacion de ?todas?
422
                 * estas variables: http://www.hispacad.com/variables
423
                 */
424

    
425
                ByteBuffer decompressedBB = readSection(bb, "AcDb:Header");
426

    
427
                byte[] sentinel = new byte[16];
428
                decompressedBB.order(ByteOrder.nativeOrder());
429
                decompressedBB.position(0);
430
                decompressedBB.get(sentinel); // we get the sentinel that ALWAYS
431
                // appears before the data
432

    
433
                if ((sentinel[0] & 0xFF) != 0xcf)
434
                        logger.trace("sentinel[0] != 0xcf found " + (sentinel[0] & 0xFF));
435
                if ((sentinel[1] & 0xFF) != 0x7b)
436
                        logger.trace("sentinel[1] != 0x7b found " + (sentinel[1] & 0xFF));
437
                if ((sentinel[2] & 0xFF) != 0x1f)
438
                        logger.trace("sentinel[2] != 0x1f found " + (sentinel[2] & 0xFF));
439
                if ((sentinel[3] & 0xFF) != 0x23)
440
                        logger.trace("sentinel[3] != 0x23 found " + (sentinel[3] & 0xFF));
441
                if ((sentinel[4] & 0xFF) != 0xfd)
442
                        logger.trace("sentinel[4] != 0xfd found " + (sentinel[4] & 0xFF));
443
                if ((sentinel[5] & 0xFF) != 0xde)
444
                        logger.trace("sentinel[5] != 0xde found " + (sentinel[5] & 0xFF));
445
                if ((sentinel[6] & 0xFF) != 0x38)
446
                        logger.trace("sentinel[6] != 0x38 found " + (sentinel[6] & 0xFF));
447
                if ((sentinel[7] & 0xFF) != 0xa9)
448
                        logger.trace("sentinel[7] != 0xa9 found " + (sentinel[7] & 0xFF));
449
                if ((sentinel[8] & 0xFF) != 0x5f)
450
                        logger.trace("sentinel[8] != 0x5f found " + (sentinel[8] & 0xFF));
451
                if ((sentinel[9] & 0xFF) != 0x7c)
452
                        logger.trace("sentinel[9] != 0x7c found " + (sentinel[9] & 0xFF));
453
                if ((sentinel[10] & 0xFF) != 0x68)
454
                        logger.trace("sentinel[10] != 0x68 found " + (sentinel[10] & 0xFF));
455
                if ((sentinel[11] & 0xFF) != 0xb8)
456
                        logger.trace("sentinel[11] != 0xb8 found " + (sentinel[11] & 0xFF));
457
                if ((sentinel[12] & 0xFF) != 0x4e)
458
                        logger.trace("sentinel[12] != 0x4e found " + (sentinel[12] & 0xFF));
459
                if ((sentinel[13] & 0xFF) != 0x6d)
460
                        logger.trace("sentinel[13] != 0x6d found " + (sentinel[13] & 0xFF));
461
                if ((sentinel[14] & 0xFF) != 0x33)
462
                        logger.trace("sentinel[14] != 0x33 found " + (sentinel[14] & 0xFF));
463
                if ((sentinel[15] & 0xFF) != 0x5f)
464
                        logger.trace("sentinel[15] != 0x5f found " + (sentinel[15] & 0xFF));
465

    
466
                // we start working with data that comes after the beginning sentinel
467
                decompressedBB.order(ByteOrder.LITTLE_ENDIAN);
468
                int size = decompressedBB.getInt(); // this size is never correct
469

    
470
                decompressedBB.order(ByteOrder.nativeOrder());
471
                byte[] data = new byte[size];
472
                decompressedBB.get(data);
473

    
474
                int[] intData = DwgUtil.toIntArray(data);
475

    
476
                bb.order(ByteOrder.LITTLE_ENDIAN);
477
                decompressedBB.getShort(); // CRC
478

    
479
                decompressedBB.order(ByteOrder.nativeOrder());
480
                byte[] lastSentinnel = new byte[16]; // we know it comes there because we already found it
481
                decompressedBB.get(lastSentinnel);
482

    
483
                if ((lastSentinnel[0] & 0xFF) != 0x30)
484
                        logger.trace("lastSentinnel[0] != 0x30 , is: " + lastSentinnel[0]);
485
                if ((lastSentinnel[1] & 0xFF) != 0x84)
486
                        logger.trace("lastSentinnel[1] != 0x84 , is: " + lastSentinnel[1]);
487
                if ((lastSentinnel[2] & 0xFF) != 0xe0)
488
                        logger.trace("lastSentinnel[2] != 0xe0 , is: " + lastSentinnel[2]);
489
                if ((lastSentinnel[3] & 0xFF) != 0xdc)
490
                        logger.trace("lastSentinnel[3] != 0xdc , is: " + lastSentinnel[3]);
491
                if ((lastSentinnel[4] & 0xFF) != 0x02)
492
                        logger.trace("lastSentinnel[4] != 0x02 , is: " + lastSentinnel[4]);
493
                if ((lastSentinnel[5] & 0xFF) != 0x21)
494
                        logger.trace("lastSentinnel[5] != 0x21 , is: " + lastSentinnel[5]);
495
                if ((lastSentinnel[6] & 0xFF) != 0xc7)
496
                        logger.trace("lastSentinnel[6] != 0xc7 , is: " + lastSentinnel[6]);
497
                if ((lastSentinnel[7] & 0xFF) != 0x56)
498
                        logger.trace("lastSentinnel[7] != 0x56 , is: " + lastSentinnel[7]);
499
                if ((lastSentinnel[8] & 0xFF) != 0xa0)
500
                        logger.trace("lastSentinnel[8] != 0xa0 , is: " + lastSentinnel[8]);
501
                if ((lastSentinnel[9] & 0xFF) != 0x83)
502
                        logger.trace("lastSentinnel[9] != 0x83 , is: " + lastSentinnel[9]);
503
                if ((lastSentinnel[10] & 0xFF) != 0x97)
504
                        logger.trace("lastSentinnel[10] != 0x97 , is: " + lastSentinnel[10]);
505
                if ((lastSentinnel[11] & 0xFF) != 0x47)
506
                        logger.trace("lastSentinnel[11] != 0x47 , is: " + lastSentinnel[11]);
507
                if ((lastSentinnel[12] & 0xFF) != 0xb1)
508
                        logger.trace("lastSentinnel[12] != 0xb1 , is: " + lastSentinnel[12]);
509
                if ((lastSentinnel[13] & 0xFF) != 0x92)
510
                        logger.trace("lastSentinnel[13] != 0x92 , is: " + lastSentinnel[13]);
511
                if ((lastSentinnel[14] & 0xFF) != 0xcc)
512
                        logger.trace("lastSentinnel[14] != 0xcc , is: " + lastSentinnel[14]);
513
                if ((lastSentinnel[15] & 0xFF) != 0xa0)
514
                        logger.trace("lastSentinnel[15] != 0xa0 , is: " + lastSentinnel[15]);
515

    
516
                int bitPos = 0;
517
                try {
518

    
519
                        List val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
520
                        bitPos = ((Integer) val.get(0)).intValue();
521
                        dwgFile.setHeader("VAL1", val.get(1));
522

    
523
                        val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
524
                        bitPos = ((Integer) val.get(0)).intValue();
525
                        dwgFile.setHeader("VAL2", val.get(1));
526

    
527
                        val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
528
                        bitPos = ((Integer) val.get(0)).intValue();
529
                        dwgFile.setHeader("VAL3", val.get(1));
530

    
531
                        val = DwgUtil.getBitDouble(intData, bitPos); // Unknown
532
                        bitPos = ((Integer) val.get(0)).intValue();
533
                        dwgFile.setHeader("VAL4", val.get(1));
534

    
535
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
536
                        bitPos = ((Integer) val.get(0)).intValue();
537
                        dwgFile.setHeader("STRING1", val.get(1));
538

    
539
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
540
                        bitPos = ((Integer) val.get(0)).intValue();
541
                        dwgFile.setHeader("STRING2", val.get(1));
542

    
543
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
544
                        bitPos = ((Integer) val.get(0)).intValue();
545
                        dwgFile.setHeader("STRING3", val.get(1));
546

    
547
                        val = DwgUtil.getTextString(intData, bitPos); // Unknown
548
                        bitPos = ((Integer) val.get(0)).intValue();
549
                        dwgFile.setHeader("STRING4", val.get(1));
550

    
551
                        val = DwgUtil.getBitLong(intData, bitPos); // Unknown
552
                        bitPos = ((Integer) val.get(0)).intValue();
553
                        dwgFile.setHeader("LONG1", val.get(1));
554

    
555
                        val = DwgUtil.getBitLong(intData, bitPos); // Unknown
556
                        bitPos = ((Integer) val.get(0)).intValue();
557
                        dwgFile.setHeader("LONG2", val.get(1));
558

    
559
                        val = DwgUtil.testBit(intData, bitPos);
560
                        bitPos = ((Integer) val.get(0)).intValue();
561
                        dwgFile.setHeader("DIMASO", val.get(1));
562

    
563
                        val = DwgUtil.testBit(intData, bitPos);
564
                        bitPos = ((Integer) val.get(0)).intValue();
565
                        dwgFile.setHeader("DIMSHO", val.get(1));
566

    
567
                        val = DwgUtil.testBit(intData, bitPos);
568
                        bitPos = ((Integer) val.get(0)).intValue();
569
                        dwgFile.setHeader("PLINEGEN", val.get(1));
570

    
571
                        val = DwgUtil.testBit(intData, bitPos);
572
                        bitPos = ((Integer) val.get(0)).intValue();
573
                        dwgFile.setHeader("ORTHOMODE", val.get(1));
574

    
575
                        val = DwgUtil.testBit(intData, bitPos);
576
                        bitPos = ((Integer) val.get(0)).intValue();
577
                        dwgFile.setHeader("REGENMODE", val.get(1));
578

    
579
                        val = DwgUtil.testBit(intData, bitPos);
580
                        bitPos = ((Integer) val.get(0)).intValue();
581
                        dwgFile.setHeader("FILLMODE", val.get(1));
582

    
583
                        val = DwgUtil.testBit(intData, bitPos);
584
                        bitPos = ((Integer) val.get(0)).intValue();
585
                        dwgFile.setHeader("QTEXTMODE", val.get(1));
586

    
587
                        val = DwgUtil.testBit(intData, bitPos);
588
                        bitPos = ((Integer) val.get(0)).intValue();
589
                        dwgFile.setHeader("PSLTSCALE", val.get(1));
590

    
591
                        val = DwgUtil.testBit(intData, bitPos);
592
                        bitPos = ((Integer) val.get(0)).intValue();
593
                        dwgFile.setHeader("LIMCHECK", val.get(1));
594

    
595
                        val = DwgUtil.testBit(intData, bitPos);
596
                        bitPos = ((Integer) val.get(0)).intValue();
597
                        dwgFile.setHeader("UNDOCUMENTED1", val.get(1));
598

    
599
                        val = DwgUtil.testBit(intData, bitPos);
600
                        bitPos = ((Integer) val.get(0)).intValue();
601
                        dwgFile.setHeader("USER_TIMER", val.get(1));
602

    
603
                        val = DwgUtil.testBit(intData, bitPos);
604
                        bitPos = ((Integer) val.get(0)).intValue();
605
                        dwgFile.setHeader("SKPOLY", val.get(1));
606

    
607
                        val = DwgUtil.testBit(intData, bitPos);
608
                        bitPos = ((Integer) val.get(0)).intValue();
609
                        dwgFile.setHeader("ANGDIR", val.get(1));
610

    
611
                        val = DwgUtil.testBit(intData, bitPos);
612
                        bitPos = ((Integer) val.get(0)).intValue();
613
                        dwgFile.setHeader("SPLFRAME", val.get(1));
614

    
615
                        val = DwgUtil.testBit(intData, bitPos);
616
                        bitPos = ((Integer) val.get(0)).intValue();
617
                        dwgFile.setHeader("MIRRTEXT", val.get(1));
618

    
619
                        val = DwgUtil.testBit(intData, bitPos);
620
                        bitPos = ((Integer) val.get(0)).intValue();
621
                        dwgFile.setHeader("WORLDVIEW", val.get(1));
622

    
623
                        val = DwgUtil.testBit(intData, bitPos);
624
                        bitPos = ((Integer) val.get(0)).intValue();
625
                        dwgFile.setHeader("TILEMODE", val.get(1));
626

    
627
                        val = DwgUtil.testBit(intData, bitPos);
628
                        bitPos = ((Integer) val.get(0)).intValue();
629
                        dwgFile.setHeader("PLIMCHECK", val.get(1));
630

    
631
                        val = DwgUtil.testBit(intData, bitPos);
632
                        bitPos = ((Integer) val.get(0)).intValue();
633
                        dwgFile.setHeader("VISRETAIN", val.get(1));
634

    
635
                        val = DwgUtil.testBit(intData, bitPos);
636
                        bitPos = ((Integer) val.get(0)).intValue();
637
                        dwgFile.setHeader("DISPSILH", val.get(1));
638

    
639
                        val = DwgUtil.testBit(intData, bitPos);
640
                        bitPos = ((Integer) val.get(0)).intValue();
641
                        dwgFile.setHeader("PELLISE", val.get(1));
642

    
643
                        val = DwgUtil.getBitShort(intData, bitPos);
644
                        bitPos = ((Integer) val.get(0)).intValue();
645
                        dwgFile.setHeader("PROXYGRAPH", val.get(1));
646

    
647
                        val = DwgUtil.getBitShort(intData, bitPos);
648
                        bitPos = ((Integer) val.get(0)).intValue();
649
                        dwgFile.setHeader("TREEDEPTH", val.get(1));
650

    
651
                        val = DwgUtil.getBitShort(intData, bitPos);
652
                        bitPos = ((Integer) val.get(0)).intValue();
653
                        dwgFile.setHeader("LUNITS", val.get(1));
654

    
655
                        val = DwgUtil.getBitShort(intData, bitPos);
656
                        bitPos = ((Integer) val.get(0)).intValue();
657
                        dwgFile.setHeader("LUPREC", val.get(1));
658

    
659
                        val = DwgUtil.getBitShort(intData, bitPos);
660
                        bitPos = ((Integer) val.get(0)).intValue();
661
                        dwgFile.setHeader("AUNITS", val.get(1));
662

    
663
                        val = DwgUtil.getBitShort(intData, bitPos);
664
                        bitPos = ((Integer) val.get(0)).intValue();
665
                        dwgFile.setHeader("AUPREC", val.get(1));
666

    
667
                        val = DwgUtil.getBitShort(intData, bitPos);
668
                        bitPos = ((Integer) val.get(0)).intValue();
669
                        dwgFile.setHeader("ATTMODE", val.get(1));
670

    
671
                        val = DwgUtil.getBitShort(intData, bitPos);
672
                        bitPos = ((Integer) val.get(0)).intValue();
673
                        dwgFile.setHeader("PDMODE", val.get(1));
674

    
675
                        val = DwgUtil.getBitLong(intData, bitPos);
676
                        bitPos = ((Integer) val.get(0)).intValue();
677
                        dwgFile.setHeader("UNKNOWN1", val.get(1));
678

    
679
                        val = DwgUtil.getBitLong(intData, bitPos);
680
                        bitPos = ((Integer) val.get(0)).intValue();
681
                        dwgFile.setHeader("UNKNOWN2", val.get(1));
682

    
683
                        val = DwgUtil.getBitLong(intData, bitPos);
684
                        bitPos = ((Integer) val.get(0)).intValue();
685
                        dwgFile.setHeader("UNKNOWN3", val.get(1));
686

    
687
                        val = DwgUtil.getBitShort(intData, bitPos);
688
                        bitPos = ((Integer) val.get(0)).intValue();
689
                        dwgFile.setHeader("USERI1", val.get(1));
690

    
691
                        val = DwgUtil.getBitShort(intData, bitPos);
692
                        bitPos = ((Integer) val.get(0)).intValue();
693
                        dwgFile.setHeader("USERI2", val.get(1));
694

    
695
                        val = DwgUtil.getBitShort(intData, bitPos);
696
                        bitPos = ((Integer) val.get(0)).intValue();
697
                        dwgFile.setHeader("USERI3", val.get(1));
698

    
699
                        val = DwgUtil.getBitShort(intData, bitPos);
700
                        bitPos = ((Integer) val.get(0)).intValue();
701
                        dwgFile.setHeader("USERI4", val.get(1));
702

    
703
                        val = DwgUtil.getBitShort(intData, bitPos);
704
                        bitPos = ((Integer) val.get(0)).intValue();
705
                        dwgFile.setHeader("USERI5", val.get(1));
706

    
707
                        val = DwgUtil.getBitShort(intData, bitPos);
708
                        bitPos = ((Integer) val.get(0)).intValue();
709
                        dwgFile.setHeader("SPLINESEGS", val.get(1));
710

    
711
                        val = DwgUtil.getBitShort(intData, bitPos);
712
                        bitPos = ((Integer) val.get(0)).intValue();
713
                        dwgFile.setHeader("SURFU", val.get(1));
714

    
715
                        val = DwgUtil.getBitShort(intData, bitPos);
716
                        bitPos = ((Integer) val.get(0)).intValue();
717
                        dwgFile.setHeader("SURFV", val.get(1));
718

    
719
                        val = DwgUtil.getBitShort(intData, bitPos);
720
                        bitPos = ((Integer) val.get(0)).intValue();
721
                        dwgFile.setHeader("SURFTYPE", val.get(1));
722

    
723
                        val = DwgUtil.getBitShort(intData, bitPos);
724
                        bitPos = ((Integer) val.get(0)).intValue();
725
                        dwgFile.setHeader("SURFTAB1", val.get(1));
726

    
727
                        val = DwgUtil.getBitShort(intData, bitPos);
728
                        bitPos = ((Integer) val.get(0)).intValue();
729
                        dwgFile.setHeader("SURFTAB2", val.get(1));
730

    
731
                        val = DwgUtil.getBitShort(intData, bitPos);
732
                        bitPos = ((Integer) val.get(0)).intValue();
733
                        dwgFile.setHeader("SPLINETYPE", val.get(1));
734

    
735
                        val = DwgUtil.getBitShort(intData, bitPos);
736
                        bitPos = ((Integer) val.get(0)).intValue();
737
                        dwgFile.setHeader("SHADEDGE", val.get(1));
738

    
739
                        val = DwgUtil.getBitShort(intData, bitPos);
740
                        bitPos = ((Integer) val.get(0)).intValue();
741
                        dwgFile.setHeader("SHADEDIF", val.get(1));
742

    
743
                        val = DwgUtil.getBitShort(intData, bitPos);
744
                        bitPos = ((Integer) val.get(0)).intValue();
745
                        dwgFile.setHeader("UNITMODE", val.get(1));
746

    
747
                        val = DwgUtil.getBitShort(intData, bitPos);
748
                        bitPos = ((Integer) val.get(0)).intValue();
749
                        dwgFile.setHeader("MAXACTVP", val.get(1));
750

    
751
                        val = DwgUtil.getBitShort(intData, bitPos);
752
                        bitPos = ((Integer) val.get(0)).intValue();
753
                        dwgFile.setHeader("ISOLINES", val.get(1));
754

    
755
                        val = DwgUtil.getBitShort(intData, bitPos);
756
                        bitPos = ((Integer) val.get(0)).intValue();
757
                        dwgFile.setHeader("CMLJUST", val.get(1));
758

    
759
                        val = DwgUtil.getBitShort(intData, bitPos);
760
                        bitPos = ((Integer) val.get(0)).intValue();
761
                        dwgFile.setHeader("TEXTQLTY", val.get(1));
762

    
763
                        val = DwgUtil.getBitDouble(intData, bitPos);
764
                        bitPos = ((Integer) val.get(0)).intValue();
765
                        dwgFile.setHeader("LTSCALE", val.get(1));
766

    
767
                        val = DwgUtil.getBitDouble(intData, bitPos);
768
                        bitPos = ((Integer) val.get(0)).intValue();
769
                        dwgFile.setHeader("TEXTSIZE", val.get(1));
770

    
771
                        val = DwgUtil.getBitDouble(intData, bitPos);
772
                        bitPos = ((Integer) val.get(0)).intValue();
773
                        dwgFile.setHeader("TRACEWID", val.get(1));
774

    
775
                        val = DwgUtil.getBitDouble(intData, bitPos);
776
                        bitPos = ((Integer) val.get(0)).intValue();
777
                        dwgFile.setHeader("SKETCHINC", val.get(1));
778

    
779
                        val = DwgUtil.getBitDouble(intData, bitPos);
780
                        bitPos = ((Integer) val.get(0)).intValue();
781
                        dwgFile.setHeader("FILLETRAD", val.get(1));
782

    
783
                        val = DwgUtil.getBitDouble(intData, bitPos);
784
                        bitPos = ((Integer) val.get(0)).intValue();
785
                        dwgFile.setHeader("THICKNESS", val.get(1));
786

    
787
                        val = DwgUtil.getBitDouble(intData, bitPos);
788
                        bitPos = ((Integer) val.get(0)).intValue();
789
                        dwgFile.setHeader("ANGBASE", val.get(1));
790

    
791
                        val = DwgUtil.getBitDouble(intData, bitPos);
792
                        bitPos = ((Integer) val.get(0)).intValue();
793
                        dwgFile.setHeader("PDSIZE", val.get(1));
794

    
795
                        val = DwgUtil.getBitDouble(intData, bitPos);
796
                        bitPos = ((Integer) val.get(0)).intValue();
797
                        dwgFile.setHeader("PLINEWID", val.get(1));
798

    
799
                        val = DwgUtil.getBitDouble(intData, bitPos);
800
                        bitPos = ((Integer) val.get(0)).intValue();
801
                        dwgFile.setHeader("USERR1", val.get(1));
802

    
803
                        val = DwgUtil.getBitDouble(intData, bitPos);
804
                        bitPos = ((Integer) val.get(0)).intValue();
805
                        dwgFile.setHeader("USERR2", val.get(1));
806

    
807
                        val = DwgUtil.getBitDouble(intData, bitPos);
808
                        bitPos = ((Integer) val.get(0)).intValue();
809
                        dwgFile.setHeader("USERR3", val.get(1));
810

    
811
                        val = DwgUtil.getBitDouble(intData, bitPos);
812
                        bitPos = ((Integer) val.get(0)).intValue();
813
                        dwgFile.setHeader("USERR4", val.get(1));
814

    
815
                        val = DwgUtil.getBitDouble(intData, bitPos);
816
                        bitPos = ((Integer) val.get(0)).intValue();
817
                        dwgFile.setHeader("USERR5", val.get(1));
818

    
819
                        val = DwgUtil.getBitDouble(intData, bitPos);
820
                        bitPos = ((Integer) val.get(0)).intValue();
821
                        dwgFile.setHeader("CHAMFERA", val.get(1));
822

    
823
                        val = DwgUtil.getBitDouble(intData, bitPos);
824
                        bitPos = ((Integer) val.get(0)).intValue();
825
                        dwgFile.setHeader("CHAMFERB", val.get(1));
826

    
827
                        val = DwgUtil.getBitDouble(intData, bitPos);
828
                        bitPos = ((Integer) val.get(0)).intValue();
829
                        dwgFile.setHeader("CHAMFERC", val.get(1));
830

    
831
                        val = DwgUtil.getBitDouble(intData, bitPos);
832
                        bitPos = ((Integer) val.get(0)).intValue();
833
                        dwgFile.setHeader("CHAMFERD", val.get(1));
834

    
835
                        val = DwgUtil.getBitDouble(intData, bitPos);
836
                        bitPos = ((Integer) val.get(0)).intValue();
837
                        dwgFile.setHeader("FACETRES", val.get(1));
838

    
839
                        val = DwgUtil.getBitDouble(intData, bitPos);
840
                        bitPos = ((Integer) val.get(0)).intValue();
841
                        dwgFile.setHeader("CMLSCALE", val.get(1));
842

    
843
                        val = DwgUtil.getBitDouble(intData, bitPos);
844
                        bitPos = ((Integer) val.get(0)).intValue();
845
                        dwgFile.setHeader("CELTSCALE", val.get(1));
846

    
847
                        val = DwgUtil.getTextString(intData, bitPos);
848
                        bitPos = ((Integer) val.get(0)).intValue();
849
                        dwgFile.setHeader("MENUNAME", val.get(1));
850

    
851
                        int[] tdcreate = new int[2];
852

    
853
                        val = DwgUtil.getBitLong(intData, bitPos);
854
                        bitPos = ((Integer) val.get(0)).intValue();
855
                        tdcreate[0] = ((Integer) val.get(1)).intValue();
856

    
857
                        val = DwgUtil.getBitLong(intData, bitPos);
858
                        bitPos = ((Integer) val.get(0)).intValue();
859
                        tdcreate[1] = ((Integer) val.get(1)).intValue();
860

    
861
                        dwgFile.setHeader("TDCREATE", tdcreate);
862

    
863
                        int[] tdupdate = new int[2];
864

    
865
                        val = DwgUtil.getBitLong(intData, bitPos);
866
                        bitPos = ((Integer) val.get(0)).intValue();
867
                        tdupdate[0] = ((Integer) val.get(1)).intValue();
868

    
869
                        val = DwgUtil.getBitLong(intData, bitPos);
870
                        bitPos = ((Integer) val.get(0)).intValue();
871
                        tdupdate[1] = ((Integer) val.get(1)).intValue();
872

    
873
                        dwgFile.setHeader("TDUPDATE", tdupdate);
874

    
875
                        val = DwgUtil.getBitLong(intData, bitPos);
876
                        bitPos = ((Integer) val.get(0)).intValue();
877
                        dwgFile.setHeader("UNKNOWN4", val.get(1));
878

    
879
                        val = DwgUtil.getBitLong(intData, bitPos);
880
                        bitPos = ((Integer) val.get(0)).intValue();
881
                        dwgFile.setHeader("UNKNOWN5", val.get(1));
882

    
883
                        val = DwgUtil.getBitLong(intData, bitPos);
884
                        bitPos = ((Integer) val.get(0)).intValue();
885
                        dwgFile.setHeader("UNKNOWN6", val.get(1));
886

    
887
                        int[] tdindwg = new int[2];
888

    
889
                        val = DwgUtil.getBitLong(intData, bitPos);
890
                        bitPos = ((Integer) val.get(0)).intValue();
891
                        tdindwg[0] = ((Integer) val.get(1)).intValue();
892

    
893
                        val = DwgUtil.getBitLong(intData, bitPos);
894
                        bitPos = ((Integer) val.get(0)).intValue();
895
                        tdindwg[1] = ((Integer) val.get(1)).intValue();
896

    
897
                        int[] tdusrtime = new int[2];
898

    
899
                        val = DwgUtil.getBitLong(intData, bitPos);
900
                        bitPos = ((Integer) val.get(0)).intValue();
901
                        tdusrtime[0] = ((Integer) val.get(1)).intValue();
902

    
903
                        val = DwgUtil.getBitLong(intData, bitPos);
904
                        bitPos = ((Integer) val.get(0)).intValue();
905
                        tdusrtime[1] = ((Integer) val.get(1)).intValue();
906

    
907
                        dwgFile.setHeader("TDUSRTIME", tdusrtime);
908

    
909
                        //FIXME: En versiones anteriores solo hab?a una variable
910
                        // "CECOLOR" de tipo entero, habr?a que comprobar donde se
911
                        // utiliza para, si es necesario, utilizar apropiadamente
912
                        // las nuevas.
913
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
914
                        bitPos = ((Integer) val.get(0)).intValue();
915
                        dwgFile.setHeader("CECOLOR", val.get(1));
916
                        dwgFile.setHeader("CECOLOR_RGBVALUE", val.get(2));
917
                        Object cecolorColorByte = val.get(3);
918
                        dwgFile.setHeader("CECOLOR_COLORBYTE", cecolorColorByte);
919
                        dwgFile.setHeader("CECOLOR_NAME", val.get(4));
920

    
921
                        dwgFile.getDwgVersion();
922

    
923
                        val = DwgUtil.getHandle(intData, bitPos);
924
                        bitPos = ((Integer) val.get(0)).intValue();
925
                        int intHandle = DwgUtil.handleToInt(val);
926
                        dwgFile.setHeader("HANDSEED", new Integer(intHandle));
927

    
928
                        val = DwgUtil.getHandle(intData, bitPos);
929
                        bitPos = ((Integer) val.get(0)).intValue();
930
                        intHandle = DwgUtil.handleToInt(val);
931
                        dwgFile.setHeader("CLAYER", new Integer(intHandle));
932

    
933
                        val = DwgUtil.getHandle(intData, bitPos);
934
                        bitPos = ((Integer) val.get(0)).intValue();
935
                        intHandle = DwgUtil.handleToInt(val);
936
                        dwgFile.setHeader("TEXSTYLE", new Integer(intHandle));
937

    
938
                        val = DwgUtil.getHandle(intData, bitPos);
939
                        bitPos = ((Integer) val.get(0)).intValue();
940
                        intHandle = DwgUtil.handleToInt(val);
941
                        dwgFile.setHeader("CELLTYPE", new Integer(intHandle));
942

    
943
                        val = DwgUtil.getHandle(intData, bitPos);
944
                        bitPos = ((Integer) val.get(0)).intValue();
945
                        intHandle = DwgUtil.handleToInt(val);
946
                        dwgFile.setHeader("DIMSTYLE", new Integer(intHandle));
947

    
948
                        val = DwgUtil.getHandle(intData, bitPos);
949
                        bitPos = ((Integer) val.get(0)).intValue();
950
                        intHandle = DwgUtil.handleToInt(val);
951
                        dwgFile.setHeader("CMLSTYLE", new Integer(intHandle));
952

    
953
                        // DWG 2000+
954
                        val = DwgUtil.getBitDouble(intData, bitPos);
955
                        bitPos = ((Integer) val.get(0)).intValue();
956
                        dwgFile.setHeader("PSVPSCALE", val.get(1));
957

    
958
                        double[] spaces1 = new double[3];
959

    
960
                        val = DwgUtil.getBitDouble(intData, bitPos);
961
                        bitPos = ((Integer) val.get(0)).intValue();
962
                        spaces1[0] = ((Double) val.get(1)).doubleValue();
963

    
964
                        val = DwgUtil.getBitDouble(intData, bitPos);
965
                        bitPos = ((Integer) val.get(0)).intValue();
966
                        spaces1[1] = ((Double) val.get(1)).doubleValue();
967

    
968
                        val = DwgUtil.getBitDouble(intData, bitPos);
969
                        bitPos = ((Integer) val.get(0)).intValue();
970
                        spaces1[2] = ((Double) val.get(1)).doubleValue();
971

    
972
                        dwgFile.setHeader("PSPACE_INSBASE", spaces1);
973

    
974
                        double[] spaces2 = new double[3];
975

    
976
                        val = DwgUtil.getBitDouble(intData, bitPos);
977
                        bitPos = ((Integer) val.get(0)).intValue();
978
                        spaces2[0] = ((Double) val.get(1)).doubleValue();
979

    
980
                        val = DwgUtil.getBitDouble(intData, bitPos);
981
                        bitPos = ((Integer) val.get(0)).intValue();
982
                        spaces2[1] = ((Double) val.get(1)).doubleValue();
983

    
984
                        val = DwgUtil.getBitDouble(intData, bitPos);
985
                        bitPos = ((Integer) val.get(0)).intValue();
986
                        spaces2[2] = ((Double) val.get(1)).doubleValue();
987

    
988
                        dwgFile.setHeader("PSPACE_EXTMIN", spaces2);
989

    
990
                        double[] spaces3 = new double[3];
991

    
992
                        val = DwgUtil.getBitDouble(intData, bitPos);
993
                        bitPos = ((Integer) val.get(0)).intValue();
994
                        spaces3[0] = ((Double) val.get(1)).doubleValue();
995

    
996
                        val = DwgUtil.getBitDouble(intData, bitPos);
997
                        bitPos = ((Integer) val.get(0)).intValue();
998
                        spaces3[1] = ((Double) val.get(1)).doubleValue();
999

    
1000
                        val = DwgUtil.getBitDouble(intData, bitPos);
1001
                        bitPos = ((Integer) val.get(0)).intValue();
1002
                        spaces3[2] = ((Double) val.get(1)).doubleValue();
1003
                        dwgFile.setHeader("PSPACE_EXTMAX", spaces2);
1004

    
1005
                        double[] spaces4 = new double[2];
1006
                        val = DwgUtil.getRawDouble(intData, bitPos);
1007
                        bitPos = ((Integer) val.get(0)).intValue();
1008
                        spaces4[0] = ((Double) val.get(1)).doubleValue();
1009

    
1010
                        val = DwgUtil.getRawDouble(intData, bitPos);
1011
                        bitPos = ((Integer) val.get(0)).intValue();
1012
                        spaces4[1] = ((Double) val.get(1)).doubleValue();
1013

    
1014
                        dwgFile.setHeader("PSPACE_LIMMIN", spaces4);
1015

    
1016
                        double[] spaces5 = new double[2];
1017
                        val = DwgUtil.getRawDouble(intData, bitPos);
1018
                        bitPos = ((Integer) val.get(0)).intValue();
1019
                        spaces5[0] = ((Double) val.get(1)).doubleValue();
1020

    
1021
                        val = DwgUtil.getRawDouble(intData, bitPos);
1022
                        bitPos = ((Integer) val.get(0)).intValue();
1023
                        spaces5[1] = ((Double) val.get(1)).doubleValue();
1024

    
1025
                        dwgFile.setHeader("PSPACE_LIMMAX", spaces5);
1026

    
1027
                        val = DwgUtil.getBitDouble(intData, bitPos);
1028
                        bitPos = ((Integer) val.get(0)).intValue();
1029
                        dwgFile.setHeader("PSPACE_ELEVATION", val.get(1));
1030

    
1031
                        double[] spaces6 = new double[6];
1032

    
1033
                        val = DwgUtil.getBitDouble(intData, bitPos);
1034
                        bitPos = ((Integer) val.get(0)).intValue();
1035
                        spaces6[0] = ((Double) val.get(1)).doubleValue();
1036

    
1037
                        val = DwgUtil.getBitDouble(intData, bitPos);
1038
                        bitPos = ((Integer) val.get(0)).intValue();
1039
                        spaces6[1] = ((Double) val.get(1)).doubleValue();
1040

    
1041
                        val = DwgUtil.getBitDouble(intData, bitPos);
1042
                        bitPos = ((Integer) val.get(0)).intValue();
1043
                        spaces6[2] = ((Double) val.get(1)).doubleValue();
1044

    
1045
                        dwgFile.setHeader("PSPACE_UCSORG", spaces6);
1046

    
1047
                        double[] spaces7 = new double[6];
1048
                        val = DwgUtil.getBitDouble(intData, bitPos);
1049
                        bitPos = ((Integer) val.get(0)).intValue();
1050
                        spaces7[0] = ((Double) val.get(1)).doubleValue();
1051

    
1052
                        val = DwgUtil.getBitDouble(intData, bitPos);
1053
                        bitPos = ((Integer) val.get(0)).intValue();
1054
                        spaces7[1] = ((Double) val.get(1)).doubleValue();
1055

    
1056
                        val = DwgUtil.getBitDouble(intData, bitPos);
1057
                        bitPos = ((Integer) val.get(0)).intValue();
1058
                        spaces7[2] = ((Double) val.get(1)).doubleValue();
1059

    
1060
                        dwgFile.setHeader("PSPACE_UCSXDIR", spaces7);
1061

    
1062
                        double[] spaces8 = new double[6];
1063
                        val = DwgUtil.getBitDouble(intData, bitPos);
1064
                        bitPos = ((Integer) val.get(0)).intValue();
1065
                        spaces8[0] = ((Double) val.get(1)).doubleValue();
1066

    
1067
                        val = DwgUtil.getBitDouble(intData, bitPos);
1068
                        bitPos = ((Integer) val.get(0)).intValue();
1069
                        spaces8[1] = ((Double) val.get(1)).doubleValue();
1070

    
1071
                        val = DwgUtil.getBitDouble(intData, bitPos);
1072
                        bitPos = ((Integer) val.get(0)).intValue();
1073
                        spaces8[2] = ((Double) val.get(1)).doubleValue();
1074

    
1075
                        dwgFile.setHeader("PSPACE_UCSYDIR", spaces8);
1076

    
1077
                        val = DwgUtil.getHandle(intData, bitPos);
1078
                        bitPos = ((Integer) val.get(0)).intValue();
1079
                        intHandle = DwgUtil.handleToInt(val);
1080
                        dwgFile.setHeader("PSPACE_UCSNAME", new Integer(intHandle));
1081

    
1082
                        // R2000+ Only
1083

    
1084
                        val = DwgUtil.getHandle(intData, bitPos);
1085
                        bitPos = ((Integer) val.get(0)).intValue();
1086
                        intHandle = DwgUtil.handleToInt(val);
1087
                        dwgFile.setHeader("PUCSBASE", new Integer(intHandle));
1088

    
1089
                        val = DwgUtil.getBitShort(intData, bitPos);
1090
                        bitPos = ((Integer) val.get(0)).intValue();
1091
                        dwgFile.setHeader("PUCSORTHOVIEW", val.get(1));
1092

    
1093
                        val = DwgUtil.getHandle(intData, bitPos);
1094
                        bitPos = ((Integer) val.get(0)).intValue();
1095
                        intHandle = DwgUtil.handleToInt(val);
1096
                        dwgFile.setHeader("PUCSORTHOREF", new Integer(intHandle));
1097

    
1098
                        double[] pucsorgtop = new double[3];
1099
                        val = DwgUtil.getBitDouble(intData, bitPos);
1100
                        bitPos = ((Integer) val.get(0)).intValue();
1101
                        pucsorgtop[0] = ((Double) val.get(1)).doubleValue();
1102
                        val = DwgUtil.getBitDouble(intData, bitPos);
1103
                        bitPos = ((Integer) val.get(0)).intValue();
1104
                        pucsorgtop[1] = ((Double) val.get(1)).doubleValue();
1105
                        val = DwgUtil.getBitDouble(intData, bitPos);
1106
                        bitPos = ((Integer) val.get(0)).intValue();
1107
                        pucsorgtop[2] = ((Double) val.get(1)).doubleValue();
1108
                        dwgFile.setHeader("PUCSORGTOP", pucsorgtop);
1109

    
1110
                        double[] pucsorgbottom = new double[3];
1111
                        val = DwgUtil.getBitDouble(intData, bitPos);
1112
                        bitPos = ((Integer) val.get(0)).intValue();
1113
                        pucsorgbottom[0] = ((Double) val.get(1)).doubleValue();
1114
                        val = DwgUtil.getBitDouble(intData, bitPos);
1115
                        bitPos = ((Integer) val.get(0)).intValue();
1116
                        pucsorgbottom[1] = ((Double) val.get(1)).doubleValue();
1117
                        val = DwgUtil.getBitDouble(intData, bitPos);
1118
                        bitPos = ((Integer) val.get(0)).intValue();
1119
                        pucsorgbottom[2] = ((Double) val.get(1)).doubleValue();
1120
                        dwgFile.setHeader("PUCSORGBOTTOM", pucsorgbottom);
1121

    
1122
                        double[] pucsorgleft = new double[3];
1123
                        val = DwgUtil.getBitDouble(intData, bitPos);
1124
                        bitPos = ((Integer) val.get(0)).intValue();
1125
                        pucsorgleft[0] = ((Double) val.get(1)).doubleValue();
1126
                        val = DwgUtil.getBitDouble(intData, bitPos);
1127
                        bitPos = ((Integer) val.get(0)).intValue();
1128
                        pucsorgleft[1] = ((Double) val.get(1)).doubleValue();
1129
                        val = DwgUtil.getBitDouble(intData, bitPos);
1130
                        bitPos = ((Integer) val.get(0)).intValue();
1131
                        pucsorgleft[2] = ((Double) val.get(1)).doubleValue();
1132
                        dwgFile.setHeader("PUCSORGLEFT", pucsorgleft);
1133

    
1134
                        double[] pucsorgright = new double[3];
1135
                        val = DwgUtil.getBitDouble(intData, bitPos);
1136
                        bitPos = ((Integer) val.get(0)).intValue();
1137
                        pucsorgright[0] = ((Double) val.get(1)).doubleValue();
1138
                        val = DwgUtil.getBitDouble(intData, bitPos);
1139
                        bitPos = ((Integer) val.get(0)).intValue();
1140
                        pucsorgright[1] = ((Double) val.get(1)).doubleValue();
1141
                        val = DwgUtil.getBitDouble(intData, bitPos);
1142
                        bitPos = ((Integer) val.get(0)).intValue();
1143
                        pucsorgright[2] = ((Double) val.get(1)).doubleValue();
1144
                        dwgFile.setHeader("PUCSORGRIGHT", pucsorgright);
1145

    
1146
                        double[] pucsorgfront = new double[3];
1147
                        val = DwgUtil.getBitDouble(intData, bitPos);
1148
                        bitPos = ((Integer) val.get(0)).intValue();
1149
                        pucsorgfront[0] = ((Double) val.get(1)).doubleValue();
1150
                        val = DwgUtil.getBitDouble(intData, bitPos);
1151
                        bitPos = ((Integer) val.get(0)).intValue();
1152
                        pucsorgfront[1] = ((Double) val.get(1)).doubleValue();
1153
                        val = DwgUtil.getBitDouble(intData, bitPos);
1154
                        bitPos = ((Integer) val.get(0)).intValue();
1155
                        pucsorgfront[2] = ((Double) val.get(1)).doubleValue();
1156
                        dwgFile.setHeader("PUCSORGFRONT", pucsorgfront);
1157

    
1158
                        double[] pucsorgback = new double[3];
1159
                        val = DwgUtil.getBitDouble(intData, bitPos);
1160
                        bitPos = ((Integer) val.get(0)).intValue();
1161
                        pucsorgback[0] = ((Double) val.get(1)).doubleValue();
1162
                        val = DwgUtil.getBitDouble(intData, bitPos);
1163
                        bitPos = ((Integer) val.get(0)).intValue();
1164
                        pucsorgback[1] = ((Double) val.get(1)).doubleValue();
1165
                        val = DwgUtil.getBitDouble(intData, bitPos);
1166
                        bitPos = ((Integer) val.get(0)).intValue();
1167
                        pucsorgback[2] = ((Double) val.get(1)).doubleValue();
1168
                        dwgFile.setHeader("PUCSORGBACK", pucsorgback);
1169

    
1170
                        // Common
1171

    
1172
                        double[] spaces9 = new double[6];
1173
                        val = DwgUtil.getBitDouble(intData, bitPos);
1174
                        bitPos = ((Integer) val.get(0)).intValue();
1175
                        spaces9[0] = ((Double) val.get(1)).doubleValue();
1176

    
1177
                        val = DwgUtil.getBitDouble(intData, bitPos);
1178
                        bitPos = ((Integer) val.get(0)).intValue();
1179
                        spaces9[1] = ((Double) val.get(1)).doubleValue();
1180

    
1181
                        val = DwgUtil.getBitDouble(intData, bitPos);
1182
                        bitPos = ((Integer) val.get(0)).intValue();
1183
                        spaces9[2] = ((Double) val.get(1)).doubleValue();
1184

    
1185
                        dwgFile.setHeader("MSPACE_INSBASE", spaces9);
1186

    
1187
                        double[] spaces10 = new double[6];
1188
                        val = DwgUtil.getBitDouble(intData, bitPos);
1189
                        bitPos = ((Integer) val.get(0)).intValue();
1190
                        spaces10[0] = ((Double) val.get(1)).doubleValue();
1191

    
1192
                        val = DwgUtil.getBitDouble(intData, bitPos);
1193
                        bitPos = ((Integer) val.get(0)).intValue();
1194
                        spaces10[1] = ((Double) val.get(1)).doubleValue();
1195

    
1196
                        val = DwgUtil.getBitDouble(intData, bitPos);
1197
                        bitPos = ((Integer) val.get(0)).intValue();
1198
                        spaces10[2] = ((Double) val.get(1)).doubleValue();
1199

    
1200
                        dwgFile.setHeader("MSPACE_EXTMIN", spaces10);
1201

    
1202
                        double[] spaces11 = new double[3];
1203
                        val = DwgUtil.getBitDouble(intData, bitPos);
1204
                        bitPos = ((Integer) val.get(0)).intValue();
1205
                        spaces11[0] = ((Double) val.get(1)).doubleValue();
1206

    
1207
                        val = DwgUtil.getBitDouble(intData, bitPos);
1208
                        bitPos = ((Integer) val.get(0)).intValue();
1209
                        spaces11[1] = ((Double) val.get(1)).doubleValue();
1210

    
1211
                        val = DwgUtil.getBitDouble(intData, bitPos);
1212
                        bitPos = ((Integer) val.get(0)).intValue();
1213
                        spaces11[2] = ((Double) val.get(1)).doubleValue();
1214

    
1215
                        dwgFile.setHeader("MSPACE_EXTMAX", spaces11);
1216

    
1217
                        double[] spaces12 = new double[2];
1218
                        val = DwgUtil.getRawDouble(intData, bitPos);
1219
                        bitPos = ((Integer) val.get(0)).intValue();
1220
                        spaces12[0] = ((Double) val.get(1)).doubleValue();
1221

    
1222
                        val = DwgUtil.getRawDouble(intData, bitPos);
1223
                        bitPos = ((Integer) val.get(0)).intValue();
1224
                        spaces12[1] = ((Double) val.get(1)).doubleValue();
1225

    
1226
                        dwgFile.setHeader("MSPACE_LIMMIN", spaces12);
1227

    
1228
                        double[] spaces13 = new double[2];
1229
                        val = DwgUtil.getRawDouble(intData, bitPos);
1230
                        bitPos = ((Integer) val.get(0)).intValue();
1231
                        spaces13[0] = ((Double) val.get(1)).doubleValue();
1232

    
1233
                        val = DwgUtil.getRawDouble(intData, bitPos);
1234
                        bitPos = ((Integer) val.get(0)).intValue();
1235
                        spaces13[1] = ((Double) val.get(1)).doubleValue();
1236

    
1237
                        dwgFile.setHeader("MSPACE_LIMMAX", spaces13);
1238

    
1239
                        val = DwgUtil.getBitDouble(intData, bitPos);
1240
                        bitPos = ((Integer) val.get(0)).intValue();
1241
                        dwgFile.setHeader("MSPACE_ELEVATION", (Double) val.get(1));
1242

    
1243
                        double[] spaces14 = new double[3];
1244
                        val = DwgUtil.getBitDouble(intData, bitPos);
1245
                        bitPos = ((Integer) val.get(0)).intValue();
1246
                        spaces14[0] = ((Double) val.get(1)).doubleValue();
1247

    
1248
                        val = DwgUtil.getBitDouble(intData, bitPos);
1249
                        bitPos = ((Integer) val.get(0)).intValue();
1250
                        spaces14[1] = ((Double) val.get(1)).doubleValue();
1251

    
1252
                        val = DwgUtil.getBitDouble(intData, bitPos);
1253
                        bitPos = ((Integer) val.get(0)).intValue();
1254
                        spaces14[2] = ((Double) val.get(1)).doubleValue();
1255

    
1256
                        dwgFile.setHeader("MSPACE_UCSORG", spaces14);
1257

    
1258
                        double[] spaces15 = new double[3];
1259
                        val = DwgUtil.getBitDouble(intData, bitPos);
1260
                        bitPos = ((Integer) val.get(0)).intValue();
1261
                        spaces15[0] = ((Double) val.get(1)).doubleValue();
1262

    
1263
                        val = DwgUtil.getBitDouble(intData, bitPos);
1264
                        bitPos = ((Integer) val.get(0)).intValue();
1265
                        spaces15[1] = ((Double) val.get(1)).doubleValue();
1266

    
1267
                        val = DwgUtil.getBitDouble(intData, bitPos);
1268
                        bitPos = ((Integer) val.get(0)).intValue();
1269
                        spaces15[2] = ((Double) val.get(1)).doubleValue();
1270

    
1271
                        dwgFile.setHeader("MSPACE_UCSXDIR", spaces15);
1272

    
1273
                        double[] spaces16 = new double[3];
1274
                        val = DwgUtil.getBitDouble(intData, bitPos);
1275
                        bitPos = ((Integer) val.get(0)).intValue();
1276
                        spaces16[0] = ((Double) val.get(1)).doubleValue();
1277

    
1278
                        val = DwgUtil.getBitDouble(intData, bitPos);
1279
                        bitPos = ((Integer) val.get(0)).intValue();
1280
                        spaces16[1] = ((Double) val.get(1)).doubleValue();
1281

    
1282
                        val = DwgUtil.getBitDouble(intData, bitPos);
1283
                        bitPos = ((Integer) val.get(0)).intValue();
1284
                        spaces16[2] = ((Double) val.get(1)).doubleValue();
1285

    
1286
                        dwgFile.setHeader("MSPACE_UCSYDIR", spaces16);
1287

    
1288
                        val = DwgUtil.getHandle(intData, bitPos);
1289
                        bitPos = ((Integer) val.get(0)).intValue();
1290
                        intHandle = DwgUtil.handleToInt(val);
1291
                        dwgFile.setHeader("MSPACE_UCSNAME", new Integer(intHandle));
1292

    
1293
                        val = DwgUtil.getHandle(intData, bitPos);
1294
                        bitPos = ((Integer) val.get(0)).intValue();
1295
                        intHandle = DwgUtil.handleToInt(val);
1296
                        dwgFile.setHeader("UCSBASE", new Integer(intHandle));
1297

    
1298
                        val = DwgUtil.getBitShort(intData, bitPos);
1299
                        bitPos = ((Integer) val.get(0)).intValue();
1300
                        dwgFile.setHeader("UCSORTHOVIEW", val.get(1));
1301

    
1302
                        val = DwgUtil.getHandle(intData, bitPos);
1303
                        bitPos = ((Integer) val.get(0)).intValue();
1304
                        intHandle = DwgUtil.handleToInt(val);
1305
                        dwgFile.setHeader("UCSORTHOREF", new Integer(intHandle));
1306

    
1307
                        double[] ucsorgtop = new double[3];
1308
                        val = DwgUtil.getBitDouble(intData, bitPos);
1309
                        bitPos = ((Integer) val.get(0)).intValue();
1310
                        ucsorgtop[0] = ((Double) val.get(1)).doubleValue();
1311
                        val = DwgUtil.getBitDouble(intData, bitPos);
1312
                        bitPos = ((Integer) val.get(0)).intValue();
1313
                        ucsorgtop[1] = ((Double) val.get(1)).doubleValue();
1314
                        val = DwgUtil.getBitDouble(intData, bitPos);
1315
                        bitPos = ((Integer) val.get(0)).intValue();
1316
                        ucsorgtop[2] = ((Double) val.get(1)).doubleValue();
1317
                        dwgFile.setHeader("UCSORGTOP", ucsorgtop);
1318

    
1319
                        double[] ucsorgbottom = new double[3];
1320
                        val = DwgUtil.getBitDouble(intData, bitPos);
1321
                        bitPos = ((Integer) val.get(0)).intValue();
1322
                        ucsorgbottom[0] = ((Double) val.get(1)).doubleValue();
1323
                        val = DwgUtil.getBitDouble(intData, bitPos);
1324
                        bitPos = ((Integer) val.get(0)).intValue();
1325
                        ucsorgbottom[1] = ((Double) val.get(1)).doubleValue();
1326
                        val = DwgUtil.getBitDouble(intData, bitPos);
1327
                        bitPos = ((Integer) val.get(0)).intValue();
1328
                        ucsorgbottom[2] = ((Double) val.get(1)).doubleValue();
1329
                        dwgFile.setHeader("UCSORGBOTTOM", ucsorgbottom);
1330

    
1331
                        double[] ucsorgleft = new double[3];
1332
                        val = DwgUtil.getBitDouble(intData, bitPos);
1333
                        bitPos = ((Integer) val.get(0)).intValue();
1334
                        ucsorgleft[0] = ((Double) val.get(1)).doubleValue();
1335
                        val = DwgUtil.getBitDouble(intData, bitPos);
1336
                        bitPos = ((Integer) val.get(0)).intValue();
1337
                        ucsorgleft[1] = ((Double) val.get(1)).doubleValue();
1338
                        val = DwgUtil.getBitDouble(intData, bitPos);
1339
                        bitPos = ((Integer) val.get(0)).intValue();
1340
                        ucsorgleft[2] = ((Double) val.get(1)).doubleValue();
1341
                        dwgFile.setHeader("UCSORGLEFT", ucsorgleft);
1342

    
1343
                        double[] ucsorgright = new double[3];
1344
                        val = DwgUtil.getBitDouble(intData, bitPos);
1345
                        bitPos = ((Integer) val.get(0)).intValue();
1346
                        ucsorgright[0] = ((Double) val.get(1)).doubleValue();
1347
                        val = DwgUtil.getBitDouble(intData, bitPos);
1348
                        bitPos = ((Integer) val.get(0)).intValue();
1349
                        ucsorgright[1] = ((Double) val.get(1)).doubleValue();
1350
                        val = DwgUtil.getBitDouble(intData, bitPos);
1351
                        bitPos = ((Integer) val.get(0)).intValue();
1352
                        ucsorgright[2] = ((Double) val.get(1)).doubleValue();
1353
                        dwgFile.setHeader("UCSORGRIGHT", ucsorgright);
1354

    
1355
                        double[] ucsorgfront = new double[3];
1356
                        val = DwgUtil.getBitDouble(intData, bitPos);
1357
                        bitPos = ((Integer) val.get(0)).intValue();
1358
                        ucsorgfront[0] = ((Double) val.get(1)).doubleValue();
1359
                        val = DwgUtil.getBitDouble(intData, bitPos);
1360
                        bitPos = ((Integer) val.get(0)).intValue();
1361
                        ucsorgfront[1] = ((Double) val.get(1)).doubleValue();
1362
                        val = DwgUtil.getBitDouble(intData, bitPos);
1363
                        bitPos = ((Integer) val.get(0)).intValue();
1364
                        ucsorgfront[2] = ((Double) val.get(1)).doubleValue();
1365
                        dwgFile.setHeader("UCSORGFRONT", ucsorgfront);
1366

    
1367
                        double[] ucsorgback = new double[3];
1368
                        val = DwgUtil.getBitDouble(intData, bitPos);
1369
                        bitPos = ((Integer) val.get(0)).intValue();
1370
                        ucsorgback[0] = ((Double) val.get(1)).doubleValue();
1371
                        val = DwgUtil.getBitDouble(intData, bitPos);
1372
                        bitPos = ((Integer) val.get(0)).intValue();
1373
                        ucsorgback[1] = ((Double) val.get(1)).doubleValue();
1374
                        val = DwgUtil.getBitDouble(intData, bitPos);
1375
                        bitPos = ((Integer) val.get(0)).intValue();
1376
                        ucsorgback[2] = ((Double) val.get(1)).doubleValue();
1377
                        dwgFile.setHeader("UCSORGBACK", ucsorgback);
1378

    
1379
                        val = DwgUtil.getTextString(intData, bitPos);
1380
                        bitPos = ((Integer) val.get(0)).intValue();
1381
                        dwgFile.setHeader("DIMPOST", val.get(1));
1382

    
1383
                        val = DwgUtil.getTextString(intData, bitPos);
1384
                        bitPos = ((Integer) val.get(0)).intValue();
1385
                        dwgFile.setHeader("DIMAPOST", val.get(1));
1386

    
1387
                        // Common
1388

    
1389
                        val = DwgUtil.getBitDouble(intData, bitPos);
1390
                        bitPos = ((Integer) val.get(0)).intValue();
1391
                        dwgFile.setHeader("DIMSCALE", val.get(1));
1392

    
1393
                        val = DwgUtil.getBitDouble(intData, bitPos);
1394
                        bitPos = ((Integer) val.get(0)).intValue();
1395
                        dwgFile.setHeader("DIMASZ", val.get(1));
1396

    
1397
                        val = DwgUtil.getBitDouble(intData, bitPos);
1398
                        bitPos = ((Integer) val.get(0)).intValue();
1399
                        dwgFile.setHeader("DIMEXO", val.get(1));
1400

    
1401
                        val = DwgUtil.getBitDouble(intData, bitPos);
1402
                        bitPos = ((Integer) val.get(0)).intValue();
1403
                        dwgFile.setHeader("DIMDLI", val.get(1));
1404

    
1405
                        val = DwgUtil.getBitDouble(intData, bitPos);
1406
                        bitPos = ((Integer) val.get(0)).intValue();
1407
                        dwgFile.setHeader("DIMEXE", val.get(1));
1408

    
1409
                        val = DwgUtil.getBitDouble(intData, bitPos);
1410
                        bitPos = ((Integer) val.get(0)).intValue();
1411
                        dwgFile.setHeader("DIMAND", val.get(1)); //FIXME: ?o es DIMRND?
1412

    
1413
                        val = DwgUtil.getBitDouble(intData, bitPos);
1414
                        bitPos = ((Integer) val.get(0)).intValue();
1415
                        dwgFile.setHeader("DIMDLE", val.get(1));
1416

    
1417
                        val = DwgUtil.getBitDouble(intData, bitPos);
1418
                        bitPos = ((Integer) val.get(0)).intValue();
1419
                        dwgFile.setHeader("DIMTP", val.get(1));
1420

    
1421
                        val = DwgUtil.getBitDouble(intData, bitPos);
1422
                        bitPos = ((Integer) val.get(0)).intValue();
1423
                        dwgFile.setHeader("DIMTM", val.get(1));
1424

    
1425
                        // DWG 2000 +
1426
                        val = DwgUtil.testBit(intData, bitPos);
1427
                        bitPos = ((Integer) val.get(0)).intValue();
1428
                        dwgFile.setHeader("DIMTOL", val.get(1));
1429

    
1430
                        val = DwgUtil.testBit(intData, bitPos);
1431
                        bitPos = ((Integer) val.get(0)).intValue();
1432
                        dwgFile.setHeader("DIMLIM", val.get(1));
1433

    
1434
                        val = DwgUtil.testBit(intData, bitPos);
1435
                        bitPos = ((Integer) val.get(0)).intValue();
1436
                        dwgFile.setHeader("DIMTIH", val.get(1));
1437

    
1438
                        val = DwgUtil.testBit(intData, bitPos);
1439
                        bitPos = ((Integer) val.get(0)).intValue();
1440
                        dwgFile.setHeader("DIMTOH", val.get(1));
1441

    
1442
                        val = DwgUtil.testBit(intData, bitPos);
1443
                        bitPos = ((Integer) val.get(0)).intValue();
1444
                        dwgFile.setHeader("DIMSE1", val.get(1));
1445

    
1446
                        val = DwgUtil.testBit(intData, bitPos);
1447
                        bitPos = ((Integer) val.get(0)).intValue();
1448
                        dwgFile.setHeader("DIMSE2", val.get(1));
1449

    
1450
                        val = DwgUtil.getBitShort(intData, bitPos);
1451
                        bitPos = ((Integer) val.get(0)).intValue();
1452
                        dwgFile.setHeader("DIMTAD", val.get(1));
1453

    
1454
                        val = DwgUtil.getBitShort(intData, bitPos);
1455
                        bitPos = ((Integer) val.get(0)).intValue();
1456
                        dwgFile.setHeader("DIMZIN", val.get(1));
1457

    
1458
                        val = DwgUtil.getBitShort(intData, bitPos);
1459
                        bitPos = ((Integer) val.get(0)).intValue();
1460
                        dwgFile.setHeader("DIMAZIN", val.get(1));
1461

    
1462
                        val = DwgUtil.getBitDouble(intData, bitPos);
1463
                        bitPos = ((Integer) val.get(0)).intValue();
1464
                        dwgFile.setHeader("DIMTXT", val.get(1));
1465

    
1466
                        val = DwgUtil.getBitDouble(intData, bitPos);
1467
                        bitPos = ((Integer) val.get(0)).intValue();
1468
                        dwgFile.setHeader("DIMCEN", val.get(1));
1469

    
1470
                        val = DwgUtil.getBitDouble(intData, bitPos);
1471
                        bitPos = ((Integer) val.get(0)).intValue();
1472
                        dwgFile.setHeader("DIMSZ", val.get(1));
1473

    
1474
                        val = DwgUtil.getBitDouble(intData, bitPos);
1475
                        bitPos = ((Integer) val.get(0)).intValue();
1476
                        dwgFile.setHeader("DIMALTF", val.get(1));
1477

    
1478
                        val = DwgUtil.getBitDouble(intData, bitPos);
1479
                        bitPos = ((Integer) val.get(0)).intValue();
1480
                        dwgFile.setHeader("DIMLFAC", val.get(1));
1481

    
1482
                        val = DwgUtil.getBitDouble(intData, bitPos);
1483
                        bitPos = ((Integer) val.get(0)).intValue();
1484
                        dwgFile.setHeader("DIMTVP", val.get(1));
1485

    
1486
                        val = DwgUtil.getBitDouble(intData, bitPos);
1487
                        bitPos = ((Integer) val.get(0)).intValue();
1488
                        dwgFile.setHeader("DIMTFAC", val.get(1));
1489

    
1490
                        val = DwgUtil.getBitDouble(intData, bitPos);
1491
                        bitPos = ((Integer) val.get(0)).intValue();
1492
                        dwgFile.setHeader("DIMGAP", val.get(1));
1493

    
1494
                        // DWG 2000+
1495

    
1496
                        val = DwgUtil.getBitDouble(intData, bitPos);
1497
                        bitPos = ((Integer) val.get(0)).intValue();
1498
                        dwgFile.setHeader("DIMALTRND", val.get(1));
1499

    
1500
                        val = DwgUtil.testBit(intData, bitPos);
1501
                        bitPos = ((Integer) val.get(0)).intValue();
1502
                        dwgFile.setHeader("DIMALT", val.get(1));
1503

    
1504
                        val = DwgUtil.getBitShort(intData, bitPos);
1505
                        bitPos = ((Integer) val.get(0)).intValue();
1506
                        dwgFile.setHeader("DIMALTD", val.get(1));
1507

    
1508
                        val = DwgUtil.testBit(intData, bitPos);
1509
                        bitPos = ((Integer) val.get(0)).intValue();
1510
                        dwgFile.setHeader("DIMTOFL", val.get(1));
1511

    
1512
                        val = DwgUtil.testBit(intData, bitPos);
1513
                        bitPos = ((Integer) val.get(0)).intValue();
1514
                        dwgFile.setHeader("DIMSAH", val.get(1));
1515

    
1516
                        val = DwgUtil.testBit(intData, bitPos);
1517
                        bitPos = ((Integer) val.get(0)).intValue();
1518
                        dwgFile.setHeader("DIMTIX", val.get(1));
1519

    
1520
                        val = DwgUtil.testBit(intData, bitPos);
1521
                        bitPos = ((Integer) val.get(0)).intValue();
1522
                        dwgFile.setHeader("DIMSOXD", val.get(1));
1523

    
1524
                        // common
1525

    
1526
                        //FIXME: En versiones anteriores solo hab?a una variable
1527
                        // "DIMCLRD" de tipo entero, habr?a que comprobar donde se
1528
                        // utiliza para, si es necesario, utilizar apropiadamente
1529
                        // las nuevas. Lo mismo con "DIMCLRE" y "DIMCLRT".
1530

    
1531
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
1532
                        bitPos = ((Integer) val.get(0)).intValue();
1533
                        dwgFile.setHeader("DIMCLRD", val.get(1));
1534
                        dwgFile.setHeader("DIMCLRD_RGBVALUE", val.get(2));
1535
                        Object dimclrdColorByte = val.get(3);
1536
                        dwgFile.setHeader("DIMCLRD_COLORBYTE", dimclrdColorByte);
1537
                        dwgFile.setHeader("DIMCLRD_NAME", val.get(4));
1538

    
1539
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
1540
                        bitPos = ((Integer) val.get(0)).intValue();
1541
                        dwgFile.setHeader("DIMCLRE", val.get(1));
1542
                        dwgFile.setHeader("DIMCLRE_RGBVALUE", val.get(2));
1543
                        Object dimclreColorByte = val.get(3);
1544
                        dwgFile.setHeader("DIMCLRE_COLORBYTE", dimclreColorByte);
1545
                        dwgFile.setHeader("DIMCLRE_NAME", val.get(4));
1546

    
1547
                        val = DwgUtil.getCmColor(intData, bitPos, dwgFile.getDwgVersion());
1548
                        bitPos = ((Integer) val.get(0)).intValue();
1549
                        dwgFile.setHeader("DIMCLRT", val.get(1));
1550
                        dwgFile.setHeader("DIMCLRT_RGBVALUE", val.get(2));
1551
                        Object dimclrtColorByte = val.get(3);
1552
                        dwgFile.setHeader("DIMCLRT_COLORBYTE", dimclrtColorByte);
1553

    
1554
                        dwgFile.setHeader("DIMCLRT_NAME", val.get(4));
1555

    
1556
                        // dwg2000 +
1557

    
1558
                        val = DwgUtil.getBitShort(intData, bitPos);
1559
                        bitPos = ((Integer) val.get(0)).intValue();
1560
                        dwgFile.setHeader("DIMADEC", val.get(1));
1561

    
1562
                        val = DwgUtil.getBitShort(intData, bitPos);
1563
                        bitPos = ((Integer) val.get(0)).intValue();
1564
                        dwgFile.setHeader("DIMDEC", val.get(1));
1565

    
1566
                        val = DwgUtil.getBitShort(intData, bitPos);
1567
                        bitPos = ((Integer) val.get(0)).intValue();
1568
                        dwgFile.setHeader("DIMTDEC", val.get(1));
1569

    
1570
                        val = DwgUtil.getBitShort(intData, bitPos);
1571
                        bitPos = ((Integer) val.get(0)).intValue();
1572
                        dwgFile.setHeader("DIMALTU", val.get(1));
1573

    
1574
                        val = DwgUtil.getBitShort(intData, bitPos);
1575
                        bitPos = ((Integer) val.get(0)).intValue();
1576
                        dwgFile.setHeader("DIMALTTD", val.get(1));
1577

    
1578
                        val = DwgUtil.getBitShort(intData, bitPos);
1579
                        bitPos = ((Integer) val.get(0)).intValue();
1580
                        dwgFile.setHeader("DIMAUNIT", val.get(1));
1581

    
1582
                        val = DwgUtil.getBitShort(intData, bitPos);
1583
                        bitPos = ((Integer) val.get(0)).intValue();
1584
                        dwgFile.setHeader("DIMFRAC", val.get(1));
1585

    
1586
                        val = DwgUtil.getBitShort(intData, bitPos);
1587
                        bitPos = ((Integer) val.get(0)).intValue();
1588
                        dwgFile.setHeader("DIMLUNIT", val.get(1));
1589

    
1590
                        val = DwgUtil.getBitShort(intData, bitPos);
1591
                        bitPos = ((Integer) val.get(0)).intValue();
1592
                        dwgFile.setHeader("DIMDSEP", val.get(1));
1593

    
1594
                        val = DwgUtil.getBitShort(intData, bitPos);
1595
                        bitPos = ((Integer) val.get(0)).intValue();
1596
                        dwgFile.setHeader("DIMTMOVE", val.get(1));
1597

    
1598
                        val = DwgUtil.getBitShort(intData, bitPos);
1599
                        bitPos = ((Integer) val.get(0)).intValue();
1600
                        dwgFile.setHeader("DIMJUST", val.get(1));
1601

    
1602
                        val = DwgUtil.testBit(intData, bitPos);
1603
                        bitPos = ((Integer) val.get(0)).intValue();
1604
                        dwgFile.setHeader("DIMSD1", val.get(1));
1605

    
1606
                        val = DwgUtil.testBit(intData, bitPos);
1607
                        bitPos = ((Integer) val.get(0)).intValue();
1608
                        dwgFile.setHeader("DIMSD2", val.get(1));
1609

    
1610
                        val = DwgUtil.getBitShort(intData, bitPos);
1611
                        bitPos = ((Integer) val.get(0)).intValue();
1612
                        dwgFile.setHeader("DIMTOLJ", val.get(1));
1613

    
1614
                        val = DwgUtil.getBitShort(intData, bitPos);
1615
                        bitPos = ((Integer) val.get(0)).intValue();
1616
                        dwgFile.setHeader("DIMTZIN", val.get(1));
1617

    
1618
                        val = DwgUtil.getBitShort(intData, bitPos);
1619
                        bitPos = ((Integer) val.get(0)).intValue();
1620
                        dwgFile.setHeader("DIMALTZ", val.get(1));
1621

    
1622
                        val = DwgUtil.getBitShort(intData, bitPos);
1623
                        bitPos = ((Integer) val.get(0)).intValue();
1624
                        dwgFile.setHeader("DIMALTTZ", val.get(1));
1625

    
1626
                        val = DwgUtil.testBit(intData, bitPos);
1627
                        bitPos = ((Integer) val.get(0)).intValue();
1628
                        dwgFile.setHeader("DIMUPT", val.get(1));
1629

    
1630
                        val = DwgUtil.getBitShort(intData, bitPos);
1631
                        bitPos = ((Integer) val.get(0)).intValue();
1632
                        dwgFile.setHeader("DIMFIT", val.get(1));
1633

    
1634
                        val = DwgUtil.getHandle(intData, bitPos);
1635
                        bitPos = ((Integer) val.get(0)).intValue();
1636
                        intHandle = DwgUtil.handleToInt(val);
1637
                        dwgFile.setHeader("DIMTXTSTY", new Integer(intHandle));
1638

    
1639
                        val = DwgUtil.getHandle(intData, bitPos);
1640
                        bitPos = ((Integer) val.get(0)).intValue();
1641
                        intHandle = DwgUtil.handleToInt(val);
1642
                        dwgFile.setHeader("DIMLDRBLK", new Integer(intHandle));
1643

    
1644
                        val = DwgUtil.getHandle(intData, bitPos);
1645
                        bitPos = ((Integer) val.get(0)).intValue();
1646
                        intHandle = DwgUtil.handleToInt(val);
1647
                        dwgFile.setHeader("DIMBLK", new Integer(intHandle));
1648

    
1649
                        val = DwgUtil.getHandle(intData, bitPos);
1650
                        bitPos = ((Integer) val.get(0)).intValue();
1651
                        intHandle = DwgUtil.handleToInt(val);
1652
                        dwgFile.setHeader("DIMBLK1", new Integer(intHandle));
1653

    
1654
                        val = DwgUtil.getHandle(intData, bitPos);
1655
                        bitPos = ((Integer) val.get(0)).intValue();
1656
                        intHandle = DwgUtil.handleToInt(val);
1657
                        dwgFile.setHeader("DIMBLK2", new Integer(intHandle));
1658

    
1659
                        val = DwgUtil.getBitShort(intData, bitPos);
1660
                        bitPos = ((Integer) val.get(0)).intValue();
1661
                        dwgFile.setHeader("DIMLWD", val.get(1));
1662

    
1663
                        val = DwgUtil.getBitShort(intData, bitPos);
1664
                        bitPos = ((Integer) val.get(0)).intValue();
1665
                        dwgFile.setHeader("DIMLWE", val.get(1));
1666

    
1667
                        // Common
1668

    
1669
                        val = DwgUtil.getHandle(intData, bitPos);
1670
                        bitPos = ((Integer) val.get(0)).intValue();
1671
                        intHandle = DwgUtil.handleToInt(val);
1672
                        dwgFile.setHeader("BLOCK_CONTROL_OBJECT", new Integer(intHandle));
1673

    
1674
                        val = DwgUtil.getHandle(intData, bitPos);
1675
                        bitPos = ((Integer) val.get(0)).intValue();
1676
                        intHandle = DwgUtil.handleToInt(val);
1677
                        dwgFile.setHeader("LAYER_CONTROL_OBJECT", new Integer(intHandle));
1678

    
1679
                        val = DwgUtil.getHandle(intData, bitPos);
1680
                        bitPos = ((Integer) val.get(0)).intValue();
1681
                        intHandle = DwgUtil.handleToInt(val);
1682
                        dwgFile.setHeader("STYLE_CONTROL_OBJECT", new Integer(intHandle));
1683

    
1684
                        val = DwgUtil.getHandle(intData, bitPos);
1685
                        bitPos = ((Integer) val.get(0)).intValue();
1686
                        intHandle = DwgUtil.handleToInt(val);
1687
                        dwgFile.setHeader("LINETYPE_CONTROL_OBJECT", new Integer(intHandle));
1688

    
1689
                        val = DwgUtil.getHandle(intData, bitPos);
1690
                        bitPos = ((Integer) val.get(0)).intValue();
1691
                        intHandle = DwgUtil.handleToInt(val);
1692
                        dwgFile.setHeader("VIEW_CONTROL_OBJECT", new Integer(intHandle));
1693

    
1694
                        val = DwgUtil.getHandle(intData, bitPos);
1695
                        bitPos = ((Integer) val.get(0)).intValue();
1696
                        intHandle = DwgUtil.handleToInt(val);
1697
                        dwgFile.setHeader("UCS_CONTROL_OBJECT", new Integer(intHandle));
1698

    
1699
                        val = DwgUtil.getHandle(intData, bitPos);
1700
                        bitPos = ((Integer) val.get(0)).intValue();
1701
                        intHandle = DwgUtil.handleToInt(val);
1702
                        dwgFile.setHeader("VPORT_CONTROL_OBJECT", new Integer(intHandle));
1703

    
1704
                        val = DwgUtil.getHandle(intData, bitPos);
1705
                        bitPos = ((Integer) val.get(0)).intValue();
1706
                        intHandle = DwgUtil.handleToInt(val);
1707
                        dwgFile.setHeader("APPID_CONTROL_OBJECT", new Integer(intHandle));
1708

    
1709
                        val = DwgUtil.getHandle(intData, bitPos);
1710
                        bitPos = ((Integer) val.get(0)).intValue();
1711
                        intHandle = DwgUtil.handleToInt(val);
1712
                        dwgFile.setHeader("DIMSTYLE_CONTROL_OBJECT", new Integer(intHandle));
1713

    
1714
                        val = DwgUtil.getHandle(intData, bitPos);
1715
                        bitPos = ((Integer) val.get(0)).intValue();
1716
                        intHandle = DwgUtil.handleToInt(val);
1717
                        dwgFile.setHeader("ACAD_GROUP_DICTIONARY", new Integer(intHandle));
1718

    
1719
                        val = DwgUtil.getHandle(intData, bitPos);
1720
                        bitPos = ((Integer) val.get(0)).intValue();
1721
                        intHandle = DwgUtil.handleToInt(val);
1722
                        dwgFile.setHeader("ACAD_MLINE_DICTIONARY", new Integer(intHandle));
1723

    
1724
                        val = DwgUtil.getHandle(intData, bitPos);
1725
                        bitPos = ((Integer) val.get(0)).intValue();
1726
                        intHandle = DwgUtil.handleToInt(val);
1727
                        dwgFile.setHeader("NAMED_OBJECT_DICTIONARY", new Integer(intHandle));
1728
                        // DWG 2000+
1729

    
1730
                        // unknown bitshort
1731
                        val = DwgUtil.getBitShort(intData, bitPos);
1732
                        bitPos = ((Integer) val.get(0)).intValue();
1733

    
1734
                        // unknown bitshort
1735
                        val = DwgUtil.getBitShort(intData, bitPos);
1736
                        bitPos = ((Integer) val.get(0)).intValue();
1737

    
1738
                        val = DwgUtil.getTextString(intData, bitPos);
1739
                        bitPos = ((Integer) val.get(0)).intValue();
1740
                        dwgFile.setHeader("HYPERLINKBASE", val.get(1));
1741

    
1742
                        val = DwgUtil.getTextString(intData, bitPos);
1743
                        bitPos = ((Integer) val.get(0)).intValue();
1744
                        dwgFile.setHeader("STYLESHEET", val.get(1));
1745

    
1746
                        val = DwgUtil.getHandle(intData, bitPos);
1747
                        bitPos = ((Integer) val.get(0)).intValue();
1748
                        intHandle = DwgUtil.handleToInt(val);
1749
                        dwgFile.setHeader("LAYOUT_DICTIONARY", new Integer(intHandle));
1750

    
1751
                        val = DwgUtil.getHandle(intData, bitPos);
1752
                        bitPos = ((Integer) val.get(0)).intValue();
1753
                        intHandle = DwgUtil.handleToInt(val);
1754
                        dwgFile.setHeader("PLOT_SETTINGS_DICTIONARY",
1755
                                        new Integer(intHandle));
1756

    
1757
                        val = DwgUtil.getHandle(intData, bitPos);
1758
                        bitPos = ((Integer) val.get(0)).intValue();
1759
                        intHandle = DwgUtil.handleToInt(val);
1760
                        dwgFile.setHeader("PLOT_STYLES_DICTIONARY", new Integer(intHandle));
1761

    
1762
                        // DWG 2004+
1763
                        val = DwgUtil.getHandle(intData, bitPos);
1764
                        bitPos = ((Integer) val.get(0)).intValue();
1765
                        intHandle = DwgUtil.handleToInt(val);
1766
                        dwgFile.setHeader("MATERIALS_DICTIONARY", new Integer(intHandle));
1767

    
1768
                        val = DwgUtil.getHandle(intData, bitPos);
1769
                        bitPos = ((Integer) val.get(0)).intValue();
1770
                        intHandle = DwgUtil.handleToInt(val);
1771
                        dwgFile.setHeader("COLORS_DICTIONARY", new Integer(intHandle));
1772

    
1773
                        // DWG 2000 +
1774

    
1775
                        /*
1776
                         * Flags:
1777
                         * CELWEIGHT        Flags & 0x001F
1778
                         * ENDCAPS                Flags & 0x0060
1779
                         * JOINSTYLE        Flags & 0x0180
1780
                         * LWDISPLAY        !(Flags & 0x0200)
1781
                         * XEDIT                !(Flags & 0x0400)
1782
                         * EXTNAMES                Flags & 0x0800
1783
                         * PSTYLEMODE        Flags & 0x2000
1784
                         * OLESTARTUP        Flags & 0x4000
1785
                         */
1786
                        val = DwgUtil.getBitLong(intData, bitPos);
1787
                        bitPos = ((Integer) val.get(0)).intValue();
1788
                        dwgFile.setHeader("FLAGS", val.get(1));
1789

    
1790
                        val = DwgUtil.getBitShort(intData, bitPos);
1791
                        bitPos = ((Integer) val.get(0)).intValue();
1792
                        dwgFile.setHeader("INSUNITS", val.get(1));
1793

    
1794
                        val = DwgUtil.getBitShort(intData, bitPos);
1795
                        bitPos = ((Integer) val.get(0)).intValue();
1796
                        dwgFile.setHeader("CEPSNTYPE", val.get(1));
1797

    
1798
                        if (((Integer) val.get(1)).intValue() == 3) {
1799
                                val = DwgUtil.getHandle(intData, bitPos);
1800
                                bitPos = ((Integer) val.get(0)).intValue();
1801
                                intHandle = DwgUtil.handleToInt(val);
1802
                                dwgFile.setHeader("CPSNID", new Integer(intHandle));
1803
                        }
1804

    
1805
                        val = DwgUtil.getTextString(intData, bitPos);
1806
                        bitPos = ((Integer) val.get(0)).intValue();
1807
                        dwgFile.setHeader("FINGERPRINTGUID", val.get(1));
1808

    
1809
                        val = DwgUtil.getTextString(intData, bitPos);
1810
                        bitPos = ((Integer) val.get(0)).intValue();
1811
                        dwgFile.setHeader("VERSIONGUID", val.get(1));
1812

    
1813
                        // DWG 2004+
1814

    
1815
                        val = DwgUtil.getRawChar(intData, bitPos);
1816
                        bitPos = ((Integer) val.get(0)).intValue();
1817
                        dwgFile.setHeader("SORTENTS", val.get(1));
1818

    
1819
                        val = DwgUtil.getRawChar(intData, bitPos);
1820
                        bitPos = ((Integer) val.get(0)).intValue();
1821
                        dwgFile.setHeader("INDEXCTL", val.get(1));
1822

    
1823
                        val = DwgUtil.getRawChar(intData, bitPos);
1824
                        bitPos = ((Integer) val.get(0)).intValue();
1825
                        dwgFile.setHeader("HIDETEXT", val.get(1));
1826

    
1827
                        val = DwgUtil.getRawChar(intData, bitPos);
1828
                        bitPos = ((Integer) val.get(0)).intValue();
1829
                        dwgFile.setHeader("XCLIPFRAME", val.get(1));
1830

    
1831
                        val = DwgUtil.getRawChar(intData, bitPos);
1832
                        bitPos = ((Integer) val.get(0)).intValue();
1833
                        dwgFile.setHeader("DIMASSOC", val.get(1));
1834

    
1835
                        val = DwgUtil.getRawChar(intData, bitPos);
1836
                        bitPos = ((Integer) val.get(0)).intValue();
1837
                        dwgFile.setHeader("HALOGAP", val.get(1));
1838

    
1839
                        val = DwgUtil.getBitShort(intData, bitPos);
1840
                        bitPos = ((Integer) val.get(0)).intValue();
1841
                        dwgFile.setHeader("OBSCUREDCOLOR", val.get(1));
1842

    
1843
                        val = DwgUtil.getBitShort(intData, bitPos);
1844
                        bitPos = ((Integer) val.get(0)).intValue();
1845
                        dwgFile.setHeader("INTERSECTION_COLOR", val.get(1));
1846

    
1847
                        val = DwgUtil.getRawChar(intData, bitPos);
1848
                        bitPos = ((Integer) val.get(0)).intValue();
1849
                        dwgFile.setHeader("OBSCUREDLTYPE", val.get(1));
1850

    
1851
                        val = DwgUtil.getRawChar(intData, bitPos);
1852
                        bitPos = ((Integer) val.get(0)).intValue();
1853
                        dwgFile.setHeader("INTERSECTION_DISPLAY", val.get(1));
1854

    
1855
                        val = DwgUtil.getTextString(intData, bitPos);
1856
                        bitPos = ((Integer) val.get(0)).intValue();
1857
                        dwgFile.setHeader("PROJECTNAME", val.get(1));
1858

    
1859
                        // Common
1860

    
1861
                        val = DwgUtil.getHandle(intData, bitPos);
1862
                        bitPos = ((Integer) val.get(0)).intValue();
1863
                        intHandle = DwgUtil.handleToInt(val);
1864
                        dwgFile.setHeader("PAPER_BLOCK_RECORD", new Integer(intHandle));
1865

    
1866
                        val = DwgUtil.getHandle(intData, bitPos);
1867
                        bitPos = ((Integer) val.get(0)).intValue();
1868
                        intHandle = DwgUtil.handleToInt(val);
1869
                        dwgFile.setHeader("MODEL_BLOCK_RECORD", new Integer(intHandle));
1870

    
1871
                        val = DwgUtil.getHandle(intData, bitPos);
1872
                        bitPos = ((Integer) val.get(0)).intValue();
1873
                        intHandle = DwgUtil.handleToInt(val);
1874
                        dwgFile.setHeader("LTYPE_BYLAYER", new Integer(intHandle));
1875

    
1876
                        val = DwgUtil.getHandle(intData, bitPos);
1877
                        bitPos = ((Integer) val.get(0)).intValue();
1878
                        intHandle = DwgUtil.handleToInt(val);
1879
                        dwgFile.setHeader("LTYPE_BYBLOCK", new Integer(intHandle));
1880

    
1881
                        val = DwgUtil.getHandle(intData, bitPos);
1882
                        bitPos = ((Integer) val.get(0)).intValue();
1883
                        intHandle = DwgUtil.handleToInt(val);
1884
                        dwgFile.setHeader("LTYPE_CONTINUOUS", new Integer(intHandle));
1885

    
1886
                } catch (Exception e) {
1887
                        logger.trace(e.getMessage());
1888
                }
1889

    
1890
        }
1891

    
1892
        /**
1893
         * decrypts the encrypted data
1894
         *
1895
         * @param encrypted
1896
         *            encrypted data
1897
         * @param offset
1898
         *            current position in file
1899
         * @return vector with the decrypted data
1900
         */
1901
        private int[] decryptSectionHeader(byte[] encrypted, int offset) {
1902
                int secMask = 0x4164536b ^ offset;
1903
                int[] decrypted = new int[8];
1904
                ByteBuffer Hdr = ByteBuffer.allocate(32);
1905
                Hdr.position(0);
1906
                Hdr.put(encrypted);
1907
                Hdr.order(ByteOrder.LITTLE_ENDIAN);
1908
                Hdr.position(0);
1909

    
1910
                for (int i = 0; i < 8; i++) {
1911
                        int aux = Hdr.getInt();
1912
                        aux = aux ^ secMask;
1913
                        decrypted[i] = aux;
1914
                }
1915
                return decrypted;
1916
        }
1917

    
1918
        /**
1919
         * Find all subsections of a section named "name" in the section's array sorted by startOffset
1920
         *
1921
         * @param name
1922
         *            String name of the section to find
1923
         *
1924
         * @return vector with sections named 2name"
1925
         */
1926
        private Section[] findSections(String name) {
1927

    
1928
                Comparator cmp = new Comparator(){
1929

    
1930
                        public int compare(Object arg0, Object arg1) {
1931
                                if (((Section)arg0).getStartOffset() > ((Section)arg1).getStartOffset()) {
1932
                                        return 1;
1933
                }
1934
                                return -1;
1935
                        }
1936

    
1937
                };
1938
                TreeSet foundSections = new TreeSet(cmp);
1939

    
1940
                for (int i = 0; i < sectionAmount; i++) {
1941
                        if (sections[i].getName() != null
1942
                                        && sections[i].getName().contains(name)) {
1943
                                foundSections.add(sections[i]);
1944
                        }
1945
                        if (i == sectionAmount)
1946
                                logger.trace("No se han encontrado secciones llamadas \"" + name + "\"");
1947
                }
1948
                return (Section[]) foundSections.toArray(new Section[0]);
1949
        }
1950

    
1951

    
1952
        /**
1953
         * Contains the defined classes for drawing
1954
         *
1955
         * @param bb
1956
         *            ByteBuffer containing the opened DWG file
1957
         */
1958
        private void readDwgR2004Classes(ByteBuffer bb) {
1959

    
1960
                ByteBuffer decompressedBB = readSection(bb, "AcDb:Classes");
1961

    
1962
                byte[] sentinel = new byte[16];
1963
                decompressedBB.order(ByteOrder.nativeOrder());
1964
                decompressedBB.position(0);
1965
                decompressedBB.get(sentinel); // we get the sentinel that ALWAYS
1966
                // appears before the data
1967

    
1968
                if ((sentinel[0] & 0XFF) != 0x8d)
1969
                        logger.trace(" sentinel[0] != 0x8d");
1970
                if ((sentinel[1] & 0XFF) != 0xa1)
1971
                        logger.trace("sentinel[1] != 0xa1");
1972
                if ((sentinel[2] & 0XFF) != 0xc4)
1973
                        logger.trace("sentinel[2] != 0xc4");
1974
                if ((sentinel[3] & 0XFF) != 0xb8)
1975
                        logger.trace("sentinel[3] != 0xb8");
1976
                if ((sentinel[4] & 0XFF) != 0xc4)
1977
                        logger.trace("sentinel[4] != 0xc4");
1978
                if ((sentinel[5] & 0XFF) != 0xa9)
1979
                        logger.trace("sentinel[5] != 0xa9");
1980
                if ((sentinel[6] & 0XFF) != 0xf8)
1981
                        logger.trace("sentinel[6] != 0xf8");
1982
                if ((sentinel[7] & 0XFF) != 0xc5)
1983
                        logger.trace("sentinel[7] != 0xc5");
1984
                if ((sentinel[8] & 0XFF) != 0xc0)
1985
                        logger.trace("sentinel[8] != 0xc0");
1986
                if ((sentinel[9] & 0XFF) != 0xdc)
1987
                        logger.trace("sentinel[9] != 0xdc");
1988
                if ((sentinel[10] & 0XFF) != 0xf4)
1989
                        logger.trace("sentinel[10] != 0xf4");
1990
                if ((sentinel[11] & 0XFF) != 0x5f)
1991
                        logger.trace("sentinel[11] != 0x5f");
1992
                if ((sentinel[12] & 0XFF) != 0xe7)
1993
                        logger.trace("sentinel[12] != 0xe7");
1994
                if ((sentinel[13] & 0XFF) != 0xcf)
1995
                        logger.trace("sentinel[13] != 0xcf");
1996
                if ((sentinel[14] & 0XFF) != 0xb6)
1997
                        logger.trace("sentinel[14] != 0xb6");
1998
                if ((sentinel[15] & 0XFF) != 0x8a)
1999
                        logger.trace("sentinel[15] != 0x8a");
2000

    
2001
                // we start working with data that comes after the beginning sentinel
2002
                decompressedBB.order(ByteOrder.LITTLE_ENDIAN);
2003
                int size = decompressedBB.getInt();
2004

    
2005
                decompressedBB.order(ByteOrder.nativeOrder());
2006
                byte[] data = new byte[size];
2007
                decompressedBB.get(data);
2008

    
2009
                int[] intData = DwgUtil.toIntArray(data);
2010

    
2011
                bb.order(ByteOrder.LITTLE_ENDIAN);
2012
                short crc = decompressedBB.getShort(); // CRC
2013

    
2014
                List val = null;
2015
                int bitPos = 0;
2016

    
2017
                val = DwgUtil.getBitShort(intData, bitPos);
2018
                bitPos = ((Integer) val.get(0)).intValue();
2019
                int MaxclassNum = ((Integer) val.get(1)).intValue();
2020

    
2021
                val = DwgUtil.getRawChar(intData, bitPos); // 0x00
2022
                if (((Integer) val.get(1)).intValue() != 0x00) {
2023
                        logger.trace("Classes Section RC1 != 0x00");
2024
                }
2025
                bitPos = ((Integer) val.get(0)).intValue();
2026

    
2027
                val = DwgUtil.getRawChar(intData, bitPos);
2028
                bitPos = ((Integer) val.get(0)).intValue(); // 0x00
2029
                if (((Integer) val.get(1)).intValue() != 0x00) {
2030
                        logger.trace("Classes Section RC2 != 0x00");
2031
                }
2032

    
2033
                val = DwgUtil.testBit(intData, bitPos);
2034
                bitPos = ((Integer) val.get(0)).intValue();
2035
                if (((Boolean) val.get(1)).booleanValue() != true) {
2036
                        logger.trace("Classes Section B != true");
2037
                }
2038

    
2039
                int maxBit = size * 8;
2040

    
2041
                while ((bitPos + 8) < maxBit) {
2042
                        val = DwgUtil.getBitShort(intData, bitPos);
2043
                        bitPos = ((Integer) val.get(0)).intValue();
2044
                        int classNum = ((Integer) val.get(1)).intValue();
2045

    
2046
                        val = DwgUtil.getBitShort(intData, bitPos);
2047
                        bitPos = ((Integer) val.get(0)).intValue();
2048
                        int version = ((Integer) val.get(1)).intValue();
2049

    
2050
                        val = DwgUtil.getTextString(intData, bitPos);
2051
                        bitPos = ((Integer) val.get(0)).intValue();
2052
                        String appName = (String) val.get(1);
2053

    
2054
                        val = DwgUtil.getTextString(intData, bitPos);
2055
                        bitPos = ((Integer) val.get(0)).intValue();
2056
                        String cPlusPlusName = (String) val.get(1);
2057

    
2058
                        val = DwgUtil.getTextString(intData, bitPos);
2059
                        bitPos = ((Integer) val.get(0)).intValue();
2060
                        String dxfName = (String) val.get(1);
2061

    
2062
                        val = DwgUtil.testBit(intData, bitPos);
2063
                        bitPos = ((Integer) val.get(0)).intValue();
2064
                        boolean isZombie = ((Boolean) val.get(1)).booleanValue();
2065

    
2066
                        val = DwgUtil.getBitShort(intData, bitPos);
2067
                        bitPos = ((Integer) val.get(0)).intValue();
2068
                        int id = ((Integer) val.get(1)).intValue();
2069

    
2070
                        val = DwgUtil.getBitLong(intData, bitPos);
2071
                        bitPos = ((Integer) val.get(0)).intValue();
2072
                        int numberObject = ((Integer) val.get(1)).intValue();
2073

    
2074
                        val = DwgUtil.getBitShort(intData, bitPos);
2075
                        bitPos = ((Integer) val.get(0)).intValue();
2076
                        int DwgVersion = ((Integer) val.get(1)).intValue();
2077

    
2078
                        val = DwgUtil.getBitShort(intData, bitPos);
2079
                        bitPos = ((Integer) val.get(0)).intValue();
2080
                        int maintenanceVersion = ((Integer) val.get(1)).intValue();
2081

    
2082
                        val = DwgUtil.getBitLong(intData, bitPos);
2083
                        bitPos = ((Integer) val.get(0)).intValue();
2084
                        int unknown1 = ((Integer) val.get(1)).intValue();
2085

    
2086
                        val = DwgUtil.getBitLong(intData, bitPos);
2087
                        bitPos = ((Integer) val.get(0)).intValue();
2088
                        int unknown2 = ((Integer) val.get(1)).intValue();
2089

    
2090
                        DwgClass2004 dwgClass = new DwgClass2004(classNum, version,
2091
                                        appName, cPlusPlusName, dxfName, isZombie, id,
2092
                                        numberObject, DwgVersion, maintenanceVersion, unknown1,
2093
                                        unknown2);
2094
                        dwgFile.addDwgClass(dwgClass);
2095

    
2096
                }// while
2097

    
2098
                decompressedBB.order(ByteOrder.nativeOrder());
2099
                byte[] lastSentinnel = new byte[16];
2100
                decompressedBB.get(lastSentinnel);
2101
                if (lastSentinnel[0] != 0x72)
2102
                        logger.trace("lastSentinnel[0] != 0x72");
2103
                if (lastSentinnel[1] != 0x5e)
2104
                        logger.trace("lastSentinnel[1] != 0x5e");
2105
                if (lastSentinnel[2] != 0x3b)
2106
                        logger.trace("lastSentinnel[2] != 0x3b");
2107
                if (lastSentinnel[3] != 0x47)
2108
                        logger.trace("lastSentinnel[3] != 0x47");
2109
                if (lastSentinnel[4] != 0x3b)
2110
                        logger.trace("lastSentinnel[4] != 0x3b");
2111
                if (lastSentinnel[5] != 0x56)
2112
                        logger.trace("lastSentinnel[5] != 0x56");
2113
                if (lastSentinnel[6] != 0x07)
2114
                        logger.trace("lastSentinnel[6] != 0x07");
2115
                if (lastSentinnel[7] != 0x3a)
2116
                        logger.trace("lastSentinnel[7] != 0x3a");
2117
                if (lastSentinnel[8] != 0x3f)
2118
                        logger.trace("lastSentinnel[8] != 0x3f");
2119
                if (lastSentinnel[9] != 0x23)
2120
                        logger.trace("lastSentinnel[9] != 0x23");
2121
                if (lastSentinnel[10] != 0x0b)
2122
                        logger.trace("lastSentinnel[10] != 0x0b");
2123
                if ((lastSentinnel[11] & 0xFF) != 0xa0)
2124
                        logger.trace("lastSentinnel[11] != 0xa0");
2125
                if (lastSentinnel[12] != 0x18)
2126
                        logger.trace("lastSentinnel[12] != 0x18");
2127
                if (lastSentinnel[13] != 0x30)
2128
                        logger.trace("lastSentinnel[13] != 0x30");
2129
                if (lastSentinnel[14] != 0x49)
2130
                        logger.trace("lastSentinnel[14] != 0x49");
2131
                if (lastSentinnel[15] != 0x75)
2132
                        logger.trace("lastSentinnel[15] != 0x75");
2133
        }
2134

    
2135
        /**
2136
         *
2137
         * @param bb
2138
         *            ByteBuffer containing the opened DWG File
2139
         */
2140
        private void readDwgR2004ObjectOffsets(ByteBuffer bb) {
2141

    
2142
                ByteBuffer decompressedBB = readSection(bb,"AcDb:Handles");
2143
                decompressedBB.position(0);
2144

    
2145
                short size;
2146

    
2147
                byte[] dataBytes;
2148
                int[] data;
2149
                int bitPos = 0;
2150
                int bitMax;
2151

    
2152

    
2153
                do {
2154
                        bitPos = 0;
2155
                        decompressedBB.order(ByteOrder.BIG_ENDIAN);
2156
                        size = decompressedBB.getShort();
2157
                        decompressedBB.order(ByteOrder.LITTLE_ENDIAN);
2158
                        if (size == 2)
2159
                                break;
2160
                        dataBytes = new byte[size-2];
2161
                        decompressedBB.get(dataBytes);
2162
                        data = DwgUtil.bytesToMachineBytes(dataBytes);
2163
                        bitMax = (size - 2) * 8;
2164
                        int lastHandle = 0;
2165
                        int lastLoc = 0;
2166
                        while (bitPos < bitMax) {
2167
                                ArrayList v = DwgUtil.getModularChar(data, bitPos);
2168
                                bitPos = ((Integer) v.get(0)).intValue();
2169
                                int handle = ((Integer) v.get(1)).intValue();
2170
                                if(handle<0){
2171
                                        logger.trace("offset negativo");
2172
                                        handle = - handle;
2173
                                }
2174
                                lastHandle = lastHandle + handle;
2175

    
2176
                                v = DwgUtil.getModularChar(data, bitPos);
2177
                                bitPos = ((Integer) v.get(0)).intValue();
2178
                                int loc = ((Integer) v.get(1)).intValue();
2179
                                lastLoc = lastLoc + loc;
2180

    
2181
                                dwgFile.addDwgObjectOffset(lastHandle, lastLoc);
2182

    
2183
                        }// while
2184
                        decompressedBB.getShort(); //crc
2185

    
2186
                } while (size != 2);
2187

    
2188
                return;
2189

    
2190
        }
2191

    
2192
        /**
2193
         * @return the decompressed data of a logical section,
2194
         * joining up all the physical sections belonging to it .
2195
         * @param ByteBuffer
2196
         *            Containing the opened dwg file
2197
         * @param compressedSize
2198
         *            size of the compressed data
2199
         * @param decompressedSize
2200
         *            size of the decompressed data
2201
         * @param CheckSum
2202
         */
2203
        protected ByteBuffer readSection(ByteBuffer bb, String name) {
2204

    
2205
                Section[] foundSections = findSections(name);
2206
                ByteBuffer fullSectionDecompressedBB = null;
2207
                ByteBuffer sectionDecompressedData = null;
2208
                int numberOfFoundSections = foundSections.length;
2209
                if ( numberOfFoundSections == 0) {
2210
                        logger.trace("No se han encontrado secciones llamadas " + name);
2211
                } else {
2212
                        Section section;
2213
                        int decompressedSize = foundSections[0].getMaxDecompressedSize();
2214

    
2215
                        fullSectionDecompressedBB = ByteBuffer.allocate(decompressedSize * numberOfFoundSections);
2216
                        fullSectionDecompressedBB.position(0);
2217

    
2218
                        for(int i=0; i<numberOfFoundSections; i++){
2219
                                section = (Section)foundSections[i];
2220

    
2221
                                int offset = section.getAddress();
2222
                                bb.position(offset);
2223
                                bb.order(ByteOrder.nativeOrder());
2224
                                byte[] encrypted = new byte[32];
2225
                                bb.get(encrypted); // We get the Encrypted Section Header
2226

    
2227
                                int[] decrypted = decryptSectionHeader(encrypted, offset);
2228
                                /*
2229
                                 * decrypted[0] = SectionType
2230
                                 * decrypted[1] = Data Size
2231
                                 * decrypted[2] = Section Size
2232
                                 * decrypted[3] = Start Offset
2233
                                 * decrypted[4] = Unknown
2234
                                 * decrypted[5] = CheckSum1
2235
                                 * decrypted[6] = CheckSum2
2236
                                 * decrypted[7] = ???
2237
                                 *
2238
                                 * Lo de arriba es lo de la documentacion pero yo creo [Paco]:
2239
                                 *
2240
                                 * decrypted[0] = ???
2241
                                 * decrypted[1] = SectionType
2242
                                 * decrypted[2] = Data Size
2243
                                 * decrypted[3] = Section Size
2244
                                 * decrypted[4] = Start Offset
2245
                                 * decrypted[5] = Unknown
2246
                                 * decrypted[6] = CheckSum1
2247
                                 * decrypted[7] = CheckSum2
2248
                                 *
2249
                                 */
2250

    
2251
                                if ( decrypted[1] != section.getType()){
2252
                                        logger.trace("Discrepancia en el tipo de seccion: " + section.getType() +" , " + decrypted[1] );
2253
                                }
2254
                                if ( decrypted[2] != section.getDataSize()){
2255
                                        logger.trace("Discrepancia en el tama?o de los datos de la seccion: " + section.getDataSize() +" , " + decrypted[2] );
2256
                                }
2257
                                if ( decrypted[3] != section.getSize()){
2258
                                        logger.trace("Discrepancia en el tama?o de la seccion: " + section.getSize() +" , " + decrypted[3] );
2259
                                }
2260
                                if ( decrypted[4] != section.getStartOffset()){
2261
                                        logger.trace("Discrepancia en el start offset de la seccion: " + section.getStartOffset() +" , " + decrypted[4] );
2262
                                }
2263

    
2264
                                decompressedSize = section.getMaxDecompressedSize();
2265
                                sectionDecompressedData = readCompressedSection(bb, decrypted[2],        decompressedSize, 0);
2266
                                sectionDecompressedData.position(0);
2267
                                section.setDecompressedData(sectionDecompressedData);
2268
                                if (fullSectionDecompressedBB.position() != section.getStartOffset()){
2269
                                        logger.trace("Desincronizaci?n entre el start offset de la seccion y la posici?n del ByteBuffer compuesto: " + section.getStartOffset() +" , " + fullSectionDecompressedBB.position() );
2270
                                }
2271
                                fullSectionDecompressedBB.put(section.getDecompressedData());
2272
                        }
2273
                }
2274
                return fullSectionDecompressedBB;
2275

    
2276
        }
2277

    
2278
        /**
2279
         * Reads all the object referenced in the object map section of the DWG file
2280
         * (using their object file obsets)
2281
         */
2282
        protected void readDwgR2004Objects() {
2283

    
2284
                ByteBuffer decompressedBB = readSection(bb, "AcDb:AcDbObjects");
2285
                if (decompressedBB != null){
2286
                        decompressedBB.position(0);
2287

    
2288
                        for (int i = 0; i < dwgFile.getDwgObjectOffsets().size(); i++) {
2289
                                try {
2290
                                        DwgObjectOffset doo = (DwgObjectOffset) dwgFile.getDwgObjectOffsets().get(i);
2291

    
2292
                                        DwgObject obj = readDwgR2004Object(decompressedBB, doo.getOffset(), i);
2293
                                        /*
2294
                                         * azabala: las entidades DWG no implementadas no nos aportan
2295
                                         * nada (aunque la sigo leyendo por si aparecen problemas de
2296
                                         * puntero de fichero) No considero por tanto los DwgObject if
2297
                                         * (obj != null) { dwgFile.addDwgObject(obj); }
2298
                                         *
2299
                                         * paco: propongo reconsiderar esto. Si no cargamos todos los
2300
                                         * objetos podemos tener problemas con las subentities.
2301
                                         */
2302
                                        if (obj != null && obj.getClass() != DwgObject.class) {
2303
                                                dwgFile.addDwgObject(obj);
2304
                                        }
2305
                                } catch (Exception e) {
2306
                                        logger.trace(e.getMessage());
2307
                                        continue;
2308
                                }
2309
                        }// for
2310
                }
2311

    
2312
        }
2313

    
2314
        /**
2315
         * Read commun parameters for an Object
2316
         *
2317
         * @param offset
2318
         *            Object's address
2319
         * @param index
2320
         *            object identifier
2321
         * @return the object
2322
         */
2323
        protected DwgObject readDwgR2004Object(ByteBuffer bb, int offset, int index) {
2324
                DwgObject obj = null;
2325
                try {
2326
                        if (offset >= bb.capacity()) {
2327
                                logger.trace("Posible error leyendo un objeto: capacity = "
2328
                                                + bb.capacity() + " offset = " + offset);
2329
                                return null;
2330
                        }
2331
                        bb.position(offset);
2332
                        int size = DwgUtil.getModularShort(bb);
2333

    
2334

    
2335
                        //FIXME: Esto es para saltarse posibles objetos defectuosos que nos
2336
                        //impedir?an ver el resto del archivo
2337
                        if (size == 0 || size>29696) {
2338
                                logger.trace("Posible error leyendo un objeto: size = "+size);
2339
                                return null;
2340
                        }
2341
                        if (offset + (size*8) >= bb.capacity()) {
2342
                                logger.trace("Posible error leyendo un objeto: capacity = "
2343
                                                + bb.capacity() + " offset = " + offset + " size = "+size);
2344
                                return null;
2345
                        }
2346

    
2347
                        bb.order(ByteOrder.LITTLE_ENDIAN);
2348
                        byte[] data = new byte[size];
2349
                        int[] intData = new int[size];
2350

    
2351
                        bb.get(data);
2352
                        try {
2353
                                intData = DwgUtil.toIntArray(data);
2354
                        } catch (Exception e) {
2355
                                logger.trace("Error leyendo un objeto: size = " + size, e);
2356
                                return null;
2357
                        }
2358

    
2359
                        int bitPos = 0;
2360
                        ArrayList v = DwgUtil.getBitShort(intData, bitPos);
2361
                        bitPos = ((Integer) v.get(0)).intValue();
2362
                        int type = ((Integer) v.get(1)).intValue(); // the type of object
2363

    
2364
                        obj = DwgObjectFactory.getInstance().create(type, index);
2365

    
2366
                        /*
2367
                         * This if is entered to check if the type of the object is a
2368
                         * non-fixed value
2369
                         */
2370
                        if (obj == null) {
2371
                                logger.trace("dwgFileVR2004Reader: Entrando en Objeto Nulo");
2372
                                if (type >= 500) {
2373
                                        int newIndex = type - 500;
2374
                                        if (newIndex < (dwgFile.getDwgClasses().size() - 1)) {
2375
                                                DwgClass2004 dwgClass = (DwgClass2004) dwgFile.getDwgClasses().get(newIndex);
2376
                                                String dxfEntityName = dwgClass.getDxfName();
2377
                                                obj = DwgObjectFactory.getInstance().create(dxfEntityName, index);
2378

    
2379
                                                if (obj == null) {
2380
                                                        logger.trace(dxfEntityName
2381
                                                                        + " todavia no est? implementado");
2382
                                                        return null;
2383
                                                }// if
2384
                                        }// if newIndex
2385
                                        else {
2386
                                                return null;
2387
                                        }
2388
                                } else {
2389
                                        logger.trace("dwgFileVR2004Reader: Encontrado tipo " + type);
2390
                                        return null;
2391
                                }
2392
                        }
2393
                        obj.setAddress(offset); // we set the address for the object. This
2394
                        // time there is no mistake
2395
                        obj.setVersion(dwgFile.getDwgVersion());
2396

    
2397
                        v = DwgUtil.getRawLong(intData, bitPos);
2398
                        bitPos = ((Integer) v.get(0)).intValue();
2399
                        int objBSize = ((Integer) v.get(1)).intValue();
2400
                        obj.setSizeInBits(objBSize);
2401

    
2402
                        DwgHandleReference entityHandle = new DwgHandleReference();
2403
                        bitPos = entityHandle.read(intData, bitPos);
2404
                        obj.setHandle(entityHandle);
2405

    
2406
                        v = DwgUtil.readExtendedData(intData, bitPos);
2407
                        bitPos = ((Integer) v.get(0)).intValue();
2408
                        ArrayList extData = (ArrayList) v.get(1);
2409
                        obj.setExtendedData(extData);
2410

    
2411
                        boolean gflag = obj.isGraphicsFlag();
2412
                        if (gflag) {
2413
                                //lee un flag boolean
2414
                                v = DwgUtil.testBit(intData, bitPos);
2415
                                bitPos = ((Integer) v.get(0)).intValue();
2416
                                boolean val = ((Boolean) v.get(1)).booleanValue();
2417
                                //si hay imagen asociada, se lee por completo
2418
                                if (val) {
2419
                                        v = DwgUtil.getRawLong(intData, bitPos);
2420
                                        bitPos = ((Integer) v.get(0)).intValue();
2421
                                        size = ((Integer) v.get(1)).intValue();
2422
                                        int bgSize = size * 8;
2423
                                        Integer giData = (Integer) DwgUtil.getBits(intData, bgSize,
2424
                                                        bitPos);
2425
                                        obj.setGraphicData(giData.intValue());
2426
                                        bitPos = bitPos + bgSize;
2427
                                }
2428
                        }
2429
                        if(obj.getClass() != DwgObject.class)
2430
                                readSpecificObject2004(obj, intData, bitPos);
2431

    
2432
                } catch (RuntimeException e) {
2433
                        e.printStackTrace();
2434
                        return null;
2435
                } catch (CorruptedDwgEntityException e) {
2436
                        // TODO Auto-generated catch block
2437
                        e.printStackTrace();
2438
                        return null;
2439
                }
2440
                return obj;
2441
        }
2442

    
2443
        /**
2444
         * Read a specific object depending on its type
2445
         *
2446
         * @param obj
2447
         *            the object to read
2448
         * @param data
2449
         *            Data of the object
2450
         * @param bitPos
2451
         *            Position where start reading
2452
         * @throws RuntimeException
2453
         * @throws CorruptedDwgEntityException
2454
         */
2455
        private void readSpecificObject2004(DwgObject obj, int[] data, int bitPos)
2456
                        throws RuntimeException, CorruptedDwgEntityException {
2457

    
2458
                DwgObjectReaderPool pool = DwgObjectReaderPool.getInstance();
2459
                IDwgObjectReader reader = pool.get(obj, "2004");
2460
                if (reader != null) {
2461
                        // reader.setFileReader(this);
2462
                        reader.readSpecificObj(data, bitPos, obj);
2463
                } else {
2464
                        logger.trace("No se ha implementado la lectura de "
2465
                                        + obj.getClass().getName() + ", code=" + obj.getType());
2466
                }
2467
        }
2468

    
2469

    
2470
        /**
2471
         * Reads the Section Map and fills the Sections Array with the sections
2472
         * found
2473
         */
2474
        protected void readDwgR2004SectionMap(ByteBuffer bb) {
2475
                bb.order(ByteOrder.LITTLE_ENDIAN);
2476
                bb.position(sectionMapAddress);
2477
                ByteBuffer dData = readSystemSection(bb);
2478
                dData.order(ByteOrder.LITTLE_ENDIAN);
2479
                dData.position(0);
2480

    
2481
                int sectionNumber;
2482
                int gapNumber = 0;
2483
                sections = new Section[sectionAmount + 1];
2484
                gaps = new Gap[gapAmount];
2485

    
2486
                sections[0] = new Section();
2487
                sections[0].setNumber(0);
2488
                sections[0].setSize(0);
2489
                sections[0].setAddress(0x100);
2490

    
2491
                int size=0;
2492
                int previousSize=0;
2493

    
2494
                /*
2495
                 * We start reading the section map once decompressed. this usually
2496
                 * gives a pair of SectionNumber/SectionSize unless a Gap (negative
2497
                 * section number) is found
2498
                 */
2499
                for (int i = 1; i <= sectionAmount; i++) {
2500
                        previousSize=size;
2501
                        size=0;
2502
                        sections[i] = new Section();
2503
                        sectionNumber = dData.getInt();
2504
                        while (sectionNumber < 0) {
2505
                                if (gapNumber >= gapAmount) {
2506
                                        logger.trace("ERROR: Se han encontrado mas gaps de los definidos");
2507
                                }
2508
                                gaps[gapNumber] = new Gap();
2509
                                int gapSize = dData.getInt();
2510
                                size += gapSize;
2511
                                gaps[gapNumber].setSize(gapSize);
2512
                                gaps[gapNumber].setParent(dData.getInt());
2513
                                gaps[gapNumber].setLeft(dData.getInt());
2514
                                gaps[gapNumber].setRight(dData.getInt());
2515
                                gaps[gapNumber].setZero(dData.getInt());
2516
                                gapNumber++;
2517
                                sectionNumber = dData.getInt();
2518
                        }
2519

    
2520
                        if (sectionNumber == sectionInfoId) {
2521
                                // We keep this index so we can localize the Section Info
2522
                                sectionInfoIndex = i;
2523
                        }
2524
                        sections[i].setNumber(sectionNumber);
2525
                        int sectionSize = dData.getInt();
2526
                        sections[i].setSize(sectionSize);
2527
                        size += sectionSize;
2528
                        if (i == 1) {
2529
                                sections[i].setAddress(0x100);
2530
                        } else {
2531
                                sections[i].setAddress(sections[i - 1].getAddress()
2532
                                                + previousSize);
2533
                        }
2534
                }
2535
        }
2536

    
2537
        /**
2538
         * @return Returns the decompressed data of SectionMap and Section Info.
2539
         * @param ByteBuffer
2540
         *            containing the dwg opened file
2541
         */
2542
        protected ByteBuffer readSystemSection(ByteBuffer bb) {
2543

    
2544
                int sectionType = bb.getInt();
2545
                int decompressedSize = bb.getInt();
2546
                int compressedSize = bb.getInt();
2547
                int compressionType = bb.getInt();
2548
                int checksum = bb.getInt();
2549

    
2550

    
2551
                return readCompressedSection(bb, compressedSize, decompressedSize, checksum);
2552

    
2553
        }
2554

    
2555
        /**
2556
         * @return the decompressed data of a compressed section.
2557
         * @param ByteBuffer
2558
         *            Containing the opend dwg file
2559
         * @param compressedSize
2560
         *            size of the compressed data
2561
         * @param decompressedSize
2562
         *            size of the decompressed data
2563
         * @param CheckSum
2564
         */
2565
        protected ByteBuffer readCompressedSection(ByteBuffer bb, int compressedSize, int decompressedSize, int checksum) {
2566
                long calcSize = 0;
2567
                ByteBuffer decompressedData;
2568
                decompressedData = ByteBuffer.allocate(decompressedSize);
2569
                decompressedData.order(ByteOrder.LITTLE_ENDIAN);
2570
                decompressedData.position(0);
2571

    
2572
                int opcodes = 0;
2573
                byte opcode1 = bb.get();
2574
                byte opcode2 = 0;
2575
                boolean opcode2valid = false;
2576
                int literalLength = 0;
2577
                int lls = 0;
2578
                int compressedBytes = 0; // Number of "compressed" bytes that are to be copied to this
2579
                                         // location from a previous location in the uncompressed data stream
2580

    
2581
                int compOffset = 0; // Offset backwards from the current location in the decompressed data stream,
2582
                                    // where the "compressed" bytes should be copied from.
2583

    
2584
                int litCount = 0; // Number of uncompressed or literal bytes to be copied from the input stream,
2585
                                  // following the addition of the compressed bytes.
2586
                int[] twoBytesOffset;
2587
                byte b;
2588

    
2589
                try {
2590
                        if (((opcode1 & 0xFF) >= 0x00) && ((opcode1 & 0xFF) <= 0x0F)) {
2591
                                literalLength = readLiteralLength(bb, opcode1);
2592
                                lls++;
2593
                                if (literalLength != 0) { // Copy the first sequence of uncompressed(literal) data
2594
                                        for (int i = 0; i < literalLength; i++) {
2595
                                                b = bb.get();
2596
                                                decompressedData.put(b);
2597
                                        }
2598
                                        opcode1 = bb.get(); // get the first opcode
2599
                                }
2600
                                calcSize = calcSize + literalLength;
2601

    
2602
                        } else {
2603
                                logger.trace("Error leyendo el literal Length");
2604
                        }
2605

    
2606
                        // We start treating the opcodes
2607

    
2608
                        while (opcode1 != 0x11) {
2609

    
2610
                                if ((opcode1 & 0xFF) >= 0x00 && (opcode1 & 0xFF) <= 0x0F) {
2611

    
2612
                                        logger.trace("Posible error leyendo el opcode " + opcode1);
2613
                                        decompressedData.put(opcode1); // ???
2614
                                        if (opcode2valid) {
2615
                                                opcode1 = opcode2;
2616
                                                opcode2valid = false;
2617
                                        } else {
2618
                                                opcode1 = bb.get();
2619
                                        }
2620
                                        continue;
2621
                                } else {
2622
                                        compressedBytes = 0;
2623
                                        compOffset = 0;
2624
                                        litCount = 0;
2625
                                        opcodes++;
2626
                                        if ((opcode1 & 0xFF) == 0x10) {
2627
                                                compressedBytes = readLongCompressionOffset(bb) + 9;
2628
                                                twoBytesOffset = readTwoByteOffset(bb);
2629
                                                compOffset = twoBytesOffset[0] + 0x3FFF;
2630
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2631
                                                opcode2 = bb.get(); // we get the next opcode
2632
                                                opcode2valid = true;
2633
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2634
                                                        litCount = readLiteralLength(bb, opcode2);
2635
                                                        opcode2valid = false;
2636
                                                        if (litCount != 0) {
2637
                                                                opcode2 = bb.get();
2638
                                                                opcode2valid = true;
2639
                                                        }
2640
                                                }
2641
                                        } else if ((opcode1 & 0xFF) >= 0x12
2642
                                                        && (opcode1 & 0xFF) <= 0x17) {
2643
                                                compressedBytes = (opcode1 & 0x0F) + 2;
2644
                                                twoBytesOffset = readTwoByteOffset(bb);
2645
                                                compOffset = twoBytesOffset[0] + 0x3FFF;
2646
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2647
                                                opcode2 = bb.get(); // we get the next opcode
2648
                                                opcode2valid = true;
2649
                                                if (litCount == 0) { // if litCount is 0, it is read
2650
                                                        // as the next literal length
2651
                                                        litCount = readLiteralLength(bb, opcode2);
2652
                                                        opcode2valid = false;
2653
                                                        if (litCount != 0) {
2654
                                                                opcode2 = bb.get();
2655
                                                                opcode2valid = true;
2656
                                                        }
2657
                                                }
2658
                                        } else if ((opcode1 & 0xFF) == 0x18) {
2659
                                                // Fuera de las especificaciones de OpenDWG pero
2660
                                                // segun chiuinan2, un usuario del foro (en japones):
2661
                                                // http://www.programmer-club.com/pc2020v5/Forum/ShowSameTitleN.asp?URL=N&board_pc2020=general&index=16&id=4664&mode=&type_pc2020=sametitleLevel-2
2662
                                                // hay que hacer este tratamiento al recibir estos opcodes
2663

    
2664
                                                compressedBytes = readLongCompressionOffset(bb) + 9;
2665
                                                twoBytesOffset = readTwoByteOffset(bb);
2666
                                                compOffset = twoBytesOffset[0] + 0x7FFF;
2667
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2668
                                                opcode2 = bb.get(); // we get the next opcode
2669
                                                opcode2valid = true;
2670
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2671
                                                        litCount = readLiteralLength(bb, opcode2);
2672
                                                        opcode2valid = false;
2673
                                                        if (litCount != 0) {
2674
                                                                opcode2 = bb.get();
2675
                                                                opcode2valid = true;
2676
                                                        }
2677
                                                }
2678
                                        } else if ((opcode1 & 0xFF) >= 0x19
2679
                                                        && (opcode1 & 0xFF) <= 0x1f) {
2680
                                                // Fuera de las especificaciones de OpenDWG pero
2681
                                                // segun chiuinan2, un usuario del foro (en japones):
2682
                                                // http://www.programmer-club.com/pc2020v5/Forum/ShowSameTitleN.asp?URL=N&board_pc2020=general&index=16&id=4664&mode=&type_pc2020=sametitleLevel-2
2683
                                                // hay que hacer este tratamiento al recibir estos opcodes
2684

    
2685
                                                compressedBytes = (opcode1 & 0x0F) + 2;
2686
                                                twoBytesOffset = readTwoByteOffset(bb);
2687
                                                compOffset = twoBytesOffset[0] + 0x7FFF;
2688
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2689
                                                opcode2 = bb.get(); // we get the next opcode
2690
                                                opcode2valid = true;
2691
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2692
                                                        litCount = readLiteralLength(bb, opcode2);
2693
                                                        opcode2valid = false;
2694
                                                        if (litCount != 0) {
2695
                                                                opcode2 = bb.get();
2696
                                                                opcode2valid = true;
2697
                                                        }
2698
                                                }
2699
                                        } else if ((opcode1 & 0xFF) == 0x20) {
2700
                                                // Fuera de las especificaciones de OpenDWG pero
2701
                                                // segun kermit un usuario del foro de openDesign hay
2702
                                                // que a?adirle 0x21
2703
                                                compressedBytes = readLongCompressionOffset(bb) + 0x21;
2704
                                                twoBytesOffset = readTwoByteOffset(bb);
2705
                                                compOffset = twoBytesOffset[0];
2706
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2707
                                                opcode2 = bb.get(); // we get the next opcode
2708
                                                opcode2valid = true;
2709
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2710
                                                        litCount = readLiteralLength(bb, opcode2);
2711
                                                        opcode2valid = false;
2712
                                                        if (litCount != 0) {
2713
                                                                opcode2 = bb.get();
2714
                                                                opcode2valid = true;
2715
                                                        }
2716
                                                }
2717
                                        } else if ((opcode1 & 0xFF) >= 0x21
2718
                                                        && (opcode1 & 0xFF) <= 0x3f) {
2719
                                                compressedBytes = (opcode1 & 0xFF) - 0x1E;
2720

    
2721
                                                twoBytesOffset = readTwoByteOffset(bb);
2722
                                                compOffset = twoBytesOffset[0];
2723
                                                litCount = twoBytesOffset[1]; // this can take values from 0 to 3.
2724
                                                opcode2 = bb.get(); // we get the next opcode
2725
                                                opcode2valid = true;
2726
                                                if (litCount == 0) { // if litCount is 0, it is read as the next literal length
2727
                                                        litCount = readLiteralLength(bb, opcode2);
2728
                                                        opcode2valid = false;
2729
                                                        if (litCount != 0) {
2730
                                                                opcode2 = bb.get();
2731
                                                                opcode2valid = true;
2732
                                                        }
2733
                                                }
2734
                                        } else if ((opcode1 & 0xFF) >= 0x40
2735
                                                        && (opcode1 & 0xFF) <= 0xFF) {
2736
                                                compressedBytes = ((opcode1 & 0xF0) >> 4) - 1;
2737
                                                opcode2 = bb.get(); // we read the next byte
2738
                                                opcode2valid = true;
2739
                                                compOffset = ((opcode2 & 0xFF) << 2)
2740
                                                                | ((opcode1 & 0x0C) >> 2);
2741
                                                opcode2valid = false;
2742
                                                if ((opcode1 & 0x03) == 0x00) { // if litCount is 0, it is read as the next literal length
2743
                                                        litCount = 0;
2744
                                                        byte opcode3 = bb.get();
2745
                                                        litCount = readLiteralLength(bb, opcode3);
2746
                                                        if (litCount == 0) {
2747
                                                                opcode2 = opcode3; // if litCount = 0, the actual byte is the next opcode
2748
                                                        } else {
2749
                                                                opcode2 = bb.get(); // we get the next opcode
2750
                                                        }
2751
                                                        opcode2valid = true;
2752
                                                } else {
2753
                                                        litCount = opcode1 & 0x03;
2754
                                                        opcode2 = bb.get();
2755
                                                        opcode2valid = true;
2756
                                                }
2757
                                        } else {
2758
                                                logger.trace("Posible error de lectura de una seccion comprimida: " +
2759
                                                                "Ha aparecido un opcode1 con valor "
2760
                                                                + Integer.toHexString(opcode1 & 0xFF));
2761
                                                opcode2 = bb.get();
2762
                                                opcode2valid = true;
2763
                                        }
2764

    
2765
                                        if (compressedBytes < 0) {
2766
                                                logger.trace("Posible error de lectura de una seccion comprimida: compressedBytes < 0");
2767
                                        }
2768
                                        if (compOffset < 0) {
2769
                                                logger.trace("Posible error de lectura de una seccion comprimida: compOffset < 0");
2770
                                        }
2771
                                        if (litCount < 0) {
2772
                                                logger.trace("Posible error de lectura de una seccion comprimida: litCount < 0");
2773
                                        }
2774

    
2775
                                        if (compressedBytes > compOffset) {
2776
                                                logger.trace("Posible error en la lectura de una seccion comprimida: "
2777
                                                                                + "No parece logico que compressedBytes > compOffset");
2778
                                        }
2779
                                        if (compOffset >= decompressedData.position()) {
2780
                                                logger.trace("Posible error en la lectura de una seccion comprimida:"
2781
                                                                                + " el compOffset se sale");
2782
                                                compressedBytes = 0; // ???? Para no leer bytes comprimidos ni que se
2783
                                                // incluyan en el tama?o calculado.
2784
                                        }
2785
                                        /*
2786
                                         * We first copy the compressed bytes in our
2787
                                         * decompressedData buffer, from a position compOffset bytes
2788
                                         * backward from the current position
2789
                                         */
2790

    
2791
                                        for (int i = 0; i < compressedBytes; i++) {
2792
                                                b = decompressedData.get(decompressedData.position() - compOffset - 1);
2793
                                                decompressedData.put(b);
2794
                                        }
2795

    
2796
                                        /*
2797
                                         * Then we copy the literal bytes to our decompressedData
2798
                                         * from the input stream
2799
                                         */
2800
                                        for (int i = 0; i < litCount; i++) {
2801
                                                decompressedData.put(opcode2);
2802
                                                opcode2valid = false;
2803
                                                opcode2 = bb.get();
2804
                                                opcode2valid = true;
2805
                                        }
2806

    
2807
                                        calcSize = calcSize + compressedBytes + litCount;
2808
                                }
2809
                                opcode1 = opcode2;
2810
                                opcode2valid = false;
2811
                        }
2812

    
2813
                } catch (Exception e) {
2814
                        e.printStackTrace();
2815

    
2816
                }
2817

    
2818
                return decompressedData;
2819
        }
2820

    
2821
        /**
2822
         * @return the value of the Literal Length.
2823
         * @param ByteBuffer
2824
         *            Containing the opened dwg File.
2825
         * @param byte
2826
         *            b The opcode to calculate the Literal Length
2827
         */
2828
        private int readLiteralLength(ByteBuffer bb, byte b) {
2829
                int total = 0;
2830
                if (0x01 <= b && b <= 0x0F) {
2831
                        total = (b & 0xFF) + 3;
2832
                        return total;
2833
                } else if (b == 0x00) {
2834
                        total = 0x0F;
2835
                        b = bb.get();
2836
                        while (b == 0x00) {
2837
                                total += 0xFF;
2838
                                b = bb.get();
2839
                        }
2840
                        total += (b & 0xFF) + 3;
2841
                        return total;
2842
                } else if ((b & 0xF0) != 0) {
2843
                        /*
2844
                         * Any bit set in the high nibble indicates that the literal lenght
2845
                         * is 0, and the byte is actually the next compression opcode. This
2846
                         * is case is not possible when the first literal length is read
2847
                         */
2848
                        return 0;
2849
                }
2850
                logger.trace("Posible error de lectura: Se ha encontrado un Literal Lenght: "
2851
                                + Integer.toHexString(b & 0xFF));
2852
                return total;
2853
        }
2854

    
2855
        /**
2856
         * Common compression for different opcodes
2857
         *
2858
         * @param bb
2859
         *            ByteBuffer reading the opened DWG file
2860
         * @return the value for <code> offset </code> and <code> litCount </code>
2861
         */
2862
        private int[] readTwoByteOffset(ByteBuffer bb) {
2863
                byte firstByte = bb.get();
2864
                int[] values = new int[2];
2865
                int offset = (((firstByte & 0xFF) >> 2) | ((bb.get() & 0xFF) << 6));
2866
                int litCount = firstByte & 0x03; // This will make litCount taking values from 0 to 3
2867
                values[0] = offset;
2868
                values[1] = litCount;
2869
                return values;
2870
        }
2871

    
2872
        /**
2873
         * Common compression for different opcodes
2874
         *
2875
         * @param bb
2876
         *            ByteBuffer reading the opened DWG file
2877
         * @return the value for <code> compressedBytes </code>
2878
         */
2879
        private int readLongCompressionOffset(ByteBuffer bb) {
2880
                int value = 0;
2881
                byte b = bb.get();
2882
                while (b == 0x00) {
2883
                        value = value + 0xFF;
2884
                        b = bb.get();
2885
                }
2886
                value = value + (b & 0xFF);
2887
                return value;
2888
        }
2889

    
2890
        /**
2891
         * Generate a sequence into magicNumber to decrypt the encrypted data in the
2892
         * header
2893
         */
2894
        static void setMagicNumber() {
2895
                int size = 0x6C;
2896
                magicNumber = new byte[size];
2897
                int randseed = 1;
2898
                for (int i = 0; i < size; i++) {
2899
                        randseed *= 0x343fd;
2900
                        randseed += 0x269ec3;
2901
                        magicNumber[i] = (byte) (randseed >> 0x10);
2902
                }
2903
        }
2904

    
2905

    
2906
        public int readObjectHeader(int[] data, int offset, DwgObject dwgObject)
2907
                        throws RuntimeException, CorruptedDwgEntityException {
2908
                // TODO Auto-generated method stub
2909
                throw new UnsupportedOperationException();
2910
                // return 0;
2911
        }
2912

    
2913
        public int readObjectTailer(int[] data, int offset, DwgObject dwgObject)
2914
                        throws RuntimeException, CorruptedDwgEntityException {
2915
                // TODO Auto-generated method stub
2916
                throw new UnsupportedOperationException();
2917
                // return 0;
2918
        }
2919

    
2920
}
2921

    
2922
/**
2923
 * A section structure contains the number (identifier),size, address and name
2924
 * of the section
2925
 *
2926
 */
2927
class Section {
2928
        private int number;
2929

    
2930
        private int size;
2931

    
2932
        private int address;
2933

    
2934
        private String name;
2935

    
2936
        private int sizeOfLogicalSection;
2937

    
2938
        private int dataSize;
2939

    
2940
        private int maxDecompressedSize;
2941

    
2942
        private int compressed;
2943

    
2944
        private int type;
2945

    
2946
        private int encrypted;
2947

    
2948
        private int startOffset;
2949

    
2950
        private ByteBuffer decompressedData = null;
2951

    
2952
        /**
2953
         *
2954
         * @return number of Section
2955
         */
2956
        public int getNumber() {
2957
                return number;
2958
        }
2959

    
2960
        /**
2961
         * Sets number of section
2962
         *
2963
         * @param number
2964
         */
2965
        public void setNumber(int number) {
2966
                this.number = number;
2967
        }
2968

    
2969
        /**
2970
         *
2971
         * @return size of Section
2972
         */
2973
        public int getSize() {
2974
                return size;
2975
        }
2976

    
2977
        /**
2978
         * Sets size2 of Section
2979
         *
2980
         * @param size
2981
         */
2982
        public void setSizeOfLogicalSection(int size) {
2983
                this.sizeOfLogicalSection = size;
2984
        }
2985

    
2986
        /**
2987
         *
2988
         * @return size of Section
2989
         */
2990
        public int getSizeOfLogicalSection() {
2991
                return sizeOfLogicalSection;
2992
        }
2993

    
2994
        /**
2995
         * Sets size of Section
2996
         *
2997
         * @param size
2998
         */
2999
        public void setSize(int size) {
3000
                this.size = size;
3001
        }
3002

    
3003
        /**
3004
         *
3005
         * @return address of Section
3006
         */
3007
        public int getAddress() {
3008
                return address;
3009
        }
3010

    
3011
        /**
3012
         * Sets address of Section
3013
         *
3014
         * @param address
3015
         */
3016
        public void setAddress(int address) {
3017
                this.address = address;
3018
        }
3019

    
3020
        /**
3021
         *
3022
         * @return name of Section
3023
         */
3024
        public String getName() {
3025
                return this.name;
3026
        }
3027

    
3028
        /**
3029
         * Sets the name of Section
3030
         *
3031
         * @param name
3032
         */
3033
        public void setName(String name) {
3034
                this.name = name;
3035
        }
3036

    
3037
        /**
3038
         *
3039
         * @return size of data of the Section
3040
         */
3041
        public int getDataSize() {
3042
                return dataSize;
3043
        }
3044

    
3045
        /**
3046
         * Sets size of data of the Section
3047
         *
3048
         * @param size
3049
         */
3050
        public void setDataSize(int dataSize) {
3051
                this.dataSize = dataSize;
3052
        }
3053

    
3054
        /**
3055
         *
3056
         * @return the maximum decompressed size of section
3057
         */
3058
        public int getMaxDecompressedSize() {
3059
                return maxDecompressedSize;
3060
        }
3061

    
3062
        /**
3063
         * Sets the maximum decompressed size of section
3064
         *
3065
         * @param number
3066
         */
3067
        public void setMaxDecompressedSize(int maxDecompressedSize) {
3068
                this.maxDecompressedSize = maxDecompressedSize;
3069
        }
3070

    
3071
        /**
3072
         *
3073
         * @return compressed of section
3074
         */
3075
        public int getCompressed() {
3076
                return compressed;
3077
        }
3078

    
3079
        /**
3080
         * Sets compressed of section
3081
         *
3082
         * @param number
3083
         */
3084
        public void setCompressed(int compressed) {
3085
                this.compressed = compressed;
3086
        }
3087

    
3088
        /**
3089
         *
3090
         * @return type of Section
3091
         */
3092
        public int getType() {
3093
                return type;
3094
        }
3095

    
3096
        /**
3097
         * Sets type of section
3098
         *
3099
         * @param number
3100
         */
3101
        public void setType(int type) {
3102
                this.type = type;
3103
        }
3104

    
3105
        /**
3106
         *
3107
         * @return encrypted of Section
3108
         */
3109
        public int getEncrypted() {
3110
                return encrypted;
3111
        }
3112

    
3113
        /**
3114
         * Sets encrypted of section
3115
         *
3116
         * @param number
3117
         */
3118
        public void setEncrypted(int encrypted) {
3119
                this.encrypted = encrypted;
3120
        }
3121

    
3122
        /**
3123
         * Sets startOffset of Section
3124
         *
3125
         * @param size
3126
         */
3127
        public void setStartOffset(int startOffset) {
3128
                this.startOffset = startOffset;
3129
        }
3130

    
3131
        /**
3132
         *
3133
         * @return startOffset of Section
3134
         */
3135
        public int getStartOffset() {
3136
                return startOffset;
3137
        }
3138

    
3139
        /**
3140
         * Sets decompressedData of Section
3141
         *
3142
         * @param decompressedData
3143
         */
3144
        public void setDecompressedData(ByteBuffer decompressedData) {
3145
                this.decompressedData = decompressedData;
3146
        }
3147

    
3148
        /**
3149
         *
3150
         * @return decompressedData of Section
3151
         */
3152
        public ByteBuffer getDecompressedData() {
3153
                return decompressedData;
3154
        }
3155

    
3156

    
3157
}
3158

    
3159
/**
3160
 * A gap structure contains the size, parent, left, right and zero
3161
 * of the gap
3162
 *
3163
 */
3164
class Gap {
3165
        private int size;
3166

    
3167
        private int parent;
3168

    
3169
        private int left;
3170

    
3171
        private int right;
3172

    
3173
        private int zero;
3174

    
3175
        public int getParent() {
3176
                return parent;
3177
        }
3178

    
3179
        /**
3180
         * Sets parent of section
3181
         *
3182
         * @param parent
3183
         */
3184
        public void setParent(int parent) {
3185
                this.parent = parent;
3186
        }
3187

    
3188
        /**
3189
         *
3190
         * @return left of Section
3191
         */
3192
        public int getLeft() {
3193
                return left;
3194
        }
3195

    
3196
        /**
3197
         * Sets left of section
3198
         *
3199
         * @param left
3200
         */
3201
        public void setLeft(int left) {
3202
                this.left = left;
3203
        }
3204

    
3205
        /**
3206
         *
3207
         * @return right of Section
3208
         */
3209
        public int getRight() {
3210
                return right;
3211
        }
3212

    
3213
        /**
3214
         * Sets right of section
3215
         *
3216
         * @param right
3217
         */
3218
        public void setRight(int right) {
3219
                this.right = right;
3220
        }
3221

    
3222
        /**
3223
         *
3224
         * @return zero of Section
3225
         */
3226
        public int getZero() {
3227
                return zero;
3228
        }
3229

    
3230
        /**
3231
         * Sets zero of section
3232
         *
3233
         * @param zero
3234
         */
3235
        public void setZero(int zero) {
3236
                this.zero = zero;
3237
        }
3238

    
3239
        /**
3240
         *
3241
         * @return size of Section
3242
         */
3243
        public int getSize() {
3244
                return size;
3245
        }
3246

    
3247
        /**
3248
         * Sets size of section
3249
         *
3250
         * @param size
3251
         */
3252
        public void setSize(int size) {
3253
                this.size = size;
3254
        }
3255
}