svn-gvsig-desktop / tags / v1_0_2_Build_907 / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfEntityMaker.java @ 11015
History | View | Annotate | Download (87.9 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.px.dxf; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import org.cresques.geo.Point3D; |
30 |
import org.cresques.geo.Projected; |
31 |
|
32 |
import org.cresques.io.DxfFile; |
33 |
import org.cresques.io.DxfGroup; |
34 |
import org.cresques.io.DxfGroupVector; |
35 |
|
36 |
import org.cresques.px.Extent; |
37 |
import org.cresques.px.IObjList; |
38 |
|
39 |
import java.awt.geom.Point2D; |
40 |
|
41 |
import java.util.Vector; |
42 |
|
43 |
|
44 |
/**
|
45 |
* La clase DxfEntityMaker facilita la creaci?n de entidades en un modelo de datos
|
46 |
* CAD. La creaci?n se realiza partiendo de las entidades obtenidas de un fichero DXF.
|
47 |
* @author jmorell
|
48 |
*/
|
49 |
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected { |
50 |
IProjection proj = null;
|
51 |
DxfEntity lastEntity = null;
|
52 |
DxfEntityList entities = null;
|
53 |
Vector blkList = null; |
54 |
DxfBlock blk = null;
|
55 |
DxfTable layers = null;
|
56 |
double bulge = 0.0; |
57 |
double xtruX = 0.0; |
58 |
double xtruY = 0.0; |
59 |
double xtruZ = 1.0; |
60 |
int polylineFlag = 0; |
61 |
Point2D firstPt = new Point2D.Double(); |
62 |
boolean addingToBlock = false; |
63 |
int iterator = 0; |
64 |
|
65 |
// jmorell, 050406: implementaci?n inicial de los ATTRIBS para el piloto ...
|
66 |
private Vector attributes = null; |
67 |
|
68 |
/**
|
69 |
* Constructor de DxfEntityMaker.
|
70 |
* @param proj, proyecci?n cartogr?fica en la que se encontrar?n las entidades
|
71 |
* que creemos.
|
72 |
*/
|
73 |
public DxfEntityMaker(IProjection proj) {
|
74 |
this.proj = proj;
|
75 |
layers = new DxfTable();
|
76 |
entities = new DxfEntityList(proj);
|
77 |
blkList = new Vector(); |
78 |
|
79 |
// jmorell, 050406: implementaci?n inicial de los ATTRIBS para el piloto ...
|
80 |
attributes = new Vector(); |
81 |
} |
82 |
|
83 |
/* (non-Javadoc)
|
84 |
* @see org.cresques.io.DxfFile.EntityFactory#getBlkList()
|
85 |
*/
|
86 |
public Vector getBlkList() { |
87 |
return blkList;
|
88 |
} |
89 |
|
90 |
/* (non-Javadoc)
|
91 |
* @see org.cresques.io.DxfFile.EntityFactory#getObjects()
|
92 |
*/
|
93 |
public IObjList getObjects() {
|
94 |
return entities;
|
95 |
} |
96 |
|
97 |
/* (non-Javadoc)
|
98 |
* @see org.cresques.io.DxfFile.EntityFactory#getExtent()
|
99 |
*/
|
100 |
public Extent getExtent() {
|
101 |
return entities.getExtent();
|
102 |
} |
103 |
|
104 |
/* (non-Javadoc)
|
105 |
* @see org.cresques.io.DxfFile.EntityFactory#setAddingToBlock(boolean)
|
106 |
*/
|
107 |
public void setAddingToBlock(boolean a) { |
108 |
addingToBlock = a; |
109 |
} |
110 |
|
111 |
/* (non-Javadoc)
|
112 |
* @see org.cresques.io.DxfFile.EntityFactory#createLayer(org.cresques.io.DxfGroupVector)
|
113 |
*/
|
114 |
public void createLayer(DxfGroupVector grp) throws Exception { |
115 |
int color = grp.getDataAsInt(62); |
116 |
DxfLayer layer = new DxfLayer(grp.getDataAsString(2), |
117 |
Math.abs(grp.getDataAsInt(62))); |
118 |
|
119 |
if (color < 0) { |
120 |
layer.isOff = true;
|
121 |
} |
122 |
|
123 |
layer.lType = grp.getDataAsString(6);
|
124 |
layer.setFlags(grp.getDataAsInt(70));
|
125 |
|
126 |
// compruebo flags
|
127 |
if ((layer.flags & 0x01) == 0x01) { |
128 |
layer.frozen = true;
|
129 |
} |
130 |
|
131 |
if ((layer.flags & 0x02) == 0x02) { |
132 |
layer.frozen = true;
|
133 |
} |
134 |
|
135 |
System.out.println("LAYER color=" + layer.getColor()); |
136 |
|
137 |
layers.add(layer); |
138 |
} |
139 |
|
140 |
/* (non-Javadoc)
|
141 |
* @see org.cresques.io.DxfFile.EntityFactory#createPolyline(org.cresques.io.DxfGroupVector)
|
142 |
*/
|
143 |
public void createPolyline(DxfGroupVector grp) throws Exception { |
144 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
145 |
DxfPolyline entity = new DxfPolyline(proj, layer);
|
146 |
|
147 |
if (grp.hasCode(5)) { |
148 |
String hexS = grp.getDataAsString(5); |
149 |
Integer hexI = Integer.decode("0x" + hexS); |
150 |
int hexi = hexI.intValue();
|
151 |
entity.setHandle(hexi); |
152 |
} else {
|
153 |
entity.setHandle(entities.size() + 40);
|
154 |
} |
155 |
|
156 |
if (grp.hasCode(100)) { |
157 |
entity.setSubclassMarker(grp.getDataAsString(100));
|
158 |
} |
159 |
|
160 |
double x = 0.0; |
161 |
double y = 0.0; |
162 |
double z = 0.0; |
163 |
double thickness = 0; |
164 |
|
165 |
if (grp.hasCode(10)) { |
166 |
x = grp.getDataAsDouble(10);
|
167 |
} |
168 |
|
169 |
if (grp.hasCode(20)) { |
170 |
y = grp.getDataAsDouble(20);
|
171 |
} |
172 |
|
173 |
if (grp.hasCode(30)) { |
174 |
z = grp.getDataAsDouble(30);
|
175 |
entity.setElevation(z); |
176 |
} |
177 |
|
178 |
/*if (grp.hasCode(39))
|
179 |
System.out.println("Leer el thickness provoca un error");
|
180 |
thickness = grp.getDataAsDouble(39);*/
|
181 |
if (grp.hasCode(62)) { |
182 |
entity.dxfColor = grp.getDataAsInt(62);
|
183 |
} else {
|
184 |
//entity.dxfColor = 0;
|
185 |
} |
186 |
|
187 |
if (grp.hasCode(66)) { |
188 |
entity.entitiesFollow = grp.getDataAsInt(66);
|
189 |
} |
190 |
|
191 |
if (grp.hasCode(70)) { |
192 |
entity.flags = grp.getDataAsInt(70);
|
193 |
} |
194 |
|
195 |
if (grp.hasCode(210)) { |
196 |
xtruX = grp.getDataAsDouble(210);
|
197 |
} |
198 |
|
199 |
if (grp.hasCode(220)) { |
200 |
xtruY = grp.getDataAsDouble(220);
|
201 |
} |
202 |
|
203 |
if (grp.hasCode(230)) { |
204 |
xtruZ = grp.getDataAsDouble(230);
|
205 |
} |
206 |
|
207 |
if ((entity.flags & 0x01) == 0x01) { |
208 |
entity.closed = true;
|
209 |
} |
210 |
|
211 |
lastEntity = entity; |
212 |
} |
213 |
|
214 |
/* (non-Javadoc)
|
215 |
* @see org.cresques.io.DxfFile.EntityFactory#endSeq(org.cresques.io.DxfGroupVector)
|
216 |
*/
|
217 |
public void endSeq() throws Exception { |
218 |
if (lastEntity instanceof DxfPolyline) { |
219 |
DxfPolyline polyline = (DxfPolyline) lastEntity; |
220 |
|
221 |
if (polyline.closed) {
|
222 |
((DxfPolyline) lastEntity).add(firstPt); |
223 |
|
224 |
if (bulge > 0) { |
225 |
int cnt = ((DxfPolyline) lastEntity).pts.size();
|
226 |
|
227 |
if ((((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
228 |
2))).getX() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
229 |
1))).getX()) &&
|
230 |
(((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt -
|
231 |
2))).getY() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
232 |
1))).getY())) {
|
233 |
// no se construye el arco
|
234 |
} else {
|
235 |
Vector arc = DxfPolyline.createArc((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
236 |
2)),
|
237 |
(Point2D) (((DxfPolyline) lastEntity).pts.get(cnt -
|
238 |
1)),
|
239 |
bulge); |
240 |
((DxfPolyline) lastEntity).pts.remove(cnt - 1);
|
241 |
|
242 |
for (int i = 0; i < arc.size(); i++) { |
243 |
Point2D pt = proj.createPoint(((Point2D) arc.get(i)).getX(), |
244 |
((Point2D) arc.get(i)).getY());
|
245 |
((DxfPolyline) lastEntity).add(pt); |
246 |
|
247 |
if (((DxfPolyline) lastEntity).pts.size() == 1) { |
248 |
firstPt = pt; |
249 |
} |
250 |
} |
251 |
} |
252 |
|
253 |
bulge = 0.0;
|
254 |
} else if (bulge < 0) { |
255 |
int cnt = ((DxfPolyline) lastEntity).pts.size();
|
256 |
|
257 |
if ((((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
258 |
2))).getX() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
259 |
1))).getX()) &&
|
260 |
(((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt -
|
261 |
2))).getY() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
262 |
1))).getY())) {
|
263 |
// no se construye el arco
|
264 |
} else {
|
265 |
Vector arc = DxfPolyline.createArc((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
266 |
2)),
|
267 |
(Point2D) (((DxfPolyline) lastEntity).pts.get(cnt -
|
268 |
1)),
|
269 |
bulge); |
270 |
((DxfPolyline) lastEntity).pts.remove(cnt - 1);
|
271 |
|
272 |
for (int i = arc.size() - 1; i >= 0; i--) { |
273 |
Point2D pt = proj.createPoint(((Point2D) arc.get(i)).getX(), |
274 |
((Point2D) arc.get(i)).getY());
|
275 |
((DxfPolyline) lastEntity).add(pt); |
276 |
|
277 |
if (((DxfPolyline) lastEntity).pts.size() == 1) { |
278 |
firstPt = pt; |
279 |
} |
280 |
} |
281 |
} |
282 |
|
283 |
bulge = 0.0;
|
284 |
} |
285 |
} |
286 |
|
287 |
// 050315, jmorell: Para leer Polylines estas tb deben tener vector de bulges.
|
288 |
for (int i = 0; i < ((DxfPolyline) lastEntity).pts.size(); i++) { |
289 |
// jmorell, 050405: intentando leer DxfPolylines con bulges para el
|
290 |
// piloto ...
|
291 |
//polyline.addBulge(new Double(0));
|
292 |
((DxfPolyline) lastEntity).addBulge(new Double(0)); |
293 |
} |
294 |
|
295 |
//System.out.println("DxfEntityMaker.endSeq(): ((DxfPolyline)lastEntity).getBulges().size() = " + ((DxfPolyline)lastEntity).getBulges().size());
|
296 |
//((DxfPolyline)lastEntity).addBulge(new Double(bulge));
|
297 |
//lastEntity.setHandle(entities.size()+40);
|
298 |
if (addingToBlock == false) { |
299 |
//System.out.println("createPolyline: A?adimos una polilinea a la lista de entidades");
|
300 |
entities.add(lastEntity); |
301 |
} else {
|
302 |
//System.out.println("createPolyline: A?adimos una polilinea al bloque " + iterator);
|
303 |
blk.add(lastEntity); |
304 |
|
305 |
//System.out.println("PLINE color="+polyline.getColor());
|
306 |
} |
307 |
|
308 |
lastEntity = null;
|
309 |
} else if (lastEntity instanceof DxfInsert) { |
310 |
// Se trata de un SEQEND despues de un ATTRIB
|
311 |
gestionaInsert((DxfInsert) lastEntity, lastEntity.getLayer()); |
312 |
|
313 |
if (addingToBlock == false) { |
314 |
entities.add(lastEntity); |
315 |
} else {
|
316 |
blk.add(lastEntity); |
317 |
} |
318 |
|
319 |
lastEntity = null;
|
320 |
} else {
|
321 |
// Caso no contemplado
|
322 |
} |
323 |
|
324 |
xtruX = 0.0;
|
325 |
xtruY = 0.0;
|
326 |
xtruZ = 1.0;
|
327 |
bulge = 0.0;
|
328 |
} |
329 |
|
330 |
/* (non-Javadoc)
|
331 |
* @see org.cresques.io.DxfFile.EntityFactory#addVertex(org.cresques.io.DxfGroupVector)
|
332 |
*/
|
333 |
public void addVertex(DxfGroupVector grp) throws Exception { |
334 |
double x = 0.0; |
335 |
double y = 0.0; |
336 |
double z = 0.0; |
337 |
int flags = 0; |
338 |
x = grp.getDataAsDouble(10);
|
339 |
y = grp.getDataAsDouble(20);
|
340 |
|
341 |
if (grp.hasCode(30)) { |
342 |
z = grp.getDataAsDouble(30);
|
343 |
} |
344 |
|
345 |
if (grp.hasCode(70)) { |
346 |
flags = grp.getDataAsInt(70);
|
347 |
} |
348 |
|
349 |
//bulge = 0.0;
|
350 |
if (bulge == 0.0) { |
351 |
if (grp.hasCode(42)) { |
352 |
bulge = grp.getDataAsDouble(42);
|
353 |
|
354 |
//bulge = 0.0;
|
355 |
} else {
|
356 |
bulge = 0.0;
|
357 |
} |
358 |
|
359 |
Point3D point_in = new Point3D(x, y, z);
|
360 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
361 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
362 |
|
363 |
if (((flags & 0x80) == 0x80) && ((flags & 0x40) == 0)) { |
364 |
int[] face = { 0, 0, 0, 0 }; |
365 |
face[0] = grp.getDataAsInt(71); |
366 |
face[1] = grp.getDataAsInt(72); |
367 |
face[2] = grp.getDataAsInt(73); |
368 |
face[3] = grp.getDataAsInt(74); |
369 |
((DxfPolyline) lastEntity).addFace(face); |
370 |
} else {
|
371 |
x = point_out.getX(); |
372 |
y = point_out.getY(); |
373 |
z = point_out.getZ(); |
374 |
|
375 |
Point2D ptaux = proj.createPoint(x, y);
|
376 |
Point3D pt = new Point3D(ptaux.getX(), ptaux.getY(), z);
|
377 |
((DxfPolyline) lastEntity).add(pt); |
378 |
|
379 |
if (((DxfPolyline) lastEntity).pts.size() == 1) { |
380 |
firstPt = pt; |
381 |
} |
382 |
} |
383 |
} else if (bulge > 0.0) { |
384 |
double bulge_aux = 0.0; |
385 |
|
386 |
if (grp.hasCode(42)) { |
387 |
bulge_aux = grp.getDataAsDouble(42);
|
388 |
} else {
|
389 |
bulge_aux = 0.0;
|
390 |
} |
391 |
|
392 |
Point3D point_in = new Point3D(x, y, z);
|
393 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
394 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
395 |
x = point_out.getX(); |
396 |
y = point_out.getY(); |
397 |
z = point_out.getZ(); |
398 |
|
399 |
Point2D ptaux = proj.createPoint(x, y);
|
400 |
Point3D pt = new Point3D(ptaux.getX(), ptaux.getY(), z);
|
401 |
((DxfPolyline) lastEntity).add(pt); |
402 |
|
403 |
if (((DxfPolyline) lastEntity).pts.size() == 1) { |
404 |
firstPt = pt; |
405 |
} |
406 |
|
407 |
int cnt = ((DxfPolyline) lastEntity).pts.size();
|
408 |
|
409 |
if ((((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - 2))).getX() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
410 |
1))).getX()) &&
|
411 |
(((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - 2))).getY() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
412 |
1))).getY())) {
|
413 |
// no se construye el arco
|
414 |
} else {
|
415 |
Vector arc = DxfPolyline.createArc((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
416 |
2)),
|
417 |
(Point2D) (((DxfPolyline) lastEntity).pts.get(cnt -
|
418 |
1)),
|
419 |
bulge); |
420 |
((DxfPolyline) lastEntity).pts.remove(cnt - 1);
|
421 |
|
422 |
for (int i = 0; i < arc.size(); i++) { |
423 |
ptaux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
424 |
((Point2D) arc.get(i)).getY());
|
425 |
pt = new Point3D(ptaux.getX(), ptaux.getY(), z);
|
426 |
((DxfPolyline) lastEntity).add(pt); |
427 |
|
428 |
if (((DxfPolyline) lastEntity).pts.size() == 1) { |
429 |
firstPt = pt; |
430 |
} |
431 |
} |
432 |
} |
433 |
|
434 |
bulge = bulge_aux; |
435 |
} else { //si el bulge es menor que cero. |
436 |
|
437 |
double bulge_aux = 0.0; |
438 |
|
439 |
if (grp.hasCode(42)) { |
440 |
bulge_aux = grp.getDataAsDouble(42); // * (-1.0); |
441 |
} else {
|
442 |
bulge_aux = 0.0;
|
443 |
} |
444 |
|
445 |
Point3D point_in = new Point3D(x, y, z);
|
446 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
447 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
448 |
x = point_out.getX(); |
449 |
y = point_out.getY(); |
450 |
z = point_out.getZ(); |
451 |
|
452 |
Point2D ptaux = proj.createPoint(x, y);
|
453 |
Point3D pt = new Point3D(ptaux.getX(), ptaux.getY(), z);
|
454 |
((DxfPolyline) lastEntity).add(pt); |
455 |
|
456 |
if (((DxfPolyline) lastEntity).pts.size() == 1) { |
457 |
firstPt = pt; |
458 |
} |
459 |
|
460 |
int cnt = ((DxfPolyline) lastEntity).pts.size();
|
461 |
|
462 |
if ((((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - 2))).getX() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
463 |
1))).getX()) &&
|
464 |
(((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - 2))).getY() == ((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
465 |
1))).getY())) {
|
466 |
// no se construye el arco
|
467 |
} else {
|
468 |
Vector arc = DxfPolyline.createArc((Point2D) (((DxfPolyline) lastEntity).pts.get(cnt - |
469 |
2)),
|
470 |
(Point2D) (((DxfPolyline) lastEntity).pts.get(cnt -
|
471 |
1)),
|
472 |
bulge); |
473 |
((DxfPolyline) lastEntity).pts.remove(cnt - 1);
|
474 |
|
475 |
for (int i = arc.size() - 1; i >= 0; i--) { |
476 |
ptaux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
477 |
((Point2D) arc.get(i)).getY());
|
478 |
pt = new Point3D(ptaux.getX(), ptaux.getY(), z);
|
479 |
((DxfPolyline) lastEntity).add(pt); |
480 |
|
481 |
if (((DxfPolyline) lastEntity).pts.size() == 1) { |
482 |
firstPt = pt; |
483 |
} |
484 |
} |
485 |
} |
486 |
|
487 |
bulge = bulge_aux; |
488 |
} |
489 |
|
490 |
/*if (grp.hasCode(5)) {
|
491 |
String hexS = grp.getDataAsString(5);
|
492 |
Integer hexI = Integer.decode("0x" + hexS);
|
493 |
int hexi = hexI.intValue();
|
494 |
lastEntity.setHandle(hexi);
|
495 |
} else {
|
496 |
lastEntity.setHandle(entities.size()+40);
|
497 |
}*/
|
498 |
} |
499 |
|
500 |
/* (non-Javadoc)
|
501 |
* @see org.cresques.io.DxfFile.EntityFactory#createLwPolyline(org.cresques.io.DxfGroupVector)
|
502 |
*/
|
503 |
public void createLwPolyline(DxfGroupVector grp) throws Exception { |
504 |
double x = 0.0; |
505 |
double y = 0.0; |
506 |
double elev = 0.0; |
507 |
DxfGroup g = null;
|
508 |
double extx = 0.0; |
509 |
double exty = 0.0; |
510 |
double extz = 1.0; |
511 |
|
512 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
513 |
DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
|
514 |
|
515 |
if (grp.hasCode(38)) { |
516 |
entity.setElevation(grp.getDataAsDouble(38));
|
517 |
} |
518 |
|
519 |
if (grp.hasCode(5)) { |
520 |
String hexS = grp.getDataAsString(5); |
521 |
Integer hexI = Integer.decode("0x" + hexS); |
522 |
int hexi = hexI.intValue();
|
523 |
entity.setHandle(hexi); |
524 |
} else {
|
525 |
entity.setHandle(entities.size() + 40);
|
526 |
} |
527 |
|
528 |
if (grp.hasCode(210)) { |
529 |
extx = grp.getDataAsDouble(210);
|
530 |
} |
531 |
|
532 |
if (grp.hasCode(220)) { |
533 |
exty = grp.getDataAsDouble(220);
|
534 |
} |
535 |
|
536 |
if (grp.hasCode(230)) { |
537 |
extz = grp.getDataAsDouble(230);
|
538 |
} |
539 |
|
540 |
double bulge = 0; |
541 |
boolean isNewCoord = false; |
542 |
|
543 |
for (int i = 0; i < grp.size(); i++) { |
544 |
bulge = 0;
|
545 |
isNewCoord = false;
|
546 |
g = (DxfGroup) grp.get(i); |
547 |
|
548 |
if (g.getCode() == 10) { |
549 |
x = ((Double) g.getData()).doubleValue();
|
550 |
} else if (g.getCode() == 20) { |
551 |
y = ((Double) g.getData()).doubleValue();
|
552 |
|
553 |
// A?adiendo extrusion a LwPolyline ...
|
554 |
Point3D point_in1 = new Point3D(x, y, elev);
|
555 |
Point3D xtru = new Point3D(extx, exty, extz);
|
556 |
Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru); |
557 |
x = point_out1.getX(); |
558 |
y = point_out1.getY(); |
559 |
elev = point_out1.getZ(); |
560 |
|
561 |
//
|
562 |
//if (y <= 1.0) throw new Exception("Y == "+y);
|
563 |
entity.add(proj.createPoint(x, y)); |
564 |
entity.addBulge(new Double(0)); |
565 |
x = 0.0;
|
566 |
y = 0.0;
|
567 |
isNewCoord = true;
|
568 |
} else if (g.getCode() == 42) { |
569 |
//entity.addBulge((Double)g.getData());
|
570 |
entity.getBulges().remove(entity.getBulges().size() - 1);
|
571 |
entity.getBulges().add((Double) g.getData());
|
572 |
bulge = ((Double) g.getData()).doubleValue();
|
573 |
} |
574 |
|
575 |
/*if (bulge == 0 && isNewCoord) {
|
576 |
entity.addBulge(new Double(0));
|
577 |
}*/
|
578 |
} |
579 |
|
580 |
//System.out.println("entity.getPts().size() = " + entity.getPts().size());
|
581 |
//System.out.println("entity.getBulges().size() = " + entity.getBulges().size());
|
582 |
if (grp.hasCode(62)) { |
583 |
entity.dxfColor = grp.getDataAsInt(62);
|
584 |
} else {
|
585 |
//entity.dxfColor = 0;
|
586 |
} |
587 |
|
588 |
if (grp.hasCode(70)) { |
589 |
entity.flags = grp.getDataAsInt(70);
|
590 |
|
591 |
//System.out.println("entity.flags = " + entity.flags);
|
592 |
} |
593 |
|
594 |
if ((entity.flags & 0x01) == 0x01) { |
595 |
entity.closed = true;
|
596 |
} |
597 |
|
598 |
if (addingToBlock == false) { |
599 |
entities.add(entity); |
600 |
} else {
|
601 |
//System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
|
602 |
blk.add(entity); |
603 |
} |
604 |
} |
605 |
|
606 |
/* (non-Javadoc)
|
607 |
* @see org.cresques.io.DxfFile.EntityFactory#createLine(org.cresques.io.DxfGroupVector)
|
608 |
*/
|
609 |
public void createLine(DxfGroupVector grp) throws Exception { |
610 |
double x = 0.0; |
611 |
double y = 0.0; |
612 |
double z1 = 0.0; |
613 |
double z2 = 0.0; |
614 |
DxfGroup g = null;
|
615 |
Point2D pt1 = null; |
616 |
Point2D pt2 = null; |
617 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
618 |
double extx = 0.0; |
619 |
double exty = 0.0; |
620 |
double extz = 1.0; |
621 |
|
622 |
x = grp.getDataAsDouble(10);
|
623 |
y = grp.getDataAsDouble(20);
|
624 |
|
625 |
if (grp.hasCode(30)) { |
626 |
z1 = grp.getDataAsDouble(30);
|
627 |
} |
628 |
|
629 |
pt1 = proj.createPoint(x, y); |
630 |
x = grp.getDataAsDouble(11);
|
631 |
y = grp.getDataAsDouble(21);
|
632 |
|
633 |
if (grp.hasCode(31)) { |
634 |
z2 = grp.getDataAsDouble(31);
|
635 |
} |
636 |
|
637 |
pt2 = proj.createPoint(x, y); |
638 |
|
639 |
if (grp.hasCode(210)) { |
640 |
extx = grp.getDataAsDouble(210);
|
641 |
} |
642 |
|
643 |
if (grp.hasCode(220)) { |
644 |
exty = grp.getDataAsInt(220);
|
645 |
} |
646 |
|
647 |
if (grp.hasCode(230)) { |
648 |
extz = grp.getDataAsInt(230);
|
649 |
} |
650 |
|
651 |
Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
|
652 |
Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
|
653 |
Point3D xtru = new Point3D(extx, exty, extz);
|
654 |
Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
655 |
Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
656 |
pt1.setLocation(point_out1); |
657 |
pt2.setLocation(point_out2); |
658 |
|
659 |
DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
|
660 |
|
661 |
if (grp.hasCode(5)) { |
662 |
String hexS = grp.getDataAsString(5); |
663 |
Integer hexI = Integer.decode("0x" + hexS); |
664 |
int hexi = hexI.intValue();
|
665 |
entity.setHandle(hexi); |
666 |
} else {
|
667 |
entity.setHandle(entities.size() + 40);
|
668 |
} |
669 |
|
670 |
if (grp.hasCode(62)) { |
671 |
entity.dxfColor = grp.getDataAsInt(62);
|
672 |
} else {
|
673 |
//entity.dxfColor = 0;
|
674 |
} |
675 |
|
676 |
if (addingToBlock == false) { |
677 |
//System.out.println("createLine(): A?adimos una linea a la lista de entidades");
|
678 |
entities.add(entity); |
679 |
} else {
|
680 |
//System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
|
681 |
blk.add(entity); |
682 |
} |
683 |
} |
684 |
|
685 |
/* (non-Javadoc)
|
686 |
* @see org.cresques.io.DxfFile.EntityFactory#createText(org.cresques.io.DxfGroupVector)
|
687 |
*/
|
688 |
public void createText(DxfGroupVector grp) throws Exception { |
689 |
double x = 0.0; |
690 |
double y = 0.0; |
691 |
double z = 0.0; |
692 |
double h = 0.0; |
693 |
double rot = 0.0; |
694 |
DxfGroup g = null;
|
695 |
|
696 |
//OJO! El segundo punto es opcional ...
|
697 |
Point2D pt1 = null; |
698 |
|
699 |
//OJO! El segundo punto es opcional ...
|
700 |
Point2D pt2 = null; |
701 |
String txt = null; |
702 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
703 |
|
704 |
txt = grp.getDataAsString(1);
|
705 |
|
706 |
DxfText entity = new DxfText(proj, layer, txt);
|
707 |
double extx = 0.0; |
708 |
double exty = 0.0; |
709 |
double extz = 1.0; |
710 |
|
711 |
x = grp.getDataAsDouble(10);
|
712 |
y = grp.getDataAsDouble(20);
|
713 |
z = grp.getDataAsDouble(30);
|
714 |
|
715 |
if (grp.hasCode(210)) { |
716 |
extx = grp.getDataAsDouble(210);
|
717 |
} |
718 |
|
719 |
if (grp.hasCode(220)) { |
720 |
exty = grp.getDataAsDouble(220);
|
721 |
} |
722 |
|
723 |
if (grp.hasCode(230)) { |
724 |
extz = grp.getDataAsDouble(230);
|
725 |
} |
726 |
|
727 |
Point3D point_in = new Point3D(x, y, z);
|
728 |
Point3D xtru = new Point3D(extx, exty, extz);
|
729 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
730 |
x = point_out.getX(); |
731 |
y = point_out.getY(); |
732 |
z = point_out.getZ(); |
733 |
|
734 |
entity.setPt(proj.createPoint(x, y)); |
735 |
|
736 |
//entity.setPt1(proj.createPoint(x, y));
|
737 |
if (grp.hasCode(11)) { |
738 |
entity.setTwoPointsFlag(true);
|
739 |
entity.setPt1(proj.createPoint(entity.getPt().getX(), |
740 |
entity.getPt().getY())); |
741 |
x = grp.getDataAsDouble(11);
|
742 |
y = grp.getDataAsDouble(21);
|
743 |
z = grp.getDataAsDouble(31);
|
744 |
|
745 |
point_in = new Point3D(x, y, z);
|
746 |
point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
747 |
x = point_out.getX(); |
748 |
y = point_out.getY(); |
749 |
z = point_out.getZ(); |
750 |
|
751 |
entity.setPt2(proj.createPoint(x, y)); |
752 |
} |
753 |
|
754 |
entity.setHeight(grp.getDataAsDouble(40));
|
755 |
|
756 |
if (grp.hasCode(50)) { |
757 |
entity.setRotation(grp.getDataAsDouble(50));
|
758 |
|
759 |
//System.out.println("AAAAAA: entity.getRotation = " + entity.getRotation());
|
760 |
} |
761 |
|
762 |
if (grp.hasCode(62)) { |
763 |
entity.dxfColor = grp.getDataAsInt(62);
|
764 |
} else {
|
765 |
//entity.dxfColor = 0;
|
766 |
} |
767 |
|
768 |
if (grp.hasCode(72)) { |
769 |
entity.align = grp.getDataAsInt(72);
|
770 |
} |
771 |
|
772 |
if (addingToBlock == false) { |
773 |
entities.add(entity); |
774 |
} else {
|
775 |
//System.out.println("createText(): A?adimos un text al bloque " + iterator);
|
776 |
blk.add(entity); |
777 |
} |
778 |
} |
779 |
|
780 |
/* (non-Javadoc)
|
781 |
* @see org.cresques.io.DxfFile.EntityFactory#createMText(org.cresques.io.DxfGroupVector)
|
782 |
*/
|
783 |
public void createMText(DxfGroupVector v) throws Exception { |
784 |
// TODO Auto-generated method stub
|
785 |
} |
786 |
|
787 |
/* (non-Javadoc)
|
788 |
* @see org.cresques.io.DxfFile.EntityFactory#createPoint(org.cresques.io.DxfGroupVector)
|
789 |
*/
|
790 |
public void createPoint(DxfGroupVector grp) throws Exception { |
791 |
double x = 0.0; //, h= 0.0, rot= 0.0; |
792 |
double y = 0.0; //, h= 0.0, rot= 0.0; |
793 |
double z = 0.0; //, h= 0.0, rot= 0.0; |
794 |
DxfGroup g = null;
|
795 |
Point2D pt = null; |
796 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
797 |
double extx = 0.0; |
798 |
double exty = 0.0; |
799 |
double extz = 1.0; |
800 |
|
801 |
DxfPoint entity = new DxfPoint(proj, layer);
|
802 |
|
803 |
if (grp.hasCode(5)) { |
804 |
String hexS = grp.getDataAsString(5); |
805 |
Integer hexI = Integer.decode("0x" + hexS); |
806 |
int hexi = hexI.intValue();
|
807 |
entity.setHandle(hexi); |
808 |
} else {
|
809 |
entity.setHandle(entities.size() + 40);
|
810 |
} |
811 |
|
812 |
x = grp.getDataAsDouble(10);
|
813 |
y = grp.getDataAsDouble(20);
|
814 |
|
815 |
if (grp.hasCode(30)) { |
816 |
z = grp.getDataAsDouble(30);
|
817 |
} |
818 |
|
819 |
if (grp.hasCode(62)) { |
820 |
entity.dxfColor = grp.getDataAsInt(62);
|
821 |
} else {
|
822 |
//entity.dxfColor = 0;
|
823 |
} |
824 |
|
825 |
if (grp.hasCode(210)) { |
826 |
extx = grp.getDataAsDouble(210);
|
827 |
} |
828 |
|
829 |
if (grp.hasCode(220)) { |
830 |
exty = grp.getDataAsInt(220);
|
831 |
} |
832 |
|
833 |
if (grp.hasCode(230)) { |
834 |
extz = grp.getDataAsInt(230);
|
835 |
} |
836 |
|
837 |
Point3D point_in = new Point3D(x, y, z);
|
838 |
Point3D xtru = new Point3D(extx, exty, extz);
|
839 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
840 |
x = point_out.getX(); |
841 |
y = point_out.getY(); |
842 |
entity.setPt(proj.createPoint(x, y)); |
843 |
|
844 |
if (addingToBlock == false) { |
845 |
entities.add(entity); |
846 |
} else {
|
847 |
//System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
|
848 |
blk.add(entity); |
849 |
} |
850 |
} |
851 |
|
852 |
/* (non-Javadoc)
|
853 |
* @see org.cresques.io.DxfFile.EntityFactory#createCircle(org.cresques.io.DxfGroupVector)
|
854 |
*/
|
855 |
public void createCircle(DxfGroupVector grp) throws Exception { |
856 |
//System.out.println("Encontramos un Circle.");
|
857 |
double x = 0.0; |
858 |
|
859 |
//System.out.println("Encontramos un Circle.");
|
860 |
double y = 0.0; |
861 |
|
862 |
//System.out.println("Encontramos un Circle.");
|
863 |
double z = 0.0; |
864 |
double r = 0.0; |
865 |
DxfGroup g = null;
|
866 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
867 |
double extx = 0.0; |
868 |
double exty = 0.0; |
869 |
double extz = 1.0; |
870 |
|
871 |
x = grp.getDataAsDouble(10);
|
872 |
y = grp.getDataAsDouble(20);
|
873 |
|
874 |
if (grp.hasCode(30)) { |
875 |
z = grp.getDataAsDouble(30);
|
876 |
} |
877 |
|
878 |
if (grp.hasCode(40)) { |
879 |
r = grp.getDataAsDouble(40);
|
880 |
} |
881 |
|
882 |
if (grp.hasCode(210)) { |
883 |
extx = grp.getDataAsDouble(210);
|
884 |
} |
885 |
|
886 |
if (grp.hasCode(220)) { |
887 |
exty = grp.getDataAsDouble(220);
|
888 |
} |
889 |
|
890 |
if (grp.hasCode(230)) { |
891 |
extz = grp.getDataAsDouble(230);
|
892 |
} |
893 |
|
894 |
Point3D point_in = new Point3D(x, y, z);
|
895 |
Point3D xtru = new Point3D(extx, exty, extz);
|
896 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
897 |
x = point_out.getX(); |
898 |
y = point_out.getY(); |
899 |
|
900 |
Point2D center = proj.createPoint(x, y);
|
901 |
Point2D[] pts = new Point2D[360]; |
902 |
int angulo = 0; |
903 |
|
904 |
for (angulo = 0; angulo < 360; angulo++) { |
905 |
pts[angulo] = new Point2D.Double(center.getX(), center.getY()); |
906 |
pts[angulo].setLocation(pts[angulo].getX() + |
907 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
908 |
pts[angulo].getY() + |
909 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0))); |
910 |
|
911 |
if (pts.length == 1) { |
912 |
firstPt = pts[angulo]; |
913 |
} |
914 |
} |
915 |
|
916 |
DxfCircle entity = new DxfCircle(proj, layer, pts);
|
917 |
|
918 |
if (grp.hasCode(5)) { |
919 |
String hexS = grp.getDataAsString(5); |
920 |
Integer hexI = Integer.decode("0x" + hexS); |
921 |
int hexi = hexI.intValue();
|
922 |
entity.setHandle(hexi); |
923 |
} else {
|
924 |
entity.setHandle(entities.size() + 40);
|
925 |
} |
926 |
|
927 |
entity.setCenter(new Point2D.Double(x, y)); |
928 |
|
929 |
//System.out.println("Y le metemos el centro.");
|
930 |
entity.setRadius(r); |
931 |
|
932 |
if (grp.hasCode(62)) { |
933 |
entity.dxfColor = grp.getDataAsInt(62);
|
934 |
} else {
|
935 |
//entity.dxfColor = 0;
|
936 |
} |
937 |
|
938 |
if (addingToBlock == false) { |
939 |
//System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
|
940 |
entities.add(entity); |
941 |
} else {
|
942 |
//System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
|
943 |
blk.add(entity); |
944 |
} |
945 |
} |
946 |
|
947 |
/* (non-Javadoc)
|
948 |
* @see org.cresques.io.DxfFile.EntityFactory#createEllipse(org.cresques.io.DxfGroupVector)
|
949 |
*/
|
950 |
public void createEllipse(DxfGroupVector grp) throws Exception { |
951 |
double incX = 0.0; |
952 |
double incY = 0.0; |
953 |
double incZ = 0.0; |
954 |
double xc = 0.0; |
955 |
double yc = 0.0; |
956 |
double zc = 0.0; |
957 |
double mMAxisRatio = 0.0; |
958 |
DxfGroup g = null;
|
959 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
960 |
double extx = 0.0; |
961 |
double exty = 0.0; |
962 |
double extz = 1.0; |
963 |
|
964 |
xc = grp.getDataAsDouble(10);
|
965 |
yc = grp.getDataAsDouble(20);
|
966 |
|
967 |
if (grp.hasCode(30)) { |
968 |
zc = grp.getDataAsDouble(30);
|
969 |
} |
970 |
|
971 |
if (grp.hasCode(210)) { |
972 |
extx = grp.getDataAsDouble(210);
|
973 |
} |
974 |
|
975 |
if (grp.hasCode(220)) { |
976 |
exty = grp.getDataAsDouble(220);
|
977 |
} |
978 |
|
979 |
if (grp.hasCode(230)) { |
980 |
extz = grp.getDataAsDouble(230);
|
981 |
} |
982 |
|
983 |
Point3D point_in = new Point3D(xc, yc, zc);
|
984 |
Point3D xtru = new Point3D(extx, exty, extz);
|
985 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
986 |
xc = point_out.getX(); |
987 |
yc = point_out.getY(); |
988 |
zc = point_out.getZ(); |
989 |
|
990 |
incX = grp.getDataAsDouble(11);
|
991 |
incY = grp.getDataAsDouble(21);
|
992 |
|
993 |
if (grp.hasCode(31)) { |
994 |
incZ = grp.getDataAsDouble(31);
|
995 |
} |
996 |
|
997 |
if (grp.hasCode(40)) { |
998 |
mMAxisRatio = grp.getDataAsDouble(40);
|
999 |
} |
1000 |
|
1001 |
Point2D pt2 = new Point2D.Double(xc + incX, yc + incY); |
1002 |
Point2D pt1 = new Point2D.Double(xc - incX, yc - incY); |
1003 |
double majorAxisLength = pt1.distance(pt2);
|
1004 |
double minorAxisLength = majorAxisLength * mMAxisRatio;
|
1005 |
|
1006 |
DxfEllipse entity = new DxfEllipse(proj, layer, pt1, pt2,
|
1007 |
minorAxisLength); |
1008 |
|
1009 |
if (grp.hasCode(5)) { |
1010 |
String hexS = grp.getDataAsString(5); |
1011 |
Integer hexI = Integer.decode("0x" + hexS); |
1012 |
int hexi = hexI.intValue();
|
1013 |
entity.setHandle(hexi); |
1014 |
} else {
|
1015 |
entity.setHandle(entities.size() + 40);
|
1016 |
} |
1017 |
|
1018 |
if (grp.hasCode(62)) { |
1019 |
entity.dxfColor = grp.getDataAsInt(62);
|
1020 |
} else {
|
1021 |
//entity.dxfColor = 0;
|
1022 |
} |
1023 |
|
1024 |
if (addingToBlock == false) { |
1025 |
//System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
|
1026 |
entities.add(entity); |
1027 |
} else {
|
1028 |
//System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
|
1029 |
blk.add(entity); |
1030 |
} |
1031 |
} |
1032 |
|
1033 |
/* (non-Javadoc)
|
1034 |
* @see org.cresques.io.DxfFile.EntityFactory#createArc(org.cresques.io.DxfGroupVector)
|
1035 |
*/
|
1036 |
public void createArc(DxfGroupVector grp) throws Exception { |
1037 |
double x = 0.0; |
1038 |
double y = 0.0; |
1039 |
double z = 0.0; |
1040 |
double r = 0.0; |
1041 |
double empieza = 0.0; |
1042 |
double acaba = 0.0; |
1043 |
DxfGroup g = null;
|
1044 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1045 |
double extx = 0.0; |
1046 |
double exty = 0.0; |
1047 |
double extz = 1.0; |
1048 |
|
1049 |
x = grp.getDataAsDouble(10);
|
1050 |
y = grp.getDataAsDouble(20);
|
1051 |
|
1052 |
if (grp.hasCode(30)) { |
1053 |
z = grp.getDataAsDouble(30);
|
1054 |
} |
1055 |
|
1056 |
if (grp.hasCode(40)) { |
1057 |
r = grp.getDataAsDouble(40);
|
1058 |
} |
1059 |
|
1060 |
if (grp.hasCode(50)) { |
1061 |
empieza = grp.getDataAsDouble(50);
|
1062 |
} |
1063 |
|
1064 |
if (grp.hasCode(51)) { |
1065 |
acaba = grp.getDataAsDouble(51);
|
1066 |
} |
1067 |
|
1068 |
if (grp.hasCode(210)) { |
1069 |
extx = grp.getDataAsDouble(210);
|
1070 |
} |
1071 |
|
1072 |
if (grp.hasCode(220)) { |
1073 |
exty = grp.getDataAsDouble(220);
|
1074 |
} |
1075 |
|
1076 |
if (grp.hasCode(230)) { |
1077 |
extz = grp.getDataAsDouble(230);
|
1078 |
} |
1079 |
|
1080 |
Point3D point_in = new Point3D(x, y, z);
|
1081 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1082 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
1083 |
x = point_out.getX(); |
1084 |
y = point_out.getY(); |
1085 |
|
1086 |
Point2D center = proj.createPoint(x, y);
|
1087 |
|
1088 |
//System.out.println("empieza = " + empieza + ", acaba = " + acaba);
|
1089 |
int iempieza = (int) empieza; |
1090 |
int iacaba = (int) acaba; |
1091 |
|
1092 |
//System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
|
1093 |
double angulo = 0; |
1094 |
Point2D[] pts = null; |
1095 |
|
1096 |
if (empieza <= acaba) {
|
1097 |
pts = new Point2D[(iacaba - iempieza) + 2]; |
1098 |
angulo = empieza; |
1099 |
pts[0] = new Point2D.Double(center.getX() + |
1100 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1101 |
center.getY() + |
1102 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0))); |
1103 |
|
1104 |
for (int i = 1; i <= ((iacaba - iempieza) + 1); i++) { |
1105 |
angulo = (double) (iempieza + i);
|
1106 |
pts[i] = new Point2D.Double(center.getX() + |
1107 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1108 |
center.getY() + |
1109 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0))); |
1110 |
} |
1111 |
|
1112 |
angulo = acaba; |
1113 |
pts[(iacaba - iempieza) + 1] = new Point2D.Double(center.getX() + |
1114 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1115 |
center.getY() + |
1116 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0))); |
1117 |
} else {
|
1118 |
pts = new Point2D[(360 - iempieza) + iacaba + 2]; |
1119 |
angulo = empieza; |
1120 |
|
1121 |
//System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
|
1122 |
pts[0] = new Point2D.Double(center.getX() + |
1123 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1124 |
center.getY() + |
1125 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0))); |
1126 |
|
1127 |
for (int i = 1; i <= (360 - iempieza); i++) { |
1128 |
angulo = (double) (iempieza + i);
|
1129 |
pts[i] = new Point2D.Double(center.getX() + |
1130 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1131 |
center.getY() + |
1132 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0))); |
1133 |
} |
1134 |
|
1135 |
for (int i = (360 - iempieza) + 1; |
1136 |
i <= ((360 - iempieza) + iacaba); i++) {
|
1137 |
angulo = (double) (i - (360 - iempieza)); |
1138 |
pts[i] = new Point2D.Double(center.getX() + |
1139 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1140 |
center.getY() + |
1141 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0))); |
1142 |
} |
1143 |
|
1144 |
angulo = acaba; |
1145 |
pts[(360 - iempieza) + iacaba + 1] = new Point2D.Double(center.getX() + |
1146 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1147 |
center.getY() + |
1148 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0))); |
1149 |
} |
1150 |
|
1151 |
DxfArc entity = new DxfArc(proj, layer, pts);
|
1152 |
|
1153 |
if (grp.hasCode(5)) { |
1154 |
String hexS = grp.getDataAsString(5); |
1155 |
Integer hexI = Integer.decode("0x" + hexS); |
1156 |
int hexi = hexI.intValue();
|
1157 |
entity.setHandle(hexi); |
1158 |
} else {
|
1159 |
entity.setHandle(entities.size() + 40);
|
1160 |
} |
1161 |
|
1162 |
// 050223, jmorell: Establecimiento de los par?metros del arco.
|
1163 |
//System.out.println("DxfEntityMaker.createArc(): pts.length = " + pts.length);
|
1164 |
entity.setCentralPoint(pts[(pts.length) / 2]);
|
1165 |
|
1166 |
//System.out.println("DxfEntityMaker.createArc(): (pts.length)/2 = " + (pts.length/2));
|
1167 |
entity.setInit(pts[0]);
|
1168 |
entity.setEnd(pts[pts.length - 1]);
|
1169 |
|
1170 |
//System.out.println("DxfEntityMaker.createArc(): (pts.length)-1 = " + (pts.length-1));
|
1171 |
entity.setCenter(center); |
1172 |
entity.setRadius(r); |
1173 |
entity.setInitAngle(empieza); |
1174 |
|
1175 |
//System.out.println("DxfEntityMaker.createArc(): empieza = " + empieza);
|
1176 |
entity.setEndAngle(acaba); |
1177 |
|
1178 |
//System.out.println("DxfEntityMaker.createArc(): acaba = " + acaba);
|
1179 |
if (grp.hasCode(62)) { |
1180 |
entity.dxfColor = grp.getDataAsInt(62);
|
1181 |
} else {
|
1182 |
//entity.dxfColor = 0;
|
1183 |
} |
1184 |
|
1185 |
//System.out.println("createArc(): A?adimos un arco al bloque");
|
1186 |
if (addingToBlock == false) { |
1187 |
entities.add(entity); |
1188 |
} else {
|
1189 |
//System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
|
1190 |
blk.add(entity); |
1191 |
} |
1192 |
} |
1193 |
|
1194 |
/* (non-Javadoc)
|
1195 |
* @see org.cresques.io.DxfFile.EntityFactory#createInsert(org.cresques.io.DxfGroupVector)
|
1196 |
*/
|
1197 |
public void createInsert(DxfGroupVector grp) throws Exception { |
1198 |
double x = 0.0; |
1199 |
double y = 0.0; |
1200 |
double z = 0.0; |
1201 |
DxfGroup g = null;
|
1202 |
Point2D pt = new Point2D.Double(0.0, 0.0); |
1203 |
Point2D scaleFactor = new Point2D.Double(1.0, 1.0); |
1204 |
double rotAngle = 0.0; |
1205 |
String blockName = ""; |
1206 |
double extx = 0.0; |
1207 |
double exty = 0.0; |
1208 |
double extz = 1.0; |
1209 |
|
1210 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1211 |
|
1212 |
DxfInsert entity = new DxfInsert(proj, layer);
|
1213 |
DxfPoint secondEntity = new DxfPoint(proj, layer);
|
1214 |
|
1215 |
// jmorell, 050406: implementaci?n inicial de los ATTRIBS para el piloto ...
|
1216 |
int attributesFollowFlag = 0; |
1217 |
|
1218 |
if (grp.hasCode(2)) { |
1219 |
blockName = grp.getDataAsString(2);
|
1220 |
entity.setBlockName(blockName); |
1221 |
} |
1222 |
|
1223 |
if (grp.hasCode(10)) { |
1224 |
x = grp.getDataAsDouble(10);
|
1225 |
} |
1226 |
|
1227 |
if (grp.hasCode(20)) { |
1228 |
y = grp.getDataAsDouble(20);
|
1229 |
} |
1230 |
|
1231 |
if (grp.hasCode(30)) { |
1232 |
z = grp.getDataAsDouble(30);
|
1233 |
} |
1234 |
|
1235 |
if (grp.hasCode(41)) { |
1236 |
scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
|
1237 |
entity.setScaleFactor(scaleFactor); |
1238 |
} else {
|
1239 |
entity.setScaleFactor(scaleFactor); |
1240 |
} |
1241 |
|
1242 |
if (grp.hasCode(42)) { |
1243 |
scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
|
1244 |
entity.setScaleFactor(scaleFactor); |
1245 |
} else {
|
1246 |
entity.setScaleFactor(scaleFactor); |
1247 |
} |
1248 |
|
1249 |
if (grp.hasCode(43)) { |
1250 |
// TODO La coordenada z
|
1251 |
} |
1252 |
|
1253 |
if (grp.hasCode(50)) { |
1254 |
rotAngle = grp.getDataAsDouble(50);
|
1255 |
entity.setRotAngle(rotAngle); |
1256 |
} |
1257 |
|
1258 |
if (grp.hasCode(62)) { |
1259 |
entity.dxfColor = grp.getDataAsInt(62);
|
1260 |
} else {
|
1261 |
//entity.dxfColor = 0;
|
1262 |
} |
1263 |
|
1264 |
if (grp.hasCode(66)) { |
1265 |
attributesFollowFlag = grp.getDataAsInt(66);
|
1266 |
|
1267 |
//System.out.println("createInsert: attributesFollowFlag = " + attributesFollowFlag);
|
1268 |
} |
1269 |
|
1270 |
if (grp.hasCode(210)) { |
1271 |
extx = grp.getDataAsDouble(210);
|
1272 |
} |
1273 |
|
1274 |
if (grp.hasCode(220)) { |
1275 |
exty = grp.getDataAsDouble(220);
|
1276 |
} |
1277 |
|
1278 |
if (grp.hasCode(230)) { |
1279 |
extz = grp.getDataAsDouble(230);
|
1280 |
} |
1281 |
|
1282 |
Point3D point_in = new Point3D(x, y, z);
|
1283 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1284 |
Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
|
1285 |
x = point_out.getX(); |
1286 |
y = point_out.getY(); |
1287 |
|
1288 |
entity.setBlkList(blkList); |
1289 |
|
1290 |
entity.encuentraBloque(blockName); |
1291 |
|
1292 |
entity.setPt(proj.createPoint(x, y)); |
1293 |
secondEntity.setPt(proj.createPoint(x, y)); |
1294 |
|
1295 |
if ((entity.getBlockFound() == true) && (attributesFollowFlag != 1)) { |
1296 |
gestionaInsert(entity, layer); |
1297 |
} |
1298 |
|
1299 |
//System.out.println("createInsert: entity.getBlockName = " + entity.getBlockName());
|
1300 |
//System.out.println("createInsert: entity.getRotAngle = " + entity.getRotAngle());
|
1301 |
if (attributesFollowFlag == 1) { |
1302 |
//System.out.println("createInsert: Coloca como lastEntity el insert");
|
1303 |
lastEntity = entity; |
1304 |
} else {
|
1305 |
if (addingToBlock == false) { |
1306 |
entities.add(secondEntity); |
1307 |
} else if ((addingToBlock == true) && (entity.blockFound == true)) { |
1308 |
//System.out.println("createArc(): A?adimos un insert al bloque " + iterator);
|
1309 |
blk.add(entity); |
1310 |
} |
1311 |
} |
1312 |
} |
1313 |
|
1314 |
/* (non-Javadoc)
|
1315 |
* @see org.cresques.io.DxfFile.EntityFactory#createSolid(org.cresques.io.DxfGroupVector)
|
1316 |
*/
|
1317 |
public void createSolid(DxfGroupVector grp) throws Exception { |
1318 |
double x = 0.0; |
1319 |
double y = 0.0; |
1320 |
double z1 = 0.0; |
1321 |
double z2 = 0.0; |
1322 |
double z3 = 0.0; |
1323 |
double z4 = 0.0; |
1324 |
DxfGroup g = null;
|
1325 |
|
1326 |
//Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
|
1327 |
Point2D[] pts = new Point2D[4]; |
1328 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1329 |
double extx = 0.0; |
1330 |
double exty = 0.0; |
1331 |
double extz = 1.0; |
1332 |
|
1333 |
x = grp.getDataAsDouble(10);
|
1334 |
y = grp.getDataAsDouble(20);
|
1335 |
|
1336 |
if (grp.hasCode(30)) { |
1337 |
z1 = grp.getDataAsDouble(30);
|
1338 |
} |
1339 |
|
1340 |
pts[0] = proj.createPoint(x, y);
|
1341 |
x = grp.getDataAsDouble(11);
|
1342 |
y = grp.getDataAsDouble(21);
|
1343 |
|
1344 |
if (grp.hasCode(31)) { |
1345 |
z2 = grp.getDataAsDouble(31);
|
1346 |
} |
1347 |
|
1348 |
pts[1] = proj.createPoint(x, y);
|
1349 |
x = grp.getDataAsDouble(12);
|
1350 |
y = grp.getDataAsDouble(22);
|
1351 |
|
1352 |
if (grp.hasCode(32)) { |
1353 |
z3 = grp.getDataAsDouble(32);
|
1354 |
} |
1355 |
|
1356 |
pts[2] = proj.createPoint(x, y);
|
1357 |
x = grp.getDataAsDouble(13);
|
1358 |
y = grp.getDataAsDouble(23);
|
1359 |
|
1360 |
if (grp.hasCode(33)) { |
1361 |
z2 = grp.getDataAsDouble(33);
|
1362 |
} |
1363 |
|
1364 |
pts[3] = proj.createPoint(x, y);
|
1365 |
|
1366 |
if (grp.hasCode(210)) { |
1367 |
extx = grp.getDataAsDouble(210);
|
1368 |
} |
1369 |
|
1370 |
if (grp.hasCode(220)) { |
1371 |
exty = grp.getDataAsDouble(220);
|
1372 |
} |
1373 |
|
1374 |
if (grp.hasCode(230)) { |
1375 |
extz = grp.getDataAsDouble(230);
|
1376 |
} |
1377 |
|
1378 |
Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1); |
1379 |
Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2); |
1380 |
Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3); |
1381 |
Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4); |
1382 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1383 |
Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
|
1384 |
Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
|
1385 |
Point2D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
|
1386 |
Point2D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
|
1387 |
pts[0].setLocation(point_out1);
|
1388 |
pts[1].setLocation(point_out2);
|
1389 |
pts[2].setLocation(point_out3);
|
1390 |
pts[3].setLocation(point_out4);
|
1391 |
|
1392 |
DxfSolid entity = new DxfSolid(proj, layer, pts);
|
1393 |
|
1394 |
if (grp.hasCode(62)) { |
1395 |
entity.dxfColor = grp.getDataAsInt(62);
|
1396 |
} else {
|
1397 |
//entity.dxfColor = 0;
|
1398 |
} |
1399 |
|
1400 |
if (addingToBlock == false) { |
1401 |
//System.out.println("createLine(): A?adimos una linea a la lista de entidades");
|
1402 |
entities.add(entity); |
1403 |
} else {
|
1404 |
//System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
|
1405 |
blk.add(entity); |
1406 |
} |
1407 |
} |
1408 |
|
1409 |
/* (non-Javadoc)
|
1410 |
* @see org.cresques.io.DxfFile.EntityFactory#createSpline(org.cresques.io.DxfGroupVector)
|
1411 |
*/
|
1412 |
/**
|
1413 |
* Los Splines estan implementados como LwPolylines. Se pintan las lineas
|
1414 |
* entre los vertices pero no se aplica la curvatura Spline.
|
1415 |
* TODO: Contemplar la curvatura spline para Splines.
|
1416 |
*/
|
1417 |
public void createSpline(DxfGroupVector grp) throws Exception { |
1418 |
double x = 0.0; |
1419 |
double y = 0.0; |
1420 |
double elev = 0.0; |
1421 |
DxfGroup g = null;
|
1422 |
|
1423 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1424 |
DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
|
1425 |
|
1426 |
for (int i = 0; i < grp.size(); i++) { |
1427 |
g = (DxfGroup) grp.get(i); |
1428 |
|
1429 |
if (g.getCode() == 10) { |
1430 |
x = ((Double) g.getData()).doubleValue();
|
1431 |
} else if (g.getCode() == 20) { |
1432 |
y = ((Double) g.getData()).doubleValue();
|
1433 |
|
1434 |
//if (y <= 1.0) throw new Exception("Y == "+y);
|
1435 |
entity.add(proj.createPoint(x, y)); |
1436 |
x = 0.0;
|
1437 |
y = 0.0;
|
1438 |
} |
1439 |
} |
1440 |
|
1441 |
if (grp.hasCode(62)) { |
1442 |
entity.dxfColor = grp.getDataAsInt(62);
|
1443 |
} else {
|
1444 |
//entity.dxfColor = 0;
|
1445 |
} |
1446 |
|
1447 |
if (grp.hasCode(70)) { |
1448 |
entity.flags = grp.getDataAsInt(70);
|
1449 |
} |
1450 |
|
1451 |
if ((entity.flags & 0x01) == 0x01) { |
1452 |
entity.closed = true;
|
1453 |
} |
1454 |
|
1455 |
if (addingToBlock == false) { |
1456 |
entities.add(entity); |
1457 |
} else {
|
1458 |
//System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
|
1459 |
blk.add(entity); |
1460 |
} |
1461 |
} |
1462 |
|
1463 |
/* (non-Javadoc)
|
1464 |
* @see org.cresques.io.DxfFile.EntityFactory#createBlock(org.cresques.io.DxfGroupVector)
|
1465 |
*/
|
1466 |
public void createBlock(DxfGroupVector grp) throws Exception { |
1467 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1468 |
blk = new DxfBlock(proj);
|
1469 |
|
1470 |
Point2D basePoint = new Point2D.Double(); |
1471 |
String blockName = ""; |
1472 |
|
1473 |
//System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
|
1474 |
addingToBlock = true;
|
1475 |
|
1476 |
//System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
|
1477 |
blkList.add(iterator, blk); |
1478 |
|
1479 |
//System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
|
1480 |
if (grp.hasCode(1)) { |
1481 |
blockName = grp.getDataAsString(1);
|
1482 |
blk.setBlkName(blockName); |
1483 |
} |
1484 |
|
1485 |
if (grp.hasCode(2)) { |
1486 |
blockName = grp.getDataAsString(2);
|
1487 |
blk.setBlkName(blockName); |
1488 |
} |
1489 |
|
1490 |
if (grp.hasCode(3)) { |
1491 |
blockName = grp.getDataAsString(3);
|
1492 |
blk.setBlkName(blockName); |
1493 |
} |
1494 |
|
1495 |
if (grp.hasCode(10)) { |
1496 |
basePoint = new Point2D.Double(grp.getDataAsDouble(10), |
1497 |
basePoint.getY()); |
1498 |
blk.setBPoint(basePoint); |
1499 |
} |
1500 |
|
1501 |
if (grp.hasCode(20)) { |
1502 |
basePoint = new Point2D.Double(basePoint.getX(), |
1503 |
grp.getDataAsDouble(20));
|
1504 |
blk.setBPoint(basePoint); |
1505 |
} |
1506 |
|
1507 |
if (grp.hasCode(30)) { |
1508 |
// TODO Contemplar la coordenada z
|
1509 |
} |
1510 |
|
1511 |
if (grp.hasCode(70)) { |
1512 |
blk.flags = grp.getDataAsInt(70);
|
1513 |
} |
1514 |
} |
1515 |
|
1516 |
/* (non-Javadoc)
|
1517 |
* @see org.cresques.io.DxfFile.EntityFactory#endBlk(org.cresques.io.DxfGroupVector)
|
1518 |
*/
|
1519 |
public void endBlk(DxfGroupVector grp) throws Exception { |
1520 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1521 |
setAddingToBlock(false);
|
1522 |
iterator = iterator + 1;
|
1523 |
} |
1524 |
|
1525 |
/* (non-Javadoc)
|
1526 |
* @see org.cresques.io.DxfFile.EntityFactory#testBlocks()
|
1527 |
*/
|
1528 |
public void testBlocks() { |
1529 |
Vector blkList = getBlkList();
|
1530 |
DxfBlock dxfBlock = null;
|
1531 |
DxfEntity dxfEntity = null;
|
1532 |
DxfLine dxfLine = null;
|
1533 |
DxfInsert dxfInsert = null;
|
1534 |
Point2D point1 = new Point2D.Double(); |
1535 |
Point2D point2 = new Point2D.Double(); |
1536 |
|
1537 |
for (int i = 0; i < blkList.size(); i++) { |
1538 |
dxfBlock = (DxfBlock) blkList.get(i); |
1539 |
|
1540 |
int aux = dxfBlock.getBlkElements().size();
|
1541 |
|
1542 |
for (int j = 0; j < aux; j++) { |
1543 |
dxfEntity = (DxfEntity) dxfBlock.getBlkElements().get(j); |
1544 |
|
1545 |
if (dxfEntity instanceof DxfLine) { |
1546 |
dxfLine = (DxfLine) dxfEntity; |
1547 |
point1 = dxfLine.getPts()[0];
|
1548 |
point2 = dxfLine.getPts()[1];
|
1549 |
|
1550 |
//System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", vertice1 = " + point1 + ", vertice2 = " + point2);
|
1551 |
} else if (dxfEntity instanceof DxfInsert) { |
1552 |
dxfInsert = (DxfInsert) dxfEntity; |
1553 |
|
1554 |
String nomBlock = dxfInsert.getBlockName();
|
1555 |
|
1556 |
//System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", inserta el bloque = " + nomBlock);
|
1557 |
//System.out.println("compruebaBloques(): dxfInsert.pt = " + dxfInsert.getPt());
|
1558 |
//System.out.println("compruebaBloques(): dxfInsert.rotAngle = " + dxfInsert.getRotAngle());
|
1559 |
//System.out.println("compruebaBloques(): dxfInsert.scaleFactor = " + dxfInsert.getScaleFactor());
|
1560 |
if (dxfInsert.getBlockFound() == false) { |
1561 |
//System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock);
|
1562 |
boolean aux_bool = dxfInsert.encuentraBloque(nomBlock);
|
1563 |
gestionaInsert(dxfInsert, dxfInsert.getDxfLayer()); |
1564 |
dxfBlock.add(dxfInsert); |
1565 |
} |
1566 |
} |
1567 |
} |
1568 |
} |
1569 |
} |
1570 |
|
1571 |
/**
|
1572 |
* Establece la proyecci?n cartogr?fica en la que se van a crear las entidades.
|
1573 |
* @param p, Proyecci?n cartogr?fica.
|
1574 |
*/
|
1575 |
public void setProjection(IProjection proj) { |
1576 |
this.proj = proj;
|
1577 |
} |
1578 |
|
1579 |
/**
|
1580 |
* Devuelve la proyecci?n cartogr?fica en la que se encuentran las entidades.
|
1581 |
* @return IProjection, proyecci?n cartogr?fica.
|
1582 |
*/
|
1583 |
public IProjection getProjection() {
|
1584 |
return proj;
|
1585 |
} |
1586 |
|
1587 |
/**
|
1588 |
* Permite reproyectar las entidades creadas dado un conjunto de coordenadas de
|
1589 |
* transformaci?n.
|
1590 |
* @param rp, coordenadas de transformaci?n.
|
1591 |
*/
|
1592 |
public void reProject(ICoordTrans rp) { |
1593 |
entities.reProject(rp); |
1594 |
setProjection(rp.getPDest()); |
1595 |
} |
1596 |
|
1597 |
/**
|
1598 |
* Devuelve las entidades creadas.
|
1599 |
* @return DxfEntityList
|
1600 |
*/
|
1601 |
public DxfEntityList getEntities() {
|
1602 |
return entities;
|
1603 |
} |
1604 |
|
1605 |
/**
|
1606 |
* Devuelve las capas del DXF en forma de DxfTable.
|
1607 |
* @return DxfTable
|
1608 |
*/
|
1609 |
public DxfTable getLayers() {
|
1610 |
return layers;
|
1611 |
} |
1612 |
|
1613 |
/**
|
1614 |
* Devuelve el bloque activo.
|
1615 |
* @return DxfBlock
|
1616 |
*/
|
1617 |
public DxfBlock getBlk() {
|
1618 |
return blk;
|
1619 |
} |
1620 |
|
1621 |
/**
|
1622 |
* M?todo que permite incluir en la lista general de objetos los objetos que se
|
1623 |
* encuentran dentro del bloque referenciado por cada DxfInsert.
|
1624 |
* @param entity, el punto de inserci?n.
|
1625 |
* @param layer, la capa en la que se encuentra.
|
1626 |
*/
|
1627 |
public void gestionaInsert(DxfInsert entity, DxfLayer layer) { |
1628 |
DxfEntity dxfEntity = null;
|
1629 |
DxfLine dxfLine = null;
|
1630 |
DxfInsert dxfInsert = null;
|
1631 |
DxfPolyline dxfPolyline = null;
|
1632 |
DxfArc dxfArc = null;
|
1633 |
DxfCircle dxfCircle = null;
|
1634 |
DxfLwPolyline dxfLwPolyline = null;
|
1635 |
DxfPoint dxfPoint = null;
|
1636 |
DxfText dxfText = null;
|
1637 |
DxfSolid dxfSolid = null;
|
1638 |
|
1639 |
// jmorell, 050406: intentando corregir cosas que salen fuera de sitio ...
|
1640 |
double bPointX = 0.0; |
1641 |
double bPointY = 0.0; |
1642 |
|
1643 |
//if (entity.getBlockFound() == true) {
|
1644 |
bPointX = entity.block.bPoint.getX(); |
1645 |
bPointY = entity.block.bPoint.getY(); |
1646 |
|
1647 |
//}
|
1648 |
double sFactorX = entity.getScaleFactor().getX();
|
1649 |
double sFactorY = entity.getScaleFactor().getY();
|
1650 |
double rAngleGra = entity.getRotAngle();
|
1651 |
double rAngleRad = (rAngleGra * Math.PI) / 180.0; |
1652 |
|
1653 |
for (int i = 0; i < entity.block.size(); i++) { |
1654 |
//System.out.println("gestionaInserts: entity.block.blkElements.size() = " + entity.block.blkElements.size());
|
1655 |
dxfEntity = (DxfEntity) entity.block.get(i); |
1656 |
|
1657 |
Point2D point1 = new Point2D.Double(); |
1658 |
Point2D point2 = new Point2D.Double(); |
1659 |
Point2D point11 = new Point2D.Double(); |
1660 |
Point2D point22 = new Point2D.Double(); |
1661 |
Point2D pointAux = null; |
1662 |
|
1663 |
if (dxfEntity instanceof DxfLine) { |
1664 |
dxfLine = (DxfLine) dxfEntity; |
1665 |
point1 = dxfLine.getPts()[0];
|
1666 |
|
1667 |
//double laX = entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX());
|
1668 |
//double laY = entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY());
|
1669 |
pointAux = new Point2D.Double(point1.getX() - bPointX, |
1670 |
point1.getY() - bPointY); |
1671 |
|
1672 |
double laX = entity.pt.getX() +
|
1673 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1674 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1675 |
double laY = entity.pt.getY() +
|
1676 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1677 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1678 |
point11.setLocation(laX, laY); |
1679 |
point2 = dxfLine.getPts()[1];
|
1680 |
pointAux = new Point2D.Double(point2.getX() - bPointX, |
1681 |
point2.getY() - bPointY); |
1682 |
laX = entity.pt.getX() + |
1683 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1684 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1685 |
laY = entity.pt.getY() + |
1686 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1687 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1688 |
point22.setLocation(laX, laY); |
1689 |
|
1690 |
DxfLine dxfLinee = new DxfLine(proj, layer, point11, point22);
|
1691 |
|
1692 |
if (addingToBlock == false) { |
1693 |
entities.add(dxfLinee); |
1694 |
} |
1695 |
} else if (dxfEntity instanceof DxfInsert) { |
1696 |
dxfInsert = (DxfInsert) dxfEntity; |
1697 |
point1 = dxfInsert.pt; |
1698 |
pointAux = new Point2D.Double(point1.getX() - bPointX, |
1699 |
point1.getY() - bPointY); |
1700 |
|
1701 |
//point11.setLocation(entity.pt.getX() - entity.block.bPoint.getX() + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - entity.block.bPoint.getY() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1702 |
//point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1703 |
double laX = entity.pt.getX() +
|
1704 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1705 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1706 |
double laY = entity.pt.getY() +
|
1707 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1708 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1709 |
point11.setLocation(laX, laY); |
1710 |
|
1711 |
DxfInsert dxfInsertt = new DxfInsert(proj, layer);
|
1712 |
|
1713 |
dxfInsertt.pt = point11; |
1714 |
|
1715 |
dxfInsertt.blkList = dxfInsert.blkList; |
1716 |
dxfInsertt.block = dxfInsert.block; |
1717 |
dxfInsertt.blockName = dxfInsert.blockName; |
1718 |
dxfInsertt.rotAngle = dxfInsert.rotAngle; |
1719 |
dxfInsertt.layer = dxfInsert.layer; |
1720 |
dxfInsertt.proj = dxfInsert.proj; |
1721 |
|
1722 |
Point2D newScale = new Point2D.Double(dxfInsert.getScaleFactor() |
1723 |
.getX() * sFactorX, |
1724 |
dxfInsert.getScaleFactor() |
1725 |
.getY() * sFactorY); |
1726 |
dxfInsertt.setScaleFactor(newScale); |
1727 |
|
1728 |
//dxfInsertt.scaleFactor = new Point2D.Double(dxfInsert.scaleFactor.getX() * entity.scaleFactor.getX(), dxfInsert.scaleFactor.getY() * entity.scaleFactor.getY());
|
1729 |
gestionaInsert(dxfInsertt, layer); |
1730 |
} else if (dxfEntity instanceof DxfPolyline) { |
1731 |
dxfPolyline = (DxfPolyline) dxfEntity; |
1732 |
|
1733 |
DxfPolyline dxfPolylinee = new DxfPolyline(proj, layer);
|
1734 |
|
1735 |
if (dxfPolyline.closed) {
|
1736 |
dxfPolylinee.closed = true;
|
1737 |
} |
1738 |
|
1739 |
Point2D[] points = new Point2D[dxfPolyline.pts.size()]; |
1740 |
Point2D[] pointss = new Point2D[dxfPolyline.pts.size()]; |
1741 |
|
1742 |
for (int j = 0; j < dxfPolyline.pts.size(); j++) { |
1743 |
points[j] = (Point2D) dxfPolyline.pts.get(j);
|
1744 |
pointss[j] = new Point2D.Double(); |
1745 |
|
1746 |
//pointss[j].setLocation(entity.pt.getX() - entity.block.bPoint.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - entity.block.bPoint.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1747 |
//pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1748 |
pointAux = new Point2D.Double(points[j].getX() - bPointX, |
1749 |
points[j].getY() - bPointY); |
1750 |
|
1751 |
double laX = entity.pt.getX() +
|
1752 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1753 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1754 |
double laY = entity.pt.getY() +
|
1755 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1756 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1757 |
pointss[j].setLocation(laX, laY); |
1758 |
|
1759 |
//pointss[j].setLocation(entity.pt.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1760 |
dxfPolylinee.add(pointss[j]); |
1761 |
|
1762 |
// jmorell, 050405: Bulges en Dxfpolyline para el piloto
|
1763 |
dxfPolylinee.addBulge((Double) dxfPolyline.getBulges().get(j));
|
1764 |
} |
1765 |
|
1766 |
if (addingToBlock == false) { |
1767 |
entities.add(dxfPolylinee); |
1768 |
} |
1769 |
} else if (dxfEntity instanceof DxfArc) { |
1770 |
dxfArc = (DxfArc) dxfEntity; |
1771 |
|
1772 |
Point2D[] points = new Point2D[dxfArc.pts.length]; |
1773 |
Point2D[] pointss = new Point2D[dxfArc.pts.length]; |
1774 |
|
1775 |
for (int j = 0; j < dxfArc.pts.length; j++) { |
1776 |
points[j] = (Point2D) dxfArc.pts[j];
|
1777 |
pointss[j] = new Point2D.Double(); |
1778 |
pointAux = new Point2D.Double(points[j].getX() - bPointX, |
1779 |
points[j].getY() - bPointY); |
1780 |
|
1781 |
double laX = entity.pt.getX() +
|
1782 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1783 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1784 |
double laY = entity.pt.getY() +
|
1785 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1786 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1787 |
pointss[j].setLocation(laX, laY); |
1788 |
|
1789 |
//pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1790 |
} |
1791 |
|
1792 |
DxfArc dxfArcc = new DxfArc(proj, layer, pointss);
|
1793 |
|
1794 |
// 050315, jmorell: Para que no se pierdan las propiedades en el
|
1795 |
// caso de objetos dentro de bloques.
|
1796 |
pointAux = new Point2D.Double(dxfArc.getCentralPoint().getX() - |
1797 |
bPointX, |
1798 |
dxfArc.getCentralPoint().getY() - |
1799 |
bPointY); |
1800 |
|
1801 |
double laX = entity.pt.getX() +
|
1802 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1803 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1804 |
double laY = entity.pt.getY() +
|
1805 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1806 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1807 |
pointAux.setLocation(laX, laY); |
1808 |
dxfArcc.setCentralPoint(pointAux); |
1809 |
pointAux = new Point2D.Double(dxfArc.getInit().getX() - |
1810 |
bPointX, |
1811 |
dxfArc.getInit().getY() - |
1812 |
bPointY); |
1813 |
laX = entity.pt.getX() + |
1814 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1815 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1816 |
laY = entity.pt.getY() + |
1817 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1818 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1819 |
pointAux.setLocation(laX, laY); |
1820 |
dxfArcc.setInit(pointAux); |
1821 |
pointAux = new Point2D.Double(dxfArc.getEnd().getX() - bPointX, |
1822 |
dxfArc.getEnd().getY() - bPointY); |
1823 |
laX = entity.pt.getX() + |
1824 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1825 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1826 |
laY = entity.pt.getY() + |
1827 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1828 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1829 |
pointAux.setLocation(laX, laY); |
1830 |
dxfArcc.setEnd(pointAux); |
1831 |
pointAux = new Point2D.Double(dxfArc.getCenter().getX() - |
1832 |
bPointX, |
1833 |
dxfArc.getCenter().getY() - |
1834 |
bPointY); |
1835 |
laX = entity.pt.getX() + |
1836 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1837 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1838 |
laY = entity.pt.getY() + |
1839 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1840 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1841 |
pointAux.setLocation(laX, laY); |
1842 |
dxfArcc.setCenter(pointAux); |
1843 |
dxfArcc.setRadius(dxfArc.getRadius() * sFactorX); |
1844 |
|
1845 |
// TODO ?Como afectan las rotaciones del insert al init y el end angle?
|
1846 |
dxfArcc.setInitAngle(dxfArc.getInitAngle()); |
1847 |
dxfArcc.setEndAngle(dxfArc.getEndAngle()); |
1848 |
|
1849 |
if (addingToBlock == false) { |
1850 |
entities.add(dxfArcc); |
1851 |
} |
1852 |
} else if (dxfEntity instanceof DxfCircle) { |
1853 |
dxfCircle = (DxfCircle) dxfEntity; |
1854 |
|
1855 |
Point2D[] points = new Point2D[dxfCircle.pts.length]; |
1856 |
Point2D[] pointss = new Point2D[dxfCircle.pts.length]; |
1857 |
|
1858 |
for (int j = 0; j < dxfCircle.pts.length; j++) { |
1859 |
points[j] = (Point2D) dxfCircle.pts[j];
|
1860 |
pointss[j] = new Point2D.Double(); |
1861 |
pointAux = new Point2D.Double(points[j].getX() - bPointX, |
1862 |
points[j].getY() - bPointY); |
1863 |
|
1864 |
double laX = entity.pt.getX() +
|
1865 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1866 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1867 |
double laY = entity.pt.getY() +
|
1868 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1869 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1870 |
pointss[j].setLocation(laX, laY); |
1871 |
|
1872 |
//pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1873 |
} |
1874 |
|
1875 |
DxfCircle dxfCirclee = new DxfCircle(proj, layer, pointss);
|
1876 |
|
1877 |
// 050315, jmorell: Para que no se pierdan las propiedades en el
|
1878 |
// caso de objetos dentro de bloques.
|
1879 |
pointAux = new Point2D.Double(dxfCircle.getCenter().getX() - |
1880 |
bPointX, |
1881 |
dxfCircle.getCenter().getY() - |
1882 |
bPointY); |
1883 |
|
1884 |
double laX = entity.pt.getX() +
|
1885 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1886 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1887 |
double laY = entity.pt.getY() +
|
1888 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1889 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1890 |
pointAux.setLocation(laX, laY); |
1891 |
dxfCirclee.setCenter(pointAux); |
1892 |
|
1893 |
// Escala en X = escala en Y ...
|
1894 |
dxfCirclee.setRadius(dxfCircle.getRadius() * sFactorX); |
1895 |
|
1896 |
if (addingToBlock == false) { |
1897 |
entities.add(dxfCirclee); |
1898 |
} |
1899 |
} else if (dxfEntity instanceof DxfLwPolyline) { |
1900 |
dxfLwPolyline = (DxfLwPolyline) dxfEntity; |
1901 |
|
1902 |
DxfLwPolyline dxfLwPolylinee = new DxfLwPolyline(proj, layer);
|
1903 |
Point2D[] points = new Point2D[dxfLwPolyline.pts.size()]; |
1904 |
Point2D[] pointss = new Point2D[dxfLwPolyline.pts.size()]; |
1905 |
|
1906 |
for (int j = 0; j < dxfLwPolyline.pts.size(); j++) { |
1907 |
points[j] = (Point2D) dxfLwPolyline.pts.get(j);
|
1908 |
pointss[j] = new Point2D.Double(); |
1909 |
pointAux = new Point2D.Double(points[j].getX() - bPointX, |
1910 |
points[j].getY() - bPointY); |
1911 |
|
1912 |
double laX = entity.pt.getX() +
|
1913 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1914 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1915 |
double laY = entity.pt.getY() +
|
1916 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1917 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1918 |
pointss[j].setLocation(laX, laY); |
1919 |
|
1920 |
//pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1921 |
dxfLwPolylinee.add(pointss[j]); |
1922 |
|
1923 |
// jmorell, 050405: Bulges en Dxfpolyline para el piloto
|
1924 |
dxfLwPolylinee.addBulge((Double) dxfPolyline.getBulges()
|
1925 |
.get(j)); |
1926 |
} |
1927 |
|
1928 |
if (addingToBlock == false) { |
1929 |
entities.add(dxfLwPolylinee); |
1930 |
} |
1931 |
} else if (dxfEntity instanceof DxfPoint) { |
1932 |
dxfPoint = (DxfPoint) dxfEntity; |
1933 |
point1 = dxfPoint.getPt(); |
1934 |
pointAux = new Point2D.Double(point1.getX() - bPointX, |
1935 |
point1.getY() - bPointY); |
1936 |
|
1937 |
double laX = entity.pt.getX() +
|
1938 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1939 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1940 |
double laY = entity.pt.getY() +
|
1941 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1942 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1943 |
point11.setLocation(laX, laY); |
1944 |
|
1945 |
//point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1946 |
DxfPoint dxfPointt = new DxfPoint(proj, layer);
|
1947 |
|
1948 |
//dxfPointt.pt = point11;
|
1949 |
dxfPointt.setPt(point11); |
1950 |
|
1951 |
if (addingToBlock == false) { |
1952 |
entities.add(dxfPointt); |
1953 |
} |
1954 |
} else if (dxfEntity instanceof DxfText) { |
1955 |
dxfText = (DxfText) dxfEntity; |
1956 |
|
1957 |
if (dxfText.getTwoPointsFlag()) {
|
1958 |
point1 = dxfText.pts[0];
|
1959 |
pointAux = new Point2D.Double(point1.getX() - bPointX, |
1960 |
point1.getY() - bPointY); |
1961 |
|
1962 |
double laX = entity.pt.getX() +
|
1963 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1964 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1965 |
double laY = entity.pt.getY() +
|
1966 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1967 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1968 |
point11.setLocation(laX, laY); |
1969 |
|
1970 |
//point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1971 |
point2 = dxfText.pts[1];
|
1972 |
pointAux = new Point2D.Double(point2.getX() - bPointX, |
1973 |
point2.getY() - bPointY); |
1974 |
laX = entity.pt.getX() + |
1975 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1976 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1977 |
laY = entity.pt.getY() + |
1978 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
1979 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
1980 |
point22.setLocation(laX, laY); |
1981 |
|
1982 |
//point22.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point2.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point2.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point2.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point2.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
1983 |
DxfText dxfTextt = new DxfText(proj, layer,
|
1984 |
dxfText.getText()); |
1985 |
dxfTextt.pts[0] = point11;
|
1986 |
dxfTextt.pts[1] = point22;
|
1987 |
|
1988 |
if (addingToBlock == false) { |
1989 |
entities.add(dxfTextt); |
1990 |
} |
1991 |
} else {
|
1992 |
point1 = dxfText.getPt(); |
1993 |
pointAux = new Point2D.Double(point1.getX() - bPointX, |
1994 |
point1.getY() - bPointY); |
1995 |
|
1996 |
double laX = entity.pt.getX() +
|
1997 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
1998 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
1999 |
double laY = entity.pt.getY() +
|
2000 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
2001 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
2002 |
point11.setLocation(laX, laY); |
2003 |
|
2004 |
//point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
2005 |
DxfText dxfTextt = new DxfText(proj, layer,
|
2006 |
dxfText.getText()); |
2007 |
dxfTextt.setPt(point11); |
2008 |
|
2009 |
if (addingToBlock == false) { |
2010 |
entities.add(dxfTextt); |
2011 |
} |
2012 |
} |
2013 |
} else if (dxfEntity instanceof DxfSolid) { |
2014 |
dxfSolid = (DxfSolid) dxfEntity; |
2015 |
|
2016 |
Point2D[] points = new Point2D[dxfSolid.pts.length]; |
2017 |
Point2D[] pointss = new Point2D[dxfSolid.pts.length]; |
2018 |
|
2019 |
for (int j = 0; j < dxfSolid.pts.length; j++) { |
2020 |
points[j] = (Point2D) dxfSolid.pts[j];
|
2021 |
pointss[j] = new Point2D.Double(); |
2022 |
pointAux = new Point2D.Double(points[j].getX() - bPointX, |
2023 |
points[j].getY() - bPointY); |
2024 |
|
2025 |
double laX = entity.pt.getX() +
|
2026 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
2027 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
2028 |
double laY = entity.pt.getY() +
|
2029 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
2030 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
2031 |
pointss[j].setLocation(laX, laY); |
2032 |
|
2033 |
//pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
|
2034 |
} |
2035 |
|
2036 |
DxfSolid dxfSolidd = new DxfSolid(proj, layer, pointss);
|
2037 |
Point2D aux = dxfSolidd.pts[2]; |
2038 |
dxfSolidd.pts[2] = dxfSolidd.pts[3]; |
2039 |
dxfSolidd.pts[3] = aux;
|
2040 |
|
2041 |
if (addingToBlock == false) { |
2042 |
entities.add(dxfSolidd); |
2043 |
} |
2044 |
} else {
|
2045 |
System.out.println("gestionaInserts: Encontrado elemento desconocido"); |
2046 |
} |
2047 |
} |
2048 |
} |
2049 |
|
2050 |
/* (non-Javadoc)
|
2051 |
* @see org.cresques.io.DxfFile.EntityFactory#createAttdef(org.cresques.io.DxfGroupVector)
|
2052 |
*/
|
2053 |
public void createAttdef(DxfGroupVector grp) throws Exception { |
2054 |
DxfGroup g = null;
|
2055 |
|
2056 |
String defaultValue = ""; |
2057 |
String tagString = ""; |
2058 |
String textStyleName = ""; |
2059 |
String[] attribute = new String[2]; |
2060 |
boolean tagDefined = false; |
2061 |
boolean defValDefined = false; |
2062 |
|
2063 |
if (grp.hasCode(1)) { |
2064 |
defaultValue = grp.getDataAsString(1);
|
2065 |
attribute[1] = DxfConvTexts.ConvertText(defaultValue);
|
2066 |
defValDefined = true;
|
2067 |
|
2068 |
if (tagDefined) {
|
2069 |
attributes.add(attribute); |
2070 |
} |
2071 |
} |
2072 |
|
2073 |
if (grp.hasCode(2)) { |
2074 |
tagString = grp.getDataAsString(2);
|
2075 |
attribute[0] = DxfConvTexts.ConvertText(tagString);
|
2076 |
tagDefined = true;
|
2077 |
|
2078 |
if (defValDefined) {
|
2079 |
attributes.add(attribute); |
2080 |
} |
2081 |
} |
2082 |
|
2083 |
if (grp.hasCode(7)) { |
2084 |
textStyleName = grp.getDataAsString(7);
|
2085 |
textStyleName = DxfConvTexts.ConvertText(textStyleName); |
2086 |
} |
2087 |
|
2088 |
// TODO setNewAttributes();
|
2089 |
} |
2090 |
|
2091 |
/* (non-Javadoc)
|
2092 |
* @see org.cresques.io.DxfFile.EntityFactory#createAttrib(org.cresques.io.DxfGroupVector)
|
2093 |
*/
|
2094 |
public void createAttrib(DxfGroupVector grp) throws Exception { |
2095 |
double x = 0.0; |
2096 |
double y = 0.0; |
2097 |
double z = 0.0; |
2098 |
double h = 0.0; |
2099 |
double rot = 0.0; |
2100 |
DxfGroup g = null;
|
2101 |
Point2D pt = null; |
2102 |
|
2103 |
String defaultValue = ""; |
2104 |
String tagString = ""; |
2105 |
String textStyleName = ""; |
2106 |
String[] att = new String[2]; |
2107 |
boolean tagDefined = false; |
2108 |
boolean defValDefined = false; |
2109 |
int attributeFlags = 0; |
2110 |
double extx = 0.0; |
2111 |
double exty = 0.0; |
2112 |
double extz = 1.0; |
2113 |
|
2114 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2115 |
DxfAttrib entity = new DxfAttrib(proj, layer);
|
2116 |
|
2117 |
if (grp.hasCode(1)) { |
2118 |
String strAux1 = grp.getDataAsString(1); |
2119 |
strAux1 = DxfConvTexts.ConvertText(strAux1); |
2120 |
defaultValue = strAux1; |
2121 |
att[1] = DxfConvTexts.ConvertText(defaultValue);
|
2122 |
defValDefined = true;
|
2123 |
|
2124 |
/*if (tagDefined) {
|
2125 |
insFea.setProp(att[0], att[1]);
|
2126 |
ptFea.setProp(att[0], att[1]);
|
2127 |
}
|
2128 |
feature.setProp("text", strAux1);*/
|
2129 |
} |
2130 |
|
2131 |
if (grp.hasCode(2)) { |
2132 |
String strAux2 = grp.getDataAsString(2); |
2133 |
strAux2 = DxfConvTexts.ConvertText(strAux2); |
2134 |
tagString = strAux2; |
2135 |
att[0] = DxfConvTexts.ConvertText(tagString);
|
2136 |
tagDefined = true;
|
2137 |
|
2138 |
/*if (defValDefined) {
|
2139 |
insFea.setProp(att[0], att[1]);
|
2140 |
ptFea.setProp(att[0], att[1]);
|
2141 |
}*/
|
2142 |
} |
2143 |
|
2144 |
if (grp.hasCode(7)) { |
2145 |
textStyleName = grp.getDataAsString(7);
|
2146 |
textStyleName = DxfConvTexts.ConvertText(textStyleName); |
2147 |
} |
2148 |
|
2149 |
x = grp.getDataAsDouble(10);
|
2150 |
y = grp.getDataAsDouble(20);
|
2151 |
z = grp.getDataAsDouble(30);
|
2152 |
|
2153 |
if (grp.hasCode(210)) { |
2154 |
extx = grp.getDataAsDouble(210);
|
2155 |
} |
2156 |
|
2157 |
if (grp.hasCode(220)) { |
2158 |
exty = grp.getDataAsDouble(220);
|
2159 |
} |
2160 |
|
2161 |
if (grp.hasCode(230)) { |
2162 |
extz = grp.getDataAsDouble(230);
|
2163 |
} |
2164 |
|
2165 |
Point3D point_in = new Point3D(x, y, z);
|
2166 |
Point3D xtru = new Point3D(extx, exty, extz);
|
2167 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
2168 |
x = point_out.getX(); |
2169 |
y = point_out.getY(); |
2170 |
z = point_out.getZ(); |
2171 |
entity.setPt(proj.createPoint(x, y)); |
2172 |
|
2173 |
if (grp.hasCode(40)) { |
2174 |
Double heightD = new Double(grp.getDataAsDouble(40)); |
2175 |
String heightS = heightD.toString();
|
2176 |
|
2177 |
//feature.setProp("textHeight", heightS);
|
2178 |
} else {
|
2179 |
//feature.setProp("textHeight", "20.0");
|
2180 |
} |
2181 |
|
2182 |
if (grp.hasCode(50)) { |
2183 |
Double rotD = new Double(grp.getDataAsDouble(50)); |
2184 |
String rotS = rotD.toString();
|
2185 |
|
2186 |
//feature.setProp("textRotation", rotS);
|
2187 |
} else {
|
2188 |
//feature.setProp("textRotation", "0.0");
|
2189 |
} |
2190 |
|
2191 |
if (grp.hasCode(62)) { |
2192 |
entity.dxfColor = grp.getDataAsInt(62);
|
2193 |
} else {
|
2194 |
//entity.dxfColor = 0;
|
2195 |
} |
2196 |
|
2197 |
if (grp.hasCode(70)) { |
2198 |
attributeFlags = grp.getDataAsInt(70);
|
2199 |
} |
2200 |
|
2201 |
if (attributeFlags == 8) { |
2202 |
if (addingToBlock == false) { |
2203 |
entities.add(entity); |
2204 |
} else {
|
2205 |
blk.add(entity); |
2206 |
} |
2207 |
} |
2208 |
} |
2209 |
|
2210 |
/* (non-Javadoc)
|
2211 |
* @see org.cresques.io.DxfFile.EntityFactory#getAttributes()
|
2212 |
*/
|
2213 |
public Vector getAttributes() { |
2214 |
return attributes;
|
2215 |
} |
2216 |
|
2217 |
/* (non-Javadoc)
|
2218 |
* @see org.cresques.io.DxfFile.EntityFactory#depureAttributes()
|
2219 |
*/
|
2220 |
public void depureAttributes() { |
2221 |
// TODO Auto-generated method stub
|
2222 |
} |
2223 |
|
2224 |
/* (non-Javadoc)
|
2225 |
* @see org.cresques.io.DxfFile.EntityFactory#isDxf3DFile()
|
2226 |
*/
|
2227 |
public boolean isDxf3DFile() { |
2228 |
// TODO Auto-generated method stub
|
2229 |
return false; |
2230 |
} |
2231 |
} |