Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfFeatureMaker.java @ 2312

History | View | Annotate | Download (85 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 * 
4
 * Copyright (C) 2004-5. 
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 * 
22
 * cresques@gmail.com
23
 */
24
package org.cresques.px.dxf;
25

    
26
import java.awt.Graphics2D;
27
import java.awt.geom.Point2D;
28
import java.util.Iterator;
29
import java.util.Vector;
30

    
31
import org.cresques.cts.ICoordTrans;
32
import org.cresques.cts.IProjection;
33
import org.cresques.geo.Point3D;
34
import org.cresques.geo.Projected;
35
import org.cresques.geo.ViewPortData;
36
import org.cresques.io.DxfFile;
37
import org.cresques.io.DxfGroup;
38
import org.cresques.io.DxfGroupVector;
39
import org.cresques.px.Extent;
40
import org.cresques.px.IObjList;
41
import org.cresques.px.gml.Feature;
42
import org.cresques.px.gml.FeatureCollection;
43
import org.cresques.px.gml.InsPoint3D;
44
import org.cresques.px.gml.LineString;
45
import org.cresques.px.gml.LineString3D;
46
import org.cresques.px.gml.Polygon;
47
import org.cresques.px.gml.Polygon3D;
48

    
49
/**
50
 * Implementaci?n de la creaci?n de features de un DXF2000.
51
 */
52
public class DxfFeatureMaker implements DxfFile.EntityFactory, Projected {
53
        IProjection proj = null;
54
        //Feature lastFeature = null;
55
        Feature lastFeaBordes = null;
56
        Feature lastFeaFondos = null;
57
        boolean isDoubleFeatured = false;
58
        FeatureCollection features = null;
59
        double bulge = 0.0;
60
    double xtruX=0.0, xtruY=0.0, xtruZ=1.0;
61
    int polylineFlag = 0;
62
    Point3D firstPt = new Point3D();
63
    Point3D ptAnterior = null;
64

    
65
    boolean addingToBlock = false;
66
    int iterator = 0;
67
        FeatureCollection blk = null;
68
        Vector blkList = null;
69
        DxfTable layers = null;
70
        
71
        private Vector faces = null;
72
        private boolean hasFaces = false;
73
        private int facesIterador = 1;
74
        private Point2D facesFirstPoint = null;
75
        
76
        private Vector attributes = null;
77
        private boolean constantPolylineElevation;
78
        private double lastVertexElevation;
79
        private boolean dxf3DFile;
80

    
81
        public DxfFeatureMaker(IProjection proj) {
82
                this.proj = proj;
83
                layers = new DxfTable();
84
                features = new FeatureCollection(proj);
85
                blkList = new Vector();
86
                attributes = new Vector();
87
                dxf3DFile = false;
88
        }
89

    
90
        public void setAddingToBlock(boolean a) { addingToBlock = a; }
91

    
92
        public void createLayer(DxfGroupVector v) throws Exception {
93
                int color = v.getDataAsInt(62);
94
                DxfLayer layer = new DxfLayer(v.getDataAsString(2), Math.abs(v.getDataAsInt(62)));
95
                if (color < 0) {
96
                        layer.isOff = true;
97
                }
98
                layer.lType = v.getDataAsString(6);
99
                layer.setFlags(v.getDataAsInt(70));
100
                // compruebo flags
101
                if ((layer.flags & 0x01) == 0x01) {
102
                        layer.frozen = true;
103
                }
104
                if ((layer.flags & 0x02) == 0x02) {
105
                        layer.frozen = true;
106
                }
107
                System.out.println("LAYER color="+layer.getColor());
108

    
109
                layers.add(layer);
110
        }
111

    
112
        public void createPolyline(DxfGroupVector grp) throws Exception {
113
                LineString3D lineString3D = new LineString3D();
114
                Polygon3D polygon3D = new Polygon3D();
115
                //Feature feature= new Feature();
116
                Feature feaBordes= new Feature();
117
                Feature feaFondos= new Feature();
118
                double x = 0.0, y = 0.0, z = 0.0;
119
                int flags = 0;
120
                constantPolylineElevation = true;
121
                
122
                // 041122: Cada polyline tiene asociado un objeto faces distinto.
123
                faces = new Vector();
124
                
125
                //feature.setProp("dxfEntity", "Polyline");
126
                feaBordes.setProp("dxfEntity", "Polyline");
127
                feaFondos.setProp("dxfEntity", "Polyline");
128
                if (grp.hasCode(8)) {
129
                        //feature.setProp("layer", grp.getDataAsString(8));                        
130
                        feaBordes.setProp("layer", grp.getDataAsString(8));                        
131
                        feaFondos.setProp("layer", grp.getDataAsString(8));                        
132
                }
133
                if (grp.hasCode(39)) {
134
                        Double doub = new Double(grp.getDataAsDouble(39));
135
                        String string = doub.toString();
136
                        //feature.setProp("thickness", string);
137
                        feaBordes.setProp("thickness", string);
138
                        feaFondos.setProp("thickness", string);
139
                } else {
140
                        Double doub = new Double(0.0);
141
                        //feature.setProp("thickness", doub.toString());
142
                        feaBordes.setProp("thickness", doub.toString());
143
                        feaFondos.setProp("thickness", doub.toString());
144
                }
145
                if (grp.hasCode(62)) {
146
                        Integer integer = new Integer(grp.getDataAsInt(62));
147
                        String string = integer.toString();
148
                        //feature.setProp("color", string);
149
                        feaBordes.setProp("color", string);
150
                        feaFondos.setProp("color", string);
151
                        feaBordes.setProp("colorByLayer", "false");
152
                        feaFondos.setProp("colorByLayer", "false");
153
                } else {
154
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
155
                        int clr = layer.colorNumber;
156
                        Integer integer = new Integer(clr);
157
                        String string = integer.toString();
158
                        //feature.setProp("color", string);
159
                        feaBordes.setProp("color", string);
160
                        feaFondos.setProp("color", string);
161
                        feaBordes.setProp("colorByLayer", "true");
162
                        feaFondos.setProp("colorByLayer", "true");
163
                }
164
                if (grp.hasCode(10))
165
                        x = grp.getDataAsDouble(10);
166
                if (grp.hasCode(20))
167
                        y = grp.getDataAsDouble(20);
168
                if (grp.hasCode(30)) {
169
                        z = grp.getDataAsDouble(30);
170
                        if (z!=0.0) dxf3DFile = true;
171
                        Double doub = new Double(z);
172
                        String string = doub.toString();
173
                        //feature.setProp("elevation", string);
174
                        feaBordes.setProp("elevation", string);
175
                        feaFondos.setProp("elevation", string);
176
                } else {
177
                        Double doub = new Double(0.0);
178
                        //feature.setProp("elevation", doub.toString());
179
                        feaBordes.setProp("elevation", doub.toString());
180
                        feaFondos.setProp("elevation", doub.toString());
181
                }
182
                if (grp.hasCode(70))
183
                        flags = grp.getDataAsInt(70);
184
                if (grp.hasCode(210))
185
                        xtruX = grp.getDataAsDouble(210);
186
                if (grp.hasCode(220))
187
                        xtruY = grp.getDataAsDouble(220);
188
                if (grp.hasCode(230))
189
                        xtruZ = grp.getDataAsDouble(230);
190
                if ((flags & 0x01) == 0x01 || (flags & 0x40) == 0x40) {
191
                        feaBordes.setGeometry(lineString3D);
192
                        feaFondos.setGeometry(polygon3D);
193
                        lastFeaBordes = feaBordes;
194
                        lastFeaFondos = feaFondos;
195
                        isDoubleFeatured = true;
196
                } else if ((flags & 0x01) == 0x00) {
197
                        feaBordes.setGeometry(lineString3D);
198
                        lastFeaBordes = feaBordes;
199
                        isDoubleFeatured = false;
200
                } else {
201
                        System.out.println("Detectada una Polyline Flag que no corresponde");
202
                        System.out.println("a una Polyline corriente, ni a una Closed Polyline");
203
                }
204
        }
205

    
206
        public void endSeq() throws Exception {
207
                if (isDoubleFeatured) {
208
                        if (lastFeaBordes.getGeometry() instanceof LineString3D) {
209
                                Feature feaBordes = lastFeaBordes;
210
                                Feature feaFondos = lastFeaFondos;
211
                                LineString3D lineString3D = (LineString3D)feaBordes.getGeometry();
212
                                Polygon3D polygon3D = (Polygon3D)feaFondos.getGeometry();
213
                                lineString3D.add(firstPt);
214
                                if (bulge!=0) {
215
                                        
216
                                        // 041122: Correcci?n del bug en los bulges de FIXT3.DXF
217
                                        Vector arc = createArc(new Point2D.Double(lineString3D.get(lineString3D.pointNr()-2).getX(), lineString3D.get(lineString3D.pointNr()-2).getY()), new Point2D.Double(lineString3D.get(lineString3D.pointNr()-1).getX(), lineString3D.get(lineString3D.pointNr()-1).getY()), bulge);
218
                                        lineString3D.remove(lineString3D.pointNr()-1);
219
                                        lineString3D.remove(lineString3D.pointNr()-1);
220
                                        polygon3D.remove(lineString3D.pointNr()-1);
221
                                        polygon3D.remove(lineString3D.pointNr()-1);
222
                                        if (bulge>0) {
223
                                                for (int i=0; i<arc.size(); i++) {
224
                                                        Point2D ptAux = new Point2D.Double();
225
                                                        double z = ((Point3D)lineString3D.get(lineString3D.pointNr()-2)).getZ();
226
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
227
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
228
                                                        lineString3D.add(ptAux3D);
229
                                                        polygon3D.add(ptAux3D);
230
                                                        if (lineString3D.pointNr() == 1) firstPt = ptAux3D;
231
                                                }
232
                                        } else {
233
                                                for (int i=arc.size()-1; i>=0; i--) {
234
                                                        Point2D ptAux = new Point2D.Double();
235
                                                        double z = ((Point3D)lineString3D.get(lineString3D.pointNr()-2)).getZ();
236
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
237
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
238
                                                        lineString3D.add(ptAux3D);
239
                                                        polygon3D.add(ptAux3D);
240
                                                        if (lineString3D.pointNr() == 1 || polygon3D.pointNr() == 1) firstPt = ptAux3D;
241
                                                }                                        
242
                                        }
243
                                        // 041122
244
                                        
245
                                        bulge = 0.0;
246
                                }
247
                                
248
                                if (hasFaces) {
249
                                        //System.out.println("Sabe que es un poligono.");
250
                                        //System.out.println("POLYLINE: caras=" +faces.size()+", puntos="+ lineString.pointNr());
251
                                        LineString ls1 = new LineString();
252
                                        Polygon pl1 = new Polygon();
253
                                        LineString ls2 = new LineString();
254
                                        Polygon pl2 = new Polygon();
255
                                        LineString ls = new LineString();
256
                                        Polygon pl = new Polygon();
257
                                        int [] face;
258
                                        int i0, i1;
259
                                        Iterator iter = faces.iterator();
260
                                        while (iter.hasNext()) {
261
                                                face = (int []) iter.next();
262
                                                i0 = face[3];
263
                                                for (int i=0; i<4; i++) {
264
                                                        i1 = face[i];
265
                                                        if (i0 > 0) {
266
                                                                if ((facesIterador%2)!=0) {
267
                                                                        ls1.add((Point2D)lineString3D.get(i0-1));
268
                                                                        pl1.add((Point2D)polygon3D.get(i0-1));
269
                                                                } else {
270
                                                                        ls2.add((Point2D)lineString3D.get(i0-1));
271
                                                                        pl2.add((Point2D)polygon3D.get(i0-1));
272
                                                                }
273
                                                                facesIterador = facesIterador + 1;
274
                                                        }
275
                                                        i0 = i1;
276
                                                }
277
                                        }
278
                                        facesFirstPoint = new Point2D.Double(ls1.get(0).getX(), ls1.get(0).getY());
279
                                        for (int i=0;i<ls1.pointNr();i++) {
280
                                                ls.add(ls1.get(i));
281
                                                pl.add(pl1.get(i));
282
                                        }
283
                                        for (int i=ls2.pointNr()-1;i>0;i--) {
284
                                                ls.add(ls2.get(i));
285
                                                pl.add(pl2.get(i));
286
                                        }
287
                                        ls.add(facesFirstPoint);
288
                                        pl.add(facesFirstPoint);
289
                                        lastFeaBordes.setGeometry(ls);                                        
290
                                        lastFeaFondos.setGeometry(pl);                                        
291
                                } else {
292
                                        lastFeaBordes.setGeometry(lineString3D);
293
                                        lastFeaFondos.setGeometry(polygon3D);
294
                                }
295
                                
296
                                // 041130: Rellena las props con los atributos.
297
                                completeAttributes(lastFeaBordes);
298
                                completeAttributes(lastFeaFondos);
299
                                
300
                                setPolylineElevation(lastFeaBordes, lastFeaFondos);
301
                                
302
                                if (addingToBlock == false) {
303
                                        features.add(lastFeaBordes);
304
                                        features.add(lastFeaFondos);
305
                                } else {
306
                                        blk.add(lastFeaBordes);
307
                                        blk.add(lastFeaFondos);
308
                                }
309
                                lastFeaBordes = null;
310
                                lastFeaFondos = null;                                
311
                        } else if (lastFeaBordes.getGeometry() instanceof InsPoint3D) {
312
                                // Se trata de un SEQEND despues de un ATTRIB
313
                                copyAttributes(lastFeaBordes);
314
                                
315
                                gestionaInsert(lastFeaBordes);
316
                                
317
                                if (addingToBlock == false) {
318
                                        features.add(lastFeaFondos);
319
                                } else {
320
                                        blk.add(lastFeaBordes);
321
                                }
322
                                lastFeaBordes = null;
323
                                lastFeaFondos = null;
324
                        } else {
325
                                // Caso no contemplado.
326
                        }
327
                } else {
328
                        if (lastFeaBordes.getGeometry() instanceof LineString3D) {
329
                                Feature feaBordes = lastFeaBordes;
330
                                LineString3D lineString3D = (LineString3D)feaBordes.getGeometry();
331
                                if (bulge!=0) {
332
                                        
333
                                        // 041122: Correcci?n del bug en los bulges de FIXT3.DXF
334
                                        Vector arc = createArc(new Point2D.Double(lineString3D.get(lineString3D.pointNr()-2).getX(), lineString3D.get(lineString3D.pointNr()-2).getY()), new Point2D.Double(lineString3D.get(lineString3D.pointNr()-1).getX(), lineString3D.get(lineString3D.pointNr()-1).getY()), bulge);
335
                                        lineString3D.remove(lineString3D.pointNr()-1);
336
                                        lineString3D.remove(lineString3D.pointNr()-1);
337
                                        if (bulge>0) {
338
                                                for (int i=0; i<arc.size(); i++) {
339
                                                        Point2D ptAux = new Point2D.Double();
340
                                                        double z = ((Point3D)lineString3D.get(lineString3D.pointNr()-2)).getZ();
341
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
342
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
343
                                                        lineString3D.add(ptAux3D);
344
                                                        if (lineString3D.pointNr() == 1) firstPt = ptAux3D;
345
                                                }
346
                                        } else {
347
                                                for (int i=arc.size()-1; i>=0; i--) {
348
                                                        Point2D ptAux = new Point2D.Double();
349
                                                        double z = ((Point3D)lineString3D.get(lineString3D.pointNr()-2)).getZ();
350
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
351
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
352
                                                        lineString3D.add(ptAux3D);
353
                                                        if (lineString3D.pointNr() == 1) firstPt = ptAux3D;
354
                                                }                                        
355
                                        }
356
                                        // 041122
357
                                        
358
                                        bulge = 0.0;
359
                                }
360
                                
361
                                if (hasFaces) {
362
                                        //System.out.println("POLYLINE: caras=" +faces.size()+", puntos="+ lineString.pointNr());
363
                                        LineString ls1 = new LineString();
364
                                        LineString ls2 = new LineString();
365
                                        LineString ls = new LineString();
366
                                        int [] face;
367
                                        int i0, i1;
368
                                        Iterator iter = faces.iterator();
369
                                        while (iter.hasNext()) {
370
                                                face = (int []) iter.next();
371
                                                i0 = face[3];
372
                                                for (int i=0; i<4; i++) {
373
                                                        i1 = face[i];
374
                                                        if (i0 > 0) {
375
                                                                if ((facesIterador%2)!=0) {
376
                                                                        ls1.add((Point2D)lineString3D.get(i0-1));
377
                                                                        //ls.add((Point2D)lineString.get(Math.abs(i1)-1));
378
                                                                } else {
379
                                                                        ls2.add((Point2D)lineString3D.get(i0-1));
380
                                                                        //ls.add((Point2D)lineString.get(Math.abs(i1)-1));
381
                                                                }
382
                                                                facesIterador = facesIterador + 1;
383
                                                        }
384
                                                        i0 = i1;
385
                                                }
386
                                        }
387
                                        facesFirstPoint = new Point2D.Double(ls1.get(0).getX(), ls1.get(0).getY());
388
                                        for (int i=0;i<ls1.pointNr();i++) {
389
                                                ls.add(ls1.get(i));
390
                                        }
391
                                        for (int i=ls2.pointNr()-1;i>0;i--) {
392
                                                ls.add(ls2.get(i));
393
                                        }
394
                                        ls.add(facesFirstPoint);
395
                                        lastFeaBordes.setGeometry(ls);                                        
396
                                } else {
397
                                        lastFeaBordes.setGeometry(lineString3D);
398
                                }
399
                                
400
                                // 041130: Rellena las props con los atributos.
401
                                completeAttributes(lastFeaBordes);
402
                                
403
                                setPolylineElevation(lastFeaBordes);
404
                                
405
                                if (addingToBlock == false) {
406
                                        features.add(lastFeaBordes);
407
                                } else {
408
                                        blk.add(lastFeaBordes);
409
                                }
410
                                lastFeaBordes = null;                                
411
                        } else {
412
                                // Se trata de un SEQEND despues de un ATTRIB
413
                        }
414
                }
415
                xtruX = 0.0;
416
                xtruY = 0.0;
417
                xtruZ = 1.0;
418
                bulge = 0.0;
419
                isDoubleFeatured = false;
420
                hasFaces = false;
421
                facesIterador = 1;
422
        }
423
        private void setPolylineElevation(Feature feaBordes) {
424
            if (constantPolylineElevation) {
425
                        Double doub = new Double(lastVertexElevation);
426
                        String string = doub.toString();
427
                        feaBordes.setProp("elevation", string);
428
            } else {
429
                        Double doub = new Double(0.0);
430
                        String string = doub.toString();
431
                        feaBordes.setProp("elevation", string);
432
            }
433
        }
434
        private void setPolylineElevation(Feature feaBordes, Feature feaFondos) {
435
            if (constantPolylineElevation) {
436
                        Double doub = new Double(lastVertexElevation);
437
                        String string = doub.toString();
438
                        feaBordes.setProp("elevation", string);
439
                        feaFondos.setProp("elevation", string);
440
            } else {
441
                        Double doub = new Double(0.0);
442
                        String string = doub.toString();
443
                        feaBordes.setProp("elevation", string);
444
                        feaFondos.setProp("elevation", string);
445
            }
446
        }
447
        public void addVertex(DxfGroupVector grp) throws Exception {
448
                double x = 0.0, y = 0.0, z = 0.0;
449
                int vFlags = 0;
450
                if (isDoubleFeatured) {
451
                        Feature feaBordes = lastFeaBordes;                
452
                        Feature feaFondos = lastFeaFondos;                
453
                        LineString3D lineString3D = (LineString3D)feaBordes.getGeometry();
454
                        Polygon3D polygon3D = (Polygon3D)feaFondos.getGeometry();
455
                        if (grp.hasCode(8)) {
456
                                feaBordes.setProp("layer", grp.getDataAsString(8));
457
                                feaFondos.setProp("layer", grp.getDataAsString(8));
458
                        }
459
                        if (grp.hasCode(70)) {
460
                                vFlags = grp.getDataAsInt(70);
461
                        }
462
                        x  = grp.getDataAsDouble(10);
463
                        y  = grp.getDataAsDouble(20);
464
                        z = grp.getDataAsDouble(30);
465
                        Point3D point_in = new Point3D(x, y, z);
466
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
467
                        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
468
                        x = point_out.getX();
469
                        y = point_out.getY();
470
                        z = point_out.getZ();
471
                        if (z!=0.0) dxf3DFile = true;
472
                        if (z!=lastVertexElevation && lineString3D.pointNr()>0) constantPolylineElevation = false;
473
                        lastVertexElevation = z;
474
                        //System.out.println("addVertex(): vFlags = " + vFlags);
475
                        if ((vFlags & 0x80) == 0x80 && (vFlags & 0x40) == 0) {
476
                                int [] face = {0,0,0,0};
477
                                face[0] = grp.getDataAsInt(71);
478
                                face[1] = grp.getDataAsInt(72);
479
                                face[2] = grp.getDataAsInt(73);
480
                                face[3] = grp.getDataAsInt(74);
481
                                addFace(face);
482
                        } else if ((vFlags & 0x10) == 0x10) {
483
                                // Son vertices que se trataran cuando se implementen
484
                                // los splines. En principio no se hace nada con ellos.
485
                        } else {
486
                                Point3D pt = new Point3D(proj.createPoint( x, y).getX(), proj.createPoint( x, y).getY(), z);
487
                                lineString3D.add(pt);
488
                                polygon3D.add(pt);
489
                                if (lineString3D.pointNr() == 1) {
490
                                        firstPt = pt;
491
                                }
492
                                if (bulge == 0.0) {
493
                                        if (grp.hasCode(42)) {
494
                                                bulge = grp.getDataAsDouble(42);
495
                                        } else { bulge = 0.0; }
496
                                } else {
497
                                        double bulge_aux = 0.0;
498
                                        if (grp.hasCode(42)) {
499
                                                bulge_aux = grp.getDataAsDouble(42);
500
                                        } else { bulge_aux = 0.0; }
501
                                        //int cnt = lineString.pointNr();
502
                                        lineString3D.remove(lineString3D.pointNr()-1);
503
                                        lineString3D.remove(lineString3D.pointNr()-1);
504
                                        polygon3D.remove(polygon3D.pointNr()-1);
505
                                        polygon3D.remove(polygon3D.pointNr()-1);
506
                                        Vector arc = createArc(ptAnterior, pt, bulge);
507
                                        if (bulge>0) {
508
                                                for (int i=0; i<arc.size(); i++) {
509
                                                        Point2D ptAux = new Point2D.Double();
510
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
511
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
512
                                                        lineString3D.add(ptAux3D);
513
                                                        polygon3D.add(ptAux3D);
514
                                                        if (lineString3D.pointNr() == 1) firstPt = ptAux3D;
515
                                                }
516
                                        } else {
517
                                                for (int i=arc.size()-1; i>=0; i--) {
518
                                                        Point2D ptAux = new Point2D.Double();
519
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
520
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
521
                                                        lineString3D.add(ptAux3D);
522
                                                        polygon3D.add(ptAux3D);
523
                                                        if (lineString3D.pointNr() == 1 || polygon3D.pointNr() == 1) firstPt = ptAux3D;
524
                                                }                        
525
                                        }
526
                                        bulge = bulge_aux;
527
                                }
528
                                ptAnterior = pt;
529
                        }
530
                } else {
531
                        Feature feaBordes = lastFeaBordes;
532
                        LineString3D lineString3D = (LineString3D)feaBordes.getGeometry();
533
                        if (grp.hasCode(8))
534
                                feaBordes.setProp("layer", grp.getDataAsString(8));
535
                        if (grp.hasCode(70)) {
536
                                vFlags = grp.getDataAsInt(70);
537
                        }
538
                        x = grp.getDataAsDouble(10);
539
                        y = grp.getDataAsDouble(20);
540
                        z = grp.getDataAsDouble(30);
541
                        Point3D point_in = new Point3D(x, y, z);
542
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
543
                        Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
544
                        x = point_out.getX();
545
                        y = point_out.getY();
546
                        z = point_out.getZ();
547
                        if (z!=0.0) dxf3DFile = true;
548
                        if (z!=lastVertexElevation && lineString3D.pointNr()>0) constantPolylineElevation = false;
549
                        lastVertexElevation = z;
550
                        if ((vFlags & 0x80) == 0x80 && (vFlags & 0x40) == 0) {
551
                                int [] face = {0,0,0,0};
552
                                face[0] = grp.getDataAsInt(71);
553
                                face[1] = grp.getDataAsInt(72);
554
                                face[2] = grp.getDataAsInt(73);
555
                                face[3] = grp.getDataAsInt(74);
556
                                addFace(face);
557
                        } else if ((vFlags & 16) == 16) {
558
                                // no se hace nada.
559
                        } else {
560
                                Point3D pt = new Point3D(proj.createPoint( x, y).getX(), proj.createPoint( x, y).getY(), z);
561
                                lineString3D.add(pt);
562
                                //System.out.println("addVertex: pt = " + pt);
563
                                if (lineString3D.pointNr() == 1) {
564
                                        firstPt = pt;
565
                                        //System.out.println("addVertex(Primer pto de la lineString, firstPt=pt): firstPt = " + firstPt);
566
                                }
567
                                if (bulge == 0.0) {
568
                                        if (grp.hasCode(42)) {
569
                                                bulge = grp.getDataAsDouble(42);
570
                                        } else { bulge = 0.0; }
571
                                        //System.out.println("addVertex: El vertice anterior tenia bulge=0.0");
572
                                } else {
573
                                        //System.out.println("addVertex: El vertice anterior tiene bulge = " + bulge);
574
                                        double bulge_aux = 0.0;
575
                                        if (grp.hasCode(42)) {
576
                                                bulge_aux = grp.getDataAsDouble(42);
577
                                        } else { bulge_aux = 0.0; }
578
                                        // Borro los puntos inicio y final del arco.
579
                                        lineString3D.remove(lineString3D.pointNr()-1);
580
                                        lineString3D.remove(lineString3D.pointNr()-1);
581
                                        Vector arc = createArc(ptAnterior, pt, bulge);
582
                                        if (bulge>0) {
583
                                                for (int i=0; i<arc.size(); i++) {
584
                                                        Point2D ptAux = new Point2D.Double();
585
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
586
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
587
                                                        lineString3D.add(ptAux3D);
588
                                                        if (lineString3D.pointNr() == 1) firstPt = ptAux3D;
589
                                                }
590
                                        } else {
591
                                                for (int i=arc.size()-1; i>=0; i--) {
592
                                                        Point2D ptAux = new Point2D.Double();
593
                                                        ptAux = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
594
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), z);
595
                                                        lineString3D.add(ptAux3D);
596
                                                        if (lineString3D.pointNr() == 1) firstPt = ptAux3D;
597
                                                }                                        
598
                                        }
599
                                        bulge = bulge_aux;
600
                                }
601
                                ptAnterior = pt;                                
602
                        }
603
                }
604
        }
