Statistics
| Revision:

root / org.gvsig.dxf / trunk / org.gvsig.dxf / org.gvsig.dxf.lib / src / main / java / org / gvsig / dxf / px / dxf / DxfFeatureMaker.java @ 6

History | View | Annotate | Download (128 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.gvsig.dxf.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.Projected;
35
import org.cresques.geo.ViewPortData;
36
import org.cresques.px.Extent;
37
import org.gvsig.dxf.geo.Point3D;
38
import org.gvsig.dxf.io.DxfFile;
39
import org.gvsig.dxf.io.DxfGroup;
40
import org.gvsig.dxf.io.DxfGroupVector;
41
import org.gvsig.dxf.px.IObjList;
42
import org.gvsig.dxf.px.gml.Feature;
43
import org.gvsig.dxf.px.gml.FeatureCollection;
44
import org.gvsig.dxf.px.gml.InsPoint3D;
45
import org.gvsig.dxf.px.gml.LineString;
46
import org.gvsig.dxf.px.gml.LineString3D;
47
import org.gvsig.dxf.px.gml.Polygon;
48
import org.gvsig.dxf.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
        DxfFile.logger.debug("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
                DxfFile.logger.debug("Detectada una Polyline Flag que no corresponde");
258
                DxfFile.logger.debug("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
                    LineString ls1 = new LineString();
343
                    Polygon pl1 = new Polygon();
344
                    LineString ls2 = new LineString();
345
                    Polygon pl2 = new Polygon();
346
                    LineString ls = new LineString();
347
                    Polygon pl = new Polygon();
348
                    int[] face;
349
                    int i0;
350
                    int i1;
351
                    Iterator iter = faces.iterator();
352

    
353
                    while (iter.hasNext()) {
354
                        face = (int[]) iter.next();
355
                        i0 = face[3];
356

    
357
                        for (int i = 0; i < 4; i++) {
358
                            i1 = face[i];
359

    
360
                            if (i0 > 0) {
361
                                if ((facesIterador % 2) != 0) {
362
                                    ls1.add(lineString3D.get(i0 - 1));
363
                                    pl1.add(polygon3D.get(i0 - 1));
364
                                } else {
365
                                    ls2.add(lineString3D.get(i0 - 1));
366
                                    pl2.add(polygon3D.get(i0 - 1));
367
                                }
368

    
369
                                facesIterador = facesIterador + 1;
370
                            }
371

    
372
                            i0 = i1;
373
                        }
374
                    }
375

    
376
                    facesFirstPoint = new Point2D.Double(ls1.get(0).getX(),
377
                                                         ls1.get(0).getY());
378

    
379
                    for (int i = 0; i < ls1.pointNr(); i++) {
380
                        ls.add(ls1.get(i));
381
                        pl.add(pl1.get(i));
382
                    }
383

    
384
                    for (int i = ls2.pointNr() - 1; i > 0; i--) {
385
                        ls.add(ls2.get(i));
386
                        pl.add(pl2.get(i));
387
                    }
388

    
389
                    ls.add(facesFirstPoint);
390
                    pl.add(facesFirstPoint);
391
                    lastFeaBordes.setGeometry(ls);
392
                    lastFeaFondos.setGeometry(pl);
393
                } else {
394
                    lastFeaBordes.setGeometry(lineString3D);
395
                    lastFeaFondos.setGeometry(polygon3D);
396
                }
397

    
398
                // 041130: Rellena las props con los atributos.
399
                completeAttributes(lastFeaBordes);
400
                completeAttributes(lastFeaFondos);
401

    
402
                setPolylineElevation(lastFeaBordes, lastFeaFondos);
403

    
404
                if (addingToBlock == false) {
405
                    //features.add(lastFeaBordes);
406
                    features.add(lastFeaFondos);
407
                } else {
408
                    //blk.add(lastFeaBordes);
409
                    blk.add(lastFeaFondos);
410
                }
411

    
412
                lastFeaBordes = null;
413
                lastFeaFondos = null;
414
            } else if (lastFeaBordes.getGeometry() instanceof InsPoint3D) {
415
                // Se trata de un SEQEND despues de un ATTRIB
416
                copyAttributes(lastFeaBordes);
417

    
418
                gestionaInsert(lastFeaBordes);
419

    
420
                if (addingToBlock == false) {
421
                    features.add(lastFeaFondos);
422
                } else {
423
                    blk.add(lastFeaBordes);
424
                }
425

    
426
                lastFeaBordes = null;
427
                lastFeaFondos = null;
428
            } else {
429
                // Caso no contemplado.
430
            }
431
        } else {
432
            if (lastFeaBordes.getGeometry() instanceof LineString3D) {
433
                Feature feaBordes = lastFeaBordes;
434
                LineString3D lineString3D = (LineString3D) feaBordes.getGeometry();
435

    
436
                if ((bulge != 0) &&
437
                        !((lineString3D.get(lineString3D.pointNr() - 2).getX() == lineString3D.get(lineString3D.pointNr() -
438
                                                                                                       1)
439
                                                                                                  .getX()) &&
440
                        (lineString3D.get(lineString3D.pointNr() - 2).getY() == lineString3D.get(lineString3D.pointNr() -
441
                                                                                                     1)
442
                                                                                                .getY()))) {
443
                    // 041122: Correcci�n del bug en los bulges de FIXT3.DXF
444
                    Vector arc = createArc(new Point2D.Double(lineString3D.get(lineString3D.pointNr() -
445
                                                                               2)
446
                                                                          .getX(),
447
                                                              lineString3D.get(lineString3D.pointNr() -
448
                                                                               2)
449
                                                                          .getY()),
450
                                           new Point2D.Double(lineString3D.get(lineString3D.pointNr() -
451
                                                                               1)
452
                                                                          .getX(),
453
                                                              lineString3D.get(lineString3D.pointNr() -
454
                                                                               1)
455
                                                                          .getY()),
456
                                           bulge);
457
                    lineString3D.remove(lineString3D.pointNr() - 1);
458
                    lineString3D.remove(lineString3D.pointNr() - 1);
459

    
460
                    if (bulge > 0) {
461
                        for (int i = 0; i < arc.size(); i++) {
462
                            Point2D ptAux = new Point2D.Double();
463
                            double z = ((Point3D) lineString3D.get(lineString3D.pointNr() -
464
                                                                   2)).getZ();
465
                            ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
466
                                                     ((Point2D) arc.get(i)).getY());
467

    
468
                            Point3D ptAux3D = new Point3D(ptAux.getX(),
469
                                                          ptAux.getY(), z);
470
                            lineString3D.add(ptAux3D);
471

    
472
                            if (lineString3D.pointNr() == 1) {
473
                                firstPt = ptAux3D;
474
                            }
475
                        }
476
                    } else {
477
                        for (int i = arc.size() - 1; i >= 0; i--) {
478
                            Point2D ptAux = new Point2D.Double();
479
                            double z = ((Point3D) lineString3D.get(lineString3D.pointNr() -
480
                                                                   2)).getZ();
481
                            ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
482
                                                     ((Point2D) arc.get(i)).getY());
483

    
484
                            Point3D ptAux3D = new Point3D(ptAux.getX(),
485
                                                          ptAux.getY(), z);
486
                            lineString3D.add(ptAux3D);
487

    
488
                            if (lineString3D.pointNr() == 1) {
489
                                firstPt = ptAux3D;
490
                            }
491
                        }
492
                    }
493

    
494
                    // 041122
495
                    bulge = 0.0;
496
                }
497

    
498
                if (hasFaces) {
499
                    LineString ls1 = new LineString();
500
                    LineString ls2 = new LineString();
501
                    LineString ls = new LineString();
502
                    int[] face;
503
                    int i0;
504
                    int i1;
505
                    Iterator iter = faces.iterator();
506

    
507
                    while (iter.hasNext()) {
508
                        face = (int[]) iter.next();
509
                        i0 = face[3];
510

    
511
                        for (int i = 0; i < 4; i++) {
512
                            i1 = face[i];
513

    
514
                            if (i0 > 0) {
515
                                if ((facesIterador % 2) != 0) {
516
                                    ls1.add(lineString3D.get(i0 - 1));
517

    
518
                                    //ls.add((Point2D)lineString.get(Math.abs(i1)-1));
519
                                } else {
520
                                    ls2.add(lineString3D.get(i0 - 1));
521

    
522
                                    //ls.add((Point2D)lineString.get(Math.abs(i1)-1));
523
                                }
524

    
525
                                facesIterador = facesIterador + 1;
526
                            }
527

    
528
                            i0 = i1;
529
                        }
530
                    }
531

    
532
                    facesFirstPoint = new Point2D.Double(ls1.get(0).getX(),
533
                                                         ls1.get(0).getY());
534

    
535
                    for (int i = 0; i < ls1.pointNr(); i++) {
536
                        ls.add(ls1.get(i));
537
                    }
538

    
539
                    for (int i = ls2.pointNr() - 1; i > 0; i--) {
540
                        ls.add(ls2.get(i));
541
                    }
542

    
543
                    ls.add(facesFirstPoint);
544
                    lastFeaBordes.setGeometry(ls);
545
                } else {
546
                    lastFeaBordes.setGeometry(lineString3D);
547
                }
548

    
549
                // 041130: Rellena las props con los atributos.
550
                completeAttributes(lastFeaBordes);
551

    
552
                setPolylineElevation(lastFeaBordes);
553

    
554
                if (addingToBlock == false) {
555
                    features.add(lastFeaBordes);
556
                } else {
557
                    blk.add(lastFeaBordes);
558
                }
559

    
560
                lastFeaBordes = null;
561
            } else {
562
                // Se trata de un SEQEND despues de un ATTRIB
563
            }
564
        }
565

    
566
        xtruX = 0.0;
567
        xtruY = 0.0;
568
        xtruZ = 1.0;
569
        bulge = 0.0;
570
        isDoubleFeatured = false;
571
        hasFaces = false;
572
        facesIterador = 1;
573
    }
574

    
575
    /**
576
     * Establece un valor constante para la elevaci�n de una polil�nea.
577
     * @param feaBordes, la polil�nea.
578
     */
579
    private void setPolylineElevation(Feature feaBordes) {
580
        if (constantPolylineElevation) {
581
            Double doub = new Double(lastVertexElevation);
582
            String string = doub.toString();
583
            feaBordes.setProp("elevation", string);
584
        } else {
585
            Double doub = new Double(0.0);
586
            String string = doub.toString();
587
            feaBordes.setProp("elevation", string);
588
        }
589
    }
590

    
591
    /**
592
     * Establece un valor constante para la elevaci�n de un pol�gono.
593
     * @param feaBordes, borde del pol�gono.
594
     * @param feaFondos, fondo del pol�gono.
595
     */
596
    private void setPolylineElevation(Feature feaBordes, Feature feaFondos) {
597
        if (constantPolylineElevation) {
598
            Double doub = new Double(lastVertexElevation);
599
            String string = doub.toString();
600
            feaBordes.setProp("elevation", string);
601
            feaFondos.setProp("elevation", string);
602
        } else {
603
            Double doub = new Double(0.0);
604
            String string = doub.toString();
605
            feaBordes.setProp("elevation", string);
606
            feaFondos.setProp("elevation", string);
607
        }
608
    }
609

    
610
    /* (non-Javadoc)
611
     * @see org.cresques.io.DxfFile.EntityFactory#addVertex(org.cresques.io.DxfGroupVector)
612
     */
613
    public void addVertex(DxfGroupVector grp) throws Exception {
614
        double x = 0.0;
615
        double y = 0.0;
616
        double z = 0.0;
617
        int vFlags = 0;
618

    
619
        if (isDoubleFeatured) {
620
            Feature feaBordes = lastFeaBordes;
621
            Feature feaFondos = lastFeaFondos;
622
            LineString3D lineString3D = (LineString3D) feaBordes.getGeometry();
623
            Polygon3D polygon3D = (Polygon3D) feaFondos.getGeometry();
624

    
625
            if (grp.hasCode(8)) {
626
                feaBordes.setProp("layer", grp.getDataAsString(8));
627
                feaFondos.setProp("layer", grp.getDataAsString(8));
628
            }
629

    
630
            if (grp.hasCode(70)) {
631
                vFlags = grp.getDataAsInt(70);
632
            }
633

    
634
            x = grp.getDataAsDouble(10);
635
            y = grp.getDataAsDouble(20);
636
            z = grp.getDataAsDouble(30);
637

    
638
            Point3D point_in = new Point3D(x, y, z);
639
            Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
640
            Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
641
            x = point_out.getX();
642
            y = point_out.getY();
643
            z = point_out.getZ();
644

    
645
            if (z != 0.0) {
646
                dxf3DFile = true;
647
            }
648

    
649
            if ((z != lastVertexElevation) && (lineString3D.pointNr() > 0)) {
650
                constantPolylineElevation = false;
651
            }
652

    
653
            lastVertexElevation = z;
654

    
655
            if (((vFlags & 0x80) == 0x80) && ((vFlags & 0x40) == 0)) {
656
                int[] face = { 0, 0, 0, 0 };
657
                face[0] = grp.getDataAsInt(71);
658
                face[1] = grp.getDataAsInt(72);
659
                face[2] = grp.getDataAsInt(73);
660
                face[3] = grp.getDataAsInt(74);
661
                addFace(face);
662
            } else if ((vFlags & 0x10) == 0x10) {
663
                // Son vertices que se trataran cuando se implementen
664
                // los splines. En principio no se hace nada con ellos.
665
            } else {
666
                    Point2D ptaux = proj.createPoint(x, y);
667
                Point3D pt = new Point3D(ptaux.getX(), ptaux.getY(), z);
668
                lineString3D.add(pt);
669
                polygon3D.add(pt);
670

    
671
                if (lineString3D.pointNr() == 1) {
672
                    firstPt = pt;
673
                }
674

    
675
                if (bulge == 0.0) {
676
                    if (grp.hasCode(42)) {
677
                        bulge = grp.getDataAsDouble(42);
678
                    } else {
679
                        bulge = 0.0;
680
                    }
681
                } else {
682
                    double bulge_aux = 0.0;
683

    
684
                    if (grp.hasCode(42)) {
685
                        bulge_aux = grp.getDataAsDouble(42);
686
                    } else {
687
                        bulge_aux = 0.0;
688
                    }
689

    
690
                    //int cnt = lineString.pointNr();
691
                    if ((ptAnterior.getX() == pt.getX()) &&
692
                            (ptAnterior.getY() == pt.getY())) {
693
                        // no se construye el arco
694
                    } else {
695
                        lineString3D.remove(lineString3D.pointNr() - 1);
696
                        lineString3D.remove(lineString3D.pointNr() - 1);
697
                        polygon3D.remove(polygon3D.pointNr() - 1);
698
                        polygon3D.remove(polygon3D.pointNr() - 1);
699

    
700
                        Vector arc = createArc(ptAnterior, pt, bulge);
701

    
702
                        if (bulge > 0) {
703
                            for (int i = 0; i < arc.size(); i++) {
704
                                Point2D ptAux = new Point2D.Double();
705
                                ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
706
                                                         ((Point2D) arc.get(i)).getY());
707

    
708
                                Point3D ptAux3D = new Point3D(ptAux.getX(),
709
                                                              ptAux.getY(), z);
710
                                lineString3D.add(ptAux3D);
711
                                polygon3D.add(ptAux3D);
712

    
713
                                if (lineString3D.pointNr() == 1) {
714
                                    firstPt = ptAux3D;
715
                                }
716
                            }
717
                        } else {
718
                            for (int i = arc.size() - 1; i >= 0; i--) {
719
                                Point2D ptAux = new Point2D.Double();
720
                                ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
721
                                                         ((Point2D) arc.get(i)).getY());
722

    
723
                                Point3D ptAux3D = new Point3D(ptAux.getX(),
724
                                                              ptAux.getY(), z);
725
                                lineString3D.add(ptAux3D);
726
                                polygon3D.add(ptAux3D);
727

    
728
                                if ((lineString3D.pointNr() == 1) ||
729
                                        (polygon3D.pointNr() == 1)) {
730
                                    firstPt = ptAux3D;
731
                                }
732
                            }
733
                        }
734
                    }
735

    
736
                    bulge = bulge_aux;
737
                }
738

    
739
                ptAnterior = pt;
740
            }
