Statistics
| Revision:

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

History | View | Annotate | Download (10.7 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;
36

    
37
import java.util.Vector;
38

    
39
/**
40
 * The DwgObject class represents a DWG object
41
 * 
42
 * @author jmorell
43
 */
44
public class DwgObject {
45
        protected int type;
46
        protected int handle;
47
        protected int layerHandleCode;
48
        protected String version;
49
        protected int mode;
50
        protected int layerHandle;
51
        protected int color;
52
        protected int numReactors;
53
        protected boolean noLinks;
54
        protected int linetypeFlags;
55
        protected int plotstyleFlags;
56
        protected int sizeInBits;
57
        protected Vector extendedData;
58
        protected int graphicData;
59
        protected int subEntityHandle;
60
        protected int xDicObjHandle;
61
        protected boolean graphicsFlag;
62
        
63
        /**
64
         * Reads the header of an object in a DWG file Version 15 
65
         * 
66
         * @param data Array of unsigned bytes obtained from the DWG binary file
67
         * @param offset The current bit offset where the value begins
68
         * @return int New offset
69
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
70
         *                    when we are looking for LwPolylines.
71
         */
72
        public int readObjectHeaderV15(int[] data, int offset) throws Exception {
73
                int bitPos = offset;
74
                Integer mode = (Integer)DwgUtil.getBits(data, 2, bitPos);
75
            bitPos = bitPos + 2;
76
            setMode(mode.intValue());
77
            Vector v = DwgUtil.getBitLong(data, bitPos);
78
            bitPos = ((Integer)v.get(0)).intValue();
79
            int rnum = ((Integer)v.get(1)).intValue();
80
            setNumReactors(rnum);
81
            v = DwgUtil.testBit(data, bitPos);
82
            bitPos = ((Integer)v.get(0)).intValue();
83
            boolean nolinks = ((Boolean)v.get(1)).booleanValue();
84
            setNoLinks(nolinks);
85
            v = DwgUtil.getBitShort(data, bitPos);
86
            bitPos = ((Integer)v.get(0)).intValue();
87
            int color = ((Integer)v.get(1)).intValue();
88
            setColor(color);
89
            v = DwgUtil.getBitDouble(data, bitPos);
90
            bitPos = ((Integer)v.get(0)).intValue();
91
            float ltscale = ((Double)v.get(1)).floatValue();
92
            Integer ltflag = (Integer)DwgUtil.getBits(data, 2, bitPos);
93
            bitPos = bitPos + 2;
94
            Integer psflag = (Integer)DwgUtil.getBits(data, 2, bitPos);
95
            bitPos = bitPos + 2;
96
            v = DwgUtil.getBitShort(data, bitPos);
97
            bitPos = ((Integer)v.get(0)).intValue();
98
            int invis = ((Integer)v.get(1)).intValue();
99
            v = DwgUtil.getRawChar(data, bitPos);
100
            bitPos = ((Integer)v.get(0)).intValue();
101
            int weight = ((Integer)v.get(1)).intValue();
102
                return bitPos;
103
        }
104
        
105
        /**
106
         * Reads the tail of an object in a DWG file Version 15 
107
         * 
108
         * @param data Array of bytes obtained from the DWG binary file
109
         * @param offset Offset for this array of bytes
110
         * @return int New offset
111
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
112
         *                    when we are looking for LwPolylines.
113
         */
114
        public int readObjectTailV15(int[] data, int offset) throws Exception {
115
                int bitPos = offset;
116
                Vector v = null;
117
                if (getMode()==0x0) {
118
                        v = DwgUtil.getHandle(data, bitPos);
119
                    bitPos = ((Integer)v.get(0)).intValue();
120
                    int[] sh = new int[v.size()-1];
121
                    for (int i=1;i<v.size();i++) {
122
                            sh[i-1] = ((Integer)v.get(i)).intValue();
123
                    }
124
                    Vector shv = new Vector();
125
                    for (int i=0;i<sh.length;i++) {
126
                            shv.add(new Integer(sh[i]));
127
                    }
128
                    setSubEntityHandle(DwgUtil.handleBinToHandleInt(shv));
129
                }
130
                for (int i=0; i<getNumReactors(); i++) {
131
                        v = DwgUtil.getHandle(data, bitPos);
132
                        bitPos = ((Integer)v.get(0)).intValue();
133
                        int[] handle = new int[v.size()-1];
134
                    for (int j=1;j<v.size();j++) {
135
                            handle[j-1] = ((Integer)v.get(j)).intValue();
136
                    }
137
                }
138
                v = DwgUtil.getHandle(data, bitPos);
139
                bitPos = ((Integer)v.get(0)).intValue();
140
                int[] xh = new int[v.size()-1];
141
            for (int i=1;i<v.size();i++) {
142
                    xh[i-1] = ((Integer)v.get(i)).intValue();
143
            }
144
            Vector xhv = new Vector();
145
            for (int i=0;i<xh.length;i++) {
146
                    xhv.add(new Integer(xh[i]));
147
            }
148
            setXDicObjHandle(DwgUtil.handleBinToHandleInt(xhv));
149
                v = DwgUtil.getHandle(data, bitPos);
150
                bitPos = ((Integer)v.get(0)).intValue();
151
                int[] lh = new int[v.size()-1];
152
            for (int i=1;i<v.size();i++) {
153
                    lh[i-1] = ((Integer)v.get(i)).intValue();
154
            }
155
            setLayerHandleCode(lh[0]);
156
            Vector lhv = new Vector();
157
            for (int i=0;i<lh.length;i++) {
158
                    lhv.add(new Integer(lh[i]));
159
            }
160
            setLayerHandle(DwgUtil.handleBinToHandleInt(lhv));
161
            if (!isNoLinks()) {
162
                        v = DwgUtil.getHandle(data, bitPos);
163
                        bitPos = ((Integer)v.get(0)).intValue();
164
                        int[] prev = new int[v.size()-1];
165
                    for (int i=1;i<v.size();i++) {
166
                            prev[i-1] = ((Integer)v.get(i)).intValue();
167
                    }
168
                    //obj.setPrevious(prev);
169
                        v = DwgUtil.getHandle(data, bitPos);
170
                        bitPos = ((Integer)v.get(0)).intValue();
171
                        int[] next = new int[v.size()-1];
172
                    for (int i=1;i<v.size();i++) {
173
                            next[i-1] = ((Integer)v.get(i)).intValue();
174
                    }
175
                    //obj.setNext(next);
176
            }
177
            if (getLinetypeFlags()==0x3) {
178
                        v = DwgUtil.getHandle(data, bitPos);
179
                        bitPos = ((Integer)v.get(0)).intValue();
180
                        int[] lth = new int[v.size()-1];
181
                    for (int i=1;i<v.size();i++) {
182
                            lth[i-1] = ((Integer)v.get(i)).intValue();
183
                    }
184
                    //obj.setLinetype(lth);
185
            }
186
            if (getPlotstyleFlags()==0x3) {
187
                        v = DwgUtil.getHandle(data, bitPos);
188
                        bitPos = ((Integer)v.get(0)).intValue();
189
                        int[] pth = new int[v.size()-1];
190
                    for (int i=1;i<v.size();i++) {
191
                            pth[i-1] = ((Integer)v.get(i)).intValue();
192
                    }
193
                    //obj.setPlotstyle(pth);
194
            }
195
            return bitPos;
196
        }
197
        
198
        /**
199
         * @return Returns the sizeInBits.
200
         */
201
        public int getSizeInBits() {
202
                return sizeInBits;
203
        }
204
        /**
205
         * @param sizeInBits The sizeInBits to set.
206
         */
207
        public void setSizeInBits(int sizeInBits) {
208
                this.sizeInBits = sizeInBits;
209
        }
210
        /**
211
         * @return Returns the extendedData.
212
         */
213
        public Vector getExtendedData() {
214
                return extendedData;
215
        }
216
        /**
217
         * @param extendedData The extendedData to set.
218
         */
219
        public void setExtendedData(Vector extendedData) {
220
                this.extendedData = extendedData;
221
        }
222
        /**
223
         * @return Returns the graphicData.
224
         */
225
        public int getGraphicData() {
226
                return graphicData;
227
        }
228
        /**
229
         * @param graphicData The graphicData to set.
230
         */
231
        public void setGraphicData(int graphicData) {
232
                this.graphicData = graphicData;
233
        }
234
        /**
235
         * @return Returns the version.
236
         */
237
        public String getVersion() {
238
                return version;
239
        }
240
        /**
241
         * @param linetypeFlags The linetypeFlags to set.
242
         */
243
        public void setLinetypeFlags(int linetypeFlags) {
244
                this.linetypeFlags = linetypeFlags;
245
        }
246
        /**
247
         * @param plotstyleFlags The plotstyleFlags to set.
248
         */
249
        public void setPlotstyleFlags(int plotstyleFlags) {
250
                this.plotstyleFlags = plotstyleFlags;
251
        }
252
        /**
253
         * @return Returns the subEntityHandle.
254
         */
255
        public int getSubEntityHandle() {
256
                return subEntityHandle;
257
        }
258
        /**
259
         * @param subEntityHandle The subEntityHandle to set.
260
         */
261
        public void setSubEntityHandle(int subEntityHandle) {
262
                this.subEntityHandle = subEntityHandle;
263
        }
264
        /**
265
         * @return Returns the xDicObjHandle.
266
         */
267
        public int getXDicObjHandle() {
268
                return xDicObjHandle;
269
        }
270
        /**
271
         * @param dicObjHandle The xDicObjHandle to set.
272
         */
273
        public void setXDicObjHandle(int dicObjHandle) {
274
                xDicObjHandle = dicObjHandle;
275
        }
276
        /**
277
         * @return Returns the layerHandleCode.
278
         */
279
        public int getLayerHandleCode() {
280
                return layerHandleCode;
281
        }
282
        /**
283
         * @param layerHandleCode The layerHandleCode to set.
284
         */
285
        public void setLayerHandleCode(int layerHandleCode) {
286
                this.layerHandleCode = layerHandleCode;
287
        }
288
    /**
289
     * @return Returns the color.
290
     */
291
    public int getColor() {
292
        return color;
293
    }
294
    /**
295
     * @param color The color to set.
296
     */
297
    public void setColor(int color) {
298
        this.color = color;
299
    }
300
    /**
301
     * @return Returns the handle.
302
     */
303
    public int getHandle() {
304
        return handle;
305
    }
306
    /**
307
     * @param handle The handle to set.
308
     */
309
    public void setHandle(int handle) {
310
        this.handle = handle;
311
    }
312
    /**
313
     * @return Returns the layerHandle.
314
     */
315
    public int getLayerHandle() {
316
        return layerHandle;
317
    }
318
    /**
319
     * @param layerHandle The layerHandle to set.
320
     */
321
    public void setLayerHandle(int layerHandle) {
322
        this.layerHandle = layerHandle;
323
    }
324
    /**
325
     * @return Returns the mode.
326
     */
327
    public int getMode() {
328
        return mode;
329
    }
330
    /**
331
     * @param mode The mode to set.
332
     */
333
    public void setMode(int mode) {
334
        this.mode = mode;
335
    }
336
    /**
337
     * @return Returns the noLinks.
338
     */
339
    public boolean isNoLinks() {
340
        return noLinks;
341
    }
342
    /**
343
     * @param noLinks The noLinks to set.
344
     */
345
    public void setNoLinks(boolean noLinks) {
346
        this.noLinks = noLinks;
347
    }
348
    /**
349
     * @return Returns the numReactors.
350
     */
351
    public int getNumReactors() {
352
        return numReactors;
353
    }
354
    /**
355
     * @param numReactors The numReactors to set.
356
     */
357
    public void setNumReactors(int numReactors) {
358
        this.numReactors = numReactors;
359
    }
360
    /**
361
     * @return Returns the type.
362
     */
363
    public int getType() {
364
        return type;
365
    }
366
    /**
367
     * @param type The type to set.
368
     */
369
    public void setType(int type) {
370
        this.type = type;
371
    }
372
    /**
373
     * @return Returns the linetypeFlags.
374
     */
375
    public int getLinetypeFlags() {
376
        return linetypeFlags;
377
    }
378
    /**
379
     * @return Returns the plotstyleFlags.
380
     */
381
    public int getPlotstyleFlags() {
382
        return plotstyleFlags;
383
    }
384
    /**
385
     * @param version The version to set.
386
     */
387
    public void setVersion(String version) {
388
        this.version = version;
389
    }
390
    /**
391
     * @return Returns the graphicsFlag.
392
     */
393
    public boolean isGraphicsFlag() {
394
        return graphicsFlag;
395
    }
396
    /**
397
     * @param graphicsFlag The graphicsFlag to set.
398
     */
399
    public void setGraphicsFlag(boolean graphicsFlag) {
400
        this.graphicsFlag = graphicsFlag;
401
    }
402
}