605

    
606
        public void createLwPolyline(DxfGroupVector grp) throws Exception {
607
                double x = 0.0, y = 0.0;
608
                double elev = 0.0;
609
                DxfGroup g = null;
610
                LineString3D lineString3D = new LineString3D();
611
                Polygon3D polygon3D = new Polygon3D();
612
                //Geometry geometria;
613
                //Feature feature= new Feature();
614
                Feature feaBordes= new Feature();
615
                Feature feaFondos= new Feature();
616
                int flags = 0;
617
                int NumberOfVertices = 0;
618
                
619
                //feature.setProp("dxfEntity", "LwPolyline");
620
                feaBordes.setProp("dxfEntity", "LwPolyline");
621
                feaFondos.setProp("dxfEntity", "LwPolyline");
622
                if (grp.hasCode(8))
623
                        //feature.setProp("layer", grp.getDataAsString(8));
624
                        feaBordes.setProp("layer", grp.getDataAsString(8));                        
625
                        feaFondos.setProp("layer", grp.getDataAsString(8));                        
626
                if (grp.hasCode(38)) {
627
                        elev = grp.getDataAsDouble(38);
628
                        if (elev!=0.0) dxf3DFile = true;
629
                        Double doub = new Double(elev);
630
                        String string = doub.toString();
631
                        //feature.setProp("elevation", string);
632
                        feaBordes.setProp("elevation", string);
633
                        feaFondos.setProp("elevation", string);
634
                } else {
635
                        Double doub = new Double(0.0);
636
                        //feature.setProp("elevation", doub.toString());
637
                        feaBordes.setProp("elevation", doub.toString());
638
                        feaFondos.setProp("elevation", doub.toString());
639
                }
640
                if (grp.hasCode(39)) {
641
                        Double doub = new Double(grp.getDataAsDouble(39));
642
                        String string = doub.toString();
643
                        //feature.setProp("thickness", string);
644
                        feaBordes.setProp("thickness", string);
645
                        feaFondos.setProp("thickness", string);
646
                } else {
647
                        Double doub = new Double(0.0);
648
                        //feature.setProp("thickness", doub.toString());
649
                        feaBordes.setProp("thickness", doub.toString());
650
                        feaFondos.setProp("thickness", doub.toString());
651
                }
652
                if (grp.hasCode(62)) {
653
                        Integer integer = new Integer(grp.getDataAsInt(62));
654
                        String string = integer.toString();
655
                        //feature.setProp("color", string);
656
                        feaBordes.setProp("color", string);
657
                        feaFondos.setProp("color", string);
658
                        feaBordes.setProp("colorByLayer", "false");
659
                        feaFondos.setProp("colorByLayer", "false");
660
                } else {
661
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
662
                        int clr = layer.colorNumber;
663
                        Integer integer = new Integer(clr);
664
                        String string = integer.toString();
665
                        //feature.setProp("color", string);
666
                        feaBordes.setProp("color", string);
667
                        feaFondos.setProp("color", string);
668
                        feaBordes.setProp("colorByLayer", "true");
669
                        feaFondos.setProp("colorByLayer", "true");
670
                }
671
                if (grp.hasCode(70))
672
                        flags = grp.getDataAsInt(70);
673
                if ((flags & 0x01) == 0x01) {
674
                        //geometria = new Polygon();
675
                        feaBordes.setGeometry(lineString3D);
676
                        feaFondos.setGeometry(polygon3D);
677
                        isDoubleFeatured = true;
678
                } else {
679
                        //geometria = new LineString();
680
                        feaBordes.setGeometry(lineString3D);
681
                        isDoubleFeatured = false;
682
                }
683
                if (grp.hasCode(90))
684
                        NumberOfVertices = grp.getDataAsInt(90);
685
                
686
                int j = 0;
687
                double firstX = 0.0;
688
                double firstY = 0.0;
689
                boolean hasBulge = false;
690
                double bulgeLwp = 0.0;
691
                for (int i=0; i<grp.size(); i++) {
692
                        g = (DxfGroup) grp.get(i);
693
                        if (g.getCode() == 10) {
694
                                j++;
695
                                x = ((Double) g.getData()).doubleValue();
696
                        } else if (g.getCode() == 20) {
697
                                y = ((Double) g.getData()).doubleValue();
698
                                if (hasBulge) {
699
                                        Point2D finalPoint = new Point2D.Double(x, y);
700
                                        Vector arc = createArc(((LineString3D)lineString3D).get(lineString3D.pointNr()-1), finalPoint, bulgeLwp);
701
                                        lineString3D.remove(lineString3D.pointNr()-1);
702
                                        if (isDoubleFeatured) polygon3D.remove(polygon3D.pointNr()-1);
703
                                        if (bulgeLwp>0) {
704
                                                for (int k=0; k<arc.size(); k++) {
705
                                                        Point2D ptAux = new Point2D.Double();
706
                                                        ptAux = proj.createPoint(((Point2D)arc.get(k)).getX(), ((Point2D)arc.get(k)).getY());
707
                                                        //System.out.println("createLwPolyline: ptAux = " + ptAux);
708
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), elev);
709
                                                        lineString3D.add(ptAux3D);
710
                                                        //if (lineString.pointNr() == 1) firstPt = ptAux;
711
                                                        if (isDoubleFeatured) polygon3D.add(ptAux3D);
712
                                                        if (lineString3D.pointNr() == 1 || polygon3D.pointNr() == 1) firstPt = ptAux3D;
713
                                                }
714
                                        } else {
715
                                                for (int k=arc.size()-1; k>=0; k--) {
716
                                                        Point2D ptAux = new Point2D.Double();
717
                                                        ptAux = proj.createPoint(((Point2D)arc.get(k)).getX(), ((Point2D)arc.get(k)).getY());
718
                                                        Point3D ptAux3D = new Point3D(ptAux.getX(), ptAux.getY(), elev);
719
                                                        lineString3D.add(ptAux3D);
720
                                                        if (isDoubleFeatured) polygon3D.add(ptAux3D);
721
                                                        if (lineString3D.pointNr() == 1 || polygon3D.pointNr() == 1) firstPt = ptAux3D;
722
                                                }
723
                                        }
724
                                        hasBulge = false;
725
                                        bulgeLwp = 0.0;
726
                                } else {
727
                                        //System.out.println("createLwPolyline: hasBulge siempre es false");
728
                                        Point3D ptAux3D = new Point3D(proj.createPoint( x, y ).getX(), proj.createPoint( x, y ).getY(), elev);
729
                                    lineString3D.add(ptAux3D);
730
                                        if (isDoubleFeatured) polygon3D.add(ptAux3D);
731
                                }
732
                                if (j == 1) {
733
                                        firstX = x;
734
                                        firstY = y;
735
                                }
736
                                x = 0.0; y = 0.0;
737
                        } else if (g.getCode() == 42) {
738
                                //System.out.println("createLwPolyline: Lee el bulgeLwp");
739
                                hasBulge = true;
740
                                bulgeLwp = ((Double) g.getData()).doubleValue();
741
                        }