741
        } else {
742
            Feature feaBordes = lastFeaBordes;
743
            LineString3D lineString3D = (LineString3D) feaBordes.getGeometry();
744

    
745
            if (grp.hasCode(8)) {
746
                feaBordes.setProp("layer", grp.getDataAsString(8));
747
            }
748

    
749
            if (grp.hasCode(70)) {
750
                vFlags = grp.getDataAsInt(70);
751
            }
752

    
753
            x = grp.getDataAsDouble(10);
754
            y = grp.getDataAsDouble(20);
755
            if (grp.hasCode(30)){
756
                    z = grp.getDataAsDouble(30);
757
            }
758

    
759
            Point3D point_in = new Point3D(x, y, z);
760
            Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
761
            Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
762
            x = point_out.getX();
763
            y = point_out.getY();
764
            z = point_out.getZ();
765

    
766
            if (z != 0.0) {
767
                dxf3DFile = true;
768
            }
769

    
770
            if ((z != lastVertexElevation) && (lineString3D.pointNr() > 0)) {
771
                constantPolylineElevation = false;
772
            }
773

    
774
            lastVertexElevation = z;
775

    
776
            if (((vFlags & 0x80) == 0x80) && ((vFlags & 0x40) == 0)) {
777
                int[] face = { 0, 0, 0, 0 };
778
                face[0] = grp.getDataAsInt(71);
779
                face[1] = grp.getDataAsInt(72);
780
                face[2] = grp.getDataAsInt(73);
781
                face[3] = grp.getDataAsInt(74);
782
                addFace(face);
783
            } else if ((vFlags & 16) == 16) {
784
                // no se hace nada.
785
            } else {
786
                    Point2D ptaux = proj.createPoint(x, y);
787
                Point3D pt = new Point3D(ptaux.getX(), ptaux.getY(), z);
788
                lineString3D.add(pt);
789

    
790
                if (lineString3D.pointNr() == 1) {
791
                    firstPt = pt;
792

    
793
                }
794

    
795
                if (bulge == 0.0) {
796
                    if (grp.hasCode(42)) {
797
                        bulge = grp.getDataAsDouble(42);
798
                    } else {
799
                        bulge = 0.0;
800
                    }
801

    
802
                } else {
803
                    double bulge_aux = 0.0;
804

    
805
                    if (grp.hasCode(42)) {
806
                        bulge_aux = grp.getDataAsDouble(42);
807
                    } else {
808
                        bulge_aux = 0.0;
809
                    }
810

    
811
                    if ((ptAnterior.getX() == pt.getX()) &&
812
                            (ptAnterior.getY() == pt.getY())) {
813
                        // no se construye el arco
814
                    } else {
815
                        // Borro los puntos inicio y final del arco.
816
                        lineString3D.remove(lineString3D.pointNr() - 1);
817
                        lineString3D.remove(lineString3D.pointNr() - 1);
818

    
819
                        Vector arc = createArc(ptAnterior, pt, bulge);
820

    
821
                        if (bulge > 0) {
822
                            for (int i = 0; i < arc.size(); i++) {
823
                                Point2D ptAux = new Point2D.Double();
824
                                ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
825
                                                         ((Point2D) arc.get(i)).getY());
826

    
827
                                Point3D ptAux3D = new Point3D(ptAux.getX(),
828
                                                              ptAux.getY(), z);
829
                                lineString3D.add(ptAux3D);
830

    
831
                                if (lineString3D.pointNr() == 1) {
832
                                    firstPt = ptAux3D;
833
                                }
834
                            }
835
                        } else {
836
                            for (int i = arc.size() - 1; i >= 0; i--) {
837
                                Point2D ptAux = new Point2D.Double();
838
                                ptAux = proj.createPoint(((Point2D) arc.get(i)).getX(),
839
                                                         ((Point2D) arc.get(i)).getY());
840

    
841
                                Point3D ptAux3D = new Point3D(ptAux.getX(),
842
                                                              ptAux.getY(), z);
843
                                lineString3D.add(ptAux3D);
844

    
845
                                if (lineString3D.pointNr() == 1) {
846
                                    firstPt = ptAux3D;
847
                                }
848
                            }
849
                        }
850
                    }
851

    
852
                    bulge = bulge_aux;
853
                }
854

    
855
                ptAnterior = pt;
856
            }
857
        }
858
    }
859

    
860
    /* (non-Javadoc)
861
     * @see org.cresques.io.DxfFile.EntityFactory#createLwPolyline(org.cresques.io.DxfGroupVector)
862
     */
863
    public void createLwPolyline(DxfGroupVector grp) throws Exception {
864
        double x = 0.0;
865
        double y = 0.0;
866
        double elev = 0.0;
867
        DxfGroup g = null;
868
        LineString3D lineString3D = new LineString3D();
869
        Polygon3D polygon3D = new Polygon3D();
870

    
871
        //Geometry geometria;
872
        //Feature feature= new Feature();
873
        Feature feaBordes = new Feature();
874
        Feature feaFondos = new Feature();
875
        int flags = 0;
876
        //int NumberOfVertices = 0;
877
        double extx = 0.0;
878
        double exty = 0.0;
879
        double extz = 1.0;
880

    
881
        //feature.setProp("dxfEntity", "LwPolyline");
882
        feaBordes.setProp("dxfEntity", "LwPolyline");
883
        feaFondos.setProp("dxfEntity", "LwPolyline");
884

    
885
        //if (grp.hasCode(8)) {
886
            //feature.setProp("layer", grp.getDataAsString(8));
887
        //    feaBordes.setProp("layer", grp.getDataAsString(8));
888
        //}
889

    
890
        feaBordes.setProp("layer", grp.getDataAsString(8));
891
        feaFondos.setProp("layer", grp.getDataAsString(8));
892

    
893
        if (grp.hasCode(38)) {
894
            elev = grp.getDataAsDouble(38);
895

    
896
            if (elev != 0.0) {
897
                dxf3DFile = true;
898
            }
899

    
900
            Double doub = new Double(elev);
901
            String string = doub.toString();
902

    
903
            //feature.setProp("elevation", string);
904
            feaBordes.setProp("elevation", string);
905
            feaFondos.setProp("elevation", string);
906
        } else {
907
            Double doub = new Double(0.0);
908

    
909
            //feature.setProp("elevation", doub.toString());
910
            feaBordes.setProp("elevation", doub.toString());
911
            feaFondos.setProp("elevation", doub.toString());
912
        }
913

    
914
        if (grp.hasCode(39)) {
915
            Double doub = new Double(grp.getDataAsDouble(39));
916
            String string = doub.toString();
917

    
918
            //feature.setProp("thickness", string);
919
            feaBordes.setProp("thickness", string);
920
            feaFondos.setProp("thickness", string);
921
        } else {
922
            Double doub = new Double(0.0);
923

    
924
            //feature.setProp("thickness", doub.toString());
925
            feaBordes.setProp("thickness", doub.toString());
926
            feaFondos.setProp("thickness", doub.toString());
927
        }
928

    
929
        if (grp.hasCode(62)) {
930
            Integer integer = new Integer(grp.getDataAsInt(62));
931
            String string = integer.toString();
932

    
933
            //feature.setProp("color", string);
934
            feaBordes.setProp("color", string);
935
            feaFondos.setProp("color", string);
936
            feaBordes.setProp("colorByLayer", "false");
937
            feaFondos.setProp("colorByLayer", "false");
938
        } else {
939
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
940
            int clr = layer.colorNumber;
941
            Integer integer = new Integer(clr);
942
            String string = integer.toString();
943

    
944
            //feature.setProp("color", string);
945
            feaBordes.setProp("color", string);
946
            feaFondos.setProp("color", string);
947
            feaBordes.setProp("colorByLayer", "true");
948
            feaFondos.setProp("colorByLayer", "true");
949
        }
950

    
951
        if (grp.hasCode(70)) {
952
            flags = grp.getDataAsInt(70);
953
        }
954

    
955
        if ((flags & 0x01) == 0x01) {
956
            //geometria = new Polygon();
957
            feaBordes.setGeometry(lineString3D);
958
            feaFondos.setGeometry(polygon3D);
959
            isDoubleFeatured = true;
960
        } else {
961
            //geometria = new LineString();
962
            feaBordes.setGeometry(lineString3D);
963
            isDoubleFeatured = false;
964
        }
965

    
966
        //if (grp.hasCode(90)) {
967
        //    NumberOfVertices = grp.getDataAsInt(90);
968
        //}
969

    
970
        if (grp.hasCode(210)) {
971
            extx = grp.getDataAsDouble(210);
972
        }
973

    
974
        if (grp.hasCode(220)) {
975
            exty = grp.getDataAsDouble(220);
976
        }
977

    
978
        if (grp.hasCode(230)) {
979
            extz = grp.getDataAsDouble(230);
980
        }
981

    
982
        int j = 0;
983
        double firstX = 0.0;
984
        double firstY = 0.0;
985
        boolean hasBulge = false;
986
        double bulgeLwp = 0.0;
987

    
988
        for (int i = 0; i < grp.size(); i++) {
989
            g = (DxfGroup) grp.get(i);
990

    
991
            if (g.getCode() == 10) {
992
                j++;
993
                x = ((Double) g.getData()).doubleValue();
994
            } else if (g.getCode() == 20) {
995
                y = ((Double) g.getData()).doubleValue();
996

    
997
                // A�adiendo extrusion a LwPolyline ...
998
                Point3D point_in1 = new Point3D(x, y, elev);
999
                Point3D xtru = new Point3D(extx, exty, extz);
1000
                Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
1001
                x = point_out1.getX();
1002
                y = point_out1.getY();
1003
                elev = point_out1.getZ();
1004

    
1005
                //
1006
                if (hasBulge) {
1007
                    Point2D finalPoint = new Point2D.Double(x, y);
1008

    
1009
                    if (((lineString3D).get(lineString3D.pointNr() -
1010
                                                               1).getX() == finalPoint.getX()) &&
1011
                            ((lineString3D).get(lineString3D.pointNr() -
1012
                                                                   1).getY() == finalPoint.getY())) {
1013
                        // no se construye el arco
1014
                    } else {
1015
                        Vector arc = createArc((lineString3D).get(lineString3D.pointNr() -
1016
                                                                                 1),
1017
                                               finalPoint, bulgeLwp);
1018
                        lineString3D.remove(lineString3D.pointNr() - 1);
1019

    
1020
                        if (isDoubleFeatured) {
1021
                            polygon3D.remove(polygon3D.pointNr() - 1);
1022
                        }
1023

    
1024
                        if (bulgeLwp > 0) {
1025
                            for (int k = 0; k < arc.size(); k++) {
1026
                                Point2D ptAux = new Point2D.Double();
1027
                                ptAux = proj.createPoint(((Point2D) arc.get(k)).getX(),
1028
                                                         ((Point2D) arc.get(k)).getY());
1029

    
1030
                                Point3D ptAux3D = new Point3D(ptAux.getX(),
1031
                                                              ptAux.getY(), elev);
1032
                                lineString3D.add(ptAux3D);
1033

    
1034
                                //if (lineString.pointNr() == 1) firstPt = ptAux;
1035
                                if (isDoubleFeatured) {
1036
                                    polygon3D.add(ptAux3D);
1037
                                }
1038

    
1039
                                if ((lineString3D.pointNr() == 1) ||
1040
                                        (polygon3D.pointNr() == 1)) {
1041
                                    firstPt = ptAux3D;
1042
                                }
1043
                            }
1044
                        } else {
1045
                            for (int k = arc.size() - 1; k >= 0; k--) {
1046
                                Point2D ptAux = new Point2D.Double();
1047
                                ptAux = proj.createPoint(((Point2D) arc.get(k)).getX(),
1048
                                                         ((Point2D) arc.get(k)).getY());
1049

    
1050
                                Point3D ptAux3D = new Point3D(ptAux.getX(),
1051
                                                              ptAux.getY(), elev);
1052
                                lineString3D.add(ptAux3D);
1053

    
1054
                                if (isDoubleFeatured) {
1055
                                    polygon3D.add(ptAux3D);
1056
                                }
1057

    
1058
                                if ((lineString3D.pointNr() == 1) ||
1059
                                        (polygon3D.pointNr() == 1)) {
1060
                                    firstPt = ptAux3D;
1061
                                }
1062
                            }
1063
                        }
1064
                    }
1065

    
1066
                    hasBulge = false;
1067
                    bulgeLwp = 0.0;
1068
                } else {
1069
                        Point2D ptAux2D = proj.createPoint(x, y);
1070
                                        Point3D ptAux3D = new Point3D(ptAux2D.getX(), ptAux2D
1071
                                                        .getY(), elev);
1072
                    lineString3D.add(ptAux3D);
1073

    
1074
                    if (isDoubleFeatured) {
1075
                        polygon3D.add(ptAux3D);
1076
                    }
1077
                }
1078

    
1079
                if (j == 1) {
1080
                    firstX = x;
1081
                    firstY = y;
1082
                }
1083

    
1084
                x = 0.0;
1085
                y = 0.0;
1086
            } else if (g.getCode() == 42 && ((Double)g.getData()).doubleValue()!=0.0) { // Cuando los bulges eran 0.000 se provocaban errores
1087
                hasBulge = true;
1088
                bulgeLwp = ((Double) g.getData()).doubleValue();
1089
            }
1090
        }
1091

    
1092
        if (isDoubleFeatured) {
1093
            //geometria.add(proj.createPoint(firstX, firstY));
1094
                Point2D ptAux2D = proj.createPoint(firstX, firstY);
1095
                        Point3D ptAux3D = new Point3D(ptAux2D.getX(), ptAux2D.getY(),
1096
                                          elev);
1097
            lineString3D.add(ptAux3D);
1098
            polygon3D.add(ptAux3D);
1099
        }
1100

    
1101
        lastFeaBordes = feaBordes;
1102

    
1103
        if (isDoubleFeatured) {
1104
            lastFeaFondos = feaFondos;
1105
        }
1106

    
1107
        // 041130: Rellena las props con los atributos.
1108
        completeAttributes(lastFeaBordes);
1109
        completeAttributes(lastFeaFondos);
1110

    
1111
        //features.add(feature);
1112
        if (addingToBlock == false) {
1113
            if (isDoubleFeatured) {
1114
                features.add(feaFondos);
1115
            } else {
1116
                features.add(feaBordes);
1117
            }
1118
        } else {
1119
            if (isDoubleFeatured) {
1120
                blk.add(feaFondos);
1121
            } else {
1122
                blk.add(feaBordes);
1123
            }
1124
        }
1125

    
1126
        isDoubleFeatured = false;
1127
    }
1128

    
1129
    /* (non-Javadoc)
1130
     * @see org.cresques.io.DxfFile.EntityFactory#createLine(org.cresques.io.DxfGroupVector)
1131
     */
