Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgSolid.java @ 9825

History | View | Annotate | Download (7.83 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
import com.iver.cit.jdwglib.dwg.IDwg3DTestable;
42
import com.iver.cit.jdwglib.dwg.IDwgExtrusionable;
43
import com.iver.cit.jdwglib.util.AcadExtrusionCalculator;
44

    
45
/**
46
 * The DwgSolid class represents a DWG Solid
47
 * 
48
 * @author jmorell
49
 */
50
public class DwgSolid extends DwgObject 
51
        implements IDwgExtrusionable, IDwg3DTestable{
52
        public DwgSolid(int index) {
53
                super(index);
54
                // TODO Auto-generated constructor stub
55
        }
56
        private double thickness;
57
        private double elevation;
58
        private double[] corner1;
59
        private double[] corner2;
60
        private double[] corner3;
61
        private double[] corner4;
62
        private double[] extrusion;
63
        
64
        /**
65
         * Read a Solid in the DWG format Version 15
66
         * 
67
         * @param data Array of unsigned bytes obtained from the DWG binary file
68
         * @param offset The current bit offset where the value begins
69
         * @throws Exception If an unexpected bit value is found in the DWG file. Occurs
70
         *                    when we are looking for LwPolylines.
71
         */
72
        public void readDwgSolidV15(int[] data, int offset) throws Exception {
73
                int bitPos = offset;
74
                bitPos = readObjectHeaderV15(data, bitPos);
75
                ArrayList 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.getBitDouble(data, bitPos);
88
                bitPos = ((Integer)v.get(0)).intValue();
89
                val = ((Double)v.get(1)).doubleValue();
90
            elevation = val;
91
                v = DwgUtil.getRawDouble(data, bitPos);
92
                bitPos = ((Integer)v.get(0)).intValue();
93
                double x = ((Double)v.get(1)).doubleValue();
94
                v = DwgUtil.getRawDouble(data, bitPos);
95
                bitPos = ((Integer)v.get(0)).intValue();
96
                double y = ((Double)v.get(1)).doubleValue();
97
                double[] coord = new double[]{x, y, val};
98
                corner1 = coord;
99
                v = DwgUtil.getRawDouble(data, bitPos);
100
                bitPos = ((Integer)v.get(0)).intValue();
101
                x = ((Double)v.get(1)).doubleValue();
102
                v = DwgUtil.getRawDouble(data, bitPos);
103
                bitPos = ((Integer)v.get(0)).intValue();
104
                y = ((Double)v.get(1)).doubleValue();
105
                coord = new double[]{x, y, val};
106
                corner2 = coord;
107
                v = DwgUtil.getRawDouble(data, bitPos);
108
                bitPos = ((Integer)v.get(0)).intValue();
109
                x = ((Double)v.get(1)).doubleValue();
110
                v = DwgUtil.getRawDouble(data, bitPos);
111
                bitPos = ((Integer)v.get(0)).intValue();
112
                y = ((Double)v.get(1)).doubleValue();
113
                coord = new double[]{x, y, val};
114
                corner3 = coord;
115
                v = DwgUtil.getRawDouble(data, bitPos);
116
                bitPos = ((Integer)v.get(0)).intValue();
117
                x = ((Double)v.get(1)).doubleValue();
118
                v = DwgUtil.getRawDouble(data, bitPos);
119
                bitPos = ((Integer)v.get(0)).intValue();
120
                y = ((Double)v.get(1)).doubleValue();
121
                coord = new double[]{x, y, val};
122
                corner4 = coord;
123
                v = DwgUtil.testBit(data, bitPos);
124
                bitPos = ((Integer)v.get(0)).intValue();
125
                flag = ((Boolean)v.get(1)).booleanValue();
126
                double z;
127
            if (flag) {
128
                         x = y = 0.0;
129
                         z = 1.0;
130
                } else {
131
                        v = DwgUtil.getBitDouble(data, bitPos);
132
                        bitPos = ((Integer)v.get(0)).intValue();
133
                        x = ((Double)v.get(1)).doubleValue();
134
                        v = DwgUtil.getBitDouble(data, bitPos);
135
                        bitPos = ((Integer)v.get(0)).intValue();
136
                        y = ((Double)v.get(1)).doubleValue();
137
                        v = DwgUtil.getBitDouble(data, bitPos);
138
                        bitPos = ((Integer)v.get(0)).intValue();
139
                        z = ((Double)v.get(1)).doubleValue();
140
                }
141
                coord = new double[]{x, y, z};
142
                extrusion = coord;
143
                bitPos = readObjectTailV15(data, bitPos);
144
        }
145
        /**
146
         * @return Returns the corner1.
147
         */
148
        public double[] getCorner1() {
149
                return corner1;
150
        }
151
        /**
152
         * @param corner1 The corner1 to set.
153
         */
154
        public void setCorner1(double[] corner1) {
155
                this.corner1 = corner1;
156
        }
157
        /**
158
         * @return Returns the corner2.
159
         */
160
        public double[] getCorner2() {
161
                return corner2;
162
        }
163
        /**
164
         * @param corner2 The corner2 to set.
165
         */
166
        public void setCorner2(double[] corner2) {
167
                this.corner2 = corner2;
168
        }
169
        /**
170
         * @return Returns the corner3.
171
         */
172
        public double[] getCorner3() {
173
                return corner3;
174
        }
175
        /**
176
         * @param corner3 The corner3 to set.
177
         */
178
        public void setCorner3(double[] corner3) {
179
                this.corner3 = corner3;
180
        }
181
        /**
182
         * @return Returns the corner4.
183
         */
184
        public double[] getCorner4() {
185
                return corner4;
186
        }
187
        /**
188
         * @param corner4 The corner4 to set.
189
         */
190
        public void setCorner4(double[] corner4) {
191
                this.corner4 = corner4;
192
        }
193
    /**
194
     * @return Returns the elevation.
195
     */
196
    public double getElevation() {
197
        return elevation;
198
    }
199
    /**
200
     * @param elevation The elevation to set.
201
     */
202
    public void setElevation(double elevation) {
203
        this.elevation = elevation;
204
    }
205
    /**
206
     * @return Returns the extrusion.
207
     */
208
    public double[] getExtrusion() {
209
        return extrusion;
210
    }
211
        /* (non-Javadoc)
212
         * @see java.lang.Object#clone()
213
         */
214
        public Object clone() {
215
                DwgSolid dwgSolid = new DwgSolid(index);
216
                dwgSolid.setType(type);
217
                dwgSolid.setHandle(handle);
218
                dwgSolid.setVersion(version);
219
                dwgSolid.setMode(mode);
220
                dwgSolid.setLayerHandle(layerHandle);
221
                dwgSolid.setColor(color);
222
                dwgSolid.setNumReactors(numReactors);
223
                dwgSolid.setNoLinks(noLinks);
224
                dwgSolid.setLinetypeFlags(linetypeFlags);
225
                dwgSolid.setPlotstyleFlags(plotstyleFlags);
226
                dwgSolid.setSizeInBits(sizeInBits);
227
                dwgSolid.setExtendedData(extendedData);
228
                dwgSolid.setGraphicData(graphicData);
229
                //dwgSolid.setInsideBlock(insideBlock);
230
                dwgSolid.setThickness(thickness);
231
                dwgSolid.setElevation(elevation);
232
                dwgSolid.setCorner1(corner1);
233
                dwgSolid.setCorner2(corner2);
234
                dwgSolid.setCorner3(corner3);
235
                dwgSolid.setCorner4(corner4);
236
                dwgSolid.setExtrusion(extrusion);
237
                return dwgSolid;
238
        }
239
        /**
240
         * @return Returns the thickness.
241
         */
242
        public double getThickness() {
243
                return thickness;
244
        }
245
        /**
246
         * @param thickness The thickness to set.
247
         */
248
        public void setThickness(double thickness) {
249
                this.thickness = thickness;
250
        }
251
        /**
252
         * @param extrusion The extrusion to set.
253
         */
254
        public void setExtrusion(double[] extrusion) {
255
                this.extrusion = extrusion;
256
        }
257
        /* (non-Javadoc)
258
         * @see com.iver.cit.jdwglib.dwg.IDwgExtrusionable#applyExtrussion()
259
         */
260
        public void applyExtrussion() {
261
                 double[] corner1 = getCorner1();
262
         double[] corner2 = getCorner2();
263
         double[] corner3 = getCorner3();
264
         double[] corner4 = getCorner4();
265
         double[] solidExt = getExtrusion();
266
         corner1 = AcadExtrusionCalculator.CalculateAcadExtrusion(corner1, solidExt);
267
         setCorner1(corner1);
268
         setCorner2(corner2);
269
         setCorner3(corner3);
270
         setCorner4(corner4);
271
        }
272
        /* (non-Javadoc)
273
         * @see com.iver.cit.jdwglib.dwg.IDwg3DTestable#has3DData()
274
         */
275
        public boolean has3DData() {
276
                return (getElevation() != 0.0);
277
        }
278
}