root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / objects / DwgSpline.java @ 9718
History | View | Annotate | Download (11.7 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 DwgSpline class represents a DWG Spline
|
44 |
*
|
45 |
* @author jmorell
|
46 |
*/
|
47 |
public class DwgSpline extends DwgObject { |
48 |
public DwgSpline(int index) { |
49 |
super(index);
|
50 |
// TODO Auto-generated constructor stub
|
51 |
} |
52 |
private int scenario; |
53 |
private int degree; |
54 |
private double fitTolerance; |
55 |
private double[] beginTanVector; |
56 |
private double[] endTanVector; |
57 |
private boolean rational; |
58 |
private boolean closed; |
59 |
private boolean periodic; |
60 |
private double knotTolerance; |
61 |
private double controlTolerance; |
62 |
private double[] knotPoints; |
63 |
private double[][] controlPoints; |
64 |
private double[] weights; |
65 |
private double[][] fitPoints; |
66 |
|
67 |
/**
|
68 |
* Read a Spline in the DWG format Version 15
|
69 |
*
|
70 |
* @param data Array of unsigned bytes obtained from the DWG binary file
|
71 |
* @param offset The current bit offset where the value begins
|
72 |
* @throws Exception If an unexpected bit value is found in the DWG file. Occurs
|
73 |
* when we are looking for LwPolylines.
|
74 |
*/
|
75 |
public void readDwgSplineV15(int[] data, int offset) throws Exception { |
76 |
int bitPos = offset;
|
77 |
bitPos = readObjectHeaderV15(data, bitPos); |
78 |
ArrayList v = DwgUtil.getBitShort(data, bitPos);
|
79 |
bitPos = ((Integer)v.get(0)).intValue(); |
80 |
int sc = ((Integer)v.get(1)).intValue(); |
81 |
scenario = sc; |
82 |
v = DwgUtil.getBitShort(data, bitPos); |
83 |
bitPos = ((Integer)v.get(0)).intValue(); |
84 |
int deg = ((Integer)v.get(1)).intValue(); |
85 |
degree = deg; |
86 |
int knotsNumber = 0; |
87 |
int controlPointsNumber = 0; |
88 |
int fitPointsNumber = 0; |
89 |
boolean weight = false; |
90 |
if (sc==2) { |
91 |
v = DwgUtil.getBitDouble(data, bitPos); |
92 |
bitPos = ((Integer)v.get(0)).intValue(); |
93 |
double ft = ((Double)v.get(1)).doubleValue(); |
94 |
fitTolerance = ft; |
95 |
v = DwgUtil.getBitDouble(data, bitPos); |
96 |
bitPos = ((Integer)v.get(0)).intValue(); |
97 |
double x = ((Double)v.get(1)).doubleValue(); |
98 |
v = DwgUtil.getBitDouble(data, bitPos); |
99 |
bitPos = ((Integer)v.get(0)).intValue(); |
100 |
double y = ((Double)v.get(1)).doubleValue(); |
101 |
v = DwgUtil.getBitDouble(data, bitPos); |
102 |
bitPos = ((Integer)v.get(0)).intValue(); |
103 |
double z = ((Double)v.get(1)).doubleValue(); |
104 |
double[] coord = new double[]{x, y, z}; |
105 |
beginTanVector = coord; |
106 |
v = DwgUtil.getBitDouble(data, bitPos); |
107 |
bitPos = ((Integer)v.get(0)).intValue(); |
108 |
x = ((Double)v.get(1)).doubleValue(); |
109 |
v = DwgUtil.getBitDouble(data, bitPos); |
110 |
bitPos = ((Integer)v.get(0)).intValue(); |
111 |
y = ((Double)v.get(1)).doubleValue(); |
112 |
v = DwgUtil.getBitDouble(data, bitPos); |
113 |
bitPos = ((Integer)v.get(0)).intValue(); |
114 |
z = ((Double)v.get(1)).doubleValue(); |
115 |
coord = new double[]{x, y, z}; |
116 |
endTanVector = coord; |
117 |
v = DwgUtil.getBitShort(data, bitPos); |
118 |
bitPos = ((Integer)v.get(0)).intValue(); |
119 |
fitPointsNumber = ((Integer)v.get(1)).intValue(); |
120 |
} else if (sc==1) { |
121 |
v = DwgUtil.testBit(data, bitPos); |
122 |
bitPos = ((Integer)v.get(0)).intValue(); |
123 |
boolean rat = ((Boolean)v.get(1)).booleanValue(); |
124 |
rational = rat; |
125 |
v = DwgUtil.testBit(data, bitPos); |
126 |
bitPos = ((Integer)v.get(0)).intValue(); |
127 |
boolean closed = ((Boolean)v.get(1)).booleanValue(); |
128 |
this.closed = closed;
|
129 |
v = DwgUtil.testBit(data, bitPos); |
130 |
bitPos = ((Integer)v.get(0)).intValue(); |
131 |
boolean per = ((Boolean)v.get(1)).booleanValue(); |
132 |
periodic = per; |
133 |
v = DwgUtil.getBitDouble(data, bitPos); |
134 |
bitPos = ((Integer)v.get(0)).intValue(); |
135 |
double ktol = ((Double)v.get(1)).doubleValue(); |
136 |
knotTolerance = ktol; |
137 |
v = DwgUtil.getBitDouble(data, bitPos); |
138 |
bitPos = ((Integer)v.get(0)).intValue(); |
139 |
double ctol = ((Double)v.get(1)).doubleValue(); |
140 |
controlTolerance = ctol; |
141 |
v = DwgUtil.getBitLong(data, bitPos); |
142 |
bitPos = ((Integer)v.get(0)).intValue(); |
143 |
knotsNumber = ((Integer)v.get(1)).intValue(); |
144 |
v = DwgUtil.getBitLong(data, bitPos); |
145 |
bitPos = ((Integer)v.get(0)).intValue(); |
146 |
controlPointsNumber = ((Integer)v.get(1)).intValue(); |
147 |
v = DwgUtil.testBit(data, bitPos); |
148 |
bitPos = ((Integer)v.get(0)).intValue(); |
149 |
weight = ((Boolean)v.get(1)).booleanValue(); |
150 |
} else {
|
151 |
System.out.println("ERROR: Escenario desconocido"); |
152 |
} |
153 |
if (knotsNumber>0) { |
154 |
double[] knotpts = new double[knotsNumber]; |
155 |
for (int i=0;i<knotsNumber;i++) { |
156 |
v = DwgUtil.getBitDouble(data, bitPos); |
157 |
bitPos = ((Integer)v.get(0)).intValue(); |
158 |
knotpts[i] = ((Double)v.get(1)).doubleValue(); |
159 |
} |
160 |
knotPoints = knotpts; |
161 |
} |
162 |
if (controlPointsNumber>0) { |
163 |
// Si el n?mero de weights no coincide con el de ctrlpts habr? problemas ...
|
164 |
double[][] ctrlpts = new double[controlPointsNumber][3]; |
165 |
double[] weights = new double[controlPointsNumber]; |
166 |
for (int i=0;i<controlPointsNumber;i++) { |
167 |
v = DwgUtil.getBitDouble(data, bitPos); |
168 |
bitPos = ((Integer)v.get(0)).intValue(); |
169 |
double x = ((Double)v.get(1)).doubleValue(); |
170 |
v = DwgUtil.getBitDouble(data, bitPos); |
171 |
bitPos = ((Integer)v.get(0)).intValue(); |
172 |
double y = ((Double)v.get(1)).doubleValue(); |
173 |
v = DwgUtil.getBitDouble(data, bitPos); |
174 |
bitPos = ((Integer)v.get(0)).intValue(); |
175 |
double z = ((Double)v.get(1)).doubleValue(); |
176 |
//double[] coord = new double[]{x, y, z};
|
177 |
ctrlpts[i][0] = x;
|
178 |
ctrlpts[i][1] = y;
|
179 |
ctrlpts[i][2] = z;
|
180 |
if (weight) {
|
181 |
v = DwgUtil.getBitDouble(data, bitPos); |
182 |
bitPos = ((Integer)v.get(0)).intValue(); |
183 |
weights[i] = ((Double)v.get(1)).doubleValue(); |
184 |
} |
185 |
} |
186 |
controlPoints = ctrlpts; |
187 |
if (weight) {
|
188 |
this.weights = weights;
|
189 |
} |
190 |
} |
191 |
if (fitPointsNumber>0) { |
192 |
double[][] fitpts = new double[fitPointsNumber][3]; |
193 |
for (int i=0;i<fitPointsNumber;i++) { |
194 |
v = DwgUtil.getBitDouble(data, bitPos); |
195 |
bitPos = ((Integer)v.get(0)).intValue(); |
196 |
double x = ((Double)v.get(1)).doubleValue(); |
197 |
v = DwgUtil.getBitDouble(data, bitPos); |
198 |
bitPos = ((Integer)v.get(0)).intValue(); |
199 |
double y = ((Double)v.get(1)).doubleValue(); |
200 |
v = DwgUtil.getBitDouble(data, bitPos); |
201 |
bitPos = ((Integer)v.get(0)).intValue(); |
202 |
double z = ((Double)v.get(1)).doubleValue(); |
203 |
fitpts[i][0] = x;
|
204 |
fitpts[i][1] = y;
|
205 |
fitpts[i][2] = z;
|
206 |
} |
207 |
fitPoints = fitpts; |
208 |
} |
209 |
bitPos = readObjectTailV15(data, bitPos); |
210 |
} |
211 |
/**
|
212 |
* @return Returns the closed.
|
213 |
*/
|
214 |
public boolean isClosed() { |
215 |
return closed;
|
216 |
} |
217 |
/**
|
218 |
* @param closed The closed to set.
|
219 |
*/
|
220 |
public void setClosed(boolean closed) { |
221 |
this.closed = closed;
|
222 |
} |
223 |
/**
|
224 |
* @return Returns the controlPoints.
|
225 |
*/
|
226 |
public double[][] getControlPoints() { |
227 |
return controlPoints;
|
228 |
} |
229 |
/**
|
230 |
* @param controlPoints The controlPoints to set.
|
231 |
*/
|
232 |
public void setControlPoints(double[][] controlPoints) { |
233 |
this.controlPoints = controlPoints;
|
234 |
} |
235 |
/**
|
236 |
* @return Returns the fitPoints.
|
237 |
*/
|
238 |
public double[][] getFitPoints() { |
239 |
return fitPoints;
|
240 |
} |
241 |
/**
|
242 |
* @param fitPoints The fitPoints to set.
|
243 |
*/
|
244 |
public void setFitPoints(double[][] fitPoints) { |
245 |
this.fitPoints = fitPoints;
|
246 |
} |
247 |
/**
|
248 |
* @return Returns the knotPoints.
|
249 |
*/
|
250 |
public double[] getKnotPoints() { |
251 |
return knotPoints;
|
252 |
} |
253 |
/**
|
254 |
* @param knotPoints The knotPoints to set.
|
255 |
*/
|
256 |
public void setKnotPoints(double[] knotPoints) { |
257 |
this.knotPoints = knotPoints;
|
258 |
} |
259 |
/**
|
260 |
* @return Returns the scenario.
|
261 |
*/
|
262 |
public int getScenario() { |
263 |
return scenario;
|
264 |
} |
265 |
/**
|
266 |
* @param scenario The scenario to set.
|
267 |
*/
|
268 |
public void setScenario(int scenario) { |
269 |
this.scenario = scenario;
|
270 |
} |
271 |
/* (non-Javadoc)
|
272 |
* @see java.lang.Object#clone()
|
273 |
*/
|
274 |
public Object clone() { |
275 |
DwgSpline dwgSpline = new DwgSpline(index);
|
276 |
dwgSpline.setType(type); |
277 |
dwgSpline.setHandle(handle); |
278 |
dwgSpline.setVersion(version); |
279 |
dwgSpline.setMode(mode); |
280 |
dwgSpline.setLayerHandle(layerHandle); |
281 |
dwgSpline.setColor(color); |
282 |
dwgSpline.setNumReactors(numReactors); |
283 |
dwgSpline.setNoLinks(noLinks); |
284 |
dwgSpline.setLinetypeFlags(linetypeFlags); |
285 |
dwgSpline.setPlotstyleFlags(plotstyleFlags); |
286 |
dwgSpline.setSizeInBits(sizeInBits); |
287 |
dwgSpline.setExtendedData(extendedData); |
288 |
dwgSpline.setGraphicData(graphicData); |
289 |
//dwgSpline.setInsideBlock(insideBlock);
|
290 |
dwgSpline.setScenario(scenario); |
291 |
dwgSpline.setDegree(degree); |
292 |
dwgSpline.setFitTolerance(fitTolerance); |
293 |
dwgSpline.setBeginTanVector(beginTanVector); |
294 |
dwgSpline.setEndTanVector(endTanVector); |
295 |
dwgSpline.setRational(rational); |
296 |
dwgSpline.setClosed(closed); |
297 |
dwgSpline.setPeriodic(periodic); |
298 |
dwgSpline.setKnotTolerance(knotTolerance); |
299 |
dwgSpline.setControlTolerance(controlTolerance); |
300 |
dwgSpline.setKnotPoints(knotPoints); |
301 |
dwgSpline.setControlPoints(controlPoints); |
302 |
dwgSpline.setWeights(weights); |
303 |
dwgSpline.setFitPoints(fitPoints); |
304 |
return dwgSpline;
|
305 |
} |
306 |
/**
|
307 |
* @return Returns the beginTanVector.
|
308 |
*/
|
309 |
public double[] getBeginTanVector() { |
310 |
return beginTanVector;
|
311 |
} |
312 |
/**
|
313 |
* @param beginTanVector The beginTanVector to set.
|
314 |
*/
|
315 |
public void setBeginTanVector(double[] beginTanVector) { |
316 |
this.beginTanVector = beginTanVector;
|
317 |
} |
318 |
/**
|
319 |
* @return Returns the controlTolerance.
|
320 |
*/
|
321 |
public double getControlTolerance() { |
322 |
return controlTolerance;
|
323 |
} |
324 |
/**
|
325 |
* @param controlTolerance The controlTolerance to set.
|
326 |
*/
|
327 |
public void setControlTolerance(double controlTolerance) { |
328 |
this.controlTolerance = controlTolerance;
|
329 |
} |
330 |
/**
|
331 |
* @return Returns the degree.
|
332 |
*/
|
333 |
public int getDegree() { |
334 |
return degree;
|
335 |
} |
336 |
/**
|
337 |
* @param degree The degree to set.
|
338 |
*/
|
339 |
public void setDegree(int degree) { |
340 |
this.degree = degree;
|
341 |
} |
342 |
/**
|
343 |
* @return Returns the endTanVector.
|
344 |
*/
|
345 |
public double[] getEndTanVector() { |
346 |
return endTanVector;
|
347 |
} |
348 |
/**
|
349 |
* @param endTanVector The endTanVector to set.
|
350 |
*/
|
351 |
public void setEndTanVector(double[] endTanVector) { |
352 |
this.endTanVector = endTanVector;
|
353 |
} |
354 |
/**
|
355 |
* @return Returns the fitTolerance.
|
356 |
*/
|
357 |
public double getFitTolerance() { |
358 |
return fitTolerance;
|
359 |
} |
360 |
/**
|
361 |
* @param fitTolerance The fitTolerance to set.
|
362 |
*/
|
363 |
public void setFitTolerance(double fitTolerance) { |
364 |
this.fitTolerance = fitTolerance;
|
365 |
} |
366 |
/**
|
367 |
* @return Returns the knotTolerance.
|
368 |
*/
|
369 |
public double getKnotTolerance() { |
370 |
return knotTolerance;
|
371 |
} |
372 |
/**
|
373 |
* @param knotTolerance The knotTolerance to set.
|
374 |
*/
|
375 |
public void setKnotTolerance(double knotTolerance) { |
376 |
this.knotTolerance = knotTolerance;
|
377 |
} |
378 |
/**
|
379 |
* @return Returns the periodic.
|
380 |
*/
|
381 |
public boolean isPeriodic() { |
382 |
return periodic;
|
383 |
} |
384 |
/**
|
385 |
* @param periodic The periodic to set.
|
386 |
*/
|
387 |
public void setPeriodic(boolean periodic) { |
388 |
this.periodic = periodic;
|
389 |
} |
390 |
/**
|
391 |
* @return Returns the rational.
|
392 |
*/
|
393 |
public boolean isRational() { |
394 |
return rational;
|
395 |
} |
396 |
/**
|
397 |
* @param rational The rational to set.
|
398 |
*/
|
399 |
public void setRational(boolean rational) { |
400 |
this.rational = rational;
|
401 |
} |
402 |
/**
|
403 |
* @return Returns the weights.
|
404 |
*/
|
405 |
public double[] getWeights() { |
406 |
return weights;
|
407 |
} |
408 |
/**
|
409 |
* @param weights The weights to set.
|
410 |
*/
|
411 |
public void setWeights(double[] weights) { |
412 |
this.weights = weights;
|
413 |
} |
414 |
} |