1132
    public void createLine(DxfGroupVector grp) throws Exception {
1133
        double x = 0.0;
1134
        double y = 0.0;
1135
        double z1 = 0.0;
1136
        double z2 = 0.0;
1137
        double elev = 0.0;
1138
        DxfGroup g = null;
1139
        Point2D pt1 = null;
1140
        Point2D pt2 = null;
1141
        LineString3D lineString3D = new LineString3D();
1142
        Feature feature = new Feature();
1143
        double extx = 0.0;
1144
        double exty = 0.0;
1145
        double extz = 1.0;
1146

    
1147
        feature.setProp("dxfEntity", "Line");
1148

    
1149
        if (grp.hasCode(8)) {
1150
            feature.setProp("layer", grp.getDataAsString(8));
1151
        }
1152

    
1153
        if (grp.hasCode(39)) {
1154
            Double doub = new Double(grp.getDataAsDouble(39));
1155
            String string = doub.toString();
1156
            feature.setProp("thickness", string);
1157
        } else {
1158
            Double doub = new Double(0.0);
1159
            feature.setProp("thickness", doub.toString());
1160
        }
1161

    
1162
        if (grp.hasCode(62)) {
1163
            Integer integer = new Integer(grp.getDataAsInt(62));
1164
            String string = integer.toString();
1165
            feature.setProp("color", string);
1166
            feature.setProp("colorByLayer", "false");
1167
        } else {
1168
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1169
            int clr = layer.colorNumber;
1170
            Integer integer = new Integer(clr);
1171
            String string = integer.toString();
1172
            feature.setProp("color", string);
1173
            feature.setProp("colorByLayer", "true");
1174
        }
1175

    
1176
        x = grp.getDataAsDouble(10);
1177
        y = grp.getDataAsDouble(20);
1178
        z1 = grp.getDataAsDouble(30);
1179

    
1180
        /*if (grp.hasCode(30)) {
1181
            z1 = grp.getDataAsDouble(30);
1182
            elev = z1;
1183
            Double doub = new Double(elev);
1184
            String string = doub.toString();
1185
            //feature.setProp("elevation", string);
1186
        }*/
1187
        pt1 = proj.createPoint(x, y);
1188
        x = grp.getDataAsDouble(11);
1189
        y = grp.getDataAsDouble(21);
1190
        z2 = grp.getDataAsDouble(31);
1191

    
1192
        /*if (grp.hasCode(31)) {
1193
            z2 = grp.getDataAsDouble(31);
1194
        } else {
1195
            // Cuando no se especifican z para las lineas se asume que la
1196
            // z es cero.
1197
            Double doub = new Double(0.0);
1198
            //feature.setProp("elevation", doub.toString());
1199
        }*/
1200
        pt2 = proj.createPoint(x, y);
1201

    
1202
        if (grp.hasCode(210)) {
1203
            extx = grp.getDataAsDouble(210);
1204
        }
1205

    
1206
        if (grp.hasCode(220)) {
1207
            exty = grp.getDataAsDouble(220);
1208
        }
1209

    
1210
        if (grp.hasCode(230)) {
1211
            extz = grp.getDataAsDouble(230);
1212
        }
1213

    
1214
        Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
1215
        Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
1216
        Point3D xtru = new Point3D(extx, exty, extz);
1217
        Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
1218
        Point3D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
1219

    
1220
        if (point_out1.getZ() != 0.0) {
1221
            dxf3DFile = true;
1222
        }
1223

    
1224
        if (point_out2.getZ() != 0.0) {
1225
            dxf3DFile = true;
1226
        }
1227

    
1228
        if (point_out1.getZ() == point_out2.getZ()) {
1229
            elev = z1;
1230

    
1231
            Double doub = new Double(elev);
1232
            String string = doub.toString();
1233
            feature.setProp("elevation", string);
1234
        } else {
1235
            elev = 0.0;
1236

    
1237
            Double doub = new Double(elev);
1238
            String string = doub.toString();
1239
            feature.setProp("elevation", string);
1240
        }
1241

    
1242
        //pt1.setLocation(point_out1);
1243
        //pt2.setLocation(point_out2);
1244
        lineString3D.add(point_out1);
1245
        lineString3D.add(point_out2);
1246

    
1247
        feature.setGeometry(lineString3D);
1248

    
1249
        // 041130: Rellena las props con los atributos.
1250
        completeAttributes(feature);
1251

    
1252
        //features.add(feature);
1253
        if (addingToBlock == false) {
1254
            features.add(feature);
1255
        } else {
1256
            blk.add(feature);
1257
        }
1258
    }
1259

    
1260
    /* (non-Javadoc)
1261
     * @see org.cresques.io.DxfFile.EntityFactory#createText(org.cresques.io.DxfGroupVector)
1262
     */
1263
    public void createText(DxfGroupVector grp) throws Exception {
1264
        double x = 0.0;
1265
        double y = 0.0;
1266
        double z = 0.0;
1267
        double h = 0.0;
1268
        double rot = 0.0;
1269
        DxfGroup g = null;
1270

    
1271
        //Point3D pt1 = null, pt2 = null;
1272
        Point3D pt = null;
1273
        org.gvsig.dxf.px.gml.Point3D point = new org.gvsig.dxf.px.gml.Point3D();
1274
        double extx = 0.0;
1275
        double exty = 0.0;
1276
        double extz = 1.0;
1277

    
1278
        point.setTextPoint(true);
1279

    
1280
        Feature feature = new Feature();
1281

    
1282
        feature.setProp("dxfEntity", "Text");
1283

    
1284
        if (grp.hasCode(8)) {
1285
            feature.setProp("layer", grp.getDataAsString(8));
1286
        }
1287

    
1288
        if (grp.hasCode(39)) {
1289
            Double doub = new Double(grp.getDataAsDouble(39));
1290
            String string = doub.toString();
1291
            feature.setProp("thickness", string);
1292
        } else {
1293
            Double doub = new Double(0.0);
1294
            feature.setProp("thickness", doub.toString());
1295
        }
1296

    
1297
        if (grp.hasCode(62)) {
1298
            Integer integer = new Integer(grp.getDataAsInt(62));
1299
            String string = integer.toString();
1300
            feature.setProp("color", string);
1301
            feature.setProp("colorByLayer", "false");
1302
        } else {
1303
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1304
            int clr = layer.colorNumber;
1305
            Integer integer = new Integer(clr);
1306
            String string = integer.toString();
1307
            feature.setProp("color", string);
1308
            feature.setProp("colorByLayer", "true");
1309
        }
1310

    
1311
        if (grp.hasCode(1)) {
1312
            String strAux1 = grp.getDataAsString(1);
1313
            strAux1 = DxfConvTexts.ConvertText(strAux1);
1314
            feature.setProp("text", strAux1);
1315
        } else {
1316
            feature.setProp("text", "No Text Code");
1317
        }
1318

    
1319
        if (grp.hasCode(40)) {
1320
            Double heightD = new Double(grp.getDataAsDouble(40));
1321
            String heightS = heightD.toString();
1322
            feature.setProp("textHeight", heightS);
1323
        } else {
1324
            feature.setProp("textHeight", "20.0");
1325
        }
1326

    
1327
        if (grp.hasCode(50)) {
1328
            Double rotD = new Double(grp.getDataAsDouble(50));
1329
            String rotS = rotD.toString();
1330
            feature.setProp("textRotation", rotS);
1331

    
1332
        } else {
1333
            feature.setProp("textRotation", "0.0");
1334
        }
1335

    
1336
        x = grp.getDataAsDouble(10);
1337
        y = grp.getDataAsDouble(20);
1338
        if (grp.hasCode(30)) {
1339
                z = grp.getDataAsDouble(30);
1340
        }
1341
        /*if (grp.hasCode(30)){
1342
            Double doub = new Double(z);
1343
            String string = doub.toString();
1344
            feature.setProp("elevation", string);
1345
        } else {
1346
            Double doub = new Double(0.0);
1347
            feature.setProp("elevation", doub.toString());
1348
        }*/
1349
        if (grp.hasCode(210)) {
1350
            extx = grp.getDataAsDouble(210);
1351
        }
1352

    
1353
        if (grp.hasCode(220)) {
1354
            exty = grp.getDataAsDouble(220);
1355
        }
1356

    
1357
        if (grp.hasCode(230)) {
1358
            extz = grp.getDataAsDouble(230);
1359
        }
1360

    
1361
        Point3D point_in = new Point3D(x, y, z);
1362
        Point3D xtru = new Point3D(extx, exty, extz);
1363
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1364
        x = point_out.getX();
1365
        y = point_out.getY();
1366
        z = point_out.getZ();
1367

    
1368
        Double doub = new Double(z);
1369
        feature.setProp("elevation", doub.toString());
1370

    
1371
        if (z != 0.0) {
1372
            dxf3DFile = true;
1373
        }
1374

    
1375
        point.add(new Point3D(x, y, z));
1376
        feature.setGeometry(point);
1377

    
1378
        // 041130: Rellena las props con los atributos.
1379
        completeAttributes(feature);
1380

    
1381
        //features.add(feature);
1382
        if (addingToBlock == false) {
1383
            features.add(feature);
1384
        } else {
1385
            blk.add(feature);
1386
        }
1387
    }
1388

    
1389
    /* (non-Javadoc)
1390
     * @see org.cresques.io.DxfFile.EntityFactory#createMText(org.cresques.io.DxfGroupVector)
1391
     */
1392
    public void createMText(DxfGroupVector grp) throws Exception {
1393
        double x = 0.0;
1394
        double y = 0.0;
1395
        double z = 0.0;
1396
        double h = 0.0;
1397
        double rot = 0.0;
1398
        DxfGroup g = null;
1399

    
1400
        //Point2D pt1 = null, pt2 = null;
1401
        Point3D pt = null;
1402
        org.gvsig.dxf.px.gml.Point3D point = new org.gvsig.dxf.px.gml.Point3D();
1403
        double extx = 0.0;
1404
        double exty = 0.0;
1405
        double extz = 1.0;
1406

    
1407
        point.setTextPoint(true);
1408

    
1409
        Feature feature = new Feature();
1410

    
1411
        feature.setProp("dxfEntity", "Text");
1412

    
1413
        if (grp.hasCode(8)) {
1414
            feature.setProp("layer", grp.getDataAsString(8));
1415
        }
1416

    
1417
        if (grp.hasCode(39)) {
1418
            Double doub = new Double(grp.getDataAsDouble(39));
1419
            String string = doub.toString();
1420
            feature.setProp("thickness", string);
1421
        } else {
1422
            Double doub = new Double(0.0);
1423
            feature.setProp("thickness", doub.toString());
1424
        }
1425

    
1426
        if (grp.hasCode(62)) {
1427
            Integer integer = new Integer(grp.getDataAsInt(62));
1428
            String string = integer.toString();
1429
            feature.setProp("color", string);
1430
            feature.setProp("colorByLayer", "false");
1431
        } else {
1432
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1433
            int clr = layer.colorNumber;
1434
            Integer integer = new Integer(clr);
1435
            String string = integer.toString();
1436
            feature.setProp("color", string);
1437
            feature.setProp("colorByLayer", "true");
1438
        }
1439

    
1440
        if (grp.hasCode(1)) {
1441
            String strAux1 = grp.getDataAsString(1);
1442
            strAux1 = DxfConvTexts.ConvertText(strAux1);
1443
            feature.setProp("text", strAux1);
1444
        } else {
1445
            feature.setProp("text", "No Text Code");
1446
        }
1447

    
1448
        if (grp.hasCode(40)) {
1449
            Double heightD = new Double(grp.getDataAsDouble(40));
1450
            String heightS = heightD.toString();
1451
            feature.setProp("textHeight", heightS);
1452
        } else {
1453
            feature.setProp("textHeight", "20.0");
1454
        }
1455

    
1456
        if (grp.hasCode(50)) {
1457
            Double rotD = new Double(grp.getDataAsDouble(50));
1458
            String rotS = rotD.toString();
1459
            feature.setProp("textRotation", rotS);
1460

    
1461
        } else {
1462
            feature.setProp("textRotation", "0.0");
1463
        }
1464

    
1465
        if (grp.hasCode(71)) {
1466
            int attachPoint = grp.getDataAsInt(71);
1467

    
1468
            if (attachPoint == 1) {
1469
            } else if (attachPoint == 2) {
1470
            } else if (attachPoint == 3) {
1471
            } else if (attachPoint == 4) {
1472
            } else if (attachPoint == 5) {
1473
            } else if (attachPoint == 6) {
1474
            } else if (attachPoint == 7) {
1475
            } else if (attachPoint == 8) {
1476
            } else if (attachPoint == 9) {
1477
            }
1478
        }
1479

    
1480
        if (grp.hasCode(72)) {
1481
            int drawDirection = grp.getDataAsInt(71);
1482

    
1483
            if (drawDirection == 1) {
1484
            } else if (drawDirection == 3) {
1485
            } else if (drawDirection == 5) {
1486
            }
1487
        }
1488

    
1489
        if (grp.hasCode(73)) {
1490
            int spacingStyle = grp.getDataAsInt(71);
1491

    
1492
            if (spacingStyle == 1) {
1493
            } else if (spacingStyle == 2) {
1494
            }
1495
        }
1496

    
1497
        x = grp.getDataAsDouble(10);
1498
        y = grp.getDataAsDouble(20);
1499
        z = grp.getDataAsDouble(30);
1500

    
1501
        /*if (grp.hasCode(30)){
1502
            z = grp.getDataAsDouble(30);
1503
            Double doub = new Double(z);
1504
            String string = doub.toString();
1505
            feature.setProp("elevation", string);
1506
        } else {
1507
            Double doub = new Double(0.0);
1508
            feature.setProp("elevation", doub.toString());
1509
        }*/
1510
        if (grp.hasCode(210)) {
1511
            extx = grp.getDataAsDouble(210);
1512
        }
1513

    
1514
        if (grp.hasCode(220)) {
1515
            exty = grp.getDataAsDouble(220);
1516
        }
1517

    
1518
        if (grp.hasCode(230)) {
1519
            extz = grp.getDataAsDouble(230);
1520
        }
1521

    
1522
        Point3D point_in = new Point3D(x, y, z);
1523
        Point3D xtru = new Point3D(extx, exty, extz);
1524
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1525
        x = point_out.getX();
1526
        y = point_out.getY();
1527
        z = point_out.getZ();
1528

    
1529
        Double doub = new Double(z);
1530
        feature.setProp("elevation", doub.toString());
1531

    
1532
        if (z != 0.0) {
1533
            dxf3DFile = true;
1534
        }
1535

    
1536
        point.add(new Point3D(x, y, z));
1537
        feature.setGeometry(point);
1538

    
1539
        // 041130: Rellena las props con los atributos.
1540
        completeAttributes(feature);
1541

    
1542
        //features.add(feature);
1543
        if (addingToBlock == false) {
1544
            features.add(feature);
1545
        } else {
1546
            blk.add(feature);
1547
        }
1548
    }
1549

    
1550
    /* (non-Javadoc)
1551
     * @see org.cresques.io.DxfFile.EntityFactory#createPoint(org.cresques.io.DxfGroupVector)
1552
     */
