svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfEntityMaker.java @ 65
History | View | Annotate | Download (30 KB)
1 |
package org.cresques.px.dxf; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
import java.util.Vector; |
5 |
import org.cresques.geo.Point3D; |
6 |
import org.cresques.geo.Projected; |
7 |
import org.cresques.geo.Projection; |
8 |
import org.cresques.geo.ReProjection; |
9 |
import org.cresques.io.DxfFile; |
10 |
import org.cresques.io.DxfGroup; |
11 |
import org.cresques.io.DxfGroupVector; |
12 |
import org.cresques.px.Extent; |
13 |
import org.cresques.px.PxObj; |
14 |
|
15 |
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected { |
16 |
Projection proj = null;
|
17 |
DxfEntity lastEntity = null;
|
18 |
DxfEntityList entities = null;
|
19 |
Vector blkList = null; |
20 |
DxfBlock blk = null;
|
21 |
DxfTable layers = null;
|
22 |
double bulge = 0.0; |
23 |
|
24 |
double xtruX=0.0, xtruY=0.0, xtruZ=1.0; |
25 |
|
26 |
int polylineFlag = 0; |
27 |
Point2D firstPt = new Point2D.Double(); |
28 |
|
29 |
boolean addingToBlock = false; |
30 |
int iterator = 0; |
31 |
|
32 |
public DxfEntityMaker (Projection proj) {
|
33 |
this.proj = proj;
|
34 |
layers = new DxfTable();
|
35 |
entities = new DxfEntityList(proj);
|
36 |
blkList = new Vector(); |
37 |
} |
38 |
|
39 |
public Vector getBlkList() { return blkList; } |
40 |
|
41 |
public PxObj getObjects() { return entities; } |
42 |
public Extent getExtent() { return entities.getExtent(); } |
43 |
|
44 |
public void setAddingToBlock(boolean a) { addingToBlock = a; } |
45 |
|
46 |
public void createLayer(DxfGroupVector grp) throws Exception { |
47 |
DxfLayer layer = new DxfLayer(grp.getDataAsString(2), grp.getDataAsInt(62)); |
48 |
layer.lType = grp.getDataAsString(6);
|
49 |
layer.setFlags(grp.getDataAsInt(70));
|
50 |
// compruebo flags
|
51 |
if ((layer.flags & 0x01) == 0x01) { |
52 |
layer.frozen = true;
|
53 |
} |
54 |
if ((layer.flags & 0x02) == 0x02) { |
55 |
layer.frozen = true;
|
56 |
} |
57 |
layers.add(layer); |
58 |
} |
59 |
|
60 |
public void createPolyline(DxfGroupVector grp) throws Exception { |
61 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
62 |
DxfPolyline entity = new DxfPolyline(proj, layer);
|
63 |
|
64 |
double x = 0.0, y = 0.0, z = 0.0; |
65 |
double thickness = 0; |
66 |
|
67 |
if (grp.hasCode(10)) |
68 |
x = grp.getDataAsDouble(10);
|
69 |
if (grp.hasCode(20)) |
70 |
y = grp.getDataAsDouble(20);
|
71 |
if (grp.hasCode(30)) |
72 |
z = grp.getDataAsDouble(30);
|
73 |
/*if (grp.hasCode(39))
|
74 |
System.out.println("Leer el thickness provoca un error");
|
75 |
thickness = grp.getDataAsDouble(39);*/
|
76 |
if (grp.hasCode(62)) { |
77 |
entity.dxfColor = grp.getDataAsInt(62);
|
78 |
} |
79 |
if (grp.hasCode(70)) { |
80 |
entity.flags = grp.getDataAsInt(70);
|
81 |
} |
82 |
if (grp.hasCode(210)) |
83 |
xtruX = grp.getDataAsDouble(210);
|
84 |
if (grp.hasCode(220)) |
85 |
xtruY = grp.getDataAsDouble(220);
|
86 |
if (grp.hasCode(230)) |
87 |
xtruZ = grp.getDataAsDouble(230);
|
88 |
if ((entity.flags & 0x01) == 0x01) { |
89 |
entity.closed = true;
|
90 |
} |
91 |
lastEntity = entity; |
92 |
} |
93 |
public void endSeq() throws Exception { |
94 |
DxfPolyline polyline = (DxfPolyline)lastEntity; |
95 |
if (polyline.closed) {
|
96 |
((DxfPolyline) lastEntity).add(firstPt); |
97 |
if (!(bulge==0)) { |
98 |
int cnt = ((DxfPolyline) lastEntity).pts.size();
|
99 |
Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge); |
100 |
((DxfPolyline) lastEntity).pts.remove(cnt-1);
|
101 |
for (int i=0; i<arc.size(); i++) { |
102 |
Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
103 |
((DxfPolyline) lastEntity).add(pt); |
104 |
if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt; |
105 |
} |
106 |
bulge = 0.0;
|
107 |
} |
108 |
} |
109 |
if (addingToBlock == false) { |
110 |
entities.add(lastEntity); |
111 |
} else {
|
112 |
System.out.println("createPolyline: A?adimos una polilinea al bloque " + iterator); |
113 |
blk.add(lastEntity); |
114 |
} |
115 |
lastEntity = null;
|
116 |
xtruX = 0.0;
|
117 |
xtruY = 0.0;
|
118 |
xtruZ = 1.0;
|
119 |
bulge = 0.0;
|
120 |
} |
121 |
public void addVertex(DxfGroupVector grp) throws Exception { |
122 |
double x = 0.0, y = 0.0, z = 0.0; |
123 |
|
124 |
if (bulge == 0.0) { |
125 |
x = grp.getDataAsDouble(10);
|
126 |
y = grp.getDataAsDouble(20);
|
127 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
128 |
if (grp.hasCode(42)) { |
129 |
bulge = grp.getDataAsDouble(42);
|
130 |
} else { bulge = 0.0; } |
131 |
Point3D point_in = new Point3D(x, y, z);
|
132 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
133 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
134 |
x = point_out.getX(); |
135 |
y = point_out.getY(); |
136 |
Point2D pt = proj.createPoint( x, y);
|
137 |
((DxfPolyline) lastEntity).add(pt); |
138 |
if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt; |
139 |
} else {
|
140 |
double bulge_aux = 0.0; |
141 |
x = grp.getDataAsDouble(10);
|
142 |
y = grp.getDataAsDouble(20);
|
143 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
144 |
if (grp.hasCode(42)) { |
145 |
bulge_aux = grp.getDataAsDouble(42);
|
146 |
} else { bulge_aux = 0.0; } |
147 |
Point3D point_in = new Point3D(x, y, z);
|
148 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
149 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
150 |
x = point_out.getX(); |
151 |
y = point_out.getY(); |
152 |
Point2D pt = proj.createPoint( x, y);
|
153 |
((DxfPolyline) lastEntity).add(pt); |
154 |
if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt; |
155 |
int cnt = ((DxfPolyline) lastEntity).pts.size();
|
156 |
Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge); |
157 |
((DxfPolyline) lastEntity).pts.remove(cnt-1);
|
158 |
for (int i=0; i<arc.size(); i++) { |
159 |
pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY()); |
160 |
((DxfPolyline) lastEntity).add(pt); |
161 |
if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt; |
162 |
} |
163 |
bulge = bulge_aux; |
164 |
} |
165 |
} |
166 |
public void createLwPolyline(DxfGroupVector grp) throws Exception { |
167 |
double x = 0.0, y = 0.0, elev=0.0; |
168 |
DxfGroup g = null;
|
169 |
|
170 |
if (grp.hasCode(38)) |
171 |
elev = grp.getDataAsDouble(38);
|
172 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
173 |
DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
|
174 |
for (int i=0; i<grp.size(); i++) { |
175 |
g = (DxfGroup) grp.get(i); |
176 |
if (g.getCode() == 10) |
177 |
x = ((Float) g.getData()).doubleValue();
|
178 |
else if (g.getCode() == 20) { |
179 |
y = ((Float) g.getData()).doubleValue();
|
180 |
//if (y <= 1.0) throw new Exception("Y == "+y);
|
181 |
entity.add( proj.createPoint( x, y ) ); |
182 |
x = 0.0; y = 0.0; |
183 |
} |
184 |
} |
185 |
if (grp.hasCode(62)) |
186 |
entity.dxfColor = grp.getDataAsInt(62);
|
187 |
if (grp.hasCode(70)) |
188 |
entity.flags = grp.getDataAsInt(70);
|
189 |
if (addingToBlock == false) { |
190 |
entities.add(entity); |
191 |
} else {
|
192 |
System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator); |
193 |
blk.add(entity); |
194 |
} |
195 |
} |
196 |
public void createLine(DxfGroupVector grp) throws Exception { |
197 |
double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0; |
198 |
DxfGroup g = null;
|
199 |
Point2D pt1 = null, pt2 = null; |
200 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
201 |
|
202 |
x = grp.getDataAsDouble(10);
|
203 |
y = grp.getDataAsDouble(20);
|
204 |
if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30); |
205 |
pt1 = proj.createPoint(x, y); |
206 |
x = grp.getDataAsDouble(11);
|
207 |
y = grp.getDataAsDouble(21);
|
208 |
if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31); |
209 |
pt2 = proj.createPoint(x, y); |
210 |
if (grp.hasCode(210)) |
211 |
xtruX = grp.getDataAsDouble(210);
|
212 |
if (grp.hasCode(220)) |
213 |
xtruY = grp.getDataAsInt(220);
|
214 |
if (grp.hasCode(230)) |
215 |
xtruZ = grp.getDataAsInt(230);
|
216 |
Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
|
217 |
Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
|
218 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
219 |
Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
220 |
Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
221 |
pt1.setLocation(point_out1); |
222 |
pt2.setLocation(point_out2); |
223 |
DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
|
224 |
if (grp.hasCode(62)) { |
225 |
entity.dxfColor = grp.getDataAsInt(62);
|
226 |
} |
227 |
if (addingToBlock == false) { |
228 |
System.out.println("createLine(): A?adimos una linea a la lista de entidades"); |
229 |
entities.add(entity); |
230 |
} else {
|
231 |
System.out.println("createLine(): A?adimos una linea al bloque " + iterator); |
232 |
blk.add(entity); |
233 |
} |
234 |
} |
235 |
public void createText(DxfGroupVector grp) throws Exception { |
236 |
double x = 0.0, y = 0.0, h= 0.0, rot= 0.0; |
237 |
DxfGroup g = null;
|
238 |
Point2D pt1 = null, pt2 = null; |
239 |
String txt = null; |
240 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
241 |
|
242 |
txt = grp.getDataAsString(1);
|
243 |
DxfText entity = new DxfText(proj, layer, txt);
|
244 |
|
245 |
x = grp.getDataAsDouble(10);
|
246 |
y = grp.getDataAsDouble(20);
|
247 |
entity.setPt1(proj.createPoint(x, y)); |
248 |
if (grp.hasCode(11)) { |
249 |
x = grp.getDataAsDouble(11);
|
250 |
y = grp.getDataAsDouble(21);
|
251 |
entity.setPt2(proj.createPoint(x, y)); |
252 |
} |
253 |
entity.h = grp.getDataAsDouble(40);
|
254 |
if (grp.hasCode(50)) |
255 |
entity.rot = grp.getDataAsDouble(50);
|
256 |
if (grp.hasCode(62)) |
257 |
entity.dxfColor = grp.getDataAsInt(62);
|
258 |
if (grp.hasCode(72)) |
259 |
entity.align = grp.getDataAsInt(72);
|
260 |
if (addingToBlock == false) { |
261 |
entities.add(entity); |
262 |
} else {
|
263 |
System.out.println("createText(): A?adimos un text al bloque " + iterator); |
264 |
blk.add(entity); |
265 |
} |
266 |
} |
267 |
public void createPoint(DxfGroupVector grp) throws Exception { |
268 |
double x = 0.0, y = 0.0, z = 0.0; //, h= 0.0, rot= 0.0; |
269 |
DxfGroup g = null;
|
270 |
Point2D pt = null; |
271 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
272 |
|
273 |
DxfPoint entity = new DxfPoint(proj, layer);
|
274 |
|
275 |
x = grp.getDataAsDouble(10);
|
276 |
y = grp.getDataAsDouble(20);
|
277 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
278 |
if (grp.hasCode(62)) |
279 |
entity.dxfColor = grp.getDataAsInt(62);
|
280 |
if (grp.hasCode(210)) |
281 |
xtruX = grp.getDataAsDouble(210);
|
282 |
if (grp.hasCode(220)) |
283 |
xtruY = grp.getDataAsInt(220);
|
284 |
if (grp.hasCode(230)) |
285 |
xtruZ = grp.getDataAsInt(230);
|
286 |
Point3D point_in = new Point3D(x, y, z);
|
287 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
288 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
289 |
x = point_out.getX(); |
290 |
y = point_out.getY(); |
291 |
entity.setPt(proj.createPoint(x, y)); |
292 |
if (addingToBlock == false) { |
293 |
entities.add(entity); |
294 |
} else {
|
295 |
System.out.println("createPoint(): A?adimos un punto al bloque " + iterator); |
296 |
blk.add(entity); |
297 |
} |
298 |
} |
299 |
public void createCircle(DxfGroupVector grp) throws Exception { |
300 |
double x = 0.0, y = 0.0, z = 0.0; |
301 |
double r = 0.0; |
302 |
DxfGroup g = null;
|
303 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
304 |
|
305 |
x = grp.getDataAsDouble(10);
|
306 |
y = grp.getDataAsDouble(20);
|
307 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
308 |
if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
309 |
if (grp.hasCode(210)) |
310 |
xtruX = grp.getDataAsDouble(210);
|
311 |
if (grp.hasCode(220)) |
312 |
xtruY = grp.getDataAsDouble(220);
|
313 |
if (grp.hasCode(230)) |
314 |
xtruZ = grp.getDataAsDouble(230);
|
315 |
Point3D point_in = new Point3D(x, y, z);
|
316 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
317 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
318 |
x = point_out.getX(); |
319 |
y = point_out.getY(); |
320 |
|
321 |
Point2D center = proj.createPoint( x, y);
|
322 |
Point2D[] pts = new Point2D[360]; |
323 |
int angulo = 0; |
324 |
for (angulo=0; angulo<360; angulo++) { |
325 |
pts[angulo] = new Point2D.Double(center.getX(), center.getY()); |
326 |
pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0)); |
327 |
if (pts.length == 1) { |
328 |
firstPt = pts[angulo]; |
329 |
} |
330 |
} |
331 |
DxfCircle entity = new DxfCircle(proj, layer, pts);
|
332 |
if (grp.hasCode(62)) |
333 |
entity.dxfColor = grp.getDataAsInt(62);
|
334 |
if (addingToBlock == false) { |
335 |
System.out.println("createCircle(): A?ade un circulo a la lista de entidades"); |
336 |
entities.add(entity); |
337 |
} else {
|
338 |
System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator); |
339 |
blk.add(entity); |
340 |
} |
341 |
} |
342 |
public void createArc(DxfGroupVector grp) throws Exception { |
343 |
double x = 0.0, y = 0.0, z = 0.0; |
344 |
double r = 0.0, empieza = 0.0, acaba = 0.0; |
345 |
DxfGroup g = null;
|
346 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
347 |
|
348 |
x = grp.getDataAsDouble(10);
|
349 |
y = grp.getDataAsDouble(20);
|
350 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
351 |
if (grp.hasCode(40)) r = grp.getDataAsDouble(40); |
352 |
if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50); |
353 |
if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51); |
354 |
if (grp.hasCode(210)) |
355 |
xtruX = grp.getDataAsDouble(210);
|
356 |
if (grp.hasCode(220)) |
357 |
xtruY = grp.getDataAsDouble(220);
|
358 |
if (grp.hasCode(230)) |
359 |
xtruZ = grp.getDataAsDouble(230);
|
360 |
Point3D point_in = new Point3D(x, y, z);
|
361 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
362 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
363 |
x = point_out.getX(); |
364 |
y = point_out.getY(); |
365 |
|
366 |
Point2D center = proj.createPoint( x, y);
|
367 |
System.out.println("empieza = " + empieza + ", acaba = " + acaba); |
368 |
int iempieza = (int)empieza; |
369 |
int iacaba = (int)acaba; |
370 |
System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba); |
371 |
double angulo = 0; |
372 |
Point2D[] pts = null; |
373 |
if (empieza <= acaba) {
|
374 |
pts = new Point2D[(iacaba-iempieza)+2]; |
375 |
angulo = empieza; |
376 |
pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
377 |
for (int i=1; i<=(iacaba-iempieza)+1; i++) { |
378 |
angulo = (double)(iempieza+i);
|
379 |
pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
380 |
} |
381 |
angulo = acaba; |
382 |
pts[(iacaba-iempieza)+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
383 |
} else {
|
384 |
pts = new Point2D[(360-iempieza)+iacaba+2]; |
385 |
angulo = empieza; |
386 |
System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo); |
387 |
pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
388 |
for (int i=1; i<=(360-iempieza); i++) { |
389 |
angulo = (double)(iempieza+i);
|
390 |
pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
391 |
} |
392 |
for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) { |
393 |
angulo = (double)(i-(360-iempieza)); |
394 |
pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
395 |
} |
396 |
angulo = acaba; |
397 |
pts[(360-iempieza)+iacaba+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0)); |
398 |
} |
399 |
DxfArc entity = new DxfArc(proj, layer, pts);
|
400 |
if (grp.hasCode(62)) |
401 |
entity.dxfColor = grp.getDataAsInt(62);
|
402 |
System.out.println("createArc(): A?ade un arco a la lista de entidades"); |
403 |
if (addingToBlock == false) { |
404 |
entities.add(entity); |
405 |
} else {
|
406 |
System.out.println("createArc(): A?adimos un arco al bloque " + iterator); |
407 |
blk.add(entity); |
408 |
} |
409 |
} |
410 |
public void createInsert(DxfGroupVector grp) throws Exception { |
411 |
double x = 0.0, y = 0.0, z = 0.0; |
412 |
DxfGroup g = null;
|
413 |
Point2D pt = new Point2D.Double(0.0, 0.0); |
414 |
Point2D scaleFactor = new Point2D.Double(1.0, 1.0); |
415 |
double rotAngle = 0.0; |
416 |
String blockName = ""; |
417 |
//boolean findFlag = false;
|
418 |
|
419 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
420 |
|
421 |
//DxfBlock block = new DxfBlock(proj);
|
422 |
|
423 |
//if (findFlag == false) System.out.println("createInsert: No se ha encontrado ningun bloque.");
|
424 |
|
425 |
DxfInsert entity = new DxfInsert(proj, layer);
|
426 |
|
427 |
if (grp.hasCode(2)) { |
428 |
blockName = grp.getDataAsString(2);
|
429 |
entity.setBlockName(blockName); |
430 |
} |
431 |
if (grp.hasCode(10)) x = grp.getDataAsDouble(10); |
432 |
if (grp.hasCode(20)) y = grp.getDataAsDouble(20); |
433 |
if (grp.hasCode(30)) z = grp.getDataAsDouble(30); |
434 |
if (grp.hasCode(41)) { |
435 |
scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
|
436 |
entity.setScaleFactor(scaleFactor); |
437 |
} else {
|
438 |
entity.setScaleFactor(scaleFactor); |
439 |
} |
440 |
if (grp.hasCode(42)) { |
441 |
scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
|
442 |
entity.setScaleFactor(scaleFactor); |
443 |
} else {
|
444 |
entity.setScaleFactor(scaleFactor); |
445 |
} |
446 |
if (grp.hasCode(43)) { |
447 |
//scaleFactor.setLocation(scaleFactor.getX(), scaleFactor.getY());
|
448 |
//entity.setScaleFactor(scaleFactor);
|
449 |
} |
450 |
if (grp.hasCode(50)) { |
451 |
rotAngle = grp.getDataAsDouble(50);
|
452 |
entity.setRotAngle(rotAngle); |
453 |
|
454 |
// ?Hay que restarle 30? ?por que? ??????
|
455 |
//if (!(rotAngle == 0.0)) entity.setRotAngle(rotAngle-30);
|
456 |
|
457 |
} |
458 |
if (grp.hasCode(62)) |
459 |
entity.dxfColor = grp.getDataAsInt(62);
|
460 |
if (grp.hasCode(210)) |
461 |
xtruX = grp.getDataAsDouble(210);
|
462 |
if (grp.hasCode(220)) |
463 |
xtruY = grp.getDataAsDouble(220);
|
464 |
if (grp.hasCode(230)) |
465 |
xtruZ = grp.getDataAsDouble(230);
|
466 |
Point3D point_in = new Point3D(x, y, z);
|
467 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
468 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
469 |
x = point_out.getX(); |
470 |
y = point_out.getY(); |
471 |
|
472 |
entity.setPt(proj.createPoint(x, y)); |
473 |
|
474 |
entity.setBlkList(blkList); |
475 |
|
476 |
/*boolean found = false;
|
477 |
Iterator iter = blocks.entities.iterator();
|
478 |
DxfEntityList b = null;
|
479 |
|
480 |
int numBlocks = blocks.entities.size();
|
481 |
System.out.println(numBlocks);
|
482 |
|
483 |
while (iter.hasNext()) {
|
484 |
b = (DxfEntityList)iter.next();
|
485 |
|
486 |
System.out.println("NBLOCK = " + b.getAttribute("NBLOCK") + ", bname = " + blockName);
|
487 |
if (b.getAttribute("NBLOCK").equals(blockName)) {
|
488 |
Point2D c = new Point2D.Double(x,y);
|
489 |
DxfEntityList gc = b;
|
490 |
System.err.print("Rotacion = " + rotAngle);
|
491 |
b = DxfInsert.moveGeometryCollection( gc, c, scaleFactor, rotAngle);
|
492 |
entities.add(b);
|
493 |
|
494 |
found = true;
|
495 |
System.out.println("ENCONTRADO");
|
496 |
break;
|
497 |
}
|
498 |
}
|
499 |
if (! found) {
|
500 |
System.out.println("NO ENCONTRADO"+ blockName);
|
501 |
|
502 |
//b.setGeometry(new GeometryFactory(DPM,0).createPoint(new Coordinate(x,y,z)));
|
503 |
entity.setPt(proj.createPoint(x, y));
|
504 |
|
505 |
//int aux = feature.getID();
|
506 |
//if (debug) System.out.println("AUXXXXXXXXXXXXXXX = " + aux);
|
507 |
//DxfEntity block = null;
|
508 |
//block = feature.getGeometry();
|
509 |
String marca = (String) blockName;
|
510 |
Double xx = new Double(x);
|
511 |
Double yy = new Double(y);
|
512 |
//Double zz = new Double(z);
|
513 |
Double xxscale = new Double(scaleFactor.getX());
|
514 |
Double yyscale = new Double(scaleFactor.getY());
|
515 |
Double zzscale = new Double(scaleFactor.getZ());
|
516 |
Double aangle = new Double(rotAngle);
|
517 |
Object datos[] = new Object[8];
|
518 |
datos[0] = marca;
|
519 |
datos[1] = xx;
|
520 |
datos[2] = yy;
|
521 |
//datos[3] = zz;
|
522 |
datos[4] = xxscale;
|
523 |
datos[5] = yyscale;
|
524 |
datos[6] = zzscale;
|
525 |
datos[7] = aangle;
|
526 |
block.setUserData(datos);
|
527 |
entities.add(b);
|
528 |
}*/
|
529 |
|
530 |
entity.encuentraBloque(blockName); |
531 |
|
532 |
gestionaInsert(blk, entity, layer); |
533 |
|
534 |
if (addingToBlock == false) { |
535 |
//entities.add(entity);
|
536 |
} else {
|
537 |
System.out.println("createArc(): A?adimos un arco al bloque " + iterator); |
538 |
blk.add(entity); |
539 |
} |
540 |
|
541 |
/*if (addingToBlock == false) {
|
542 |
System.out.println("createInsert(): A?adimos un insert a la lista de entidades");
|
543 |
entities.add(entity);
|
544 |
} else {
|
545 |
System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
|
546 |
blk.add(entity);
|
547 |
}*/
|
548 |
} |
549 |
public void createSolid(DxfGroupVector grp) throws Exception { |
550 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
551 |
} |
552 |
public void createBlock(DxfGroupVector grp) throws Exception { |
553 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
554 |
blk = new DxfBlock(proj);
|
555 |
|
556 |
Point3D basePoint = new Point3D();
|
557 |
String blockName = ""; |
558 |
System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator); |
559 |
|
560 |
addingToBlock = true;
|
561 |
System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques"); |
562 |
blkList.add(iterator, blk); |
563 |
|
564 |
System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator); |
565 |
if (grp.hasCode(1)) { |
566 |
blockName = grp.getDataAsString(1);
|
567 |
blk.setBlkName(blockName); |
568 |
} |
569 |
if (grp.hasCode(2)) { |
570 |
blockName = grp.getDataAsString(2);
|
571 |
blk.setBlkName(blockName); |
572 |
} |
573 |
if (grp.hasCode(3)) { |
574 |
blockName = grp.getDataAsString(3);
|
575 |
blk.setBlkName(blockName); |
576 |
} |
577 |
if (grp.hasCode(10)) { |
578 |
basePoint.X = grp.getDataAsDouble(10);
|
579 |
blk.setBasePoint(basePoint); |
580 |
} |
581 |
if (grp.hasCode(20)) { |
582 |
basePoint.Y = grp.getDataAsDouble(20);
|
583 |
blk.setBasePoint(basePoint); |
584 |
} |
585 |
if (grp.hasCode(30)) { |
586 |
basePoint.Z = grp.getDataAsDouble(30);
|
587 |
blk.setBasePoint(basePoint); |
588 |
} |
589 |
if (grp.hasCode(70)) { |
590 |
blk.flags = grp.getDataAsInt(70);
|
591 |
} |
592 |
} |
593 |
public void endBlk(DxfGroupVector grp) throws Exception { |
594 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
595 |
setAddingToBlock(false);
|
596 |
iterator = iterator + 1;
|
597 |
} |
598 |
|
599 |
public Projection getProjection() { return proj;} |
600 |
|
601 |
/**
|
602 |
* Cambia de proyeccion.
|
603 |
*
|
604 |
* @param rp
|
605 |
*/
|
606 |
public void reProject(ReProjection rp) { |
607 |
entities.reProject(rp); |
608 |
} |
609 |
public DxfEntityList getEntities() { return entities;} |
610 |
public DxfTable getLayers() { return layers;} |
611 |
|
612 |
public void gestionaInsert(DxfBlock blk, DxfInsert entity, DxfLayer layer) { |
613 |
DxfEntity dxfEntity = null;
|
614 |
DxfLine dxfLine = null;
|
615 |
DxfInsert dxfInsert = null;
|
616 |
DxfPolyline dxfPolyline = null;
|
617 |
DxfArc dxfArc = null;
|
618 |
DxfCircle dxfCircle = null;
|
619 |
DxfLwPolyline dxfLwPolyline = null;
|
620 |
DxfPoint dxfPoint = null;
|
621 |
DxfText dxfText = null;
|
622 |
for (int i=0; i<entity.block.blkElements.size(); i++) { |
623 |
System.out.println("gestionaInserts: entity.block.blkElements.size() = " + entity.block.blkElements.size()); |
624 |
dxfEntity = (DxfEntity)entity.block.blkElements.get(i); |
625 |
|
626 |
Point2D point1 = new Point2D.Double(); |
627 |
Point2D point2 = new Point2D.Double(); |
628 |
Point2D point11 = new Point2D.Double(); |
629 |
Point2D point22 = new Point2D.Double(); |
630 |
if (dxfEntity instanceof DxfLine) { |
631 |
dxfLine = (DxfLine)dxfEntity; |
632 |
//dxfLine = entity.moveDxfLine(dxfLine, entity.pt, entity.scaleFactor, entity.rotAngle);
|
633 |
point1 = dxfLine.getPts()[0];
|
634 |
System.out.println("entity.pt.getX() = " + entity.pt.getX()); |
635 |
System.out.println("point1.getX() = " + point1.getX()); |
636 |
System.out.println("entity.rotAngle = " + entity.rotAngle); |
637 |
|
638 |
//x = (c2.getX()*Math.cos(alfa) + c2.getY()*(-1)*Math.sin(alfa)) * scale.getX();
|
639 |
//y = (c2.getX()*Math.sin(alfa) + c2.getY()*Math.cos(alfa)) * scale.getY();
|
640 |
|
641 |
point11.setLocation(entity.pt.getX() + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
642 |
//entity.add(point11);
|
643 |
point2 = dxfLine.getPts()[1];
|
644 |
point22.setLocation(entity.pt.getX() + ((point2.getX()*Math.cos((entity.rotAngle*Math.PI)/180) + point2.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((point2.getX()*Math.sin((entity.rotAngle*Math.PI)/180) + point2.getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
645 |
//entity.add(point22);
|
646 |
|
647 |
DxfLine dxfLinee = new DxfLine(proj, layer, point11, point22);
|
648 |
entities.add(dxfLinee); |
649 |
/*if (addingToBlock == false) {
|
650 |
entities.add(dxfLine);
|
651 |
} else {
|
652 |
System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
|
653 |
blk.add(dxfLine);
|
654 |
}*/
|
655 |
} else if (dxfEntity instanceof DxfInsert){ |
656 |
//Vector points = new Vector();
|
657 |
dxfInsert = (DxfInsert)dxfEntity; |
658 |
String name1 = dxfInsert.blockName;
|
659 |
System.out.println("INSERTS: name1 = " + name1); |
660 |
point1 = dxfInsert.pt; |
661 |
point11.setLocation(entity.pt.getX() + point1.getX(), entity.pt.getY() + point1.getY()); |
662 |
//dxfInsert.pt = point11;
|
663 |
System.out.println("INSERTS: point1 = " + point1); |
664 |
System.out.println("INSERTS: point11 = " + point11); |
665 |
double rot = dxfInsert.rotAngle;
|
666 |
System.out.println("INSERTS: rot = " + rot); |
667 |
Point2D scale1 = new Point2D.Double(); |
668 |
Point2D scale11 = new Point2D.Double(); |
669 |
scale1 = dxfInsert.scaleFactor; |
670 |
scale11.setLocation(entity.scaleFactor.getX() * scale1.getX(), entity.scaleFactor.getY() * scale1.getY()); |
671 |
//dxfInsert.scaleFactor = scale11;
|
672 |
System.out.println("INSERTS: scale1 = " + scale1); |
673 |
System.out.println("INSERTS: scale11 = " + scale11); |
674 |
DxfBlock bl = new DxfBlock(proj);
|
675 |
bl = dxfInsert.getDxfBlock(); |
676 |
String name2 = bl.blkName;
|
677 |
System.out.println("INSERTS: name2 = " + name2); |
678 |
|
679 |
/*for (int j=0; j<dxfInsert.pts.size(); j++) {
|
680 |
System.out.println("PILTRAFILLA: dxfInsert.pts.get(j) = " + dxfInsert.pts.get(j));
|
681 |
points.add(j, dxfInsert.pts.get(j));
|
682 |
point1 = (Point2D)points.get(j);
|
683 |
point11.setLocation(entity.pt.getX() + ((point1.getX()*Math.cos(entity.rotAngle) + point1.getY()*(-1)*Math.sin(entity.rotAngle)) * entity.scaleFactor.getX()), entity.pt.getY() + ((point1.getX()*Math.sin(entity.rotAngle) + point1.getY()*Math.cos(entity.rotAngle)) * entity.scaleFactor.getY()));
|
684 |
entity.add(point11);
|
685 |
}*/
|
686 |
|
687 |
// Esto no ha hecho na? ????
|
688 |
//dxfInsert.pt.setLocation(entity.pt.getX() + dxfInsert.pt.getX(), entity.pt.getY() + dxfInsert.pt.getY());
|
689 |
/*if (addingToBlock == false) {
|
690 |
System.out.println("INSERTS: A las entidades no les a?adimos el INSERT");
|
691 |
} else {
|
692 |
blk.add(entity);
|
693 |
}*/
|
694 |
gestionaInsert(bl, dxfInsert, layer); |
695 |
} else if (dxfEntity instanceof DxfPolyline) { |
696 |
dxfPolyline = (DxfPolyline)dxfEntity; |
697 |
DxfPolyline dxfPolylinee = new DxfPolyline(proj, layer);
|
698 |
Point2D[] points = new Point2D[dxfPolyline.pts.size()]; |
699 |
Point2D[] pointss = new Point2D[dxfPolyline.pts.size()]; |
700 |
for (int j=0; j<dxfPolyline.pts.size(); j++) { |
701 |
points[j] = (Point2D)dxfPolyline.pts.get(j);
|
702 |
pointss[j] = new Point2D.Double(); |
703 |
pointss[j].setLocation(entity.pt.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
704 |
dxfPolylinee.add(pointss[j]); |
705 |
} |
706 |
entities.add(dxfPolylinee); |
707 |
} else if (dxfEntity instanceof DxfArc) { |
708 |
dxfArc = (DxfArc)dxfEntity; |
709 |
Point2D[] points = new Point2D[dxfArc.pts.length]; |
710 |
Point2D[] pointss = new Point2D[dxfArc.pts.length]; |
711 |
for (int j=0; j<dxfArc.pts.length; j++) { |
712 |
points[j] = (Point2D)dxfArc.pts[j];
|
713 |
pointss[j] = new Point2D.Double(); |
714 |
pointss[j].setLocation(entity.pt.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
715 |
} |
716 |
DxfArc dxfArcc = new DxfArc(proj, layer, pointss);
|
717 |
entities.add(dxfArc); |
718 |
} else if (dxfEntity instanceof DxfCircle) { |
719 |
dxfCircle = (DxfCircle)dxfEntity; |
720 |
Point2D[] points = new Point2D[dxfCircle.pts.length]; |
721 |
Point2D[] pointss = new Point2D[dxfCircle.pts.length]; |
722 |
for (int j=0; j<dxfCircle.pts.length; j++) { |
723 |
points[j] = (Point2D)dxfCircle.pts[j];
|
724 |
System.out.println("pointss[" + j + "] = " + pointss[j]); |
725 |
System.out.println("entity.pt.getX() = " + entity.pt.getX()); |
726 |
System.out.println("points[j].getX() = " + points[j].getX()); |
727 |
System.out.println("entity.rotAngle = " + entity.rotAngle); |
728 |
System.out.println("points[j].getY() = " + points[j].getY()); |
729 |
System.out.println("entity.scaleFactor.getX() = " + entity.scaleFactor.getX()); |
730 |
System.out.println("entity.pt.getY() = " + entity.pt.getY()); |
731 |
pointss[j] = new Point2D.Double(); |
732 |
pointss[j].setLocation(entity.pt.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
733 |
} |
734 |
DxfCircle dxfCirclee = new DxfCircle(proj, layer, pointss);
|
735 |
entities.add(dxfCirclee); |
736 |
} else if (dxfEntity instanceof DxfLwPolyline) { |
737 |
dxfLwPolyline = (DxfLwPolyline)dxfEntity; |
738 |
DxfLwPolyline dxfLwPolylinee = new DxfLwPolyline(proj, layer);
|
739 |
Point2D[] points = new Point2D[dxfLwPolyline.pts.size()]; |
740 |
Point2D[] pointss = new Point2D[dxfLwPolyline.pts.size()]; |
741 |
for (int j=0; j<dxfLwPolyline.pts.size(); j++) { |
742 |
points[j] = (Point2D)dxfLwPolyline.pts.get(j);
|
743 |
pointss[j] = new Point2D.Double(); |
744 |
pointss[j].setLocation(entity.pt.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
745 |
dxfLwPolylinee.add(pointss[j]); |
746 |
} |
747 |
entities.add(dxfLwPolylinee); |
748 |
} else if (dxfEntity instanceof DxfPoint) { |
749 |
dxfPoint = (DxfPoint)dxfEntity; |
750 |
point1 = dxfPoint.pt; |
751 |
point11.setLocation(entity.pt.getX() + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
752 |
DxfPoint dxfPointt = new DxfPoint(proj, layer);
|
753 |
dxfPointt.pt = point11; |
754 |
entities.add(dxfPointt); |
755 |
} else if (dxfEntity instanceof DxfText) { |
756 |
dxfText = (DxfText)dxfEntity; |
757 |
point1 = dxfText.pts[0];
|
758 |
point11.setLocation(entity.pt.getX() + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
759 |
point2 = dxfText.pts[1];
|
760 |
point22.setLocation(entity.pt.getX() + ((point2.getX()*Math.cos((entity.rotAngle*Math.PI)/180) + point2.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getX()), entity.pt.getY() + ((point2.getX()*Math.sin((entity.rotAngle*Math.PI)/180) + point2.getY()*Math.cos((entity.rotAngle*Math.PI)/180)) * entity.scaleFactor.getY())); |
761 |
DxfText dxfTextt = new DxfText(proj, layer, dxfText.text);
|
762 |
dxfTextt.pts[0] = point11;
|
763 |
dxfTextt.pts[1] = point22;
|
764 |
entities.add(dxfTextt); |
765 |
} else {
|
766 |
System.out.println("gestionaInserts: Encontrado elemento desconocido"); |
767 |
} |
768 |
} |
769 |
} |
770 |
|
771 |
} |