742
                        
743
                }
744
                if (isDoubleFeatured) {
745
                        //geometria.add(proj.createPoint(firstX, firstY));                        
746
                        Point3D ptAux3D = new Point3D(proj.createPoint(firstX, firstY).getX(), proj.createPoint(firstX, firstY).getY(), elev);
747
                        lineString3D.add(ptAux3D);                        
748
                        polygon3D.add(ptAux3D);                        
749
                }
750
                                
751
                lastFeaBordes = feaBordes;
752
                if (isDoubleFeatured) lastFeaFondos = feaFondos;
753
                
754
                // 041130: Rellena las props con los atributos.
755
                completeAttributes(lastFeaBordes);
756
                completeAttributes(lastFeaFondos);
757
                
758
                //features.add(feature);
759
                if (addingToBlock == false) {
760
                        features.add(feaBordes);
761
                        if (isDoubleFeatured) features.add(feaFondos);
762
                } else {
763
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
764
                        blk.add(feaBordes);
765
                        if (isDoubleFeatured) blk.add(feaFondos);
766
                }
767
                isDoubleFeatured = false;
768
        }
769

    
770
        public void createLine(DxfGroupVector grp) throws Exception {
771
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0;
772
                double elev = 0.0;
773
                DxfGroup g = null;
774
                Point2D pt1 = null, pt2 = null;
775
                LineString3D lineString3D = new LineString3D();
776
                Feature feature = new Feature();
777

    
778
                feature.setProp("dxfEntity", "Line");
779
                if (grp.hasCode(8))
780
                        feature.setProp("layer", grp.getDataAsString(8));
781
                if (grp.hasCode(39)) {
782
                        Double doub = new Double(grp.getDataAsDouble(39));
783
                        String string = doub.toString();
784
                        feature.setProp("thickness", string);
785
                } else {
786
                        Double doub = new Double(0.0);
787
                        feature.setProp("thickness", doub.toString());
788
                }
789
                if (grp.hasCode(62)) {
790
                        Integer integer = new Integer(grp.getDataAsInt(62));
791
                        String string = integer.toString();
792
                        feature.setProp("color", string);
793
                        feature.setProp("colorByLayer", "false");
794
                } else {
795
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
796
                        int clr = layer.colorNumber;
797
                        Integer integer = new Integer(clr);
798
                        String string = integer.toString();
799
                        feature.setProp("color", string);
800
                        feature.setProp("colorByLayer", "true");
801
                }
802
                x = grp.getDataAsDouble(10);
803
                y = grp.getDataAsDouble(20);
804
                z1 = grp.getDataAsDouble(30);
805
                /*if (grp.hasCode(30)) {
806
                        z1 = grp.getDataAsDouble(30);
807
                        elev = z1;
808
                        Double doub = new Double(elev);
809
                        String string = doub.toString();
810
                        //feature.setProp("elevation", string);
811
                }*/
812
                pt1 = proj.createPoint(x, y);
813
                x = grp.getDataAsDouble(11);
814
                y = grp.getDataAsDouble(21);
815
                z2 = grp.getDataAsDouble(31);
816
                /*if (grp.hasCode(31)) {
817
                        z2 = grp.getDataAsDouble(31);
818
                } else {
819
                        // Cuando no se especifican z para las lineas se asume que la
820
                        // z es cero.
821
                        Double doub = new Double(0.0);
822
                        //feature.setProp("elevation", doub.toString());
823
                }*/
824
                pt2 = proj.createPoint(x, y);
825
                if (grp.hasCode(210))
826
                        xtruX = grp.getDataAsDouble(210);
827
                if (grp.hasCode(220))
828
                        xtruY = grp.getDataAsDouble(220);
829
                if (grp.hasCode(230))
830
                        xtruZ = grp.getDataAsDouble(230);
831
                Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
832
                Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
833
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
834
                Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
835
                Point3D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
836
                if (point_out1.getZ()!=0.0) dxf3DFile = true;
837
                if (point_out2.getZ()!=0.0) dxf3DFile = true;
838
                
839
                if (point_out1.getZ()==point_out2.getZ()) {
840
                        elev = z1;
841
                        Double doub = new Double(elev);
842
                        String string = doub.toString();
843
                        feature.setProp("elevation", string);
844
                } else {
845
                        elev = 0.0;
846
                        Double doub = new Double(elev);
847
                        String string = doub.toString();
848
                        feature.setProp("elevation", string);
849
                }
850
                
851
                //pt1.setLocation(point_out1);
852
                //pt2.setLocation(point_out2);
853
                lineString3D.add(point_out1);
854
                lineString3D.add(point_out2);
855
                
856
                feature.setGeometry(lineString3D);
857
                
858
                // 041130: Rellena las props con los atributos.
859
                completeAttributes(feature);
860
                
861
                //features.add(feature);
862
                if (addingToBlock == false) {
863
                        //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
864
                        features.add(feature);
865
                } else {
866
                        //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
867
                        blk.add(feature);
868
                }
869
        }
870

    
871
        /* (non-Javadoc)
872
         * @see org.cresques.io.DxfFile.EntityFactory#createText(org.cresques.io.DxfGroupVector)
873
         */
874
        public void createText(DxfGroupVector grp) throws Exception {
875
                double x = 0.0, y = 0.0, z = 0.0, h= 0.0, rot= 0.0;
876
                DxfGroup g = null;
877
                //Point3D pt1 = null, pt2 = null;
878
                Point3D pt = null;
879
                org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
880
                
881
                point.setTextPoint(true);
882
                
883
                Feature feature = new Feature();
884

    
885
                feature.setProp("dxfEntity", "Text");
886
                if (grp.hasCode(8))
887
                        feature.setProp("layer", grp.getDataAsString(8));
888
                if (grp.hasCode(39)) {
889
                        Double doub = new Double(grp.getDataAsDouble(39));
890
                        String string = doub.toString();
891
                        feature.setProp("thickness", string);
892
                } else {
893
                        Double doub = new Double(0.0);
894
                        feature.setProp("thickness", doub.toString());
895
                }
896
                if (grp.hasCode(62)) {
897
                        Integer integer = new Integer(grp.getDataAsInt(62));
898
                        String string = integer.toString();
899
                        feature.setProp("color", string);
900
                        feature.setProp("colorByLayer", "false");
901
                } else {
902
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
903
                        int clr = layer.colorNumber;
904
                        Integer integer = new Integer(clr);
905
                        String string = integer.toString();
906
                        feature.setProp("color", string);
907
                        feature.setProp("colorByLayer", "true");
908
                }
909
                if (grp.hasCode(1)) {
910
                        String strAux1 = grp.getDataAsString(1);                        
911
                        strAux1 = DxfConvTexts.ConvertText(strAux1);
912
                        feature.setProp("text", strAux1);
913
                } else {
914
                        feature.setProp("text", "No Text Code");
915
                }
916
                if (grp.hasCode(40)) {
917
                        Double heightD = new Double(grp.getDataAsDouble(40));
918
                        String heightS = heightD.toString();
919
                        feature.setProp("textHeight", heightS);
920
                } else {
921
                        feature.setProp("textHeight", "20.0");
922
                }
923
                if (grp.hasCode(50)) {
924
                        Double rotD = new Double(grp.getDataAsDouble(50));
925
                        String rotS = rotD.toString();
926
                        feature.setProp("textRotation", rotS);
927
                        //System.out.println("rotS = " + rotS);
928
                } else {
929
                        feature.setProp("textRotation", "0.0");
930
                }
931
                x = grp.getDataAsDouble(10);
932
                y = grp.getDataAsDouble(20);
933
                z = grp.getDataAsDouble(30);
934
                /*if (grp.hasCode(30)){
935
                        Double doub = new Double(z);
936
                        String string = doub.toString();
937
                        feature.setProp("elevation", string);
938
                } else {
939
                        Double doub = new Double(0.0);
940
                        feature.setProp("elevation", doub.toString());
941
                }*/
942
                if (grp.hasCode(210))
943
                        xtruX = grp.getDataAsDouble(210);
944
                if (grp.hasCode(220))
945
                        xtruY = grp.getDataAsDouble(220);
946
                if (grp.hasCode(230))
947
                        xtruZ = grp.getDataAsDouble(230);
948
                Point3D point_in = new Point3D(x, y, z);
949
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
950
                Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
951
                x = point_out.getX();
952
                y = point_out.getY();
953
                z = point_out.getZ();
954
                Double doub = new Double(z);
955
                feature.setProp("elevation", doub.toString());
956
                if (z!=0.0) dxf3DFile = true;
957
                point.add(new Point3D(x, y, z));
958
                feature.setGeometry(point);
959
                
960
                // 041130: Rellena las props con los atributos.
961
                completeAttributes(feature);
962
                
963
                //features.add(feature);
964
                if (addingToBlock == false) {
965
                        features.add(feature);
966
                } else {
967
                        //System.out.println("createText(): A?adimos un text al bloque " + iterator);
968
                        blk.add(feature);
969
                }
970
        }