1553
    public void createPoint(DxfGroupVector grp) throws Exception {
1554
        double x = 0.0;
1555
        double y = 0.0;
1556
        double z = 0.0;
1557
        DxfGroup g = null;
1558
        Point3D pt = null;
1559
        double extx = 0.0;
1560
        double exty = 0.0;
1561
        double extz = 1.0;
1562
        org.gvsig.dxf.px.gml.Point3D point = new org.gvsig.dxf.px.gml.Point3D();
1563
        Feature feature = new Feature();
1564

    
1565
        feature.setProp("dxfEntity", "Point");
1566

    
1567
        if (grp.hasCode(8)) {
1568
            feature.setProp("layer", grp.getDataAsString(8));
1569
        }
1570

    
1571
        if (grp.hasCode(39)) {
1572
            Double doub = new Double(grp.getDataAsDouble(39));
1573
            String string = doub.toString();
1574
            feature.setProp("thickness", string);
1575
        } else {
1576
            Double doub = new Double(0.0);
1577
            feature.setProp("thickness", doub.toString());
1578
        }
1579

    
1580
        if (grp.hasCode(62)) {
1581
            Integer integer = new Integer(grp.getDataAsInt(62));
1582
            String string = integer.toString();
1583
            feature.setProp("color", string);
1584
            feature.setProp("colorByLayer", "false");
1585
        } else {
1586
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1587
            int clr = layer.colorNumber;
1588
            Integer integer = new Integer(clr);
1589
            String string = integer.toString();
1590
            feature.setProp("color", string);
1591
            feature.setProp("colorByLayer", "true");
1592
        }
1593

    
1594
        x = grp.getDataAsDouble(10);
1595
        y = grp.getDataAsDouble(20);
1596
        z = grp.getDataAsDouble(30);
1597

    
1598
        /*if (grp.hasCode(30)) {
1599
            z = grp.getDataAsDouble(30);
1600
            Double doub = new Double(z);
1601
            String string = doub.toString();
1602
            feature.setProp("elevation", string);
1603
        } else {
1604
            Double doub = new Double(0.0);
1605
            feature.setProp("elevation", doub.toString());
1606
        }*/
1607
        if (grp.hasCode(210)) {
1608
            extx = grp.getDataAsDouble(210);
1609
        }
1610

    
1611
        if (grp.hasCode(220)) {
1612
            exty = grp.getDataAsDouble(220);
1613
        }
1614

    
1615
        if (grp.hasCode(230)) {
1616
            extz = grp.getDataAsDouble(230);
1617
        }
1618

    
1619
        Point3D point_in = new Point3D(x, y, z);
1620
        Point3D xtru = new Point3D(extx, exty, extz);
1621
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1622
        x = point_out.getX();
1623
        y = point_out.getY();
1624
        z = point_out.getZ();
1625

    
1626
        Double doub = new Double(z);
1627
        feature.setProp("elevation", doub.toString());
1628

    
1629
        if (z != 0.0) {
1630
            dxf3DFile = true;
1631
        }
1632

    
1633
        point.add(new Point3D(x, y, z));
1634
        feature.setGeometry(point);
1635

    
1636
        // 041130: Rellena las props con los atributos.
1637
        completeAttributes(feature);
1638

    
1639
        /*for (int i=0;i<attributes.size();i++) {
1640
            String[] att = new String[2];
1641
            att = (String[])attributes.get(i);
1642
            feature.setProp(att[0],att[1]);
1643
        }*/
1644

    
1645
        //features.add(feature);
1646
        if (addingToBlock == false) {
1647
            features.add(feature);
1648
        } else {
1649
            blk.add(feature);
1650
        }
1651
    }
1652

    
1653
    /* (non-Javadoc)
1654
     * @see org.cresques.io.DxfFile.EntityFactory#createCircle(org.cresques.io.DxfGroupVector)
1655
     */
1656
    public void createCircle(DxfGroupVector grp) throws Exception {
1657
        double x = 0.0;
1658
        double y = 0.0;
1659
        double z = 0.0;
1660
        double r = 0.0;
1661
        Point3D firstPt = new Point3D();
1662
        DxfGroup g = null;
1663
        double extx = 0.0;
1664
        double exty = 0.0;
1665
        double extz = 1.0;
1666
        LineString3D lineString3D = new LineString3D();
1667
        Polygon3D polygon3D = new Polygon3D();
1668
        Feature feaBordes = new Feature();
1669
        Feature feaFondos = new Feature();
1670

    
1671
        feaBordes.setProp("dxfEntity", "Circle");
1672
        feaFondos.setProp("dxfEntity", "Circle");
1673

    
1674
        if (grp.hasCode(8)) {
1675
            feaBordes.setProp("layer", grp.getDataAsString(8));
1676
        }
1677

    
1678
        feaFondos.setProp("layer", grp.getDataAsString(8));
1679

    
1680
        if (grp.hasCode(39)) {
1681
            Double doub = new Double(grp.getDataAsDouble(39));
1682
            String string = doub.toString();
1683
            feaBordes.setProp("thickness", string);
1684
            feaFondos.setProp("thickness", string);
1685
        } else {
1686
            Double doub = new Double(0.0);
1687
            feaBordes.setProp("thickness", doub.toString());
1688
            feaFondos.setProp("thickness", doub.toString());
1689
        }
1690

    
1691
        if (grp.hasCode(62)) {
1692
            Integer integer = new Integer(grp.getDataAsInt(62));
1693
            String string = integer.toString();
1694
            feaBordes.setProp("color", string);
1695
            feaFondos.setProp("color", string);
1696
            feaBordes.setProp("colorByLayer", "false");
1697
            feaFondos.setProp("colorByLayer", "false");
1698
        } else {
1699
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1700
            int clr = layer.colorNumber;
1701
            Integer integer = new Integer(clr);
1702
            String string = integer.toString();
1703
            feaBordes.setProp("color", string);
1704
            feaFondos.setProp("color", string);
1705
            feaBordes.setProp("colorByLayer", "true");
1706
            feaFondos.setProp("colorByLayer", "true");
1707
        }
1708

    
1709
        x = grp.getDataAsDouble(10);
1710
        y = grp.getDataAsDouble(20);
1711
        if (grp.hasCode(30)) {
1712
            z = grp.getDataAsDouble(30);
1713
        }
1714

    
1715

    
1716
        /*if (grp.hasCode(30)) {
1717
            z = grp.getDataAsDouble(30);
1718
            Double doub = new Double(z);
1719
            String string = doub.toString();
1720
            feaBordes.setProp("elevation", string);
1721
            feaFondos.setProp("elevation", string);
1722
        } else {
1723
            Double doub = new Double(0.0);
1724
            feaBordes.setProp("elevation", doub.toString());
1725
            feaFondos.setProp("elevation", doub.toString());
1726
        }*/
1727
        if (grp.hasCode(40)) {
1728
            r = grp.getDataAsDouble(40);
1729
        }
1730

    
1731
        if (grp.hasCode(210)) {
1732
            extx = grp.getDataAsDouble(210);
1733
        }
1734

    
1735
        if (grp.hasCode(220)) {
1736
            exty = grp.getDataAsDouble(220);
1737
        }
1738

    
1739
        if (grp.hasCode(230)) {
1740
            extz = grp.getDataAsDouble(230);
1741
        }
1742

    
1743
        Point3D point_in = new Point3D(x, y, z);
1744
        Point3D xtru = new Point3D(extx, exty, extz);
1745
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1746
        x = point_out.getX();
1747
        y = point_out.getY();
1748
        z = point_out.getZ();
1749

    
1750
        Double doub = new Double(z);
1751
        feaBordes.setProp("elevation", doub.toString());
1752
        feaFondos.setProp("elevation", doub.toString());
1753

    
1754
        if (z != 0.0) {
1755
            dxf3DFile = true;
1756
        }
1757

    
1758
        Point2D c = proj.createPoint(x, y);
1759
        Point3D center = new Point3D(c.getX(), c.getY(), z);
1760
        Point3D[] pts = new Point3D[360];
1761
        int angulo = 0;
1762

    
1763
        for (angulo = 0; angulo < 360; angulo++) {
1764
            pts[angulo] = new Point3D(center.getX(), center.getY(),
1765
                                      center.getZ());
1766
            pts[angulo] = new Point3D(pts[angulo].getX() +
1767
                                      (r * Math.sin((angulo * Math.PI) / 180.0)),
1768
                                      pts[angulo].getY() +
1769
                                      (r * Math.cos((angulo * Math.PI) / 180.0)),
1770
                                      center.getZ());
1771

    
1772
            if (pts.length == 1) {
1773
                firstPt = pts[angulo];
1774
            }
1775
        }
1776

    
1777
        for (int i = 0; i < pts.length; i++) {
1778
            lineString3D.add(pts[i]);
1779
            polygon3D.add(pts[i]);
1780
        }
1781

    
1782
        feaBordes.setGeometry(lineString3D);
1783
        feaFondos.setGeometry(polygon3D);
1784

    
1785
        // 041130: Rellena las props con los atributos.
1786
        completeAttributes(feaBordes);
1787
        completeAttributes(feaFondos);
1788

    
1789
        //features.add(feature);
1790
        if (addingToBlock == false) {
1791
            //features.add(feaBordes);
1792
            features.add(feaFondos);
1793
        } else {
1794
            //blk.add(feaBordes);
1795
            blk.add(feaFondos);
1796
        }
1797
    }
1798

    
1799
    /* (non-Javadoc)
1800
     * @see org.cresques.io.DxfFile.EntityFactory#createArc(org.cresques.io.DxfGroupVector)
1801
     */
1802
    public void createArc(DxfGroupVector grp) throws Exception {
1803
        double x = 0.0;
1804
        double y = 0.0;
1805
        double z = 0.0;
1806
        double r = 0.0;
1807
        double empieza = 0.0;
1808
        double acaba = 0.0;
1809
        DxfGroup g = null;
1810
        double extx = 0.0;
1811
        double exty = 0.0;
1812
        double extz = 1.0;
1813
        LineString3D lineString3D = new LineString3D();
1814
        Feature feature = new Feature();
1815

    
1816
        feature.setProp("dxfEntity", "Arc");
1817

    
1818
        if (grp.hasCode(8)) {
1819
            feature.setProp("layer", grp.getDataAsString(8));
1820
        }
1821

    
1822
        if (grp.hasCode(39)) {
1823
            Double doub = new Double(grp.getDataAsDouble(39));
1824
            String string = doub.toString();
1825
            feature.setProp("thickness", string);
1826
        } else {
1827
            Double doub = new Double(0.0);
1828
            feature.setProp("thickness", doub.toString());
1829
        }
1830

    
1831
        if (grp.hasCode(62)) {
1832
            Integer integer = new Integer(grp.getDataAsInt(62));
1833
            String string = integer.toString();
1834
            feature.setProp("color", string);
1835
            feature.setProp("colorByLayer", "false");
1836
        } else {
1837
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1838
            int clr = layer.colorNumber;
1839
            Integer integer = new Integer(clr);
1840
            String string = integer.toString();
1841
            feature.setProp("color", string);
1842
            feature.setProp("colorByLayer", "true");
1843
        }
1844

    
1845
        x = grp.getDataAsDouble(10);
1846
        y = grp.getDataAsDouble(20);
1847
        if (grp.hasCode(30))
1848
        {
1849
                z = grp.getDataAsDouble(30);
1850
        }
1851

    
1852
        /*if (grp.hasCode(30)) {
1853
            z = grp.getDataAsDouble(30);
1854
            Double doub = new Double(z);
1855
            String string = doub.toString();
1856
            feature.setProp("elevation", string);
1857
        } else {
1858
            Double doub = new Double(0.0);
1859
            feature.setProp("elevation", doub.toString());
1860
        }*/
1861
        if (grp.hasCode(40)) {
1862
            r = grp.getDataAsDouble(40);
1863
        }
1864

    
1865
        if (grp.hasCode(50)) {
1866
            empieza = grp.getDataAsDouble(50);
1867
        }
1868

    
1869
        if (grp.hasCode(51)) {
1870
            acaba = grp.getDataAsDouble(51);
1871
        }
1872

    
1873
        if (grp.hasCode(210)) {
1874
            extx = grp.getDataAsDouble(210);
1875
        }
1876

    
1877
        if (grp.hasCode(220)) {
1878
            exty = grp.getDataAsDouble(220);
1879
        }
1880

    
1881
        if (grp.hasCode(230)) {
1882
            extz = grp.getDataAsDouble(230);
1883
        }
1884

    
1885
        Point3D point_in = new Point3D(x, y, z);
1886
        Point3D xtru = new Point3D(extx, exty, extz);
1887
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1888
        x = point_out.getX();
1889
        y = point_out.getY();
1890
        z = point_out.getZ();
1891

    
1892
        Double doub = new Double(z);
1893
        feature.setProp("elevation", doub.toString());
1894

    
1895
        if (z != 0.0) {
1896
            dxf3DFile = true;
1897
        }
1898

    
1899
        Point2D c = proj.createPoint(x, y);
1900
        Point3D center = new Point3D(c.getX(), c.getY(), z);
1901

    
1902
        int iempieza = (int) empieza;
1903
        int iacaba = (int) acaba;
1904

    
1905
        double angulo = 0;
1906
        Point3D[] pts = null;
1907

    
1908
        if (empieza <= acaba) {
1909
            pts = new Point3D[(iacaba - iempieza) + 2];
1910
            angulo = empieza;
1911
            pts[0] = new Point3D(center.getX() +
1912
                                 (r * Math.cos((angulo * Math.PI) / 180.0)),
1913
                                 center.getY() +
1914
                                 (r * Math.sin((angulo * Math.PI) / 180.0)),
1915
                                 center.getZ());
1916

    
1917
            for (int i = 1; i <= ((iacaba - iempieza) + 1); i++) {
1918
                angulo = (iempieza + i);
1919
                pts[i] = new Point3D(center.getX() +
1920
                                     (r * Math.cos((angulo * Math.PI) / 180.0)),
1921
                                     center.getY() +
1922
                                     (r * Math.sin((angulo * Math.PI) / 180.0)),
1923
                                     center.getZ());
1924
            }
1925

    
1926
            angulo = acaba;
1927
            pts[(iacaba - iempieza) + 1] = new Point3D(center.getX() +
1928
                                                       (r * Math.cos((angulo * Math.PI) / 180.0)),
1929
                                                       center.getY() +
1930
                                                       (r * Math.sin((angulo * Math.PI) / 180.0)),
1931
                                                       center.getZ());
1932
        } else {
1933
            pts = new Point3D[(360 - iempieza) + iacaba + 2];
1934
            angulo = empieza;
1935

    
1936
            pts[0] = new Point3D(center.getX() +
1937
                                 (r * Math.cos((angulo * Math.PI) / 180.0)),
1938
                                 center.getY() +
1939
                                 (r * Math.sin((angulo * Math.PI) / 180.0)),
1940
                                 center.getZ());
1941

    
1942
            for (int i = 1; i <= (360 - iempieza); i++) {
1943
                angulo = (iempieza + i);
1944
                pts[i] = new Point3D(center.getX() +
1945
                                     (r * Math.cos((angulo * Math.PI) / 180.0)),
1946
                                     center.getY() +
1947
                                     (r * Math.sin((angulo * Math.PI) / 180.0)),
1948
                                     center.getZ());
1949
            }
1950

    
1951
            for (int i = (360 - iempieza) + 1;
1952
                     i <= ((360 - iempieza) + iacaba); i++) {
1953
                angulo = (i - (360 - iempieza));
1954
                pts[i] = new Point3D(center.getX() +
1955
                                     (r * Math.cos((angulo * Math.PI) / 180.0)),
1956
                                     center.getY() +
1957
                                     (r * Math.sin((angulo * Math.PI) / 180.0)),
1958
                                     center.getZ());
1959
            }
1960

    
1961
            angulo = acaba;
1962
            pts[(360 - iempieza) + iacaba + 1] = new Point3D(center.getX() +
1963
                                                             (r * Math.cos((angulo * Math.PI) / 180.0)),
1964
                                                             center.getY() +
1965
                                                             (r * Math.sin((angulo * Math.PI) / 180.0)),
1966
                                                             center.getZ());
1967
        }
1968

    
1969
        for (int i = 0; i < pts.length; i++) {
1970
            lineString3D.add(pts[i]);
1971
        }
1972

    
1973
        feature.setGeometry(lineString3D);
1974

    
1975
        // 041130: Rellena las props con los atributos.
1976
        completeAttributes(feature);
1977

    
1978
        //features.add(feature);
1979
        if (addingToBlock == false) {
1980
            features.add(feature);
1981
        } else {
1982
            blk.add(feature);
1983
        }
1984
    }
