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