Statistics
| Revision:

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

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