1985

    
1986
    /* (non-Javadoc)
1987
     * @see org.cresques.io.DxfFile.EntityFactory#createInsert(org.cresques.io.DxfGroupVector)
1988
     */
1989
    public void createInsert(DxfGroupVector grp) throws Exception {
1990
        double x = 0.0;
1991
        double y = 0.0;
1992
        double z = 0.0;
1993
        DxfGroup g = null;
1994
        Point3D pt = new Point3D(0.0, 0.0, 0.0);
1995
        Point3D scaleFactor = new Point3D(1.0, 1.0, 1.0);
1996
        double rotAngle = 0.0;
1997
        String blockName = "";
1998
        double extx = 0.0;
1999
        double exty = 0.0;
2000
        double extz = 1.0;
2001

    
2002
        InsPoint3D insert = new InsPoint3D();
2003
        Feature feature = new Feature();
2004
        org.gvsig.dxf.px.gml.Point3D secondGeom = new org.gvsig.dxf.px.gml.Point3D();
2005
        Feature secondFeat = new Feature();
2006
        int attributesFollowFlag = 0;
2007

    
2008
        feature.setProp("dxfEntity", "Insert");
2009
        secondFeat.setProp("dxfEntity", "Insert");
2010

    
2011
        if (grp.hasCode(2)) {
2012
            blockName = grp.getDataAsString(2);
2013

    
2014
            //feature.setProp("blockName", blockName);
2015
            insert.setBlockName(blockName);
2016
        }
2017

    
2018
        if (grp.hasCode(8)) {
2019
            feature.setProp("layer", grp.getDataAsString(8));
2020
            secondFeat.setProp("layer", grp.getDataAsString(8));
2021
        }
2022

    
2023
        Double doub = new Double(0.0);
2024
        secondFeat.setProp("thickness", doub.toString());
2025

    
2026
        if (grp.hasCode(62)) {
2027
            Integer integer = new Integer(grp.getDataAsInt(62));
2028
            String string = integer.toString();
2029
            feature.setProp("color", string);
2030
            secondFeat.setProp("color", string);
2031
            feature.setProp("colorByLayer", "false");
2032
            secondFeat.setProp("colorByLayer", "false");
2033
        } else {
2034
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2035
            int clr = layer.colorNumber;
2036
            Integer integer = new Integer(clr);
2037
            String string = integer.toString();
2038
            feature.setProp("color", string);
2039
            secondFeat.setProp("color", string);
2040
            feature.setProp("colorByLayer", "true");
2041
            secondFeat.setProp("colorByLayer", "true");
2042
        }
2043

    
2044
        if (grp.hasCode(66)) {
2045
            attributesFollowFlag = grp.getDataAsInt(66);
2046
        }
2047

    
2048
        x = grp.getDataAsDouble(10);
2049
        y = grp.getDataAsDouble(20);
2050
        z = grp.getDataAsDouble(30);
2051

    
2052
        /*if (grp.hasCode(30)) {
2053
            z = grp.getDataAsDouble(30);
2054
            Double doubz = new Double(z);
2055
            String string = doubz.toString();
2056
            feature.setProp("elevation", string);
2057
            secondFeat.setProp("elevation", string);
2058
        } else {
2059
            Double elev = new Double(z);
2060
            //feature.setProp("elevation", doub.toString());
2061
            feature.setProp("elevation", elev.toString());
2062
            secondFeat.setProp("elevation", elev.toString());
2063
        }*/
2064
        if (grp.hasCode(41)) {
2065
            scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
2066
            insert.setScaleFactor(scaleFactor);
2067
        } else {
2068
            insert.setScaleFactor(scaleFactor);
2069
        }
2070

    
2071
        if (grp.hasCode(42)) {
2072
            scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
2073
            insert.setScaleFactor(scaleFactor);
2074
        } else {
2075
            insert.setScaleFactor(scaleFactor);
2076
        }
2077

    
2078
        if (grp.hasCode(43)) {
2079
            scaleFactor = new Point3D(scaleFactor.getX(), scaleFactor.getY(),
2080
                                      grp.getDataAsDouble(43));
2081
            insert.setScaleFactor(scaleFactor);
2082
        } else {
2083
            insert.setScaleFactor(scaleFactor);
2084
        }
2085

    
2086
        if (grp.hasCode(50)) {
2087
            rotAngle = grp.getDataAsDouble(50);
2088
            insert.setRotAngle(rotAngle);
2089
        }
2090

    
2091
        if (grp.hasCode(210)) {
2092
            extx = grp.getDataAsDouble(210);
2093
        }
2094

    
2095
        if (grp.hasCode(220)) {
2096
            exty = grp.getDataAsDouble(220);
2097
        }
2098

    
2099
        if (grp.hasCode(230)) {
2100
            extz = grp.getDataAsDouble(230);
2101
        }
2102

    
2103
        Point3D point_in = new Point3D(x, y, z);
2104
        Point3D xtru = new Point3D(extx, exty, extz);
2105
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
2106
        x = point_out.getX();
2107
        y = point_out.getY();
2108
        z = point_out.getZ();
2109

    
2110
        Double doubz = new Double(z);
2111
        feature.setProp("elevation", doubz.toString());
2112
        secondFeat.setProp("elevation", doubz.toString());
2113

    
2114
        if (z != 0.0) {
2115
            dxf3DFile = true;
2116
        }
2117

    
2118
        insert.setBlkList(blkList);
2119

    
2120
        insert.encuentraBloque(blockName);
2121

    
2122
        insert.add(new Point3D(x, y, z));
2123
        secondGeom.add(new Point3D(x, y, z));
2124

    
2125
        feature.setGeometry(insert);
2126
        secondFeat.setGeometry(secondGeom);
2127

    
2128
        // 041130: Rellena las props con los atributos.
2129
        completeAttributes(feature);
2130
        completeAttributes(secondFeat);
2131

    
2132
        /*for (int i=0;i<attributes.size();i++) {
2133
            String[] att = new String[2];
2134
            att = (String[])attributes.get(i);
2135
            secondFeat.setProp(att[0],att[1]);
2136
        }*/
2137
        if ((insert.getBlockFound() == true) && (attributesFollowFlag != 1)) {
2138
            gestionaInsert(feature);
2139
        }
2140

    
2141
        //if (addingToBlock == false) {
2142
        //features.add(secondFeat);
2143
        //}
2144
        //if (addingToBlock == true/* && insert.getBlockFound() == true*/) {
2145
        //blk.add(feature);
2146
        //}
2147
        // 041129: A�adido para implementar los ATTRIBS.
2148
        if (attributesFollowFlag == 1) {
2149
            isDoubleFeatured = true;
2150
            lastFeaBordes = feature;
2151
            lastFeaFondos = secondFeat;
2152
        } else {
2153
            if (addingToBlock == false) {
2154
                features.add(secondFeat);
2155
            }
2156

    
2157
            if (addingToBlock == true /* && insert.getBlockFound() == true*/) {
2158
                blk.add(feature);
2159
            }
2160
        }
2161
    }
2162

    
2163
    /* (non-Javadoc)
2164
     * @see org.cresques.io.DxfFile.EntityFactory#createSolid(org.cresques.io.DxfGroupVector)
2165
     */
2166
    public void createSolid(DxfGroupVector grp) throws Exception {
2167
        double x = 0.0;
2168
        double y = 0.0;
2169
        double z1 = 0.0;
2170
        double z2 = 0.0;
2171
        double z3 = 0.0;
2172
        double z4 = 0.0;
2173
        DxfGroup g = null;
2174

    
2175
        //Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
2176
        Point3D[] pts = new Point3D[4];
2177

    
2178
        //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2179
        double extx = 0.0;
2180
        double exty = 0.0;
2181
        double extz = 1.0;
2182

    
2183
        LineString3D lineString3D = new LineString3D();
2184
        Polygon3D polygon3D = new Polygon3D();
2185
        Feature feaBordes = new Feature();
2186
        Feature feaFondos = new Feature();
2187

    
2188
        //double elev = 0;
2189
        feaBordes.setProp("dxfEntity", "Solid");
2190
        feaFondos.setProp("dxfEntity", "Solid");
2191

    
2192
        if (grp.hasCode(8)) {
2193
            feaBordes.setProp("layer", grp.getDataAsString(8));
2194
        }
2195

    
2196
        feaFondos.setProp("layer", grp.getDataAsString(8));
2197
        x = grp.getDataAsDouble(10);
2198
        y = grp.getDataAsDouble(20);
2199
        z1 = grp.getDataAsDouble(30);
2200

    
2201
        /*if (grp.hasCode(30)) {
2202
            z1 = grp.getDataAsDouble(30);
2203
        } else {
2204
            Double doub = new Double(0.0);
2205
            feaBordes.setProp("elevation", doub.toString());
2206
            feaFondos.setProp("elevation", doub.toString());
2207
        }*/
2208
        Point2D pto = proj.createPoint(x, y);
2209
        Point3D pto3D = new Point3D(pto.getX(), pto.getY(), z1);
2210
        pts[0] = pto3D;
2211
        x = grp.getDataAsDouble(11);
2212
        y = grp.getDataAsDouble(21);
2213
        z2 = grp.getDataAsDouble(31);
2214
        pto = proj.createPoint(x, y);
2215
        pto3D = new Point3D(pto.getX(), pto.getY(), z2);
2216
        pts[1] = pto3D;
2217
        x = grp.getDataAsDouble(12);
2218
        y = grp.getDataAsDouble(22);
2219
        z3 = grp.getDataAsDouble(32);
2220
        pto = proj.createPoint(x, y);
2221
        pto3D = new Point3D(pto.getX(), pto.getY(), z3);
2222
        pts[2] = pto3D;
2223

    
2224
        if (grp.hasCode(13)) {
2225
            x = grp.getDataAsDouble(13);
2226
        }
2227

    
2228
        if (grp.hasCode(23)) {
2229
            y = grp.getDataAsDouble(23);
2230
        }
2231

    
2232
        if (grp.hasCode(33)) {
2233
            z4 = grp.getDataAsDouble(33);
2234
        }
2235

    
2236
        pto = proj.createPoint(x, y);
2237
        pto3D = new Point3D(pto.getX(), pto.getY(), z4);
2238
        pts[3] = pto3D;
2239

    
2240
        if (grp.hasCode(39)) {
2241
            Double doub = new Double(grp.getDataAsDouble(39));
2242
            String string = doub.toString();
2243
            feaBordes.setProp("thickness", string);
2244
            feaFondos.setProp("thickness", string);
2245
        } else {
2246
            Double doub = new Double(0.0);
2247
            feaBordes.setProp("thickness", doub.toString());
2248
            feaFondos.setProp("thickness", doub.toString());
2249
        }
2250

    
2251
        if (grp.hasCode(62)) {
2252
            Integer integer = new Integer(grp.getDataAsInt(62));
2253
            String string = integer.toString();
2254
            feaBordes.setProp("color", string);
2255
            feaFondos.setProp("color", string);
2256
            feaBordes.setProp("colorByLayer", "false");
2257
            feaFondos.setProp("colorByLayer", "false");
2258
        } else {
2259
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2260
            int clr = layer.colorNumber;
2261
            Integer integer = new Integer(clr);
2262
            String string = integer.toString();
2263
            feaBordes.setProp("color", string);
2264
            feaFondos.setProp("color", string);
2265
            feaBordes.setProp("colorByLayer", "true");
2266
            feaFondos.setProp("colorByLayer", "true");
2267
        }
2268

    
2269
        if (grp.hasCode(210)) {
2270
            extx = grp.getDataAsDouble(210);
2271
        }
2272

    
2273
        if (grp.hasCode(220)) {
2274
            exty = grp.getDataAsDouble(220);
2275
        }
2276

    
2277
        if (grp.hasCode(230)) {
2278
            extz = grp.getDataAsDouble(230);
2279
        }
2280

    
2281
        Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1);
2282
        Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2);
2283
        Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3);
2284
        Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4);
2285
        Point3D xtru = new Point3D(extx, exty, extz);
2286
        Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
2287
        Point3D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
2288
        Point3D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
2289
        Point3D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
2290
        pts[0] = new Point3D(point_out1);
2291
        pts[1] = new Point3D(point_out2);
2292
        pts[2] = new Point3D(point_out3);
2293
        pts[3] = new Point3D(point_out4);
2294

    
2295
        if ((pts[0].getZ() != 0.0) || (pts[1].getZ() != 0.0) ||
2296
                (pts[2].getZ() != 0.0) || (pts[3].getZ() != 0.0)) {
2297
            dxf3DFile = true;
2298
        }
2299

    
2300
        Point3D aux = new Point3D(pts[2]);
2301
        pts[2] = new Point3D(pts[3]);
2302
        pts[3] = aux;
2303

    
2304
        Double doub = new Double(0.0);
2305
        if ((pts[0].getZ() == pts[1].getZ()) &&
2306
                (pts[1].getZ() == pts[2].getZ()) &&
2307
                (pts[2].getZ() == pts[3].getZ())) {
2308
            doub = new Double(pts[0].getZ());
2309
        }
2310
        String string = doub.toString();
2311
        feaBordes.setProp("elevation", string);
2312
        feaFondos.setProp("elevation", string);
2313

    
2314
        for (int i = 0; i < pts.length; i++) {
2315
            lineString3D.add(pts[i]);
2316
            polygon3D.add(pts[i]);
2317
        }
2318

    
2319
        // Para cerrarlos.
2320
        lineString3D.add(pts[0]);
2321
        polygon3D.add(pts[0]);
2322

    
2323
        feaBordes.setGeometry(lineString3D);
2324
        feaFondos.setGeometry(polygon3D);
2325

    
2326
        // 041130: Rellena las props con los atributos.
2327
        completeAttributes(feaBordes);
2328
        completeAttributes(feaFondos);
2329

    
2330
        //features.add(feature);
2331
        if (addingToBlock == false) {
2332
            //features.add(feaBordes);
2333
            features.add(feaFondos);
2334
        } else {
2335
            //blk.add(feaBordes);
2336
            blk.add(feaFondos);
2337
        }
2338
    }
2339

    
2340
    /* (non-Javadoc)
2341
     * @see org.cresques.io.DxfFile.EntityFactory#createSpline(org.cresques.io.DxfGroupVector)
2342
     */
