root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / readers / objreaders / v1314 / DwgSplineReader1314.java @ 10820
History | View | Annotate | Download (6.01 KB)
1 | 9910 | azabala | /*
|
---|---|---|---|
2 | * Created on 25-ene-2007 by azabala
|
||
3 | *
|
||
4 | */
|
||
5 | package com.iver.cit.jdwglib.dwg.readers.objreaders.v1314; |
||
6 | |||
7 | 10113 | azabala | import java.util.List; |
8 | |||
9 | import com.iver.cit.jdwglib.dwg.CorruptedDwgEntityException; |
||
10 | 9910 | azabala | import com.iver.cit.jdwglib.dwg.DwgObject; |
11 | 10113 | azabala | import com.iver.cit.jdwglib.dwg.DwgUtil; |
12 | import com.iver.cit.jdwglib.dwg.objects.DwgSpline; |
||
13 | 9910 | azabala | |
14 | /**
|
||
15 | 10820 | azabala | * @author azabala
|
16 | 9910 | azabala | */
|
17 | 10113 | azabala | public class DwgSplineReader1314 extends AbstractDwg1314Reader{ |
18 | 9910 | azabala | |
19 | /* (non-Javadoc)
|
||
20 | * @see com.iver.cit.jdwglib.dwg.readers.IDwgObjectReader#readSpecificObj(int[], int, com.iver.cit.jdwglib.dwg.DwgObject)
|
||
21 | */
|
||
22 | 10113 | azabala | public void readSpecificObj(int[] data, int offset, DwgObject dwgObj) throws RuntimeException, CorruptedDwgEntityException { |
23 | if(! (dwgObj instanceof DwgSpline)) |
||
24 | throw new RuntimeException("ArcReader 14 solo puede leer DwgSpline"); |
||
25 | DwgSpline spline = (DwgSpline) dwgObj; |
||
26 | 9910 | azabala | |
27 | 10113 | azabala | int bitPos = offset;
|
28 | bitPos = headTailReader.readObjectHeader(data, bitPos, spline ); |
||
29 | 9910 | azabala | |
30 | 10113 | azabala | List val = DwgUtil.getBitShort(data, bitPos);
|
31 | bitPos = ((Integer) val.get(0)).intValue(); |
||
32 | int scenario = ((Integer) val.get(1)).intValue(); |
||
33 | |||
34 | val = DwgUtil.getBitShort(data, bitPos); |
||
35 | bitPos = ((Integer) val.get(0)).intValue(); |
||
36 | int degree = ((Integer) val.get(1)).intValue(); |
||
37 | spline.setDegree(degree); |
||
38 | |||
39 | int knots = 0; |
||
40 | int numCtPts = 0; |
||
41 | int numFitPts = 0; |
||
42 | |||
43 | boolean weight = false; |
||
44 | |||
45 | switch(scenario){
|
||
46 | case 2: |
||
47 | val = DwgUtil.getBitDouble(data, bitPos); |
||
48 | bitPos = ((Integer) val.get(0)).intValue(); |
||
49 | double fitTolerance = ((Integer) val.get(1)).intValue(); |
||
50 | spline.setFitTolerance(fitTolerance); |
||
51 | |||
52 | val = DwgUtil.getBitDouble(data, bitPos); |
||
53 | bitPos = ((Integer) val.get(0)).intValue(); |
||
54 | double x = ((Integer) val.get(1)).intValue(); |
||
55 | |||
56 | val = DwgUtil.getBitDouble(data, bitPos); |
||
57 | bitPos = ((Integer) val.get(0)).intValue(); |
||
58 | double y = ((Integer) val.get(1)).intValue(); |
||
59 | |||
60 | val = DwgUtil.getBitDouble(data, bitPos); |
||
61 | bitPos = ((Integer) val.get(0)).intValue(); |
||
62 | double z = ((Integer) val.get(1)).intValue(); |
||
63 | spline.setBeginTanVector(new double[]{x, y, z}); |
||
64 | |||
65 | val = DwgUtil.getBitDouble(data, bitPos); |
||
66 | bitPos = ((Integer) val.get(0)).intValue(); |
||
67 | x = ((Integer) val.get(1)).intValue(); |
||
68 | |||
69 | val = DwgUtil.getBitDouble(data, bitPos); |
||
70 | bitPos = ((Integer) val.get(0)).intValue(); |
||
71 | y = ((Integer) val.get(1)).intValue(); |
||
72 | |||
73 | val = DwgUtil.getBitDouble(data, bitPos); |
||
74 | bitPos = ((Integer) val.get(0)).intValue(); |
||
75 | z = ((Integer) val.get(1)).intValue(); |
||
76 | spline.setEndTanVector(new double[]{x, y, z}); |
||
77 | |||
78 | val = DwgUtil.getBitShort(data, bitPos); |
||
79 | bitPos = ((Integer) val.get(0)).intValue(); |
||
80 | numFitPts = ((Integer) val.get(1)).intValue(); |
||
81 | break;
|
||
82 | |||
83 | case 1: |
||
84 | val = DwgUtil.testBit(data, bitPos); |
||
85 | bitPos = ((Integer) val.get(0)).intValue(); |
||
86 | boolean rational = ((Boolean) val.get(1)).booleanValue(); |
||
87 | |||
88 | val = DwgUtil.testBit(data, bitPos); |
||
89 | bitPos = ((Integer) val.get(0)).intValue(); |
||
90 | boolean closed = ((Boolean) val.get(1)).booleanValue(); |
||
91 | |||
92 | val = DwgUtil.testBit(data, bitPos); |
||
93 | bitPos = ((Integer) val.get(0)).intValue(); |
||
94 | boolean periodic = ((Boolean) val.get(1)).booleanValue(); |
||
95 | |||
96 | val = DwgUtil.getBitDouble(data, bitPos); |
||
97 | bitPos = ((Integer) val.get(0)).intValue(); |
||
98 | double knotTolerance = ((Double) val.get(1)).doubleValue(); |
||
99 | spline.setKnotTolerance(knotTolerance); |
||
100 | |||
101 | val = DwgUtil.getBitDouble(data, bitPos); |
||
102 | bitPos = ((Integer) val.get(0)).intValue(); |
||
103 | double controlTolerance = ((Double) val.get(1)).doubleValue(); |
||
104 | spline.setControlTolerance(controlTolerance); |
||
105 | |||
106 | val = DwgUtil.getBitLong(data, bitPos); |
||
107 | bitPos = ((Integer) val.get(0)).intValue(); |
||
108 | knots = ((Integer) val.get(1)).intValue(); |
||
109 | |||
110 | val = DwgUtil.getBitLong(data, bitPos); |
||
111 | bitPos = ((Integer) val.get(0)).intValue(); |
||
112 | numCtPts = ((Integer) val.get(1)).intValue(); |
||
113 | |||
114 | val = DwgUtil.testBit(data, bitPos); |
||
115 | bitPos = ((Integer) val.get(0)).intValue(); |
||
116 | weight = ((Boolean) val.get(1)).booleanValue(); |
||
117 | |||
118 | break;
|
||
119 | |||
120 | |||
121 | default:
|
||
122 | System.out.println("Unexpected spline scenario "+scenario); |
||
123 | break;
|
||
124 | } |
||
125 | |||
126 | if(knots > 0){ |
||
127 | double[] knotsArray = new double[knots]; |
||
128 | for(int i = 0; i < knots; i++){ |
||
129 | val = DwgUtil.getBitDouble(data, bitPos); |
||
130 | bitPos = ((Integer) val.get(0)).intValue(); |
||
131 | knotsArray[i] = ((Double) val.get(1)).doubleValue(); |
||
132 | } |
||
133 | spline.setKnotPoints(knotsArray); |
||
134 | } |
||
135 | |||
136 | if(numCtPts > 0){ |
||
137 | double[][] ctrlPoint = new double[3][numCtPts]; |
||
138 | double[] weights = new double[numCtPts]; |
||
139 | for(int i = 0; i < numCtPts; i++){ |
||
140 | val = DwgUtil.getBitDouble(data, bitPos); |
||
141 | bitPos = ((Integer) val.get(0)).intValue(); |
||
142 | double x = ((Integer) val.get(1)).intValue(); |
||
143 | |||
144 | val = DwgUtil.getBitDouble(data, bitPos); |
||
145 | bitPos = ((Integer) val.get(0)).intValue(); |
||
146 | double y = ((Integer) val.get(1)).intValue(); |
||
147 | |||
148 | val = DwgUtil.getBitDouble(data, bitPos); |
||
149 | bitPos = ((Integer) val.get(0)).intValue(); |
||
150 | double z = ((Integer) val.get(1)).intValue(); |
||
151 | |||
152 | ctrlPoint[0][i] = x;
|
||
153 | ctrlPoint[1][i] = y;
|
||
154 | ctrlPoint[2][i] = z;
|
||
155 | |||
156 | if(weight){
|
||
157 | val = DwgUtil.getBitDouble(data, bitPos); |
||
158 | bitPos = ((Integer) val.get(0)).intValue(); |
||
159 | weights[i] = ((Integer) val.get(1)).intValue(); |
||
160 | } |
||
161 | }//for
|
||
162 | spline.setControlPoints(ctrlPoint); |
||
163 | spline.setWeights(weights); |
||
164 | }//if
|
||
165 | |||
166 | |||
167 | if(numFitPts > 0){ |
||
168 | double[][] fitPoint = new double[3][numCtPts]; |
||
169 | for(int i = 0; i < numFitPts; i++){ |
||
170 | val = DwgUtil.getBitDouble(data, bitPos); |
||
171 | bitPos = ((Integer) val.get(0)).intValue(); |
||
172 | double x = ((Integer) val.get(1)).intValue(); |
||
173 | |||
174 | val = DwgUtil.getBitDouble(data, bitPos); |
||
175 | bitPos = ((Integer) val.get(0)).intValue(); |
||
176 | double y = ((Integer) val.get(1)).intValue(); |
||
177 | |||
178 | val = DwgUtil.getBitDouble(data, bitPos); |
||
179 | bitPos = ((Integer) val.get(0)).intValue(); |
||
180 | double z = ((Integer) val.get(1)).intValue(); |
||
181 | |||
182 | fitPoint[0][i] = x;
|
||
183 | fitPoint[1][i] = y;
|
||
184 | fitPoint[2][i] = z;
|
||
185 | } |
||
186 | spline.setFitPoints(fitPoint); |
||
187 | } |
||
188 | bitPos = headTailReader.readObjectTailer(data, bitPos, spline); |
||
189 | 9910 | azabala | } |
190 | } |