Statistics
| Revision:

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

History | View | Annotate | Download (12.3 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.awt.geom.Point2D;
38
import java.util.Vector;
39

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

    
43
/**
44
 * The DwgAttdef class represents a DWG Attdef
45
 * 
46
 * @author jmorell
47
 */
48
public class DwgAttdef extends DwgObject {
49
        private int dataFlag;
50
        private double elevation;
51
        private Point2D insertionPoint;
52
        private Point2D alignmentPoint;
53
        private double[] extrusion;
54
        private double thickness;
55
        private double obliqueAngle;
56
        private double rotationAngle;
57
        private double height;
58
        private double widthFactor;
59
        private String text;
60
        private int generation;
61
        private int halign;
62
        private int valign;
63
        private String tag;
64
        private int fieldLength;
65
        private int flags;
66
        private String prompt;
67
        private int styleHandle;
68
        
69
        /**
70
         * Read an Attdef in the DWG format Version 15
71
         * 
72
         * @param data Array of unsigned bytes obtained from the DWG binary file
73
         * @param offset The current bit offset where the value begins
74
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
75
         *                    when we are looking for LwPolylines.
76
         */
77
        public void readDwgAttdefV15(int[] data, int offset) throws Exception {
78
                //System.out.println("readDwgAttdef() executed ...");
79
                int bitPos = offset;
80
                bitPos = readObjectHeaderV15(data, bitPos);
81
                Vector v = DwgUtil.getRawChar(data, bitPos);
82
                bitPos = ((Integer)v.get(0)).intValue();
83
                int dflag = ((Integer)v.get(1)).intValue();
84
                dataFlag = dflag;
85
                if ((dflag & 0x1)==0) {
86
                        v = DwgUtil.getRawDouble(data, bitPos);
87
                        bitPos = ((Integer)v.get(0)).intValue();
88
                        double elev = ((Double)v.get(1)).doubleValue();
89
                        elevation = elev;
90
                }
91
                v = DwgUtil.getRawDouble(data, bitPos);
92
                bitPos = ((Integer)v.get(0)).intValue();
93
                double x1 = ((Double)v.get(1)).doubleValue();
94
                v = DwgUtil.getRawDouble(data, bitPos);
95
                bitPos = ((Integer)v.get(0)).intValue();
96
                double y1 = ((Double)v.get(1)).doubleValue();
97
                insertionPoint = new Point2D.Double(x1, y1);
98
                double x=0, y=0, z=0;
99
                if ((dflag & 0x2)==0) {
100
                        v = DwgUtil.getDefaultDouble(data, bitPos, x1);
101
                        bitPos = ((Integer)v.get(0)).intValue();
102
                        x = ((Double)v.get(1)).doubleValue();
103
                        v = DwgUtil.getDefaultDouble(data, bitPos, y1);
104
                        bitPos = ((Integer)v.get(0)).intValue();
105
                        y = ((Double)v.get(1)).doubleValue();
106
                }
107
                alignmentPoint = new Point2D.Double(x, y);
108
                v = DwgUtil.testBit(data, bitPos);
109
                bitPos = ((Integer)v.get(0)).intValue();
110
                boolean flag = ((Boolean)v.get(1)).booleanValue();
111
                if (flag) {
112
                        y = 0.0;
113
                        x = y;
114
                        z = 1.0;
115
                } else {
116
                        v = DwgUtil.getBitDouble(data, bitPos);
117
                        bitPos = ((Integer)v.get(0)).intValue();
118
                        x = ((Double)v.get(1)).doubleValue();
119
                        v = DwgUtil.getBitDouble(data, bitPos);
120
                        bitPos = ((Integer)v.get(0)).intValue();
121
                        y = ((Double)v.get(1)).doubleValue();
122
                        v = DwgUtil.getBitDouble(data, bitPos);
123
                        bitPos = ((Integer)v.get(0)).intValue();
124
                        z = ((Double)v.get(1)).doubleValue();
125
                }
126
                extrusion = new double[]{x, y, z};
127
                v = DwgUtil.testBit(data, bitPos);
128
                bitPos = ((Integer)v.get(0)).intValue();
129
                flag = ((Boolean)v.get(1)).booleanValue();
130
            double th;
131
                if (flag) {
132
                        th=0.0;
133
                } else {
134
                        v = DwgUtil.getBitDouble(data, bitPos);
135
                        bitPos = ((Integer)v.get(0)).intValue();
136
                        th = ((Double)v.get(1)).doubleValue();
137
                }
138
                thickness = th;
139
                if ((dflag & 0x4)==0) {
140
                        v = DwgUtil.getRawDouble(data, bitPos);
141
                        bitPos = ((Integer)v.get(0)).intValue();
142
                        double oblique = ((Double)v.get(1)).doubleValue();
143
                        obliqueAngle = oblique;
144
                }
145
                if ((dflag & 0x8)==0) {
146
                        v = DwgUtil.getRawDouble(data, bitPos);
147
                        bitPos = ((Integer)v.get(0)).intValue();
148
                        double rot = ((Double)v.get(1)).doubleValue();
149
                        rotationAngle = rot;
150
                }
151
                v = DwgUtil.getRawDouble(data, bitPos);
152
                bitPos = ((Integer)v.get(0)).intValue();
153
                double height = ((Double)v.get(1)).doubleValue();
154
                this.height = height;
155
                if ((dflag & 0x10)==0) {
156
                        v = DwgUtil.getRawDouble(data, bitPos);
157
                        bitPos = ((Integer)v.get(0)).intValue();
158
                        double width = ((Double)v.get(1)).doubleValue();
159
                        widthFactor = width;
160
                }
161
                v = DwgUtil.getTextString(data, bitPos);
162
                bitPos = ((Integer)v.get(0)).intValue();
163
                String text = (String)v.get(1);
164
                this.text = text;
165
                if ((dflag & 0x20)==0) {
166
                        v = DwgUtil.getBitShort(data, bitPos);
167
                        bitPos = ((Integer)v.get(0)).intValue();
168
                        int gen = ((Integer)v.get(1)).intValue();
169
                        generation = gen;
170
                }
171
                if ((dflag & 0x40)==0) {
172
                        v = DwgUtil.getBitShort(data, bitPos);
173
                        bitPos = ((Integer)v.get(0)).intValue();
174
                        int halign = ((Integer)v.get(1)).intValue();
175
                        this.halign = halign;
176
                }
177
                if ((dflag & 0x80)==0) {
178
                        v = DwgUtil.getBitShort(data, bitPos);
179
                        bitPos = ((Integer)v.get(0)).intValue();
180
                        int valign = ((Integer)v.get(1)).intValue();
181
                        this.valign = valign;
182
                }
183
                v = DwgUtil.getTextString(data, bitPos);
184
                bitPos = ((Integer)v.get(0)).intValue();
185
                String tag = (String)v.get(1);
186
                this.tag = tag;
187
                v = DwgUtil.getBitShort(data, bitPos);
188
                bitPos = ((Integer)v.get(0)).intValue();
189
                int fl = ((Integer)v.get(1)).intValue();
190
                fieldLength = fl;
191
                v = DwgUtil.getRawChar(data, bitPos);
192
                bitPos = ((Integer)v.get(0)).intValue();
193
                int flags = ((Integer)v.get(1)).intValue();
194
                this.flags = flags;
195
                v = DwgUtil.getTextString(data, bitPos);
196
                bitPos = ((Integer)v.get(0)).intValue();
197
                String prompt = (String)v.get(1);
198
                this.prompt = prompt;
199
                bitPos = readObjectTailV15(data, bitPos);
200
                v = DwgUtil.getHandle(data, bitPos);
201
                bitPos = ((Integer)v.get(0)).intValue();
202
                int[] handle = new int[v.size()-1];
203
            for (int j=1;j<v.size();j++) {
204
                    handle[j-1] = ((Integer)v.get(j)).intValue();
205
            }
206
            Vector handleVect = new Vector();
207
            for (int i=0;i<handle.length;i++) {
208
                    handleVect.add(new Integer(handle[i]));
209
            }
210
            styleHandle = DwgUtil.handleBinToHandleInt(handleVect);
211
        }
212
        /* (non-Javadoc)
213
         * @see java.lang.Object#clone()
214
         */
215
        public Object clone() {
216
                DwgAttdef dwgAttdef = new DwgAttdef();
217
                dwgAttdef.setType(type);
218
                dwgAttdef.setHandle(handle);
219
                dwgAttdef.setVersion(version);
220
                dwgAttdef.setMode(mode);
221
                dwgAttdef.setLayerHandle(layerHandle);
222
                dwgAttdef.setColor(color);
223
                dwgAttdef.setNumReactors(numReactors);
224
                dwgAttdef.setNoLinks(noLinks);
225
                dwgAttdef.setLinetypeFlags(linetypeFlags);
226
                dwgAttdef.setPlotstyleFlags(plotstyleFlags);
227
                dwgAttdef.setSizeInBits(sizeInBits);
228
                dwgAttdef.setExtendedData(extendedData);
229
                dwgAttdef.setGraphicData(graphicData);
230
                //dwgAttdef.setInsideBlock(insideBlock);
231
                dwgAttdef.setDataFlag(dataFlag);
232
                dwgAttdef.setElevation(elevation);
233
                dwgAttdef.setInsertionPoint(insertionPoint);
234
                dwgAttdef.setAlignmentPoint(alignmentPoint);
235
                dwgAttdef.setExtrusion(extrusion);
236
                dwgAttdef.setThickness(thickness);
237
                dwgAttdef.setObliqueAngle(obliqueAngle);
238
                dwgAttdef.setRotationAngle(rotationAngle);
239
                dwgAttdef.setHeight(height);
240
                dwgAttdef.setWidthFactor(widthFactor);
241
                dwgAttdef.setText(text);
242
                dwgAttdef.setGeneration(generation);
243
                dwgAttdef.setHalign(halign);
244
                dwgAttdef.setValign(valign);
245
                dwgAttdef.setTag(tag);
246
                dwgAttdef.setFieldLength(fieldLength);
247
                dwgAttdef.setFlags(flags);
248
                dwgAttdef.setPrompt(prompt);
249
                dwgAttdef.setStyleHandle(styleHandle);
250
                return dwgAttdef;
251
        }
252
        /**
253
         * @return Returns the alignmentPoint.
254
         */
255
        public Point2D getAlignmentPoint() {
256
                return alignmentPoint;
257
        }
258
        /**
259
         * @param alignmentPoint The alignmentPoint to set.
260
         */
261
        public void setAlignmentPoint(Point2D alignmentPoint) {
262
                this.alignmentPoint = alignmentPoint;
263
        }
264
        /**
265
         * @return Returns the dataFlag.
266
         */
267
        public int getDataFlag() {
268
                return dataFlag;
269
        }
270
        /**
271
         * @param dataFlag The dataFlag to set.
272
         */
273
        public void setDataFlag(int dataFlag) {
274
                this.dataFlag = dataFlag;
275
        }
276
        /**
277
         * @return Returns the elevation.
278
         */
279
        public double getElevation() {
280
                return elevation;
281
        }
282
        /**
283
         * @param elevation The elevation to set.
284
         */
285
        public void setElevation(double elevation) {
286
                this.elevation = elevation;
287
        }
288
        /**
289
         * @return Returns the extrusion.
290
         */
291
        public double[] getExtrusion() {
292
                return extrusion;
293
        }
294
        /**
295
         * @param extrusion The extrusion to set.
296
         */
297
        public void setExtrusion(double[] extrusion) {
298
                this.extrusion = extrusion;
299
        }
300
        /**
301
         * @return Returns the fieldLength.
302
         */
303
        public int getFieldLength() {
304
                return fieldLength;
305
        }
306
        /**
307
         * @param fieldLength The fieldLength to set.
308
         */
309
        public void setFieldLength(int fieldLength) {
310
                this.fieldLength = fieldLength;
311
        }
312
        /**
313
         * @return Returns the flags.
314
         */
315
        public int getFlags() {
316
                return flags;
317
        }
318
        /**
319
         * @param flags The flags to set.
320
         */
321
        public void setFlags(int flags) {
322
                this.flags = flags;
323
        }
324
        /**
325
         * @return Returns the generation.
326
         */
327
        public int getGeneration() {
328
                return generation;
329
        }
330
        /**
331
         * @param generation The generation to set.
332
         */
333
        public void setGeneration(int generation) {
334
                this.generation = generation;
335
        }
336
        /**
337
         * @return Returns the halign.
338
         */
339
        public int getHalign() {
340
                return halign;
341
        }
342
        /**
343
         * @param halign The halign to set.
344
         */
345
        public void setHalign(int halign) {
346
                this.halign = halign;
347
        }
348
        /**
349
         * @return Returns the height.
350
         */
351
        public double getHeight() {
352
                return height;
353
        }
354
        /**
355
         * @param height The height to set.
356
         */
357
        public void setHeight(double height) {
358
                this.height = height;
359
        }
360
        /**
361
         * @return Returns the insertionPoint.
362
         */
363
        public Point2D getInsertionPoint() {
364
                return insertionPoint;
365
        }
366
        /**
367
         * @param insertionPoint The insertionPoint to set.
368
         */
369
        public void setInsertionPoint(Point2D insertionPoint) {
370
                this.insertionPoint = insertionPoint;
371
        }
372
        /**
373
         * @return Returns the obliqueAngle.
374
         */
375
        public double getObliqueAngle() {
376
                return obliqueAngle;
377
        }
378
        /**
379
         * @param obliqueAngle The obliqueAngle to set.
380
         */
381
        public void setObliqueAngle(double obliqueAngle) {
382
                this.obliqueAngle = obliqueAngle;
383
        }
384
        /**
385
         * @return Returns the prompt.
386
         */
387
        public String getPrompt() {
388
                return prompt;
389
        }
390
        /**
391
         * @param prompt The prompt to set.
392
         */
393
        public void setPrompt(String prompt) {
394
                this.prompt = prompt;
395
        }
396
        /**
397
         * @return Returns the rotationAngle.
398
         */
399
        public double getRotationAngle() {
400
                return rotationAngle;
401
        }
402
        /**
403
         * @param rotationAngle The rotationAngle to set.
404
         */
405
        public void setRotationAngle(double rotationAngle) {
406
                this.rotationAngle = rotationAngle;
407
        }
408
        /**
409
         * @return Returns the styleHandle.
410
         */
411
        public int getStyleHandle() {
412
                return styleHandle;
413
        }
414
        /**
415
         * @param styleHandle The styleHandle to set.
416
         */
417
        public void setStyleHandle(int styleHandle) {
418
                this.styleHandle = styleHandle;
419
        }
420
        /**
421
         * @return Returns the tag.
422
         */
423
        public String getTag() {
424
                return tag;
425
        }
426
        /**
427
         * @param tag The tag to set.
428
         */
429
        public void setTag(String tag) {
430
                this.tag = tag;
431
        }
432
        /**
433
         * @return Returns the text.
434
         */
435
        public String getText() {
436
                return text;
437
        }
438
        /**
439
         * @param text The text to set.
440
         */
441
        public void setText(String text) {
442
                this.text = text;
443
        }
444
        /**
445
         * @return Returns the thickness.
446
         */
447
        public double getThickness() {
448
                return thickness;
449
        }
450
        /**
451
         * @param thickness The thickness to set.
452
         */
453
        public void setThickness(double thickness) {
454
                this.thickness = thickness;
455
        }
456
        /**
457
         * @return Returns the valign.
458
         */
459
        public int getValign() {
460
                return valign;
461
        }
462
        /**
463
         * @param valign The valign to set.
464
         */
465
        public void setValign(int valign) {
466
                this.valign = valign;
467
        }
468
        /**
469
         * @return Returns the widthFactor.
470
         */
471
        public double getWidthFactor() {
472
                return widthFactor;
473
        }
474
        /**
475
         * @param widthFactor The widthFactor to set.
476
         */
477
        public void setWidthFactor(double widthFactor) {
478
                this.widthFactor = widthFactor;
479
        }
480
}