2343
    public void createSpline(DxfGroupVector grp) throws Exception {
2344
        double x = 0.0; //elev = 0.0;
2345
        double y = 0.0; //elev = 0.0;
2346
        double z = 0.0; //elev = 0.0;
2347

    
2348
        //double elev = 0.0;
2349
        DxfGroup g = null;
2350
        LineString3D lineString3D = new LineString3D();
2351
        Polygon3D polygon3D = new Polygon3D();
2352

    
2353
        //Geometry geometria;
2354
        //Feature feature= new Feature();
2355
        Feature feaBordes = new Feature();
2356
        Feature feaFondos = new Feature();
2357
        int flags = 0;
2358

    
2359
        //feature.setProp("dxfEntity", "LwPolyline");
2360
        feaBordes.setProp("dxfEntity", "Spline");
2361
        feaFondos.setProp("dxfEntity", "Spline");
2362

    
2363
        if (grp.hasCode(8)) {
2364
            //feature.setProp("layer", grp.getDataAsString(8));
2365
            feaBordes.setProp("layer", grp.getDataAsString(8));
2366
            feaFondos.setProp("layer", grp.getDataAsString(8));
2367
        }
2368

    
2369
        if (grp.hasCode(39)) {
2370
            Double doub = new Double(grp.getDataAsDouble(39));
2371
            String string = doub.toString();
2372

    
2373
            //feature.setProp("thickness", string);
2374
            feaBordes.setProp("thickness", string);
2375
            feaFondos.setProp("thickness", string);
2376
        } else {
2377
            Double doub = new Double(0.0);
2378

    
2379
            //feature.setProp("thickness", doub.toString());
2380
            feaBordes.setProp("thickness", doub.toString());
2381
            feaFondos.setProp("thickness", doub.toString());
2382
        }
2383

    
2384
        if (grp.hasCode(62)) {
2385
            Integer integer = new Integer(grp.getDataAsInt(62));
2386
            String string = integer.toString();
2387

    
2388
            //feature.setProp("color", string);
2389
            feaBordes.setProp("color", string);
2390
            feaFondos.setProp("color", string);
2391
            feaBordes.setProp("colorByLayer", "false");
2392
            feaFondos.setProp("colorByLayer", "false");
2393
        } else {
2394
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2395
            int clr = layer.colorNumber;
2396
            Integer integer = new Integer(clr);
2397
            String string = integer.toString();
2398

    
2399
            //feature.setProp("color", string);
2400
            feaBordes.setProp("color", string);
2401
            feaFondos.setProp("color", string);
2402
            feaBordes.setProp("colorByLayer", "true");
2403
            feaFondos.setProp("colorByLayer", "true");
2404
        }
2405

    
2406
        if (grp.hasCode(70)) {
2407
            flags = grp.getDataAsInt(70);
2408
        }
2409

    
2410
        if ((flags & 0x01) == 0x01) {
2411
            //geometria = new Polygon();
2412
            feaBordes.setGeometry(lineString3D);
2413
            feaFondos.setGeometry(polygon3D);
2414
            isDoubleFeatured = true;
2415
        } else {
2416
            //geometria = new LineString();
2417
            feaBordes.setGeometry(lineString3D);
2418
            isDoubleFeatured = false;
2419
        }
2420

    
2421
        int j = 0;
2422
        double firstX = 0.0;
2423
        double firstY = 0.0;
2424
        double firstZ = 0.0;
2425

    
2426
        for (int i = 0; i < grp.size(); i++) {
2427
            g = (DxfGroup) grp.get(i);
2428

    
2429
            if (g.getCode() == 10) {
2430
                j++;
2431
                x = ((Double) g.getData()).doubleValue();
2432
            } else if (g.getCode() == 20) {
2433
                y = ((Double) g.getData()).doubleValue();
2434
            } else if (g.getCode() == 30) {
2435
                z = ((Double) g.getData()).doubleValue();
2436

    
2437
                Point2D p = proj.createPoint(x, y);
2438
                Point3D p3d = new Point3D(p.getX(), p.getY(), z);
2439
                lineString3D.add(p3d);
2440

    
2441
                if (isDoubleFeatured) {
2442
                    polygon3D.add(p3d);
2443
                }
2444

    
2445
                if (j == 1) {
2446
                    firstX = x;
2447
                    firstY = y;
2448
                    firstZ = z;
2449
                }
2450

    
2451
                //elev = z;
2452
                x = 0.0;
2453
                y = 0.0;
2454
                z = 0.0;
2455
            }
2456
        }
2457

    
2458
        //Double doub = new Double(elev);
2459
        //String string = doub.toString();
2460
        //feature.setProp("elevation", string);
2461
        //feaBordes.setProp("elevation", string);
2462
        //feaFondos.setProp("elevation", string);
2463
        if (isDoubleFeatured) {
2464
            Point2D p = proj.createPoint(firstX, firstY);
2465
            Point3D p3d = new Point3D(p.getX(), p.getY(), z);
2466
            lineString3D.add(p3d);
2467
            polygon3D.add(p3d);
2468
        }
2469

    
2470
        double zprev = 0;
2471
        boolean constSplineElev = true;
2472

    
2473
        for (int i = 0; i < lineString3D.pointNr(); i++) {
2474
            z = lineString3D.getPoint3D(i).getZ();
2475

    
2476
            if (z != 0.0) {
2477
                dxf3DFile = true;
2478
            }
2479

    
2480
            if ((i > 0) && (z != zprev)) {
2481
                constSplineElev = false;
2482
            }
2483

    
2484
            zprev = z;
2485
        }
2486

    
2487
        if (constSplineElev) {
2488
            Double doub = new Double(lineString3D.getPoint3D(0).getZ());
2489
            String string = doub.toString();
2490
            feaBordes.setProp("elevation", string);
2491

    
2492
            if (isDoubleFeatured) {
2493
                feaFondos.setProp("elevation", string);
2494
            }
2495
        } else {
2496
            Double doub = new Double(0.0);
2497
            String string = doub.toString();
2498
            feaBordes.setProp("elevation", string);
2499

    
2500
            if (isDoubleFeatured) {
2501
                feaFondos.setProp("elevation", string);
2502
            }
2503
        }
2504

    
2505
        lastFeaBordes = feaBordes;
2506

    
2507
        if (isDoubleFeatured) {
2508
            lastFeaFondos = feaFondos;
2509
        }
2510

    
2511
        // 041130: Rellena las props con los atributos.
2512
        completeAttributes(feaBordes);
2513
        completeAttributes(feaFondos);
2514

    
2515
        //features.add(feature);
2516
        if (addingToBlock == false) {
2517
            if (isDoubleFeatured) {
2518
                features.add(feaFondos);
2519
            } else {
2520
                features.add(feaBordes);
2521
            }
2522
        } else {
2523
            if (isDoubleFeatured) {
2524
                blk.add(feaFondos);
2525
            } else {
2526
                blk.add(feaBordes);
2527
            }
2528
        }
2529

    
2530
        isDoubleFeatured = false;
2531
    }
2532

    
2533
    /* (non-Javadoc)
2534
     * @see org.cresques.io.DxfFile.EntityFactory#createAttdef(org.cresques.io.DxfGroupVector)
2535
     */
2536
    public void createAttdef(DxfGroupVector grp) throws Exception {
2537
        DxfGroup g = null;
2538

    
2539
        String defaultValue = "";
2540
        String tagString = "";
2541
        String textStyleName = "";
2542
        String[] attribute = new String[2];
2543
        boolean tagDefined = false;
2544
        boolean defValDefined = false;
2545

    
2546
        if (grp.hasCode(1)) {
2547
            defaultValue = grp.getDataAsString(1);
2548
            attribute[1] = DxfConvTexts.ConvertText(defaultValue);
2549
            defValDefined = true;
2550

    
2551
            if (tagDefined) {
2552
                attributes.add(attribute);
2553
            }
2554
        }
2555

    
2556
        if (grp.hasCode(2)) {
2557
            tagString = grp.getDataAsString(2);
2558
            attribute[0] = DxfConvTexts.ConvertText(tagString);
2559
            tagDefined = true;
2560

    
2561
            if (defValDefined) {
2562
                attributes.add(attribute);
2563
            }
2564
        }
2565

    
2566
        if (grp.hasCode(7)) {
2567
            textStyleName = grp.getDataAsString(7);
2568
            textStyleName = DxfConvTexts.ConvertText(textStyleName);
2569
        }
2570

    
2571
        setNewAttributes();
2572
    }
2573

    
2574
    /* (non-Javadoc)
2575
     * @see org.cresques.io.DxfFile.EntityFactory#createAttrib(org.cresques.io.DxfGroupVector)
2576
     */
2577
    public void createAttrib(DxfGroupVector grp) throws Exception {
2578
        double x = 0.0;
2579
        double y = 0.0;
2580
        double z = 0.0;
2581
        double h = 0.0;
2582
        double rot = 0.0;
2583
        DxfGroup g = null;
2584

    
2585
        //Point2D pt1 = null, pt2 = null;
2586
        Point3D pt = null;
2587
        org.gvsig.dxf.px.gml.Point3D point = new org.gvsig.dxf.px.gml.Point3D();
2588

    
2589
        point.setTextPoint(true);
2590

    
2591
        String defaultValue = "";
2592
        String tagString = "";
2593
        String textStyleName = "";
2594
        String[] att = new String[2];
2595
        boolean tagDefined = false;
2596
        boolean defValDefined = false;
2597
        int attributeFlags = 0;
2598

    
2599
        double extx = 0.0;
2600
        double exty = 0.0;
2601
        double extz = 1.0;
2602

    
2603
        Feature insFea = lastFeaBordes;
2604
        Feature ptFea = lastFeaFondos;
2605

    
2606
        Feature feature = new Feature();
2607

    
2608
        feature.setProp("dxfEntity", "Attrib"); // <-- Es un INSERT con attributes.
2609

    
2610
        if (grp.hasCode(8)) {
2611
            feature.setProp("layer", grp.getDataAsString(8));
2612
        }
2613

    
2614
        if (grp.hasCode(39)) {
2615
            Double doub = new Double(grp.getDataAsDouble(39));
2616
            String string = doub.toString();
2617
            feature.setProp("thickness", string);
2618
        } else {
2619
            Double doub = new Double(0.0);
2620
            feature.setProp("thickness", doub.toString());
2621
        }
2622

    
2623
        if (grp.hasCode(62)) {
2624
            Integer integer = new Integer(grp.getDataAsInt(62));
2625
            String string = integer.toString();
2626
            feature.setProp("color", string);
2627
            feature.setProp("colorByLayer", "false");
2628
        } else {
2629
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2630
            int clr = layer.colorNumber;
2631
            Integer integer = new Integer(clr);
2632
            String string = integer.toString();
2633
            feature.setProp("color", string);
2634
            feature.setProp("colorByLayer", "true");
2635
        }
2636

    
2637
        if (grp.hasCode(1)) {
2638
            String strAux1 = grp.getDataAsString(1);
2639
            strAux1 = DxfConvTexts.ConvertText(strAux1);
2640
            defaultValue = strAux1;
2641
            att[1] = DxfConvTexts.ConvertText(defaultValue);
2642
            defValDefined = true;
2643

    
2644
            if (tagDefined) {
2645
                insFea.setProp(att[0], att[1]);
2646
                ptFea.setProp(att[0], att[1]);
2647
            }
2648

    
2649
            feature.setProp("text", strAux1);
2650
        }
2651

    
2652
        if (grp.hasCode(2)) {
2653
            String strAux2 = grp.getDataAsString(2);
2654
            strAux2 = DxfConvTexts.ConvertText(strAux2);
2655
            tagString = strAux2;
2656
            att[0] = DxfConvTexts.ConvertText(tagString);
2657
            tagDefined = true;
2658

    
2659
            if (defValDefined) {
2660
                insFea.setProp(att[0], att[1]);
2661
                ptFea.setProp(att[0], att[1]);
2662
            }
2663
        }
2664

    
2665
        if (grp.hasCode(7)) {
2666
            textStyleName = grp.getDataAsString(7);
2667
            textStyleName = DxfConvTexts.ConvertText(textStyleName);
2668
        }
2669

    
2670
        if (grp.hasCode(70)) {
2671
            attributeFlags = grp.getDataAsInt(70);
2672
        }
2673

    
2674
        if (grp.hasCode(40)) {
2675
            Double heightD = new Double(grp.getDataAsDouble(40));
2676
            String heightS = heightD.toString();
2677
            feature.setProp("textHeight", heightS);
2678
        } else {
2679
            feature.setProp("textHeight", "20.0");
2680
        }
2681

    
2682
        if (grp.hasCode(50)) {
2683
            Double rotD = new Double(grp.getDataAsDouble(50));
2684
            String rotS = rotD.toString();
2685
            feature.setProp("textRotation", rotS);
2686
        } else {
2687
            feature.setProp("textRotation", "0.0");
2688
        }
2689

    
2690
        x = grp.getDataAsDouble(10);
2691
        y = grp.getDataAsDouble(20);
2692
        z = grp.getDataAsDouble(30);
2693

    
2694
        /*if (grp.hasCode(30)){
2695
            z = grp.getDataAsDouble(30);
2696
            Double doub = new Double(z);
2697
            String string = doub.toString();
2698
            feature.setProp("elevation", string);
2699
        } else {
2700
            Double doub = new Double(0.0);
2701
            feature.setProp("elevation", doub.toString());
2702
        }*/
2703
        if (grp.hasCode(210)) {
2704
            extx = grp.getDataAsDouble(210);
2705
        }
2706

    
2707
        if (grp.hasCode(220)) {
2708
            exty = grp.getDataAsDouble(220);
2709
        }
2710

    
2711
        if (grp.hasCode(230)) {
2712
            extz = grp.getDataAsDouble(230);
2713
        }
2714

    
2715
        Point3D point_in = new Point3D(x, y, z);
2716
        Point3D xtru = new Point3D(extx, exty, extz);
2717
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
2718
        x = point_out.getX();
2719
        y = point_out.getY();
2720
        z = point_out.getZ();
2721

    
2722
        Double doub = new Double(z);
2723
        feature.setProp("elevation", doub.toString());
2724

    
2725
        if (z != 0.0) {
2726
            dxf3DFile = true;
2727
        }
2728

    
2729
        point.add(new Point3D(x, y, z));
2730
        feature.setGeometry(point);
2731

    
2732
        // 041130: Rellena las props con los atributos.
2733
        completeAttributes(feature);
2734

    
2735
        if (attributeFlags == 8) {
2736
            if (addingToBlock == false) {
2737
                features.add(feature);
2738
            } else {
2739
                blk.add(feature);
2740
            }
2741
        }
2742
    }
2743

    
2744
    /* (non-Javadoc)
2745
     * @see org.cresques.io.DxfFile.EntityFactory#createBlock(org.cresques.io.DxfGroupVector)
2746
     */
2747
    public void createBlock(DxfGroupVector grp) throws Exception {
2748
        //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2749
        blk = new FeatureCollection(proj);
2750

    
2751
        Point3D basePoint = new Point3D();
2752
        String blockName = "";
2753

    
2754
        addingToBlock = true;
2755

    
2756
        blkList.add(iterator, blk);
2757

    
2758
        if (grp.hasCode(8)) {
2759
            blk.setProp("layer", grp.getDataAsString(8));
2760
        }
2761

    
2762
        if (grp.hasCode(62)) {
2763
            Integer integer = new Integer(grp.getDataAsInt(62));
2764
            String string = integer.toString();
2765
            blk.setProp("color", string);
2766
            blk.setProp("colorByLayer", "false");
2767
        } else {
2768
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2769
            int clr = layer.colorNumber;
2770
            Integer integer = new Integer(clr);
2771
            String string = integer.toString();
2772
            blk.setProp("color", string);
2773
            blk.setProp("colorByLayer", "true");
2774
        }
2775

    
2776
        if (grp.hasCode(1)) {
2777
            blockName = grp.getDataAsString(1);
2778

    
2779
            //blk.setBlkName(blockName);
2780
            blk.setProp("blockName", blockName);
2781
        }
2782

    
2783
        if (grp.hasCode(2)) {
2784
            blockName = grp.getDataAsString(2);
2785

    
2786
            //blk.setBlkName(blockName);
2787
            blk.setProp("blockName", blockName);
2788
        }
2789

    
2790
        if (grp.hasCode(10)) {
2791
            Double basePointX = new Double(grp.getDataAsDouble(10));
2792
            basePoint.X = grp.getDataAsDouble(10);
2793
            blk.setProp("basePointX", basePointX.toString());
2794
        }
2795

    
2796
        if (grp.hasCode(20)) {
2797
            Double basePointY = new Double(grp.getDataAsDouble(20));
2798
            basePoint.Y = grp.getDataAsDouble(20);
2799
            blk.setProp("basePointY", basePointY.toString());
2800
        }
2801

    
2802
        if (grp.hasCode(30)) {
2803
            Double basePointZ = new Double(grp.getDataAsDouble(30));
2804
            basePoint.Z = grp.getDataAsDouble(30);
2805

    
2806
            if (basePoint.getZ() != 0.0) {
2807
                dxf3DFile = true;
2808
            }
2809

    
2810
            blk.setProp("basePointZ", basePointZ.toString());
2811
        }
2812

    
2813
        if (grp.hasCode(70)) {
2814
            //blk.flags = grp.getDataAsInt(70);
2815
            Integer blockFlags = new Integer(grp.getDataAsInt(70));
2816
            blk.setProp("blockFlags", blockFlags.toString());
2817

    
2818
            // 041103: Hoy por hoy esto no lo utilizamos.
2819
        }
2820
    }