971
        
972
        public void createMText(DxfGroupVector grp) throws Exception {
973
                double x = 0.0, y = 0.0, z = 0.0, h= 0.0, rot= 0.0;
974
                DxfGroup g = null;
975
                //Point2D pt1 = null, pt2 = null;
976
                Point3D pt = null;
977
                org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
978
                
979
                point.setTextPoint(true);
980
                
981
                Feature feature = new Feature();
982

    
983
                feature.setProp("dxfEntity", "Text");
984
                if (grp.hasCode(8))
985
                        feature.setProp("layer", grp.getDataAsString(8));
986
                if (grp.hasCode(39)) {
987
                        Double doub = new Double(grp.getDataAsDouble(39));
988
                        String string = doub.toString();
989
                        feature.setProp("thickness", string);
990
                } else {
991
                        Double doub = new Double(0.0);
992
                        feature.setProp("thickness", doub.toString());
993
                }
994
                if (grp.hasCode(62)) {
995
                        Integer integer = new Integer(grp.getDataAsInt(62));
996
                        String string = integer.toString();
997
                        feature.setProp("color", string);
998
                        feature.setProp("colorByLayer", "false");
999
                } else {
1000
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1001
                        int clr = layer.colorNumber;
1002
                        Integer integer = new Integer(clr);
1003
                        String string = integer.toString();
1004
                        feature.setProp("color", string);
1005
                        feature.setProp("colorByLayer", "true");
1006
                }
1007
                if (grp.hasCode(1)) {
1008
                        String strAux1 = grp.getDataAsString(1);                        
1009
                        strAux1 = DxfConvTexts.ConvertText(strAux1);
1010
                        feature.setProp("text", strAux1);
1011
                } else {
1012
                        feature.setProp("text", "No Text Code");
1013
                }
1014
                if (grp.hasCode(40)) {
1015
                        Double heightD = new Double(grp.getDataAsDouble(40));
1016
                        String heightS = heightD.toString();
1017
                        feature.setProp("textHeight", heightS);
1018
                } else {
1019
                        feature.setProp("textHeight", "20.0");
1020
                }
1021
                if (grp.hasCode(50)) {
1022
                        Double rotD = new Double(grp.getDataAsDouble(50));
1023
                        String rotS = rotD.toString();
1024
                        feature.setProp("textRotation", rotS);
1025
                        //System.out.println("rotS = " + rotS);
1026
                } else {
1027
                        feature.setProp("textRotation", "0.0");
1028
                }
1029
                if (grp.hasCode(71)) {
1030
                        int attachPoint = grp.getDataAsInt(71);
1031
                        if (attachPoint == 1) {
1032
                        } else if (attachPoint == 2) {
1033
                        } else if (attachPoint == 3) {
1034
                        } else if (attachPoint == 4) {
1035
                        } else if (attachPoint == 5) {
1036
                        } else if (attachPoint == 6) {
1037
                        } else if (attachPoint == 7) {
1038
                        } else if (attachPoint == 8) {
1039
                        } else if (attachPoint == 9) {
1040
                        }
1041
                }
1042
                if (grp.hasCode(72)) {
1043
                        int drawDirection = grp.getDataAsInt(71);
1044
                        if (drawDirection == 1) {
1045
                        } else if (drawDirection == 3) {
1046
                        } else if (drawDirection == 5) {
1047
                        }
1048
                }
1049
                if (grp.hasCode(73)) {
1050
                        int spacingStyle = grp.getDataAsInt(71);
1051
                        if (spacingStyle == 1) {
1052
                        } else if (spacingStyle == 2) {
1053
                        }
1054
                }
1055
                x = grp.getDataAsDouble(10);
1056
                y = grp.getDataAsDouble(20);
1057
                z = grp.getDataAsDouble(30);
1058
                /*if (grp.hasCode(30)){
1059
                        z = grp.getDataAsDouble(30);
1060
                        Double doub = new Double(z);
1061
                        String string = doub.toString();
1062
                        feature.setProp("elevation", string);
1063
                } else {
1064
                        Double doub = new Double(0.0);
1065
                        feature.setProp("elevation", doub.toString());
1066
                }*/
1067
                if (grp.hasCode(210))
1068
                        xtruX = grp.getDataAsDouble(210);
1069
                if (grp.hasCode(220))
1070
                        xtruY = grp.getDataAsDouble(220);
1071
                if (grp.hasCode(230))
1072
                        xtruZ = grp.getDataAsDouble(230);
1073
                Point3D point_in = new Point3D(x, y, z);
1074
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
1075
                Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1076
                x = point_out.getX();
1077
                y = point_out.getY();
1078
                z = point_out.getZ();
1079
                Double doub = new Double(z);
1080
                feature.setProp("elevation", doub.toString());
1081
                if (z!=0.0) dxf3DFile = true;
1082
                point.add(new Point3D(x, y, z));
1083
                feature.setGeometry(point);
1084
                
1085
                // 041130: Rellena las props con los atributos.
1086
                completeAttributes(feature);
1087
                
1088
                //features.add(feature);
1089
                if (addingToBlock == false) {
1090
                        features.add(feature);
1091
                } else {
1092
                        //System.out.println("createText(): A?adimos un text al bloque " + iterator);
1093
                        blk.add(feature);
1094
                }
1095
        }
1096

    
1097
        public void createPoint(DxfGroupVector grp) throws Exception {
1098
                double x = 0.0, y = 0.0, z = 0.0;
1099
                DxfGroup g = null;
1100
                Point3D pt = null;
1101
                org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
1102
                Feature feature = new Feature();
1103

    
1104
                feature.setProp("dxfEntity", "Point");
1105
                if (grp.hasCode(8))
1106
                        feature.setProp("layer", grp.getDataAsString(8));
1107
                if (grp.hasCode(39)) {
1108
                        Double doub = new Double(grp.getDataAsDouble(39));
1109
                        String string = doub.toString();
1110
                        feature.setProp("thickness", string);
1111
                } else {
1112
                        Double doub = new Double(0.0);
1113
                        feature.setProp("thickness", doub.toString());
1114
                }
1115
                if (grp.hasCode(62)) {
1116
                        Integer integer = new Integer(grp.getDataAsInt(62));
1117
                        String string = integer.toString();
1118
                        feature.setProp("color", string);
1119
                        feature.setProp("colorByLayer", "false");
1120
                } else {
1121
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1122
                        int clr = layer.colorNumber;
1123
                        Integer integer = new Integer(clr);
1124
                        String string = integer.toString();
1125
                        feature.setProp("color", string);
1126
                        feature.setProp("colorByLayer", "true");
1127
                }
1128
                x = grp.getDataAsDouble(10);
1129
                y = grp.getDataAsDouble(20);
1130
                z = grp.getDataAsDouble(30);
1131
                /*if (grp.hasCode(30)) {
1132
                        z = grp.getDataAsDouble(30);
1133
                        Double doub = new Double(z);
1134
                        String string = doub.toString();
1135
                        feature.setProp("elevation", string);
1136
                } else {
1137
                        Double doub = new Double(0.0);
1138
                        feature.setProp("elevation", doub.toString());
1139
                }*/
1140
                if (grp.hasCode(210))
1141
                        xtruX = grp.getDataAsDouble(210);
1142
                if (grp.hasCode(220))
1143
                        xtruY = grp.getDataAsDouble(220);
1144
                if (grp.hasCode(230))
1145
                        xtruZ = grp.getDataAsDouble(230);
1146
                Point3D point_in = new Point3D(x, y, z);
1147
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
1148
                Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1149
                x = point_out.getX();
1150
                y = point_out.getY();
1151
                z = point_out.getZ();
1152
                Double doub = new Double(z);
1153
                feature.setProp("elevation", doub.toString());
1154
                if (z!=0.0) dxf3DFile = true;
1155
                point.add(new Point3D(x, y, z));
1156
                feature.setGeometry(point);
1157
                
1158
                // 041130: Rellena las props con los atributos.
1159
                completeAttributes(feature);
1160
                /*for (int i=0;i<attributes.size();i++) {
1161
                        String[] att = new String[2];
1162
                        att = (String[])attributes.get(i);
1163
                        feature.setProp(att[0],att[1]);
1164
                }*/
1165
                
1166
                //features.add(feature);
1167
                if (addingToBlock == false) {
1168
                        features.add(feature);
1169
                } else {
1170
                        //System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
1171
                        blk.add(feature);
1172
                }
1173
        }
1174

    
1175
        public void createCircle(DxfGroupVector grp) throws Exception {
1176
                double x = 0.0, y = 0.0, z = 0.0;
1177
                double r = 0.0;
1178
                Point3D firstPt = new Point3D();
1179
                DxfGroup g = null;
1180
                LineString3D lineString3D = new LineString3D();
1181
                Polygon3D polygon3D = new Polygon3D();
1182
                Feature feaBordes = new Feature();
1183
                Feature feaFondos = new Feature();
1184
                
1185
                feaBordes.setProp("dxfEntity", "Circle");
1186
                feaFondos.setProp("dxfEntity", "Circle");
1187
                if (grp.hasCode(8))
1188
                        feaBordes.setProp("layer", grp.getDataAsString(8));
1189
                        feaFondos.setProp("layer", grp.getDataAsString(8));
1190
                if (grp.hasCode(39)) {
1191
                        Double doub = new Double(grp.getDataAsDouble(39));
1192
                        String string = doub.toString();
1193
                        feaBordes.setProp("thickness", string);
1194
                        feaFondos.setProp("thickness", string);
1195
                } else {
1196
                        Double doub = new Double(0.0);
1197
                        feaBordes.setProp("thickness", doub.toString());
1198
                        feaFondos.setProp("thickness", doub.toString());
1199
                }
1200
                if (grp.hasCode(62)) {
1201
                        Integer integer = new Integer(grp.getDataAsInt(62));
1202
                        String string = integer.toString();
1203
                        feaBordes.setProp("color", string);
1204
                        feaFondos.setProp("color", string);
1205
                        feaBordes.setProp("colorByLayer", "false");
1206
                        feaFondos.setProp("colorByLayer", "false");
1207
                } else {
1208
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1209
                        int clr = layer.colorNumber;
1210
                        Integer integer = new Integer(clr);
1211
                        String string = integer.toString();
1212
                        feaBordes.setProp("color", string);
1213
                        feaFondos.setProp("color", string);
1214
                        feaBordes.setProp("colorByLayer", "true");
1215
                        feaFondos.setProp("colorByLayer", "true");
1216
                }
1217
                x = grp.getDataAsDouble(10);
1218
                y = grp.getDataAsDouble(20);
1219
                z = grp.getDataAsDouble(30);
1220
                /*if (grp.hasCode(30)) {
1221
                        z = grp.getDataAsDouble(30);
1222
                        Double doub = new Double(z);
1223
                        String string = doub.toString();
1224
                        feaBordes.setProp("elevation", string);
1225
                        feaFondos.setProp("elevation", string);
1226
                } else {
1227
                        Double doub = new Double(0.0);
1228
                        feaBordes.setProp("elevation", doub.toString());
1229
                        feaFondos.setProp("elevation", doub.toString());
1230
                }*/
1231
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
1232
                if (grp.hasCode(210))
1233
                        xtruX = grp.getDataAsDouble(210);
1234
                if (grp.hasCode(220))
1235
                        xtruY = grp.getDataAsDouble(220);
1236
                if (grp.hasCode(230))
1237
                        xtruZ = grp.getDataAsDouble(230);
1238
                Point3D point_in = new Point3D(x, y, z);
1239
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
1240
                Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1241
                x = point_out.getX();
1242
                y = point_out.getY();
1243
                z = point_out.getZ();
1244
                Double doub = new Double(z);
1245
                feaBordes.setProp("elevation", doub.toString());
1246
                feaFondos.setProp("elevation", doub.toString());
1247
                if (z!=0.0) dxf3DFile = true;
1248
                Point2D c = proj.createPoint( x, y);
1249
                Point3D center = new Point3D(c.getX(), c.getY(), z);
1250
                Point3D[] pts = new Point3D[360];
1251
                int angulo = 0;
1252
                for (angulo=0; angulo<360; angulo++) {
1253
                        pts[angulo] = new Point3D(center.getX(), center.getY(), center.getZ());
1254
                        pts[angulo] = new Point3D(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getZ());
1255
                        if (pts.length == 1) {
1256
                                firstPt = pts[angulo];
1257
                        }
1258
                }
1259
                for (int i=0; i<pts.length; i++) {
1260
                        lineString3D.add(pts[i]);
1261
                        polygon3D.add(pts[i]);
1262
                }
1263
                
1264
                feaBordes.setGeometry(lineString3D);
1265
                feaFondos.setGeometry(polygon3D);
1266
                
1267
                // 041130: Rellena las props con los atributos.
1268
                completeAttributes(feaBordes);
1269
                completeAttributes(feaFondos);
1270
                
1271
                //features.add(feature);
1272
                if (addingToBlock == false) {
1273
                        //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
1274
                        features.add(feaBordes);
1275
                        features.add(feaFondos);
1276
                } else {
1277
                        //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
1278
                        blk.add(feaBordes);
1279
                        blk.add(feaFondos);
1280
                }
1281
        }
