Statistics
| Revision:

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

History | View | Annotate | Download (5.19 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 DwgCircle class represents a DWG Circle
44
 * 
45
 * @author jmorell
46
 */
47
public class DwgCircle extends DwgObject {
48
        private double[] center;
49
        private double radius;
50
        private double thickness;
51
        private double[] extrusion;
52
        
53
        /**
54
         * Read a Circle in the DWG format Version 15
55
         * 
56
         * @param data Array of unsigned bytes obtained from the DWG binary file
57
         * @param offset The current bit offset where the value begins
58
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
59
         *                    when we are looking for LwPolylines.
60
         */
61
        public void readDwgCircleV15(int[] data, int offset) throws Exception {
62
                int bitPos = offset;
63
                bitPos = readObjectHeaderV15(data, bitPos);
64
                Vector v = DwgUtil.getBitDouble(data, bitPos);
65
                bitPos = ((Integer)v.get(0)).intValue();
66
                double x = ((Double)v.get(1)).doubleValue();
67
                v = DwgUtil.getBitDouble(data, bitPos);
68
                bitPos = ((Integer)v.get(0)).intValue();
69
                double y = ((Double)v.get(1)).doubleValue();
70
                v = DwgUtil.getBitDouble(data, bitPos);
71
                bitPos = ((Integer)v.get(0)).intValue();
72
                double z = ((Double)v.get(1)).doubleValue();
73
                double[] coord = new double[]{x, y, z};
74
                center = coord;
75
                v = DwgUtil.getBitDouble(data, bitPos);
76
                bitPos = ((Integer)v.get(0)).intValue();
77
                double val = ((Double)v.get(1)).doubleValue();
78
                radius = val;
79
                v = DwgUtil.testBit(data, bitPos);
80
                bitPos = ((Integer)v.get(0)).intValue();
81
                boolean flag = ((Boolean)v.get(1)).booleanValue();
82
            if (flag) {
83
                        val=0.0;
84
                } else {
85
                        v = DwgUtil.getBitDouble(data, bitPos);
86
                        bitPos = ((Integer)v.get(0)).intValue();
87
                        val = ((Double)v.get(1)).doubleValue();
88
                }
89
            thickness = val;
90
                v = DwgUtil.testBit(data, bitPos);
91
                bitPos = ((Integer)v.get(0)).intValue();
92
                flag = ((Boolean)v.get(1)).booleanValue();
93
                if (flag) {
94
                         x = y = 0.0;
95
                         z = 1.0;
96
                } else {
97
                        v = DwgUtil.getBitDouble(data, bitPos);
98
                        bitPos = ((Integer)v.get(0)).intValue();
99
                        x = ((Double)v.get(1)).doubleValue();
100
                        v = DwgUtil.getBitDouble(data, bitPos);
101
                        bitPos = ((Integer)v.get(0)).intValue();
102
                        y = ((Double)v.get(1)).doubleValue();
103
                        v = DwgUtil.getBitDouble(data, bitPos);
104
                        bitPos = ((Integer)v.get(0)).intValue();
105
                        z = ((Double)v.get(1)).doubleValue();
106
                }
107
                coord = new double[]{x, y, z};
108
                extrusion = coord;
109
                bitPos = readObjectTailV15(data, bitPos);
110
        }
111
        /**
112
         * @return Returns the center.
113
         */
114
        public double[] getCenter() {
115
                return center;
116
        }
117
        /**
118
         * @param center The center to set.
119
         */
120
        public void setCenter(double[] center) {
121
                this.center = center;
122
        }
123
        /**
124
         * @return Returns the radius.
125
         */
126
        public double getRadius() {
127
                return radius;
128
        }
129
        /**
130
         * @param radius The radius to set.
131
         */
132
        public void setRadius(double radius) {
133
                this.radius = radius;
134
        }
135
    /**
136
     * @return Returns the extrusion.
137
     */
138
    public double[] getExtrusion() {
139
        return extrusion;
140
    }
141
        /* (non-Javadoc)
142
         * @see java.lang.Object#clone()
143
         */
144
        public Object clone() {
145
                DwgCircle dwgCircle = new DwgCircle();
146
                dwgCircle.setType(type);
147
                dwgCircle.setHandle(handle);
148
                dwgCircle.setVersion(version);
149
                dwgCircle.setMode(mode);
150
                dwgCircle.setLayerHandle(layerHandle);
151
                dwgCircle.setColor(color);
152
                dwgCircle.setNumReactors(numReactors);
153
                dwgCircle.setNoLinks(noLinks);
154
                dwgCircle.setLinetypeFlags(linetypeFlags);
155
                dwgCircle.setPlotstyleFlags(plotstyleFlags);
156
                dwgCircle.setSizeInBits(sizeInBits);
157
                dwgCircle.setExtendedData(extendedData);
158
                dwgCircle.setGraphicData(graphicData);
159
                //dwgCircle.setInsideBlock(insideBlock);
160
                dwgCircle.setCenter(center);
161
                dwgCircle.setRadius(radius);
162
                dwgCircle.setThickness(thickness);
163
                dwgCircle.setExtrusion(extrusion);
164
                return dwgCircle;
165
        }
166
        /**
167
         * @return Returns the thickness.
168
         */
169
        public double getThickness() {
170
                return thickness;
171
        }
172
        /**
173
         * @param thickness The thickness to set.
174
         */
175
        public void setThickness(double thickness) {
176
                this.thickness = thickness;
177
        }
178
        /**
179
         * @param extrusion The extrusion to set.
180
         */
181
        public void setExtrusion(double[] extrusion) {
182
                this.extrusion = extrusion;
183
        }
184
}