2821

    
2822
    /* (non-Javadoc)
2823
     * @see org.cresques.io.DxfFile.EntityFactory#endBlk(org.cresques.io.DxfGroupVector)
2824
     */
2825
    public void endBlk(DxfGroupVector grp) throws Exception {
2826
        //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2827
        setAddingToBlock(false);
2828
        iterator = iterator + 1;
2829
    }
2830

    
2831
    /* (non-Javadoc)
2832
     * @see org.cresques.io.DxfFile.EntityFactory#testBlocks()
2833
     */
2834
    public void testBlocks() {
2835
        Vector blkList = getBlkList();
2836
        FeatureCollection block = null;
2837
        Feature feature = null;
2838
        InsPoint3D insert = null;
2839

    
2840
        for (int i = 0; i < blkList.size(); i++) {
2841
            block = (FeatureCollection) blkList.get(i);
2842

    
2843
            int aux = block.size();
2844

    
2845
            for (int j = 0; j < aux; j++) {
2846
                feature = (Feature) block.get(j);
2847

    
2848
                //if (feature.getGeometry() instanceof InsPoint && feature.getProp("isAnInsert") == "true") {
2849
                if (feature.getGeometry() instanceof InsPoint3D) {
2850
                    insert = (InsPoint3D) feature.getGeometry();
2851

    
2852
                    String nomBlock = insert.getBlockName();
2853

    
2854
                    if (insert.getBlockFound() == false) {
2855
                        insert.encuentraBloque(nomBlock);
2856

    
2857
                        //gestionaInsert(feature);
2858
                        //block.add(feature);
2859
                    }
2860
                }
2861
            }
2862
        }
2863
    }
2864

    
2865
    /**
2866
     * M�todo que permite incluir en la lista general de objetos los objetos que se
2867
     * encuentran dentro del bloque referenciado por cada InsPoint3D.
2868
     * @param feature, el punto de inserci�n.
2869
     */
