svn-gvsig-desktop / tags / v1_1_Build_1015 / libraries / libCq_CMS_praster / src / org / cresques / px / dxf / DxfFeatureMaker.java @ 13679
History | View | Annotate | Download (129 KB)
1 | 8026 | nacho | /*
|
---|---|---|---|
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 | 12744 | caballero | if (grp.hasCode(30)){ |
760 | z = grp.getDataAsDouble(30);
|
||
761 | } |
||
762 | 8026 | nacho | |
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 | 12744 | caballero | if (grp.hasCode(30)) { |
1354 | z = grp.getDataAsDouble(30);
|
||
1355 | } |
||
1356 | 8026 | nacho | |
1357 | /*if (grp.hasCode(30)){
|
||
1358 | Double doub = new Double(z);
|
||
1359 | String string = doub.toString();
|
||
1360 | feature.setProp("elevation", string);
|
||
1361 | } else {
|
||
1362 | Double doub = new Double(0.0);
|
||
1363 | feature.setProp("elevation", doub.toString());
|
||
1364 | }*/
|
||
1365 | if (grp.hasCode(210)) { |
||
1366 | extx = grp.getDataAsDouble(210);
|
||
1367 | } |
||
1368 | |||
1369 | if (grp.hasCode(220)) { |
||
1370 | exty = grp.getDataAsDouble(220);
|
||
1371 | } |
||
1372 | |||
1373 | if (grp.hasCode(230)) { |
||
1374 | extz = grp.getDataAsDouble(230);
|
||
1375 | } |
||
1376 | |||
1377 | Point3D point_in = new Point3D(x, y, z);
|
||
1378 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
1379 | Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
||
1380 | x = point_out.getX(); |
||
1381 | y = point_out.getY(); |
||
1382 | z = point_out.getZ(); |
||
1383 | |||
1384 | Double doub = new Double(z); |
||
1385 | feature.setProp("elevation", doub.toString());
|
||
1386 | |||
1387 | if (z != 0.0) { |
||
1388 | dxf3DFile = true;
|
||
1389 | } |
||
1390 | |||
1391 | point.add(new Point3D(x, y, z));
|
||
1392 | feature.setGeometry(point); |
||
1393 | |||
1394 | // 041130: Rellena las props con los atributos.
|
||
1395 | completeAttributes(feature); |
||
1396 | |||
1397 | //features.add(feature);
|
||
1398 | if (addingToBlock == false) { |
||
1399 | features.add(feature); |
||
1400 | } else {
|
||
1401 | //System.out.println("createText(): A?adimos un text al bloque " + iterator);
|
||
1402 | blk.add(feature); |
||
1403 | } |
||
1404 | } |
||
1405 | |||
1406 | /* (non-Javadoc)
|
||
1407 | * @see org.cresques.io.DxfFile.EntityFactory#createMText(org.cresques.io.DxfGroupVector)
|
||
1408 | */
|
||
1409 | public void createMText(DxfGroupVector grp) throws Exception { |
||
1410 | double x = 0.0; |
||
1411 | double y = 0.0; |
||
1412 | double z = 0.0; |
||
1413 | double h = 0.0; |
||
1414 | double rot = 0.0; |
||
1415 | DxfGroup g = null;
|
||
1416 | |||
1417 | //Point2D pt1 = null, pt2 = null;
|
||
1418 | Point3D pt = null;
|
||
1419 | org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
|
||
1420 | double extx = 0.0; |
||
1421 | double exty = 0.0; |
||
1422 | double extz = 1.0; |
||
1423 | |||
1424 | point.setTextPoint(true);
|
||
1425 | |||
1426 | Feature feature = new Feature();
|
||
1427 | |||
1428 | feature.setProp("dxfEntity", "Text"); |
||
1429 | |||
1430 | if (grp.hasCode(8)) { |
||
1431 | feature.setProp("layer", grp.getDataAsString(8)); |
||
1432 | } |
||
1433 | |||
1434 | if (grp.hasCode(39)) { |
||
1435 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
1436 | String string = doub.toString();
|
||
1437 | feature.setProp("thickness", string);
|
||
1438 | } else {
|
||
1439 | Double doub = new Double(0.0); |
||
1440 | feature.setProp("thickness", doub.toString());
|
||
1441 | } |
||
1442 | |||
1443 | if (grp.hasCode(62)) { |
||
1444 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
1445 | String string = integer.toString();
|
||
1446 | feature.setProp("color", string);
|
||
1447 | feature.setProp("colorByLayer", "false"); |
||
1448 | } else {
|
||
1449 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
1450 | int clr = layer.colorNumber;
|
||
1451 | Integer integer = new Integer(clr); |
||
1452 | String string = integer.toString();
|
||
1453 | feature.setProp("color", string);
|
||
1454 | feature.setProp("colorByLayer", "true"); |
||
1455 | } |
||
1456 | |||
1457 | if (grp.hasCode(1)) { |
||
1458 | String strAux1 = grp.getDataAsString(1); |
||
1459 | strAux1 = DxfConvTexts.ConvertText(strAux1); |
||
1460 | feature.setProp("text", strAux1);
|
||
1461 | } else {
|
||
1462 | feature.setProp("text", "No Text Code"); |
||
1463 | } |
||
1464 | |||
1465 | if (grp.hasCode(40)) { |
||
1466 | Double heightD = new Double(grp.getDataAsDouble(40)); |
||
1467 | String heightS = heightD.toString();
|
||
1468 | feature.setProp("textHeight", heightS);
|
||
1469 | } else {
|
||
1470 | feature.setProp("textHeight", "20.0"); |
||
1471 | } |
||
1472 | |||
1473 | if (grp.hasCode(50)) { |
||
1474 | Double rotD = new Double(grp.getDataAsDouble(50)); |
||
1475 | String rotS = rotD.toString();
|
||
1476 | feature.setProp("textRotation", rotS);
|
||
1477 | |||
1478 | //System.out.println("rotS = " + rotS);
|
||
1479 | } else {
|
||
1480 | feature.setProp("textRotation", "0.0"); |
||
1481 | } |
||
1482 | |||
1483 | if (grp.hasCode(71)) { |
||
1484 | int attachPoint = grp.getDataAsInt(71); |
||
1485 | |||
1486 | if (attachPoint == 1) { |
||
1487 | } else if (attachPoint == 2) { |
||
1488 | } else if (attachPoint == 3) { |
||
1489 | } else if (attachPoint == 4) { |
||
1490 | } else if (attachPoint == 5) { |
||
1491 | } else if (attachPoint == 6) { |
||
1492 | } else if (attachPoint == 7) { |
||
1493 | } else if (attachPoint == 8) { |
||
1494 | } else if (attachPoint == 9) { |
||
1495 | } |
||
1496 | } |
||
1497 | |||
1498 | if (grp.hasCode(72)) { |
||
1499 | int drawDirection = grp.getDataAsInt(71); |
||
1500 | |||
1501 | if (drawDirection == 1) { |
||
1502 | } else if (drawDirection == 3) { |
||
1503 | } else if (drawDirection == 5) { |
||
1504 | } |
||
1505 | } |
||
1506 | |||
1507 | if (grp.hasCode(73)) { |
||
1508 | int spacingStyle = grp.getDataAsInt(71); |
||
1509 | |||
1510 | if (spacingStyle == 1) { |
||
1511 | } else if (spacingStyle == 2) { |
||
1512 | } |
||
1513 | } |
||
1514 | |||
1515 | x = grp.getDataAsDouble(10);
|
||
1516 | y = grp.getDataAsDouble(20);
|
||
1517 | z = grp.getDataAsDouble(30);
|
||
1518 | |||
1519 | /*if (grp.hasCode(30)){
|
||
1520 | z = grp.getDataAsDouble(30);
|
||
1521 | Double doub = new Double(z);
|
||
1522 | String string = doub.toString();
|
||
1523 | feature.setProp("elevation", string);
|
||
1524 | } else {
|
||
1525 | Double doub = new Double(0.0);
|
||
1526 | feature.setProp("elevation", doub.toString());
|
||
1527 | }*/
|
||
1528 | if (grp.hasCode(210)) { |
||
1529 | extx = grp.getDataAsDouble(210);
|
||
1530 | } |
||
1531 | |||
1532 | if (grp.hasCode(220)) { |
||
1533 | exty = grp.getDataAsDouble(220);
|
||
1534 | } |
||
1535 | |||
1536 | if (grp.hasCode(230)) { |
||
1537 | extz = grp.getDataAsDouble(230);
|
||
1538 | } |
||
1539 | |||
1540 | Point3D point_in = new Point3D(x, y, z);
|
||
1541 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
1542 | Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
||
1543 | x = point_out.getX(); |
||
1544 | y = point_out.getY(); |
||
1545 | z = point_out.getZ(); |
||
1546 | |||
1547 | Double doub = new Double(z); |
||
1548 | feature.setProp("elevation", doub.toString());
|
||
1549 | |||
1550 | if (z != 0.0) { |
||
1551 | dxf3DFile = true;
|
||
1552 | } |
||
1553 | |||
1554 | point.add(new Point3D(x, y, z));
|
||
1555 | feature.setGeometry(point); |
||
1556 | |||
1557 | // 041130: Rellena las props con los atributos.
|
||
1558 | completeAttributes(feature); |
||
1559 | |||
1560 | //features.add(feature);
|
||
1561 | if (addingToBlock == false) { |
||
1562 | features.add(feature); |
||
1563 | } else {
|
||
1564 | //System.out.println("createText(): A?adimos un text al bloque " + iterator);
|
||
1565 | blk.add(feature); |
||
1566 | } |
||
1567 | } |
||
1568 | |||
1569 | /* (non-Javadoc)
|
||
1570 | * @see org.cresques.io.DxfFile.EntityFactory#createPoint(org.cresques.io.DxfGroupVector)
|
||
1571 | */
|
||
1572 | public void createPoint(DxfGroupVector grp) throws Exception { |
||
1573 | double x = 0.0; |
||
1574 | double y = 0.0; |
||
1575 | double z = 0.0; |
||
1576 | DxfGroup g = null;
|
||
1577 | Point3D pt = null;
|
||
1578 | double extx = 0.0; |
||
1579 | double exty = 0.0; |
||
1580 | double extz = 1.0; |
||
1581 | org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
|
||
1582 | Feature feature = new Feature();
|
||
1583 | |||
1584 | feature.setProp("dxfEntity", "Point"); |
||
1585 | |||
1586 | if (grp.hasCode(8)) { |
||
1587 | feature.setProp("layer", grp.getDataAsString(8)); |
||
1588 | } |
||
1589 | |||
1590 | if (grp.hasCode(39)) { |
||
1591 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
1592 | String string = doub.toString();
|
||
1593 | feature.setProp("thickness", string);
|
||
1594 | } else {
|
||
1595 | Double doub = new Double(0.0); |
||
1596 | feature.setProp("thickness", doub.toString());
|
||
1597 | } |
||
1598 | |||
1599 | if (grp.hasCode(62)) { |
||
1600 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
1601 | String string = integer.toString();
|
||
1602 | feature.setProp("color", string);
|
||
1603 | feature.setProp("colorByLayer", "false"); |
||
1604 | } else {
|
||
1605 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
1606 | int clr = layer.colorNumber;
|
||
1607 | Integer integer = new Integer(clr); |
||
1608 | String string = integer.toString();
|
||
1609 | feature.setProp("color", string);
|
||
1610 | feature.setProp("colorByLayer", "true"); |
||
1611 | } |
||
1612 | |||
1613 | x = grp.getDataAsDouble(10);
|
||
1614 | y = grp.getDataAsDouble(20);
|
||
1615 | z = grp.getDataAsDouble(30);
|
||
1616 | |||
1617 | /*if (grp.hasCode(30)) {
|
||
1618 | z = grp.getDataAsDouble(30);
|
||
1619 | Double doub = new Double(z);
|
||
1620 | String string = doub.toString();
|
||
1621 | feature.setProp("elevation", string);
|
||
1622 | } else {
|
||
1623 | Double doub = new Double(0.0);
|
||
1624 | feature.setProp("elevation", doub.toString());
|
||
1625 | }*/
|
||
1626 | if (grp.hasCode(210)) { |
||
1627 | extx = grp.getDataAsDouble(210);
|
||
1628 | } |
||
1629 | |||
1630 | if (grp.hasCode(220)) { |
||
1631 | exty = grp.getDataAsDouble(220);
|
||
1632 | } |
||
1633 | |||
1634 | if (grp.hasCode(230)) { |
||
1635 | extz = grp.getDataAsDouble(230);
|
||
1636 | } |
||
1637 | |||
1638 | Point3D point_in = new Point3D(x, y, z);
|
||
1639 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
1640 | Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
||
1641 | x = point_out.getX(); |
||
1642 | y = point_out.getY(); |
||
1643 | z = point_out.getZ(); |
||
1644 | |||
1645 | Double doub = new Double(z); |
||
1646 | feature.setProp("elevation", doub.toString());
|
||
1647 | |||
1648 | if (z != 0.0) { |
||
1649 | dxf3DFile = true;
|
||
1650 | } |
||
1651 | |||
1652 | point.add(new Point3D(x, y, z));
|
||
1653 | feature.setGeometry(point); |
||
1654 | |||
1655 | // 041130: Rellena las props con los atributos.
|
||
1656 | completeAttributes(feature); |
||
1657 | |||
1658 | /*for (int i=0;i<attributes.size();i++) {
|
||
1659 | String[] att = new String[2];
|
||
1660 | att = (String[])attributes.get(i);
|
||
1661 | feature.setProp(att[0],att[1]);
|
||
1662 | }*/
|
||
1663 | |||
1664 | //features.add(feature);
|
||
1665 | if (addingToBlock == false) { |
||
1666 | features.add(feature); |
||
1667 | } else {
|
||
1668 | //System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
|
||
1669 | blk.add(feature); |
||
1670 | } |
||
1671 | } |
||
1672 | |||
1673 | /* (non-Javadoc)
|
||
1674 | * @see org.cresques.io.DxfFile.EntityFactory#createCircle(org.cresques.io.DxfGroupVector)
|
||
1675 | */
|
||
1676 | public void createCircle(DxfGroupVector grp) throws Exception { |
||
1677 | double x = 0.0; |
||
1678 | double y = 0.0; |
||
1679 | double z = 0.0; |
||
1680 | double r = 0.0; |
||
1681 | Point3D firstPt = new Point3D();
|
||
1682 | DxfGroup g = null;
|
||
1683 | double extx = 0.0; |
||
1684 | double exty = 0.0; |
||
1685 | double extz = 1.0; |
||
1686 | LineString3D lineString3D = new LineString3D();
|
||
1687 | Polygon3D polygon3D = new Polygon3D();
|
||
1688 | Feature feaBordes = new Feature();
|
||
1689 | Feature feaFondos = new Feature();
|
||
1690 | |||
1691 | feaBordes.setProp("dxfEntity", "Circle"); |
||
1692 | feaFondos.setProp("dxfEntity", "Circle"); |
||
1693 | |||
1694 | if (grp.hasCode(8)) { |
||
1695 | feaBordes.setProp("layer", grp.getDataAsString(8)); |
||
1696 | } |
||
1697 | |||
1698 | feaFondos.setProp("layer", grp.getDataAsString(8)); |
||
1699 | |||
1700 | if (grp.hasCode(39)) { |
||
1701 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
1702 | String string = doub.toString();
|
||
1703 | feaBordes.setProp("thickness", string);
|
||
1704 | feaFondos.setProp("thickness", string);
|
||
1705 | } else {
|
||
1706 | Double doub = new Double(0.0); |
||
1707 | feaBordes.setProp("thickness", doub.toString());
|
||
1708 | feaFondos.setProp("thickness", doub.toString());
|
||
1709 | } |
||
1710 | |||
1711 | if (grp.hasCode(62)) { |
||
1712 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
1713 | String string = integer.toString();
|
||
1714 | feaBordes.setProp("color", string);
|
||
1715 | feaFondos.setProp("color", string);
|
||
1716 | feaBordes.setProp("colorByLayer", "false"); |
||
1717 | feaFondos.setProp("colorByLayer", "false"); |
||
1718 | } else {
|
||
1719 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
1720 | int clr = layer.colorNumber;
|
||
1721 | Integer integer = new Integer(clr); |
||
1722 | String string = integer.toString();
|
||
1723 | feaBordes.setProp("color", string);
|
||
1724 | feaFondos.setProp("color", string);
|
||
1725 | feaBordes.setProp("colorByLayer", "true"); |
||
1726 | feaFondos.setProp("colorByLayer", "true"); |
||
1727 | } |
||
1728 | |||
1729 | x = grp.getDataAsDouble(10);
|
||
1730 | y = grp.getDataAsDouble(20);
|
||
1731 | if (grp.hasCode(30)) { |
||
1732 | z = grp.getDataAsDouble(30);
|
||
1733 | } |
||
1734 | |||
1735 | |||
1736 | /*if (grp.hasCode(30)) {
|
||
1737 | z = grp.getDataAsDouble(30);
|
||
1738 | Double doub = new Double(z);
|
||
1739 | String string = doub.toString();
|
||
1740 | feaBordes.setProp("elevation", string);
|
||
1741 | feaFondos.setProp("elevation", string);
|
||
1742 | } else {
|
||
1743 | Double doub = new Double(0.0);
|
||
1744 | feaBordes.setProp("elevation", doub.toString());
|
||
1745 | feaFondos.setProp("elevation", doub.toString());
|
||
1746 | }*/
|
||
1747 | if (grp.hasCode(40)) { |
||
1748 | r = grp.getDataAsDouble(40);
|
||
1749 | } |
||
1750 | |||
1751 | if (grp.hasCode(210)) { |
||
1752 | extx = grp.getDataAsDouble(210);
|
||
1753 | } |
||
1754 | |||
1755 | if (grp.hasCode(220)) { |
||
1756 | exty = grp.getDataAsDouble(220);
|
||
1757 | } |
||
1758 | |||
1759 | if (grp.hasCode(230)) { |
||
1760 | extz = grp.getDataAsDouble(230);
|
||
1761 | } |
||
1762 | |||
1763 | Point3D point_in = new Point3D(x, y, z);
|
||
1764 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
1765 | Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
||
1766 | x = point_out.getX(); |
||
1767 | y = point_out.getY(); |
||
1768 | z = point_out.getZ(); |
||
1769 | |||
1770 | Double doub = new Double(z); |
||
1771 | feaBordes.setProp("elevation", doub.toString());
|
||
1772 | feaFondos.setProp("elevation", doub.toString());
|
||
1773 | |||
1774 | if (z != 0.0) { |
||
1775 | dxf3DFile = true;
|
||
1776 | } |
||
1777 | |||
1778 | Point2D c = proj.createPoint(x, y);
|
||
1779 | Point3D center = new Point3D(c.getX(), c.getY(), z);
|
||
1780 | Point3D[] pts = new Point3D[360]; |
||
1781 | int angulo = 0; |
||
1782 | |||
1783 | for (angulo = 0; angulo < 360; angulo++) { |
||
1784 | pts[angulo] = new Point3D(center.getX(), center.getY(),
|
||
1785 | center.getZ()); |
||
1786 | pts[angulo] = new Point3D(pts[angulo].getX() +
|
||
1787 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1788 | pts[angulo].getY() + |
||
1789 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1790 | center.getZ()); |
||
1791 | |||
1792 | if (pts.length == 1) { |
||
1793 | firstPt = pts[angulo]; |
||
1794 | } |
||
1795 | } |
||
1796 | |||
1797 | for (int i = 0; i < pts.length; i++) { |
||
1798 | lineString3D.add(pts[i]); |
||
1799 | polygon3D.add(pts[i]); |
||
1800 | } |
||
1801 | |||
1802 | feaBordes.setGeometry(lineString3D); |
||
1803 | feaFondos.setGeometry(polygon3D); |
||
1804 | |||
1805 | // 041130: Rellena las props con los atributos.
|
||
1806 | completeAttributes(feaBordes); |
||
1807 | completeAttributes(feaFondos); |
||
1808 | |||
1809 | //features.add(feature);
|
||
1810 | if (addingToBlock == false) { |
||
1811 | //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
|
||
1812 | //features.add(feaBordes);
|
||
1813 | features.add(feaFondos); |
||
1814 | } else {
|
||
1815 | //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
|
||
1816 | //blk.add(feaBordes);
|
||
1817 | blk.add(feaFondos); |
||
1818 | } |
||
1819 | } |
||
1820 | |||
1821 | /* (non-Javadoc)
|
||
1822 | * @see org.cresques.io.DxfFile.EntityFactory#createArc(org.cresques.io.DxfGroupVector)
|
||
1823 | */
|
||
1824 | public void createArc(DxfGroupVector grp) throws Exception { |
||
1825 | double x = 0.0; |
||
1826 | double y = 0.0; |
||
1827 | double z = 0.0; |
||
1828 | double r = 0.0; |
||
1829 | double empieza = 0.0; |
||
1830 | double acaba = 0.0; |
||
1831 | DxfGroup g = null;
|
||
1832 | double extx = 0.0; |
||
1833 | double exty = 0.0; |
||
1834 | double extz = 1.0; |
||
1835 | LineString3D lineString3D = new LineString3D();
|
||
1836 | Feature feature = new Feature();
|
||
1837 | |||
1838 | feature.setProp("dxfEntity", "Arc"); |
||
1839 | |||
1840 | if (grp.hasCode(8)) { |
||
1841 | feature.setProp("layer", grp.getDataAsString(8)); |
||
1842 | } |
||
1843 | |||
1844 | if (grp.hasCode(39)) { |
||
1845 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
1846 | String string = doub.toString();
|
||
1847 | feature.setProp("thickness", string);
|
||
1848 | } else {
|
||
1849 | Double doub = new Double(0.0); |
||
1850 | feature.setProp("thickness", doub.toString());
|
||
1851 | } |
||
1852 | |||
1853 | if (grp.hasCode(62)) { |
||
1854 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
1855 | String string = integer.toString();
|
||
1856 | feature.setProp("color", string);
|
||
1857 | feature.setProp("colorByLayer", "false"); |
||
1858 | } else {
|
||
1859 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
1860 | int clr = layer.colorNumber;
|
||
1861 | Integer integer = new Integer(clr); |
||
1862 | String string = integer.toString();
|
||
1863 | feature.setProp("color", string);
|
||
1864 | feature.setProp("colorByLayer", "true"); |
||
1865 | } |
||
1866 | |||
1867 | x = grp.getDataAsDouble(10);
|
||
1868 | y = grp.getDataAsDouble(20);
|
||
1869 | if (grp.hasCode(30)) |
||
1870 | { |
||
1871 | z = grp.getDataAsDouble(30);
|
||
1872 | } |
||
1873 | |||
1874 | /*if (grp.hasCode(30)) {
|
||
1875 | z = grp.getDataAsDouble(30);
|
||
1876 | Double doub = new Double(z);
|
||
1877 | String string = doub.toString();
|
||
1878 | feature.setProp("elevation", string);
|
||
1879 | } else {
|
||
1880 | Double doub = new Double(0.0);
|
||
1881 | feature.setProp("elevation", doub.toString());
|
||
1882 | }*/
|
||
1883 | if (grp.hasCode(40)) { |
||
1884 | r = grp.getDataAsDouble(40);
|
||
1885 | } |
||
1886 | |||
1887 | if (grp.hasCode(50)) { |
||
1888 | empieza = grp.getDataAsDouble(50);
|
||
1889 | } |
||
1890 | |||
1891 | if (grp.hasCode(51)) { |
||
1892 | acaba = grp.getDataAsDouble(51);
|
||
1893 | } |
||
1894 | |||
1895 | if (grp.hasCode(210)) { |
||
1896 | extx = grp.getDataAsDouble(210);
|
||
1897 | } |
||
1898 | |||
1899 | if (grp.hasCode(220)) { |
||
1900 | exty = grp.getDataAsDouble(220);
|
||
1901 | } |
||
1902 | |||
1903 | if (grp.hasCode(230)) { |
||
1904 | extz = grp.getDataAsDouble(230);
|
||
1905 | } |
||
1906 | |||
1907 | Point3D point_in = new Point3D(x, y, z);
|
||
1908 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
1909 | Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
||
1910 | x = point_out.getX(); |
||
1911 | y = point_out.getY(); |
||
1912 | z = point_out.getZ(); |
||
1913 | |||
1914 | Double doub = new Double(z); |
||
1915 | feature.setProp("elevation", doub.toString());
|
||
1916 | |||
1917 | if (z != 0.0) { |
||
1918 | dxf3DFile = true;
|
||
1919 | } |
||
1920 | |||
1921 | Point2D c = proj.createPoint(x, y);
|
||
1922 | Point3D center = new Point3D(c.getX(), c.getY(), z);
|
||
1923 | |||
1924 | //System.out.println("empieza = " + empieza + ", acaba = " + acaba);
|
||
1925 | int iempieza = (int) empieza; |
||
1926 | int iacaba = (int) acaba; |
||
1927 | |||
1928 | //System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
|
||
1929 | double angulo = 0; |
||
1930 | Point3D[] pts = null; |
||
1931 | |||
1932 | if (empieza <= acaba) {
|
||
1933 | pts = new Point3D[(iacaba - iempieza) + 2]; |
||
1934 | angulo = empieza; |
||
1935 | pts[0] = new Point3D(center.getX() + |
||
1936 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1937 | center.getY() + |
||
1938 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1939 | center.getZ()); |
||
1940 | |||
1941 | for (int i = 1; i <= ((iacaba - iempieza) + 1); i++) { |
||
1942 | angulo = (double) (iempieza + i);
|
||
1943 | pts[i] = new Point3D(center.getX() +
|
||
1944 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1945 | center.getY() + |
||
1946 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1947 | center.getZ()); |
||
1948 | } |
||
1949 | |||
1950 | angulo = acaba; |
||
1951 | pts[(iacaba - iempieza) + 1] = new Point3D(center.getX() + |
||
1952 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1953 | center.getY() + |
||
1954 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1955 | center.getZ()); |
||
1956 | } else {
|
||
1957 | pts = new Point3D[(360 - iempieza) + iacaba + 2]; |
||
1958 | angulo = empieza; |
||
1959 | |||
1960 | //System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
|
||
1961 | pts[0] = new Point3D(center.getX() + |
||
1962 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1963 | center.getY() + |
||
1964 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1965 | center.getZ()); |
||
1966 | |||
1967 | for (int i = 1; i <= (360 - iempieza); i++) { |
||
1968 | angulo = (double) (iempieza + i);
|
||
1969 | pts[i] = new Point3D(center.getX() +
|
||
1970 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1971 | center.getY() + |
||
1972 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1973 | center.getZ()); |
||
1974 | } |
||
1975 | |||
1976 | for (int i = (360 - iempieza) + 1; |
||
1977 | i <= ((360 - iempieza) + iacaba); i++) {
|
||
1978 | angulo = (double) (i - (360 - iempieza)); |
||
1979 | pts[i] = new Point3D(center.getX() +
|
||
1980 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1981 | center.getY() + |
||
1982 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1983 | center.getZ()); |
||
1984 | } |
||
1985 | |||
1986 | angulo = acaba; |
||
1987 | pts[(360 - iempieza) + iacaba + 1] = new Point3D(center.getX() + |
||
1988 | (r * Math.cos((angulo * Math.PI) / (double) 180.0)), |
||
1989 | center.getY() + |
||
1990 | (r * Math.sin((angulo * Math.PI) / (double) 180.0)), |
||
1991 | center.getZ()); |
||
1992 | } |
||
1993 | |||
1994 | for (int i = 0; i < pts.length; i++) { |
||
1995 | lineString3D.add(pts[i]); |
||
1996 | } |
||
1997 | |||
1998 | feature.setGeometry(lineString3D); |
||
1999 | |||
2000 | // 041130: Rellena las props con los atributos.
|
||
2001 | completeAttributes(feature); |
||
2002 | |||
2003 | //features.add(feature);
|
||
2004 | if (addingToBlock == false) { |
||
2005 | features.add(feature); |
||
2006 | } else {
|
||
2007 | //System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
|
||
2008 | blk.add(feature); |
||
2009 | } |
||
2010 | } |
||
2011 | |||
2012 | /* (non-Javadoc)
|
||
2013 | * @see org.cresques.io.DxfFile.EntityFactory#createInsert(org.cresques.io.DxfGroupVector)
|
||
2014 | */
|
||
2015 | public void createInsert(DxfGroupVector grp) throws Exception { |
||
2016 | double x = 0.0; |
||
2017 | double y = 0.0; |
||
2018 | double z = 0.0; |
||
2019 | DxfGroup g = null;
|
||
2020 | Point3D pt = new Point3D(0.0, 0.0, 0.0); |
||
2021 | Point3D scaleFactor = new Point3D(1.0, 1.0, 1.0); |
||
2022 | double rotAngle = 0.0; |
||
2023 | String blockName = ""; |
||
2024 | double extx = 0.0; |
||
2025 | double exty = 0.0; |
||
2026 | double extz = 1.0; |
||
2027 | |||
2028 | InsPoint3D insert = new InsPoint3D();
|
||
2029 | Feature feature = new Feature();
|
||
2030 | org.cresques.px.gml.Point3D secondGeom = new org.cresques.px.gml.Point3D();
|
||
2031 | Feature secondFeat = new Feature();
|
||
2032 | int attributesFollowFlag = 0; |
||
2033 | |||
2034 | feature.setProp("dxfEntity", "Insert"); |
||
2035 | secondFeat.setProp("dxfEntity", "Insert"); |
||
2036 | |||
2037 | if (grp.hasCode(2)) { |
||
2038 | blockName = grp.getDataAsString(2);
|
||
2039 | |||
2040 | //feature.setProp("blockName", blockName);
|
||
2041 | insert.setBlockName(blockName); |
||
2042 | } |
||
2043 | |||
2044 | if (grp.hasCode(8)) { |
||
2045 | feature.setProp("layer", grp.getDataAsString(8)); |
||
2046 | secondFeat.setProp("layer", grp.getDataAsString(8)); |
||
2047 | } |
||
2048 | |||
2049 | Double doub = new Double(0.0); |
||
2050 | secondFeat.setProp("thickness", doub.toString());
|
||
2051 | |||
2052 | if (grp.hasCode(62)) { |
||
2053 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
2054 | String string = integer.toString();
|
||
2055 | feature.setProp("color", string);
|
||
2056 | secondFeat.setProp("color", string);
|
||
2057 | feature.setProp("colorByLayer", "false"); |
||
2058 | secondFeat.setProp("colorByLayer", "false"); |
||
2059 | } else {
|
||
2060 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2061 | int clr = layer.colorNumber;
|
||
2062 | Integer integer = new Integer(clr); |
||
2063 | String string = integer.toString();
|
||
2064 | feature.setProp("color", string);
|
||
2065 | secondFeat.setProp("color", string);
|
||
2066 | feature.setProp("colorByLayer", "true"); |
||
2067 | secondFeat.setProp("colorByLayer", "true"); |
||
2068 | } |
||
2069 | |||
2070 | if (grp.hasCode(66)) { |
||
2071 | attributesFollowFlag = grp.getDataAsInt(66);
|
||
2072 | } |
||
2073 | |||
2074 | x = grp.getDataAsDouble(10);
|
||
2075 | y = grp.getDataAsDouble(20);
|
||
2076 | z = grp.getDataAsDouble(30);
|
||
2077 | |||
2078 | /*if (grp.hasCode(30)) {
|
||
2079 | z = grp.getDataAsDouble(30);
|
||
2080 | Double doubz = new Double(z);
|
||
2081 | String string = doubz.toString();
|
||
2082 | feature.setProp("elevation", string);
|
||
2083 | secondFeat.setProp("elevation", string);
|
||
2084 | } else {
|
||
2085 | Double elev = new Double(z);
|
||
2086 | //feature.setProp("elevation", doub.toString());
|
||
2087 | feature.setProp("elevation", elev.toString());
|
||
2088 | secondFeat.setProp("elevation", elev.toString());
|
||
2089 | }*/
|
||
2090 | if (grp.hasCode(41)) { |
||
2091 | scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
|
||
2092 | insert.setScaleFactor(scaleFactor); |
||
2093 | } else {
|
||
2094 | insert.setScaleFactor(scaleFactor); |
||
2095 | } |
||
2096 | |||
2097 | if (grp.hasCode(42)) { |
||
2098 | scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
|
||
2099 | insert.setScaleFactor(scaleFactor); |
||
2100 | } else {
|
||
2101 | insert.setScaleFactor(scaleFactor); |
||
2102 | } |
||
2103 | |||
2104 | if (grp.hasCode(43)) { |
||
2105 | scaleFactor = new Point3D(scaleFactor.getX(), scaleFactor.getY(),
|
||
2106 | grp.getDataAsDouble(43));
|
||
2107 | insert.setScaleFactor(scaleFactor); |
||
2108 | } else {
|
||
2109 | insert.setScaleFactor(scaleFactor); |
||
2110 | } |
||
2111 | |||
2112 | if (grp.hasCode(50)) { |
||
2113 | rotAngle = grp.getDataAsDouble(50);
|
||
2114 | insert.setRotAngle(rotAngle); |
||
2115 | } |
||
2116 | |||
2117 | if (grp.hasCode(210)) { |
||
2118 | extx = grp.getDataAsDouble(210);
|
||
2119 | } |
||
2120 | |||
2121 | if (grp.hasCode(220)) { |
||
2122 | exty = grp.getDataAsDouble(220);
|
||
2123 | } |
||
2124 | |||
2125 | if (grp.hasCode(230)) { |
||
2126 | extz = grp.getDataAsDouble(230);
|
||
2127 | } |
||
2128 | |||
2129 | Point3D point_in = new Point3D(x, y, z);
|
||
2130 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
2131 | Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
||
2132 | x = point_out.getX(); |
||
2133 | y = point_out.getY(); |
||
2134 | z = point_out.getZ(); |
||
2135 | |||
2136 | Double doubz = new Double(z); |
||
2137 | feature.setProp("elevation", doubz.toString());
|
||
2138 | secondFeat.setProp("elevation", doubz.toString());
|
||
2139 | |||
2140 | if (z != 0.0) { |
||
2141 | dxf3DFile = true;
|
||
2142 | } |
||
2143 | |||
2144 | insert.setBlkList(blkList); |
||
2145 | |||
2146 | insert.encuentraBloque(blockName); |
||
2147 | |||
2148 | insert.add(new Point3D(x, y, z));
|
||
2149 | secondGeom.add(new Point3D(x, y, z));
|
||
2150 | |||
2151 | feature.setGeometry(insert); |
||
2152 | secondFeat.setGeometry(secondGeom); |
||
2153 | |||
2154 | // 041130: Rellena las props con los atributos.
|
||
2155 | completeAttributes(feature); |
||
2156 | completeAttributes(secondFeat); |
||
2157 | |||
2158 | /*for (int i=0;i<attributes.size();i++) {
|
||
2159 | String[] att = new String[2];
|
||
2160 | att = (String[])attributes.get(i);
|
||
2161 | secondFeat.setProp(att[0],att[1]);
|
||
2162 | }*/
|
||
2163 | if ((insert.getBlockFound() == true) && (attributesFollowFlag != 1)) { |
||
2164 | gestionaInsert(feature); |
||
2165 | } |
||
2166 | |||
2167 | //if (addingToBlock == false) {
|
||
2168 | //features.add(secondFeat);
|
||
2169 | //}
|
||
2170 | //if (addingToBlock == true/* && insert.getBlockFound() == true*/) {
|
||
2171 | //System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
|
||
2172 | //blk.add(feature);
|
||
2173 | //}
|
||
2174 | // 041129: A?adido para implementar los ATTRIBS.
|
||
2175 | if (attributesFollowFlag == 1) { |
||
2176 | isDoubleFeatured = true;
|
||
2177 | lastFeaBordes = feature; |
||
2178 | lastFeaFondos = secondFeat; |
||
2179 | } else {
|
||
2180 | if (addingToBlock == false) { |
||
2181 | features.add(secondFeat); |
||
2182 | } |
||
2183 | |||
2184 | if (addingToBlock == true /* && insert.getBlockFound() == true*/) { |
||
2185 | //System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
|
||
2186 | blk.add(feature); |
||
2187 | } |
||
2188 | } |
||
2189 | } |
||
2190 | |||
2191 | /* (non-Javadoc)
|
||
2192 | * @see org.cresques.io.DxfFile.EntityFactory#createSolid(org.cresques.io.DxfGroupVector)
|
||
2193 | */
|
||
2194 | public void createSolid(DxfGroupVector grp) throws Exception { |
||
2195 | double x = 0.0; |
||
2196 | double y = 0.0; |
||
2197 | double z1 = 0.0; |
||
2198 | double z2 = 0.0; |
||
2199 | double z3 = 0.0; |
||
2200 | double z4 = 0.0; |
||
2201 | DxfGroup g = null;
|
||
2202 | |||
2203 | //Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
|
||
2204 | Point3D[] pts = new Point3D[4]; |
||
2205 | |||
2206 | //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2207 | double extx = 0.0; |
||
2208 | double exty = 0.0; |
||
2209 | double extz = 1.0; |
||
2210 | |||
2211 | LineString3D lineString3D = new LineString3D();
|
||
2212 | Polygon3D polygon3D = new Polygon3D();
|
||
2213 | Feature feaBordes = new Feature();
|
||
2214 | Feature feaFondos = new Feature();
|
||
2215 | |||
2216 | //double elev = 0;
|
||
2217 | feaBordes.setProp("dxfEntity", "Solid"); |
||
2218 | feaFondos.setProp("dxfEntity", "Solid"); |
||
2219 | |||
2220 | if (grp.hasCode(8)) { |
||
2221 | feaBordes.setProp("layer", grp.getDataAsString(8)); |
||
2222 | } |
||
2223 | |||
2224 | feaFondos.setProp("layer", grp.getDataAsString(8)); |
||
2225 | x = grp.getDataAsDouble(10);
|
||
2226 | y = grp.getDataAsDouble(20);
|
||
2227 | z1 = grp.getDataAsDouble(30);
|
||
2228 | |||
2229 | /*if (grp.hasCode(30)) {
|
||
2230 | z1 = grp.getDataAsDouble(30);
|
||
2231 | } else {
|
||
2232 | Double doub = new Double(0.0);
|
||
2233 | feaBordes.setProp("elevation", doub.toString());
|
||
2234 | feaFondos.setProp("elevation", doub.toString());
|
||
2235 | }*/
|
||
2236 | Point2D pto = proj.createPoint(x, y);
|
||
2237 | Point3D pto3D = new Point3D(pto.getX(), pto.getY(), z1);
|
||
2238 | pts[0] = pto3D;
|
||
2239 | x = grp.getDataAsDouble(11);
|
||
2240 | y = grp.getDataAsDouble(21);
|
||
2241 | z2 = grp.getDataAsDouble(31);
|
||
2242 | pto = proj.createPoint(x, y); |
||
2243 | pto3D = new Point3D(pto.getX(), pto.getY(), z2);
|
||
2244 | pts[1] = pto3D;
|
||
2245 | x = grp.getDataAsDouble(12);
|
||
2246 | y = grp.getDataAsDouble(22);
|
||
2247 | z3 = grp.getDataAsDouble(32);
|
||
2248 | pto = proj.createPoint(x, y); |
||
2249 | pto3D = new Point3D(pto.getX(), pto.getY(), z3);
|
||
2250 | pts[2] = pto3D;
|
||
2251 | |||
2252 | if (grp.hasCode(13)) { |
||
2253 | x = grp.getDataAsDouble(13);
|
||
2254 | } |
||
2255 | |||
2256 | if (grp.hasCode(23)) { |
||
2257 | y = grp.getDataAsDouble(23);
|
||
2258 | } |
||
2259 | |||
2260 | if (grp.hasCode(33)) { |
||
2261 | z4 = grp.getDataAsDouble(33);
|
||
2262 | } |
||
2263 | |||
2264 | pto = proj.createPoint(x, y); |
||
2265 | pto3D = new Point3D(pto.getX(), pto.getY(), z4);
|
||
2266 | pts[3] = pto3D;
|
||
2267 | |||
2268 | if (grp.hasCode(39)) { |
||
2269 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
2270 | String string = doub.toString();
|
||
2271 | feaBordes.setProp("thickness", string);
|
||
2272 | feaFondos.setProp("thickness", string);
|
||
2273 | } else {
|
||
2274 | Double doub = new Double(0.0); |
||
2275 | feaBordes.setProp("thickness", doub.toString());
|
||
2276 | feaFondos.setProp("thickness", doub.toString());
|
||
2277 | } |
||
2278 | |||
2279 | if (grp.hasCode(62)) { |
||
2280 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
2281 | String string = integer.toString();
|
||
2282 | feaBordes.setProp("color", string);
|
||
2283 | feaFondos.setProp("color", string);
|
||
2284 | feaBordes.setProp("colorByLayer", "false"); |
||
2285 | feaFondos.setProp("colorByLayer", "false"); |
||
2286 | } else {
|
||
2287 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2288 | int clr = layer.colorNumber;
|
||
2289 | Integer integer = new Integer(clr); |
||
2290 | String string = integer.toString();
|
||
2291 | feaBordes.setProp("color", string);
|
||
2292 | feaFondos.setProp("color", string);
|
||
2293 | feaBordes.setProp("colorByLayer", "true"); |
||
2294 | feaFondos.setProp("colorByLayer", "true"); |
||
2295 | } |
||
2296 | |||
2297 | if (grp.hasCode(210)) { |
||
2298 | extx = grp.getDataAsDouble(210);
|
||
2299 | } |
||
2300 | |||
2301 | if (grp.hasCode(220)) { |
||
2302 | exty = grp.getDataAsDouble(220);
|
||
2303 | } |
||
2304 | |||
2305 | if (grp.hasCode(230)) { |
||
2306 | extz = grp.getDataAsDouble(230);
|
||
2307 | } |
||
2308 | |||
2309 | Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1); |
||
2310 | Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2); |
||
2311 | Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3); |
||
2312 | Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4); |
||
2313 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
2314 | Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru); |
||
2315 | Point3D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru); |
||
2316 | Point3D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru); |
||
2317 | Point3D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru); |
||
2318 | pts[0] = new Point3D(point_out1); |
||
2319 | pts[1] = new Point3D(point_out2); |
||
2320 | pts[2] = new Point3D(point_out3); |
||
2321 | pts[3] = new Point3D(point_out4); |
||
2322 | |||
2323 | if ((pts[0].getZ() != 0.0) || (pts[1].getZ() != 0.0) || |
||
2324 | (pts[2].getZ() != 0.0) || (pts[3].getZ() != 0.0)) { |
||
2325 | dxf3DFile = true;
|
||
2326 | } |
||
2327 | |||
2328 | Point3D aux = new Point3D(pts[2]); |
||
2329 | pts[2] = new Point3D(pts[3]); |
||
2330 | pts[3] = aux;
|
||
2331 | |||
2332 | Double doub = new Double(0.0); |
||
2333 | if ((pts[0].getZ() == pts[1].getZ()) && |
||
2334 | (pts[1].getZ() == pts[2].getZ()) && |
||
2335 | (pts[2].getZ() == pts[3].getZ())) { |
||
2336 | doub = new Double(pts[0].getZ()); |
||
2337 | } |
||
2338 | String string = doub.toString();
|
||
2339 | feaBordes.setProp("elevation", string);
|
||
2340 | feaFondos.setProp("elevation", string);
|
||
2341 | |||
2342 | for (int i = 0; i < pts.length; i++) { |
||
2343 | lineString3D.add(pts[i]); |
||
2344 | polygon3D.add(pts[i]); |
||
2345 | } |
||
2346 | |||
2347 | // Para cerrarlos.
|
||
2348 | lineString3D.add(pts[0]);
|
||
2349 | polygon3D.add(pts[0]);
|
||
2350 | |||
2351 | feaBordes.setGeometry(lineString3D); |
||
2352 | feaFondos.setGeometry(polygon3D); |
||
2353 | |||
2354 | // 041130: Rellena las props con los atributos.
|
||
2355 | completeAttributes(feaBordes); |
||
2356 | completeAttributes(feaFondos); |
||
2357 | |||
2358 | //features.add(feature);
|
||
2359 | if (addingToBlock == false) { |
||
2360 | //System.out.println("createSolid(): A?ade un solid a la lista de entidades");
|
||
2361 | //features.add(feaBordes);
|
||
2362 | features.add(feaFondos); |
||
2363 | } else {
|
||
2364 | //System.out.println("createSolid(): A?adimos un circulo al bloque " + iterator);
|
||
2365 | //blk.add(feaBordes);
|
||
2366 | blk.add(feaFondos); |
||
2367 | } |
||
2368 | } |
||
2369 | |||
2370 | /* (non-Javadoc)
|
||
2371 | * @see org.cresques.io.DxfFile.EntityFactory#createSpline(org.cresques.io.DxfGroupVector)
|
||
2372 | */
|
||
2373 | public void createSpline(DxfGroupVector grp) throws Exception { |
||
2374 | double x = 0.0; //elev = 0.0; |
||
2375 | double y = 0.0; //elev = 0.0; |
||
2376 | double z = 0.0; //elev = 0.0; |
||
2377 | |||
2378 | //double elev = 0.0;
|
||
2379 | DxfGroup g = null;
|
||
2380 | LineString3D lineString3D = new LineString3D();
|
||
2381 | Polygon3D polygon3D = new Polygon3D();
|
||
2382 | |||
2383 | //Geometry geometria;
|
||
2384 | //Feature feature= new Feature();
|
||
2385 | Feature feaBordes = new Feature();
|
||
2386 | Feature feaFondos = new Feature();
|
||
2387 | int flags = 0; |
||
2388 | |||
2389 | //feature.setProp("dxfEntity", "LwPolyline");
|
||
2390 | feaBordes.setProp("dxfEntity", "Spline"); |
||
2391 | feaFondos.setProp("dxfEntity", "Spline"); |
||
2392 | |||
2393 | if (grp.hasCode(8)) { |
||
2394 | //feature.setProp("layer", grp.getDataAsString(8));
|
||
2395 | feaBordes.setProp("layer", grp.getDataAsString(8)); |
||
2396 | feaFondos.setProp("layer", grp.getDataAsString(8)); |
||
2397 | } |
||
2398 | |||
2399 | if (grp.hasCode(39)) { |
||
2400 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
2401 | String string = doub.toString();
|
||
2402 | |||
2403 | //feature.setProp("thickness", string);
|
||
2404 | feaBordes.setProp("thickness", string);
|
||
2405 | feaFondos.setProp("thickness", string);
|
||
2406 | } else {
|
||
2407 | Double doub = new Double(0.0); |
||
2408 | |||
2409 | //feature.setProp("thickness", doub.toString());
|
||
2410 | feaBordes.setProp("thickness", doub.toString());
|
||
2411 | feaFondos.setProp("thickness", doub.toString());
|
||
2412 | } |
||
2413 | |||
2414 | if (grp.hasCode(62)) { |
||
2415 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
2416 | String string = integer.toString();
|
||
2417 | |||
2418 | //feature.setProp("color", string);
|
||
2419 | feaBordes.setProp("color", string);
|
||
2420 | feaFondos.setProp("color", string);
|
||
2421 | feaBordes.setProp("colorByLayer", "false"); |
||
2422 | feaFondos.setProp("colorByLayer", "false"); |
||
2423 | } else {
|
||
2424 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2425 | int clr = layer.colorNumber;
|
||
2426 | Integer integer = new Integer(clr); |
||
2427 | String string = integer.toString();
|
||
2428 | |||
2429 | //feature.setProp("color", string);
|
||
2430 | feaBordes.setProp("color", string);
|
||
2431 | feaFondos.setProp("color", string);
|
||
2432 | feaBordes.setProp("colorByLayer", "true"); |
||
2433 | feaFondos.setProp("colorByLayer", "true"); |
||
2434 | } |
||
2435 | |||
2436 | if (grp.hasCode(70)) { |
||
2437 | flags = grp.getDataAsInt(70);
|
||
2438 | } |
||
2439 | |||
2440 | if ((flags & 0x01) == 0x01) { |
||
2441 | //geometria = new Polygon();
|
||
2442 | feaBordes.setGeometry(lineString3D); |
||
2443 | feaFondos.setGeometry(polygon3D); |
||
2444 | isDoubleFeatured = true;
|
||
2445 | } else {
|
||
2446 | //geometria = new LineString();
|
||
2447 | feaBordes.setGeometry(lineString3D); |
||
2448 | isDoubleFeatured = false;
|
||
2449 | } |
||
2450 | |||
2451 | int j = 0; |
||
2452 | double firstX = 0.0; |
||
2453 | double firstY = 0.0; |
||
2454 | double firstZ = 0.0; |
||
2455 | |||
2456 | for (int i = 0; i < grp.size(); i++) { |
||
2457 | g = (DxfGroup) grp.get(i); |
||
2458 | |||
2459 | if (g.getCode() == 10) { |
||
2460 | j++; |
||
2461 | x = ((Double) g.getData()).doubleValue();
|
||
2462 | } else if (g.getCode() == 20) { |
||
2463 | y = ((Double) g.getData()).doubleValue();
|
||
2464 | } else if (g.getCode() == 30) { |
||
2465 | z = ((Double) g.getData()).doubleValue();
|
||
2466 | |||
2467 | Point2D p = proj.createPoint(x, y);
|
||
2468 | Point3D p3d = new Point3D(p.getX(), p.getY(), z);
|
||
2469 | lineString3D.add(p3d); |
||
2470 | |||
2471 | if (isDoubleFeatured) {
|
||
2472 | polygon3D.add(p3d); |
||
2473 | } |
||
2474 | |||
2475 | if (j == 1) { |
||
2476 | firstX = x; |
||
2477 | firstY = y; |
||
2478 | firstZ = z; |
||
2479 | } |
||
2480 | |||
2481 | //elev = z;
|
||
2482 | x = 0.0;
|
||
2483 | y = 0.0;
|
||
2484 | z = 0.0;
|
||
2485 | } |
||
2486 | } |
||
2487 | |||
2488 | //Double doub = new Double(elev);
|
||
2489 | //String string = doub.toString();
|
||
2490 | //feature.setProp("elevation", string);
|
||
2491 | //feaBordes.setProp("elevation", string);
|
||
2492 | //feaFondos.setProp("elevation", string);
|
||
2493 | if (isDoubleFeatured) {
|
||
2494 | Point2D p = proj.createPoint(firstX, firstY);
|
||
2495 | Point3D p3d = new Point3D(p.getX(), p.getY(), z);
|
||
2496 | lineString3D.add(p3d); |
||
2497 | polygon3D.add(p3d); |
||
2498 | } |
||
2499 | |||
2500 | double zprev = 0; |
||
2501 | boolean constSplineElev = true; |
||
2502 | |||
2503 | for (int i = 0; i < lineString3D.pointNr(); i++) { |
||
2504 | z = lineString3D.getPoint3D(i).getZ(); |
||
2505 | |||
2506 | if (z != 0.0) { |
||
2507 | dxf3DFile = true;
|
||
2508 | } |
||
2509 | |||
2510 | if ((i > 0) && (z != zprev)) { |
||
2511 | constSplineElev = false;
|
||
2512 | } |
||
2513 | |||
2514 | zprev = z; |
||
2515 | } |
||
2516 | |||
2517 | if (constSplineElev) {
|
||
2518 | Double doub = new Double(lineString3D.getPoint3D(0).getZ()); |
||
2519 | String string = doub.toString();
|
||
2520 | feaBordes.setProp("elevation", string);
|
||
2521 | |||
2522 | if (isDoubleFeatured) {
|
||
2523 | feaFondos.setProp("elevation", string);
|
||
2524 | } |
||
2525 | } else {
|
||
2526 | Double doub = new Double(0.0); |
||
2527 | String string = doub.toString();
|
||
2528 | feaBordes.setProp("elevation", string);
|
||
2529 | |||
2530 | if (isDoubleFeatured) {
|
||
2531 | feaFondos.setProp("elevation", string);
|
||
2532 | } |
||
2533 | } |
||
2534 | |||
2535 | lastFeaBordes = feaBordes; |
||
2536 | |||
2537 | if (isDoubleFeatured) {
|
||
2538 | lastFeaFondos = feaFondos; |
||
2539 | } |
||
2540 | |||
2541 | // 041130: Rellena las props con los atributos.
|
||
2542 | completeAttributes(feaBordes); |
||
2543 | completeAttributes(feaFondos); |
||
2544 | |||
2545 | //features.add(feature);
|
||
2546 | if (addingToBlock == false) { |
||
2547 | if (isDoubleFeatured) {
|
||
2548 | features.add(feaFondos); |
||
2549 | } else {
|
||
2550 | features.add(feaBordes); |
||
2551 | } |
||
2552 | } else {
|
||
2553 | //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
|
||
2554 | if (isDoubleFeatured) {
|
||
2555 | blk.add(feaFondos); |
||
2556 | } else {
|
||
2557 | blk.add(feaBordes); |
||
2558 | } |
||
2559 | } |
||
2560 | |||
2561 | isDoubleFeatured = false;
|
||
2562 | } |
||
2563 | |||
2564 | /* (non-Javadoc)
|
||
2565 | * @see org.cresques.io.DxfFile.EntityFactory#createAttdef(org.cresques.io.DxfGroupVector)
|
||
2566 | */
|
||
2567 | public void createAttdef(DxfGroupVector grp) throws Exception { |
||
2568 | DxfGroup g = null;
|
||
2569 | |||
2570 | String defaultValue = ""; |
||
2571 | String tagString = ""; |
||
2572 | String textStyleName = ""; |
||
2573 | String[] attribute = new String[2]; |
||
2574 | boolean tagDefined = false; |
||
2575 | boolean defValDefined = false; |
||
2576 | |||
2577 | if (grp.hasCode(1)) { |
||
2578 | defaultValue = grp.getDataAsString(1);
|
||
2579 | attribute[1] = DxfConvTexts.ConvertText(defaultValue);
|
||
2580 | defValDefined = true;
|
||
2581 | |||
2582 | if (tagDefined) {
|
||
2583 | attributes.add(attribute); |
||
2584 | } |
||
2585 | } |
||
2586 | |||
2587 | if (grp.hasCode(2)) { |
||
2588 | tagString = grp.getDataAsString(2);
|
||
2589 | attribute[0] = DxfConvTexts.ConvertText(tagString);
|
||
2590 | tagDefined = true;
|
||
2591 | |||
2592 | if (defValDefined) {
|
||
2593 | attributes.add(attribute); |
||
2594 | } |
||
2595 | } |
||
2596 | |||
2597 | if (grp.hasCode(7)) { |
||
2598 | textStyleName = grp.getDataAsString(7);
|
||
2599 | textStyleName = DxfConvTexts.ConvertText(textStyleName); |
||
2600 | } |
||
2601 | |||
2602 | setNewAttributes(); |
||
2603 | } |
||
2604 | |||
2605 | /* (non-Javadoc)
|
||
2606 | * @see org.cresques.io.DxfFile.EntityFactory#createAttrib(org.cresques.io.DxfGroupVector)
|
||
2607 | */
|
||
2608 | public void createAttrib(DxfGroupVector grp) throws Exception { |
||
2609 | double x = 0.0; |
||
2610 | double y = 0.0; |
||
2611 | double z = 0.0; |
||
2612 | double h = 0.0; |
||
2613 | double rot = 0.0; |
||
2614 | DxfGroup g = null;
|
||
2615 | |||
2616 | //Point2D pt1 = null, pt2 = null;
|
||
2617 | Point3D pt = null;
|
||
2618 | org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
|
||
2619 | |||
2620 | point.setTextPoint(true);
|
||
2621 | |||
2622 | String defaultValue = ""; |
||
2623 | String tagString = ""; |
||
2624 | String textStyleName = ""; |
||
2625 | String[] att = new String[2]; |
||
2626 | boolean tagDefined = false; |
||
2627 | boolean defValDefined = false; |
||
2628 | int attributeFlags = 0; |
||
2629 | |||
2630 | double extx = 0.0; |
||
2631 | double exty = 0.0; |
||
2632 | double extz = 1.0; |
||
2633 | |||
2634 | Feature insFea = lastFeaBordes; |
||
2635 | Feature ptFea = lastFeaFondos; |
||
2636 | |||
2637 | Feature feature = new Feature();
|
||
2638 | |||
2639 | feature.setProp("dxfEntity", "Attrib"); // <-- Es un INSERT con attributes. |
||
2640 | |||
2641 | if (grp.hasCode(8)) { |
||
2642 | feature.setProp("layer", grp.getDataAsString(8)); |
||
2643 | } |
||
2644 | |||
2645 | if (grp.hasCode(39)) { |
||
2646 | Double doub = new Double(grp.getDataAsDouble(39)); |
||
2647 | String string = doub.toString();
|
||
2648 | feature.setProp("thickness", string);
|
||
2649 | } else {
|
||
2650 | Double doub = new Double(0.0); |
||
2651 | feature.setProp("thickness", doub.toString());
|
||
2652 | } |
||
2653 | |||
2654 | if (grp.hasCode(62)) { |
||
2655 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
2656 | String string = integer.toString();
|
||
2657 | feature.setProp("color", string);
|
||
2658 | feature.setProp("colorByLayer", "false"); |
||
2659 | } else {
|
||
2660 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2661 | int clr = layer.colorNumber;
|
||
2662 | Integer integer = new Integer(clr); |
||
2663 | String string = integer.toString();
|
||
2664 | feature.setProp("color", string);
|
||
2665 | feature.setProp("colorByLayer", "true"); |
||
2666 | } |
||
2667 | |||
2668 | if (grp.hasCode(1)) { |
||
2669 | String strAux1 = grp.getDataAsString(1); |
||
2670 | strAux1 = DxfConvTexts.ConvertText(strAux1); |
||
2671 | defaultValue = strAux1; |
||
2672 | att[1] = DxfConvTexts.ConvertText(defaultValue);
|
||
2673 | defValDefined = true;
|
||
2674 | |||
2675 | if (tagDefined) {
|
||
2676 | insFea.setProp(att[0], att[1]); |
||
2677 | ptFea.setProp(att[0], att[1]); |
||
2678 | } |
||
2679 | |||
2680 | feature.setProp("text", strAux1);
|
||
2681 | } |
||
2682 | |||
2683 | if (grp.hasCode(2)) { |
||
2684 | String strAux2 = grp.getDataAsString(2); |
||
2685 | strAux2 = DxfConvTexts.ConvertText(strAux2); |
||
2686 | tagString = strAux2; |
||
2687 | att[0] = DxfConvTexts.ConvertText(tagString);
|
||
2688 | tagDefined = true;
|
||
2689 | |||
2690 | if (defValDefined) {
|
||
2691 | insFea.setProp(att[0], att[1]); |
||
2692 | ptFea.setProp(att[0], att[1]); |
||
2693 | } |
||
2694 | } |
||
2695 | |||
2696 | if (grp.hasCode(7)) { |
||
2697 | textStyleName = grp.getDataAsString(7);
|
||
2698 | textStyleName = DxfConvTexts.ConvertText(textStyleName); |
||
2699 | } |
||
2700 | |||
2701 | if (grp.hasCode(70)) { |
||
2702 | attributeFlags = grp.getDataAsInt(70);
|
||
2703 | } |
||
2704 | |||
2705 | if (grp.hasCode(40)) { |
||
2706 | Double heightD = new Double(grp.getDataAsDouble(40)); |
||
2707 | String heightS = heightD.toString();
|
||
2708 | feature.setProp("textHeight", heightS);
|
||
2709 | } else {
|
||
2710 | feature.setProp("textHeight", "20.0"); |
||
2711 | } |
||
2712 | |||
2713 | if (grp.hasCode(50)) { |
||
2714 | Double rotD = new Double(grp.getDataAsDouble(50)); |
||
2715 | String rotS = rotD.toString();
|
||
2716 | feature.setProp("textRotation", rotS);
|
||
2717 | } else {
|
||
2718 | feature.setProp("textRotation", "0.0"); |
||
2719 | } |
||
2720 | |||
2721 | x = grp.getDataAsDouble(10);
|
||
2722 | y = grp.getDataAsDouble(20);
|
||
2723 | z = grp.getDataAsDouble(30);
|
||
2724 | |||
2725 | /*if (grp.hasCode(30)){
|
||
2726 | z = grp.getDataAsDouble(30);
|
||
2727 | Double doub = new Double(z);
|
||
2728 | String string = doub.toString();
|
||
2729 | feature.setProp("elevation", string);
|
||
2730 | } else {
|
||
2731 | Double doub = new Double(0.0);
|
||
2732 | feature.setProp("elevation", doub.toString());
|
||
2733 | }*/
|
||
2734 | if (grp.hasCode(210)) { |
||
2735 | extx = grp.getDataAsDouble(210);
|
||
2736 | } |
||
2737 | |||
2738 | if (grp.hasCode(220)) { |
||
2739 | exty = grp.getDataAsDouble(220);
|
||
2740 | } |
||
2741 | |||
2742 | if (grp.hasCode(230)) { |
||
2743 | extz = grp.getDataAsDouble(230);
|
||
2744 | } |
||
2745 | |||
2746 | Point3D point_in = new Point3D(x, y, z);
|
||
2747 | Point3D xtru = new Point3D(extx, exty, extz);
|
||
2748 | Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru); |
||
2749 | x = point_out.getX(); |
||
2750 | y = point_out.getY(); |
||
2751 | z = point_out.getZ(); |
||
2752 | |||
2753 | Double doub = new Double(z); |
||
2754 | feature.setProp("elevation", doub.toString());
|
||
2755 | |||
2756 | if (z != 0.0) { |
||
2757 | dxf3DFile = true;
|
||
2758 | } |
||
2759 | |||
2760 | point.add(new Point3D(x, y, z));
|
||
2761 | feature.setGeometry(point); |
||
2762 | |||
2763 | // 041130: Rellena las props con los atributos.
|
||
2764 | completeAttributes(feature); |
||
2765 | |||
2766 | if (attributeFlags == 8) { |
||
2767 | if (addingToBlock == false) { |
||
2768 | features.add(feature); |
||
2769 | } else {
|
||
2770 | blk.add(feature); |
||
2771 | } |
||
2772 | } |
||
2773 | } |
||
2774 | |||
2775 | /* (non-Javadoc)
|
||
2776 | * @see org.cresques.io.DxfFile.EntityFactory#createBlock(org.cresques.io.DxfGroupVector)
|
||
2777 | */
|
||
2778 | public void createBlock(DxfGroupVector grp) throws Exception { |
||
2779 | //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2780 | blk = new FeatureCollection(proj);
|
||
2781 | |||
2782 | Point3D basePoint = new Point3D();
|
||
2783 | String blockName = ""; |
||
2784 | |||
2785 | //System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
|
||
2786 | addingToBlock = true;
|
||
2787 | |||
2788 | //System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
|
||
2789 | blkList.add(iterator, blk); |
||
2790 | |||
2791 | //System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
|
||
2792 | if (grp.hasCode(8)) { |
||
2793 | blk.setProp("layer", grp.getDataAsString(8)); |
||
2794 | } |
||
2795 | |||
2796 | if (grp.hasCode(62)) { |
||
2797 | Integer integer = new Integer(grp.getDataAsInt(62)); |
||
2798 | String string = integer.toString();
|
||
2799 | blk.setProp("color", string);
|
||
2800 | blk.setProp("colorByLayer", "false"); |
||
2801 | } else {
|
||
2802 | DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2803 | int clr = layer.colorNumber;
|
||
2804 | Integer integer = new Integer(clr); |
||
2805 | String string = integer.toString();
|
||
2806 | blk.setProp("color", string);
|
||
2807 | blk.setProp("colorByLayer", "true"); |
||
2808 | } |
||
2809 | |||
2810 | if (grp.hasCode(1)) { |
||
2811 | blockName = grp.getDataAsString(1);
|
||
2812 | |||
2813 | //blk.setBlkName(blockName);
|
||
2814 | blk.setProp("blockName", blockName);
|
||
2815 | } |
||
2816 | |||
2817 | if (grp.hasCode(2)) { |
||
2818 | blockName = grp.getDataAsString(2);
|
||
2819 | |||
2820 | //blk.setBlkName(blockName);
|
||
2821 | blk.setProp("blockName", blockName);
|
||
2822 | } |
||
2823 | |||
2824 | if (grp.hasCode(10)) { |
||
2825 | Double basePointX = new Double(grp.getDataAsDouble(10)); |
||
2826 | basePoint.X = grp.getDataAsDouble(10);
|
||
2827 | blk.setProp("basePointX", basePointX.toString());
|
||
2828 | } |
||
2829 | |||
2830 | if (grp.hasCode(20)) { |
||
2831 | Double basePointY = new Double(grp.getDataAsDouble(20)); |
||
2832 | basePoint.Y = grp.getDataAsDouble(20);
|
||
2833 | blk.setProp("basePointY", basePointY.toString());
|
||
2834 | } |
||
2835 | |||
2836 | if (grp.hasCode(30)) { |
||
2837 | Double basePointZ = new Double(grp.getDataAsDouble(30)); |
||
2838 | basePoint.Z = grp.getDataAsDouble(30);
|
||
2839 | |||
2840 | if (basePoint.getZ() != 0.0) { |
||
2841 | dxf3DFile = true;
|
||
2842 | } |
||
2843 | |||
2844 | blk.setProp("basePointZ", basePointZ.toString());
|
||
2845 | } |
||
2846 | |||
2847 | if (grp.hasCode(70)) { |
||
2848 | //blk.flags = grp.getDataAsInt(70);
|
||
2849 | Integer blockFlags = new Integer(grp.getDataAsInt(70)); |
||
2850 | blk.setProp("blockFlags", blockFlags.toString());
|
||
2851 | |||
2852 | // 041103: Hoy por hoy esto no lo utilizamos.
|
||
2853 | } |
||
2854 | } |
||
2855 | |||
2856 | /* (non-Javadoc)
|
||
2857 | * @see org.cresques.io.DxfFile.EntityFactory#endBlk(org.cresques.io.DxfGroupVector)
|
||
2858 | */
|
||
2859 | public void endBlk(DxfGroupVector grp) throws Exception { |
||
2860 | //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
|
||
2861 | setAddingToBlock(false);
|
||
2862 | iterator = iterator + 1;
|
||
2863 | } |
||
2864 | |||
2865 | /* (non-Javadoc)
|
||
2866 | * @see org.cresques.io.DxfFile.EntityFactory#testBlocks()
|
||
2867 | */
|
||
2868 | public void testBlocks() { |
||
2869 | //System.out.println("getBlkList() = " + getBlkList());
|
||
2870 | Vector blkList = getBlkList();
|
||
2871 | FeatureCollection block = null;
|
||
2872 | Feature feature = null;
|
||
2873 | InsPoint3D insert = null;
|
||
2874 | |||
2875 | for (int i = 0; i < blkList.size(); i++) { |
||
2876 | //System.out.println("compruebaBloques(): Bloque " + i +" de " + blkList.size());
|
||
2877 | block = (FeatureCollection) blkList.get(i); |
||
2878 | |||
2879 | int aux = block.size();
|
||
2880 | |||
2881 | for (int j = 0; j < aux; j++) { |
||
2882 | feature = (Feature) block.get(j); |
||
2883 | |||
2884 | //if (feature.getGeometry() instanceof InsPoint && feature.getProp("isAnInsert") == "true") {
|
||
2885 | if (feature.getGeometry() instanceof InsPoint3D) { |
||
2886 | insert = (InsPoint3D) feature.getGeometry(); |
||
2887 | |||
2888 | String nomBlock = insert.getBlockName();
|
||
2889 | |||
2890 | if (insert.getBlockFound() == false) { |
||
2891 | //System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock);
|
||
2892 | insert.encuentraBloque(nomBlock); |
||
2893 | |||
2894 | //gestionaInsert(feature);
|
||
2895 | //block.add(feature);
|
||
2896 | } |
||
2897 | } |
||
2898 | } |
||
2899 | } |
||
2900 | } |
||
2901 | |||
2902 | /**
|
||
2903 | * M?todo que permite incluir en la lista general de objetos los objetos que se
|
||
2904 | * encuentran dentro del bloque referenciado por cada InsPoint3D.
|
||
2905 | * @param feature, el punto de inserci?n.
|
||
2906 | */
|
||
2907 | private void gestionaInsert(Feature feature) { |
||
2908 | Feature feature2 = null;
|
||
2909 | org.cresques.px.gml.Point3D point = null;
|
||
2910 | LineString3D lineString3D = null;
|
||
2911 | Polygon3D polygon3D = null;
|
||
2912 | InsPoint3D insert = new InsPoint3D();
|
||
2913 | insert = (InsPoint3D) feature.getGeometry(); |
||
2914 | |||
2915 | double bPointX = 0.0; |
||
2916 | double bPointY = 0.0; |
||
2917 | double bPointZ = 0.0; |
||
2918 | |||
2919 | 12744 | caballero | if (insert.getBlockFound() != true) |
2920 | { |
||
2921 | System.err.println("BLOQUE NO ENCONTRADO !!!" + insert.getBlockName() + " " + insert.toString()); |
||
2922 | return;
|
||
2923 | } |
||
2924 | 8026 | nacho | 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 | } |