1282

    
1283
        public void createArc(DxfGroupVector grp) throws Exception {
1284
                double x = 0.0, y = 0.0, z = 0.0;
1285
                double r = 0.0, empieza = 0.0, acaba = 0.0;
1286
                DxfGroup g = null;
1287
                LineString3D lineString3D = new LineString3D();
1288
                Feature feature = new Feature();
1289

    
1290
                feature.setProp("dxfEntity", "Arc");
1291
                if (grp.hasCode(8))
1292
                        feature.setProp("layer", grp.getDataAsString(8));
1293
                if (grp.hasCode(39)) {
1294
                        Double doub = new Double(grp.getDataAsDouble(39));
1295
                        String string = doub.toString();
1296
                        feature.setProp("thickness", string);
1297
                } else {
1298
                        Double doub = new Double(0.0);
1299
                        feature.setProp("thickness", doub.toString());
1300
                }
1301
                if (grp.hasCode(62)) {
1302
                        Integer integer = new Integer(grp.getDataAsInt(62));
1303
                        String string = integer.toString();
1304
                        feature.setProp("color", string);
1305
                        feature.setProp("colorByLayer", "false");
1306
                } else {
1307
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1308
                        int clr = layer.colorNumber;
1309
                        Integer integer = new Integer(clr);
1310
                        String string = integer.toString();
1311
                        feature.setProp("color", string);
1312
                        feature.setProp("colorByLayer", "true");
1313
                }
1314
                x = grp.getDataAsDouble(10);
1315
                y = grp.getDataAsDouble(20);
1316
                z = grp.getDataAsDouble(30);
1317
                /*if (grp.hasCode(30)) {
1318
                        z = grp.getDataAsDouble(30);
1319
                        Double doub = new Double(z);
1320
                        String string = doub.toString();
1321
                        feature.setProp("elevation", string);
1322
                } else {
1323
                        Double doub = new Double(0.0);
1324
                        feature.setProp("elevation", doub.toString());
1325
                }*/
1326
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
1327
                if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50);
1328
                if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51);
1329
                if (grp.hasCode(210))
1330
                        xtruX = grp.getDataAsDouble(210);
1331
                if (grp.hasCode(220))
1332
                        xtruY = grp.getDataAsDouble(220);
1333
                if (grp.hasCode(230))
1334
                        xtruZ = grp.getDataAsDouble(230);
1335
                Point3D point_in = new Point3D(x, y, z);
1336
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
1337
                Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1338
                x = point_out.getX();
1339
                y = point_out.getY();
1340
                z = point_out.getZ();
1341
                Double doub = new Double(z);
1342
                feature.setProp("elevation", doub.toString());
1343
                if (z!=0.0) dxf3DFile = true;
1344
                Point2D c = proj.createPoint( x, y);
1345
                Point3D center = new Point3D(c.getX(), c.getY(), z);
1346
                //System.out.println("empieza = " + empieza + ", acaba = " + acaba);
1347
                int iempieza = (int)empieza;
1348
                int iacaba = (int)acaba;
1349
                //System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
1350
                double angulo = 0;
1351
                Point3D[] pts = null;
1352
                if (empieza <= acaba) {
1353
                        pts = new Point3D[(iacaba-iempieza)+2];
1354
                        angulo = empieza;
1355
                        pts[0] = new Point3D(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0), center.getZ());
1356
                        for (int i=1; i<=(iacaba-iempieza)+1; i++) {
1357
                                angulo = (double)(iempieza+i);
1358
                                pts[i] = new Point3D(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0), center.getZ());
1359
                        }
1360
                        angulo = acaba;
1361
                        pts[(iacaba-iempieza)+1] = new Point3D(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0), center.getZ());
1362
                } else {
1363
                        pts = new Point3D[(360-iempieza)+iacaba+2];
1364
                        angulo = empieza;
1365
                        //System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
1366
                        pts[0] = new Point3D(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0), center.getZ());
1367
                        for (int i=1; i<=(360-iempieza); i++) {
1368
                                angulo = (double)(iempieza+i);
1369
                                pts[i] = new Point3D(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0), center.getZ());
1370
                        }
1371
                        for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) {
1372
                                angulo = (double)(i-(360-iempieza));
1373
                                pts[i] = new Point3D(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0), center.getZ());
1374
                        }
1375
                        angulo = acaba;
1376
                        pts[(360-iempieza)+iacaba+1] = new Point3D(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0), center.getZ());
1377
                }
1378
                for (int i=0; i<pts.length; i++) {
1379
                        lineString3D.add(pts[i]);
1380
                }
1381
                
1382
                feature.setGeometry(lineString3D);
1383
                
1384
                // 041130: Rellena las props con los atributos.
1385
                completeAttributes(feature);
1386
                
1387
                //features.add(feature);
1388
                if (addingToBlock == false) {
1389
                        features.add(feature);
1390
                } else {
1391
                        //System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
1392
                        blk.add(feature);
1393
                }
1394
        }
1395

    
1396
        public void createInsert(DxfGroupVector grp) throws Exception {
1397
                double x = 0.0, y = 0.0, z = 0.0;
1398
                DxfGroup g = null;
1399
                Point3D pt = new Point3D(0.0, 0.0, 0.0);
1400
                Point3D scaleFactor = new Point3D(1.0, 1.0, 1.0);
1401
                double rotAngle = 0.0;
1402
                String blockName = "";
1403

    
1404
                InsPoint3D insert = new InsPoint3D();
1405
                Feature feature = new Feature();
1406
                org.cresques.px.gml.Point3D secondGeom = new org.cresques.px.gml.Point3D();
1407
                Feature secondFeat = new Feature();
1408
                int attributesFollowFlag = 0;
1409

    
1410
                feature.setProp("dxfEntity", "Insert");
1411
                secondFeat.setProp("dxfEntity", "Insert");
1412
                if (grp.hasCode(2)) {
1413
                        blockName = grp.getDataAsString(2);
1414
                        //feature.setProp("blockName", blockName);
1415
                        insert.setBlockName(blockName);
1416
                }
1417
                if (grp.hasCode(8)) {
1418
                        feature.setProp("layer", grp.getDataAsString(8));
1419
                        secondFeat.setProp("layer", grp.getDataAsString(8));
1420
                }
1421
                
1422
                Double doub = new Double(0.0);
1423
                secondFeat.setProp("thickness", doub.toString());
1424
                
1425
                if (grp.hasCode(62)) {
1426
                        Integer integer = new Integer(grp.getDataAsInt(62));
1427
                        String string = integer.toString();
1428
                        feature.setProp("color", string);
1429
                        secondFeat.setProp("color", string);
1430
                        feature.setProp("colorByLayer", "false");
1431
                        secondFeat.setProp("colorByLayer", "false");
1432
                } else {
1433
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1434
                        int clr = layer.colorNumber;
1435
                        Integer integer = new Integer(clr);
1436
                        String string = integer.toString();
1437
                        feature.setProp("color", string);
1438
                        secondFeat.setProp("color", string);
1439
                        feature.setProp("colorByLayer", "true");
1440
                        secondFeat.setProp("colorByLayer", "true");
1441
                }
1442
                if (grp.hasCode(66)) {
1443
                        attributesFollowFlag = grp.getDataAsInt(66);
1444
                }
1445
                x = grp.getDataAsDouble(10);
1446
                y = grp.getDataAsDouble(20);
1447
                z = grp.getDataAsDouble(30);
1448
                /*if (grp.hasCode(30)) {
1449
                        z = grp.getDataAsDouble(30);
1450
                        Double doubz = new Double(z);
1451
                        String string = doubz.toString();
1452
                        feature.setProp("elevation", string);
1453
                        secondFeat.setProp("elevation", string);
1454
                } else {
1455
                        Double elev = new Double(z);
1456
                        //feature.setProp("elevation", doub.toString());
1457
                        feature.setProp("elevation", elev.toString());
1458
                        secondFeat.setProp("elevation", elev.toString());
1459
                }*/
1460
                if (grp.hasCode(41)) {
1461
                        scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
1462
                        insert.setScaleFactor(scaleFactor);
1463
                } else {
1464
                        insert.setScaleFactor(scaleFactor);
1465
                }
1466
                if (grp.hasCode(42)) {
1467
                        scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
1468
                        insert.setScaleFactor(scaleFactor);
1469
                } else {
1470
                        insert.setScaleFactor(scaleFactor);
1471
                }
1472
                if (grp.hasCode(43)) {
1473
                        scaleFactor = new Point3D(scaleFactor.getX(), scaleFactor.getY(), grp.getDataAsDouble(43));
1474
                        insert.setScaleFactor(scaleFactor);
1475
                } else {
1476
                        insert.setScaleFactor(scaleFactor);
1477
                }
1478
                if (grp.hasCode(50)) {
1479
                        rotAngle = grp.getDataAsDouble(50);
1480
                        insert.setRotAngle(rotAngle);
1481
                }
1482
                if (grp.hasCode(210))
1483
                        xtruX = grp.getDataAsDouble(210);
1484
                if (grp.hasCode(220))
1485
                        xtruY = grp.getDataAsDouble(220);
1486
                if (grp.hasCode(230))
1487
                        xtruZ = grp.getDataAsDouble(230);
1488
                Point3D point_in = new Point3D(x, y, z);
1489
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
1490
                Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1491
                x = point_out.getX();
1492
                y = point_out.getY();
1493
                z = point_out.getZ();
1494
                Double doubz = new Double(z);
1495
                feature.setProp("elevation", doubz.toString());
1496
                secondFeat.setProp("elevation", doubz.toString());
1497
                if (z!=0.0) dxf3DFile = true;
1498
                insert.setBlkList(blkList);
1499
                
1500
                insert.encuentraBloque(blockName);
1501
                
1502
                insert.add(new Point3D(x, y, z));
1503
                secondGeom.add(new Point3D(x, y, z));
1504
                
1505
                feature.setGeometry(insert);
1506
                secondFeat.setGeometry(secondGeom);
1507
                
1508
                // 041130: Rellena las props con los atributos.
1509
                completeAttributes(feature);
1510
                completeAttributes(secondFeat);
1511
                /*for (int i=0;i<attributes.size();i++) {
1512
                        String[] att = new String[2];
1513
                        att = (String[])attributes.get(i);
1514
                        secondFeat.setProp(att[0],att[1]);
1515
                }*/
1516
                
1517
                if (insert.getBlockFound()==true && attributesFollowFlag!=1) gestionaInsert(feature);
1518
                
1519
                //if (addingToBlock == false) {
1520
                        //features.add(secondFeat);
1521
                //}
1522
                //if (addingToBlock == true/* && insert.getBlockFound() == true*/) {
1523
                        //System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
1524
                        //blk.add(feature);
1525
                //}
1526
                
1527
                // 041129: A?adido para implementar los ATTRIBS.
1528
                if (attributesFollowFlag==1) {
1529
                        isDoubleFeatured = true;
1530
                        lastFeaBordes = feature;
1531
                        lastFeaFondos = secondFeat;
1532
                } else {
1533
                        if (addingToBlock == false) {
1534
                                features.add(secondFeat);
1535
                        }
1536
                        if (addingToBlock == true/* && insert.getBlockFound() == true*/) {
1537
                                //System.out.println("createInsert(): A?adimos un insert al bloque " + iterator);
1538
                                blk.add(feature);
1539
                        }
1540
                }
1541
        }
1542

    
1543
        public void createSolid(DxfGroupVector grp) throws Exception {
1544
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0;
1545
                DxfGroup g = null;
1546
                //Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
1547
                Point3D[] pts = new Point3D[4];
1548
                //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1549
                
1550
                LineString3D lineString3D = new LineString3D();
1551
                Polygon3D polygon3D = new Polygon3D();
1552
                Feature feaBordes = new Feature();
1553
                Feature feaFondos = new Feature();
1554
                //double elev = 0;
1555

    
1556
                feaBordes.setProp("dxfEntity", "Solid");
1557
                feaFondos.setProp("dxfEntity", "Solid");
1558
                if (grp.hasCode(8))
1559
                        feaBordes.setProp("layer", grp.getDataAsString(8));
1560
                        feaFondos.setProp("layer", grp.getDataAsString(8));
1561
                x = grp.getDataAsDouble(10);
1562
                y = grp.getDataAsDouble(20);
1563
                z1 = grp.getDataAsDouble(30);
1564
                /*if (grp.hasCode(30)) {
1565
                        z1 = grp.getDataAsDouble(30);
1566
                } else {
1567
                        Double doub = new Double(0.0);
1568
                        feaBordes.setProp("elevation", doub.toString());
1569
                        feaFondos.setProp("elevation", doub.toString());
1570
                }*/
1571
                Point2D pto = proj.createPoint(x, y);
1572
                Point3D pto3D = new Point3D(pto.getX(), pto.getY(), z1);
1573
                pts[0] = pto3D;
1574
                x = grp.getDataAsDouble(11);
1575
                y = grp.getDataAsDouble(21);
1576
                z2 = grp.getDataAsDouble(31);
1577
                pto = proj.createPoint(x, y);
1578
                pto3D = new Point3D(pto.getX(), pto.getY(), z2);
1579
                pts[1] = pto3D;
1580
                x = grp.getDataAsDouble(12);
1581
                y = grp.getDataAsDouble(22);
1582
                z3 = grp.getDataAsDouble(32);
1583
                pto = proj.createPoint(x, y);
1584
                pto3D = new Point3D(pto.getX(), pto.getY(), z3);
1585
                pts[2] = pto3D;
1586
                if (grp.hasCode(13)) x = grp.getDataAsDouble(13);
1587
                if (grp.hasCode(23)) y = grp.getDataAsDouble(23);
1588
                if (grp.hasCode(33)) z4 = grp.getDataAsDouble(33);
1589
                pto = proj.createPoint(x, y);
1590
                pto3D = new Point3D(pto.getX(), pto.getY(), z4);
1591
                pts[3] = pto3D;
1592
                if (grp.hasCode(39)) {
1593
                        Double doub = new Double(grp.getDataAsDouble(39));
1594
                        String string = doub.toString();
1595
                        feaBordes.setProp("thickness", string);
1596
                        feaFondos.setProp("thickness", string);
1597
                } else {
1598
                        Double doub = new Double(0.0);
1599
                        feaBordes.setProp("thickness", doub.toString());
1600
                        feaFondos.setProp("thickness", doub.toString());
1601
                }
1602
                if (grp.hasCode(62)) {
1603
                        Integer integer = new Integer(grp.getDataAsInt(62));
1604
                        String string = integer.toString();
1605
                        feaBordes.setProp("color", string);
1606
                        feaFondos.setProp("color", string);
1607
                        feaBordes.setProp("colorByLayer", "false");
1608
                        feaFondos.setProp("colorByLayer", "false");
1609
                } else {
1610
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1611
                        int clr = layer.colorNumber;
1612
                        Integer integer = new Integer(clr);
1613
                        String string = integer.toString();
1614
                        feaBordes.setProp("color", string);
1615
                        feaFondos.setProp("color", string);
1616
                        feaBordes.setProp("colorByLayer", "true");
1617
                        feaFondos.setProp("colorByLayer", "true");
1618
                }
1619
                if (grp.hasCode(210))
1620
                        xtruX = grp.getDataAsDouble(210);
1621
                if (grp.hasCode(220))
1622
                        xtruY = grp.getDataAsDouble(220);
1623
                if (grp.hasCode(230))
1624
                        xtruZ = grp.getDataAsDouble(230);
1625
                Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1);
