Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgLinearDimension.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.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 DwgLinearDimension class represents a DWG Linear dimension
45
 * 
46
 * @author jmorell
47
 */
48
public class DwgLinearDimension extends DwgObject {
49
        private double[] extrusion;
50
        private Point2D textMidpoint;
51
        private double elevation;
52
        private int flags;
53
        private String text;
54
        private double rotation;
55
        private double horizDir;
56
        private double[] insScale;
57
        private double insRotation;
58
        private int attachmentPoint;
59
        private int linespaceStyle;
60
        private double linespaceFactor;
61
        private double actualMeasurement;
62
        private Point2D pt12;
63
        private double[] pt10;
64
        private double[] pt13;
65
        private double[] pt14;
66
        private double extRotation;
67
        private double dimensionRotation;
68
        private int dimstyleHandle;
69
        private int anonBlockHandle;
70
        
71
        /**
72
         * Read a Linear dimension in the DWG format Version 15
73
         * 
74
         * @param data Array of unsigned bytes obtained from the DWG binary file
75
         * @param offset The current bit offset where the value begins
76
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
77
         *                    when we are looking for LwPolylines.
78
         */
79
        public void readDwgLinearDimensionV15(int[] data, int offset) throws Exception {
80
                int bitPos = offset;
81
                bitPos = readObjectHeaderV15(data, bitPos);
82
                Vector v = DwgUtil.getBitDouble(data, bitPos);
83
                bitPos = ((Integer)v.get(0)).intValue();
84
                double x = ((Double)v.get(1)).doubleValue();
85
                v = DwgUtil.getBitDouble(data, bitPos);
86
                bitPos = ((Integer)v.get(0)).intValue();
87
                double y = ((Double)v.get(1)).doubleValue();
88
                v = DwgUtil.getBitDouble(data, bitPos);
89
                bitPos = ((Integer)v.get(0)).intValue();
90
                double z = ((Double)v.get(1)).doubleValue();
91
                extrusion = new double[]{x, y, z};
92
                v = DwgUtil.getRawDouble(data, bitPos);
93
                bitPos = ((Integer)v.get(0)).intValue();
94
                x = ((Double)v.get(1)).doubleValue();
95
                v = DwgUtil.getRawDouble(data, bitPos);
96
                bitPos = ((Integer)v.get(0)).intValue();
97
                y = ((Double)v.get(1)).doubleValue();
98
                textMidpoint = new Point2D.Double(x, y);
99
                v = DwgUtil.getBitDouble(data, bitPos);
100
                bitPos = ((Integer)v.get(0)).intValue();
101
                double val = ((Double)v.get(1)).doubleValue();
102
                elevation = val;
103
                v = DwgUtil.getRawChar(data, bitPos);
104
                bitPos = ((Integer)v.get(0)).intValue();
105
                int flags = ((Integer)v.get(1)).intValue();
106
                this.flags = flags;
107
                v = DwgUtil.getTextString(data, bitPos);
108
                bitPos = ((Integer)v.get(0)).intValue();
109
                String text = (String)v.get(1);
110
                this.text = text;
111
                v = DwgUtil.getBitDouble(data, bitPos);
112
                bitPos = ((Integer)v.get(0)).intValue();
113
                val = ((Double)v.get(1)).doubleValue();
114
                rotation = val;
115
                v = DwgUtil.getBitDouble(data, bitPos);
116
                bitPos = ((Integer)v.get(0)).intValue();
117
                val = ((Double)v.get(1)).doubleValue();
118
                horizDir = val;
119
                v = DwgUtil.getBitDouble(data, bitPos);
120
                bitPos = ((Integer)v.get(0)).intValue();
121
                x = ((Double)v.get(1)).doubleValue();
122
                v = DwgUtil.getBitDouble(data, bitPos);
123
                bitPos = ((Integer)v.get(0)).intValue();
124
                y = ((Double)v.get(1)).doubleValue();
125
                v = DwgUtil.getBitDouble(data, bitPos);
126
                bitPos = ((Integer)v.get(0)).intValue();
127
                z = ((Double)v.get(1)).doubleValue();
128
                insScale = new double[]{x, y, z};
129
                v = DwgUtil.getBitDouble(data, bitPos);
130
                bitPos = ((Integer)v.get(0)).intValue();
131
                val = ((Double)v.get(1)).doubleValue();
132
                insRotation = val;
133
                v = DwgUtil.getBitShort(data, bitPos);
134
                bitPos = ((Integer)v.get(0)).intValue();
135
                int ap = ((Integer)v.get(1)).intValue();
136
                attachmentPoint = ap;
137
                v = DwgUtil.getBitShort(data, bitPos);
138
                bitPos = ((Integer)v.get(0)).intValue();
139
                int lss = ((Integer)v.get(1)).intValue();
140
                linespaceStyle = lss;
141
                v = DwgUtil.getBitDouble(data, bitPos);
142
                bitPos = ((Integer)v.get(0)).intValue();
143
                val = ((Double)v.get(1)).doubleValue();
144
                linespaceFactor = val;
145
                v = DwgUtil.getBitDouble(data, bitPos);
146
                bitPos = ((Integer)v.get(0)).intValue();
147
                val = ((Double)v.get(1)).doubleValue();
148
                actualMeasurement = val;
149
                v = DwgUtil.getRawDouble(data, bitPos);
150
                bitPos = ((Integer)v.get(0)).intValue();
151
                x = ((Double)v.get(1)).doubleValue();
152
                v = DwgUtil.getRawDouble(data, bitPos);
153
                bitPos = ((Integer)v.get(0)).intValue();
154
                val = ((Double)v.get(1)).doubleValue();
155
                pt12 = new Point2D.Double(x, y);
156
                v = DwgUtil.getBitDouble(data, bitPos);
157
                bitPos = ((Integer)v.get(0)).intValue();
158
                x = ((Double)v.get(1)).doubleValue();
159
                v = DwgUtil.getBitDouble(data, bitPos);
160
                bitPos = ((Integer)v.get(0)).intValue();
161
                y = ((Double)v.get(1)).doubleValue();
162
                v = DwgUtil.getBitDouble(data, bitPos);
163
                bitPos = ((Integer)v.get(0)).intValue();
164
                z = ((Double)v.get(1)).doubleValue();
165
                pt10 = new double[]{x, y, z};
166
                v = DwgUtil.getBitDouble(data, bitPos);
167
                bitPos = ((Integer)v.get(0)).intValue();
168
                x = ((Double)v.get(1)).doubleValue();
169
                v = DwgUtil.getBitDouble(data, bitPos);
170
                bitPos = ((Integer)v.get(0)).intValue();
171
                y = ((Double)v.get(1)).doubleValue();
172
                v = DwgUtil.getBitDouble(data, bitPos);
173
                bitPos = ((Integer)v.get(0)).intValue();
174
                z = ((Double)v.get(1)).doubleValue();
175
                pt13 = new double[]{x, y, z};
176
                v = DwgUtil.getBitDouble(data, bitPos);
177
                bitPos = ((Integer)v.get(0)).intValue();
178
                x = ((Double)v.get(1)).doubleValue();
179
                v = DwgUtil.getBitDouble(data, bitPos);
180
                bitPos = ((Integer)v.get(0)).intValue();
181
                y = ((Double)v.get(1)).doubleValue();
182
                v = DwgUtil.getBitDouble(data, bitPos);
183
                bitPos = ((Integer)v.get(0)).intValue();
184
                z = ((Double)v.get(1)).doubleValue();
185
                pt14 = new double[]{x, y, z};
186
                v = DwgUtil.getBitDouble(data, bitPos);
187
                bitPos = ((Integer)v.get(0)).intValue();
188
                val = ((Double)v.get(1)).doubleValue();
189
                extRotation = val;
190
                v = DwgUtil.getBitDouble(data, bitPos);
191
                bitPos = ((Integer)v.get(0)).intValue();
192
                val = ((Double)v.get(1)).doubleValue();
193
                dimensionRotation = val;
194
                bitPos = readObjectTailV15(data, bitPos);
195
                v = DwgUtil.getHandle(data, bitPos);
196
                bitPos = ((Integer)v.get(0)).intValue();
197
                int[] handle = new int[v.size()-1];
198
            for (int i=1;i<v.size();i++) {
199
                    handle[i-1] = ((Integer)v.get(i)).intValue();
200
            }
201
            Vector handleVect = new Vector();
202
            for (int i=0;i<handle.length;i++) {
203
                    handleVect.add(new Integer(handle[i]));
204
            }
205
            dimstyleHandle = DwgUtil.handleBinToHandleInt(handleVect);
206
                v = DwgUtil.getHandle(data, bitPos);
207
                bitPos = ((Integer)v.get(0)).intValue();
208
                handle = new int[v.size()-1];
209
            for (int i=1;i<v.size();i++) {
210
                    handle[i-1] = ((Integer)v.get(i)).intValue();
211
            }
212
            handleVect = new Vector();
213
            for (int i=0;i<handle.length;i++) {
214
                    handleVect.add(new Integer(handle[i]));
215
            }
216
            anonBlockHandle = DwgUtil.handleBinToHandleInt(handleVect);
217
        }
218
    /**
219
     * @return Returns the elevation.
220
     */
221
    public double getElevation() {
222
        return elevation;
223
    }
224
    /**
225
     * @param elevation The elevation to set.
226
     */
227
    public void setElevation(double elevation) {
228
        this.elevation = elevation;
229
    }
230
        /* (non-Javadoc)
231
         * @see java.lang.Object#clone()
232
         */
233
        public Object clone() {
234
                DwgLinearDimension dwgLinearDimension = new DwgLinearDimension();
235
                dwgLinearDimension.setType(type);
236
                dwgLinearDimension.setHandle(handle);
237
                dwgLinearDimension.setVersion(version);
238
                dwgLinearDimension.setMode(mode);
239
                dwgLinearDimension.setLayerHandle(layerHandle);
240
                dwgLinearDimension.setColor(color);
241
                dwgLinearDimension.setNumReactors(numReactors);
242
                dwgLinearDimension.setNoLinks(noLinks);
243
                dwgLinearDimension.setLinetypeFlags(linetypeFlags);
244
                dwgLinearDimension.setPlotstyleFlags(plotstyleFlags);
245
                dwgLinearDimension.setSizeInBits(sizeInBits);
246
                dwgLinearDimension.setExtendedData(extendedData);
247
                dwgLinearDimension.setGraphicData(graphicData);
248
                //dwgLinearDimension.setInsideBlock(insideBlock);
249
                dwgLinearDimension.setTextMidpoint(textMidpoint);
250
                dwgLinearDimension.setElevation(elevation);
251
                dwgLinearDimension.setFlags(flags);
252
                dwgLinearDimension.setText(text);
253
                dwgLinearDimension.setRotation(rotation);
254
                dwgLinearDimension.setHorizDir(horizDir);
255
                dwgLinearDimension.setInsScale(insScale);
256
                dwgLinearDimension.setInsRotation(insRotation);
257
                dwgLinearDimension.setAttachmentPoint(attachmentPoint);
258
                dwgLinearDimension.setLinespaceStyle(linespaceStyle);
259
                dwgLinearDimension.setLinespaceFactor(linespaceFactor);
260
                dwgLinearDimension.setActualMeasurement(actualMeasurement);
261
                dwgLinearDimension.setPt12(pt12);
262
                dwgLinearDimension.setPt10(pt10);
263
                dwgLinearDimension.setPt13(pt13);
264
                dwgLinearDimension.setPt14(pt14);
265
                dwgLinearDimension.setExtRotation(extRotation);
266
                dwgLinearDimension.setDimensionRotation(dimensionRotation);
267
                dwgLinearDimension.setDimstyleHandle(dimstyleHandle);
268
                dwgLinearDimension.setAnonBlockHandle(anonBlockHandle);
269
                return dwgLinearDimension;
270
        }
271
        /**
272
         * @return Returns the actualMeasurement.
273
         */
274
        public double getActualMeasurement() {
275
                return actualMeasurement;
276
        }
277
        /**
278
         * @param actualMeasurement The actualMeasurement to set.
279
         */
280
        public void setActualMeasurement(double actualMeasurement) {
281
                this.actualMeasurement = actualMeasurement;
282
        }
283
        /**
284
         * @return Returns the anonBlockHandle.
285
         */
286
        public int getAnonBlockHandle() {
287
                return anonBlockHandle;
288
        }
289
        /**
290
         * @param anonBlockHandle The anonBlockHandle to set.
291
         */
292
        public void setAnonBlockHandle(int anonBlockHandle) {
293
                this.anonBlockHandle = anonBlockHandle;
294
        }
295
        /**
296
         * @return Returns the attachmentPoint.
297
         */
298
        public int getAttachmentPoint() {
299
                return attachmentPoint;
300
        }
301
        /**
302
         * @param attachmentPoint The attachmentPoint to set.
303
         */
304
        public void setAttachmentPoint(int attachmentPoint) {
305
                this.attachmentPoint = attachmentPoint;
306
        }
307
        /**
308
         * @return Returns the dimensionRotation.
309
         */
310
        public double getDimensionRotation() {
311
                return dimensionRotation;
312
        }
313
        /**
314
         * @param dimensionRotation The dimensionRotation to set.
315
         */
316
        public void setDimensionRotation(double dimensionRotation) {
317
                this.dimensionRotation = dimensionRotation;
318
        }
319
        /**
320
         * @return Returns the dimstyleHandle.
321
         */
322
        public int getDimstyleHandle() {
323
                return dimstyleHandle;
324
        }
325
        /**
326
         * @param dimstyleHandle The dimstyleHandle to set.
327
         */
328
        public void setDimstyleHandle(int dimstyleHandle) {
329
                this.dimstyleHandle = dimstyleHandle;
330
        }
331
        /**
332
         * @return Returns the extRotation.
333
         */
334
        public double getExtRotation() {
335
                return extRotation;
336
        }
337
        /**
338
         * @param extRotation The extRotation to set.
339
         */
340
        public void setExtRotation(double extRotation) {
341
                this.extRotation = extRotation;
342
        }
343
        /**
344
         * @return Returns the extrusion.
345
         */
346
        public double[] getExtrusion() {
347
                return extrusion;
348
        }
349
        /**
350
         * @param extrusion The extrusion to set.
351
         */
352
        public void setExtrusion(double[] extrusion) {
353
                this.extrusion = extrusion;
354
        }
355
        /**
356
         * @return Returns the flags.
357
         */
358
        public int getFlags() {
359
                return flags;
360
        }
361
        /**
362
         * @param flags The flags to set.
363
         */
364
        public void setFlags(int flags) {
365
                this.flags = flags;
366
        }
367
        /**
368
         * @return Returns the horizDir.
369
         */
370
        public double getHorizDir() {
371
                return horizDir;
372
        }
373
        /**
374
         * @param horizDir The horizDir to set.
375
         */
376
        public void setHorizDir(double horizDir) {
377
                this.horizDir = horizDir;
378
        }
379
        /**
380
         * @return Returns the insRotation.
381
         */
382
        public double getInsRotation() {
383
                return insRotation;
384
        }
385
        /**
386
         * @param insRotation The insRotation to set.
387
         */
388
        public void setInsRotation(double insRotation) {
389
                this.insRotation = insRotation;
390
        }
391
        /**
392
         * @return Returns the insScale.
393
         */
394
        public double[] getInsScale() {
395
                return insScale;
396
        }
397
        /**
398
         * @param insScale The insScale to set.
399
         */
400
        public void setInsScale(double[] insScale) {
401
                this.insScale = insScale;
402
        }
403
        /**
404
         * @return Returns the linespaceFactor.
405
         */
406
        public double getLinespaceFactor() {
407
                return linespaceFactor;
408
        }
409
        /**
410
         * @param linespaceFactor The linespaceFactor to set.
411
         */
412
        public void setLinespaceFactor(double linespaceFactor) {
413
                this.linespaceFactor = linespaceFactor;
414
        }
415
        /**
416
         * @return Returns the linespaceStyle.
417
         */
418
        public int getLinespaceStyle() {
419
                return linespaceStyle;
420
        }
421
        /**
422
         * @param linespaceStyle The linespaceStyle to set.
423
         */
424
        public void setLinespaceStyle(int linespaceStyle) {
425
                this.linespaceStyle = linespaceStyle;
426
        }
427
        /**
428
         * @return Returns the pt10.
429
         */
430
        public double[] getPt10() {
431
                return pt10;
432
        }
433
        /**
434
         * @param pt10 The pt10 to set.
435
         */
436
        public void setPt10(double[] pt10) {
437
                this.pt10 = pt10;
438
        }
439
        /**
440
         * @return Returns the pt12.
441
         */
442
        public Point2D getPt12() {
443
                return pt12;
444
        }
445
        /**
446
         * @param pt12 The pt12 to set.
447
         */
448
        public void setPt12(Point2D pt12) {
449
                this.pt12 = pt12;
450
        }
451
        /**
452
         * @return Returns the pt13.
453
         */
454
        public double[] getPt13() {
455
                return pt13;
456
        }
457
        /**
458
         * @param pt13 The pt13 to set.
459
         */
460
        public void setPt13(double[] pt13) {
461
                this.pt13 = pt13;
462
        }
463
        /**
464
         * @return Returns the pt14.
465
         */
466
        public double[] getPt14() {
467
                return pt14;
468
        }
469
        /**
470
         * @param pt14 The pt14 to set.
471
         */
472
        public void setPt14(double[] pt14) {
473
                this.pt14 = pt14;
474
        }
475
        /**
476
         * @return Returns the rotation.
477
         */
478
        public double getRotation() {
479
                return rotation;
480
        }
481
        /**
482
         * @param rotation The rotation to set.
483
         */
484
        public void setRotation(double rotation) {
485
                this.rotation = rotation;
486
        }
487
        /**
488
         * @return Returns the text.
489
         */
490
        public String getText() {
491
                return text;
492
        }
493
        /**
494
         * @param text The text to set.
495
         */
496
        public void setText(String text) {
497
                this.text = text;
498
        }
499
        /**
500
         * @return Returns the textMidpoint.
501
         */
502
        public Point2D getTextMidpoint() {
503
                return textMidpoint;
504
        }
505
        /**
506
         * @param textMidpoint The textMidpoint to set.
507
         */
508
        public void setTextMidpoint(Point2D textMidpoint) {
509
                this.textMidpoint = textMidpoint;
510
        }
511
}