Statistics
| Revision:

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

History | View | Annotate | Download (9.06 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 DwgInsert class represents a DWG Insert
44
 * 
45
 * @author jmorell
46
 */
47
public class DwgInsert extends DwgObject {
48
        private double[] insertionPoint;
49
        private double[] scale;
50
        private double rotation;
51
        private double[] extrusion;
52
        private int blockHeaderHandle;
53
        private int firstAttribHandle;
54
        private int lastAttribHandle;
55
        private int seqendHandle;
56
        
57
        /**
58
         * Read a Insert in the DWG format Version 15
59
         * 
60
         * @param data Array of unsigned bytes obtained from the DWG binary file
61
         * @param offset The current bit offset where the value begins
62
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
63
         *                    when we are looking for LwPolylines.
64
         */
65
        public void readDwgInsertV15(int[] data, int offset) throws Exception {
66
                //System.out.println("readDwgInsert() executed ...");
67
                int bitPos = offset;
68
                bitPos = readObjectHeaderV15(data, bitPos);
69
                Vector v = DwgUtil.getBitDouble(data, bitPos);
70
                bitPos = ((Integer)v.get(0)).intValue();
71
                double x = ((Double)v.get(1)).doubleValue();
72
                v = DwgUtil.getBitDouble(data, bitPos);
73
                bitPos = ((Integer)v.get(0)).intValue();
74
                double y = ((Double)v.get(1)).doubleValue();
75
                v = DwgUtil.getBitDouble(data, bitPos);
76
                bitPos = ((Integer)v.get(0)).intValue();
77
                double z = ((Double)v.get(1)).doubleValue();
78
                double[] coord = new double[]{x, y, z};
79
                insertionPoint = coord;
80
                int dflag = ((Integer)DwgUtil.getBits(data, 2, bitPos)).intValue();
81
                bitPos = bitPos + 2;
82
                if (dflag==0x0) {
83
                        v = DwgUtil.getRawDouble(data, bitPos);
84
                        bitPos = ((Integer)v.get(0)).intValue();
85
                        x = ((Double)v.get(1)).doubleValue();
86
                        v = DwgUtil.getDefaultDouble(data, bitPos, x);
87
                        bitPos = ((Integer)v.get(0)).intValue();
88
                        y = ((Double)v.get(1)).doubleValue();
89
                        v = DwgUtil.getDefaultDouble(data, bitPos, x);
90
                        bitPos = ((Integer)v.get(0)).intValue();
91
                        z = ((Double)v.get(1)).doubleValue();
92
                } else if (dflag==0x1) {
93
                        x = 1.0;
94
                        v = DwgUtil.getDefaultDouble(data, bitPos, x);
95
                        bitPos = ((Integer)v.get(0)).intValue();
96
                        y = ((Double)v.get(1)).doubleValue();
97
                        v = DwgUtil.getDefaultDouble(data, bitPos, x);
98
                        bitPos = ((Integer)v.get(0)).intValue();
99
                        z = ((Double)v.get(1)).doubleValue();
100
                } else if (dflag==0x2) {
101
                        v = DwgUtil.getRawDouble(data, bitPos);
102
                        bitPos = ((Integer)v.get(0)).intValue();
103
                        x = ((Double)v.get(1)).doubleValue();
104
                        z = x;
105
                        y = z;
106
                } else {
107
                        z = 1.0;
108
                        y = z;
109
                        x = y;
110
                }
111
                coord = new double[]{x, y, z};
112
                scale = coord;
113
                v = DwgUtil.getBitDouble(data, bitPos);
114
                bitPos = ((Integer)v.get(0)).intValue();
115
                double rot = ((Double)v.get(1)).doubleValue();
116
                rotation = rot;
117
                v = DwgUtil.getBitDouble(data, bitPos);
118
                bitPos = ((Integer)v.get(0)).intValue();
119
                x = ((Double)v.get(1)).doubleValue();
120
                v = DwgUtil.getBitDouble(data, bitPos);
121
                bitPos = ((Integer)v.get(0)).intValue();
122
                y = ((Double)v.get(1)).doubleValue();
123
                v = DwgUtil.getBitDouble(data, bitPos);
124
                bitPos = ((Integer)v.get(0)).intValue();
125
                z = ((Double)v.get(1)).doubleValue();
126
                coord = new double[]{x, y, z};
127
                extrusion = coord;
128
                v = DwgUtil.testBit(data, bitPos);
129
                bitPos = ((Integer)v.get(0)).intValue();
130
                boolean hasattr = ((Boolean)v.get(1)).booleanValue();
131
                bitPos = readObjectTailV15(data, bitPos);
132
                v = DwgUtil.getHandle(data, bitPos);
133
                bitPos = ((Integer)v.get(0)).intValue();
134
                int[] handle = new int[v.size()-1];
135
            for (int i=1;i<v.size();i++) {
136
                    handle[i-1] = ((Integer)v.get(i)).intValue();
137
            }
138
            Vector handleVect = new Vector();
139
            for (int i=0;i<handle.length;i++) {
140
                    handleVect.add(new Integer(handle[i]));
141
            }
142
            blockHeaderHandle = DwgUtil.handleBinToHandleInt(handleVect);
143
                if (hasattr) {
144
                        v = DwgUtil.getHandle(data, bitPos);
145
                        bitPos = ((Integer)v.get(0)).intValue();
146
                        handle = new int[v.size()-1];
147
                    for (int i=1;i<v.size();i++) {
148
                            handle[i-1] = ((Integer)v.get(i)).intValue();
149
                    }
150
                    handleVect = new Vector();
151
                    for (int i=0;i<handle.length;i++) {
152
                            handleVect.add(new Integer(handle[i]));
153
                    }
154
                    firstAttribHandle = DwgUtil.handleBinToHandleInt(handleVect);
155
                        v = DwgUtil.getHandle(data, bitPos);
156
                        bitPos = ((Integer)v.get(0)).intValue();
157
                        handle = new int[v.size()-1];
158
                    for (int i=1;i<v.size();i++) {
159
                            handle[i-1] = ((Integer)v.get(i)).intValue();
160
                    }
161
                    handleVect = new Vector();
162
                    for (int i=0;i<handle.length;i++) {
163
                            handleVect.add(new Integer(handle[i]));
164
                    }
165
                    lastAttribHandle = DwgUtil.handleBinToHandleInt(handleVect);
166
                        v = DwgUtil.getHandle(data, bitPos);
167
                        bitPos = ((Integer)v.get(0)).intValue();
168
                        handle = new int[v.size()-1];
169
                    for (int i=1;i<v.size();i++) {
170
                            handle[i-1] = ((Integer)v.get(i)).intValue();
171
                    }
172
                    handleVect = new Vector();
173
                    for (int i=0;i<handle.length;i++) {
174
                            handleVect.add(new Integer(handle[i]));
175
                    }
176
                    seqendHandle = DwgUtil.handleBinToHandleInt(handleVect);
177
                }
178
        }
179
        /**
180
         * @return Returns the blockHeaderHandle.
181
         */
182
        public int getBlockHeaderHandle() {
183
                return blockHeaderHandle;
184
        }
185
        /**
186
         * @param blockHeaderHandle The blockHeaderHandle to set.
187
         */
188
        public void setBlockHeaderHandle(int blockHeaderHandle) {
189
                this.blockHeaderHandle = blockHeaderHandle;
190
        }
191
        /**
192
         * @return Returns the firstAttribHandle.
193
         */
194
        public int getFirstAttribHandle() {
195
                return firstAttribHandle;
196
        }
197
        /**
198
         * @param firstAttribHandle The firstAttribHandle to set.
199
         */
200
        public void setFirstAttribHandle(int firstAttribHandle) {
201
                this.firstAttribHandle = firstAttribHandle;
202
        }
203
        /**
204
         * @return Returns the insertionPoint.
205
         */
206
        public double[] getInsertionPoint() {
207
                return insertionPoint;
208
        }
209
        /**
210
         * @param insertionPoint The insertionPoint to set.
211
         */
212
        public void setInsertionPoint(double[] insertionPoint) {
213
                this.insertionPoint = insertionPoint;
214
        }
215
        /**
216
         * @return Returns the lastAttribHandle.
217
         */
218
        public int getLastAttribHandle() {
219
                return lastAttribHandle;
220
        }
221
        /**
222
         * @param lastAttribHandle The lastAttribHandle to set.
223
         */
224
        public void setLastAttribHandle(int lastAttribHandle) {
225
                this.lastAttribHandle = lastAttribHandle;
226
        }
227
        /**
228
         * @return Returns the rotation.
229
         */
230
        public double getRotation() {
231
                return rotation;
232
        }
233
        /**
234
         * @param rotation The rotation to set.
235
         */
236
        public void setRotation(double rotation) {
237
                this.rotation = rotation;
238
        }
239
        /**
240
         * @return Returns the scale.
241
         */
242
        public double[] getScale() {
243
                return scale;
244
        }
245
        /**
246
         * @param scale The scale to set.
247
         */
248
        public void setScale(double[] scale) {
249
                this.scale = scale;
250
        }
251
        /**
252
         * @return Returns the extrusion.
253
         */
254
        public double[] getExtrusion() {
255
                return extrusion;
256
        }
257
        /**
258
         * @param extrusion The extrusion to set.
259
         */
260
        public void setExtrusion(double[] extrusion) {
261
                this.extrusion = extrusion;
262
        }
263
        /**
264
         * @return Returns the seqendHandle.
265
         */
266
        public int getSeqendHandle() {
267
                return seqendHandle;
268
        }
269
        /**
270
         * @param seqendHandle The seqendHandle to set.
271
         */
272
        public void setSeqendHandle(int seqendHandle) {
273
                this.seqendHandle = seqendHandle;
274
        }
275
        /* (non-Javadoc)
276
         * @see java.lang.Object#clone()
277
         */
278
        public Object clone() {
279
                DwgInsert dwgInsert = new DwgInsert();
280
                dwgInsert.setType(type);
281
                dwgInsert.setHandle(handle);
282
                dwgInsert.setVersion(version);
283
                dwgInsert.setMode(mode);
284
                dwgInsert.setLayerHandle(layerHandle);
285
                dwgInsert.setColor(color);
286
                dwgInsert.setNumReactors(numReactors);
287
                dwgInsert.setNoLinks(noLinks);
288
                dwgInsert.setLinetypeFlags(linetypeFlags);
289
                dwgInsert.setPlotstyleFlags(plotstyleFlags);
290
                dwgInsert.setSizeInBits(sizeInBits);
291
                dwgInsert.setExtendedData(extendedData);
292
                dwgInsert.setGraphicData(graphicData);
293
                //dwgInsert.setInsideBlock(insideBlock);
294
                dwgInsert.setInsertionPoint(insertionPoint);
295
                dwgInsert.setScale(scale);
296
                dwgInsert.setRotation(rotation);
297
                dwgInsert.setExtrusion(extrusion);
298
                dwgInsert.setBlockHeaderHandle(blockHeaderHandle);
299
                dwgInsert.setFirstAttribHandle(firstAttribHandle);
300
                dwgInsert.setLastAttribHandle(lastAttribHandle);
301
                dwgInsert.setSeqendHandle(seqendHandle);
302
                return dwgInsert;
303
        }
304
}