Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgBlockHeader.java @ 2896

History | View | Annotate | Download (14.4 KB)

1
/* jdwglib. Java Library for reading Dwg files.
2
 * 
3
 * Author: Jose Morell Rama (jose.morell@gmail.com).
4
 * Port from the Pythoncad Dwg library by Art Haas.
5
 *
6
 * Copyright (C) 2005 Jose Morell, IVER TI S.A. 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
 * Jose Morell (jose.morell@gmail.com)
25
 * 
26
 * or
27
 *
28
 * IVER TI S.A.
29
 *  C/Salamanca, 50
30
 *  46005 Valencia
31
 *  Spain
32
 *  +34 963163400
33
 *  dac@iver.es
34
 */
35
package com.iver.cit.jdwglib.dwg.objects;
36

    
37
import java.util.Vector;
38

    
39
import com.iver.cit.jdwglib.dwg.DwgObject;
40
import com.iver.cit.jdwglib.dwg.DwgUtil;
41

    
42
/**
43
 * The DwgBlockHeader class represents a DWG Block header
44
 * 
45
 * @author jmorell
46
 */
47
public class DwgBlockHeader extends DwgObject {
48
        private String name;
49
        private boolean flag64;
50
        private int xRefPlus;
51
        private boolean xdep;
52
        private boolean anonymous;
53
        private boolean hasAttrs;
54
        private boolean blkIsXRef;
55
        private boolean xRefOverLaid;
56
        private boolean loaded;
57
        private double[] basePoint;
58
        private String xRefPName;
59
        private String blockDescription;
60
        private int previewData;
61
        private int blockControlHandle;
62
        private int nullHandle;
63
        private int blockEntityHandle;
64
        private int firstEntityHandle;
65
        private int lastEntityHandle;
66
        private int endBlkEntityHandle;
67
        private Vector insertHandles;
68
        private int layoutHandle;
69
        private Vector objects;
70
        
71
        /**
72
         * Create new DwgBlockHeader object
73
         */
74
        public DwgBlockHeader() {
75
                objects = new Vector();
76
        }
77
        /**
78
         * Read a Block header in the DWG format Version 15
79
         * 
80
         * @param data Array of unsigned bytes obtained from the DWG binary file
81
         * @param offset The current bit offset where the value begins
82
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
83
         *                    when we are looking for LwPolylines.
84
         */
85
        public void readDwgBlockHeaderV15(int[] data, int offset) throws Exception {
86
                int bitPos = offset;
87
                Vector v = DwgUtil.getBitLong(data, bitPos);
88
                bitPos = ((Integer)v.get(0)).intValue();
89
                int numReactors = ((Integer)v.get(1)).intValue();
90
                setNumReactors(numReactors);
91
                v = DwgUtil.getTextString(data, bitPos);
92
                bitPos = ((Integer)v.get(0)).intValue();
93
                String name = (String)v.get(1);
94
                this.name = name;
95
                v = DwgUtil.testBit(data, bitPos);
96
                bitPos = ((Integer)v.get(0)).intValue();
97
                boolean flag = ((Boolean)v.get(1)).booleanValue();
98
                flag64 = flag;
99
                v = DwgUtil.getBitShort(data, bitPos);
100
                bitPos = ((Integer)v.get(0)).intValue();
101
                int xrefplus1 = ((Integer)v.get(1)).intValue();
102
                xRefPlus = xrefplus1;
103
                v = DwgUtil.testBit(data, bitPos);
104
                bitPos = ((Integer)v.get(0)).intValue();
105
                boolean xdep = ((Boolean)v.get(1)).booleanValue();
106
                this.xdep = xdep;
107
                v = DwgUtil.testBit(data, bitPos);
108
                bitPos = ((Integer)v.get(0)).intValue();
109
                boolean anon = ((Boolean)v.get(1)).booleanValue();
110
                anonymous = anon;
111
                v = DwgUtil.testBit(data, bitPos);
112
                bitPos = ((Integer)v.get(0)).intValue();
113
                boolean hasatts = ((Boolean)v.get(1)).booleanValue();
114
                hasAttrs = hasatts;
115
                v = DwgUtil.testBit(data, bitPos);
116
                bitPos = ((Integer)v.get(0)).intValue();
117
                boolean bxref = ((Boolean)v.get(1)).booleanValue();
118
                blkIsXRef = bxref;
119
                v = DwgUtil.testBit(data, bitPos);
120
                bitPos = ((Integer)v.get(0)).intValue();
121
                boolean xover = ((Boolean)v.get(1)).booleanValue();
122
                xRefOverLaid = xover;
123
                v = DwgUtil.testBit(data, bitPos);
124
                bitPos = ((Integer)v.get(0)).intValue();
125
                boolean loaded = ((Boolean)v.get(1)).booleanValue();
126
                this.loaded = loaded;
127
                v = DwgUtil.getBitDouble(data, bitPos);
128
                bitPos = ((Integer)v.get(0)).intValue();
129
                double bx = ((Double)v.get(1)).doubleValue();
130
                v = DwgUtil.getBitDouble(data, bitPos);
131
                bitPos = ((Integer)v.get(0)).intValue();
132
                double by = ((Double)v.get(1)).doubleValue();
133
                v = DwgUtil.getBitDouble(data, bitPos);
134
                bitPos = ((Integer)v.get(0)).intValue();
135
                double bz = ((Double)v.get(1)).doubleValue();
136
                double[] coord = new double[]{bx, by, bz};
137
                basePoint = coord;
138
                v = DwgUtil.getTextString(data, bitPos);
139
                bitPos = ((Integer)v.get(0)).intValue();
140
                String pname = (String)v.get(1);
141
                xRefPName = pname;
142
                int icount = 0;
143
                while (true) {
144
                        v = DwgUtil.getRawChar(data, bitPos);
145
                        bitPos = ((Integer)v.get(0)).intValue();
146
                        int val = ((Integer)v.get(1)).intValue();
147
                        if (val==0) {
148
                                break;
149
                        }
150
                        icount++;
151
                }
152
                v = DwgUtil.getTextString(data, bitPos);
153
                bitPos = ((Integer)v.get(0)).intValue();
154
                String desc = (String)v.get(1);
155
                blockDescription = desc;
156
                v = DwgUtil.getBitLong(data, bitPos);
157
                bitPos = ((Integer)v.get(0)).intValue();
158
                int pdsize = ((Integer)v.get(1)).intValue();
159
                if (pdsize>0) {
160
                        int count = pdsize + icount;
161
                        //int pdata = ((Integer)DwgUtil.getBits(data, count, bitPos)).intValue();
162
                        //previewData = pdata;
163
                        bitPos = bitPos + count;
164
                }
165
                v = DwgUtil.getHandle(data, bitPos);
166
                bitPos = ((Integer)v.get(0)).intValue();
167
                int[] handle = new int[v.size()-1];
168
            for (int j=1;j<v.size();j++) {
169
                    handle[j-1] = ((Integer)v.get(j)).intValue();
170
            }
171
            Vector handleVect = new Vector();
172
            for (int i=0;i<handle.length;i++) {
173
                    handleVect.add(new Integer(handle[i]));
174
            }
175
            blockControlHandle = DwgUtil.handleBinToHandleInt(handleVect);
176
                for (int i=0;i<numReactors;i++) {
177
                        v = DwgUtil.getHandle(data, bitPos);
178
                        bitPos = ((Integer)v.get(0)).intValue();
179
                        handle = new int[v.size()-1];
180
                    for (int j=1;j<v.size();j++) {
181
                            handle[j-1] = ((Integer)v.get(j)).intValue();
182
                    }
183
                }
184
                v = DwgUtil.getHandle(data, bitPos);
185
                bitPos = ((Integer)v.get(0)).intValue();
186
                handle = new int[v.size()-1];
187
            for (int j=1;j<v.size();j++) {
188
                    handle[j-1] = ((Integer)v.get(j)).intValue();
189
            }
190
                v = DwgUtil.getHandle(data, bitPos);
191
                bitPos = ((Integer)v.get(0)).intValue();
192
                handle = new int[v.size()-1];
193
            for (int j=1;j<v.size();j++) {
194
                    handle[j-1] = ((Integer)v.get(j)).intValue();
195
            }
196
            handleVect = new Vector();
197
            for (int i=0;i<handle.length;i++) {
198
                    handleVect.add(new Integer(handle[i]));
199
            }
200
            nullHandle = DwgUtil.handleBinToHandleInt(handleVect);
201
                v = DwgUtil.getHandle(data, bitPos);
202
                bitPos = ((Integer)v.get(0)).intValue();
203
                handle = new int[v.size()-1];
204
            for (int j=1;j<v.size();j++) {
205
                    handle[j-1] = ((Integer)v.get(j)).intValue();
206
            }
207
            handleVect = new Vector();
208
            for (int i=0;i<handle.length;i++) {
209
                    handleVect.add(new Integer(handle[i]));
210
            }
211
            blockEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
212
                if ((!bxref) && (!xover)) {
213
                        v = DwgUtil.getHandle(data, bitPos);
214
                        bitPos = ((Integer)v.get(0)).intValue();
215
                        handle = new int[v.size()-1];
216
                    for (int j=1;j<v.size();j++) {
217
                            handle[j-1] = ((Integer)v.get(j)).intValue();
218
                    }
219
                    handleVect = new Vector();
220
                    for (int i=0;i<handle.length;i++) {
221
                            handleVect.add(new Integer(handle[i]));
222
                    }
223
                    firstEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
224
                        v = DwgUtil.getHandle(data, bitPos);
225
                        bitPos = ((Integer)v.get(0)).intValue();
226
                        handle = new int[v.size()-1];
227
                    for (int j=1;j<v.size();j++) {
228
                            handle[j-1] = ((Integer)v.get(j)).intValue();
229
                    }
230
                    handleVect = new Vector();
231
                    for (int i=0;i<handle.length;i++) {
232
                            handleVect.add(new Integer(handle[i]));
233
                    }
234
                    lastEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
235
                }
236
                v = DwgUtil.getHandle(data, bitPos);
237
                bitPos = ((Integer)v.get(0)).intValue();
238
                handle = new int[v.size()-1];
239
            for (int j=1;j<v.size();j++) {
240
                    handle[j-1] = ((Integer)v.get(j)).intValue();
241
            }
242
            handleVect = new Vector();
243
            for (int i=0;i<handle.length;i++) {
244
                    handleVect.add(new Integer(handle[i]));
245
            }
246
            endBlkEntityHandle = DwgUtil.handleBinToHandleInt(handleVect);
247
                if (icount>0) {
248
                        Vector handles = new Vector();
249
                        for (int i=0;i<icount;i++) {
250
                                v = DwgUtil.getHandle(data, bitPos);
251
                                bitPos = ((Integer)v.get(0)).intValue();
252
                                handle = new int[v.size()-1];
253
                            for (int j=1;j<v.size();j++) {
254
                                    handle[j-1] = ((Integer)v.get(j)).intValue();
255
                            }
256
                                handles.add(handle);
257
                        }
258
                    insertHandles = handles;
259
                }
260
                v = DwgUtil.getHandle(data, bitPos);
261
                bitPos = ((Integer)v.get(0)).intValue();
262
                handle = new int[v.size()-1];
263
            for (int j=1;j<v.size();j++) {
264
                    handle[j-1] = ((Integer)v.get(j)).intValue();
265
            }
266
            handleVect = new Vector();
267
            for (int i=0;i<handle.length;i++) {
268
                    handleVect.add(new Integer(handle[i]));
269
            }
270
            layoutHandle = DwgUtil.handleBinToHandleInt(handleVect);
271
        }
272
        /**
273
         * @return Returns the basePoint.
274
         */
275
        public double[] getBasePoint() {
276
                return basePoint;
277
        }
278
        /**
279
         * @param basePoint The basePoint to set.
280
         */
281
        public void setBasePoint(double[] basePoint) {
282
                this.basePoint = basePoint;
283
        }
284
        /**
285
         * @return Returns the firstEntityHandle.
286
         */
287
        public int getFirstEntityHandle() {
288
                return firstEntityHandle;
289
        }
290
        /**
291
         * @param firstEntityHandle The firstEntityHandle to set.
292
         */
293
        public void setFirstEntityHandle(int firstEntityHandle) {
294
                this.firstEntityHandle = firstEntityHandle;
295
        }
296
        /**
297
         * @return Returns the lastEntityHandle.
298
         */
299
        public int getLastEntityHandle() {
300
                return lastEntityHandle;
301
        }
302
        /**
303
         * @param lastEntityHandle The lastEntityHandle to set.
304
         */
305
        public void setLastEntityHandle(int lastEntityHandle) {
306
                this.lastEntityHandle = lastEntityHandle;
307
        }
308
        /**
309
         * @return Returns the name.
310
         */
311
        public String getName() {
312
                return name;
313
        }
314
        /**
315
         * @param name The name to set.
316
         */
317
        public void setName(String name) {
318
                this.name = name;
319
        }
320
        /**
321
         * @return Returns the blockEntityHandle.
322
         */
323
        public int getBlockEntityHandle() {
324
                return blockEntityHandle;
325
        }
326
        /**
327
         * @param blockEntityHandle The blockEntityHandle to set.
328
         */
329
        public void setBlockEntityHandle(int blockEntityHandle) {
330
                this.blockEntityHandle = blockEntityHandle;
331
        }
332
        /**
333
         * @return Returns the anonymous.
334
         */
335
        public boolean isAnonymous() {
336
                return anonymous;
337
        }
338
        /**
339
         * @param anonymous The anonymous to set.
340
         */
341
        public void setAnonymous(boolean anonymous) {
342
                this.anonymous = anonymous;
343
        }
344
        /**
345
         * @return Returns the blkIsXRef.
346
         */
347
        public boolean isBlkIsXRef() {
348
                return blkIsXRef;
349
        }
350
        /**
351
         * @param blkIsXRef The blkIsXRef to set.
352
         */
353
        public void setBlkIsXRef(boolean blkIsXRef) {
354
                this.blkIsXRef = blkIsXRef;
355
        }
356
        /**
357
         * @return Returns the blockControlHandle.
358
         */
359
        public int getBlockControlHandle() {
360
                return blockControlHandle;
361
        }
362
        /**
363
         * @param blockControlHandle The blockControlHandle to set.
364
         */
365
        public void setBlockControlHandle(int blockControlHandle) {
366
                this.blockControlHandle = blockControlHandle;
367
        }
368
        /**
369
         * @return Returns the blockDescription.
370
         */
371
        public String getBlockDescription() {
372
                return blockDescription;
373
        }
374
        /**
375
         * @param blockDescription The blockDescription to set.
376
         */
377
        public void setBlockDescription(String blockDescription) {
378
                this.blockDescription = blockDescription;
379
        }
380
        /**
381
         * @return Returns the endBlkEntityHandle.
382
         */
383
        public int getEndBlkEntityHandle() {
384
                return endBlkEntityHandle;
385
        }
386
        /**
387
         * @param endBlkEntityHandle The endBlkEntityHandle to set.
388
         */
389
        public void setEndBlkEntityHandle(int endBlkEntityHandle) {
390
                this.endBlkEntityHandle = endBlkEntityHandle;
391
        }
392
        /**
393
         * @return Returns the flag64.
394
         */
395
        public boolean isFlag64() {
396
                return flag64;
397
        }
398
        /**
399
         * @param flag64 The flag64 to set.
400
         */
401
        public void setFlag64(boolean flag64) {
402
                this.flag64 = flag64;
403
        }
404
        /**
405
         * @return Returns the hasAttrs.
406
         */
407
        public boolean isHasAttrs() {
408
                return hasAttrs;
409
        }
410
        /**
411
         * @param hasAttrs The hasAttrs to set.
412
         */
413
        public void setHasAttrs(boolean hasAttrs) {
414
                this.hasAttrs = hasAttrs;
415
        }
416
        /**
417
         * @return Returns the insertHandles.
418
         */
419
        public Vector getInsertHandles() {
420
                return insertHandles;
421
        }
422
        /**
423
         * @param insertHandles The insertHandles to set.
424
         */
425
        public void setInsertHandles(Vector insertHandles) {
426
                this.insertHandles = insertHandles;
427
        }
428
        /**
429
         * @return Returns the layoutHandle.
430
         */
431
        public int getLayoutHandle() {
432
                return layoutHandle;
433
        }
434
        /**
435
         * @param layoutHandle The layoutHandle to set.
436
         */
437
        public void setLayoutHandle(int layoutHandle) {
438
                this.layoutHandle = layoutHandle;
439
        }
440
        /**
441
         * @return Returns the loaded.
442
         */
443
        public boolean isLoaded() {
444
                return loaded;
445
        }
446
        /**
447
         * @param loaded The loaded to set.
448
         */
449
        public void setLoaded(boolean loaded) {
450
                this.loaded = loaded;
451
        }
452
        /**
453
         * @return Returns the nullHandle.
454
         */
455
        public int getNullHandle() {
456
                return nullHandle;
457
        }
458
        /**
459
         * @param nullHandle The nullHandle to set.
460
         */
461
        public void setNullHandle(int nullHandle) {
462
                this.nullHandle = nullHandle;
463
        }
464
        /**
465
         * @return Returns the previewData.
466
         */
467
        public int getPreviewData() {
468
                return previewData;
469
        }
470
        /**
471
         * @param previewData The previewData to set.
472
         */
473
        public void setPreviewData(int previewData) {
474
                this.previewData = previewData;
475
        }
476
        /**
477
         * @return Returns the xdep.
478
         */
479
        public boolean isXdep() {
480
                return xdep;
481
        }
482
        /**
483
         * @param xdep The xdep to set.
484
         */
485
        public void setXdep(boolean xdep) {
486
                this.xdep = xdep;
487
        }
488
        /**
489
         * @return Returns the xRefOverLaid.
490
         */
491
        public boolean isXRefOverLaid() {
492
                return xRefOverLaid;
493
        }
494
        /**
495
         * @param refOverLaid The xRefOverLaid to set.
496
         */
497
        public void setXRefOverLaid(boolean refOverLaid) {
498
                xRefOverLaid = refOverLaid;
499
        }
500
        /**
501
         * @return Returns the xRefPlus.
502
         */
503
        public int getXRefPlus() {
504
                return xRefPlus;
505
        }
506
        /**
507
         * @param refPlus The xRefPlus to set.
508
         */
509
        public void setXRefPlus(int refPlus) {
510
                xRefPlus = refPlus;
511
        }
512
        /**
513
         * @return Returns the xRefPName.
514
         */
515
        public String getXRefPName() {
516
                return xRefPName;
517
        }
518
        /**
519
         * @param refPName The xRefPName to set.
520
         */
521
        public void setXRefPName(String refPName) {
522
                xRefPName = refPName;
523
        }
524
        /**
525
         * @return Returns the objects.
526
         */
527
        public Vector getObjects() {
528
                return objects;
529
        }
530
        /**
531
         * @param objects The objects to set.
532
         */
533
        public void setObjects(Vector objects) {
534
                this.objects = objects;
535
        }
536
        /**
537
         * Add a DWG object to the blockObjects vector
538
         * 
539
         * @param object DWG object
540
         */
541
        public void addObject(DwgObject object) {
542
                this.objects.add(object);
543
        }
544
}