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