root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / readers / objreaders / v15 / DwgLwPolylineReader15.java @ 10632
History | View | Annotate | Download (7.69 KB)
1 |
/*
|
---|---|
2 |
* Created on 25-ene-2007 by azabala
|
3 |
*
|
4 |
*/
|
5 |
package com.iver.cit.jdwglib.dwg.readers.objreaders.v15; |
6 |
|
7 |
import java.awt.geom.Point2D; |
8 |
import java.util.ArrayList; |
9 |
import java.util.List; |
10 |
|
11 |
import com.iver.cit.jdwglib.dwg.CorruptedDwgEntityException; |
12 |
import com.iver.cit.jdwglib.dwg.DwgObject; |
13 |
import com.iver.cit.jdwglib.dwg.DwgUtil; |
14 |
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline; |
15 |
|
16 |
/**
|
17 |
* @author alzabord
|
18 |
*
|
19 |
* TODO To change the template for this generated type comment go to Window -
|
20 |
* Preferences - Java - Code Style - Code Templates
|
21 |
*/
|
22 |
public class DwgLwPolylineReader15 extends AbstractDwg15Reader { |
23 |
|
24 |
/*
|
25 |
*TODO El metodo original de J.Morell daba excepciones (que eran
|
26 |
*ocultadas con un catch(Exception){}...BUF!
|
27 |
*
|
28 |
* Este metodo trata de copiar literalmente el de Python, para ver
|
29 |
* si somos capaces de resolver el bug.
|
30 |
*
|
31 |
* */
|
32 |
public void readSpecificObj(int[] data, int offset, DwgObject dwgObj) throws RuntimeException, CorruptedDwgEntityException { |
33 |
|
34 |
if (!(dwgObj instanceof DwgLwPolyline)) |
35 |
throw new RuntimeException( |
36 |
"ArcReader 15 solo puede leer DwgLwPolyLine");
|
37 |
DwgLwPolyline line = (DwgLwPolyline) dwgObj; |
38 |
List val = null; |
39 |
int bitPos = offset;
|
40 |
bitPos = headTailReader.readObjectHeader(data, bitPos, dwgObj); |
41 |
val = DwgUtil.getBitShort(data, bitPos); |
42 |
bitPos = ((Integer) val.get(0)).intValue(); |
43 |
int flag = ((Integer) val.get(1)).intValue(); |
44 |
line.setFlag(flag); |
45 |
|
46 |
/*
|
47 |
* Flag son 4 bits que indican si la lwpline tiene ancho,
|
48 |
* (3er bit), elevacion (4o bit), grosor (2? bit) y vector
|
49 |
* de extrusion (1er bit).
|
50 |
* 5? bit -> n? de bulges
|
51 |
* 60 bit -> n? de widths
|
52 |
*
|
53 |
* ahora se verifican y se van leyendo
|
54 |
* */
|
55 |
|
56 |
|
57 |
double constWidth = 0d; |
58 |
if( (flag & 0x4) > 0){ |
59 |
val = DwgUtil.getBitDouble(data, bitPos); |
60 |
bitPos = ((Integer) val.get(0)).intValue(); |
61 |
constWidth = ((Double) val.get(1)).doubleValue(); |
62 |
}//if
|
63 |
line.setConstWidth(constWidth); |
64 |
|
65 |
double elev = 0d; |
66 |
if ( (flag & 0x8) > 0){ |
67 |
val = DwgUtil.getBitDouble(data, bitPos); |
68 |
bitPos = ((Integer) val.get(0)).intValue(); |
69 |
elev = ((Double) val.get(1)).doubleValue(); |
70 |
} |
71 |
line.setElevation(elev); |
72 |
|
73 |
double thickness = 0d; |
74 |
if ( (flag & 0x2) > 0){ |
75 |
val = DwgUtil.getBitDouble(data, bitPos); |
76 |
bitPos = ((Integer) val.get(0)).intValue(); |
77 |
thickness = ((Double) val.get(1)).doubleValue(); |
78 |
} |
79 |
line.setThickness(thickness); |
80 |
|
81 |
double nx = 0d; |
82 |
double ny = 0d; |
83 |
double nz = 0d; |
84 |
if( (flag & 0x1) > 0){ |
85 |
val = DwgUtil.getBitDouble(data, bitPos); |
86 |
bitPos = ((Integer) val.get(0)).intValue(); |
87 |
nx = ((Double) val.get(1)).doubleValue(); |
88 |
|
89 |
val = DwgUtil.getBitDouble(data, bitPos); |
90 |
bitPos = ((Integer) val.get(0)).intValue(); |
91 |
ny = ((Double) val.get(1)).doubleValue(); |
92 |
|
93 |
val = DwgUtil.getBitDouble(data, bitPos); |
94 |
bitPos = ((Integer) val.get(0)).intValue(); |
95 |
nz = ((Double) val.get(1)).doubleValue(); |
96 |
} |
97 |
line.setNormal(new double[]{nx, ny, nz}); |
98 |
|
99 |
val = DwgUtil.getBitLong(data, bitPos); |
100 |
bitPos = ((Integer) val.get(0)).intValue(); |
101 |
int numberOfPoints = ((Integer) val.get(1)).intValue(); |
102 |
|
103 |
int numberOfBulges = 0; |
104 |
if ((flag & 0x10) > 0){ |
105 |
val = DwgUtil.getBitLong(data, bitPos); |
106 |
bitPos = ((Integer) val.get(0)).intValue(); |
107 |
numberOfBulges = ((Integer) val.get(1)).intValue(); |
108 |
} |
109 |
|
110 |
int numberOfWidths = 0; |
111 |
if ((flag & 0x20) > 0){ |
112 |
val = DwgUtil.getBitLong(data, bitPos); |
113 |
bitPos = ((Integer) val.get(0)).intValue(); |
114 |
numberOfWidths = ((Integer) val.get(1)).intValue(); |
115 |
} |
116 |
|
117 |
if(numberOfPoints > 0){ |
118 |
//Esto es una chapuza, pero las LwPolylines no se est?n
|
119 |
//leyendo bien y en ocasiones nos llegan entidades
|
120 |
//con MILLONES de puntos (OutOfMemoryException)
|
121 |
//Plantear en la lista de PythonCAD
|
122 |
if(numberOfPoints > 10000) |
123 |
throw new CorruptedDwgEntityException("LwPolyline corrupta"); |
124 |
List vertices = new ArrayList(); |
125 |
val = DwgUtil.getRawDouble(data, bitPos); |
126 |
bitPos = ((Integer) val.get(0)).intValue(); |
127 |
double x0 = ((Double) val.get(1)).doubleValue(); |
128 |
|
129 |
val = DwgUtil.getRawDouble(data, bitPos); |
130 |
bitPos = ((Integer) val.get(0)).intValue(); |
131 |
double y0 = ((Double) val.get(1)).doubleValue(); |
132 |
|
133 |
vertices.add(new double[]{x0, y0}); |
134 |
|
135 |
|
136 |
/*
|
137 |
* TODO azabala
|
138 |
* Algunos metodos de DwgUtil lanzan excepciones inexperadas
|
139 |
* cuando trabajan para rellenar clases de LwPolyline:
|
140 |
* ->getDefaultDouble
|
141 |
* ->getBits
|
142 |
* etc
|
143 |
*
|
144 |
* Estas excepciones son del tipo OutOfBounds (se intenta leer un bit
|
145 |
* cuyo orden excede de la capacidad del array)
|
146 |
* La especificaci?n 15 de DWG es seguida al pie de la letra por Pythoncad,
|
147 |
* (y por nosotros) as? que puede ser que el problema est? en los metodos
|
148 |
* de DwgUtil.
|
149 |
*
|
150 |
* Intentar capturar la excepcion para que no se pierdan las entidades que las
|
151 |
* provocan, y luego solucionar el error
|
152 |
*
|
153 |
*
|
154 |
* */
|
155 |
for (int i = 1; i < numberOfPoints; i++) { |
156 |
val = DwgUtil.getDefaultDouble(data, bitPos, x0); |
157 |
bitPos = ((Integer) val.get(0)).intValue(); |
158 |
double x = ((Double) val.get(1)).doubleValue(); |
159 |
|
160 |
val = DwgUtil.getDefaultDouble(data, bitPos, y0); |
161 |
bitPos = ((Integer) val.get(0)).intValue(); |
162 |
double y = ((Double) val.get(1)).doubleValue(); |
163 |
|
164 |
vertices.add(new double[]{x, y}); |
165 |
|
166 |
x0 = x;//se proporcionan como valores por defecto las coordenadas del pto anterior
|
167 |
y0 = y; |
168 |
} |
169 |
line.setVertices(vertices); |
170 |
}else{
|
171 |
System.out.println("vertices == 0: lanzamos una excepcion??"); |
172 |
} |
173 |
|
174 |
|
175 |
|
176 |
if(numberOfBulges > 0){ |
177 |
if (numberOfBulges != numberOfPoints){
|
178 |
System.out.println("bulges != vertices: lanzamos una excepcion??"); |
179 |
} |
180 |
double[] bulges = new double[numberOfBulges]; |
181 |
for(int i = 0; i < numberOfBulges; i++){ |
182 |
//TODO OJOOOOOO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
183 |
//En PythonCAD se hacia getRawDouble, pero en la especificacion
|
184 |
//(pagina 136) dice que es BitDouble (BD)
|
185 |
val = DwgUtil.getBitDouble(data, bitPos); |
186 |
bitPos = ((Integer) val.get(0)).intValue(); |
187 |
bulges[i] = ((Double) val.get(1)).doubleValue(); |
188 |
} |
189 |
line.setBulges(bulges); |
190 |
}else{
|
191 |
double[] bulges = new double[numberOfPoints]; |
192 |
for(int i = 0; i < numberOfPoints; i++) |
193 |
bulges[i] = 0d;
|
194 |
line.setBulges(bulges); |
195 |
} |
196 |
|
197 |
if(numberOfWidths > 0){ |
198 |
if (numberOfWidths != numberOfPoints){
|
199 |
System.out.println("widths != vertices: lanzamos una excepcion??"); |
200 |
} |
201 |
double[][] widths = new double[numberOfWidths][2]; |
202 |
for (int i = 0; i < numberOfWidths; i++) { |
203 |
val = DwgUtil.getBitDouble(data, bitPos); |
204 |
bitPos = ((Integer) val.get(0)).intValue(); |
205 |
double sw = ((Double) val.get(1)).doubleValue(); |
206 |
|
207 |
val = DwgUtil.getBitDouble(data, bitPos); |
208 |
bitPos = ((Integer) val.get(0)).intValue(); |
209 |
double ew = ((Double) val.get(1)).doubleValue(); |
210 |
widths[i][0] = sw;
|
211 |
widths[i][1] = ew;
|
212 |
} |
213 |
line.setWidths(widths); |
214 |
}else{
|
215 |
line.setWidths(new double[0][0]); |
216 |
} |
217 |
|
218 |
|
219 |
|
220 |
/*
|
221 |
* azabala: de siempre se producen excepciones al tratar de leer
|
222 |
* LwPolyline (si no se veian es pq se capturaban y no se sacaba
|
223 |
* traza)
|
224 |
*
|
225 |
* Se producen siempre que numVertices == 0 ????
|
226 |
* Probar a saltarmelos.
|
227 |
*
|
228 |
*
|
229 |
*
|
230 |
* TODO Ver por qu? aparecen (y lo peor, pq una vez se da una se propagan
|
231 |
* todas)
|
232 |
*
|
233 |
* */
|
234 |
bitPos = headTailReader.readObjectTailer(data, bitPos, line); |
235 |
} |
236 |
} |