2870
    private void gestionaInsert(Feature feature) {
2871
        Feature feature2 = null;
2872
        org.gvsig.dxf.px.gml.Point3D point = null;
2873
        LineString3D lineString3D = null;
2874
        Polygon3D polygon3D = null;
2875
        InsPoint3D insert = new InsPoint3D();
2876
        insert = (InsPoint3D) feature.getGeometry();
2877

    
2878
        double bPointX = 0.0;
2879
        double bPointY = 0.0;
2880
        double bPointZ = 0.0;
2881

    
2882
        if (insert.getBlockFound() != true)
2883
        {
2884
                DxfFile.logger.debug("BLOQUE NO ENCONTRADO !!!" + insert.getBlockName() + " " + insert.toString());
2885
                return;
2886
        }
2887

    
2888
        bPointX = Double.parseDouble(insert.getBlock().getProp("basePointX"));
2889
        bPointY = Double.parseDouble(insert.getBlock().getProp("basePointY"));
2890
        bPointZ = Double.parseDouble(insert.getBlock().getProp("basePointZ"));
2891

    
2892
        //}
2893
        double sFactorX = insert.getScaleFactor().getX();
2894
        double sFactorY = insert.getScaleFactor().getY();
2895
        double sFactorZ = insert.getScaleFactor().getZ();
2896
        double rAngleGra = insert.getRotAngle();
2897
        double rAngleRad = (rAngleGra * Math.PI) / 180.0;
2898
        InsPoint3D insert2 = null;
2899

    
2900
        for (int i = 0; i < insert.getBlock().size(); i++) {
2901
            feature2 = (Feature) insert.getBlock().get(i);
2902

    
2903
            // Para que los elementos dentro del bloque tengan la misma layer
2904
            // y color que el insert al que corresponden.
2905
            // Segun la especificacion del formato DXF de Autodesk, la layer
2906
            // de las entities dentro de un bloque es la del bloque. La
2907
            // layer especifica para estos elementos en la defincion del
2908
            // bloque se ignora.
2909
            if ((feature2.getProp("colorByLayer").equals("false") ||
2910
                    feature2.getProp("layer").equals("0")) &&
2911
                    !feature.getProp("layer").equals("0")) {
2912
                feature2.setProp("color", feature.getProp("color"));
2913
            }
2914

    
2915
            feature2.setProp("layer", feature.getProp("layer"));
2916

    
2917
            Point3D point1 = new Point3D();
2918
            Point3D point11 = new Point3D();
2919
            Point3D pointAux = null;
2920

    
2921
            if (feature2.getGeometry() instanceof InsPoint3D) {
2922
                insert2 = (InsPoint3D) feature2.getGeometry();
2923
                point1 = insert2.getPoint3D(0);
2924

    
2925
                pointAux = new Point3D(point1.getX() - bPointX,
2926
                                       point1.getY() - bPointY,
2927
                                       point1.getZ() - bPointZ);
2928

    
2929
                double laX = insert.getPoint3D(0).getX() +
2930
                             (((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
2931
                             ((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad)));
2932
                double laY = insert.getPoint3D(0).getY() +
2933
                             (((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
2934
                             ((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
2935
                double laZ = insert.getPoint3D(0).getZ() +
2936
                             (pointAux.getZ() * sFactorZ);
2937
                point11 = new Point3D(laX, laY, laZ);
2938

    
2939
                InsPoint3D insert3 = new InsPoint3D();
2940

    
2941
                insert3.add(point11);
2942

    
2943
                insert3.setBlkList(insert2.getBlkList());
2944
                insert3.setBlock(insert2.getBlock());
2945
                insert3.setBlockName(insert2.getBlockName());
2946
                insert3.setRotAngle(insert2.getRotAngle());
2947

    
2948
                Point3D newScale = new Point3D(insert2.getScaleFactor().getX() * sFactorX,
2949
                                               insert2.getScaleFactor().getY() * sFactorY,
2950
                                               insert2.getScaleFactor().getZ() * sFactorZ);
2951
                insert3.setScaleFactor(newScale);
2952

    
2953
                Feature feature3 = new Feature();
2954
                feature3.setProp("layer", feature2.getProp("layer"));
2955
                feature3.setProp("color", feature2.getProp("color"));
2956
                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
2957
                feature3.setProp("elevation", feature2.getProp("elevation"));
2958

    
2959
                //041130
2960
                for (int j = 0; j < attributes.size(); j++) {
2961
                    String[] att = new String[2];
2962
                    att = (String[]) attributes.get(j);
2963
                    feature3.setProp(att[0], feature2.getProp(att[0]));
2964
                }
2965

    
2966
                feature3.setGeometry(insert3);
2967

    
2968
                gestionaInsert(feature3);
2969
            } else if (feature2.getGeometry() instanceof LineString3D) {
2970
                lineString3D = (LineString3D) feature2.getGeometry();
2971

    
2972
                LineString3D lineString2 = new LineString3D();
2973
                Point3D[] points = new Point3D[lineString3D.pointNr()];
2974
                Point3D[] pointss = new Point3D[lineString3D.pointNr()];
2975

    
2976
                for (int j = 0; j < lineString3D.pointNr(); j++) {
2977
                    points[j] = (Point3D) lineString3D.get(j);
2978
                    pointss[j] = new Point3D();
2979

    
2980
                    pointAux = new Point3D(points[j].getX() - bPointX,
2981
                                           points[j].getY() - bPointY,
2982
                                           points[j].getZ() - bPointZ);
2983

    
2984
                    double laX = insert.getPoint3D(0).getX() +
2985
                                 (((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
2986
                                 ((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad)));
2987
                    double laY = insert.getPoint3D(0).getY() +
2988
                                 (((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
2989
                                 ((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
2990
                    double laZ = insert.getPoint3D(0).getZ() +
2991
                                 (pointAux.getZ() * sFactorZ);
2992
                    pointss[j] = new Point3D(laX, laY, laZ);
2993
                    lineString2.add(pointss[j]);
2994
                }
2995

    
2996
                Feature feature3 = new Feature();
2997
                feature3.setProp("layer", feature2.getProp("layer"));
2998
                feature3.setProp("color", feature2.getProp("color"));
2999
                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
3000

    
3001
                if (feature2.getProp("elevation") != null) {
3002
                    feature3.setProp("elevation", feature2.getProp("elevation"));
3003
                }
3004

    
3005
                feature3.setProp("thickness", feature2.getProp("thickness"));
3006

    
3007
                //041130
3008
                for (int j = 0; j < attributes.size(); j++) {
3009
                    String[] att = new String[2];
3010
                    att = (String[]) attributes.get(j);
3011

    
3012
                    String str = att[0];
3013
                    feature3.setProp(str, feature2.getProp(str));
3014
                }
3015

    
3016
                feature3.setGeometry(lineString2);
3017

    
3018
                if (addingToBlock == false) {
3019
                    features.add(feature3);
3020
                }
3021
            } else if (feature2.getGeometry() instanceof Polygon3D) {
3022
                polygon3D = (Polygon3D) feature2.getGeometry();
3023

    
3024
                Polygon3D polygon2 = new Polygon3D();
3025
                Point3D[] points = new Point3D[polygon3D.pointNr()];
3026
                Point3D[] pointss = new Point3D[polygon3D.pointNr()];
3027

    
3028
                for (int j = 0; j < polygon3D.pointNr(); j++) {
3029
                    points[j] = (Point3D) polygon3D.get(j);
3030
                    pointss[j] = new Point3D();
3031

    
3032
                    pointAux = new Point3D(points[j].getX() - bPointX,
3033
                                           points[j].getY() - bPointY,
3034
                                           points[j].getZ() - bPointZ);
3035

    
3036
                    double laX = insert.getPoint3D(0).getX() +
3037
                                 (((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
3038
                                 ((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad)));
3039
                    double laY = insert.getPoint3D(0).getY() +
3040
                                 (((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
3041
                                 ((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
3042
                    double laZ = insert.getPoint3D(0).getZ() +
3043
                                 (pointAux.getZ() * sFactorZ);
3044
                    pointss[j] = new Point3D(laX, laY, laZ);
3045
                    polygon2.add(pointss[j]);
3046
                }
3047

    
3048
                Feature feature3 = new Feature();
3049
                feature3.setProp("layer", feature2.getProp("layer"));
3050
                feature3.setProp("color", feature2.getProp("color"));
3051
                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
3052

    
3053
                if (feature2.getProp("elevation") != null) {
3054
                    feature3.setProp("elevation", feature2.getProp("elevation"));
3055
                }
3056

    
3057
                feature3.setProp("thickness", feature2.getProp("thickness"));
3058

    
3059
                //041130
3060
                for (int j = 0; j < attributes.size(); j++) {
3061
                    String[] att = new String[2];
3062
                    att = (String[]) attributes.get(j);
3063
                    feature3.setProp(att[0], feature2.getProp(att[0]));
3064
                }
3065

    
3066
                feature3.setGeometry(polygon2);
3067

    
3068
                if (addingToBlock == false) {
3069
                    features.add(feature3);
3070
                }
3071
            } else if (feature2.getGeometry() instanceof org.gvsig.dxf.px.gml.Point3D) {
3072
                point = (org.gvsig.dxf.px.gml.Point3D) feature2.getGeometry();
3073
                point1 = point.getPoint3D(0);
3074

    
3075
                pointAux = new Point3D(point1.getX() - bPointX,
3076
                                       point1.getY() - bPointY,
3077
                                       point1.getZ() - bPointZ);
3078

    
3079
                double laX = insert.getPoint3D(0).getX() +
3080
                             (((pointAux.getX() * sFactorX) * Math.cos(rAngleRad)) +
3081
                             ((pointAux.getY() * sFactorY) * (-1) * Math.sin(rAngleRad)));
3082
                double laY = insert.getPoint3D(0).getY() +
3083
                             (((pointAux.getX() * sFactorX) * Math.sin(rAngleRad)) +
3084
                             ((pointAux.getY() * sFactorY) * Math.cos(rAngleRad)));
3085
                double laZ = insert.getPoint3D(0).getZ() +
3086
                             (pointAux.getZ() * sFactorZ);
3087
                point11 = new Point3D(laX, laY, laZ);
3088

    
3089
                org.gvsig.dxf.px.gml.Point3D pointt = new org.gvsig.dxf.px.gml.Point3D();
3090
                pointt.add(point11);
3091

    
3092
                Feature feature3 = new Feature();
3093
                feature3.setProp("layer", feature2.getProp("layer"));
3094
                feature3.setProp("color", feature2.getProp("color"));
3095
                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
3096
                feature3.setProp("elevation", feature2.getProp("elevation"));
3097
                feature3.setProp("thickness", feature2.getProp("thickness"));
3098

    
3099
                if (point.isTextPoint()) {
3100
                    feature3.setProp("text", feature2.getProp("text"));
3101
                    feature3.setProp("textHeight",
3102
                                     feature2.getProp("textHeight"));
3103

    
3104
                    double auxR = Double.parseDouble(feature2.getProp("textRotation"));
3105

    
3106
                    auxR = auxR + rAngleGra;
3107
                    feature3.setProp("textRotation", Double.toString(auxR));
3108

    
3109
                    pointt.setTextPoint(true);
3110
                }
3111

    
3112
                //041130
3113
                for (int j = 0; j < attributes.size(); j++) {
3114
                    String[] att = new String[2];
3115
                    att = (String[]) attributes.get(j);
3116
                    feature3.setProp(att[0], feature2.getProp(att[0]));
3117
                }
3118

    
3119
                feature3.setGeometry(pointt);
3120

    
3121
                //if (addingToBlock == false) {
3122
                features.add(feature3);
3123

    
3124
                //}
3125
            } else {
3126
                    DxfFile.logger.debug("gestionaInsert(): Encontrado elemento desconocido");
3127
            }
3128
        }
3129
    }
3130

    
3131
    /**
3132
     * Gestiona la caracter�stica faces en las polil�neas.
3133
     * @param face
3134
     */
3135
    private void addFace(int[] face) {
3136
        hasFaces = true;
3137

    
3138
        if (faces == null) {
3139
            faces = new Vector();
3140
        }
3141

    
3142
        faces.add(face);
3143
    }
3144

    
3145
    /* (non-Javadoc)
3146
     * @see org.cresques.io.DxfFile.EntityFactory#depureAttributes()
3147
     */
3148
    public void depureAttributes() {
3149
        //String[] att = null;
3150

    
3151
        /*Set conjunto = new HashSet();
3152
        for (int i=0;i<attributes.size();i++) {
3153
            att = (String[])attributes.get(i);
3154
            String str = att[0];
3155
            conjunto.add(str);
3156
        }
3157
        //conjunto.addAll(attributes);
3158
        Vector atts = new Vector();
3159
        Vector atts2 = new Vector();
3160
        atts.addAll(conjunto);
3161
        for (int i=0;i<atts.size();i++) {
3162
            if (((String[])(attributes.get(i)))[0] == atts.get(i)) {
3163
                atts2.add(i, attributes.get(i));
3164
            }
3165
        }*/
3166
        String[] lastAtt = new String[2];
3167

    
3168
        for (int i = 0; i < attributes.size(); i++) {
3169
            String[] att = (String[]) attributes.get(i);
3170

    
3171
            for (int j = i + 1; j < attributes.size(); j++) {
3172
                String[] st = (String[]) attributes.get(j);
3173
                String st1 = att[0];
3174
                String st2 = st[0];
3175

    
3176
                if (st2.equals(st1)) {
3177
                    attributes.remove(j);
3178
                }
3179

    
3180
                if (i == (attributes.size() - 1)) {
3181
                    lastAtt = att;
3182
                }
3183
            }
3184
        }
3185

    
3186
        for (int i = attributes.size() - 2; i >= 0; i--) {
3187
            String[] att = (String[]) attributes.get(i);
3188
            String st1 = lastAtt[0];
3189
            String st2 = att[0];
3190

    
3191
            if (st2.equals(st1)) {
3192
                attributes.remove(i);
3193
            }
3194
        }
3195

    
3196
        /*String[] attStrs = new String[attributes.size()];
3197
        Vector attribs = new Vector();
3198
        for (int i=0;i<attributes.size();i++) {
3199
            att = (String[])attributes.get(i);
3200
            attStrs[i] = att[0];
3201
        }
3202
        Set attStrsNR = new HashSet();
3203
        for (int i=0;i<attStrs.length;i++) {
3204
            attStrsNR.add(attStrs[i]);
3205
        }
3206
        String[] attStrsNRA = new String[attStrsNR.size()];
3207
        attStrsNR.toArray(attStrsNRA);
3208
        for (int i=0;i<attStrsNR.size();i++) {
3209
            att[0] = attStrsNRA[i];
3210
            attribs.add(att);
3211
        }
3212
        for (int i=0;i<attributes.size();i++) {
3213
            att = (String[])attributes.get(i);
3214
            String[] att2 = new String[2];
3215
            for (int j=0;j<attribs.size();j++) {
3216
                att2 = (String[])attribs.get(j);
3217
                if (att[0].equals(att2[0])) {
3218
                    att2[1] = att[1];
3219
                }
3220
                attribs.set(j, att2);
3221
            }
3222
        }
3223
        attributes = attribs;*/
3224
    }
3225

    
3226
    /**
3227
     * Hace los setProp para los atributos extra de las entidades.
3228
     * @param feature
3229
     */
3230
    private void completeAttributes(Feature feature) {
3231
        // 041130: Rellena las props con los atributos.
3232
        for (int i = 0; i < attributes.size(); i++) {
3233
            String[] att = new String[2];
3234
            att = (String[]) attributes.get(i);
3235
            feature.setProp(att[0], att[1]);
3236
        }
3237
    }
3238

    
3239
    /**
3240
     * Copia los atributos extra cargados en InsPoint y ya perfectamente definidos a los
3241
     * elementos del bloque al que referencia el punto de insercion.
3242
     * @param feaInsert, punto de inserci�n.
3243
     */
3244
    private void copyAttributes(Feature feaInsert) {
3245
        Feature feature = null;
3246
        InsPoint3D insert = new InsPoint3D();
3247
        insert = (InsPoint3D) feaInsert.getGeometry();
3248

    
3249
        for (int i = 0; i < insert.getBlock().size(); i++) {
3250
            feature = (Feature) insert.getBlock().get(i);
3251

    
3252
            for (int j = 0; j < attributes.size(); j++) {
3253
                String[] att = new String[2];
3254
                att = (String[]) attributes.get(j);
3255
                feature.setProp(att[0], feaInsert.getProp(att[0]));
3256
            }
3257
        }
3258
    }
3259

    
3260
    /**
3261
     * Se ejecuta cuando se declaran nuevos atributos, es decir, tras cada ATTDEF.
3262
     * A�ade estos atributos a las features existentes.
3263
     */
3264
    private void setNewAttributes() {
3265
        for (int i = 0; i < features.size(); i++) {
3266
            Feature fea = new Feature();
3267
            fea = (Feature) features.get(i);
3268
            completeAttributes(fea);
3269
        }
3270

    
3271
        for (int i = 0; i < blkList.size(); i++) {
3272
            FeatureCollection bloque = new FeatureCollection(proj);
3273
            bloque = (FeatureCollection) blkList.get(i);
3274

    
3275
            for (int j = 0; j < bloque.size(); j++) {
3276
                Feature fea = new Feature();
3277
                fea = (Feature) bloque.get(j);
3278
                completeAttributes(fea);
3279
            }
3280
        }
3281
    }
3282

    
3283
    /* (non-Javadoc)
3284
     * @see org.cresques.io.DxfFile.EntityFactory#getAttributes()
3285
     */
3286
    public Vector getAttributes() {
3287
        return attributes;
3288
    }
3289

    
3290
    /* (non-Javadoc)
3291
     * @see org.cresques.io.DxfFile.EntityFactory#getExtent()
3292
     */
3293
    public Extent getExtent() {
3294
        Feature feature = new Feature();
3295
        Extent extent = new Extent();
3296
        Iterator iter = features.iterator();
3297

    
3298
        while (iter.hasNext()) {
3299
            feature = (Feature) iter.next();
3300
            extent.add(feature.getExtent());
3301
        }
3302

    
3303
        return extent;
3304
    }
3305

    
3306
    /**
3307
     * Establece la proyecci�n cartogr�fica en la que se van a crear las features.
3308
     * @param p, Proyecci�n cartogr�fica.
3309
     */
3310
    public void setProjection(IProjection p) {
3311
        proj = p;
3312
    }
3313

    
3314
    /* (non-Javadoc)
3315
     * @see org.cresques.io.DxfFile.EntityFactory#reProject(org.cresques.geo.ReProjection)
3316
     */
3317
    public void reProject(ICoordTrans rp) {
3318
        Feature feature = new Feature();
3319
        Extent extent = new Extent();
3320
        Iterator iter = features.iterator();
3321

    
3322
        while (iter.hasNext()) {
3323
            feature = (Feature) iter.next();
3324
            ((Projected) feature).reProject(rp);
3325
            extent.add(feature.getExtent());
3326
        }
3327

    
3328
        setProjection(rp.getPDest());
3329
    }
3330

    
3331
    /* (non-Javadoc)
3332
     * @see org.cresques.geo.Projected#getProjection()
3333
     */
3334
    public IProjection getProjection() {
3335
        return proj;
3336
    }
3337

    
3338
    /**
3339
     * Devuelve las features creadas.
3340
     * @return IObjList
3341
     */
3342
    public IObjList getObjects() {
3343
        return features;
3344
    }
3345

    
3346
    /**
3347
     * Permite dibujar las features creadas.
3348
     */
3349
    public void draw(Graphics2D g, ViewPortData vp) {
3350
        Iterator iter = features.iterator();
3351
        Extent extent;
3352

    
3353
        while (iter.hasNext()) {
3354
            Feature feature = new Feature();
3355
            feature = (Feature) iter.next();
3356
            extent = feature.getExtent();
3357

    
3358
            if (vp.getExtent().minX() > extent.maxX()) {
3359
                continue;
3360
            }
3361

    
3362
            if (vp.getExtent().minY() > extent.maxY()) {
3363
                continue;
3364
            }
3365

    
3366
            if (vp.getExtent().maxX() < extent.minX()) {
3367
                continue;
3368
            }
3369

    
3370
            if (vp.getExtent().maxY() < extent.minY()) {
3371
                continue;
3372
            }
3373

    
3374
            //if (!feature.layer.frozen)
3375
            feature.draw(g, vp);
3376
        }
3377
    }
3378

    
3379
    /**
3380
     * Invoca el m�todo de creaci�n de arcos para polil�neas con par�metros de
3381
     * curvatura.
3382
     * @param coord1, punto inicial del arco.
3383
     * @param coord2, punto final del arco.
3384
     * @param bulge, par�metro de curvatura.
3385
     * @return Vector con los puntos del arco.
3386
     */
3387
    public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) {
3388
        return new DxfCalArcs(coord1, coord2, bulge).getPoints(1);
3389
    }
3390

    
3391
    /* (non-Javadoc)
3392
     * @see org.cresques.io.DxfFile.EntityFactory#getBlkList()
3393
     */
3394
    public Vector getBlkList() {
3395
        return blkList;
3396
    }
3397

    
3398
    /* (non-Javadoc)
3399
     * @see org.cresques.io.DxfFile.EntityFactory#getDxfEntityList()
3400
     */
3401
    public DxfEntityList getDxfEntityList() {
3402
        // TODO Auto-generated method stub
3403
        return null;
3404
    }
3405

    
3406
    /* (non-Javadoc)
3407
     * @see org.cresques.io.DxfFile.EntityFactory#getBlk()
3408
     */
3409
    public DxfBlock getBlk() {
3410
        // TODO Auto-generated method stub
3411
        return null;
3412
    }
3413

    
3414
    /* (non-Javadoc)
3415
     * @see org.cresques.io.DxfFile.EntityFactory#createEllipse(org.cresques.io.DxfGroupVector)
3416
     */
3417
    public void createEllipse(DxfGroupVector grp) throws Exception {
3418
        double cx = 0.0;
3419
        double cy = 0.0;
3420
        double cz = 0.0;
3421

    
3422
        double x_end_point_major_axis = 0.0;
3423
        double y_end_point_major_axis = 0.0;
3424
        double z_end_point_major_axis = 0.0;
3425

    
3426
        double extx = 0.0;
3427
        double exty = 0.0;
3428
        double extz = 1.0;
3429
        double ratio_minor_to_major_axis = 1.0;
3430
        double start = 0.0;
3431
        double end = 2* Math.PI;
3432
        LineString3D lineString3D = new LineString3D();
3433
        Polygon3D polygon3D = new Polygon3D();
3434
        Feature feaBordes = new Feature();
3435
        Feature feaFondos = new Feature();
3436

    
3437
        feaBordes.setProp("dxfEntity", "Ellipse");
3438
        feaFondos.setProp("dxfEntity", "Ellipse");
3439

    
3440
        if (grp.hasCode(8)) {
3441
            feaBordes.setProp("layer", grp.getDataAsString(8));
3442
        }
3443

    
3444
        feaFondos.setProp("layer", grp.getDataAsString(8));
3445

    
3446
        if (grp.hasCode(39)) {
3447
            Double doub = new Double(grp.getDataAsDouble(39));
3448
            String string = doub.toString();
3449
            feaBordes.setProp("thickness", string);
3450
            feaFondos.setProp("thickness", string);
3451
        } else {
3452
            Double doub = new Double(0.0);
3453
            feaBordes.setProp("thickness", doub.toString());
3454
            feaFondos.setProp("thickness", doub.toString());
3455
        }
3456

    
3457
        if (grp.hasCode(62)) {
3458
            Integer integer = new Integer(grp.getDataAsInt(62));
3459
            String string = integer.toString();
3460
            feaBordes.setProp("color", string);
3461
            feaFondos.setProp("color", string);
3462
            feaBordes.setProp("colorByLayer", "false");
3463
            feaFondos.setProp("colorByLayer", "false");
3464
        } else {
3465
            DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
3466
            int clr = layer.colorNumber;
3467
            Integer integer = new Integer(clr);
3468
            String string = integer.toString();
3469
            feaBordes.setProp("color", string);
3470
            feaFondos.setProp("color", string);
3471
            feaBordes.setProp("colorByLayer", "true");
3472
            feaFondos.setProp("colorByLayer", "true");
3473
        }
3474

    
3475
        // Center point
3476
        cx = grp.getDataAsDouble(10);
3477
        cy = grp.getDataAsDouble(20);
3478
        if (grp.hasCode(30)) {
3479
            cz = grp.getDataAsDouble(30);
3480
        }
3481

    
3482
        // end_point_major_axis  (RELATIVE to the center)
3483
        x_end_point_major_axis = grp.getDataAsDouble(11);
3484
        y_end_point_major_axis = grp.getDataAsDouble(21);
3485
        if (grp.hasCode(31)) {
3486
            z_end_point_major_axis = grp.getDataAsDouble(31);
3487
        }
3488

    
3489
        // ratio minor axis to major axis
3490
        if (grp.hasCode(40)) {
3491
                ratio_minor_to_major_axis = grp.getDataAsDouble(40);
3492
        }
3493
        Point2D c = proj.createPoint(cx, cy);
3494
        // Point2D end_major = proj.createPoint(x_end_point_major_axis, y_end_point_major_axis);
3495
        // double r_major_axis_2D = c.distance(end_major)/2.0;
3496
        double r_major_axis_2D = Math.sqrt(x_end_point_major_axis*
3497
                        x_end_point_major_axis +
3498
                        y_end_point_major_axis * y_end_point_major_axis);
3499
        double r_minor_axis_2D = r_major_axis_2D * ratio_minor_to_major_axis;
3500
        double rotation_angle = Math.atan2(y_end_point_major_axis , x_end_point_major_axis);
3501

    
3502
        if (grp.hasCode(210)) {
3503
            extx = grp.getDataAsDouble(210);
3504
        }
3505

    
3506
        if (grp.hasCode(220)) {
3507
            exty = grp.getDataAsDouble(220);
3508
        }
3509

    
3510
        if (grp.hasCode(230)) {
3511
            extz = grp.getDataAsDouble(230);
3512
        }
3513

    
3514
        Point3D point_in = new Point3D(cx, cy, cz);
3515
        Point3D xtru = new Point3D(extx, exty, extz);
3516
        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
3517
        cx = point_out.getX();
3518
        cy = point_out.getY();
3519
        cz = point_out.getZ();
3520

    
3521
        Double doub = new Double(cz);
3522
        feaBordes.setProp("elevation", doub.toString());
3523
        feaFondos.setProp("elevation", doub.toString());
3524

    
3525
        if (cz != 0.0) {
3526
            dxf3DFile = true;
3527
        }
3528

    
3529

    
3530
        Point3D center = new Point3D(c.getX(), c.getY(), cz);
3531
        Point3D[] pts = new Point3D[360];
3532
        int angulo = 0;
3533

    
3534
        for (angulo = 0; angulo < 360; angulo++) {
3535
            pts[angulo] = new Point3D(center.getX() +
3536
                                      r_major_axis_2D * Math.cos(Math.toRadians(angulo)),
3537
                                      center.getY() +
3538
                                      r_minor_axis_2D * Math.sin(Math.toRadians(angulo)),
3539
                                      center.getZ());
3540

    
3541
            if (pts.length == 1) {
3542
                firstPt = pts[angulo];
3543
            }
3544
        }
3545

    
3546
        AffineTransform at = new AffineTransform();
3547
        at.rotate(rotation_angle, cx, cy);
3548
        for (int i = 0; i < pts.length; i++) {
3549
                Point2D pAux = pts[i];
3550
                Point2D pRot = at.transform(pAux, null);
3551
            lineString3D.add(pRot);
3552
            polygon3D.add(pRot);
3553
        }
3554

    
3555
        feaBordes.setGeometry(lineString3D);
3556
        feaFondos.setGeometry(polygon3D);
3557

    
3558
        // 041130: Rellena las props con los atributos.
3559
        completeAttributes(feaBordes);
3560
        completeAttributes(feaFondos);
3561

    
3562
        //features.add(feature);
3563
        if (addingToBlock == false) {
3564
            //features.add(feaBordes);
3565
            features.add(feaFondos);
3566
        } else {
3567
            //blk.add(feaBordes);
3568
            blk.add(feaFondos);
3569
        }
3570

    
3571
    }
3572

    
3573
    /**
3574
     * @return Returns the dxf3DFile.
3575
     */
3576
    public boolean isDxf3DFile() {
3577
        return dxf3DFile;
3578
    }
3579

    
3580
    /**
3581
     * @param dxf3DFile The dxf3DFile to set.
3582
     */
3583
    public void setDxf3DFile(boolean dxf3DFile) {
3584
        this.dxf3DFile = dxf3DFile;
3585
    }
3586
}