svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgPolyline2D.java @ 2896
History | View | Annotate | Download (9.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.awt.geom.Point2D; |
38 |
import java.util.Vector; |
39 |
|
40 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
41 |
import com.iver.cit.jdwglib.dwg.DwgUtil; |
42 |
|
43 |
/**
|
44 |
* The DwgPolyline2D class represents a DWG Polyline2D
|
45 |
*
|
46 |
* @author jmorell
|
47 |
*/
|
48 |
public class DwgPolyline2D extends DwgObject { |
49 |
private int flags; |
50 |
private int curveType; |
51 |
private double initWidth; |
52 |
private double endWidth; |
53 |
private double thickness; |
54 |
private double elevation; |
55 |
private double[] extrusion; |
56 |
private int firstVertexHandle; |
57 |
private int lastVertexHandle; |
58 |
private int seqendHandle; |
59 |
private Point2D[] pts; |
60 |
private double[] bulges; |
61 |
|
62 |
/**
|
63 |
* Read a Polyline2D in the DWG format Version 15
|
64 |
*
|
65 |
* @param data Array of unsigned bytes obtained from the DWG binary file
|
66 |
* @param offset The current bit offset where the value begins
|
67 |
* @throws Exception If an unexpected bit value is found in the DWG file. Occurs
|
68 |
* when we are looking for LwPolylines.
|
69 |
*/
|
70 |
public void readDwgPolyline2DV15(int[] data, int offset) throws Exception { |
71 |
//System.out.println("readDwgPolyline2D executing ...");
|
72 |
int bitPos = offset;
|
73 |
bitPos = readObjectHeaderV15(data, bitPos); |
74 |
Vector v = DwgUtil.getBitShort(data, bitPos);
|
75 |
bitPos = ((Integer)v.get(0)).intValue(); |
76 |
int flags = ((Integer)v.get(1)).intValue(); |
77 |
this.flags = flags;
|
78 |
v = DwgUtil.getBitShort(data, bitPos); |
79 |
bitPos = ((Integer)v.get(0)).intValue(); |
80 |
int ctype = ((Integer)v.get(1)).intValue(); |
81 |
curveType = ctype; |
82 |
v = DwgUtil.getBitDouble(data, bitPos); |
83 |
bitPos = ((Integer)v.get(0)).intValue(); |
84 |
double sw = ((Double)v.get(1)).doubleValue(); |
85 |
initWidth = sw; |
86 |
v = DwgUtil.getBitDouble(data, bitPos); |
87 |
bitPos = ((Integer)v.get(0)).intValue(); |
88 |
double ew = ((Double)v.get(1)).doubleValue(); |
89 |
endWidth = ew; |
90 |
v = DwgUtil.testBit(data, bitPos); |
91 |
bitPos = ((Integer)v.get(0)).intValue(); |
92 |
boolean flag = ((Boolean)v.get(1)).booleanValue(); |
93 |
double th = 0.0; |
94 |
if (!flag) {
|
95 |
v = DwgUtil.getBitDouble(data, bitPos); |
96 |
bitPos = ((Integer)v.get(0)).intValue(); |
97 |
th = ((Double)v.get(1)).doubleValue(); |
98 |
} |
99 |
this.thickness = th;
|
100 |
v = DwgUtil.getBitDouble(data, bitPos); |
101 |
bitPos = ((Integer)v.get(0)).intValue(); |
102 |
double elev = ((Double)v.get(1)).doubleValue(); |
103 |
elevation = elev; |
104 |
v = DwgUtil.testBit(data, bitPos); |
105 |
bitPos = ((Integer)v.get(0)).intValue(); |
106 |
flag = ((Boolean)v.get(1)).booleanValue(); |
107 |
double ex, ey, ez = 0.0; |
108 |
if (flag) {
|
109 |
ex = 0.0;
|
110 |
ey = 0.0;
|
111 |
ez = 1.0;
|
112 |
} else {
|
113 |
v = DwgUtil.getBitDouble(data, bitPos); |
114 |
bitPos = ((Integer)v.get(0)).intValue(); |
115 |
ex = ((Double)v.get(1)).doubleValue(); |
116 |
v = DwgUtil.getBitDouble(data, bitPos); |
117 |
bitPos = ((Integer)v.get(0)).intValue(); |
118 |
ey = ((Double)v.get(1)).doubleValue(); |
119 |
v = DwgUtil.getBitDouble(data, bitPos); |
120 |
bitPos = ((Integer)v.get(0)).intValue(); |
121 |
ez = ((Double)v.get(1)).doubleValue(); |
122 |
} |
123 |
extrusion = new double[]{ex, ey, ez}; |
124 |
bitPos = readObjectTailV15(data, bitPos); |
125 |
v = DwgUtil.getHandle(data, bitPos); |
126 |
bitPos = ((Integer)v.get(0)).intValue(); |
127 |
int[] handle = new int[v.size()-1]; |
128 |
for (int i=1;i<v.size();i++) { |
129 |
handle[i-1] = ((Integer)v.get(i)).intValue(); |
130 |
} |
131 |
Vector handleVect = new Vector(); |
132 |
for (int i=0;i<handle.length;i++) { |
133 |
handleVect.add(new Integer(handle[i])); |
134 |
} |
135 |
firstVertexHandle = DwgUtil.handleBinToHandleInt(handleVect); |
136 |
v = DwgUtil.getHandle(data, bitPos); |
137 |
bitPos = ((Integer)v.get(0)).intValue(); |
138 |
handle = new int[v.size()-1]; |
139 |
for (int i=1;i<v.size();i++) { |
140 |
handle[i-1] = ((Integer)v.get(i)).intValue(); |
141 |
} |
142 |
handleVect = new Vector(); |
143 |
for (int i=0;i<handle.length;i++) { |
144 |
handleVect.add(new Integer(handle[i])); |
145 |
} |
146 |
lastVertexHandle = DwgUtil.handleBinToHandleInt(handleVect); |
147 |
v = DwgUtil.getHandle(data, bitPos); |
148 |
bitPos = ((Integer)v.get(0)).intValue(); |
149 |
handle = new int[v.size()-1]; |
150 |
for (int i=1;i<v.size();i++) { |
151 |
handle[i-1] = ((Integer)v.get(i)).intValue(); |
152 |
} |
153 |
handleVect = new Vector(); |
154 |
for (int i=0;i<handle.length;i++) { |
155 |
handleVect.add(new Integer(handle[i])); |
156 |
} |
157 |
seqendHandle = DwgUtil.handleBinToHandleInt(handleVect); |
158 |
} |
159 |
/**
|
160 |
* @return Returns the firstVertexHandle.
|
161 |
*/
|
162 |
public int getFirstVertexHandle() { |
163 |
return firstVertexHandle;
|
164 |
} |
165 |
/**
|
166 |
* @param firstVertexHandle The firstVertexHandle to set.
|
167 |
*/
|
168 |
public void setFirstVertexHandle(int firstVertexHandle) { |
169 |
this.firstVertexHandle = firstVertexHandle;
|
170 |
} |
171 |
/**
|
172 |
* @return Returns the flags.
|
173 |
*/
|
174 |
public int getFlags() { |
175 |
return flags;
|
176 |
} |
177 |
/**
|
178 |
* @param flags The flags to set.
|
179 |
*/
|
180 |
public void setFlags(int flags) { |
181 |
this.flags = flags;
|
182 |
} |
183 |
/**
|
184 |
* @return Returns the lastVertexHandle.
|
185 |
*/
|
186 |
public int getLastVertexHandle() { |
187 |
return lastVertexHandle;
|
188 |
} |
189 |
/**
|
190 |
* @param lastVertexHandle The lastVertexHandle to set.
|
191 |
*/
|
192 |
public void setLastVertexHandle(int lastVertexHandle) { |
193 |
this.lastVertexHandle = lastVertexHandle;
|
194 |
} |
195 |
/**
|
196 |
* @return Returns the pts.
|
197 |
*/
|
198 |
public Point2D[] getPts() { |
199 |
return pts;
|
200 |
} |
201 |
/**
|
202 |
* @param pts The pts to set.
|
203 |
*/
|
204 |
public void setPts(Point2D[] pts) { |
205 |
this.pts = pts;
|
206 |
} |
207 |
/**
|
208 |
* @return Returns the bulges.
|
209 |
*/
|
210 |
public double[] getBulges() { |
211 |
return bulges;
|
212 |
} |
213 |
/**
|
214 |
* @param bulges The bulges to set.
|
215 |
*/
|
216 |
public void setBulges(double[] bulges) { |
217 |
this.bulges = bulges;
|
218 |
} |
219 |
/**
|
220 |
* @return Returns the initWidth.
|
221 |
*/
|
222 |
public double getInitWidth() { |
223 |
return initWidth;
|
224 |
} |
225 |
/**
|
226 |
* @param initWidth The initWidth to set.
|
227 |
*/
|
228 |
public void setInitWidth(double initWidth) { |
229 |
this.initWidth = initWidth;
|
230 |
} |
231 |
/**
|
232 |
* @return Returns the seqendHandle.
|
233 |
*/
|
234 |
public int getSeqendHandle() { |
235 |
return seqendHandle;
|
236 |
} |
237 |
/**
|
238 |
* @param seqendHandle The seqendHandle to set.
|
239 |
*/
|
240 |
public void setSeqendHandle(int seqendHandle) { |
241 |
this.seqendHandle = seqendHandle;
|
242 |
} |
243 |
/**
|
244 |
* @return Returns the thickness.
|
245 |
*/
|
246 |
public double getThickness() { |
247 |
return thickness;
|
248 |
} |
249 |
/**
|
250 |
* @param thickness The thickness to set.
|
251 |
*/
|
252 |
public void setThickness(double thickness) { |
253 |
this.thickness = thickness;
|
254 |
} |
255 |
/**
|
256 |
* @return Returns the curveType.
|
257 |
*/
|
258 |
public int getCurveType() { |
259 |
return curveType;
|
260 |
} |
261 |
/**
|
262 |
* @param curveType The curveType to set.
|
263 |
*/
|
264 |
public void setCurveType(int curveType) { |
265 |
this.curveType = curveType;
|
266 |
} |
267 |
/**
|
268 |
* @return Returns the elevation.
|
269 |
*/
|
270 |
public double getElevation() { |
271 |
return elevation;
|
272 |
} |
273 |
/**
|
274 |
* @param elevation The elevation to set.
|
275 |
*/
|
276 |
public void setElevation(double elevation) { |
277 |
this.elevation = elevation;
|
278 |
} |
279 |
/**
|
280 |
* @return Returns the endWidth.
|
281 |
*/
|
282 |
public double getEndWidth() { |
283 |
return endWidth;
|
284 |
} |
285 |
/**
|
286 |
* @param endWidth The endWidth to set.
|
287 |
*/
|
288 |
public void setEndWidth(double endWidth) { |
289 |
this.endWidth = endWidth;
|
290 |
} |
291 |
/**
|
292 |
* @return Returns the extrusion.
|
293 |
*/
|
294 |
public double[] getExtrusion() { |
295 |
return extrusion;
|
296 |
} |
297 |
/**
|
298 |
* @param extrusion The extrusion to set.
|
299 |
*/
|
300 |
public void setExtrusion(double[] extrusion) { |
301 |
this.extrusion = extrusion;
|
302 |
} |
303 |
/* (non-Javadoc)
|
304 |
* @see java.lang.Object#clone()
|
305 |
*/
|
306 |
public Object clone() { |
307 |
DwgPolyline2D dwgPolyline2D = new DwgPolyline2D();
|
308 |
dwgPolyline2D.setType(type); |
309 |
dwgPolyline2D.setHandle(handle); |
310 |
dwgPolyline2D.setVersion(version); |
311 |
dwgPolyline2D.setMode(mode); |
312 |
dwgPolyline2D.setLayerHandle(layerHandle); |
313 |
dwgPolyline2D.setColor(color); |
314 |
dwgPolyline2D.setNumReactors(numReactors); |
315 |
dwgPolyline2D.setNoLinks(noLinks); |
316 |
dwgPolyline2D.setLinetypeFlags(linetypeFlags); |
317 |
dwgPolyline2D.setPlotstyleFlags(plotstyleFlags); |
318 |
dwgPolyline2D.setSizeInBits(sizeInBits); |
319 |
dwgPolyline2D.setExtendedData(extendedData); |
320 |
dwgPolyline2D.setGraphicData(graphicData); |
321 |
//dwgPolyline2D.setInsideBlock(insideBlock);
|
322 |
dwgPolyline2D.setFlags(flags); |
323 |
dwgPolyline2D.setCurveType(curveType); |
324 |
dwgPolyline2D.setInitWidth(initWidth); |
325 |
dwgPolyline2D.setEndWidth(endWidth); |
326 |
dwgPolyline2D.setThickness(thickness); |
327 |
dwgPolyline2D.setElevation(elevation); |
328 |
dwgPolyline2D.setExtrusion(extrusion); |
329 |
dwgPolyline2D.setFirstVertexHandle(firstVertexHandle); |
330 |
dwgPolyline2D.setLastVertexHandle(lastVertexHandle); |
331 |
dwgPolyline2D.setSeqendHandle(seqendHandle); |
332 |
dwgPolyline2D.setPts(pts); |
333 |
dwgPolyline2D.setBulges(bulges); |
334 |
return dwgPolyline2D;
|
335 |
} |
336 |
} |