Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgPoint.java @ 9718

History | View | Annotate | Download (5.28 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.ArrayList;
38

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

    
42
/**
43
 * The DwgPoint class represents a DWG Point
44
 * 
45
 * @author jmorell
46
 */
47
public class DwgPoint extends DwgObject {
48
        public DwgPoint(int index) {
49
                super(index);
50
                // TODO Auto-generated constructor stub
51
        }
52
        private double[] point;
53
        private double thickness;
54
        private double[] extrusion;
55
        private double xAxisAngle;
56
        
57
        /**
58
         * Read a Point 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 readDwgPointV15(int[] data, int offset) throws Exception {
66
                int bitPos = offset;
67
                bitPos = readObjectHeaderV15(data, bitPos);
68
                ArrayList v = DwgUtil.getBitDouble(data, bitPos);
69
                bitPos = ((Integer)v.get(0)).intValue();
70
                double x = ((Double)v.get(1)).doubleValue();
71
                v = DwgUtil.getBitDouble(data, bitPos);
72
                bitPos = ((Integer)v.get(0)).intValue();
73
                double y = ((Double)v.get(1)).doubleValue();
74
                v = DwgUtil.getBitDouble(data, bitPos);
75
                bitPos = ((Integer)v.get(0)).intValue();
76
                double z = ((Double)v.get(1)).doubleValue();
77
                double[] coord = new double[]{x, y, z};
78
                point = coord;
79
                v = DwgUtil.testBit(data, bitPos);
80
                bitPos = ((Integer)v.get(0)).intValue();
81
                boolean flag = ((Boolean)v.get(1)).booleanValue();
82
            double val;
83
                if (flag) {
84
                        val=0.0;
85
                } else {
86
                        v = DwgUtil.getBitDouble(data, bitPos);
87
                        bitPos = ((Integer)v.get(0)).intValue();
88
                        val = ((Double)v.get(1)).doubleValue();
89
                }
90
                thickness = val;
91
                v = DwgUtil.testBit(data, bitPos);
92
                bitPos = ((Integer)v.get(0)).intValue();
93
                flag = ((Boolean)v.get(1)).booleanValue();
94
                if (flag) {
95
                         x = y = 0.0;
96
                         z = 1.0;
97
                } else {
98
                        v = DwgUtil.getBitDouble(data, bitPos);
99
                        bitPos = ((Integer)v.get(0)).intValue();
100
                        x = ((Double)v.get(1)).doubleValue();
101
                        v = DwgUtil.getBitDouble(data, bitPos);
102
                        bitPos = ((Integer)v.get(0)).intValue();
103
                        y = ((Double)v.get(1)).doubleValue();
104
                        v = DwgUtil.getBitDouble(data, bitPos);
105
                        bitPos = ((Integer)v.get(0)).intValue();
106
                        z = ((Double)v.get(1)).doubleValue();
107
                }
108
                coord = new double[]{x, y, z};
109
                extrusion = coord;
110
                v = DwgUtil.getBitDouble(data, bitPos);
111
                bitPos = ((Integer)v.get(0)).intValue();
112
                val = ((Double)v.get(1)).doubleValue();
113
            xAxisAngle = val;
114
                bitPos = readObjectTailV15(data, bitPos);
115
        }
116
        /**
117
         * @return Returns the point.
118
         */
119
        public double[] getPoint() {
120
                return point;
121
        }
122
        /**
123
         * @param point The point to set.
124
         */
125
        public void setPoint(double[] point) {
126
                this.point = point;
127
        }
128
        /**
129
         * @return Returns the extrusion.
130
         */
131
        public double[] getExtrusion() {
132
                return extrusion;
133
        }
134
        /**
135
         * @param extrusion The extrusion to set.
136
         */
137
        public void setExtrusion(double[] extrusion) {
138
                this.extrusion = extrusion;
139
        }
140
        /**
141
         * @return Returns the thickness.
142
         */
143
        public double getThickness() {
144
                return thickness;
145
        }
146
        /**
147
         * @param thickness The thickness to set.
148
         */
149
        public void setThickness(double thickness) {
150
                this.thickness = thickness;
151
        }
152
        /**
153
         * @return Returns the xAxisAngle.
154
         */
155
        public double getXAxisAngle() {
156
                return xAxisAngle;
157
        }
158
        /**
159
         * @param axisAngle The xAxisAngle to set.
160
         */
161
        public void setXAxisAngle(double axisAngle) {
162
                xAxisAngle = axisAngle;
163
        }
164
        /* (non-Javadoc)
165
         * @see java.lang.Object#clone()
166
         */
167
        public Object clone() {
168
                DwgPoint dwgPoint = new DwgPoint(index);
169
                dwgPoint.setType(type);
170
                dwgPoint.setHandle(handle);
171
                dwgPoint.setVersion(version);
172
                dwgPoint.setMode(mode);
173
                dwgPoint.setLayerHandle(layerHandle);
174
                dwgPoint.setColor(color);
175
                dwgPoint.setNumReactors(numReactors);
176
                dwgPoint.setNoLinks(noLinks);
177
                dwgPoint.setLinetypeFlags(linetypeFlags);
178
                dwgPoint.setPlotstyleFlags(plotstyleFlags);
179
                dwgPoint.setSizeInBits(sizeInBits);
180
                dwgPoint.setExtendedData(extendedData);
181
                dwgPoint.setGraphicData(graphicData);
182
                //dwgPoint.setInsideBlock(insideBlock);
183
                dwgPoint.setPoint(point);
184
                dwgPoint.setThickness(thickness);
185
                dwgPoint.setXAxisAngle(xAxisAngle);
186
                dwgPoint.setExtrusion(extrusion);
187
                return dwgPoint;
188
        }
189
}