Statistics
| Revision:

svn-gvsig-desktop / tags / v1_0_2_Build_898 / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgArc.java @ 10513

History | View | Annotate | Download (6.03 KB)

1 2896 jmorell
/* 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 8765 jjdelcerro
import java.util.ArrayList;
38 2896 jmorell
39
import com.iver.cit.jdwglib.dwg.DwgObject;
40
import com.iver.cit.jdwglib.dwg.DwgUtil;
41
42
/**
43
 * The DwgArc class represents a DWG Arc
44
 *
45
 * @author jmorell
46
 */
47
public class DwgArc extends DwgObject {
48
        private double[] center;
49
        private double radius;
50
        private double thickness;
51
        private double[] extrusion;
52
        private double initAngle;
53
        private double endAngle;
54
55
        /**
56
         * Read an Arc in the DWG format Version 15
57
         *
58
         * @param data Array of unsigned bytes obtained from the DWG binary file
59
         * @param offset The current bit offset where the value begins
60
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
61
         *                    when we are looking for LwPolylines.
62
         */
63
        public void readDwgArcV15(int[] data, int offset) throws Exception {
64
                //System.out.println("readDwgArc() executed ...");
65
                int bitPos = offset;
66
                bitPos = readObjectHeaderV15(data, bitPos);
67 8765 jjdelcerro
                ArrayList v = DwgUtil.getBitDouble(data, bitPos);
68 2896 jmorell
                bitPos = ((Integer)v.get(0)).intValue();
69
                double x = ((Double)v.get(1)).doubleValue();
70
                v = DwgUtil.getBitDouble(data, bitPos);
71
                bitPos = ((Integer)v.get(0)).intValue();
72
                double y = ((Double)v.get(1)).doubleValue();
73
                v = DwgUtil.getBitDouble(data, bitPos);
74
                bitPos = ((Integer)v.get(0)).intValue();
75
                double z = ((Double)v.get(1)).doubleValue();
76
                double[] coord = new double[]{x, y, z};
77
                center = coord;
78
                v = DwgUtil.getBitDouble(data, bitPos);
79
                bitPos = ((Integer)v.get(0)).intValue();
80
                double val = ((Double)v.get(1)).doubleValue();
81
                radius = val;
82
                v = DwgUtil.testBit(data, bitPos);
83
                bitPos = ((Integer)v.get(0)).intValue();
84
                boolean flag = ((Boolean)v.get(1)).booleanValue();
85
                if (flag) {
86
                        val=0.0;
87
                } else {
88
                        v = DwgUtil.getBitDouble(data, bitPos);
89
                        bitPos = ((Integer)v.get(0)).intValue();
90
                        val = ((Double)v.get(1)).doubleValue();
91
                }
92
            thickness = val;
93
                v = DwgUtil.testBit(data, bitPos);
94
                bitPos = ((Integer)v.get(0)).intValue();
95
                flag = ((Boolean)v.get(1)).booleanValue();
96
                if (flag) {
97
                         x = y = 0.0;
98
                         z = 1.0;
99
                } else {
100
                        v = DwgUtil.getBitDouble(data, bitPos);
101
                        bitPos = ((Integer)v.get(0)).intValue();
102
                        x = ((Double)v.get(1)).doubleValue();
103
                        v = DwgUtil.getBitDouble(data, bitPos);
104
                        bitPos = ((Integer)v.get(0)).intValue();
105
                        y = ((Double)v.get(1)).doubleValue();
106
                        v = DwgUtil.getBitDouble(data, bitPos);
107
                        bitPos = ((Integer)v.get(0)).intValue();
108
                        z = ((Double)v.get(1)).doubleValue();
109
                }
110
                coord = new double[]{x, y, z};
111
                extrusion = coord;
112
                v = DwgUtil.getBitDouble(data, bitPos);
113
                bitPos = ((Integer)v.get(0)).intValue();
114
                val = ((Double)v.get(1)).doubleValue();
115
            initAngle = val;
116
                v = DwgUtil.getBitDouble(data, bitPos);
117
                bitPos = ((Integer)v.get(0)).intValue();
118
                val = ((Double)v.get(1)).doubleValue();
119
            endAngle = val;
120
                bitPos = readObjectTailV15(data, bitPos);
121
        }
122
        /**
123
         * @return Returns the center.
124
         */
125
        public double[] getCenter() {
126
                return center;
127
        }
128
        /**
129
         * @param center The center to set.
130
         */
131
        public void setCenter(double[] center) {
132
                this.center = center;
133
        }
134
        /**
135
         * @return Returns the endAngle.
136
         */
137
        public double getEndAngle() {
138
                return endAngle;
139
        }
140
        /**
141
         * @param endAngle The endAngle to set.
142
         */
143
        public void setEndAngle(double endAngle) {
144
                this.endAngle = endAngle;
145
        }
146
        /**
147
         * @return Returns the initAngle.
148
         */
149
        public double getInitAngle() {
150
                return initAngle;
151
        }
152
        /**
153
         * @param initAngle The initAngle to set.
154
         */
155
        public void setInitAngle(double initAngle) {
156
                this.initAngle = initAngle;
157
        }
158
        /**
159
         * @return Returns the radius.
160
         */
161
        public double getRadius() {
162
                return radius;
163
        }
164
        /**
165
         * @param radius The radius to set.
166
         */
167
        public void setRadius(double radius) {
168
                this.radius = radius;
169
        }
170
    /**
171
     * @return Returns the extrusion.
172
     */
173
    public double[] getExtrusion() {
174
        return extrusion;
175
    }
176
177
        /* (non-Javadoc)
178
         * @see java.lang.Object#clone()
179
         */
180
        public Object clone() {
181
                DwgArc dwgArc = new DwgArc();
182
                dwgArc.setType(type);
183
                dwgArc.setHandle(handle);
184
                dwgArc.setVersion(version);
185
                dwgArc.setMode(mode);
186
                dwgArc.setLayerHandle(layerHandle);
187
                dwgArc.setColor(color);
188
                dwgArc.setNumReactors(numReactors);
189
                dwgArc.setNoLinks(noLinks);
190
                dwgArc.setLinetypeFlags(linetypeFlags);
191
                dwgArc.setPlotstyleFlags(plotstyleFlags);
192
                dwgArc.setSizeInBits(sizeInBits);
193
                dwgArc.setExtendedData(extendedData);
194
                dwgArc.setGraphicData(graphicData);
195
                //dwgArc.setInsideBlock(insideBlock);
196
                dwgArc.setCenter(center);
197
                dwgArc.setRadius(radius);
198
                dwgArc.setThickness(thickness);
199
                dwgArc.setExtrusion(extrusion);
200
                dwgArc.setInitAngle(initAngle);
201
                dwgArc.setEndAngle(endAngle);
202
                return dwgArc;
203
        }
204
        /**
205
         * @return Returns the thickness.
206
         */
207
        public double getThickness() {
208
                return thickness;
209
        }
210
        /**
211
         * @param thickness The thickness to set.
212
         */
213
        public void setThickness(double thickness) {
214
                this.thickness = thickness;
215
        }
216
        /**
217
         * @param extrusion The extrusion to set.
218
         */
219
        public void setExtrusion(double[] extrusion) {
220
                this.extrusion = extrusion;
221
        }
222
}