1626
                Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2);
1627
                Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3);
1628
                Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4);
1629
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
1630
                Point3D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
1631
                Point3D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
1632
                Point3D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
1633
                Point3D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
1634
                pts[0] = new Point3D(point_out1);
1635
                pts[1] = new Point3D(point_out2);
1636
                pts[2] = new Point3D(point_out3);
1637
                pts[3] = new Point3D(point_out4);
1638
                if (pts[0].getZ()!=0.0 || pts[1].getZ()!=0.0 || pts[2].getZ()!=0.0 || pts[3].getZ()!=0.0) dxf3DFile = true;
1639
                Point3D aux = pts[3];
1640
                pts[2] = pts[3];
1641
                pts[3] = aux;
1642
                
1643
                if (pts[0].getZ()==pts[1].getZ() && pts[1].getZ()==pts[2].getZ() && pts[2].getZ()==pts[3].getZ()) {
1644
                        Double doub = new Double(pts[0].getZ());
1645
                        String string = doub.toString();
1646
                        feaBordes.setProp("elevation", string);
1647
                        feaFondos.setProp("elevation", string);
1648
                } else {
1649
                        Double doub = new Double(0.0);
1650
                        String string = doub.toString();
1651
                        feaBordes.setProp("elevation", string);
1652
                        feaFondos.setProp("elevation", string);
1653
                }
1654
                
1655
                for (int i=0; i<pts.length; i++) {
1656
                        lineString3D.add(pts[i]);
1657
                        polygon3D.add(pts[i]);
1658
                }
1659
                
1660
                // Para cerrarlos.
1661
                lineString3D.add(pts[0]);
1662
                polygon3D.add(pts[0]);
1663
                
1664
                feaBordes.setGeometry(lineString3D);
1665
                feaFondos.setGeometry(polygon3D);
1666
                
1667
                // 041130: Rellena las props con los atributos.
1668
                completeAttributes(feaBordes);
1669
                completeAttributes(feaFondos);
1670
                
1671
                //features.add(feature);
1672
                if (addingToBlock == false) {
1673
                        //System.out.println("createSolid(): A?ade un solid a la lista de entidades");
1674
                        features.add(feaBordes);
1675
                        features.add(feaFondos);
1676
                } else {
1677
                        //System.out.println("createSolid(): A?adimos un circulo al bloque " + iterator);
1678
                        blk.add(feaBordes);
1679
                        blk.add(feaFondos);
1680
                }
1681
        }
1682
        
1683
        public void createSpline(DxfGroupVector grp) throws Exception {
1684
                double x = 0.0, y = 0.0, z = 0.0; //elev = 0.0;
1685
                //double elev = 0.0;
1686
                DxfGroup g = null;
1687
                LineString3D lineString3D = new LineString3D();
1688
                Polygon3D polygon3D = new Polygon3D();
1689
                //Geometry geometria;
1690
                //Feature feature= new Feature();
1691
                Feature feaBordes= new Feature();
1692
                Feature feaFondos= new Feature();
1693
                int flags = 0;
1694
                
1695
                //feature.setProp("dxfEntity", "LwPolyline");
1696
                feaBordes.setProp("dxfEntity", "Spline");
1697
                feaFondos.setProp("dxfEntity", "Spline");
1698
                if (grp.hasCode(8)) {
1699
                        //feature.setProp("layer", grp.getDataAsString(8));
1700
                        feaBordes.setProp("layer", grp.getDataAsString(8));                        
1701
                        feaFondos.setProp("layer", grp.getDataAsString(8));                        
1702
                }
1703
                if (grp.hasCode(39)) {
1704
                        Double doub = new Double(grp.getDataAsDouble(39));
1705
                        String string = doub.toString();
1706
                        //feature.setProp("thickness", string);
1707
                        feaBordes.setProp("thickness", string);
1708
                        feaFondos.setProp("thickness", string);
1709
                } else {
1710
                        Double doub = new Double(0.0);
1711
                        //feature.setProp("thickness", doub.toString());
1712
                        feaBordes.setProp("thickness", doub.toString());
1713
                        feaFondos.setProp("thickness", doub.toString());
1714
                }
1715
                if (grp.hasCode(62)) {
1716
                        Integer integer = new Integer(grp.getDataAsInt(62));
1717
                        String string = integer.toString();
1718
                        //feature.setProp("color", string);
1719
                        feaBordes.setProp("color", string);
1720
                        feaFondos.setProp("color", string);
1721
                        feaBordes.setProp("colorByLayer", "false");
1722
                        feaFondos.setProp("colorByLayer", "false");
1723
                } else {
1724
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1725
                        int clr = layer.colorNumber;
1726
                        Integer integer = new Integer(clr);
1727
                        String string = integer.toString();
1728
                        //feature.setProp("color", string);
1729
                        feaBordes.setProp("color", string);
1730
                        feaFondos.setProp("color", string);
1731
                        feaBordes.setProp("colorByLayer", "true");
1732
                        feaFondos.setProp("colorByLayer", "true");
1733
                }
1734
                if (grp.hasCode(70))
1735
                        flags = grp.getDataAsInt(70);
1736
                if ((flags & 0x01) == 0x01) {
1737
                        //geometria = new Polygon();
1738
                        feaBordes.setGeometry(lineString3D);
1739
                        feaFondos.setGeometry(polygon3D);
1740
                        isDoubleFeatured = true;
1741
                } else {
1742
                        //geometria = new LineString();
1743
                        feaBordes.setGeometry(lineString3D);
1744
                        isDoubleFeatured = false;
1745
                }
1746
                
1747
                int j = 0;
1748
                double firstX = 0.0;
1749
                double firstY = 0.0;
1750
                double firstZ = 0.0;
1751
                for (int i=0; i<grp.size(); i++) {
1752
                        g = (DxfGroup) grp.get(i);
1753
                        if (g.getCode() == 10) {
1754
                                j++;
1755
                                x = ((Double) g.getData()).doubleValue();
1756
                        } else if (g.getCode() == 20) {
1757
                                y = ((Double) g.getData()).doubleValue();
1758
                        } else if (g.getCode() == 30) {
1759
                                z = ((Double) g.getData()).doubleValue();                                
1760
                                Point2D p = proj.createPoint(x, y);
1761
                                Point3D p3d = new Point3D(p.getX(), p.getY(), z);
1762
                                lineString3D.add(p3d);
1763
                                if (isDoubleFeatured) polygon3D.add(p3d);
1764
                                if (j == 1) {
1765
                                        firstX = x;
1766
                                        firstY = y;
1767
                                        firstZ = z;
1768
                                }
1769
                                //elev = z;
1770
                                x = 0.0; y = 0.0; z = 0.0;
1771
                        }
1772
                }
1773
                
1774
                //Double doub = new Double(elev);
1775
                //String string = doub.toString();
1776
                //feature.setProp("elevation", string);
1777
                //feaBordes.setProp("elevation", string);
1778
                //feaFondos.setProp("elevation", string);
1779
                
1780
                if (isDoubleFeatured) {
1781
                    Point2D p = proj.createPoint(firstX, firstY);
1782
                        Point3D p3d = new Point3D(p.getX(), p.getY(), z);
1783
                        lineString3D.add(p3d);
1784
                        polygon3D.add(p3d);                        
1785
                }
1786
                
1787
                double zprev = 0;
1788
                boolean constSplineElev = true;
1789
                for (int i=0;i<lineString3D.pointNr();i++) {
1790
                    z = lineString3D.getPoint3D(i).getZ();
1791
                        if (z!=0.0) dxf3DFile = true;
1792
                    if (i>0 && z!=zprev) {
1793
                        constSplineElev = false;
1794
                    }
1795
                    zprev = z;
1796
                }
1797
                if (constSplineElev) {
1798
                        Double doub = new Double(lineString3D.getPoint3D(0).getZ());
1799
                        String string = doub.toString();
1800
                        feaBordes.setProp("elevation", string);
1801
                        if (isDoubleFeatured) feaFondos.setProp("elevation", string);
1802
                } else {
1803
                        Double doub = new Double(0.0);
1804
                        String string = doub.toString();
1805
                        feaBordes.setProp("elevation", string);
1806
                        if (isDoubleFeatured) feaFondos.setProp("elevation", string);
1807
                }
1808
                
1809
                lastFeaBordes = feaBordes;
1810
                if (isDoubleFeatured) lastFeaFondos = feaFondos;
1811
                
1812
                // 041130: Rellena las props con los atributos.
1813
                completeAttributes(feaBordes);
1814
                completeAttributes(feaFondos);
1815
                
1816
                //features.add(feature);
1817
                if (addingToBlock == false) {
1818
                        features.add(feaBordes);
1819
                        if (isDoubleFeatured) features.add(feaFondos);
1820
                } else {
1821
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
1822
                        blk.add(feaBordes);
1823
                        if (isDoubleFeatured) blk.add(feaFondos);
1824
                }
1825
                isDoubleFeatured = false;
1826
        }
1827
        public void createAttdef(DxfGroupVector grp) throws Exception {
1828
                DxfGroup g = null;
1829
                
1830
                String defaultValue = "";
1831
                String tagString = "";
1832
                String textStyleName = "";
1833
                String attribute[] = new String[2];
1834
                boolean tagDefined = false;
1835
                boolean defValDefined = false;
1836
                
1837
                if (grp.hasCode(1)) {
1838
                        defaultValue = grp.getDataAsString(1);                        
1839
                        attribute[1] = DxfConvTexts.ConvertText(defaultValue);
1840
                        defValDefined = true;
1841
                        if (tagDefined) attributes.add(attribute);
1842
                }
1843
                if (grp.hasCode(2)) {
1844
                        tagString = grp.getDataAsString(2);                        
1845
                        attribute[0] = DxfConvTexts.ConvertText(tagString);
1846
                        tagDefined = true;
1847
                        if (defValDefined) attributes.add(attribute);
1848
                }
1849
                if (grp.hasCode(7)) {
1850
                        textStyleName = grp.getDataAsString(7);                        
1851
                        textStyleName = DxfConvTexts.ConvertText(textStyleName);
1852
                }
1853
                setNewAttributes();
1854
        }
