svn-gvsig-desktop / branches / v10 / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfFeatureMaker.java @ 12363
History | View | Annotate | Download (129 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 java.awt.Graphics2D; |
27 |
import java.awt.geom.AffineTransform; |
28 |
import java.awt.geom.Point2D; |
29 |
import java.util.Iterator; |
30 |
import java.util.Vector; |
31 |
|
32 |
import org.cresques.cts.ICoordTrans; |
33 |
import org.cresques.cts.IProjection; |
34 |
import org.cresques.geo.Point3D; |
35 |
import org.cresques.geo.Projected; |
36 |
import org.cresques.geo.ViewPortData; |
37 |
import org.cresques.io.DxfFile; |
38 |
import org.cresques.io.DxfGroup; |
39 |
import org.cresques.io.DxfGroupVector; |
40 |
import org.cresques.px.Extent; |
41 |
import org.cresques.px.IObjList; |
42 |
import org.cresques.px.gml.Feature; |
43 |
import org.cresques.px.gml.FeatureCollection; |
44 |
import org.cresques.px.gml.InsPoint3D; |
45 |
import org.cresques.px.gml.LineString; |
46 |
import org.cresques.px.gml.LineString3D; |
47 |
import org.cresques.px.gml.Polygon; |
48 |
import org.cresques.px.gml.Polygon3D; |
49 |
|
50 |
|
51 |
/**
|
52 |
* La clase DxfFeatureMaker facilita la creaci?n de entidades en un modelo de datos
|
53 |
* GIS. La creaci?n se realiza partiendo de las entidades obtenidas de un fichero DXF.
|
54 |
* @author jmorell
|
55 |
*/
|
56 |
public class DxfFeatureMaker implements DxfFile.EntityFactory, Projected { |
57 |
IProjection proj = null;
|
58 |
|
59 |
//Feature lastFeature = null;
|
60 |
Feature lastFeaBordes = null;
|
61 |
Feature lastFeaFondos = null;
|
62 |
boolean isDoubleFeatured = false; |
63 |
FeatureCollection features = null;
|
64 |
double bulge = 0.0; |
65 |
double xtruX = 0.0; |
66 |
double xtruY = 0.0; |
67 |
double xtruZ = 1.0; |
68 |
int polylineFlag = 0; |
69 |
Point3D firstPt = new Point3D();
|
70 |
Point3D ptAnterior = null;
|
71 |
boolean addingToBlock = false; |
72 |
int iterator = 0; |
73 |
FeatureCollection blk = null;
|
74 |
Vector blkList = null; |
75 |
DxfTable layers = null;
|
76 |
private Vector faces = null; |
77 |
private boolean hasFaces = false; |
78 |
private int facesIterador = 1; |
79 |
private Point2D facesFirstPoint = null; |
80 |
private Vector attributes = null; |
81 |
private boolean constantPolylineElevation; |
82 |
private double lastVertexElevation; |
83 |
private boolean dxf3DFile; |
84 |
|
85 |
/**
|
86 |
* Constructor de DxfFeatureMaker.
|
87 |
* @param proj, proyecci?n cartogr?fica en la que se encontrar?n las entidades
|
88 |
* que creemos.
|
89 |
*/
|
90 |
public DxfFeatureMaker(IProjection proj) {
|
91 |
this.proj = proj;
|
92 |
layers = new DxfTable();
|
93 |
features = new FeatureCollection(proj);
|
94 |
blkList = new Vector(); |
95 |
attributes = new Vector(); |
96 |
dxf3DFile = false;
|
97 |
} |
98 |
|
99 |
/* (non-Javadoc)
|
100 |
* @see org.cresques.io.DxfFile.EntityFactory#setAddingToBlock(boolean)
|
101 |
*/
|
102 |
public void setAddingToBlock(boolean a) { |
103 |
addingToBlock = a; |
104 |
} |
105 |
|
106 |
/* (non-Javadoc)
|
107 |
* @see org.cresques.io.DxfFile.EntityFactory#createLayer(org.cresques.io.DxfGroupVector)
|
108 |
*/
|
109 |
public void createLayer(DxfGroupVector v) throws Exception { |
110 |
int color = v.getDataAsInt(62); |
111 |
DxfLayer layer = new DxfLayer(v.getDataAsString(2), |
112 |
Math.abs(v.getDataAsInt(62))); |
113 |
|
114 |
if (color < 0) { |
115 |
layer.isOff = true;
|
116 |
} |
117 |
|
118 |
layer.lType = v.getDataAsString(6);
|
119 |
layer.setFlags(v.getDataAsInt(70));
|
120 |
|
121 |
// compruebo flags
|
122 |
if ((layer.flags & 0x01) == 0x01) { |
123 |
layer.frozen = true;
|
124 |
} |
125 |
|
126 |
if ((layer.flags & 0x02) == 0x02) { |
127 |
layer.frozen = true;
|
128 |
} |
129 |
|
130 |
System.out.println("LAYER color=" + layer.getColor()); |
131 |
|
132 |
layers.add(layer); |
133 |
} |
134 |
|
135 |
/* (non-Javadoc)
|
136 |
* @see org.cresques.io.DxfFile.EntityFactory#createPolyline(org.cresques.io.DxfGroupVector)
|
137 |
*/
|
138 |
public void createPolyline(DxfGroupVector grp) throws Exception { |
139 |
LineString3D lineString3D = new LineString3D();
|
140 |
Polygon3D polygon3D = new Polygon3D();
|
141 |
|
142 |
//Feature feature= new Feature();
|
143 |
Feature feaBordes = new Feature();
|
144 |
Feature feaFondos = new Feature();
|
145 |
double x = 0.0; |
146 |
double y = 0.0; |
147 |
double z = 0.0; |
148 |
int flags = 0; |
149 |
constantPolylineElevation = true;
|
150 |
|
151 |
// 041122: Cada polyline tiene asociado un objeto faces distinto.
|
152 |
faces = new Vector(); |
153 |
|
154 |
//feature.setProp("dxfEntity", "Polyline");
|
155 |
feaBordes.setProp("dxfEntity", "Polyline"); |
156 |
feaFondos.setProp("dxfEntity", "Polyline"); |
157 |
|
158 |
if (grp.hasCode(8)) { |
159 |
//feature.setProp("layer", grp.getDataAsString(8));
|
160 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
161 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
162 |
} |
163 |
|
164 |
if (grp.hasCode(39)) { |
165 |
Double doub = new Double(grp.getDataAsDouble(39)); |
166 |
String string = doub.toString();
|
167 |
|
168 |
//feature.setProp("thickness", string);
|
169 |
feaBordes.setProp("thickness", string);
|
170 |
feaFondos.setProp("thickness", string);
|
171 |
} else {
|
172 |
Double doub = new Double(0.0); |
173 |
|
174 |
//feature.setProp("thickness", doub.toString());
|
175 |
feaBordes.setProp("thickness", doub.toString());
|
176 |
feaFondos.setProp("thickness", doub.toString());
|
177 |
} |
178 |
|
179 |
if (grp.hasCode(62)) { |
180 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
181 |
String string = integer.toString();
|
182 |
|
183 |
//feature.setProp("color", string);
|
184 |
feaBordes.setProp("color", string);
|
185 |
feaFondos.setProp("color", string);
|
186 |
feaBordes.setProp("colorByLayer", "false"); |
187 |
feaFondos.setProp("colorByLayer", "false"); |
188 |
} else {
|
189 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
190 |
int clr = layer.colorNumber;
|
191 |
Integer integer = new Integer(clr); |
192 |
String string = integer.toString();
|
193 |
|
194 |
//feature.setProp("color", string);
|
195 |
feaBordes.setProp("color", string);
|
196 |
feaFondos.setProp("color", string);
|
197 |
feaBordes.setProp("colorByLayer", "true"); |
198 |
feaFondos.setProp("colorByLayer", "true"); |
199 |
} |
200 |
|
201 |
if (grp.hasCode(10)) { |
202 |
x = grp.getDataAsDouble(10);
|
203 |
} |
204 |
|
205 |
if (grp.hasCode(20)) { |
206 |
y = grp.getDataAsDouble(20);
|
207 |
} |
208 |
|
209 |
if (grp.hasCode(30)) { |
210 |
z = grp.getDataAsDouble(30);
|
211 |
|
212 |
if (z != 0.0) { |
213 |
dxf3DFile = true;
|
214 |
} |
215 |
|
216 |
Double doub = new Double(z); |
217 |
String string = doub.toString();
|
218 |
|
219 |
//feature.setProp("elevation", string);
|
220 |
feaBordes.setProp("elevation", string);
|
221 |
feaFondos.setProp("elevation", string);
|
222 |
} else {
|
223 |
Double doub = new Double(0.0); |
224 |
|
225 |
//feature.setProp("elevation", doub.toString());
|
226 |
feaBordes.setProp("elevation", doub.toString());
|
227 |
feaFondos.setProp("elevation", doub.toString());
|
228 |
} |
229 |
|
230 |
if (grp.hasCode(70)) { |
231 |
flags = grp.getDataAsInt(70);
|
232 |
} |
233 |
|
234 |
if (grp.hasCode(210)) { |
235 |
xtruX = grp.getDataAsDouble(210);
|
236 |
} |
237 |
|
238 |
if (grp.hasCode(220)) { |
239 |
xtruY = grp.getDataAsDouble(220);
|
240 |
} |
241 |
|
242 |
if (grp.hasCode(230)) { |
243 |
xtruZ = grp.getDataAsDouble(230);
|
244 |
} |
245 |
|
246 |
if (((flags & 0x01) == 0x01) || ((flags & 0x40) == 0x40)) { |
247 |
feaBordes.setGeometry(lineString3D); |
248 |
feaFondos.setGeometry(polygon3D); |
249 |
lastFeaBordes = feaBordes; |
250 |
lastFeaFondos = feaFondos; |
251 |
isDoubleFeatured = true;
|
252 |
} else if ((flags & 0x01) == 0x00) { |
253 |
feaBordes.setGeometry(lineString3D); |
254 |
lastFeaBordes = feaBordes; |
255 |
isDoubleFeatured = false;
|
256 |
} else {
|
257 |
System.out.println("Detectada una Polyline Flag que no corresponde"); |
258 |
System.out.println("a una Polyline corriente, ni a una Closed Polyline"); |
259 |
} |
260 |
} |
261 |
|
262 |
/* (non-Javadoc)
|
263 |
* @see org.cresques.io.DxfFile.EntityFactory#endSeq(org.cresques.io.DxfGroupVector)
|
264 |
*/
|
265 |
public void endSeq() throws Exception { |
266 |
if (isDoubleFeatured) {
|
267 |
if (lastFeaBordes.getGeometry() instanceof LineString3D) { |
268 |
Feature feaBordes = lastFeaBordes; |
269 |
Feature feaFondos = lastFeaFondos; |
270 |
LineString3D lineString3D = (LineString3D) feaBordes.getGeometry(); |
271 |
Polygon3D polygon3D = (Polygon3D) feaFondos.getGeometry(); |
272 |
lineString3D.add(firstPt); |
273 |
|
274 |
if ((bulge != 0) && |
275 |
!((lineString3D.get(lineString3D.pointNr() - 2).getX() == lineString3D.get(lineString3D.pointNr() -
|
276 |
1)
|
277 |
.getX()) && |
278 |
(lineString3D.get(lineString3D.pointNr() - 2).getY() == lineString3D.get(lineString3D.pointNr() -
|
279 |
1)
|
280 |
.getY()))) { |
281 |
// 041122: Correcci?n del bug en los bulges de FIXT3.DXF
|
282 |
Vector arc = createArc(new Point2D.Double(lineString3D.get(lineString3D.pointNr() - |
283 |
2)
|
284 |
.getX(), |
285 |
lineString3D.get(lineString3D.pointNr() - |
286 |
2)
|
287 |
.getY()), |
288 |
new Point2D.Double(lineString3D.get(lineString3D.pointNr() - |
289 |
1)
|
290 |
.getX(), |
291 |
lineString3D.get(lineString3D.pointNr() - |
292 |
1)
|
293 |
.getY()), |
294 |
bulge); |
295 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
296 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
297 |
polygon3D.remove(lineString3D.pointNr() - 1);
|
298 |
polygon3D.remove(lineString3D.pointNr() - 1);
|
299 |
|
300 |
if (bulge > 0) { |
301 |
for (int i = 0; i < arc.size(); i++) { |
302 |
Point2D ptAux = new Point2D.Double(); |
303 |
double z = ((Point3D) lineString3D.get(lineString3D.pointNr() -
|
304 |
2)).getZ();
|
305 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
306 |
((Point2D) arc.get(i)).getY());
|
307 |
|
308 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
309 |
ptAux.getY(), z); |
310 |
lineString3D.add(ptAux3D); |
311 |
polygon3D.add(ptAux3D); |
312 |
|
313 |
if (lineString3D.pointNr() == 1) { |
314 |
firstPt = ptAux3D; |
315 |
} |
316 |
} |
317 |
} else {
|
318 |
for (int i = arc.size() - 1; i >= 0; i--) { |
319 |
Point2D ptAux = new Point2D.Double(); |
320 |
double z = ((Point3D) lineString3D.get(lineString3D.pointNr() -
|
321 |
2)).getZ();
|
322 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
323 |
((Point2D) arc.get(i)).getY());
|
324 |
|
325 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
326 |
ptAux.getY(), z); |
327 |
lineString3D.add(ptAux3D); |
328 |
polygon3D.add(ptAux3D); |
329 |
|
330 |
if ((lineString3D.pointNr() == 1) || |
331 |
(polygon3D.pointNr() == 1)) {
|
332 |
firstPt = ptAux3D; |
333 |
} |
334 |
} |
335 |
} |
336 |
|
337 |
// 041122
|
338 |
bulge = 0.0;
|
339 |
} |
340 |
|
341 |
if (hasFaces) {
|
342 |
//System.out.println("Sabe que es un poligono.");
|
343 |
//System.out.println("POLYLINE: caras=" +faces.size()+", puntos="+ lineString.pointNr());
|
344 |
LineString ls1 = new LineString();
|
345 |
Polygon pl1 = new Polygon(); |
346 |
LineString ls2 = new LineString();
|
347 |
Polygon pl2 = new Polygon(); |
348 |
LineString ls = new LineString();
|
349 |
Polygon pl = new Polygon(); |
350 |
int[] face; |
351 |
int i0;
|
352 |
int i1;
|
353 |
Iterator iter = faces.iterator();
|
354 |
|
355 |
while (iter.hasNext()) {
|
356 |
face = (int[]) iter.next(); |
357 |
i0 = face[3];
|
358 |
|
359 |
for (int i = 0; i < 4; i++) { |
360 |
i1 = face[i]; |
361 |
|
362 |
if (i0 > 0) { |
363 |
if ((facesIterador % 2) != 0) { |
364 |
ls1.add((Point2D) lineString3D.get(i0 - 1)); |
365 |
pl1.add((Point2D) polygon3D.get(i0 - 1)); |
366 |
} else {
|
367 |
ls2.add((Point2D) lineString3D.get(i0 - 1)); |
368 |
pl2.add((Point2D) polygon3D.get(i0 - 1)); |
369 |
} |
370 |
|
371 |
facesIterador = facesIterador + 1;
|
372 |
} |
373 |
|
374 |
i0 = i1; |
375 |
} |
376 |
} |
377 |
|
378 |
facesFirstPoint = new Point2D.Double(ls1.get(0).getX(), |
379 |
ls1.get(0).getY());
|
380 |
|
381 |
for (int i = 0; i < ls1.pointNr(); i++) { |
382 |
ls.add(ls1.get(i)); |
383 |
pl.add(pl1.get(i)); |
384 |
} |
385 |
|
386 |
for (int i = ls2.pointNr() - 1; i > 0; i--) { |
387 |
ls.add(ls2.get(i)); |
388 |
pl.add(pl2.get(i)); |
389 |
} |
390 |
|
391 |
ls.add(facesFirstPoint); |
392 |
pl.add(facesFirstPoint); |
393 |
lastFeaBordes.setGeometry(ls); |
394 |
lastFeaFondos.setGeometry(pl); |
395 |
} else {
|
396 |
lastFeaBordes.setGeometry(lineString3D); |
397 |
lastFeaFondos.setGeometry(polygon3D); |
398 |
} |
399 |
|
400 |
// 041130: Rellena las props con los atributos.
|
401 |
completeAttributes(lastFeaBordes); |
402 |
completeAttributes(lastFeaFondos); |
403 |
|
404 |
setPolylineElevation(lastFeaBordes, lastFeaFondos); |
405 |
|
406 |
if (addingToBlock == false) { |
407 |
//features.add(lastFeaBordes);
|
408 |
features.add(lastFeaFondos); |
409 |
} else {
|
410 |
//blk.add(lastFeaBordes);
|
411 |
blk.add(lastFeaFondos); |
412 |
} |
413 |
|
414 |
lastFeaBordes = null;
|
415 |
lastFeaFondos = null;
|
416 |
} else if (lastFeaBordes.getGeometry() instanceof InsPoint3D) { |
417 |
// Se trata de un SEQEND despues de un ATTRIB
|
418 |
copyAttributes(lastFeaBordes); |
419 |
|
420 |
gestionaInsert(lastFeaBordes); |
421 |
|
422 |
if (addingToBlock == false) { |
423 |
features.add(lastFeaFondos); |
424 |
} else {
|
425 |
blk.add(lastFeaBordes); |
426 |
} |
427 |
|
428 |
lastFeaBordes = null;
|
429 |
lastFeaFondos = null;
|
430 |
} else {
|
431 |
// Caso no contemplado.
|
432 |
} |
433 |
} else {
|
434 |
if (lastFeaBordes.getGeometry() instanceof LineString3D) { |
435 |
Feature feaBordes = lastFeaBordes; |
436 |
LineString3D lineString3D = (LineString3D) feaBordes.getGeometry(); |
437 |
|
438 |
if ((bulge != 0) && |
439 |
!((lineString3D.get(lineString3D.pointNr() - 2).getX() == lineString3D.get(lineString3D.pointNr() -
|
440 |
1)
|
441 |
.getX()) && |
442 |
(lineString3D.get(lineString3D.pointNr() - 2).getY() == lineString3D.get(lineString3D.pointNr() -
|
443 |
1)
|
444 |
.getY()))) { |
445 |
// 041122: Correcci?n del bug en los bulges de FIXT3.DXF
|
446 |
Vector arc = createArc(new Point2D.Double(lineString3D.get(lineString3D.pointNr() - |
447 |
2)
|
448 |
.getX(), |
449 |
lineString3D.get(lineString3D.pointNr() - |
450 |
2)
|
451 |
.getY()), |
452 |
new Point2D.Double(lineString3D.get(lineString3D.pointNr() - |
453 |
1)
|
454 |
.getX(), |
455 |
lineString3D.get(lineString3D.pointNr() - |
456 |
1)
|
457 |
.getY()), |
458 |
bulge); |
459 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
460 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
461 |
|
462 |
if (bulge > 0) { |
463 |
for (int i = 0; i < arc.size(); i++) { |
464 |
Point2D ptAux = new Point2D.Double(); |
465 |
double z = ((Point3D) lineString3D.get(lineString3D.pointNr() -
|
466 |
2)).getZ();
|
467 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
468 |
((Point2D) arc.get(i)).getY());
|
469 |
|
470 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
471 |
ptAux.getY(), z); |
472 |
lineString3D.add(ptAux3D); |
473 |
|
474 |
if (lineString3D.pointNr() == 1) { |
475 |
firstPt = ptAux3D; |
476 |
} |
477 |
} |
478 |
} else {
|
479 |
for (int i = arc.size() - 1; i >= 0; i--) { |
480 |
Point2D ptAux = new Point2D.Double(); |
481 |
double z = ((Point3D) lineString3D.get(lineString3D.pointNr() -
|
482 |
2)).getZ();
|
483 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
484 |
((Point2D) arc.get(i)).getY());
|
485 |
|
486 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
487 |
ptAux.getY(), z); |
488 |
lineString3D.add(ptAux3D); |
489 |
|
490 |
if (lineString3D.pointNr() == 1) { |
491 |
firstPt = ptAux3D; |
492 |
} |
493 |
} |
494 |
} |
495 |
|
496 |
// 041122
|
497 |
bulge = 0.0;
|
498 |
} |
499 |
|
500 |
if (hasFaces) {
|
501 |
//System.out.println("POLYLINE: caras=" +faces.size()+", puntos="+ lineString.pointNr());
|
502 |
LineString ls1 = new LineString();
|
503 |
LineString ls2 = new LineString();
|
504 |
LineString ls = new LineString();
|
505 |
int[] face; |
506 |
int i0;
|
507 |
int i1;
|
508 |
Iterator iter = faces.iterator();
|
509 |
|
510 |
while (iter.hasNext()) {
|
511 |
face = (int[]) iter.next(); |
512 |
i0 = face[3];
|
513 |
|
514 |
for (int i = 0; i < 4; i++) { |
515 |
i1 = face[i]; |
516 |
|
517 |
if (i0 > 0) { |
518 |
if ((facesIterador % 2) != 0) { |
519 |
ls1.add((Point2D) lineString3D.get(i0 - 1)); |
520 |
|
521 |
//ls.add((Point2D)lineString.get(Math.abs(i1)-1));
|
522 |
} else {
|
523 |
ls2.add((Point2D) lineString3D.get(i0 - 1)); |
524 |
|
525 |
//ls.add((Point2D)lineString.get(Math.abs(i1)-1));
|
526 |
} |
527 |
|
528 |
facesIterador = facesIterador + 1;
|
529 |
} |
530 |
|
531 |
i0 = i1; |
532 |
} |
533 |
} |
534 |
|
535 |
facesFirstPoint = new Point2D.Double(ls1.get(0).getX(), |
536 |
ls1.get(0).getY());
|
537 |
|
538 |
for (int i = 0; i < ls1.pointNr(); i++) { |
539 |
ls.add(ls1.get(i)); |
540 |
} |
541 |
|
542 |
for (int i = ls2.pointNr() - 1; i > 0; i--) { |
543 |
ls.add(ls2.get(i)); |
544 |
} |
545 |
|
546 |
ls.add(facesFirstPoint); |
547 |
lastFeaBordes.setGeometry(ls); |
548 |
} else {
|
549 |
lastFeaBordes.setGeometry(lineString3D); |
550 |
} |
551 |
|
552 |
// 041130: Rellena las props con los atributos.
|
553 |
completeAttributes(lastFeaBordes); |
554 |
|
555 |
setPolylineElevation(lastFeaBordes); |
556 |
|
557 |
if (addingToBlock == false) { |
558 |
features.add(lastFeaBordes); |
559 |
} else {
|
560 |
blk.add(lastFeaBordes); |
561 |
} |
562 |
|
563 |
lastFeaBordes = null;
|
564 |
} else {
|
565 |
// Se trata de un SEQEND despues de un ATTRIB
|
566 |
} |
567 |
} |
568 |
|
569 |
xtruX = 0.0;
|
570 |
xtruY = 0.0;
|
571 |
xtruZ = 1.0;
|
572 |
bulge = 0.0;
|
573 |
isDoubleFeatured = false;
|
574 |
hasFaces = false;
|
575 |
facesIterador = 1;
|
576 |
} |
577 |
|
578 |
/**
|
579 |
* Establece un valor constante para la elevaci?n de una polil?nea.
|
580 |
* @param feaBordes, la polil?nea.
|
581 |
*/
|
582 |
private void setPolylineElevation(Feature feaBordes) { |
583 |
if (constantPolylineElevation) {
|
584 |
Double doub = new Double(lastVertexElevation); |
585 |
String string = doub.toString();
|
586 |
feaBordes.setProp("elevation", string);
|
587 |
} else {
|
588 |
Double doub = new Double(0.0); |
589 |
String string = doub.toString();
|
590 |
feaBordes.setProp("elevation", string);
|
591 |
} |
592 |
} |
593 |
|
594 |
/**
|
595 |
* Establece un valor constante para la elevaci?n de un pol?gono.
|
596 |
* @param feaBordes, borde del pol?gono.
|
597 |
* @param feaFondos, fondo del pol?gono.
|
598 |
*/
|
599 |
private void setPolylineElevation(Feature feaBordes, Feature feaFondos) { |
600 |
if (constantPolylineElevation) {
|
601 |
Double doub = new Double(lastVertexElevation); |
602 |
String string = doub.toString();
|
603 |
feaBordes.setProp("elevation", string);
|
604 |
feaFondos.setProp("elevation", string);
|
605 |
} else {
|
606 |
Double doub = new Double(0.0); |
607 |
String string = doub.toString();
|
608 |
feaBordes.setProp("elevation", string);
|
609 |
feaFondos.setProp("elevation", string);
|
610 |
} |
611 |
} |
612 |
|
613 |
/* (non-Javadoc)
|
614 |
* @see org.cresques.io.DxfFile.EntityFactory#addVertex(org.cresques.io.DxfGroupVector)
|
615 |
*/
|
616 |
public void addVertex(DxfGroupVector grp) throws Exception { |
617 |
double x = 0.0; |
618 |
double y = 0.0; |
619 |
double z = 0.0; |
620 |
int vFlags = 0; |
621 |
|
622 |
if (isDoubleFeatured) {
|
623 |
Feature feaBordes = lastFeaBordes; |
624 |
Feature feaFondos = lastFeaFondos; |
625 |
LineString3D lineString3D = (LineString3D) feaBordes.getGeometry(); |
626 |
Polygon3D polygon3D = (Polygon3D) feaFondos.getGeometry(); |
627 |
|
628 |
if (grp.hasCode(8)) { |
629 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
630 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
631 |
} |
632 |
|
633 |
if (grp.hasCode(70)) { |
634 |
vFlags = grp.getDataAsInt(70);
|
635 |
} |
636 |
|
637 |
x = grp.getDataAsDouble(10);
|
638 |
y = grp.getDataAsDouble(20);
|
639 |
z = grp.getDataAsDouble(30);
|
640 |
|
641 |
Point3D point_in = new Point3D(x, y, z);
|
642 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
643 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
644 |
x = point_out.getX(); |
645 |
y = point_out.getY(); |
646 |
z = point_out.getZ(); |
647 |
|
648 |
if (z != 0.0) { |
649 |
dxf3DFile = true;
|
650 |
} |
651 |
|
652 |
if ((z != lastVertexElevation) && (lineString3D.pointNr() > 0)) { |
653 |
constantPolylineElevation = false;
|
654 |
} |
655 |
|
656 |
lastVertexElevation = z; |
657 |
|
658 |
//System.out.println("addVertex(): vFlags = " + vFlags);
|
659 |
if (((vFlags & 0x80) == 0x80) && ((vFlags & 0x40) == 0)) { |
660 |
int[] face = { 0, 0, 0, 0 }; |
661 |
face[0] = grp.getDataAsInt(71); |
662 |
face[1] = grp.getDataAsInt(72); |
663 |
face[2] = grp.getDataAsInt(73); |
664 |
face[3] = grp.getDataAsInt(74); |
665 |
addFace(face); |
666 |
} else if ((vFlags & 0x10) == 0x10) { |
667 |
// Son vertices que se trataran cuando se implementen
|
668 |
// los splines. En principio no se hace nada con ellos.
|
669 |
} else {
|
670 |
Point3D pt = new Point3D(proj.createPoint(x, y).getX(),
|
671 |
proj.createPoint(x, y).getY(), z); |
672 |
lineString3D.add(pt); |
673 |
polygon3D.add(pt); |
674 |
|
675 |
if (lineString3D.pointNr() == 1) { |
676 |
firstPt = pt; |
677 |
} |
678 |
|
679 |
if (bulge == 0.0) { |
680 |
if (grp.hasCode(42)) { |
681 |
bulge = grp.getDataAsDouble(42);
|
682 |
} else {
|
683 |
bulge = 0.0;
|
684 |
} |
685 |
} else {
|
686 |
double bulge_aux = 0.0; |
687 |
|
688 |
if (grp.hasCode(42)) { |
689 |
bulge_aux = grp.getDataAsDouble(42);
|
690 |
} else {
|
691 |
bulge_aux = 0.0;
|
692 |
} |
693 |
|
694 |
//int cnt = lineString.pointNr();
|
695 |
if ((ptAnterior.getX() == pt.getX()) &&
|
696 |
(ptAnterior.getY() == pt.getY())) { |
697 |
// no se construye el arco
|
698 |
} else {
|
699 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
700 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
701 |
polygon3D.remove(polygon3D.pointNr() - 1);
|
702 |
polygon3D.remove(polygon3D.pointNr() - 1);
|
703 |
|
704 |
Vector arc = createArc(ptAnterior, pt, bulge);
|
705 |
|
706 |
if (bulge > 0) { |
707 |
for (int i = 0; i < arc.size(); i++) { |
708 |
Point2D ptAux = new Point2D.Double(); |
709 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
710 |
((Point2D) arc.get(i)).getY());
|
711 |
|
712 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
713 |
ptAux.getY(), z); |
714 |
lineString3D.add(ptAux3D); |
715 |
polygon3D.add(ptAux3D); |
716 |
|
717 |
if (lineString3D.pointNr() == 1) { |
718 |
firstPt = ptAux3D; |
719 |
} |
720 |
} |
721 |
} else {
|
722 |
for (int i = arc.size() - 1; i >= 0; i--) { |
723 |
Point2D ptAux = new Point2D.Double(); |
724 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
725 |
((Point2D) arc.get(i)).getY());
|
726 |
|
727 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
728 |
ptAux.getY(), z); |
729 |
lineString3D.add(ptAux3D); |
730 |
polygon3D.add(ptAux3D); |
731 |
|
732 |
if ((lineString3D.pointNr() == 1) || |
733 |
(polygon3D.pointNr() == 1)) {
|
734 |
firstPt = ptAux3D; |
735 |
} |
736 |
} |
737 |
} |
738 |
} |
739 |
|
740 |
bulge = bulge_aux; |
741 |
} |
742 |
|
743 |
ptAnterior = pt; |
744 |
} |
745 |
} else {
|
746 |
Feature feaBordes = lastFeaBordes; |
747 |
LineString3D lineString3D = (LineString3D) feaBordes.getGeometry(); |
748 |
|
749 |
if (grp.hasCode(8)) { |
750 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
751 |
} |
752 |
|
753 |
if (grp.hasCode(70)) { |
754 |
vFlags = grp.getDataAsInt(70);
|
755 |
} |
756 |
|
757 |
x = grp.getDataAsDouble(10);
|
758 |
y = grp.getDataAsDouble(20);
|
759 |
if (grp.hasCode(30)){ |
760 |
z = grp.getDataAsDouble(30);
|
761 |
} |
762 |
|
763 |
Point3D point_in = new Point3D(x, y, z);
|
764 |
Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
|
765 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
766 |
x = point_out.getX(); |
767 |
y = point_out.getY(); |
768 |
z = point_out.getZ(); |
769 |
|
770 |
if (z != 0.0) { |
771 |
dxf3DFile = true;
|
772 |
} |
773 |
|
774 |
if ((z != lastVertexElevation) && (lineString3D.pointNr() > 0)) { |
775 |
constantPolylineElevation = false;
|
776 |
} |
777 |
|
778 |
lastVertexElevation = z; |
779 |
|
780 |
if (((vFlags & 0x80) == 0x80) && ((vFlags & 0x40) == 0)) { |
781 |
int[] face = { 0, 0, 0, 0 }; |
782 |
face[0] = grp.getDataAsInt(71); |
783 |
face[1] = grp.getDataAsInt(72); |
784 |
face[2] = grp.getDataAsInt(73); |
785 |
face[3] = grp.getDataAsInt(74); |
786 |
addFace(face); |
787 |
} else if ((vFlags & 16) == 16) { |
788 |
// no se hace nada.
|
789 |
} else {
|
790 |
Point3D pt = new Point3D(proj.createPoint(x, y).getX(),
|
791 |
proj.createPoint(x, y).getY(), z); |
792 |
lineString3D.add(pt); |
793 |
|
794 |
//System.out.println("addVertex: pt = " + pt);
|
795 |
if (lineString3D.pointNr() == 1) { |
796 |
firstPt = pt; |
797 |
|
798 |
//System.out.println("addVertex(Primer pto de la lineString, firstPt=pt): firstPt = " + firstPt);
|
799 |
} |
800 |
|
801 |
if (bulge == 0.0) { |
802 |
if (grp.hasCode(42)) { |
803 |
bulge = grp.getDataAsDouble(42);
|
804 |
} else {
|
805 |
bulge = 0.0;
|
806 |
} |
807 |
|
808 |
//System.out.println("addVertex: El vertice anterior tenia bulge=0.0");
|
809 |
} else {
|
810 |
//System.out.println("addVertex: El vertice anterior tiene bulge = " + bulge);
|
811 |
double bulge_aux = 0.0; |
812 |
|
813 |
if (grp.hasCode(42)) { |
814 |
bulge_aux = grp.getDataAsDouble(42);
|
815 |
} else {
|
816 |
bulge_aux = 0.0;
|
817 |
} |
818 |
|
819 |
if ((ptAnterior.getX() == pt.getX()) &&
|
820 |
(ptAnterior.getY() == pt.getY())) { |
821 |
// no se construye el arco
|
822 |
} else {
|
823 |
// Borro los puntos inicio y final del arco.
|
824 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
825 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
826 |
|
827 |
Vector arc = createArc(ptAnterior, pt, bulge);
|
828 |
|
829 |
if (bulge > 0) { |
830 |
for (int i = 0; i < arc.size(); i++) { |
831 |
Point2D ptAux = new Point2D.Double(); |
832 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
833 |
((Point2D) arc.get(i)).getY());
|
834 |
|
835 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
836 |
ptAux.getY(), z); |
837 |
lineString3D.add(ptAux3D); |
838 |
|
839 |
if (lineString3D.pointNr() == 1) { |
840 |
firstPt = ptAux3D; |
841 |
} |
842 |
} |
843 |
} else {
|
844 |
for (int i = arc.size() - 1; i >= 0; i--) { |
845 |
Point2D ptAux = new Point2D.Double(); |
846 |
ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
|
847 |
((Point2D) arc.get(i)).getY());
|
848 |
|
849 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
850 |
ptAux.getY(), z); |
851 |
lineString3D.add(ptAux3D); |
852 |
|
853 |
if (lineString3D.pointNr() == 1) { |
854 |
firstPt = ptAux3D; |
855 |
} |
856 |
} |
857 |
} |
858 |
} |
859 |
|
860 |
bulge = bulge_aux; |
861 |
} |
862 |
|
863 |
ptAnterior = pt; |
864 |
} |
865 |
} |
866 |
} |
867 |
|
868 |
/* (non-Javadoc)
|
869 |
* @see org.cresques.io.DxfFile.EntityFactory#createLwPolyline(org.cresques.io.DxfGroupVector)
|
870 |
*/
|
871 |
public void createLwPolyline(DxfGroupVector grp) throws Exception { |
872 |
double x = 0.0; |
873 |
double y = 0.0; |
874 |
double elev = 0.0; |
875 |
DxfGroup g = null;
|
876 |
LineString3D lineString3D = new LineString3D();
|
877 |
Polygon3D polygon3D = new Polygon3D();
|
878 |
|
879 |
//Geometry geometria;
|
880 |
//Feature feature= new Feature();
|
881 |
Feature feaBordes = new Feature();
|
882 |
Feature feaFondos = new Feature();
|
883 |
int flags = 0; |
884 |
//int NumberOfVertices = 0;
|
885 |
double extx = 0.0; |
886 |
double exty = 0.0; |
887 |
double extz = 1.0; |
888 |
|
889 |
//feature.setProp("dxfEntity", "LwPolyline");
|
890 |
feaBordes.setProp("dxfEntity", "LwPolyline"); |
891 |
feaFondos.setProp("dxfEntity", "LwPolyline"); |
892 |
|
893 |
//if (grp.hasCode(8)) {
|
894 |
//feature.setProp("layer", grp.getDataAsString(8));
|
895 |
// feaBordes.setProp("layer", grp.getDataAsString(8));
|
896 |
//}
|
897 |
|
898 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
899 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
900 |
|
901 |
if (grp.hasCode(38)) { |
902 |
elev = grp.getDataAsDouble(38);
|
903 |
|
904 |
if (elev != 0.0) { |
905 |
dxf3DFile = true;
|
906 |
} |
907 |
|
908 |
Double doub = new Double(elev); |
909 |
String string = doub.toString();
|
910 |
|
911 |
//feature.setProp("elevation", string);
|
912 |
feaBordes.setProp("elevation", string);
|
913 |
feaFondos.setProp("elevation", string);
|
914 |
} else {
|
915 |
Double doub = new Double(0.0); |
916 |
|
917 |
//feature.setProp("elevation", doub.toString());
|
918 |
feaBordes.setProp("elevation", doub.toString());
|
919 |
feaFondos.setProp("elevation", doub.toString());
|
920 |
} |
921 |
|
922 |
if (grp.hasCode(39)) { |
923 |
Double doub = new Double(grp.getDataAsDouble(39)); |
924 |
String string = doub.toString();
|
925 |
|
926 |
//feature.setProp("thickness", string);
|
927 |
feaBordes.setProp("thickness", string);
|
928 |
feaFondos.setProp("thickness", string);
|
929 |
} else {
|
930 |
Double doub = new Double(0.0); |
931 |
|
932 |
//feature.setProp("thickness", doub.toString());
|
933 |
feaBordes.setProp("thickness", doub.toString());
|
934 |
feaFondos.setProp("thickness", doub.toString());
|
935 |
} |
936 |
|
937 |
if (grp.hasCode(62)) { |
938 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
939 |
String string = integer.toString();
|
940 |
|
941 |
//feature.setProp("color", string);
|
942 |
feaBordes.setProp("color", string);
|
943 |
feaFondos.setProp("color", string);
|
944 |
feaBordes.setProp("colorByLayer", "false"); |
945 |
feaFondos.setProp("colorByLayer", "false"); |
946 |
} else {
|
947 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
948 |
int clr = layer.colorNumber;
|
949 |
Integer integer = new Integer(clr); |
950 |
String string = integer.toString();
|
951 |
|
952 |
//feature.setProp("color", string);
|
953 |
feaBordes.setProp("color", string);
|
954 |
feaFondos.setProp("color", string);
|
955 |
feaBordes.setProp("colorByLayer", "true"); |
956 |
feaFondos.setProp("colorByLayer", "true"); |
957 |
} |
958 |
|
959 |
if (grp.hasCode(70)) { |
960 |
flags = grp.getDataAsInt(70);
|
961 |
} |
962 |
|
963 |
if ((flags & 0x01) == 0x01) { |
964 |
//geometria = new Polygon();
|
965 |
feaBordes.setGeometry(lineString3D); |
966 |
feaFondos.setGeometry(polygon3D); |
967 |
isDoubleFeatured = true;
|
968 |
} else {
|
969 |
//geometria = new LineString();
|
970 |
feaBordes.setGeometry(lineString3D); |
971 |
isDoubleFeatured = false;
|
972 |
} |
973 |
|
974 |
//if (grp.hasCode(90)) {
|
975 |
// NumberOfVertices = grp.getDataAsInt(90);
|
976 |
//}
|
977 |
|
978 |
if (grp.hasCode(210)) { |
979 |
extx = grp.getDataAsDouble(210);
|
980 |
} |
981 |
|
982 |
if (grp.hasCode(220)) { |
983 |
exty = grp.getDataAsDouble(220);
|
984 |
} |
985 |
|
986 |
if (grp.hasCode(230)) { |
987 |
extz = grp.getDataAsDouble(230);
|
988 |
} |
989 |
|
990 |
int j = 0; |
991 |
double firstX = 0.0; |
992 |
double firstY = 0.0; |
993 |
boolean hasBulge = false; |
994 |
double bulgeLwp = 0.0; |
995 |
|
996 |
for (int i = 0; i < grp.size(); i++) { |
997 |
g = (DxfGroup) grp.get(i); |
998 |
|
999 |
if (g.getCode() == 10) { |
1000 |
j++; |
1001 |
x = ((Double) g.getData()).doubleValue();
|
1002 |
} else if (g.getCode() == 20) { |
1003 |
y = ((Double) g.getData()).doubleValue();
|
1004 |
|
1005 |
// A?adiendo extrusion a LwPolyline ...
|
1006 |
Point3D point_in1 = new Point3D(x, y, elev);
|
1007 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1008 |
Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru); |
1009 |
x = point_out1.getX(); |
1010 |
y = point_out1.getY(); |
1011 |
elev = point_out1.getZ(); |
1012 |
|
1013 |
//
|
1014 |
if (hasBulge) {
|
1015 |
Point2D finalPoint = new Point2D.Double(x, y); |
1016 |
|
1017 |
if ((((LineString3D) lineString3D).get(lineString3D.pointNr() -
|
1018 |
1).getX() == finalPoint.getX()) &&
|
1019 |
(((LineString3D) lineString3D).get(lineString3D.pointNr() - |
1020 |
1).getY() == finalPoint.getY())) {
|
1021 |
// no se construye el arco
|
1022 |
} else {
|
1023 |
Vector arc = createArc(((LineString3D) lineString3D).get(lineString3D.pointNr() -
|
1024 |
1),
|
1025 |
finalPoint, bulgeLwp); |
1026 |
lineString3D.remove(lineString3D.pointNr() - 1);
|
1027 |
|
1028 |
if (isDoubleFeatured) {
|
1029 |
polygon3D.remove(polygon3D.pointNr() - 1);
|
1030 |
} |
1031 |
|
1032 |
if (bulgeLwp > 0) { |
1033 |
for (int k = 0; k < arc.size(); k++) { |
1034 |
Point2D ptAux = new Point2D.Double(); |
1035 |
ptAux = proj.createPoint(((Point2D) arc.get(k)).getX(),
|
1036 |
((Point2D) arc.get(k)).getY());
|
1037 |
|
1038 |
//System.out.println("createLwPolyline: ptAux = " + ptAux);
|
1039 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
1040 |
ptAux.getY(), elev); |
1041 |
lineString3D.add(ptAux3D); |
1042 |
|
1043 |
//if (lineString.pointNr() == 1) firstPt = ptAux;
|
1044 |
if (isDoubleFeatured) {
|
1045 |
polygon3D.add(ptAux3D); |
1046 |
} |
1047 |
|
1048 |
if ((lineString3D.pointNr() == 1) || |
1049 |
(polygon3D.pointNr() == 1)) {
|
1050 |
firstPt = ptAux3D; |
1051 |
} |
1052 |
} |
1053 |
} else {
|
1054 |
for (int k = arc.size() - 1; k >= 0; k--) { |
1055 |
Point2D ptAux = new Point2D.Double(); |
1056 |
ptAux = proj.createPoint(((Point2D) arc.get(k)).getX(),
|
1057 |
((Point2D) arc.get(k)).getY());
|
1058 |
|
1059 |
Point3D ptAux3D = new Point3D(ptAux.getX(),
|
1060 |
ptAux.getY(), elev); |
1061 |
lineString3D.add(ptAux3D); |
1062 |
|
1063 |
if (isDoubleFeatured) {
|
1064 |
polygon3D.add(ptAux3D); |
1065 |
} |
1066 |
|
1067 |
if ((lineString3D.pointNr() == 1) || |
1068 |
(polygon3D.pointNr() == 1)) {
|
1069 |
firstPt = ptAux3D; |
1070 |
} |
1071 |
} |
1072 |
} |
1073 |
} |
1074 |
|
1075 |
hasBulge = false;
|
1076 |
bulgeLwp = 0.0;
|
1077 |
} else {
|
1078 |
//System.out.println("createLwPolyline: hasBulge siempre es false");
|
1079 |
Point3D ptAux3D = new Point3D(proj.createPoint(x, y).getX(),
|
1080 |
proj.createPoint(x, y).getY(), |
1081 |
elev); |
1082 |
lineString3D.add(ptAux3D); |
1083 |
|
1084 |
if (isDoubleFeatured) {
|
1085 |
polygon3D.add(ptAux3D); |
1086 |
} |
1087 |
} |
1088 |
|
1089 |
if (j == 1) { |
1090 |
firstX = x; |
1091 |
firstY = y; |
1092 |
} |
1093 |
|
1094 |
x = 0.0;
|
1095 |
y = 0.0;
|
1096 |
} else if (g.getCode() == 42 && ((Double)g.getData()).doubleValue()!=0.0) { // Cuando los bulges eran 0.000 se provocaban errores |
1097 |
//System.out.println("createLwPolyline: Lee el bulgeLwp");
|
1098 |
hasBulge = true;
|
1099 |
bulgeLwp = ((Double) g.getData()).doubleValue();
|
1100 |
} |
1101 |
} |
1102 |
|
1103 |
if (isDoubleFeatured) {
|
1104 |
//geometria.add(proj.createPoint(firstX, firstY));
|
1105 |
Point3D ptAux3D = new Point3D(proj.createPoint(firstX, firstY).getX(),
|
1106 |
proj.createPoint(firstX, firstY).getY(), |
1107 |
elev); |
1108 |
lineString3D.add(ptAux3D); |
1109 |
polygon3D.add(ptAux3D); |
1110 |
} |
1111 |
|
1112 |
lastFeaBordes = feaBordes; |
1113 |
|
1114 |
if (isDoubleFeatured) {
|
1115 |
lastFeaFondos = feaFondos; |
1116 |
} |
1117 |
|
1118 |
// 041130: Rellena las props con los atributos.
|
1119 |
completeAttributes(lastFeaBordes); |
1120 |
completeAttributes(lastFeaFondos); |
1121 |
|
1122 |
//features.add(feature);
|
1123 |
if (addingToBlock == false) { |
1124 |
if (isDoubleFeatured) {
|
1125 |
features.add(feaFondos); |
1126 |
} else {
|
1127 |
features.add(feaBordes); |
1128 |
} |
1129 |
} else {
|
1130 |
//System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
|
1131 |
if (isDoubleFeatured) {
|
1132 |
blk.add(feaFondos); |
1133 |
} else {
|
1134 |
blk.add(feaBordes); |
1135 |
} |
1136 |
} |
1137 |
|
1138 |
isDoubleFeatured = false;
|
1139 |
} |
1140 |
|
1141 |
/* (non-Javadoc)
|
1142 |
* @see org.cresques.io.DxfFile.EntityFactory#createLine(org.cresques.io.DxfGroupVector)
|
1143 |
*/
|
1144 |
public void createLine(DxfGroupVector grp) throws Exception { |
1145 |
double x = 0.0; |
1146 |
double y = 0.0; |
1147 |
double z1 = 0.0; |
1148 |
double z2 = 0.0; |
1149 |
double elev = 0.0; |
1150 |
DxfGroup g = null;
|
1151 |
Point2D pt1 = null; |
1152 |
Point2D pt2 = null; |
1153 |
LineString3D lineString3D = new LineString3D();
|
1154 |
Feature feature = new Feature();
|
1155 |
double extx = 0.0; |
1156 |
double exty = 0.0; |
1157 |
double extz = 1.0; |
1158 |
|
1159 |
feature.setProp("dxfEntity", "Line"); |
1160 |
|
1161 |
if (grp.hasCode(8)) { |
1162 |
feature.setProp("layer", grp.getDataAsString(8)); |
1163 |
} |
1164 |
|
1165 |
if (grp.hasCode(39)) { |
1166 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1167 |
String string = doub.toString();
|
1168 |
feature.setProp("thickness", string);
|
1169 |
} else {
|
1170 |
Double doub = new Double(0.0); |
1171 |
feature.setProp("thickness", doub.toString());
|
1172 |
} |
1173 |
|
1174 |
if (grp.hasCode(62)) { |
1175 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1176 |
String string = integer.toString();
|
1177 |
feature.setProp("color", string);
|
1178 |
feature.setProp("colorByLayer", "false"); |
1179 |
} else {
|
1180 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1181 |
int clr = layer.colorNumber;
|
1182 |
Integer integer = new Integer(clr); |
1183 |
String string = integer.toString();
|
1184 |
feature.setProp("color", string);
|
1185 |
feature.setProp("colorByLayer", "true"); |
1186 |
} |
1187 |
|
1188 |
x = grp.getDataAsDouble(10);
|
1189 |
y = grp.getDataAsDouble(20);
|
1190 |
z1 = grp.getDataAsDouble(30);
|
1191 |
|
1192 |
/*if (grp.hasCode(30)) {
|
1193 |
z1 = grp.getDataAsDouble(30);
|
1194 |
elev = z1;
|
1195 |
Double doub = new Double(elev);
|
1196 |
String string = doub.toString();
|
1197 |
//feature.setProp("elevation", string);
|
1198 |
}*/
|
1199 |
pt1 = proj.createPoint(x, y); |
1200 |
x = grp.getDataAsDouble(11);
|
1201 |
y = grp.getDataAsDouble(21);
|
1202 |
z2 = grp.getDataAsDouble(31);
|
1203 |
|
1204 |
/*if (grp.hasCode(31)) {
|
1205 |
z2 = grp.getDataAsDouble(31);
|
1206 |
} else {
|
1207 |
// Cuando no se especifican z para las lineas se asume que la
|
1208 |
// z es cero.
|
1209 |
Double doub = new Double(0.0);
|
1210 |
//feature.setProp("elevation", doub.toString());
|
1211 |
}*/
|
1212 |
pt2 = proj.createPoint(x, y); |
1213 |
|
1214 |
if (grp.hasCode(210)) { |
1215 |
extx = grp.getDataAsDouble(210);
|
1216 |
} |
1217 |
|
1218 |
if (grp.hasCode(220)) { |
1219 |
exty = grp.getDataAsDouble(220);
|
1220 |
} |
1221 |
|
1222 |
if (grp.hasCode(230)) { |
1223 |
extz = grp.getDataAsDouble(230);
|
1224 |
} |
1225 |
|
1226 |
Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
|
1227 |
Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
|
1228 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1229 |
Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru); |
1230 |
Point3D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru); |
1231 |
|
1232 |
if (point_out1.getZ() != 0.0) { |
1233 |
dxf3DFile = true;
|
1234 |
} |
1235 |
|
1236 |
if (point_out2.getZ() != 0.0) { |
1237 |
dxf3DFile = true;
|
1238 |
} |
1239 |
|
1240 |
if (point_out1.getZ() == point_out2.getZ()) {
|
1241 |
elev = z1; |
1242 |
|
1243 |
Double doub = new Double(elev); |
1244 |
String string = doub.toString();
|
1245 |
feature.setProp("elevation", string);
|
1246 |
} else {
|
1247 |
elev = 0.0;
|
1248 |
|
1249 |
Double doub = new Double(elev); |
1250 |
String string = doub.toString();
|
1251 |
feature.setProp("elevation", string);
|
1252 |
} |
1253 |
|
1254 |
//pt1.setLocation(point_out1);
|
1255 |
//pt2.setLocation(point_out2);
|
1256 |
lineString3D.add(point_out1); |
1257 |
lineString3D.add(point_out2); |
1258 |
|
1259 |
feature.setGeometry(lineString3D); |
1260 |
|
1261 |
// 041130: Rellena las props con los atributos.
|
1262 |
completeAttributes(feature); |
1263 |
|
1264 |
//features.add(feature);
|
1265 |
if (addingToBlock == false) { |
1266 |
//System.out.println("createLine(): A?adimos una linea a la lista de entidades");
|
1267 |
features.add(feature); |
1268 |
} else {
|
1269 |
//System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
|
1270 |
blk.add(feature); |
1271 |
} |
1272 |
} |
1273 |
|
1274 |
/* (non-Javadoc)
|
1275 |
* @see org.cresques.io.DxfFile.EntityFactory#createText(org.cresques.io.DxfGroupVector)
|
1276 |
*/
|
1277 |
public void createText(DxfGroupVector grp) throws Exception { |
1278 |
double x = 0.0; |
1279 |
double y = 0.0; |
1280 |
double z = 0.0; |
1281 |
double h = 0.0; |
1282 |
double rot = 0.0; |
1283 |
DxfGroup g = null;
|
1284 |
|
1285 |
//Point3D pt1 = null, pt2 = null;
|
1286 |
Point3D pt = null;
|
1287 |
org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
|
1288 |
double extx = 0.0; |
1289 |
double exty = 0.0; |
1290 |
double extz = 1.0; |
1291 |
|
1292 |
point.setTextPoint(true);
|
1293 |
|
1294 |
Feature feature = new Feature();
|
1295 |
|
1296 |
feature.setProp("dxfEntity", "Text"); |
1297 |
|
1298 |
if (grp.hasCode(8)) { |
1299 |
feature.setProp("layer", grp.getDataAsString(8)); |
1300 |
} |
1301 |
|
1302 |
if (grp.hasCode(39)) { |
1303 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1304 |
String string = doub.toString();
|
1305 |
feature.setProp("thickness", string);
|
1306 |
} else {
|
1307 |
Double doub = new Double(0.0); |
1308 |
feature.setProp("thickness", doub.toString());
|
1309 |
} |
1310 |
|
1311 |
if (grp.hasCode(62)) { |
1312 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1313 |
String string = integer.toString();
|
1314 |
feature.setProp("color", string);
|
1315 |
feature.setProp("colorByLayer", "false"); |
1316 |
} else {
|
1317 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1318 |
int clr = layer.colorNumber;
|
1319 |
Integer integer = new Integer(clr); |
1320 |
String string = integer.toString();
|
1321 |
feature.setProp("color", string);
|
1322 |
feature.setProp("colorByLayer", "true"); |
1323 |
} |
1324 |
|
1325 |
if (grp.hasCode(1)) { |
1326 |
String strAux1 = grp.getDataAsString(1); |
1327 |
strAux1 = DxfConvTexts.ConvertText(strAux1); |
1328 |
feature.setProp("text", strAux1);
|
1329 |
} else {
|
1330 |
feature.setProp("text", "No Text Code"); |
1331 |
} |
1332 |
|
1333 |
if (grp.hasCode(40)) { |
1334 |
Double heightD = new Double(grp.getDataAsDouble(40)); |
1335 |
String heightS = heightD.toString();
|
1336 |
feature.setProp("textHeight", heightS);
|
1337 |
} else {
|
1338 |
feature.setProp("textHeight", "20.0"); |
1339 |
} |
1340 |
|
1341 |
if (grp.hasCode(50)) { |
1342 |
Double rotD = new Double(grp.getDataAsDouble(50)); |
1343 |
String rotS = rotD.toString();
|
1344 |
feature.setProp("textRotation", rotS);
|
1345 |
|
1346 |
//System.out.println("rotS = " + rotS);
|
1347 |
} else {
|
1348 |
feature.setProp("textRotation", "0.0"); |
1349 |
} |
1350 |
|
1351 |
x = grp.getDataAsDouble(10);
|
1352 |
y = grp.getDataAsDouble(20);
|
1353 |
if (grp.hasCode(30)) { |
1354 |
z = grp.getDataAsDouble(30);
|
1355 |
} |
1356 |
/*if (grp.hasCode(30)){
|
1357 |
Double doub = new Double(z);
|
1358 |
String string = doub.toString();
|
1359 |
feature.setProp("elevation", string);
|
1360 |
} else {
|
1361 |
Double doub = new Double(0.0);
|
1362 |
feature.setProp("elevation", doub.toString());
|
1363 |
}*/
|
1364 |
if (grp.hasCode(210)) { |
1365 |
extx = grp.getDataAsDouble(210);
|
1366 |
} |
1367 |
|
1368 |
if (grp.hasCode(220)) { |
1369 |
exty = grp.getDataAsDouble(220);
|
1370 |
} |
1371 |
|
1372 |
if (grp.hasCode(230)) { |
1373 |
extz = grp.getDataAsDouble(230);
|
1374 |
} |
1375 |
|
1376 |
Point3D point_in = new Point3D(x, y, z);
|
1377 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1378 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
1379 |
x = point_out.getX(); |
1380 |
y = point_out.getY(); |
1381 |
z = point_out.getZ(); |
1382 |
|
1383 |
Double doub = new Double(z); |
1384 |
feature.setProp("elevation", doub.toString());
|
1385 |
|
1386 |
if (z != 0.0) { |
1387 |
dxf3DFile = true;
|
1388 |
} |
1389 |
|
1390 |
point.add(new Point3D(x, y, z));
|
1391 |
feature.setGeometry(point); |
1392 |
|
1393 |
// 041130: Rellena las props con los atributos.
|
1394 |
completeAttributes(feature); |
1395 |
|
1396 |
//features.add(feature);
|
1397 |
if (addingToBlock == false) { |
1398 |
features.add(feature); |
1399 |
} else {
|
1400 |
//System.out.println("createText(): A?adimos un text al bloque " + iterator);
|
1401 |
blk.add(feature); |
1402 |
} |
1403 |
} |
1404 |
|
1405 |
/* (non-Javadoc)
|
1406 |
* @see org.cresques.io.DxfFile.EntityFactory#createMText(org.cresques.io.DxfGroupVector)
|
1407 |
*/
|
1408 |
public void createMText(DxfGroupVector grp) throws Exception { |
1409 |
double x = 0.0; |
1410 |
double y = 0.0; |
1411 |
double z = 0.0; |
1412 |
double h = 0.0; |
1413 |
double rot = 0.0; |
1414 |
DxfGroup g = null;
|
1415 |
|
1416 |
//Point2D pt1 = null, pt2 = null;
|
1417 |
Point3D pt = null;
|
1418 |
org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
|
1419 |
double extx = 0.0; |
1420 |
double exty = 0.0; |
1421 |
double extz = 1.0; |
1422 |
|
1423 |
point.setTextPoint(true);
|
1424 |
|
1425 |
Feature feature = new Feature();
|
1426 |
|
1427 |
feature.setProp("dxfEntity", "Text"); |
1428 |
|
1429 |
if (grp.hasCode(8)) { |
1430 |
feature.setProp("layer", grp.getDataAsString(8)); |
1431 |
} |
1432 |
|
1433 |
if (grp.hasCode(39)) { |
1434 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1435 |
String string = doub.toString();
|
1436 |
feature.setProp("thickness", string);
|
1437 |
} else {
|
1438 |
Double doub = new Double(0.0); |
1439 |
feature.setProp("thickness", doub.toString());
|
1440 |
} |
1441 |
|
1442 |
if (grp.hasCode(62)) { |
1443 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1444 |
String string = integer.toString();
|
1445 |
feature.setProp("color", string);
|
1446 |
feature.setProp("colorByLayer", "false"); |
1447 |
} else {
|
1448 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1449 |
int clr = layer.colorNumber;
|
1450 |
Integer integer = new Integer(clr); |
1451 |
String string = integer.toString();
|
1452 |
feature.setProp("color", string);
|
1453 |
feature.setProp("colorByLayer", "true"); |
1454 |
} |
1455 |
|
1456 |
if (grp.hasCode(1)) { |
1457 |
String strAux1 = grp.getDataAsString(1); |
1458 |
strAux1 = DxfConvTexts.ConvertText(strAux1); |
1459 |
feature.setProp("text", strAux1);
|
1460 |
} else {
|
1461 |
feature.setProp("text", "No Text Code"); |
1462 |
} |
1463 |
|
1464 |
if (grp.hasCode(40)) { |
1465 |
Double heightD = new Double(grp.getDataAsDouble(40)); |
1466 |
String heightS = heightD.toString();
|
1467 |
feature.setProp("textHeight", heightS);
|
1468 |
} else {
|
1469 |
feature.setProp("textHeight", "20.0"); |
1470 |
} |
1471 |
|
1472 |
if (grp.hasCode(50)) { |
1473 |
Double rotD = new Double(grp.getDataAsDouble(50)); |
1474 |
String rotS = rotD.toString();
|
1475 |
feature.setProp("textRotation", rotS);
|
1476 |
|
1477 |
//System.out.println("rotS = " + rotS);
|
1478 |
} else {
|
1479 |
feature.setProp("textRotation", "0.0"); |
1480 |
} |
1481 |
|
1482 |
if (grp.hasCode(71)) { |
1483 |
int attachPoint = grp.getDataAsInt(71); |
1484 |
|
1485 |
if (attachPoint == 1) { |
1486 |
} else if (attachPoint == 2) { |
1487 |
} else if (attachPoint == 3) { |
1488 |
} else if (attachPoint == 4) { |
1489 |
} else if (attachPoint == 5) { |
1490 |
} else if (attachPoint == 6) { |
1491 |
} else if (attachPoint == 7) { |
1492 |
} else if (attachPoint == 8) { |
1493 |
} else if (attachPoint == 9) { |
1494 |
} |
1495 |
} |
1496 |
|
1497 |
if (grp.hasCode(72)) { |
1498 |
int drawDirection = grp.getDataAsInt(71); |
1499 |
|
1500 |
if (drawDirection == 1) { |
1501 |
} else if (drawDirection == 3) { |
1502 |
} else if (drawDirection == 5) { |
1503 |
} |
1504 |
} |
1505 |
|
1506 |
if (grp.hasCode(73)) { |
1507 |
int spacingStyle = grp.getDataAsInt(71); |
1508 |
|
1509 |
if (spacingStyle == 1) { |
1510 |
} else if (spacingStyle == 2) { |
1511 |
} |
1512 |
} |
1513 |
|
1514 |
x = grp.getDataAsDouble(10);
|
1515 |
y = grp.getDataAsDouble(20);
|
1516 |
z = grp.getDataAsDouble(30);
|
1517 |
|
1518 |
/*if (grp.hasCode(30)){
|
1519 |
z = grp.getDataAsDouble(30);
|
1520 |
Double doub = new Double(z);
|
1521 |
String string = doub.toString();
|
1522 |
feature.setProp("elevation", string);
|
1523 |
} else {
|
1524 |
Double doub = new Double(0.0);
|
1525 |
feature.setProp("elevation", doub.toString());
|
1526 |
}*/
|
1527 |
if (grp.hasCode(210)) { |
1528 |
extx = grp.getDataAsDouble(210);
|
1529 |
} |
1530 |
|
1531 |
if (grp.hasCode(220)) { |
1532 |
exty = grp.getDataAsDouble(220);
|
1533 |
} |
1534 |
|
1535 |
if (grp.hasCode(230)) { |
1536 |
extz = grp.getDataAsDouble(230);
|
1537 |
} |
1538 |
|
1539 |
Point3D point_in = new Point3D(x, y, z);
|
1540 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1541 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
1542 |
x = point_out.getX(); |
1543 |
y = point_out.getY(); |
1544 |
z = point_out.getZ(); |
1545 |
|
1546 |
Double doub = new Double(z); |
1547 |
feature.setProp("elevation", doub.toString());
|
1548 |
|
1549 |
if (z != 0.0) { |
1550 |
dxf3DFile = true;
|
1551 |
} |
1552 |
|
1553 |
point.add(new Point3D(x, y, z));
|
1554 |
feature.setGeometry(point); |
1555 |
|
1556 |
// 041130: Rellena las props con los atributos.
|
1557 |
completeAttributes(feature); |
1558 |
|
1559 |
//features.add(feature);
|
1560 |
if (addingToBlock == false) { |
1561 |
features.add(feature); |
1562 |
} else {
|
1563 |
//System.out.println("createText(): A?adimos un text al bloque " + iterator);
|
1564 |
blk.add(feature); |
1565 |
} |
1566 |
} |
1567 |
|
1568 |
/* (non-Javadoc)
|
1569 |
* @see org.cresques.io.DxfFile.EntityFactory#createPoint(org.cresques.io.DxfGroupVector)
|
1570 |
*/
|
1571 |
public void createPoint(DxfGroupVector grp) throws Exception { |
1572 |
double x = 0.0; |
1573 |
double y = 0.0; |
1574 |
double z = 0.0; |
1575 |
DxfGroup g = null;
|
1576 |
Point3D pt = null;
|
1577 |
double extx = 0.0; |
1578 |
double exty = 0.0; |
1579 |
double extz = 1.0; |
1580 |
org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
|
1581 |
Feature feature = new Feature();
|
1582 |
|
1583 |
feature.setProp("dxfEntity", "Point"); |
1584 |
|
1585 |
if (grp.hasCode(8)) { |
1586 |
feature.setProp("layer", grp.getDataAsString(8)); |
1587 |
} |
1588 |
|
1589 |
if (grp.hasCode(39)) { |
1590 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1591 |
String string = doub.toString();
|
1592 |
feature.setProp("thickness", string);
|
1593 |
} else {
|
1594 |
Double doub = new Double(0.0); |
1595 |
feature.setProp("thickness", doub.toString());
|
1596 |
} |
1597 |
|
1598 |
if (grp.hasCode(62)) { |
1599 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1600 |
String string = integer.toString();
|
1601 |
feature.setProp("color", string);
|
1602 |
feature.setProp("colorByLayer", "false"); |
1603 |
} else {
|
1604 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1605 |
int clr = layer.colorNumber;
|
1606 |
Integer integer = new Integer(clr); |
1607 |
String string = integer.toString();
|
1608 |
feature.setProp("color", string);
|
1609 |
feature.setProp("colorByLayer", "true"); |
1610 |
} |
1611 |
|
1612 |
x = grp.getDataAsDouble(10);
|
1613 |
y = grp.getDataAsDouble(20);
|
1614 |
z = grp.getDataAsDouble(30);
|
1615 |
|
1616 |
/*if (grp.hasCode(30)) {
|
1617 |
z = grp.getDataAsDouble(30);
|
1618 |
Double doub = new Double(z);
|
1619 |
String string = doub.toString();
|
1620 |
feature.setProp("elevation", string);
|
1621 |
} else {
|
1622 |
Double doub = new Double(0.0);
|
1623 |
feature.setProp("elevation", doub.toString());
|
1624 |
}*/
|
1625 |
if (grp.hasCode(210)) { |
1626 |
extx = grp.getDataAsDouble(210);
|
1627 |
} |
1628 |
|
1629 |
if (grp.hasCode(220)) { |
1630 |
exty = grp.getDataAsDouble(220);
|
1631 |
} |
1632 |
|
1633 |
if (grp.hasCode(230)) { |
1634 |
extz = grp.getDataAsDouble(230);
|
1635 |
} |
1636 |
|
1637 |
Point3D point_in = new Point3D(x, y, z);
|
1638 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1639 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
1640 |
x = point_out.getX(); |
1641 |
y = point_out.getY(); |
1642 |
z = point_out.getZ(); |
1643 |
|
1644 |
Double doub = new Double(z); |
1645 |
feature.setProp("elevation", doub.toString());
|
1646 |
|
1647 |
if (z != 0.0) { |
1648 |
dxf3DFile = true;
|
1649 |
} |
1650 |
|
1651 |
point.add(new Point3D(x, y, z));
|
1652 |
feature.setGeometry(point); |
1653 |
|
1654 |
// 041130: Rellena las props con los atributos.
|
1655 |
completeAttributes(feature); |
1656 |
|
1657 |
/*for (int i=0;i<attributes.size();i++) {
|
1658 |
String[] att = new String[2];
|
1659 |
att = (String[])attributes.get(i);
|
1660 |
feature.setProp(att[0],att[1]);
|
1661 |
}*/
|
1662 |
|
1663 |
//features.add(feature);
|
1664 |
if (addingToBlock == false) { |
1665 |
features.add(feature); |
1666 |
} else {
|
1667 |
//System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
|
1668 |
blk.add(feature); |
1669 |
} |
1670 |
} |
1671 |
|
1672 |
/* (non-Javadoc)
|
1673 |
* @see org.cresques.io.DxfFile.EntityFactory#createCircle(org.cresques.io.DxfGroupVector)
|
1674 |
*/
|
1675 |
public void createCircle(DxfGroupVector grp) throws Exception { |
1676 |
double x = 0.0; |
1677 |
double y = 0.0; |
1678 |
double z = 0.0; |
1679 |
double r = 0.0; |
1680 |
Point3D firstPt = new Point3D();
|
1681 |
DxfGroup g = null;
|
1682 |
double extx = 0.0; |
1683 |
double exty = 0.0; |
1684 |
double extz = 1.0; |
1685 |
LineString3D lineString3D = new LineString3D();
|
1686 |
Polygon3D polygon3D = new Polygon3D();
|
1687 |
Feature feaBordes = new Feature();
|
1688 |
Feature feaFondos = new Feature();
|
1689 |
|
1690 |
feaBordes.setProp("dxfEntity", "Circle"); |
1691 |
feaFondos.setProp("dxfEntity", "Circle"); |
1692 |
|
1693 |
if (grp.hasCode(8)) { |
1694 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
1695 |
} |
1696 |
|
1697 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
1698 |
|
1699 |
if (grp.hasCode(39)) { |
1700 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1701 |
String string = doub.toString();
|
1702 |
feaBordes.setProp("thickness", string);
|
1703 |
feaFondos.setProp("thickness", string);
|
1704 |
} else {
|
1705 |
Double doub = new Double(0.0); |
1706 |
feaBordes.setProp("thickness", doub.toString());
|
1707 |
feaFondos.setProp("thickness", doub.toString());
|
1708 |
} |
1709 |
|
1710 |
if (grp.hasCode(62)) { |
1711 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1712 |
String string = integer.toString();
|
1713 |
feaBordes.setProp("color", string);
|
1714 |
feaFondos.setProp("color", string);
|
1715 |
feaBordes.setProp("colorByLayer", "false"); |
1716 |
feaFondos.setProp("colorByLayer", "false"); |
1717 |
} else {
|
1718 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1719 |
int clr = layer.colorNumber;
|
1720 |
Integer integer = new Integer(clr); |
1721 |
String string = integer.toString();
|
1722 |
feaBordes.setProp("color", string);
|
1723 |
feaFondos.setProp("color", string);
|
1724 |
feaBordes.setProp("colorByLayer", "true"); |
1725 |
feaFondos.setProp("colorByLayer", "true"); |
1726 |
} |
1727 |
|
1728 |
x = grp.getDataAsDouble(10);
|
1729 |
y = grp.getDataAsDouble(20);
|
1730 |
if (grp.hasCode(30)) { |
1731 |
z = grp.getDataAsDouble(30);
|
1732 |
} |
1733 |
|
1734 |
|
1735 |
/*if (grp.hasCode(30)) {
|
1736 |
z = grp.getDataAsDouble(30);
|
1737 |
Double doub = new Double(z);
|
1738 |
String string = doub.toString();
|
1739 |
feaBordes.setProp("elevation", string);
|
1740 |
feaFondos.setProp("elevation", string);
|
1741 |
} else {
|
1742 |
Double doub = new Double(0.0);
|
1743 |
feaBordes.setProp("elevation", doub.toString());
|
1744 |
feaFondos.setProp("elevation", doub.toString());
|
1745 |
}*/
|
1746 |
if (grp.hasCode(40)) { |
1747 |
r = grp.getDataAsDouble(40);
|
1748 |
} |
1749 |
|
1750 |
if (grp.hasCode(210)) { |
1751 |
extx = grp.getDataAsDouble(210);
|
1752 |
} |
1753 |
|
1754 |
if (grp.hasCode(220)) { |
1755 |
exty = grp.getDataAsDouble(220);
|
1756 |
} |
1757 |
|
1758 |
if (grp.hasCode(230)) { |
1759 |
extz = grp.getDataAsDouble(230);
|
1760 |
} |
1761 |
|
1762 |
Point3D point_in = new Point3D(x, y, z);
|
1763 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1764 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
1765 |
x = point_out.getX(); |
1766 |
y = point_out.getY(); |
1767 |
z = point_out.getZ(); |
1768 |
|
1769 |
Double doub = new Double(z); |
1770 |
feaBordes.setProp("elevation", doub.toString());
|
1771 |
feaFondos.setProp("elevation", doub.toString());
|
1772 |
|
1773 |
if (z != 0.0) { |
1774 |
dxf3DFile = true;
|
1775 |
} |
1776 |
|
1777 |
Point2D c = proj.createPoint(x, y);
|
1778 |
Point3D center = new Point3D(c.getX(), c.getY(), z);
|
1779 |
Point3D[] pts = new Point3D[360]; |
1780 |
int angulo = 0; |
1781 |
|
1782 |
for (angulo = 0; angulo < 360; angulo++) { |
1783 |
pts[angulo] = new Point3D(center.getX(), center.getY(),
|
1784 |
center.getZ()); |
1785 |
pts[angulo] = new Point3D(pts[angulo].getX() +
|
1786 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1787 |
pts[angulo].getY() + |
1788 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1789 |
center.getZ()); |
1790 |
|
1791 |
if (pts.length == 1) { |
1792 |
firstPt = pts[angulo]; |
1793 |
} |
1794 |
} |
1795 |
|
1796 |
for (int i = 0; i < pts.length; i++) { |
1797 |
lineString3D.add(pts[i]); |
1798 |
polygon3D.add(pts[i]); |
1799 |
} |
1800 |
|
1801 |
feaBordes.setGeometry(lineString3D); |
1802 |
feaFondos.setGeometry(polygon3D); |
1803 |
|
1804 |
// 041130: Rellena las props con los atributos.
|
1805 |
completeAttributes(feaBordes); |
1806 |
completeAttributes(feaFondos); |
1807 |
|
1808 |
//features.add(feature);
|
1809 |
if (addingToBlock == false) { |
1810 |
//System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
|
1811 |
//features.add(feaBordes);
|
1812 |
features.add(feaFondos); |
1813 |
} else {
|
1814 |
//System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
|
1815 |
//blk.add(feaBordes);
|
1816 |
blk.add(feaFondos); |
1817 |
} |
1818 |
} |
1819 |
|
1820 |
/* (non-Javadoc)
|
1821 |
* @see org.cresques.io.DxfFile.EntityFactory#createArc(org.cresques.io.DxfGroupVector)
|
1822 |
*/
|
1823 |
public void createArc(DxfGroupVector grp) throws Exception { |
1824 |
double x = 0.0; |
1825 |
double y = 0.0; |
1826 |
double z = 0.0; |
1827 |
double r = 0.0; |
1828 |
double empieza = 0.0; |
1829 |
double acaba = 0.0; |
1830 |
DxfGroup g = null;
|
1831 |
double extx = 0.0; |
1832 |
double exty = 0.0; |
1833 |
double extz = 1.0; |
1834 |
LineString3D lineString3D = new LineString3D();
|
1835 |
Feature feature = new Feature();
|
1836 |
|
1837 |
feature.setProp("dxfEntity", "Arc"); |
1838 |
|
1839 |
if (grp.hasCode(8)) { |
1840 |
feature.setProp("layer", grp.getDataAsString(8)); |
1841 |
} |
1842 |
|
1843 |
if (grp.hasCode(39)) { |
1844 |
Double doub = new Double(grp.getDataAsDouble(39)); |
1845 |
String string = doub.toString();
|
1846 |
feature.setProp("thickness", string);
|
1847 |
} else {
|
1848 |
Double doub = new Double(0.0); |
1849 |
feature.setProp("thickness", doub.toString());
|
1850 |
} |
1851 |
|
1852 |
if (grp.hasCode(62)) { |
1853 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
1854 |
String string = integer.toString();
|
1855 |
feature.setProp("color", string);
|
1856 |
feature.setProp("colorByLayer", "false"); |
1857 |
} else {
|
1858 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
1859 |
int clr = layer.colorNumber;
|
1860 |
Integer integer = new Integer(clr); |
1861 |
String string = integer.toString();
|
1862 |
feature.setProp("color", string);
|
1863 |
feature.setProp("colorByLayer", "true"); |
1864 |
} |
1865 |
|
1866 |
x = grp.getDataAsDouble(10);
|
1867 |
y = grp.getDataAsDouble(20);
|
1868 |
if (grp.hasCode(30)) |
1869 |
{ |
1870 |
z = grp.getDataAsDouble(30);
|
1871 |
} |
1872 |
|
1873 |
/*if (grp.hasCode(30)) {
|
1874 |
z = grp.getDataAsDouble(30);
|
1875 |
Double doub = new Double(z);
|
1876 |
String string = doub.toString();
|
1877 |
feature.setProp("elevation", string);
|
1878 |
} else {
|
1879 |
Double doub = new Double(0.0);
|
1880 |
feature.setProp("elevation", doub.toString());
|
1881 |
}*/
|
1882 |
if (grp.hasCode(40)) { |
1883 |
r = grp.getDataAsDouble(40);
|
1884 |
} |
1885 |
|
1886 |
if (grp.hasCode(50)) { |
1887 |
empieza = grp.getDataAsDouble(50);
|
1888 |
} |
1889 |
|
1890 |
if (grp.hasCode(51)) { |
1891 |
acaba = grp.getDataAsDouble(51);
|
1892 |
} |
1893 |
|
1894 |
if (grp.hasCode(210)) { |
1895 |
extx = grp.getDataAsDouble(210);
|
1896 |
} |
1897 |
|
1898 |
if (grp.hasCode(220)) { |
1899 |
exty = grp.getDataAsDouble(220);
|
1900 |
} |
1901 |
|
1902 |
if (grp.hasCode(230)) { |
1903 |
extz = grp.getDataAsDouble(230);
|
1904 |
} |
1905 |
|
1906 |
Point3D point_in = new Point3D(x, y, z);
|
1907 |
Point3D xtru = new Point3D(extx, exty, extz);
|
1908 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
1909 |
x = point_out.getX(); |
1910 |
y = point_out.getY(); |
1911 |
z = point_out.getZ(); |
1912 |
|
1913 |
Double doub = new Double(z); |
1914 |
feature.setProp("elevation", doub.toString());
|
1915 |
|
1916 |
if (z != 0.0) { |
1917 |
dxf3DFile = true;
|
1918 |
} |
1919 |
|
1920 |
Point2D c = proj.createPoint(x, y);
|
1921 |
Point3D center = new Point3D(c.getX(), c.getY(), z);
|
1922 |
|
1923 |
//System.out.println("empieza = " + empieza + ", acaba = " + acaba);
|
1924 |
int iempieza = (int) empieza; |
1925 |
int iacaba = (int) acaba; |
1926 |
|
1927 |
//System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
|
1928 |
double angulo = 0; |
1929 |
Point3D[] pts = null; |
1930 |
|
1931 |
if (empieza <= acaba) {
|
1932 |
pts = new Point3D[(iacaba - iempieza) + 2]; |
1933 |
angulo = empieza; |
1934 |
pts[0] = new Point3D(center.getX() + |
1935 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1936 |
center.getY() + |
1937 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1938 |
center.getZ()); |
1939 |
|
1940 |
for (int i = 1; i <= ((iacaba - iempieza) + 1); i++) { |
1941 |
angulo = (double) (iempieza + i);
|
1942 |
pts[i] = new Point3D(center.getX() +
|
1943 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1944 |
center.getY() + |
1945 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1946 |
center.getZ()); |
1947 |
} |
1948 |
|
1949 |
angulo = acaba; |
1950 |
pts[(iacaba - iempieza) + 1] = new Point3D(center.getX() + |
1951 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1952 |
center.getY() + |
1953 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1954 |
center.getZ()); |
1955 |
} else {
|
1956 |
pts = new Point3D[(360 - iempieza) + iacaba + 2]; |
1957 |
angulo = empieza; |
1958 |
|
1959 |
//System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
|
1960 |
pts[0] = new Point3D(center.getX() + |
1961 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1962 |
center.getY() + |
1963 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1964 |
center.getZ()); |
1965 |
|
1966 |
for (int i = 1; i <= (360 - iempieza); i++) { |
1967 |
angulo = (double) (iempieza + i);
|
1968 |
pts[i] = new Point3D(center.getX() +
|
1969 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1970 |
center.getY() + |
1971 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1972 |
center.getZ()); |
1973 |
} |
1974 |
|
1975 |
for (int i = (360 - iempieza) + 1; |
1976 |
i <= ((360 - iempieza) + iacaba); i++) {
|
1977 |
angulo = (double) (i - (360 - iempieza)); |
1978 |
pts[i] = new Point3D(center.getX() +
|
1979 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1980 |
center.getY() + |
1981 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1982 |
center.getZ()); |
1983 |
} |
1984 |
|
1985 |
angulo = acaba; |
1986 |
pts[(360 - iempieza) + iacaba + 1] = new Point3D(center.getX() + |
1987 |
(r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
1988 |
center.getY() + |
1989 |
(r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
1990 |
center.getZ()); |
1991 |
} |
1992 |
|
1993 |
for (int i = 0; i < pts.length; i++) { |
1994 |
lineString3D.add(pts[i]); |
1995 |
} |
1996 |
|
1997 |
feature.setGeometry(lineString3D); |
1998 |
|
1999 |
// 041130: Rellena las props con los atributos.
|
2000 |
completeAttributes(feature); |
2001 |
|
2002 |
//features.add(feature);
|
2003 |
if (addingToBlock == false) { |
2004 |
features.add(feature); |
2005 |
} else {
|
2006 |
//System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
|
2007 |
blk.add(feature); |
2008 |
} |
2009 |
} |
2010 |
|
2011 |
/* (non-Javadoc)
|
2012 |
* @see org.cresques.io.DxfFile.EntityFactory#createInsert(org.cresques.io.DxfGroupVector)
|
2013 |
*/
|
2014 |
public void createInsert(DxfGroupVector grp) throws Exception { |
2015 |
double x = 0.0; |
2016 |
double y = 0.0; |
2017 |
double z = 0.0; |
2018 |
DxfGroup g = null;
|
2019 |
Point3D pt = new Point3D(0.0, 0.0, 0.0); |
2020 |
Point3D scaleFactor = new Point3D(1.0, 1.0, 1.0); |
2021 |
double rotAngle = 0.0; |
2022 |
String blockName = ""; |
2023 |
double extx = 0.0; |
2024 |
double exty = 0.0; |
2025 |
double extz = 1.0; |
2026 |
|
2027 |
InsPoint3D insert = new InsPoint3D();
|
2028 |
Feature feature = new Feature();
|
2029 |
org.cresques.px.gml.Point3D secondGeom = new org.cresques.px.gml.Point3D();
|
2030 |
Feature secondFeat = new Feature();
|
2031 |
int attributesFollowFlag = 0; |
2032 |
|
2033 |
feature.setProp("dxfEntity", "Insert"); |
2034 |
secondFeat.setProp("dxfEntity", "Insert"); |
2035 |
|
2036 |
if (grp.hasCode(2)) { |
2037 |
blockName = grp.getDataAsString(2);
|
2038 |
|
2039 |
//feature.setProp("blockName", blockName);
|
2040 |
insert.setBlockName(blockName); |
2041 |
} |
2042 |
|
2043 |
if (grp.hasCode(8)) { |
2044 |
feature.setProp("layer", grp.getDataAsString(8)); |
2045 |
secondFeat.setProp("layer", grp.getDataAsString(8)); |
2046 |
} |
2047 |
|
2048 |
Double doub = new Double(0.0); |
2049 |
secondFeat.setProp("thickness", doub.toString());
|
2050 |
|
2051 |
if (grp.hasCode(62)) { |
2052 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
2053 |
String string = integer.toString();
|
2054 |
feature.setProp("color", string);
|
2055 |
secondFeat.setProp("color", string);
|
2056 |
feature.setProp("colorByLayer", "false"); |
2057 |
secondFeat.setProp("colorByLayer", "false"); |
2058 |
} else {
|
2059 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2060 |
int clr = layer.colorNumber;
|
2061 |
Integer integer = new Integer(clr); |
2062 |
String string = integer.toString();
|
2063 |
feature.setProp("color", string);
|
2064 |
secondFeat.setProp("color", string);
|
2065 |
feature.setProp("colorByLayer", "true"); |
2066 |
secondFeat.setProp("colorByLayer", "true"); |
2067 |
} |
2068 |
|
2069 |
if (grp.hasCode(66)) { |
2070 |
attributesFollowFlag = grp.getDataAsInt(66);
|
2071 |
} |
2072 |
|
2073 |
x = grp.getDataAsDouble(10);
|
2074 |
y = grp.getDataAsDouble(20);
|
2075 |
z = grp.getDataAsDouble(30);
|
2076 |
|
2077 |
/*if (grp.hasCode(30)) {
|
2078 |
z = grp.getDataAsDouble(30);
|
2079 |
Double doubz = new Double(z);
|
2080 |
String string = doubz.toString();
|
2081 |
feature.setProp("elevation", string);
|
2082 |
secondFeat.setProp("elevation", string);
|
2083 |
} else {
|
2084 |
Double elev = new Double(z);
|
2085 |
//feature.setProp("elevation", doub.toString());
|
2086 |
feature.setProp("elevation", elev.toString());
|
2087 |
secondFeat.setProp("elevation", elev.toString());
|
2088 |
}*/
|
2089 |
if (grp.hasCode(41)) { |
2090 |
scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
|
2091 |
insert.setScaleFactor(scaleFactor); |
2092 |
} else {
|
2093 |
insert.setScaleFactor(scaleFactor); |
2094 |
} |
2095 |
|
2096 |
if (grp.hasCode(42)) { |
2097 |
scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
|
2098 |
insert.setScaleFactor(scaleFactor); |
2099 |
} else {
|
2100 |
insert.setScaleFactor(scaleFactor); |
2101 |
} |
2102 |
|
2103 |
if (grp.hasCode(43)) { |
2104 |
scaleFactor = new Point3D(scaleFactor.getX(), scaleFactor.getY(),
|
2105 |
grp.getDataAsDouble(43));
|
2106 |
insert.setScaleFactor(scaleFactor); |
2107 |
} else {
|
2108 |
insert.setScaleFactor(scaleFactor); |
2109 |
} |
2110 |
|
2111 |
if (grp.hasCode(50)) { |
2112 |
rotAngle = grp.getDataAsDouble(50);
|
2113 |
insert.setRotAngle(rotAngle); |
2114 |
} |
2115 |
|
2116 |
if (grp.hasCode(210)) { |
2117 |
extx = grp.getDataAsDouble(210);
|
2118 |
} |
2119 |
|
2120 |
if (grp.hasCode(220)) { |
2121 |
exty = grp.getDataAsDouble(220);
|
2122 |
} |
2123 |
|
2124 |
if (grp.hasCode(230)) { |
2125 |
extz = grp.getDataAsDouble(230);
|
2126 |
} |
2127 |
|
2128 |
Point3D point_in = new Point3D(x, y, z);
|
2129 |
Point3D xtru = new Point3D(extx, exty, extz);
|
2130 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
2131 |
x = point_out.getX(); |
2132 |
y = point_out.getY(); |
2133 |
z = point_out.getZ(); |
2134 |
|
2135 |
Double doubz = new Double(z); |
2136 |
feature.setProp("elevation", doubz.toString());
|
2137 |
secondFeat.setProp("elevation", doubz.toString());
|
2138 |
|
2139 |
if (z != 0.0) { |
2140 |
dxf3DFile = true;
|
2141 |
} |
2142 |
|
2143 |
insert.setBlkList(blkList); |
2144 |
|
2145 |
insert.encuentraBloque(blockName); |
2146 |
|
2147 |
insert.add(new Point3D(x, y, z));
|
2148 |
secondGeom.add(new Point3D(x, y, z));
|
2149 |
|
2150 |
feature.setGeometry(insert); |
2151 |
secondFeat.setGeometry(secondGeom); |
2152 |
|
2153 |
// 041130: Rellena las props con los atributos.
|
2154 |
completeAttributes(feature); |
2155 |
completeAttributes(secondFeat); |
2156 |
|
2157 |
/*for (int i=0;i<attributes.size();i++) {
|
2158 |
String[] att = new String[2];
|
2159 |
att = (String[])attributes.get(i);
|
2160 |
secondFeat.setProp(att[0],att[1]);
|
2161 |
}*/
|
2162 |
if ((insert.getBlockFound() == true) && (attributesFollowFlag != 1)) { |
2163 |
gestionaInsert(feature); |
2164 |
} |
2165 |
|
2166 |
//if (addingToBlock == false) {
|
2167 |
//features.add(secondFeat);
|
2168 |
//}
|
2169 |
//if (addingToBlock == true/* && insert.getBlockFound() == true*/) {
|
2170 |
//System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
|
2171 |
//blk.add(feature);
|
2172 |
//}
|
2173 |
// 041129: A?adido para implementar los ATTRIBS.
|
2174 |
if (attributesFollowFlag == 1) { |
2175 |
isDoubleFeatured = true;
|
2176 |
lastFeaBordes = feature; |
2177 |
lastFeaFondos = secondFeat; |
2178 |
} else {
|
2179 |
if (addingToBlock == false) { |
2180 |
features.add(secondFeat); |
2181 |
} |
2182 |
|
2183 |
if (addingToBlock == true /* && insert.getBlockFound() == true*/) { |
2184 |
//System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
|
2185 |
blk.add(feature); |
2186 |
} |
2187 |
} |
2188 |
} |
2189 |
|
2190 |
/* (non-Javadoc)
|
2191 |
* @see org.cresques.io.DxfFile.EntityFactory#createSolid(org.cresques.io.DxfGroupVector)
|
2192 |
*/
|
2193 |
public void createSolid(DxfGroupVector grp) throws Exception { |
2194 |
double x = 0.0; |
2195 |
double y = 0.0; |
2196 |
double z1 = 0.0; |
2197 |
double z2 = 0.0; |
2198 |
double z3 = 0.0; |
2199 |
double z4 = 0.0; |
2200 |
DxfGroup g = null;
|
2201 |
|
2202 |
//Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
|
2203 |
Point3D[] pts = new Point3D[4]; |
2204 |
|
2205 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2206 |
double extx = 0.0; |
2207 |
double exty = 0.0; |
2208 |
double extz = 1.0; |
2209 |
|
2210 |
LineString3D lineString3D = new LineString3D();
|
2211 |
Polygon3D polygon3D = new Polygon3D();
|
2212 |
Feature feaBordes = new Feature();
|
2213 |
Feature feaFondos = new Feature();
|
2214 |
|
2215 |
//double elev = 0;
|
2216 |
feaBordes.setProp("dxfEntity", "Solid"); |
2217 |
feaFondos.setProp("dxfEntity", "Solid"); |
2218 |
|
2219 |
if (grp.hasCode(8)) { |
2220 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
2221 |
} |
2222 |
|
2223 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
2224 |
x = grp.getDataAsDouble(10);
|
2225 |
y = grp.getDataAsDouble(20);
|
2226 |
z1 = grp.getDataAsDouble(30);
|
2227 |
|
2228 |
/*if (grp.hasCode(30)) {
|
2229 |
z1 = grp.getDataAsDouble(30);
|
2230 |
} else {
|
2231 |
Double doub = new Double(0.0);
|
2232 |
feaBordes.setProp("elevation", doub.toString());
|
2233 |
feaFondos.setProp("elevation", doub.toString());
|
2234 |
}*/
|
2235 |
Point2D pto = proj.createPoint(x, y);
|
2236 |
Point3D pto3D = new Point3D(pto.getX(), pto.getY(), z1);
|
2237 |
pts[0] = pto3D;
|
2238 |
x = grp.getDataAsDouble(11);
|
2239 |
y = grp.getDataAsDouble(21);
|
2240 |
z2 = grp.getDataAsDouble(31);
|
2241 |
pto = proj.createPoint(x, y); |
2242 |
pto3D = new Point3D(pto.getX(), pto.getY(), z2);
|
2243 |
pts[1] = pto3D;
|
2244 |
x = grp.getDataAsDouble(12);
|
2245 |
y = grp.getDataAsDouble(22);
|
2246 |
z3 = grp.getDataAsDouble(32);
|
2247 |
pto = proj.createPoint(x, y); |
2248 |
pto3D = new Point3D(pto.getX(), pto.getY(), z3);
|
2249 |
pts[2] = pto3D;
|
2250 |
|
2251 |
if (grp.hasCode(13)) { |
2252 |
x = grp.getDataAsDouble(13);
|
2253 |
} |
2254 |
|
2255 |
if (grp.hasCode(23)) { |
2256 |
y = grp.getDataAsDouble(23);
|
2257 |
} |
2258 |
|
2259 |
if (grp.hasCode(33)) { |
2260 |
z4 = grp.getDataAsDouble(33);
|
2261 |
} |
2262 |
|
2263 |
pto = proj.createPoint(x, y); |
2264 |
pto3D = new Point3D(pto.getX(), pto.getY(), z4);
|
2265 |
pts[3] = pto3D;
|
2266 |
|
2267 |
if (grp.hasCode(39)) { |
2268 |
Double doub = new Double(grp.getDataAsDouble(39)); |
2269 |
String string = doub.toString();
|
2270 |
feaBordes.setProp("thickness", string);
|
2271 |
feaFondos.setProp("thickness", string);
|
2272 |
} else {
|
2273 |
Double doub = new Double(0.0); |
2274 |
feaBordes.setProp("thickness", doub.toString());
|
2275 |
feaFondos.setProp("thickness", doub.toString());
|
2276 |
} |
2277 |
|
2278 |
if (grp.hasCode(62)) { |
2279 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
2280 |
String string = integer.toString();
|
2281 |
feaBordes.setProp("color", string);
|
2282 |
feaFondos.setProp("color", string);
|
2283 |
feaBordes.setProp("colorByLayer", "false"); |
2284 |
feaFondos.setProp("colorByLayer", "false"); |
2285 |
} else {
|
2286 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2287 |
int clr = layer.colorNumber;
|
2288 |
Integer integer = new Integer(clr); |
2289 |
String string = integer.toString();
|
2290 |
feaBordes.setProp("color", string);
|
2291 |
feaFondos.setProp("color", string);
|
2292 |
feaBordes.setProp("colorByLayer", "true"); |
2293 |
feaFondos.setProp("colorByLayer", "true"); |
2294 |
} |
2295 |
|
2296 |
if (grp.hasCode(210)) { |
2297 |
extx = grp.getDataAsDouble(210);
|
2298 |
} |
2299 |
|
2300 |
if (grp.hasCode(220)) { |
2301 |
exty = grp.getDataAsDouble(220);
|
2302 |
} |
2303 |
|
2304 |
if (grp.hasCode(230)) { |
2305 |
extz = grp.getDataAsDouble(230);
|
2306 |
} |
2307 |
|
2308 |
Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1); |
2309 |
Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2); |
2310 |
Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3); |
2311 |
Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4); |
2312 |
Point3D xtru = new Point3D(extx, exty, extz);
|
2313 |
Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru); |
2314 |
Point3D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru); |
2315 |
Point3D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru); |
2316 |
Point3D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru); |
2317 |
pts[0] = new Point3D(point_out1); |
2318 |
pts[1] = new Point3D(point_out2); |
2319 |
pts[2] = new Point3D(point_out3); |
2320 |
pts[3] = new Point3D(point_out4); |
2321 |
|
2322 |
if ((pts[0].getZ() != 0.0) || (pts[1].getZ() != 0.0) || |
2323 |
(pts[2].getZ() != 0.0) || (pts[3].getZ() != 0.0)) { |
2324 |
dxf3DFile = true;
|
2325 |
} |
2326 |
|
2327 |
Point3D aux = new Point3D(pts[2]); |
2328 |
pts[2] = new Point3D(pts[3]); |
2329 |
pts[3] = aux;
|
2330 |
|
2331 |
Double doub = new Double(0.0); |
2332 |
if ((pts[0].getZ() == pts[1].getZ()) && |
2333 |
(pts[1].getZ() == pts[2].getZ()) && |
2334 |
(pts[2].getZ() == pts[3].getZ())) { |
2335 |
doub = new Double(pts[0].getZ()); |
2336 |
} |
2337 |
String string = doub.toString();
|
2338 |
feaBordes.setProp("elevation", string);
|
2339 |
feaFondos.setProp("elevation", string);
|
2340 |
|
2341 |
for (int i = 0; i < pts.length; i++) { |
2342 |
lineString3D.add(pts[i]); |
2343 |
polygon3D.add(pts[i]); |
2344 |
} |
2345 |
|
2346 |
// Para cerrarlos.
|
2347 |
lineString3D.add(pts[0]);
|
2348 |
polygon3D.add(pts[0]);
|
2349 |
|
2350 |
feaBordes.setGeometry(lineString3D); |
2351 |
feaFondos.setGeometry(polygon3D); |
2352 |
|
2353 |
// 041130: Rellena las props con los atributos.
|
2354 |
completeAttributes(feaBordes); |
2355 |
completeAttributes(feaFondos); |
2356 |
|
2357 |
//features.add(feature);
|
2358 |
if (addingToBlock == false) { |
2359 |
//System.out.println("createSolid(): A?ade un solid a la lista de entidades");
|
2360 |
//features.add(feaBordes);
|
2361 |
features.add(feaFondos); |
2362 |
} else {
|
2363 |
//System.out.println("createSolid(): A?adimos un circulo al bloque " + iterator);
|
2364 |
//blk.add(feaBordes);
|
2365 |
blk.add(feaFondos); |
2366 |
} |
2367 |
} |
2368 |
|
2369 |
/* (non-Javadoc)
|
2370 |
* @see org.cresques.io.DxfFile.EntityFactory#createSpline(org.cresques.io.DxfGroupVector)
|
2371 |
*/
|
2372 |
public void createSpline(DxfGroupVector grp) throws Exception { |
2373 |
double x = 0.0; //elev = 0.0; |
2374 |
double y = 0.0; //elev = 0.0; |
2375 |
double z = 0.0; //elev = 0.0; |
2376 |
|
2377 |
//double elev = 0.0;
|
2378 |
DxfGroup g = null;
|
2379 |
LineString3D lineString3D = new LineString3D();
|
2380 |
Polygon3D polygon3D = new Polygon3D();
|
2381 |
|
2382 |
//Geometry geometria;
|
2383 |
//Feature feature= new Feature();
|
2384 |
Feature feaBordes = new Feature();
|
2385 |
Feature feaFondos = new Feature();
|
2386 |
int flags = 0; |
2387 |
|
2388 |
//feature.setProp("dxfEntity", "LwPolyline");
|
2389 |
feaBordes.setProp("dxfEntity", "Spline"); |
2390 |
feaFondos.setProp("dxfEntity", "Spline"); |
2391 |
|
2392 |
if (grp.hasCode(8)) { |
2393 |
//feature.setProp("layer", grp.getDataAsString(8));
|
2394 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
2395 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
2396 |
} |
2397 |
|
2398 |
if (grp.hasCode(39)) { |
2399 |
Double doub = new Double(grp.getDataAsDouble(39)); |
2400 |
String string = doub.toString();
|
2401 |
|
2402 |
//feature.setProp("thickness", string);
|
2403 |
feaBordes.setProp("thickness", string);
|
2404 |
feaFondos.setProp("thickness", string);
|
2405 |
} else {
|
2406 |
Double doub = new Double(0.0); |
2407 |
|
2408 |
//feature.setProp("thickness", doub.toString());
|
2409 |
feaBordes.setProp("thickness", doub.toString());
|
2410 |
feaFondos.setProp("thickness", doub.toString());
|
2411 |
} |
2412 |
|
2413 |
if (grp.hasCode(62)) { |
2414 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
2415 |
String string = integer.toString();
|
2416 |
|
2417 |
//feature.setProp("color", string);
|
2418 |
feaBordes.setProp("color", string);
|
2419 |
feaFondos.setProp("color", string);
|
2420 |
feaBordes.setProp("colorByLayer", "false"); |
2421 |
feaFondos.setProp("colorByLayer", "false"); |
2422 |
} else {
|
2423 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2424 |
int clr = layer.colorNumber;
|
2425 |
Integer integer = new Integer(clr); |
2426 |
String string = integer.toString();
|
2427 |
|
2428 |
//feature.setProp("color", string);
|
2429 |
feaBordes.setProp("color", string);
|
2430 |
feaFondos.setProp("color", string);
|
2431 |
feaBordes.setProp("colorByLayer", "true"); |
2432 |
feaFondos.setProp("colorByLayer", "true"); |
2433 |
} |
2434 |
|
2435 |
if (grp.hasCode(70)) { |
2436 |
flags = grp.getDataAsInt(70);
|
2437 |
} |
2438 |
|
2439 |
if ((flags & 0x01) == 0x01) { |
2440 |
//geometria = new Polygon();
|
2441 |
feaBordes.setGeometry(lineString3D); |
2442 |
feaFondos.setGeometry(polygon3D); |
2443 |
isDoubleFeatured = true;
|
2444 |
} else {
|
2445 |
//geometria = new LineString();
|
2446 |
feaBordes.setGeometry(lineString3D); |
2447 |
isDoubleFeatured = false;
|
2448 |
} |
2449 |
|
2450 |
int j = 0; |
2451 |
double firstX = 0.0; |
2452 |
double firstY = 0.0; |
2453 |
double firstZ = 0.0; |
2454 |
|
2455 |
for (int i = 0; i < grp.size(); i++) { |
2456 |
g = (DxfGroup) grp.get(i); |
2457 |
|
2458 |
if (g.getCode() == 10) { |
2459 |
j++; |
2460 |
x = ((Double) g.getData()).doubleValue();
|
2461 |
} else if (g.getCode() == 20) { |
2462 |
y = ((Double) g.getData()).doubleValue();
|
2463 |
} else if (g.getCode() == 30) { |
2464 |
z = ((Double) g.getData()).doubleValue();
|
2465 |
|
2466 |
Point2D p = proj.createPoint(x, y);
|
2467 |
Point3D p3d = new Point3D(p.getX(), p.getY(), z);
|
2468 |
lineString3D.add(p3d); |
2469 |
|
2470 |
if (isDoubleFeatured) {
|
2471 |
polygon3D.add(p3d); |
2472 |
} |
2473 |
|
2474 |
if (j == 1) { |
2475 |
firstX = x; |
2476 |
firstY = y; |
2477 |
firstZ = z; |
2478 |
} |
2479 |
|
2480 |
//elev = z;
|
2481 |
x = 0.0;
|
2482 |
y = 0.0;
|
2483 |
z = 0.0;
|
2484 |
} |
2485 |
} |
2486 |
|
2487 |
//Double doub = new Double(elev);
|
2488 |
//String string = doub.toString();
|
2489 |
//feature.setProp("elevation", string);
|
2490 |
//feaBordes.setProp("elevation", string);
|
2491 |
//feaFondos.setProp("elevation", string);
|
2492 |
if (isDoubleFeatured) {
|
2493 |
Point2D p = proj.createPoint(firstX, firstY);
|
2494 |
Point3D p3d = new Point3D(p.getX(), p.getY(), z);
|
2495 |
lineString3D.add(p3d); |
2496 |
polygon3D.add(p3d); |
2497 |
} |
2498 |
|
2499 |
double zprev = 0; |
2500 |
boolean constSplineElev = true; |
2501 |
|
2502 |
for (int i = 0; i < lineString3D.pointNr(); i++) { |
2503 |
z = lineString3D.getPoint3D(i).getZ(); |
2504 |
|
2505 |
if (z != 0.0) { |
2506 |
dxf3DFile = true;
|
2507 |
} |
2508 |
|
2509 |
if ((i > 0) && (z != zprev)) { |
2510 |
constSplineElev = false;
|
2511 |
} |
2512 |
|
2513 |
zprev = z; |
2514 |
} |
2515 |
|
2516 |
if (constSplineElev) {
|
2517 |
Double doub = new Double(lineString3D.getPoint3D(0).getZ()); |
2518 |
String string = doub.toString();
|
2519 |
feaBordes.setProp("elevation", string);
|
2520 |
|
2521 |
if (isDoubleFeatured) {
|
2522 |
feaFondos.setProp("elevation", string);
|
2523 |
} |
2524 |
} else {
|
2525 |
Double doub = new Double(0.0); |
2526 |
String string = doub.toString();
|
2527 |
feaBordes.setProp("elevation", string);
|
2528 |
|
2529 |
if (isDoubleFeatured) {
|
2530 |
feaFondos.setProp("elevation", string);
|
2531 |
} |
2532 |
} |
2533 |
|
2534 |
lastFeaBordes = feaBordes; |
2535 |
|
2536 |
if (isDoubleFeatured) {
|
2537 |
lastFeaFondos = feaFondos; |
2538 |
} |
2539 |
|
2540 |
// 041130: Rellena las props con los atributos.
|
2541 |
completeAttributes(feaBordes); |
2542 |
completeAttributes(feaFondos); |
2543 |
|
2544 |
//features.add(feature);
|
2545 |
if (addingToBlock == false) { |
2546 |
if (isDoubleFeatured) {
|
2547 |
features.add(feaFondos); |
2548 |
} else {
|
2549 |
features.add(feaBordes); |
2550 |
} |
2551 |
} else {
|
2552 |
//System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
|
2553 |
if (isDoubleFeatured) {
|
2554 |
blk.add(feaFondos); |
2555 |
} else {
|
2556 |
blk.add(feaBordes); |
2557 |
} |
2558 |
} |
2559 |
|
2560 |
isDoubleFeatured = false;
|
2561 |
} |
2562 |
|
2563 |
/* (non-Javadoc)
|
2564 |
* @see org.cresques.io.DxfFile.EntityFactory#createAttdef(org.cresques.io.DxfGroupVector)
|
2565 |
*/
|
2566 |
public void createAttdef(DxfGroupVector grp) throws Exception { |
2567 |
DxfGroup g = null;
|
2568 |
|
2569 |
String defaultValue = ""; |
2570 |
String tagString = ""; |
2571 |
String textStyleName = ""; |
2572 |
String[] attribute = new String[2]; |
2573 |
boolean tagDefined = false; |
2574 |
boolean defValDefined = false; |
2575 |
|
2576 |
if (grp.hasCode(1)) { |
2577 |
defaultValue = grp.getDataAsString(1);
|
2578 |
attribute[1] = DxfConvTexts.ConvertText(defaultValue);
|
2579 |
defValDefined = true;
|
2580 |
|
2581 |
if (tagDefined) {
|
2582 |
attributes.add(attribute); |
2583 |
} |
2584 |
} |
2585 |
|
2586 |
if (grp.hasCode(2)) { |
2587 |
tagString = grp.getDataAsString(2);
|
2588 |
attribute[0] = DxfConvTexts.ConvertText(tagString);
|
2589 |
tagDefined = true;
|
2590 |
|
2591 |
if (defValDefined) {
|
2592 |
attributes.add(attribute); |
2593 |
} |
2594 |
} |
2595 |
|
2596 |
if (grp.hasCode(7)) { |
2597 |
textStyleName = grp.getDataAsString(7);
|
2598 |
textStyleName = DxfConvTexts.ConvertText(textStyleName); |
2599 |
} |
2600 |
|
2601 |
setNewAttributes(); |
2602 |
} |
2603 |
|
2604 |
/* (non-Javadoc)
|
2605 |
* @see org.cresques.io.DxfFile.EntityFactory#createAttrib(org.cresques.io.DxfGroupVector)
|
2606 |
*/
|
2607 |
public void createAttrib(DxfGroupVector grp) throws Exception { |
2608 |
double x = 0.0; |
2609 |
double y = 0.0; |
2610 |
double z = 0.0; |
2611 |
double h = 0.0; |
2612 |
double rot = 0.0; |
2613 |
DxfGroup g = null;
|
2614 |
|
2615 |
//Point2D pt1 = null, pt2 = null;
|
2616 |
Point3D pt = null;
|
2617 |
org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
|
2618 |
|
2619 |
point.setTextPoint(true);
|
2620 |
|
2621 |
String defaultValue = ""; |
2622 |
String tagString = ""; |
2623 |
String textStyleName = ""; |
2624 |
String[] att = new String[2]; |
2625 |
boolean tagDefined = false; |
2626 |
boolean defValDefined = false; |
2627 |
int attributeFlags = 0; |
2628 |
|
2629 |
double extx = 0.0; |
2630 |
double exty = 0.0; |
2631 |
double extz = 1.0; |
2632 |
|
2633 |
Feature insFea = lastFeaBordes; |
2634 |
Feature ptFea = lastFeaFondos; |
2635 |
|
2636 |
Feature feature = new Feature();
|
2637 |
|
2638 |
feature.setProp("dxfEntity", "Attrib"); // <-- Es un INSERT con attributes. |
2639 |
|
2640 |
if (grp.hasCode(8)) { |
2641 |
feature.setProp("layer", grp.getDataAsString(8)); |
2642 |
} |
2643 |
|
2644 |
if (grp.hasCode(39)) { |
2645 |
Double doub = new Double(grp.getDataAsDouble(39)); |
2646 |
String string = doub.toString();
|
2647 |
feature.setProp("thickness", string);
|
2648 |
} else {
|
2649 |
Double doub = new Double(0.0); |
2650 |
feature.setProp("thickness", doub.toString());
|
2651 |
} |
2652 |
|
2653 |
if (grp.hasCode(62)) { |
2654 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
2655 |
String string = integer.toString();
|
2656 |
feature.setProp("color", string);
|
2657 |
feature.setProp("colorByLayer", "false"); |
2658 |
} else {
|
2659 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2660 |
int clr = layer.colorNumber;
|
2661 |
Integer integer = new Integer(clr); |
2662 |
String string = integer.toString();
|
2663 |
feature.setProp("color", string);
|
2664 |
feature.setProp("colorByLayer", "true"); |
2665 |
} |
2666 |
|
2667 |
if (grp.hasCode(1)) { |
2668 |
String strAux1 = grp.getDataAsString(1); |
2669 |
strAux1 = DxfConvTexts.ConvertText(strAux1); |
2670 |
defaultValue = strAux1; |
2671 |
att[1] = DxfConvTexts.ConvertText(defaultValue);
|
2672 |
defValDefined = true;
|
2673 |
|
2674 |
if (tagDefined) {
|
2675 |
insFea.setProp(att[0], att[1]); |
2676 |
ptFea.setProp(att[0], att[1]); |
2677 |
} |
2678 |
|
2679 |
feature.setProp("text", strAux1);
|
2680 |
} |
2681 |
|
2682 |
if (grp.hasCode(2)) { |
2683 |
String strAux2 = grp.getDataAsString(2); |
2684 |
strAux2 = DxfConvTexts.ConvertText(strAux2); |
2685 |
tagString = strAux2; |
2686 |
att[0] = DxfConvTexts.ConvertText(tagString);
|
2687 |
tagDefined = true;
|
2688 |
|
2689 |
if (defValDefined) {
|
2690 |
insFea.setProp(att[0], att[1]); |
2691 |
ptFea.setProp(att[0], att[1]); |
2692 |
} |
2693 |
} |
2694 |
|
2695 |
if (grp.hasCode(7)) { |
2696 |
textStyleName = grp.getDataAsString(7);
|
2697 |
textStyleName = DxfConvTexts.ConvertText(textStyleName); |
2698 |
} |
2699 |
|
2700 |
if (grp.hasCode(70)) { |
2701 |
attributeFlags = grp.getDataAsInt(70);
|
2702 |
} |
2703 |
|
2704 |
if (grp.hasCode(40)) { |
2705 |
Double heightD = new Double(grp.getDataAsDouble(40)); |
2706 |
String heightS = heightD.toString();
|
2707 |
feature.setProp("textHeight", heightS);
|
2708 |
} else {
|
2709 |
feature.setProp("textHeight", "20.0"); |
2710 |
} |
2711 |
|
2712 |
if (grp.hasCode(50)) { |
2713 |
Double rotD = new Double(grp.getDataAsDouble(50)); |
2714 |
String rotS = rotD.toString();
|
2715 |
feature.setProp("textRotation", rotS);
|
2716 |
} else {
|
2717 |
feature.setProp("textRotation", "0.0"); |
2718 |
} |
2719 |
|
2720 |
x = grp.getDataAsDouble(10);
|
2721 |
y = grp.getDataAsDouble(20);
|
2722 |
z = grp.getDataAsDouble(30);
|
2723 |
|
2724 |
/*if (grp.hasCode(30)){
|
2725 |
z = grp.getDataAsDouble(30);
|
2726 |
Double doub = new Double(z);
|
2727 |
String string = doub.toString();
|
2728 |
feature.setProp("elevation", string);
|
2729 |
} else {
|
2730 |
Double doub = new Double(0.0);
|
2731 |
feature.setProp("elevation", doub.toString());
|
2732 |
}*/
|
2733 |
if (grp.hasCode(210)) { |
2734 |
extx = grp.getDataAsDouble(210);
|
2735 |
} |
2736 |
|
2737 |
if (grp.hasCode(220)) { |
2738 |
exty = grp.getDataAsDouble(220);
|
2739 |
} |
2740 |
|
2741 |
if (grp.hasCode(230)) { |
2742 |
extz = grp.getDataAsDouble(230);
|
2743 |
} |
2744 |
|
2745 |
Point3D point_in = new Point3D(x, y, z);
|
2746 |
Point3D xtru = new Point3D(extx, exty, extz);
|
2747 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
2748 |
x = point_out.getX(); |
2749 |
y = point_out.getY(); |
2750 |
z = point_out.getZ(); |
2751 |
|
2752 |
Double doub = new Double(z); |
2753 |
feature.setProp("elevation", doub.toString());
|
2754 |
|
2755 |
if (z != 0.0) { |
2756 |
dxf3DFile = true;
|
2757 |
} |
2758 |
|
2759 |
point.add(new Point3D(x, y, z));
|
2760 |
feature.setGeometry(point); |
2761 |
|
2762 |
// 041130: Rellena las props con los atributos.
|
2763 |
completeAttributes(feature); |
2764 |
|
2765 |
if (attributeFlags == 8) { |
2766 |
if (addingToBlock == false) { |
2767 |
features.add(feature); |
2768 |
} else {
|
2769 |
blk.add(feature); |
2770 |
} |
2771 |
} |
2772 |
} |
2773 |
|
2774 |
/* (non-Javadoc)
|
2775 |
* @see org.cresques.io.DxfFile.EntityFactory#createBlock(org.cresques.io.DxfGroupVector)
|
2776 |
*/
|
2777 |
public void createBlock(DxfGroupVector grp) throws Exception { |
2778 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2779 |
blk = new FeatureCollection(proj);
|
2780 |
|
2781 |
Point3D basePoint = new Point3D();
|
2782 |
String blockName = ""; |
2783 |
|
2784 |
//System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
|
2785 |
addingToBlock = true;
|
2786 |
|
2787 |
//System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
|
2788 |
blkList.add(iterator, blk); |
2789 |
|
2790 |
//System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
|
2791 |
if (grp.hasCode(8)) { |
2792 |
blk.setProp("layer", grp.getDataAsString(8)); |
2793 |
} |
2794 |
|
2795 |
if (grp.hasCode(62)) { |
2796 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
2797 |
String string = integer.toString();
|
2798 |
blk.setProp("color", string);
|
2799 |
blk.setProp("colorByLayer", "false"); |
2800 |
} else {
|
2801 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2802 |
int clr = layer.colorNumber;
|
2803 |
Integer integer = new Integer(clr); |
2804 |
String string = integer.toString();
|
2805 |
blk.setProp("color", string);
|
2806 |
blk.setProp("colorByLayer", "true"); |
2807 |
} |
2808 |
|
2809 |
if (grp.hasCode(1)) { |
2810 |
blockName = grp.getDataAsString(1);
|
2811 |
|
2812 |
//blk.setBlkName(blockName);
|
2813 |
blk.setProp("blockName", blockName);
|
2814 |
} |
2815 |
|
2816 |
if (grp.hasCode(2)) { |
2817 |
blockName = grp.getDataAsString(2);
|
2818 |
|
2819 |
//blk.setBlkName(blockName);
|
2820 |
blk.setProp("blockName", blockName);
|
2821 |
} |
2822 |
|
2823 |
if (grp.hasCode(10)) { |
2824 |
Double basePointX = new Double(grp.getDataAsDouble(10)); |
2825 |
basePoint.X = grp.getDataAsDouble(10);
|
2826 |
blk.setProp("basePointX", basePointX.toString());
|
2827 |
} |
2828 |
|
2829 |
if (grp.hasCode(20)) { |
2830 |
Double basePointY = new Double(grp.getDataAsDouble(20)); |
2831 |
basePoint.Y = grp.getDataAsDouble(20);
|
2832 |
blk.setProp("basePointY", basePointY.toString());
|
2833 |
} |
2834 |
|
2835 |
if (grp.hasCode(30)) { |
2836 |
Double basePointZ = new Double(grp.getDataAsDouble(30)); |
2837 |
basePoint.Z = grp.getDataAsDouble(30);
|
2838 |
|
2839 |
if (basePoint.getZ() != 0.0) { |
2840 |
dxf3DFile = true;
|
2841 |
} |
2842 |
|
2843 |
blk.setProp("basePointZ", basePointZ.toString());
|
2844 |
} |
2845 |
|
2846 |
if (grp.hasCode(70)) { |
2847 |
//blk.flags = grp.getDataAsInt(70);
|
2848 |
Integer blockFlags = new Integer(grp.getDataAsInt(70)); |
2849 |
blk.setProp("blockFlags", blockFlags.toString());
|
2850 |
|
2851 |
// 041103: Hoy por hoy esto no lo utilizamos.
|
2852 |
} |
2853 |
} |
2854 |
|
2855 |
/* (non-Javadoc)
|
2856 |
* @see org.cresques.io.DxfFile.EntityFactory#endBlk(org.cresques.io.DxfGroupVector)
|
2857 |
*/
|
2858 |
public void endBlk(DxfGroupVector grp) throws Exception { |
2859 |
//DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
2860 |
setAddingToBlock(false);
|
2861 |
iterator = iterator + 1;
|
2862 |
} |
2863 |
|
2864 |
/* (non-Javadoc)
|
2865 |
* @see org.cresques.io.DxfFile.EntityFactory#testBlocks()
|
2866 |
*/
|
2867 |
public void testBlocks() { |
2868 |
//System.out.println("getBlkList() = " + getBlkList());
|
2869 |
Vector blkList = getBlkList();
|
2870 |
FeatureCollection block = null;
|
2871 |
Feature feature = null;
|
2872 |
InsPoint3D insert = null;
|
2873 |
|
2874 |
for (int i = 0; i < blkList.size(); i++) { |
2875 |
//System.out.println("compruebaBloques(): Bloque " + i +" de " + blkList.size());
|
2876 |
block = (FeatureCollection) blkList.get(i); |
2877 |
|
2878 |
int aux = block.size();
|
2879 |
|
2880 |
for (int j = 0; j < aux; j++) { |
2881 |
feature = (Feature) block.get(j); |
2882 |
|
2883 |
//if (feature.getGeometry() instanceof InsPoint && feature.getProp("isAnInsert") == "true") {
|
2884 |
if (feature.getGeometry() instanceof InsPoint3D) { |
2885 |
insert = (InsPoint3D) feature.getGeometry(); |
2886 |
|
2887 |
String nomBlock = insert.getBlockName();
|
2888 |
|
2889 |
if (insert.getBlockFound() == false) { |
2890 |
//System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock);
|
2891 |
insert.encuentraBloque(nomBlock); |
2892 |
|
2893 |
//gestionaInsert(feature);
|
2894 |
//block.add(feature);
|
2895 |
} |
2896 |
} |
2897 |
} |
2898 |
} |
2899 |
} |
2900 |
|
2901 |
/**
|
2902 |
* M?todo que permite incluir en la lista general de objetos los objetos que se
|
2903 |
* encuentran dentro del bloque referenciado por cada InsPoint3D.
|
2904 |
* @param feature, el punto de inserci?n.
|
2905 |
*/
|
2906 |
private void gestionaInsert(Feature feature) { |
2907 |
Feature feature2 = null;
|
2908 |
org.cresques.px.gml.Point3D point = null;
|
2909 |
LineString3D lineString3D = null;
|
2910 |
Polygon3D polygon3D = null;
|
2911 |
InsPoint3D insert = new InsPoint3D();
|
2912 |
insert = (InsPoint3D) feature.getGeometry(); |
2913 |
|
2914 |
double bPointX = 0.0; |
2915 |
double bPointY = 0.0; |
2916 |
double bPointZ = 0.0; |
2917 |
|
2918 |
if (insert.getBlockFound() != true) |
2919 |
{ |
2920 |
System.err.println("BLOQUE NO ENCONTRADO !!!" + insert.getBlockName() + " " + insert.toString()); |
2921 |
return;
|
2922 |
} |
2923 |
|
2924 |
bPointX = Double.parseDouble(insert.getBlock().getProp("basePointX")); |
2925 |
bPointY = Double.parseDouble(insert.getBlock().getProp("basePointY")); |
2926 |
bPointZ = Double.parseDouble(insert.getBlock().getProp("basePointZ")); |
2927 |
|
2928 |
//}
|
2929 |
double sFactorX = insert.getScaleFactor().getX();
|
2930 |
double sFactorY = insert.getScaleFactor().getY();
|
2931 |
double sFactorZ = insert.getScaleFactor().getZ();
|
2932 |
double rAngleGra = insert.getRotAngle();
|
2933 |
double rAngleRad = (rAngleGra * Math.PI) / 180.0; |
2934 |
InsPoint3D insert2 = null;
|
2935 |
|
2936 |
for (int i = 0; i < insert.getBlock().size(); i++) { |
2937 |
//System.out.println("gestionaInserts: insert.getBlock().features.size() = " + insert.getBlock().size());
|
2938 |
feature2 = (Feature) insert.getBlock().get(i); |
2939 |
|
2940 |
// Para que los elementos dentro del bloque tengan la misma layer
|
2941 |
// y color que el insert al que corresponden.
|
2942 |
// Segun la especificacion del formato DXF de Autodesk, la layer
|
2943 |
// de las entities dentro de un bloque es la del bloque. La
|
2944 |
// layer especifica para estos elementos en la defincion del
|
2945 |
// bloque se ignora.
|
2946 |
//System.out.println("gestionaInsert(): layer = " + feature2.getProp("layer"));
|
2947 |
if ((feature2.getProp("colorByLayer").equals("false") || |
2948 |
feature2.getProp("layer").equals("0")) && |
2949 |
!feature.getProp("layer").equals("0")) { |
2950 |
feature2.setProp("color", feature.getProp("color")); |
2951 |
} |
2952 |
|
2953 |
feature2.setProp("layer", feature.getProp("layer")); |
2954 |
|
2955 |
Point3D point1 = new Point3D();
|
2956 |
Point3D point11 = new Point3D();
|
2957 |
Point3D pointAux = null;
|
2958 |
|
2959 |
if (feature2.getGeometry() instanceof InsPoint3D) { |
2960 |
//System.out.println("gestionaInsert(): Encuentra bloques dentro de bloques");
|
2961 |
insert2 = (InsPoint3D) feature2.getGeometry(); |
2962 |
point1 = insert2.getPoint3D(0);
|
2963 |
|
2964 |
pointAux = new Point3D(point1.getX() - bPointX,
|
2965 |
point1.getY() - bPointY, |
2966 |
point1.getZ() - bPointZ); |
2967 |
|
2968 |
double laX = insert.getPoint3D(0).getX() + |
2969 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
2970 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
2971 |
double laY = insert.getPoint3D(0).getY() + |
2972 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
2973 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
2974 |
double laZ = insert.getPoint3D(0).getZ() + |
2975 |
(pointAux.getZ() * sFactorZ); |
2976 |
point11 = new Point3D(laX, laY, laZ);
|
2977 |
|
2978 |
InsPoint3D insert3 = new InsPoint3D();
|
2979 |
|
2980 |
insert3.add(point11); |
2981 |
|
2982 |
insert3.setBlkList(insert2.getBlkList()); |
2983 |
insert3.setBlock(insert2.getBlock()); |
2984 |
insert3.setBlockName(insert2.getBlockName()); |
2985 |
insert3.setRotAngle(insert2.getRotAngle()); |
2986 |
|
2987 |
Point3D newScale = new Point3D(insert2.getScaleFactor().getX() * sFactorX,
|
2988 |
insert2.getScaleFactor().getY() * sFactorY, |
2989 |
insert2.getScaleFactor().getZ() * sFactorZ); |
2990 |
insert3.setScaleFactor(newScale); |
2991 |
|
2992 |
Feature feature3 = new Feature();
|
2993 |
feature3.setProp("layer", feature2.getProp("layer")); |
2994 |
feature3.setProp("color", feature2.getProp("color")); |
2995 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
2996 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
2997 |
|
2998 |
//041130
|
2999 |
for (int j = 0; j < attributes.size(); j++) { |
3000 |
String[] att = new String[2]; |
3001 |
att = (String[]) attributes.get(j); |
3002 |
feature3.setProp(att[0], feature2.getProp(att[0])); |
3003 |
} |
3004 |
|
3005 |
feature3.setGeometry(insert3); |
3006 |
|
3007 |
gestionaInsert(feature3); |
3008 |
} else if (feature2.getGeometry() instanceof LineString3D) { |
3009 |
lineString3D = (LineString3D) feature2.getGeometry(); |
3010 |
|
3011 |
LineString3D lineString2 = new LineString3D();
|
3012 |
Point3D[] points = new Point3D[lineString3D.pointNr()]; |
3013 |
Point3D[] pointss = new Point3D[lineString3D.pointNr()]; |
3014 |
|
3015 |
for (int j = 0; j < lineString3D.pointNr(); j++) { |
3016 |
points[j] = (Point3D) lineString3D.get(j); |
3017 |
pointss[j] = new Point3D();
|
3018 |
|
3019 |
pointAux = new Point3D(points[j].getX() - bPointX,
|
3020 |
points[j].getY() - bPointY, |
3021 |
points[j].getZ() - bPointZ); |
3022 |
|
3023 |
double laX = insert.getPoint3D(0).getX() + |
3024 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
3025 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
3026 |
double laY = insert.getPoint3D(0).getY() + |
3027 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
3028 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
3029 |
double laZ = insert.getPoint3D(0).getZ() + |
3030 |
(pointAux.getZ() * sFactorZ); |
3031 |
pointss[j] = new Point3D(laX, laY, laZ);
|
3032 |
lineString2.add(pointss[j]); |
3033 |
} |
3034 |
|
3035 |
Feature feature3 = new Feature();
|
3036 |
feature3.setProp("layer", feature2.getProp("layer")); |
3037 |
feature3.setProp("color", feature2.getProp("color")); |
3038 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
3039 |
|
3040 |
if (feature2.getProp("elevation") != null) { |
3041 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
3042 |
} |
3043 |
|
3044 |
feature3.setProp("thickness", feature2.getProp("thickness")); |
3045 |
|
3046 |
//041130
|
3047 |
for (int j = 0; j < attributes.size(); j++) { |
3048 |
String[] att = new String[2]; |
3049 |
att = (String[]) attributes.get(j); |
3050 |
|
3051 |
String str = att[0]; |
3052 |
feature3.setProp(str, feature2.getProp(str)); |
3053 |
} |
3054 |
|
3055 |
feature3.setGeometry(lineString2); |
3056 |
|
3057 |
if (addingToBlock == false) { |
3058 |
features.add(feature3); |
3059 |
} |
3060 |
} else if (feature2.getGeometry() instanceof Polygon3D) { |
3061 |
polygon3D = (Polygon3D) feature2.getGeometry(); |
3062 |
|
3063 |
Polygon3D polygon2 = new Polygon3D();
|
3064 |
Point3D[] points = new Point3D[polygon3D.pointNr()]; |
3065 |
Point3D[] pointss = new Point3D[polygon3D.pointNr()]; |
3066 |
|
3067 |
for (int j = 0; j < polygon3D.pointNr(); j++) { |
3068 |
points[j] = (Point3D) polygon3D.get(j); |
3069 |
pointss[j] = new Point3D();
|
3070 |
|
3071 |
pointAux = new Point3D(points[j].getX() - bPointX,
|
3072 |
points[j].getY() - bPointY, |
3073 |
points[j].getZ() - bPointZ); |
3074 |
|
3075 |
double laX = insert.getPoint3D(0).getX() + |
3076 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
3077 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
3078 |
double laY = insert.getPoint3D(0).getY() + |
3079 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
3080 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
3081 |
double laZ = insert.getPoint3D(0).getZ() + |
3082 |
(pointAux.getZ() * sFactorZ); |
3083 |
pointss[j] = new Point3D(laX, laY, laZ);
|
3084 |
polygon2.add(pointss[j]); |
3085 |
} |
3086 |
|
3087 |
Feature feature3 = new Feature();
|
3088 |
feature3.setProp("layer", feature2.getProp("layer")); |
3089 |
feature3.setProp("color", feature2.getProp("color")); |
3090 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
3091 |
|
3092 |
if (feature2.getProp("elevation") != null) { |
3093 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
3094 |
} |
3095 |
|
3096 |
feature3.setProp("thickness", feature2.getProp("thickness")); |
3097 |
|
3098 |
//041130
|
3099 |
for (int j = 0; j < attributes.size(); j++) { |
3100 |
String[] att = new String[2]; |
3101 |
att = (String[]) attributes.get(j); |
3102 |
feature3.setProp(att[0], feature2.getProp(att[0])); |
3103 |
} |
3104 |
|
3105 |
feature3.setGeometry(polygon2); |
3106 |
|
3107 |
if (addingToBlock == false) { |
3108 |
features.add(feature3); |
3109 |
} |
3110 |
} else if (feature2.getGeometry() instanceof org.cresques.px.gml.Point3D) { |
3111 |
point = (org.cresques.px.gml.Point3D) feature2.getGeometry(); |
3112 |
point1 = point.getPoint3D(0);
|
3113 |
|
3114 |
pointAux = new Point3D(point1.getX() - bPointX,
|
3115 |
point1.getY() - bPointY, |
3116 |
point1.getZ() - bPointZ); |
3117 |
|
3118 |
double laX = insert.getPoint3D(0).getX() + |
3119 |
(((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
|
3120 |
((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad))); |
3121 |
double laY = insert.getPoint3D(0).getY() + |
3122 |
(((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
|
3123 |
((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
|
3124 |
double laZ = insert.getPoint3D(0).getZ() + |
3125 |
(pointAux.getZ() * sFactorZ); |
3126 |
point11 = new Point3D(laX, laY, laZ);
|
3127 |
|
3128 |
org.cresques.px.gml.Point3D pointt = new org.cresques.px.gml.Point3D();
|
3129 |
pointt.add(point11); |
3130 |
|
3131 |
Feature feature3 = new Feature();
|
3132 |
feature3.setProp("layer", feature2.getProp("layer")); |
3133 |
feature3.setProp("color", feature2.getProp("color")); |
3134 |
feature3.setProp("dxfEntity", feature2.getProp("dxfEntity")); |
3135 |
feature3.setProp("elevation", feature2.getProp("elevation")); |
3136 |
feature3.setProp("thickness", feature2.getProp("thickness")); |
3137 |
|
3138 |
if (point.isTextPoint()) {
|
3139 |
feature3.setProp("text", feature2.getProp("text")); |
3140 |
feature3.setProp("textHeight",
|
3141 |
feature2.getProp("textHeight"));
|
3142 |
|
3143 |
double auxR = Double.parseDouble(feature2.getProp("textRotation")); |
3144 |
|
3145 |
//System.out.println("auxR = " + auxR);
|
3146 |
auxR = auxR + rAngleGra; |
3147 |
feature3.setProp("textRotation", Double.toString(auxR)); |
3148 |
|
3149 |
//System.out.println("gestionaInsert(): feature3.getProp(textRotation) = " + feature3.getProp("textRotation"));
|
3150 |
pointt.setTextPoint(true);
|
3151 |
} |
3152 |
|
3153 |
//041130
|
3154 |
for (int j = 0; j < attributes.size(); j++) { |
3155 |
String[] att = new String[2]; |
3156 |
att = (String[]) attributes.get(j); |
3157 |
feature3.setProp(att[0], feature2.getProp(att[0])); |
3158 |
} |
3159 |
|
3160 |
feature3.setGeometry(pointt); |
3161 |
|
3162 |
//if (addingToBlock == false) {
|
3163 |
features.add(feature3); |
3164 |
|
3165 |
//}
|
3166 |
} else {
|
3167 |
System.out.println("gestionaInsert(): Encontrado elemento desconocido"); |
3168 |
} |
3169 |
} |
3170 |
} |
3171 |
|
3172 |
/**
|
3173 |
* Gestiona la caracter?stica faces en las polil?neas.
|
3174 |
* @param face
|
3175 |
*/
|
3176 |
private void addFace(int[] face) { |
3177 |
hasFaces = true;
|
3178 |
|
3179 |
if (faces == null) { |
3180 |
faces = new Vector(); |
3181 |
} |
3182 |
|
3183 |
faces.add(face); |
3184 |
} |
3185 |
|
3186 |
/* (non-Javadoc)
|
3187 |
* @see org.cresques.io.DxfFile.EntityFactory#depureAttributes()
|
3188 |
*/
|
3189 |
public void depureAttributes() { |
3190 |
//String[] att = null;
|
3191 |
|
3192 |
/*Set conjunto = new HashSet();
|
3193 |
for (int i=0;i<attributes.size();i++) {
|
3194 |
att = (String[])attributes.get(i);
|
3195 |
String str = att[0];
|
3196 |
conjunto.add(str);
|
3197 |
}
|
3198 |
//conjunto.addAll(attributes);
|
3199 |
Vector atts = new Vector();
|
3200 |
Vector atts2 = new Vector();
|
3201 |
atts.addAll(conjunto);
|
3202 |
for (int i=0;i<atts.size();i++) {
|
3203 |
if (((String[])(attributes.get(i)))[0] == atts.get(i)) {
|
3204 |
atts2.add(i, attributes.get(i));
|
3205 |
}
|
3206 |
}*/
|
3207 |
String[] lastAtt = new String[2]; |
3208 |
|
3209 |
for (int i = 0; i < attributes.size(); i++) { |
3210 |
String[] att = (String[]) attributes.get(i); |
3211 |
|
3212 |
for (int j = i + 1; j < attributes.size(); j++) { |
3213 |
//System.out.println("depureAttributes(): j = " + j);
|
3214 |
String[] st = (String[]) attributes.get(j); |
3215 |
String st1 = att[0]; |
3216 |
String st2 = st[0]; |
3217 |
|
3218 |
//System.out.println("depureAttributes(): st1 = " + st1);
|
3219 |
//System.out.println("depureAttributes(): st2 = " + st2);
|
3220 |
if (st2.equals(st1)) {
|
3221 |
//System.out.println("depureAttributes(): Borra el st2");
|
3222 |
attributes.remove(j); |
3223 |
} |
3224 |
|
3225 |
if (i == (attributes.size() - 1)) { |
3226 |
lastAtt = att; |
3227 |
} |
3228 |
} |
3229 |
} |
3230 |
|
3231 |
for (int i = attributes.size() - 2; i >= 0; i--) { |
3232 |
String[] att = (String[]) attributes.get(i); |
3233 |
String st1 = lastAtt[0]; |
3234 |
String st2 = att[0]; |
3235 |
|
3236 |
if (st2.equals(st1)) {
|
3237 |
attributes.remove(i); |
3238 |
} |
3239 |
} |
3240 |
|
3241 |
/*String[] attStrs = new String[attributes.size()];
|
3242 |
Vector attribs = new Vector();
|
3243 |
for (int i=0;i<attributes.size();i++) {
|
3244 |
att = (String[])attributes.get(i);
|
3245 |
attStrs[i] = att[0];
|
3246 |
}
|
3247 |
Set attStrsNR = new HashSet();
|
3248 |
for (int i=0;i<attStrs.length;i++) {
|
3249 |
attStrsNR.add(attStrs[i]);
|
3250 |
}
|
3251 |
String[] attStrsNRA = new String[attStrsNR.size()];
|
3252 |
attStrsNR.toArray(attStrsNRA);
|
3253 |
for (int i=0;i<attStrsNR.size();i++) {
|
3254 |
att[0] = attStrsNRA[i];
|
3255 |
attribs.add(att);
|
3256 |
}
|
3257 |
for (int i=0;i<attributes.size();i++) {
|
3258 |
att = (String[])attributes.get(i);
|
3259 |
String[] att2 = new String[2];
|
3260 |
for (int j=0;j<attribs.size();j++) {
|
3261 |
att2 = (String[])attribs.get(j);
|
3262 |
if (att[0].equals(att2[0])) {
|
3263 |
att2[1] = att[1];
|
3264 |
}
|
3265 |
attribs.set(j, att2);
|
3266 |
}
|
3267 |
}
|
3268 |
attributes = attribs;*/
|
3269 |
} |
3270 |
|
3271 |
/**
|
3272 |
* Hace los setProp para los atributos extra de las entidades.
|
3273 |
* @param feature
|
3274 |
*/
|
3275 |
private void completeAttributes(Feature feature) { |
3276 |
// 041130: Rellena las props con los atributos.
|
3277 |
for (int i = 0; i < attributes.size(); i++) { |
3278 |
String[] att = new String[2]; |
3279 |
att = (String[]) attributes.get(i); |
3280 |
feature.setProp(att[0], att[1]); |
3281 |
} |
3282 |
} |
3283 |
|
3284 |
/**
|
3285 |
* Copia los atributos extra cargados en InsPoint y ya perfectamente definidos a los
|
3286 |
* elementos del bloque al que referencia el punto de insercion.
|
3287 |
* @param feaInsert, punto de inserci?n.
|
3288 |
*/
|
3289 |
private void copyAttributes(Feature feaInsert) { |
3290 |
Feature feature = null;
|
3291 |
InsPoint3D insert = new InsPoint3D();
|
3292 |
insert = (InsPoint3D) feaInsert.getGeometry(); |
3293 |
|
3294 |
for (int i = 0; i < insert.getBlock().size(); i++) { |
3295 |
feature = (Feature) insert.getBlock().get(i); |
3296 |
|
3297 |
for (int j = 0; j < attributes.size(); j++) { |
3298 |
String[] att = new String[2]; |
3299 |
att = (String[]) attributes.get(j); |
3300 |
feature.setProp(att[0], feaInsert.getProp(att[0])); |
3301 |
} |
3302 |
} |
3303 |
} |
3304 |
|
3305 |
/**
|
3306 |
* Se ejecuta cuando se declaran nuevos atributos, es decir, tras cada ATTDEF.
|
3307 |
* A?ade estos atributos a las features existentes.
|
3308 |
*/
|
3309 |
private void setNewAttributes() { |
3310 |
for (int i = 0; i < features.size(); i++) { |
3311 |
Feature fea = new Feature();
|
3312 |
fea = (Feature) features.get(i); |
3313 |
completeAttributes(fea); |
3314 |
} |
3315 |
|
3316 |
for (int i = 0; i < blkList.size(); i++) { |
3317 |
FeatureCollection bloque = new FeatureCollection(proj);
|
3318 |
bloque = (FeatureCollection) blkList.get(i); |
3319 |
|
3320 |
for (int j = 0; j < bloque.size(); j++) { |
3321 |
Feature fea = new Feature();
|
3322 |
fea = (Feature) bloque.get(j); |
3323 |
completeAttributes(fea); |
3324 |
} |
3325 |
} |
3326 |
} |
3327 |
|
3328 |
/* (non-Javadoc)
|
3329 |
* @see org.cresques.io.DxfFile.EntityFactory#getAttributes()
|
3330 |
*/
|
3331 |
public Vector getAttributes() { |
3332 |
return attributes;
|
3333 |
} |
3334 |
|
3335 |
/* (non-Javadoc)
|
3336 |
* @see org.cresques.io.DxfFile.EntityFactory#getExtent()
|
3337 |
*/
|
3338 |
public Extent getExtent() {
|
3339 |
Feature feature = new Feature();
|
3340 |
Extent extent = new Extent();
|
3341 |
Iterator iter = features.iterator();
|
3342 |
|
3343 |
while (iter.hasNext()) {
|
3344 |
feature = (Feature) iter.next(); |
3345 |
extent.add(feature.getExtent()); |
3346 |
} |
3347 |
|
3348 |
return extent;
|
3349 |
} |
3350 |
|
3351 |
/**
|
3352 |
* Establece la proyecci?n cartogr?fica en la que se van a crear las features.
|
3353 |
* @param p, Proyecci?n cartogr?fica.
|
3354 |
*/
|
3355 |
public void setProjection(IProjection p) { |
3356 |
proj = p; |
3357 |
} |
3358 |
|
3359 |
/* (non-Javadoc)
|
3360 |
* @see org.cresques.io.DxfFile.EntityFactory#reProject(org.cresques.geo.ReProjection)
|
3361 |
*/
|
3362 |
public void reProject(ICoordTrans rp) { |
3363 |
Feature feature = new Feature();
|
3364 |
Extent extent = new Extent();
|
3365 |
Iterator iter = features.iterator();
|
3366 |
|
3367 |
while (iter.hasNext()) {
|
3368 |
feature = (Feature) iter.next(); |
3369 |
((Projected) feature).reProject(rp); |
3370 |
extent.add(feature.getExtent()); |
3371 |
} |
3372 |
|
3373 |
setProjection(rp.getPDest()); |
3374 |
} |
3375 |
|
3376 |
/* (non-Javadoc)
|
3377 |
* @see org.cresques.geo.Projected#getProjection()
|
3378 |
*/
|
3379 |
public IProjection getProjection() {
|
3380 |
return proj;
|
3381 |
} |
3382 |
|
3383 |
/**
|
3384 |
* Devuelve las features creadas.
|
3385 |
* @return IObjList
|
3386 |
*/
|
3387 |
public IObjList getObjects() {
|
3388 |
return features;
|
3389 |
} |
3390 |
|
3391 |
/**
|
3392 |
* Permite dibujar las features creadas.
|
3393 |
*/
|
3394 |
public void draw(Graphics2D g, ViewPortData vp) { |
3395 |
Iterator iter = features.iterator();
|
3396 |
Extent extent; |
3397 |
|
3398 |
while (iter.hasNext()) {
|
3399 |
Feature feature = new Feature();
|
3400 |
feature = (Feature) iter.next(); |
3401 |
extent = feature.getExtent(); |
3402 |
|
3403 |
if (vp.getExtent().minX() > extent.maxX()) {
|
3404 |
continue;
|
3405 |
} |
3406 |
|
3407 |
if (vp.getExtent().minY() > extent.maxY()) {
|
3408 |
continue;
|
3409 |
} |
3410 |
|
3411 |
if (vp.getExtent().maxX() < extent.minX()) {
|
3412 |
continue;
|
3413 |
} |
3414 |
|
3415 |
if (vp.getExtent().maxY() < extent.minY()) {
|
3416 |
continue;
|
3417 |
} |
3418 |
|
3419 |
//if (!feature.layer.frozen)
|
3420 |
feature.draw(g, vp); |
3421 |
} |
3422 |
} |
3423 |
|
3424 |
/**
|
3425 |
* Invoca el m?todo de creaci?n de arcos para polil?neas con par?metros de
|
3426 |
* curvatura.
|
3427 |
* @param coord1, punto inicial del arco.
|
3428 |
* @param coord2, punto final del arco.
|
3429 |
* @param bulge, par?metro de curvatura.
|
3430 |
* @return Vector con los puntos del arco.
|
3431 |
*/
|
3432 |
public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) { |
3433 |
return new DxfCalArcs(coord1, coord2, bulge).getPoints(1); |
3434 |
} |
3435 |
|
3436 |
/* (non-Javadoc)
|
3437 |
* @see org.cresques.io.DxfFile.EntityFactory#getBlkList()
|
3438 |
*/
|
3439 |
public Vector getBlkList() { |
3440 |
return blkList;
|
3441 |
} |
3442 |
|
3443 |
/* (non-Javadoc)
|
3444 |
* @see org.cresques.io.DxfFile.EntityFactory#getDxfEntityList()
|
3445 |
*/
|
3446 |
public DxfEntityList getDxfEntityList() {
|
3447 |
// TODO Auto-generated method stub
|
3448 |
return null; |
3449 |
} |
3450 |
|
3451 |
/* (non-Javadoc)
|
3452 |
* @see org.cresques.io.DxfFile.EntityFactory#getBlk()
|
3453 |
*/
|
3454 |
public DxfBlock getBlk() {
|
3455 |
// TODO Auto-generated method stub
|
3456 |
return null; |
3457 |
} |
3458 |
|
3459 |
/* (non-Javadoc)
|
3460 |
* @see org.cresques.io.DxfFile.EntityFactory#createEllipse(org.cresques.io.DxfGroupVector)
|
3461 |
*/
|
3462 |
public void createEllipse(DxfGroupVector grp) throws Exception { |
3463 |
double cx = 0.0; |
3464 |
double cy = 0.0; |
3465 |
double cz = 0.0; |
3466 |
|
3467 |
double x_end_point_major_axis = 0.0; |
3468 |
double y_end_point_major_axis = 0.0; |
3469 |
double z_end_point_major_axis = 0.0; |
3470 |
|
3471 |
double extx = 0.0; |
3472 |
double exty = 0.0; |
3473 |
double extz = 1.0; |
3474 |
double ratio_minor_to_major_axis = 1.0; |
3475 |
double start = 0.0; |
3476 |
double end = 2* Math.PI; |
3477 |
LineString3D lineString3D = new LineString3D();
|
3478 |
Polygon3D polygon3D = new Polygon3D();
|
3479 |
Feature feaBordes = new Feature();
|
3480 |
Feature feaFondos = new Feature();
|
3481 |
|
3482 |
feaBordes.setProp("dxfEntity", "Ellipse"); |
3483 |
feaFondos.setProp("dxfEntity", "Ellipse"); |
3484 |
|
3485 |
if (grp.hasCode(8)) { |
3486 |
feaBordes.setProp("layer", grp.getDataAsString(8)); |
3487 |
} |
3488 |
|
3489 |
feaFondos.setProp("layer", grp.getDataAsString(8)); |
3490 |
|
3491 |
if (grp.hasCode(39)) { |
3492 |
Double doub = new Double(grp.getDataAsDouble(39)); |
3493 |
String string = doub.toString();
|
3494 |
feaBordes.setProp("thickness", string);
|
3495 |
feaFondos.setProp("thickness", string);
|
3496 |
} else {
|
3497 |
Double doub = new Double(0.0); |
3498 |
feaBordes.setProp("thickness", doub.toString());
|
3499 |
feaFondos.setProp("thickness", doub.toString());
|
3500 |
} |
3501 |
|
3502 |
if (grp.hasCode(62)) { |
3503 |
Integer integer = new Integer(grp.getDataAsInt(62)); |
3504 |
String string = integer.toString();
|
3505 |
feaBordes.setProp("color", string);
|
3506 |
feaFondos.setProp("color", string);
|
3507 |
feaBordes.setProp("colorByLayer", "false"); |
3508 |
feaFondos.setProp("colorByLayer", "false"); |
3509 |
} else {
|
3510 |
DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
3511 |
int clr = layer.colorNumber;
|
3512 |
Integer integer = new Integer(clr); |
3513 |
String string = integer.toString();
|
3514 |
feaBordes.setProp("color", string);
|
3515 |
feaFondos.setProp("color", string);
|
3516 |
feaBordes.setProp("colorByLayer", "true"); |
3517 |
feaFondos.setProp("colorByLayer", "true"); |
3518 |
} |
3519 |
|
3520 |
// Center point
|
3521 |
cx = grp.getDataAsDouble(10);
|
3522 |
cy = grp.getDataAsDouble(20);
|
3523 |
if (grp.hasCode(30)) { |
3524 |
cz = grp.getDataAsDouble(30);
|
3525 |
} |
3526 |
|
3527 |
// end_point_major_axis (RELATIVE to the center)
|
3528 |
x_end_point_major_axis = grp.getDataAsDouble(11);
|
3529 |
y_end_point_major_axis = grp.getDataAsDouble(21);
|
3530 |
if (grp.hasCode(31)) { |
3531 |
z_end_point_major_axis = grp.getDataAsDouble(31);
|
3532 |
} |
3533 |
|
3534 |
// ratio minor axis to major axis
|
3535 |
if (grp.hasCode(40)) { |
3536 |
ratio_minor_to_major_axis = grp.getDataAsDouble(40);
|
3537 |
} |
3538 |
Point2D c = proj.createPoint(cx, cy);
|
3539 |
// Point2D end_major = proj.createPoint(x_end_point_major_axis, y_end_point_major_axis);
|
3540 |
// double r_major_axis_2D = c.distance(end_major)/2.0;
|
3541 |
double r_major_axis_2D = Math.sqrt(x_end_point_major_axis* |
3542 |
x_end_point_major_axis + |
3543 |
y_end_point_major_axis * y_end_point_major_axis); |
3544 |
double r_minor_axis_2D = r_major_axis_2D * ratio_minor_to_major_axis;
|
3545 |
double rotation_angle = Math.atan2(y_end_point_major_axis , x_end_point_major_axis); |
3546 |
|
3547 |
if (grp.hasCode(210)) { |
3548 |
extx = grp.getDataAsDouble(210);
|
3549 |
} |
3550 |
|
3551 |
if (grp.hasCode(220)) { |
3552 |
exty = grp.getDataAsDouble(220);
|
3553 |
} |
3554 |
|
3555 |
if (grp.hasCode(230)) { |
3556 |
extz = grp.getDataAsDouble(230);
|
3557 |
} |
3558 |
|
3559 |
Point3D point_in = new Point3D(cx, cy, cz);
|
3560 |
Point3D xtru = new Point3D(extx, exty, extz);
|
3561 |
Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
3562 |
cx = point_out.getX(); |
3563 |
cy = point_out.getY(); |
3564 |
cz = point_out.getZ(); |
3565 |
|
3566 |
Double doub = new Double(cz); |
3567 |
feaBordes.setProp("elevation", doub.toString());
|
3568 |
feaFondos.setProp("elevation", doub.toString());
|
3569 |
|
3570 |
if (cz != 0.0) { |
3571 |
dxf3DFile = true;
|
3572 |
} |
3573 |
|
3574 |
|
3575 |
Point3D center = new Point3D(c.getX(), c.getY(), cz);
|
3576 |
Point3D[] pts = new Point3D[360]; |
3577 |
int angulo = 0; |
3578 |
|
3579 |
for (angulo = 0; angulo < 360; angulo++) { |
3580 |
pts[angulo] = new Point3D(center.getX() +
|
3581 |
r_major_axis_2D * Math.cos(Math.toRadians(angulo)), |
3582 |
center.getY() + |
3583 |
r_minor_axis_2D * Math.sin(Math.toRadians(angulo)), |
3584 |
center.getZ()); |
3585 |
|
3586 |
if (pts.length == 1) { |
3587 |
firstPt = pts[angulo]; |
3588 |
} |
3589 |
} |
3590 |
|
3591 |
AffineTransform at = new AffineTransform(); |
3592 |
at.rotate(rotation_angle, cx, cy); |
3593 |
for (int i = 0; i < pts.length; i++) { |
3594 |
Point2D pAux = pts[i];
|
3595 |
Point2D pRot = at.transform(pAux, null); |
3596 |
lineString3D.add(pRot); |
3597 |
polygon3D.add(pRot); |
3598 |
} |
3599 |
|
3600 |
feaBordes.setGeometry(lineString3D); |
3601 |
feaFondos.setGeometry(polygon3D); |
3602 |
|
3603 |
// 041130: Rellena las props con los atributos.
|
3604 |
completeAttributes(feaBordes); |
3605 |
completeAttributes(feaFondos); |
3606 |
|
3607 |
//features.add(feature);
|
3608 |
if (addingToBlock == false) { |
3609 |
//System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
|
3610 |
//features.add(feaBordes);
|
3611 |
features.add(feaFondos); |
3612 |
} else {
|
3613 |
//System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
|
3614 |
//blk.add(feaBordes);
|
3615 |
blk.add(feaFondos); |
3616 |
} |
3617 |
|
3618 |
} |
3619 |
|
3620 |
/**
|
3621 |
* @return Returns the dxf3DFile.
|
3622 |
*/
|
3623 |
public boolean isDxf3DFile() { |
3624 |
return dxf3DFile;
|
3625 |
} |
3626 |
|
3627 |
/**
|
3628 |
* @param dxf3DFile The dxf3DFile to set.
|
3629 |
*/
|
3630 |
public void setDxf3DFile(boolean dxf3DFile) { |
3631 |
this.dxf3DFile = dxf3DFile;
|
3632 |
} |
3633 |
} |