Statistics
| Revision:

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

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