1855
        public void createAttrib(DxfGroupVector grp) throws Exception {
1856
                double x = 0.0, y = 0.0, z = 0.0, h= 0.0, rot= 0.0;
1857
                DxfGroup g = null;
1858
                //Point2D pt1 = null, pt2 = null;
1859
                Point3D pt = null;
1860
                org.cresques.px.gml.Point3D point = new org.cresques.px.gml.Point3D();
1861
                
1862
                point.setTextPoint(true);
1863
                
1864
                String defaultValue = "";
1865
                String tagString = "";
1866
                String textStyleName = "";
1867
                String att[] = new String[2];
1868
                boolean tagDefined = false;
1869
                boolean defValDefined = false;
1870
                int attributeFlags = 0;
1871
                
1872
                Feature insFea = lastFeaBordes;
1873
                Feature ptFea = lastFeaFondos;
1874
                
1875
                Feature feature = new Feature();
1876

    
1877
                feature.setProp("dxfEntity", "Attrib"); // <-- Es un INSERT con attributes.
1878
                if (grp.hasCode(8))
1879
                        feature.setProp("layer", grp.getDataAsString(8));
1880
                if (grp.hasCode(39)) {
1881
                        Double doub = new Double(grp.getDataAsDouble(39));
1882
                        String string = doub.toString();
1883
                        feature.setProp("thickness", string);
1884
                } else {
1885
                        Double doub = new Double(0.0);
1886
                        feature.setProp("thickness", doub.toString());
1887
                }
1888
                if (grp.hasCode(62)) {
1889
                        Integer integer = new Integer(grp.getDataAsInt(62));
1890
                        String string = integer.toString();
1891
                        feature.setProp("color", string);
1892
                        feature.setProp("colorByLayer", "false");
1893
                } else {
1894
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
1895
                        int clr = layer.colorNumber;
1896
                        Integer integer = new Integer(clr);
1897
                        String string = integer.toString();
1898
                        feature.setProp("color", string);
1899
                        feature.setProp("colorByLayer", "true");
1900
                }
1901
                
1902
                if (grp.hasCode(1)) {
1903
                        String strAux1 = grp.getDataAsString(1);                        
1904
                        strAux1 = DxfConvTexts.ConvertText(strAux1);
1905
                        defaultValue = strAux1;
1906
                        att[1] = DxfConvTexts.ConvertText(defaultValue);
1907
                        defValDefined = true;
1908
                        if (tagDefined) {
1909
                                insFea.setProp(att[0], att[1]);
1910
                                ptFea.setProp(att[0], att[1]);
1911
                        }
1912
                        feature.setProp("text", strAux1);
1913
                }
1914
                if (grp.hasCode(2)) {
1915
                        String strAux2 = grp.getDataAsString(2);                        
1916
                        strAux2 = DxfConvTexts.ConvertText(strAux2);
1917
                        tagString = strAux2;                        
1918
                        att[0] = DxfConvTexts.ConvertText(tagString);
1919
                        tagDefined = true;
1920
                        if (defValDefined) {
1921
                                insFea.setProp(att[0], att[1]);
1922
                                ptFea.setProp(att[0], att[1]);
1923
                        }
1924
                }
1925
                if (grp.hasCode(7)) {
1926
                        textStyleName = grp.getDataAsString(7);                        
1927
                        textStyleName = DxfConvTexts.ConvertText(textStyleName);
1928
                }
1929
                if (grp.hasCode(70)) {
1930
                        attributeFlags = grp.getDataAsInt(70);
1931
                }
1932
                
1933
                if (grp.hasCode(40)) {
1934
                        Double heightD = new Double(grp.getDataAsDouble(40));
1935
                        String heightS = heightD.toString();
1936
                        feature.setProp("textHeight", heightS);
1937
                } else {
1938
                        feature.setProp("textHeight", "20.0");
1939
                }
1940
                if (grp.hasCode(50)) {
1941
                        Double rotD = new Double(grp.getDataAsDouble(50));
1942
                        String rotS = rotD.toString();
1943
                        feature.setProp("textRotation", rotS);
1944
                } else {
1945
                        feature.setProp("textRotation", "0.0");
1946
                }
1947
                x = grp.getDataAsDouble(10);
1948
                y = grp.getDataAsDouble(20);
1949
                z = grp.getDataAsDouble(30);
1950
                /*if (grp.hasCode(30)){
1951
                        z = grp.getDataAsDouble(30);
1952
                        Double doub = new Double(z);
1953
                        String string = doub.toString();
1954
                        feature.setProp("elevation", string);
1955
                } else {
1956
                        Double doub = new Double(0.0);
1957
                        feature.setProp("elevation", doub.toString());
1958
                }*/
1959
                if (grp.hasCode(210))
1960
                        xtruX = grp.getDataAsDouble(210);
1961
                if (grp.hasCode(220))
1962
                        xtruY = grp.getDataAsDouble(220);
1963
                if (grp.hasCode(230))
1964
                        xtruZ = grp.getDataAsDouble(230);
1965
                Point3D point_in = new Point3D(x, y, z);
1966
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
1967
                Point3D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
1968
                x = point_out.getX();
1969
                y = point_out.getY();
1970
                z = point_out.getZ();
1971
                Double doub = new Double(z);
1972
                feature.setProp("elevation", doub.toString());
1973
                if (z!=0.0) dxf3DFile = true;
1974
                point.add(new Point3D(x, y, z));
1975
                feature.setGeometry(point);
1976
                
1977
                // 041130: Rellena las props con los atributos.
1978
                completeAttributes(feature);
1979
                
1980
                if (attributeFlags==8) {
1981
                        if (addingToBlock == false) {
1982
                                features.add(feature);
1983
                        } else {
1984
                                blk.add(feature);
1985
                        }
1986
                }
1987
        }
1988
        
1989
        public void createBlock(DxfGroupVector grp) throws Exception {
1990
                //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1991
                blk = new FeatureCollection(proj);
1992
                
1993
                Point3D basePoint = new Point3D();
1994
                String blockName = "";
1995
                //System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
1996
                
1997
                addingToBlock = true;
1998
                //System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
1999
                blkList.add(iterator, blk);
2000
                
2001
                //System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
2002
                
2003
                if (grp.hasCode(8))
2004
                        blk.setProp("layer", grp.getDataAsString(8));
2005
                if (grp.hasCode(62)) {
2006
                        Integer integer = new Integer(grp.getDataAsInt(62));
2007
                        String string = integer.toString();
2008
                        blk.setProp("color", string);
2009
                        blk.setProp("colorByLayer", "false");
2010
                } else {
2011
                        DxfLayer layer = (DxfLayer)layers.getByName(grp.getDataAsString(8));
2012
                        int clr = layer.colorNumber;
2013
                        Integer integer = new Integer(clr);
2014
                        String string = integer.toString();
2015
                        blk.setProp("color", string);
2016
                        blk.setProp("colorByLayer", "true");
2017
                }
2018
                
2019
                if (grp.hasCode(1)) {
2020
                        blockName = grp.getDataAsString(1);
2021
                        //blk.setBlkName(blockName);
2022
                        blk.setProp("blockName", blockName);
2023
                }
2024
                if (grp.hasCode(2)) {
2025
                        blockName = grp.getDataAsString(2);
2026
                        //blk.setBlkName(blockName);
2027
                        blk.setProp("blockName", blockName);
2028
                }
2029
                if (grp.hasCode(10)) {
2030
                        Double basePointX = new Double(grp.getDataAsDouble(10));
2031
                        basePoint.X = grp.getDataAsDouble(10);
2032
                        blk.setProp("basePointX", basePointX.toString());
2033
                }
2034
                if (grp.hasCode(20)) {
2035
                        Double basePointY = new Double(grp.getDataAsDouble(20));
2036
                        basePoint.Y = grp.getDataAsDouble(20);
2037
                        blk.setProp("basePointY", basePointY.toString());
2038
                }
2039
                if (grp.hasCode(30)) {
2040
                        Double basePointZ = new Double(grp.getDataAsDouble(30));
2041
                        basePoint.Z = grp.getDataAsDouble(30);
2042
                        if (basePoint.getZ()!=0.0) dxf3DFile = true;
2043
                        blk.setProp("basePointZ", basePointZ.toString());
2044
                }
2045
                if (grp.hasCode(70)) {
2046
                        //blk.flags = grp.getDataAsInt(70);
2047
                        Integer blockFlags = new Integer(grp.getDataAsInt(70));
2048
                        blk.setProp("blockFlags", blockFlags.toString());
2049
                        // 041103: Hoy por hoy esto no lo utilizamos.
2050
                }
2051
        }
2052
        
2053
        public void endBlk(DxfGroupVector grp) throws Exception {
2054
                //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
2055
                setAddingToBlock(false);
2056
                iterator = iterator + 1;
2057
        }
2058
        
2059
        public void testBlocks() {
2060
                //System.out.println("getBlkList() = " + getBlkList());
2061
                Vector blkList = getBlkList();
2062
                FeatureCollection block = null;
2063
                Feature feature = null;
2064
                InsPoint3D insert = null;
2065
                for (int i=0; i<blkList.size(); i++) {
2066
                        //System.out.println("compruebaBloques(): Bloque " + i +" de " + blkList.size());
2067
                        block = (FeatureCollection) blkList.get(i);
2068
                        int aux = block.size();
2069
                        for (int j=0; j<aux; j++) {
2070
                                feature = (Feature)block.get(j);
2071
                                //if (feature.getGeometry() instanceof InsPoint && feature.getProp("isAnInsert") == "true") {
2072
                                if (feature.getGeometry() instanceof InsPoint3D) {
2073
                                        insert = (InsPoint3D)feature.getGeometry();
2074
                                        String nomBlock = insert.getBlockName();
2075
                                        if (insert.getBlockFound() == false) {
2076
                                                //System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock);
2077
                                                insert.encuentraBloque(nomBlock);
2078
                                                //gestionaInsert(feature);
2079
                                                //block.add(feature);
2080
                                        }
2081
                                }
2082
                        }
2083
                }
2084
        }
2085
    
2086
        private void gestionaInsert(Feature feature) {
2087
                Feature feature2 = null;
2088
                org.cresques.px.gml.Point3D point = null;
2089
                LineString3D lineString3D = null;
2090
                Polygon3D polygon3D = null;
2091
                InsPoint3D insert = new InsPoint3D();
2092
                insert = (InsPoint3D)feature.getGeometry();
2093
                double bPointX = 0.0;
2094
                double bPointY = 0.0;
2095
                double bPointZ = 0.0;
2096
                //if (insert.getBlockFound() == true) {
2097
                        bPointX = Double.parseDouble(insert.getBlock().getProp("basePointX"));
2098
                        bPointY = Double.parseDouble(insert.getBlock().getProp("basePointY"));
2099
                        bPointZ = Double.parseDouble(insert.getBlock().getProp("basePointZ"));
2100
                //}
2101
                double sFactorX = insert.getScaleFactor().getX();
2102
                double sFactorY = insert.getScaleFactor().getY();
2103
                double sFactorZ = insert.getScaleFactor().getZ();
2104
                double rAngleGra = insert.getRotAngle();
2105
                double rAngleRad = rAngleGra*Math.PI/180.0;
2106
                InsPoint3D insert2 = null;
2107
                
2108
                for (int i=0; i<insert.getBlock().size(); i++) {
2109
                        //System.out.println("gestionaInserts: insert.getBlock().features.size() = " + insert.getBlock().size());
2110
                        feature2 = (Feature)insert.getBlock().get(i);
2111
                        
2112
                        // Para que los elementos dentro del bloque tengan la misma layer
2113
                        // y color que el insert al que corresponden.
2114
                        // Segun la especificacion del formato DXF de Autodesk, la layer
2115
                        // de las entities dentro de un bloque es la del bloque. La
2116
                        // layer especifica para estos elementos en la defincion del
2117
                        // bloque se ignora.
2118
                        //System.out.println("gestionaInsert(): layer = " + feature2.getProp("layer"));
2119
                        if ((feature2.getProp("colorByLayer").equals("false") || feature2.getProp("layer").equals("0")) && !feature.getProp("layer").equals("0")) {
2120
                                feature2.setProp("color", feature.getProp("color"));
2121
                        }
2122
                        feature2.setProp("layer", feature.getProp("layer"));
2123
                        
2124
                        Point3D point1 = new Point3D();
2125
                        Point3D point11 = new Point3D();
2126
                        Point3D pointAux = null;
2127
                        
2128
                        if (feature2.getGeometry() instanceof InsPoint3D){
2129
                                
2130
                                //System.out.println("gestionaInsert(): Encuentra bloques dentro de bloques");
2131
                                
2132
                                insert2 = (InsPoint3D)feature2.getGeometry();
2133
                                point1 = insert2.getPoint3D(0);
2134
                                
2135
                                pointAux = new Point3D(point1.getX() - bPointX, point1.getY() - bPointY, point1.getZ() - bPointZ);
2136
                                double laX = insert.getPoint3D(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
2137
                                double laY = insert.getPoint3D(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
2138
                                double laZ = insert.getPoint3D(0).getZ() + (pointAux.getZ()*sFactorZ);
2139
                                point11 = new Point3D(laX, laY, laZ);
2140
                                InsPoint3D insert3 = new InsPoint3D();
2141
                                
2142
                                insert3.add(point11);
2143
                                
2144
                                insert3.setBlkList(insert2.getBlkList());
2145
                                insert3.setBlock(insert2.getBlock());
2146
                                insert3.setBlockName(insert2.getBlockName());
2147
                                insert3.setRotAngle(insert2.getRotAngle());
2148
                                Point3D newScale = new Point3D(insert2.getScaleFactor().getX() * sFactorX, insert2.getScaleFactor().getY() * sFactorY, insert2.getScaleFactor().getZ() * sFactorZ);
2149
                                insert3.setScaleFactor(newScale);
2150
                                
2151
                                Feature feature3 = new Feature();
2152
                                feature3.setProp("layer", feature2.getProp("layer"));
2153
                                feature3.setProp("color", feature2.getProp("color"));
2154
                                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
2155
                                feature3.setProp("elevation", feature2.getProp("elevation"));
2156
                                
2157
                                //041130
2158
                                for (int j=0;j<attributes.size();j++) {
2159
                                        String[] att = new String[2];
2160
                                        att = (String[])attributes.get(j);
2161
                                        feature3.setProp(att[0],feature2.getProp(att[0]));
2162
                                }
2163
                                
2164
                                feature3.setGeometry(insert3);
2165
                                
2166
                                gestionaInsert(feature3);
2167
                        } else if (feature2.getGeometry() instanceof LineString3D) {
2168
                                lineString3D = (LineString3D)feature2.getGeometry();
2169
                                LineString3D lineString2 = new LineString3D();
2170
                                Point3D[] points = new Point3D[lineString3D.pointNr()];
2171
                                Point3D[] pointss = new Point3D[lineString3D.pointNr()];
2172
                                for (int j=0; j<lineString3D.pointNr(); j++) {
2173
                                        points[j] = (Point3D)lineString3D.get(j);
2174
                                        pointss[j] = new Point3D();
2175
                                        
2176
                                        pointAux = new Point3D(points[j].getX() - bPointX, points[j].getY() - bPointY, points[j].getZ() - bPointZ);
2177
                                        double laX = insert.getPoint3D(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
2178
                                        double laY = insert.getPoint3D(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
2179
                                        double laZ = insert.getPoint3D(0).getZ() + (pointAux.getZ()*sFactorZ);
2180
                                        pointss[j] = new Point3D(laX, laY, laZ);
2181
                                        lineString2.add(pointss[j]);
2182
                                }
2183
                                
2184
                                Feature feature3 = new Feature();
2185
                                feature3.setProp("layer", feature2.getProp("layer"));
2186
                                feature3.setProp("color", feature2.getProp("color"));
2187
                                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
2188
                                if (feature2.getProp("elevation")!=null) feature3.setProp("elevation", feature2.getProp("elevation"));
2189
                                feature3.setProp("thickness", feature2.getProp("thickness"));
2190
                                
2191
                                //041130
2192
                                for (int j=0;j<attributes.size();j++) {
2193
                                        String[] att = new String[2];
2194
                                        att = (String[])attributes.get(j);
2195
                                        String str = att[0];
2196
                                        feature3.setProp(str,feature2.getProp(str));
2197
                                }
2198
                                
2199
                                feature3.setGeometry(lineString2);
2200
                                
2201
                                if (addingToBlock == false) {
2202
                                        features.add(feature3);
2203
                                }
2204
                        } else if (feature2.getGeometry() instanceof Polygon3D) {
2205
                                polygon3D = (Polygon3D)feature2.getGeometry();
2206
                                Polygon3D polygon2 = new Polygon3D();
2207
                                Point3D[] points = new Point3D[polygon3D.pointNr()];
2208
                                Point3D[] pointss = new Point3D[polygon3D.pointNr()];
2209
                                for (int j=0; j<polygon3D.pointNr(); j++) {
2210
                                        points[j] = (Point3D)polygon3D.get(j);
2211
                                        pointss[j] = new Point3D();
2212
                                        
2213
                                        pointAux = new Point3D(points[j].getX() - bPointX, points[j].getY() - bPointY, points[j].getZ() - bPointZ);
2214
                                        double laX = insert.getPoint3D(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
2215
                                        double laY = insert.getPoint3D(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
2216
                                        double laZ = insert.getPoint3D(0).getZ() + (pointAux.getZ()*sFactorZ);
2217
                                        pointss[j] = new Point3D(laX, laY, laZ);
2218
                                        polygon2.add(pointss[j]);
2219
                                }
2220
                                
2221
                                Feature feature3 = new Feature();
2222
                                feature3.setProp("layer", feature2.getProp("layer"));
2223
                                feature3.setProp("color", feature2.getProp("color"));
2224
                                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
2225
                                if (feature2.getProp("elevation")!=null) feature3.setProp("elevation", feature2.getProp("elevation"));
2226
                                feature3.setProp("thickness", feature2.getProp("thickness"));
2227
                                
2228
                                //041130
2229
                                for (int j=0;j<attributes.size();j++) {
2230
                                        String[] att = new String[2];
2231
                                        att = (String[])attributes.get(j);
2232
                                        feature3.setProp(att[0],feature2.getProp(att[0]));
2233
                                }
2234
                                
2235
                                feature3.setGeometry(polygon2);
2236
                                
2237
                                if (addingToBlock == false) {
2238
                                        features.add(feature3);
2239
                                }
2240
                        } else if (feature2.getGeometry() instanceof org.cresques.px.gml.Point3D) {
2241
                                point = (org.cresques.px.gml.Point3D)feature2.getGeometry();
2242
                                point1 = point.getPoint3D(0);
2243
                                
2244
                                pointAux = new Point3D(point1.getX() - bPointX, point1.getY() - bPointY, point1.getZ() - bPointZ);
2245
                                double laX = insert.getPoint3D(0).getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
2246
                                double laY = insert.getPoint3D(0).getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
2247
                                double laZ = insert.getPoint3D(0).getZ() + (pointAux.getZ()*sFactorZ);
2248
                                point11 = new Point3D(laX, laY, laZ);
2249
                                org.cresques.px.gml.Point3D pointt = new org.cresques.px.gml.Point3D();
2250
                                pointt.add(point11);
2251
                                
2252
                                Feature feature3 = new Feature();
2253
                                feature3.setProp("layer", feature2.getProp("layer"));
2254
                                feature3.setProp("color", feature2.getProp("color"));
2255
                                feature3.setProp("dxfEntity", feature2.getProp("dxfEntity"));
2256
                                feature3.setProp("elevation", feature2.getProp("elevation"));
2257
                                feature3.setProp("thickness", feature2.getProp("thickness"));
2258
                                if (point.isTextPoint()) {
2259
                                        feature3.setProp("text", feature2.getProp("text"));
2260
                                        feature3.setProp("textHeight", feature2.getProp("textHeight"));
2261
                        double auxR = Double.parseDouble(feature2.getProp("textRotation"));
2262
                                        //System.out.println("auxR = " + auxR);
2263
                        auxR = auxR + rAngleGra;
2264
                        feature3.setProp("textRotation", Double.toString(auxR));
2265
                                        //System.out.println("gestionaInsert(): feature3.getProp(textRotation) = " + feature3.getProp("textRotation"));
2266
                                        pointt.setTextPoint(true);
2267
                                }
2268
                                
2269
                                //041130
2270
                                for (int j=0;j<attributes.size();j++) {
2271
                                        String[] att = new String[2];
2272
                                        att = (String[])attributes.get(j);
2273
                                        feature3.setProp(att[0],feature2.getProp(att[0]));
2274
                                }
2275
                                
2276
                                feature3.setGeometry(pointt);
2277
                                
2278
                                //if (addingToBlock == false) {
2279
                                        features.add(feature3);
2280
                                //}
2281
                        } else {
2282
                                System.out.println("gestionaInsert(): Encontrado elemento desconocido");
2283
                        }
2284
                }
2285
        }
2286
        
2287
        private void addFace(int [] face) {
2288
                hasFaces = true;
2289
                if (faces == null)
2290
                        faces = new Vector();
2291
                faces.add(face);
2292
        }
2293
        
2294
        /**
2295
         * Quita los atributos repetidos.
2296
         */
2297
        public void depureAttributes() {
2298
                //String[] att = null;
2299
                /*Set conjunto = new HashSet();
2300
                for (int i=0;i<attributes.size();i++) {
2301
                        att = (String[])attributes.get(i);
2302
                        String str = att[0];
2303
                        conjunto.add(str);
2304
                }
2305
                //conjunto.addAll(attributes);
2306
                Vector atts = new Vector();
2307
                Vector atts2 = new Vector();
2308
                atts.addAll(conjunto);
2309
                for (int i=0;i<atts.size();i++) {
2310
                        if (((String[])(attributes.get(i)))[0] == atts.get(i)) {
2311
                                atts2.add(i, attributes.get(i));
2312
                        }
2313
                }*/
2314
                
2315
                String[] lastAtt = new String[2];
2316
                for (int i=0;i<attributes.size();i++) {
2317
                        String[] att = (String[])attributes.get(i);
2318
                        for (int j=i+1;j<attributes.size();j++) {
2319
                                //System.out.println("depureAttributes(): j = " + j);
2320
                                String[] st = (String[])attributes.get(j);
2321
                                String st1 = att[0];
2322
                                String st2 = st[0];
2323
                                //System.out.println("depureAttributes(): st1 = " + st1);
2324
                                //System.out.println("depureAttributes(): st2 = " + st2);
2325
                                if (st2.equals(st1)) {
2326
                                        //System.out.println("depureAttributes(): Borra el st2");
2327
                                        attributes.remove(j);
2328
                                }
2329
                                if (i==attributes.size()-1) {
2330
                                        lastAtt = att;
2331
                                }
2332
                        }
2333
                }
2334
                for (int i=attributes.size()-2;i>=0;i--) {
2335
                        String[] att = (String[])attributes.get(i);
2336
                        String st1 = lastAtt[0];
2337
                        String st2 = att[0];
2338
                        if (st2.equals(st1)) {
2339
                                attributes.remove(i);
2340
                        }
2341
                }
2342
                
2343
                /*String[] attStrs = new String[attributes.size()];
2344
                Vector attribs = new Vector();
2345
                for (int i=0;i<attributes.size();i++) {
2346
                        att = (String[])attributes.get(i);
2347
                        attStrs[i] = att[0];
2348
                }
2349
                Set attStrsNR = new HashSet();
2350
                for (int i=0;i<attStrs.length;i++) {
2351
                        attStrsNR.add(attStrs[i]);
2352
                }
2353
                String[] attStrsNRA = new String[attStrsNR.size()];
2354
                attStrsNR.toArray(attStrsNRA);
2355
                for (int i=0;i<attStrsNR.size();i++) {
2356
                        att[0] = attStrsNRA[i];
2357
                        attribs.add(att);
2358
                }
2359
                for (int i=0;i<attributes.size();i++) {
2360
                        att = (String[])attributes.get(i);
2361
                        String[] att2 = new String[2];
2362
                        for (int j=0;j<attribs.size();j++) {
2363
                                att2 = (String[])attribs.get(j);
2364
                                if (att[0].equals(att2[0])) {
2365
                                        att2[1] = att[1];
2366
                                }
2367
                                attribs.set(j, att2);
2368
                        }
2369
                }
2370
                attributes = attribs;*/
2371
        }
2372
        
2373
        /**
2374
         * Hace los setProp para los atributos extra.
2375
         * @param feature
2376
         */
2377
        private void completeAttributes(Feature feature) {
2378
                // 041130: Rellena las props con los atributos.
2379
                for (int i=0;i<attributes.size();i++) {
2380
                        String[] att = new String[2];
2381
                        att = (String[])attributes.get(i);
2382
                        feature.setProp(att[0],att[1]);
2383
                }
2384
        }
2385
        
2386
        /**
2387
         * Copia los atributos extra cargados en InsPoint y ya perfectamente definidos a los
2388
         * elementos del bloque al que referencia el punto de insercion.
2389
         * @param insert
2390
         */
2391
        private void copyAttributes(Feature feaInsert) {
2392
                Feature feature = null;
2393
                InsPoint3D insert = new InsPoint3D();
2394
                insert = (InsPoint3D)feaInsert.getGeometry();
2395
                for (int i=0; i<insert.getBlock().size(); i++) {
2396
                        feature = (Feature)insert.getBlock().get(i);
2397
                        for (int j=0;j<attributes.size();j++) {
2398
                                String[] att = new String[2];
2399
                                att = (String[])attributes.get(j);
2400
                                feature.setProp(att[0],feaInsert.getProp(att[0]));
2401
                        }
2402
                }
2403
        }
2404
        
2405
        /**
2406
         * Se ejecuta cuando se declaran nuevos atributos, es decir, tras cada ATTDEF.
2407
         * A?ade estos atributos a las features existentes.
2408
         */
2409
        private void setNewAttributes() {
2410
                for (int i=0;i<features.size();i++) {
2411
                        Feature fea = new Feature();
2412
                        fea = (Feature)features.get(i);
2413
                        completeAttributes(fea);
2414
                }
2415
                for (int i=0;i<blkList.size();i++) {
2416
                        FeatureCollection bloque = new FeatureCollection(proj);
2417
                        bloque = (FeatureCollection)blkList.get(i);
2418
                        for (int j=0;j<bloque.size();j++) {
2419
                                Feature fea = new Feature();
2420
                                fea = (Feature)bloque.get(j);
2421
                                completeAttributes(fea);
2422
                        }
2423
                }
2424
        }
2425
        
2426
        public Vector getAttributes() {
2427
                return attributes;
2428
        }
2429

    
2430
        /* (non-Javadoc)
2431
         * @see org.cresques.io.DxfFile.EntityFactory#getExtent()
2432
         */
2433
        public Extent getExtent() {
2434
                Feature feature = new Feature();
2435
                Extent extent = new Extent();
2436
                Iterator iter = features.iterator();
2437
                while (iter.hasNext()) {
2438
                        feature = (Feature)iter.next();
2439
                        extent.add(feature.getExtent());
2440
                }
2441
                return extent;
2442
        }
2443
        
2444
        public void setProjection(IProjection p) {
2445
                proj = p;
2446
        }
2447

    
2448
        /* (non-Javadoc)
2449
         * @see org.cresques.io.DxfFile.EntityFactory#reProject(org.cresques.geo.ReProjection)
2450
         */
2451
        public void reProject(ICoordTrans rp) {
2452
                Feature feature = new Feature();
2453
                Extent extent = new Extent();
2454
                Iterator iter = features.iterator();
2455
                while (iter.hasNext()) {
2456
                        feature = (Feature)iter.next();
2457
                        ((Projected) feature).reProject(rp);
2458
                        extent.add(feature.getExtent());
2459
                }
2460
                setProjection(rp.getPDest());
2461
        }
2462

    
2463
        /* (non-Javadoc)
2464
         * @see org.cresques.geo.Projected#getProjection()
2465
         */
2466
        public IProjection getProjection() {
2467
                return proj;
2468
        }
2469
        
2470
        public IObjList getObjects() { return features;}
2471
        
2472
        public void draw(Graphics2D g, ViewPortData vp) {
2473
                Iterator iter = features.iterator();
2474
                Extent extent;
2475
                while (iter.hasNext()) {
2476
                        Feature feature = new Feature();
2477
                        feature = (Feature)iter.next();
2478
                        extent = feature.getExtent();
2479
                        if (vp.getExtent().minX()> extent.maxX()) continue;
2480
                        if (vp.getExtent().minY()> extent.maxY()) continue;
2481
                        if (vp.getExtent().maxX()< extent.minX()) continue;
2482
                        if (vp.getExtent().maxY()< extent.minY()) continue;
2483
                        //if (!feature.layer.frozen)
2484
                                feature.draw(g, vp);
2485
                }
2486
        }
2487
        
2488
        public static Vector createArc(Point2D coord1, Point2D coord2, double bulge) {
2489
                return new DxfCalArcs(coord1, coord2, bulge).getPoints(1);
2490
        }
2491

    
2492
        /* (non-Javadoc)
2493
         * @see org.cresques.io.DxfFile.EntityFactory#getBlkList()
2494
         */
2495
        public Vector getBlkList() {
2496
                return blkList;
2497
        }
2498

    
2499
        /* (non-Javadoc)
2500
         * @see org.cresques.io.DxfFile.EntityFactory#getDxfEntityList()
2501
         */
2502
        public DxfEntityList getDxfEntityList() {
2503
                // TODO Auto-generated method stub
2504
                return null;
2505
        }
2506

    
2507
        /* (non-Javadoc)
2508
         * @see org.cresques.io.DxfFile.EntityFactory#getBlk()
2509
         */
2510
        public DxfBlock getBlk() {
2511
                // TODO Auto-generated method stub
2512
                return null;
2513
        }
2514

    
2515
        /* (non-Javadoc)
2516
         * @see org.cresques.io.DxfFile.EntityFactory#createEllipse(org.cresques.io.DxfGroupVector)
2517
         */
2518
        public void createEllipse(DxfGroupVector v) throws Exception {
2519
                // TODO Auto-generated method stub
2520
                
2521
        }
2522
        
2523
    /**
2524
     * @return Returns the dxf3DFile.
2525
     */
2526
    public boolean isDxf3DFile() {
2527
        return dxf3DFile;
2528
    }
2529
    /**
2530
     * @param dxf3DFile The dxf3DFile to set.
2531
     */
2532
    public void setDxf3DFile(boolean dxf3DFile) {
2533
        this.dxf3DFile = dxf3DFile;
2534
    }
2535
}