Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / dxf / DxfEntityMaker.java @ 2323

History | View | Annotate | Download (57.6 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.geom.Point2D;
27
import java.util.Vector;
28

    
29
import org.cresques.cts.ICoordTrans;
30
import org.cresques.cts.IProjection;
31
import org.cresques.geo.Point3D;
32
import org.cresques.geo.Projected;
33
import org.cresques.io.DxfFile;
34
import org.cresques.io.DxfGroup;
35
import org.cresques.io.DxfGroupVector;
36
import org.cresques.px.Extent;
37
import org.cresques.px.IObjList;
38
import org.cresques.px.PxObj;
39
import org.cresques.px.gml.InsPoint;
40
import org.cresques.px.gml.LineString;
41

    
42
/**
43
 * jmorell: Implementaci?n de la creaci?n de entidades DXF2000.
44
 */
45
/**
46
 * @author nacho
47
 *
48
 * TODO To change the template for this generated type comment go to
49
 * Window - Preferences - Java - Code Style - Code Templates
50
 */
51
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected {
52
        IProjection proj = null;
53
        DxfEntity lastEntity = null;
54
        DxfEntityList entities = null;
55
        Vector blkList = null;
56
        DxfBlock blk = null;
57
        DxfTable layers = null;
58
        double bulge = 0.0;
59
    double xtruX=0.0, xtruY=0.0, xtruZ=1.0;
60
    int polylineFlag = 0;
61
    Point2D firstPt = new Point2D.Double();
62
    
63
    boolean addingToBlock = false;
64
    int iterator = 0;
65
    
66
    // jmorell, 050406: implementaci?n inicial de los ATTRIBS para el piloto ...
67
        private Vector attributes = null;
68
    
69
        public DxfEntityMaker (IProjection proj) {
70
                this.proj = proj;
71
                layers = new DxfTable();
72
                entities = new DxfEntityList(proj);
73
                blkList = new Vector();
74
            // jmorell, 050406: implementaci?n inicial de los ATTRIBS para el piloto ...
75
                attributes = new Vector();
76
        }
77
        
78
        public Vector getBlkList() { return blkList; }
79
        
80
        public IObjList getObjects() { return entities; }
81
        public Extent getExtent() { return entities.getExtent(); }
82

    
83
        public void setAddingToBlock(boolean a) { addingToBlock = a; }
84
        
85
        public void createLayer(DxfGroupVector grp) throws Exception {
86
                int color = grp.getDataAsInt(62);
87
                DxfLayer layer = new DxfLayer(grp.getDataAsString(2), Math.abs(grp.getDataAsInt(62)));
88
                if (color < 0) {
89
                        layer.isOff = true;
90
                }
91
                layer.lType = grp.getDataAsString(6);
92
                layer.setFlags(grp.getDataAsInt(70));
93
                // compruebo flags
94
                if ((layer.flags & 0x01) == 0x01) {
95
                        layer.frozen = true;
96
                }
97
                if ((layer.flags & 0x02) == 0x02) {
98
                        layer.frozen = true;
99
                }
100
                System.out.println("LAYER color="+layer.getColor());
101

    
102
                layers.add(layer);
103
        }
104
        
105
        public void createPolyline(DxfGroupVector grp) throws Exception {
106
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
107
                DxfPolyline entity = new DxfPolyline(proj, layer);
108
                if (grp.hasCode(5)) {
109
                        String hexS = grp.getDataAsString(5);
110
                        Integer hexI = Integer.decode("0x" + hexS);
111
                        int hexi = hexI.intValue();
112
                        entity.setHandle(hexi);
113
                } else {
114
                        entity.setHandle(entities.size()+40);
115
                }
116

    
117
                double x = 0.0, y = 0.0, z = 0.0;
118
                double thickness = 0;
119
                
120
                if (grp.hasCode(10))
121
                        x = grp.getDataAsDouble(10);
122
                if (grp.hasCode(20))
123
                        y = grp.getDataAsDouble(20);
124
                if (grp.hasCode(30))
125
                        z = grp.getDataAsDouble(30);
126
                /*if (grp.hasCode(39))
127
                        System.out.println("Leer el thickness provoca un error");
128
                        thickness = grp.getDataAsDouble(39);*/
129
                if (grp.hasCode(62)) {
130
                        entity.dxfColor = grp.getDataAsInt(62);
131
                } else {
132
                        //entity.dxfColor = 0;
133
                }
134
                if (grp.hasCode(66)) {
135
                        entity.entitiesFollow = grp.getDataAsInt(66);
136
                }
137
                if (grp.hasCode(70)) {
138
                        entity.flags = grp.getDataAsInt(70);                        
139
                }
140
                if (grp.hasCode(210))
141
                        xtruX = grp.getDataAsDouble(210);
142
                if (grp.hasCode(220))
143
                        xtruY = grp.getDataAsDouble(220);
144
                if (grp.hasCode(230))
145
                        xtruZ = grp.getDataAsDouble(230);
146
                        
147
                if ((entity.flags & 0x01) == 0x01) {
148
                        entity.closed = true;
149
                }
150
                lastEntity = entity;
151
        }
152
        
153
        public void endSeq() throws Exception {
154
                if (lastEntity instanceof DxfPolyline) {
155
                        DxfPolyline polyline = (DxfPolyline)lastEntity;
156
                        if (polyline.closed) {
157
                                ((DxfPolyline) lastEntity).add(firstPt);
158
                                if (!(bulge==0)) {
159
                                        int cnt = ((DxfPolyline) lastEntity).pts.size();
160
                                        Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
161
                                        ((DxfPolyline) lastEntity).pts.remove(cnt-1);
162
                                        for (int i=0; i<arc.size(); i++) {
163
                                                Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
164
                                                ((DxfPolyline) lastEntity).add(pt);
165
                                                if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
166
                                        }
167
                                        bulge = 0.0;
168
                                }
169
                        }
170
                        // 050315, jmorell: Para leer Polylines estas tb deben tener vector de bulges.
171
                        for (int i=0; i<((DxfPolyline)lastEntity).pts.size(); i++) {
172
                                // jmorell, 050405: intentando leer DxfPolylines con bulges para el
173
                                // piloto ...
174
                                //polyline.addBulge(new Double(0));
175
                                ((DxfPolyline)lastEntity).addBulge(new Double(0));
176
                        }
177
                        //System.out.println("DxfEntityMaker.endSeq(): ((DxfPolyline)lastEntity).getBulges().size() = " + ((DxfPolyline)lastEntity).getBulges().size());
178
                        //((DxfPolyline)lastEntity).addBulge(new Double(bulge));
179
                        //lastEntity.setHandle(entities.size()+40);
180
                        if (addingToBlock == false) {
181
                                //System.out.println("createPolyline: A?adimos una polilinea a la lista de entidades");
182
                                entities.add(lastEntity);
183
                        } else {
184
                                //System.out.println("createPolyline: A?adimos una polilinea al bloque " + iterator);
185
                                blk.add(lastEntity);
186
                                //System.out.println("PLINE color="+polyline.getColor());
187
                        }
188
                        lastEntity = null;
189
                } else if (lastEntity instanceof DxfInsert) {
190
                        // Se trata de un SEQEND despues de un ATTRIB
191
                        gestionaInsert((DxfInsert)lastEntity, lastEntity.getLayer());
192
                        if (addingToBlock == false) {
193
                                entities.add(lastEntity);
194
                        } else {
195
                                blk.add(lastEntity);
196
                        }
197
                        lastEntity = null;
198
                } else {
199
                        // Caso no contemplado
200
                }
201
                xtruX = 0.0;
202
                xtruY = 0.0;
203
                xtruZ = 1.0;
204
                bulge = 0.0;
205
        }
206
        
207
        public void addVertex(DxfGroupVector grp) throws Exception {
208
                double x = 0.0, y = 0.0, z = 0.0;
209
                int flags = 0;
210
                x  = grp.getDataAsDouble(10);
211
                y  = grp.getDataAsDouble(20);
212
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
213
                if (grp.hasCode(70)) {
214
                        flags = grp.getDataAsInt(70);
215
                }
216
                //bulge = 0.0;
217
                if (bulge == 0.0) {
218
                        if (grp.hasCode(42)) {
219
                                bulge = grp.getDataAsDouble(42);
220
                                //bulge = 0.0;
221
                        } else { bulge = 0.0; }
222
                        Point3D point_in = new Point3D(x, y, z);
223
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
224
                        Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
225
                        if ((flags & 0x80) == 0x80 && (flags & 0x40) == 0) {
226
                                int [] face = {0,0,0,0};
227
                                face[0] = grp.getDataAsInt(71);
228
                                face[1] = grp.getDataAsInt(72);
229
                                face[2] = grp.getDataAsInt(73);
230
                                face[3] = grp.getDataAsInt(74);
231
                                ((DxfPolyline) lastEntity).addFace(face);
232
                        } else {
233
                                x = point_out.getX();
234
                                y = point_out.getY();
235
                                Point2D pt = proj.createPoint( x, y);
236
                                ((DxfPolyline) lastEntity).add(pt);
237
                                if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
238
                        }
239
                } else if (bulge > 0.0) {
240
                        double bulge_aux = 0.0;
241
                        if (grp.hasCode(42)) {
242
                                bulge_aux = grp.getDataAsDouble(42);
243
                        } else { bulge_aux = 0.0; }
244
                        Point3D point_in = new Point3D(x, y, z);
245
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
246
                        Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
247
                        x = point_out.getX();
248
                        y = point_out.getY();
249
                        Point2D pt = proj.createPoint( x, y);
250
                        ((DxfPolyline) lastEntity).add(pt);
251
                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
252
                        int cnt = ((DxfPolyline) lastEntity).pts.size();
253
                        if (((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2))).getX()==((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1))).getX() && ((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2))).getY()==((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1))).getY()) {
254
                            // no se construye el arco
255
                        } else {
256
                                Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
257
                                ((DxfPolyline) lastEntity).pts.remove(cnt-1);
258
                                for (int i=0; i<arc.size(); i++) {
259
                                        pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
260
                                        ((DxfPolyline) lastEntity).add(pt);
261
                                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
262
                                }
263
                        }
264
                        bulge = bulge_aux;
265
                } else { //si el bulge es menor que cero.
266
                        double bulge_aux = 0.0;
267
                        if (grp.hasCode(42)) {
268
                                bulge_aux = grp.getDataAsDouble(42); // * (-1.0);
269
                        } else { bulge_aux = 0.0; }
270
                        Point3D point_in = new Point3D(x, y, z);
271
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
272
                        Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
273
                        x = point_out.getX();
274
                        y = point_out.getY();
275
                        Point2D pt = proj.createPoint( x, y);
276
                        ((DxfPolyline) lastEntity).add(pt);
277
                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
278
                        int cnt = ((DxfPolyline) lastEntity).pts.size();
279
                        if (((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2))).getX()==((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1))).getX() && ((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2))).getY()==((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1))).getY()) {
280
                            // no se construye el arco
281
                        } else {
282
                                Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
283
                                ((DxfPolyline) lastEntity).pts.remove(cnt-1);
284
                                for (int i=arc.size()-1; i>=0; i--) {
285
                                        pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
286
                                        ((DxfPolyline) lastEntity).add(pt);
287
                                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
288
                                }
289
                        }
290
                        bulge = bulge_aux;                        
291
                }
292
                /*if (grp.hasCode(5)) {
293
                        String hexS = grp.getDataAsString(5);
294
                        Integer hexI = Integer.decode("0x" + hexS);
295
                        int hexi = hexI.intValue();
296
                        lastEntity.setHandle(hexi);
297
                } else {
298
                        lastEntity.setHandle(entities.size()+40);
299
                }*/
300
        }
301
        
302
        public void createLwPolyline(DxfGroupVector grp) throws Exception {
303
                double x = 0.0, y = 0.0, elev=0.0;
304
                DxfGroup g = null;
305
                
306
                if (grp.hasCode(38))
307
                        elev = grp.getDataAsDouble(38);
308
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
309
                DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
310
                if (grp.hasCode(5)) {
311
                        String hexS = grp.getDataAsString(5);
312
                        Integer hexI = Integer.decode("0x" + hexS);
313
                        int hexi = hexI.intValue();
314
                        entity.setHandle(hexi);
315
                } else {
316
                        entity.setHandle(entities.size()+40);
317
                }
318
                double bulge = 0;
319
                boolean isNewCoord = false;
320
                for (int i=0; i<grp.size(); i++) {
321
                        bulge = 0;
322
                        isNewCoord = false;
323
                        g = (DxfGroup) grp.get(i);
324
                        if (g.getCode() == 10) {
325
                                x = ((Double) g.getData()).doubleValue();
326
                        } else if (g.getCode() == 20) {
327
                                y = ((Double) g.getData()).doubleValue();
328
                                //if (y <= 1.0) throw new Exception("Y == "+y);
329
                                entity.add( proj.createPoint( x, y ) );
330
                                entity.addBulge(new Double(0));
331
                                x = 0.0; y = 0.0;
332
                                isNewCoord = true;
333
                        } else if (g.getCode() == 42) {
334
                                //entity.addBulge((Double)g.getData());
335
                                entity.getBulges().remove(entity.getBulges().size()-1);
336
                                entity.getBulges().add((Double)g.getData());
337
                                bulge = ((Double) g.getData()).doubleValue();
338
                        }
339
                        /*if (bulge == 0 && isNewCoord) {
340
                                entity.addBulge(new Double(0));
341
                        }*/
342
                }
343
                //System.out.println("entity.getPts().size() = " + entity.getPts().size());
344
                //System.out.println("entity.getBulges().size() = " + entity.getBulges().size());
345
                if (grp.hasCode(62)) {
346
                        entity.dxfColor = grp.getDataAsInt(62);
347
                } else {
348
                        //entity.dxfColor = 0;
349
                }
350
                if (grp.hasCode(70)) {
351
                        entity.flags = grp.getDataAsInt(70);
352
                        //System.out.println("entity.flags = " + entity.flags);
353
                }
354
                if ((entity.flags & 0x01) == 0x01) {
355
                        entity.closed = true;
356
                }
357
                if (addingToBlock == false) {
358
                        entities.add(entity);
359
                } else {
360
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
361
                        blk.add(entity);
362
                }
363
        }
364
        public void createLine(DxfGroupVector grp) throws Exception {
365
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0;
366
                DxfGroup g = null;
367
                Point2D pt1 = null, pt2 = null;
368
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
369

    
370
                x = grp.getDataAsDouble(10);
371
                y = grp.getDataAsDouble(20);
372
                if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30);
373
                pt1 = proj.createPoint(x, y);
374
                x = grp.getDataAsDouble(11);
375
                y = grp.getDataAsDouble(21);
376
                if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31);
377
                pt2 = proj.createPoint(x, y);
378
                if (grp.hasCode(210))
379
                        xtruX = grp.getDataAsDouble(210);
380
                if (grp.hasCode(220))
381
                        xtruY = grp.getDataAsInt(220);
382
                if (grp.hasCode(230))
383
                        xtruZ = grp.getDataAsInt(230);
384
                Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
385
                Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
386
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
387
                Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
388
                Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
389
                pt1.setLocation(point_out1);
390
                pt2.setLocation(point_out2);
391
                DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
392
                if (grp.hasCode(5)) {
393
                        String hexS = grp.getDataAsString(5);
394
                        Integer hexI = Integer.decode("0x" + hexS);
395
                        int hexi = hexI.intValue();
396
                        entity.setHandle(hexi);
397
                } else {
398
                        entity.setHandle(entities.size()+40);
399
                }
400
                if (grp.hasCode(62)) {
401
                        entity.dxfColor = grp.getDataAsInt(62);
402
                } else {
403
                        //entity.dxfColor = 0;
404
                }
405
                if (addingToBlock == false) {
406
                        //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
407
                        entities.add(entity);
408
                } else {
409
                        //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
410
                        blk.add(entity);
411
                }
412
        }
413
        public void createText(DxfGroupVector grp) throws Exception {
414
                double x = 0.0, y = 0.0, h= 0.0, rot= 0.0;
415
                DxfGroup g = null;
416
                //OJO! El segundo punto es opcional ...
417
                Point2D pt1 = null, pt2 = null;
418
                String txt = null;
419
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
420

    
421
                txt = grp.getDataAsString(1);
422
                DxfText entity = new DxfText(proj, layer, txt);
423

    
424
                x = grp.getDataAsDouble(10);
425
                y = grp.getDataAsDouble(20);
426
                entity.setPt(proj.createPoint(x, y));
427
                //entity.setPt1(proj.createPoint(x, y));
428
                if (grp.hasCode(11)) {
429
                        entity.setTwoPointsFlag(true);
430
                        entity.setPt1(proj.createPoint(entity.getPt().getX(), entity.getPt().getY()));
431
                        x = grp.getDataAsDouble(11);
432
                        y = grp.getDataAsDouble(21);
433
                        entity.setPt2(proj.createPoint(x, y));
434
                }
435
                entity.setHeight(grp.getDataAsDouble(40));
436
                if (grp.hasCode(50)) {
437
                        entity.setRotation(grp.getDataAsDouble(50));                        
438
                        //System.out.println("AAAAAA: entity.getRotation = " + entity.getRotation());
439
                }
440
                if (grp.hasCode(62)) {
441
                        entity.dxfColor = grp.getDataAsInt(62);
442
                } else {
443
                        //entity.dxfColor = 0;
444
                }
445
                if (grp.hasCode(72))
446
                        entity.align = grp.getDataAsInt(72);
447
                if (addingToBlock == false) {
448
                        entities.add(entity);
449
                } else {
450
                        //System.out.println("createText(): A?adimos un text al bloque " + iterator);
451
                        blk.add(entity);
452
                }
453
        }
454
        /* (non-Javadoc)
455
         * @see org.cresques.io.DxfFile.EntityFactory#createMText(org.cresques.io.DxfGroupVector)
456
         */
457
        public void createMText(DxfGroupVector v) throws Exception {
458
                // TODO Auto-generated method stub
459
                
460
        }
461
        public void createPoint(DxfGroupVector grp) throws Exception {
462
                double x = 0.0, y = 0.0, z = 0.0; //, h= 0.0, rot= 0.0;
463
                DxfGroup g = null;
464
                Point2D pt = null;
465
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
466

    
467
                DxfPoint entity = new DxfPoint(proj, layer);
468
                
469
                if (grp.hasCode(5)) {
470
                        String hexS = grp.getDataAsString(5);
471
                        Integer hexI = Integer.decode("0x" + hexS);
472
                        int hexi = hexI.intValue();
473
                        entity.setHandle(hexi);
474
                } else {
475
                        entity.setHandle(entities.size()+40);
476
                }
477

    
478
                x = grp.getDataAsDouble(10);
479
                y = grp.getDataAsDouble(20);
480
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
481
                if (grp.hasCode(62)) {
482
                        entity.dxfColor = grp.getDataAsInt(62);
483
                } else {
484
                        //entity.dxfColor = 0;
485
                }
486
                if (grp.hasCode(210))
487
                        xtruX = grp.getDataAsDouble(210);
488
                if (grp.hasCode(220))
489
                        xtruY = grp.getDataAsInt(220);
490
                if (grp.hasCode(230))
491
                        xtruZ = grp.getDataAsInt(230);
492
                Point3D point_in = new Point3D(x, y, z);
493
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
494
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
495
                x = point_out.getX();
496
                y = point_out.getY();
497
                entity.setPt(proj.createPoint(x, y));
498
                if (addingToBlock == false) {
499
                        entities.add(entity);
500
                } else {
501
                        //System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
502
                        blk.add(entity);
503
                }
504
        }
505
        public void createCircle(DxfGroupVector grp) throws Exception {
506
                //System.out.println("Encontramos un Circle.");
507
                double x = 0.0, y = 0.0, z = 0.0;
508
                double r = 0.0;
509
                DxfGroup g = null;
510
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
511

    
512
                x = grp.getDataAsDouble(10);
513
                y = grp.getDataAsDouble(20);
514
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
515
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
516
                if (grp.hasCode(210))
517
                        xtruX = grp.getDataAsDouble(210);
518
                if (grp.hasCode(220))
519
                        xtruY = grp.getDataAsDouble(220);
520
                if (grp.hasCode(230))
521
                        xtruZ = grp.getDataAsDouble(230);
522
                Point3D point_in = new Point3D(x, y, z);
523
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
524
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
525
                x = point_out.getX();
526
                y = point_out.getY();
527
                
528
                Point2D center = proj.createPoint( x, y);
529
                Point2D[] pts = new Point2D[360];
530
                int angulo = 0;
531
                for (angulo=0; angulo<360; angulo++) {
532
                        pts[angulo] = new Point2D.Double(center.getX(), center.getY());
533
                        pts[angulo].setLocation(pts[angulo].getX() + r * Math.sin(angulo*Math.PI/(double)180.0), pts[angulo].getY() + r * Math.cos(angulo*Math.PI/(double)180.0));
534
                        if (pts.length == 1) {
535
                                firstPt = pts[angulo];
536
                        }
537
                }
538
                DxfCircle entity = new DxfCircle(proj, layer, pts);
539
                if (grp.hasCode(5)) {
540
                        String hexS = grp.getDataAsString(5);
541
                        Integer hexI = Integer.decode("0x" + hexS);
542
                        int hexi = hexI.intValue();
543
                        entity.setHandle(hexi);
544
                } else {
545
                        entity.setHandle(entities.size()+40);
546
                }
547
                entity.setCenter(new Point2D.Double(x,y));
548
                //System.out.println("Y le metemos el centro.");
549
                entity.setRadius(r);
550
                if (grp.hasCode(62)) {
551
                        entity.dxfColor = grp.getDataAsInt(62);
552
                } else {
553
                        //entity.dxfColor = 0;
554
                }
555
                if (addingToBlock == false) {
556
                        //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
557
                        entities.add(entity);
558
                } else {
559
                        //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
560
                        blk.add(entity);
561
                }
562
        }
563
        public void createEllipse(DxfGroupVector grp) throws Exception {
564
                double incX = 0.0, incY = 0.0, incZ = 0.0;
565
                double xc = 0.0, yc = 0.0, zc = 0.0;
566
                double mMAxisRatio = 0.0;
567
                DxfGroup g = null;
568
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
569

    
570
                xc = grp.getDataAsDouble(10);
571
                yc = grp.getDataAsDouble(20);
572
                if (grp.hasCode(30)) zc = grp.getDataAsDouble(30);
573
                incX = grp.getDataAsDouble(11);
574
                incY = grp.getDataAsDouble(21);
575
                if (grp.hasCode(30)) incZ = grp.getDataAsDouble(31);
576
                if (grp.hasCode(40)) mMAxisRatio = grp.getDataAsDouble(40);
577
                
578
                Point2D pt2 = new Point2D.Double(xc+incX, yc+incY);
579
                Point2D pt1 = new Point2D.Double(xc-incX, yc-incY);
580
                double majorAxisLength = pt1.distance(pt2);
581
                double minorAxisLength = majorAxisLength*mMAxisRatio;
582
                
583
                DxfEllipse entity = new DxfEllipse(proj, layer, pt1, pt2, minorAxisLength);
584
                if (grp.hasCode(5)) {
585
                        String hexS = grp.getDataAsString(5);
586
                        Integer hexI = Integer.decode("0x" + hexS);
587
                        int hexi = hexI.intValue();
588
                        entity.setHandle(hexi);
589
                } else {
590
                        entity.setHandle(entities.size()+40);
591
                }
592
                if (grp.hasCode(62)) {
593
                        entity.dxfColor = grp.getDataAsInt(62);
594
                } else {
595
                        //entity.dxfColor = 0;
596
                }
597
                if (addingToBlock == false) {
598
                        //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
599
                        entities.add(entity);
600
                } else {
601
                        //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
602
                        blk.add(entity);
603
                }
604
        }
605
        public void createArc(DxfGroupVector grp) throws Exception {
606
                double x = 0.0, y = 0.0, z = 0.0;
607
                double r = 0.0, empieza = 0.0, acaba = 0.0;
608
                DxfGroup g = null;
609
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
610

    
611
                x = grp.getDataAsDouble(10);
612
                y = grp.getDataAsDouble(20);
613
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
614
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
615
                if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50);
616
                if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51);
617
                if (grp.hasCode(210))
618
                        xtruX = grp.getDataAsDouble(210);
619
                if (grp.hasCode(220))
620
                        xtruY = grp.getDataAsDouble(220);
621
                if (grp.hasCode(230))
622
                        xtruZ = grp.getDataAsDouble(230);
623
                Point3D point_in = new Point3D(x, y, z);
624
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
625
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
626
                x = point_out.getX();
627
                y = point_out.getY();
628
                
629
                Point2D center = proj.createPoint( x, y);
630
                //System.out.println("empieza = " + empieza + ", acaba = " + acaba);
631
                int iempieza = (int)empieza;
632
                int iacaba = (int)acaba;
633
                //System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
634
                double angulo = 0;
635
                Point2D[] pts = null;
636
                if (empieza <= acaba) {
637
                        pts = new Point2D[(iacaba-iempieza)+2];
638
                        angulo = empieza;
639
                        pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
640
                        for (int i=1; i<=(iacaba-iempieza)+1; i++) {
641
                                angulo = (double)(iempieza+i);
642
                                pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
643
                        }
644
                        angulo = acaba;
645
                        pts[(iacaba-iempieza)+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
646
                } else {
647
                        pts = new Point2D[(360-iempieza)+iacaba+2];
648
                        angulo = empieza;
649
                        //System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
650
                        pts[0] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
651
                        for (int i=1; i<=(360-iempieza); i++) {
652
                                angulo = (double)(iempieza+i);
653
                                pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
654
                        }
655
                        for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) {
656
                                angulo = (double)(i-(360-iempieza));
657
                                pts[i] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
658
                        }
659
                        angulo = acaba;
660
                        pts[(360-iempieza)+iacaba+1] = new Point2D.Double(center.getX() + r * Math.cos(angulo*Math.PI/(double)180.0), center.getY() + r * Math.sin(angulo*Math.PI/(double)180.0));
661
                }
662
                DxfArc entity = new DxfArc(proj, layer, pts);
663
                if (grp.hasCode(5)) {
664
                        String hexS = grp.getDataAsString(5);
665
                        Integer hexI = Integer.decode("0x" + hexS);
666
                        int hexi = hexI.intValue();
667
                        entity.setHandle(hexi);
668
                } else {
669
                        entity.setHandle(entities.size()+40);
670
                }
671
                // 050223, jmorell: Establecimiento de los par?metros del arco.
672
                //System.out.println("DxfEntityMaker.createArc(): pts.length = " + pts.length);
673
                entity.setCentralPoint(pts[(pts.length)/2]);
674
                //System.out.println("DxfEntityMaker.createArc(): (pts.length)/2 = " + (pts.length/2));
675
                entity.setInit(pts[0]);
676
                entity.setEnd(pts[pts.length-1]);
677
                //System.out.println("DxfEntityMaker.createArc(): (pts.length)-1 = " + (pts.length-1));
678
                entity.setCenter(center);
679
                entity.setRadius(r);
680
                entity.setInitAngle(empieza);
681
                //System.out.println("DxfEntityMaker.createArc(): empieza = " + empieza);
682
                entity.setEndAngle(acaba);
683
                //System.out.println("DxfEntityMaker.createArc(): acaba = " + acaba);
684
                if (grp.hasCode(62)) {
685
                        entity.dxfColor = grp.getDataAsInt(62);
686
                } else {
687
                        //entity.dxfColor = 0;
688
                }
689
                //System.out.println("createArc(): A?adimos un arco al bloque");
690
                if (addingToBlock == false) {
691
                        entities.add(entity);
692
                } else {
693
                        //System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
694
                        blk.add(entity);
695
                }
696
        }
697
        
698
        /**
699
         * TODO Detectados fallos en las rotaciones de bloques. Hoja 72231.
700
         *      Detectado en los bloques correspondientes a campos de futbol,
701
         *      de tipo solid.
702
         */
703
        public void createInsert(DxfGroupVector grp) throws Exception {
704
                double x = 0.0, y = 0.0, z = 0.0;
705
                DxfGroup g = null;
706
                Point2D pt = new Point2D.Double(0.0, 0.0);
707
                Point2D scaleFactor = new Point2D.Double(1.0, 1.0);
708
                double rotAngle = 0.0;
709
                String blockName = "";
710
                
711
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
712
                
713
                DxfInsert entity = new DxfInsert(proj, layer);
714
                DxfPoint secondEntity = new DxfPoint(proj, layer);
715
            // jmorell, 050406: implementaci?n inicial de los ATTRIBS para el piloto ...
716
                int attributesFollowFlag = 0;
717

    
718
                if (grp.hasCode(2)) {
719
                        blockName = grp.getDataAsString(2);
720
                        entity.setBlockName(blockName);
721
                }
722
                if (grp.hasCode(10)) x = grp.getDataAsDouble(10);
723
                if (grp.hasCode(20)) y = grp.getDataAsDouble(20);
724
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
725
                if (grp.hasCode(41)) {
726
                        scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
727
                        entity.setScaleFactor(scaleFactor);
728
                } else {
729
                        entity.setScaleFactor(scaleFactor);                        
730
                }
731
                if (grp.hasCode(42)) {
732
                        scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
733
                        entity.setScaleFactor(scaleFactor);
734
                } else {
735
                        entity.setScaleFactor(scaleFactor);
736
                }
737
                if (grp.hasCode(43)) {
738
                        // TODO La coordenada z
739
                }
740
                if (grp.hasCode(50)) {
741
                        rotAngle = grp.getDataAsDouble(50);
742
                        entity.setRotAngle(rotAngle);
743
                }
744
                if (grp.hasCode(62)) {
745
                        entity.dxfColor = grp.getDataAsInt(62);
746
                } else {
747
                        //entity.dxfColor = 0;
748
                }
749
                if (grp.hasCode(66)) {
750
                        attributesFollowFlag = grp.getDataAsInt(66);
751
                        //System.out.println("createInsert: attributesFollowFlag = " + attributesFollowFlag);
752
                }
753
                if (grp.hasCode(210))
754
                        xtruX = grp.getDataAsDouble(210);
755
                if (grp.hasCode(220))
756
                        xtruY = grp.getDataAsDouble(220);
757
                if (grp.hasCode(230))
758
                        xtruZ = grp.getDataAsDouble(230);
759
                Point3D point_in = new Point3D(x, y, z);
760
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
761
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
762
                x = point_out.getX();
763
                y = point_out.getY();
764
                                
765
                entity.setBlkList(blkList);
766
                                
767
                entity.encuentraBloque(blockName);
768
                
769
                entity.setPt(proj.createPoint(x, y));
770
                secondEntity.setPt(proj.createPoint(x, y));
771
                
772
                if (entity.getBlockFound()==true && attributesFollowFlag!=1) gestionaInsert(entity, layer);
773
                
774
                //System.out.println("createInsert: entity.getBlockName = " + entity.getBlockName());
775
                //System.out.println("createInsert: entity.getRotAngle = " + entity.getRotAngle());
776
                if (attributesFollowFlag==1) {
777
                        //System.out.println("createInsert: Coloca como lastEntity el insert");
778
                        lastEntity = entity;
779
                } else {
780
                        if (addingToBlock == false) {
781
                                entities.add(secondEntity);
782
                        } else if (addingToBlock == true && entity.blockFound == true) {
783
                                //System.out.println("createArc(): A?adimos un insert al bloque " + iterator);
784
                                blk.add(entity);
785
                        }
786
                }
787
        }
788
        
789
        public void createSolid(DxfGroupVector grp) throws Exception {
790
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0;
791
                DxfGroup g = null;
792
                //Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
793
                Point2D[] pts = new Point2D[4];
794
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
795

    
796
                x = grp.getDataAsDouble(10);
797
                y = grp.getDataAsDouble(20);
798
                if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30);
799
                pts[0] = proj.createPoint(x, y);
800
                x = grp.getDataAsDouble(11);
801
                y = grp.getDataAsDouble(21);
802
                if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31);
803
                pts[1] = proj.createPoint(x, y);
804
                x = grp.getDataAsDouble(12);
805
                y = grp.getDataAsDouble(22);
806
                if (grp.hasCode(32)) z3 = grp.getDataAsDouble(32);
807
                pts[2] = proj.createPoint(x, y);
808
                x = grp.getDataAsDouble(13);
809
                y = grp.getDataAsDouble(23);
810
                if (grp.hasCode(33)) z2 = grp.getDataAsDouble(33);
811
                pts[3] = proj.createPoint(x, y);
812
                if (grp.hasCode(210))
813
                        xtruX = grp.getDataAsDouble(210);
814
                if (grp.hasCode(220))
815
                        xtruY = grp.getDataAsDouble(220);
816
                if (grp.hasCode(230))
817
                        xtruZ = grp.getDataAsDouble(230);
818
                Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1);
819
                Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2);
820
                Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3);
821
                Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4);
822
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
823
                Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
824
                Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
825
                Point2D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
826
                Point2D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
827
                pts[0].setLocation(point_out1);
828
                pts[1].setLocation(point_out2);
829
                pts[2].setLocation(point_out3);
830
                pts[3].setLocation(point_out4);
831
                DxfSolid entity = new DxfSolid(proj, layer, pts);
832
                if (grp.hasCode(62)) {
833
                        entity.dxfColor = grp.getDataAsInt(62);
834
                } else {
835
                        //entity.dxfColor = 0;
836
                }
837
                if (addingToBlock == false) {
838
                        //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
839
                        entities.add(entity);
840
                } else {
841
                        //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
842
                        blk.add(entity);
843
                }
844
        }
845
        /**
846
         * Los Splines estan implementados como LwPolylines. Se pintan las lineas
847
         * entre los vertices pero no se aplica la curvatura Spline.
848
         * TODO Contemplar la curvatura spline para Splines.
849
         */
850
        public void createSpline(DxfGroupVector grp) throws Exception {
851
                double x = 0.0, y = 0.0, elev=0.0;
852
                DxfGroup g = null;
853
                
854
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
855
                DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
856
                for (int i=0; i<grp.size(); i++) {
857
                        g = (DxfGroup) grp.get(i);
858
                        if (g.getCode() == 10)
859
                                x = ((Double) g.getData()).doubleValue();
860
                        else if (g.getCode() == 20) {
861
                                y = ((Double) g.getData()).doubleValue();
862
                                //if (y <= 1.0) throw new Exception("Y == "+y);
863
                                entity.add( proj.createPoint( x, y ) );
864
                                x = 0.0; y = 0.0;
865
                        }
866
                }
867
                if (grp.hasCode(62)) {
868
                        entity.dxfColor = grp.getDataAsInt(62);
869
                } else {
870
                        //entity.dxfColor = 0;
871
                }
872
                if (grp.hasCode(70))
873
                        entity.flags = grp.getDataAsInt(70);
874
                if ((entity.flags & 0x01) == 0x01) {
875
                        entity.closed = true;
876
                }
877
                if (addingToBlock == false) {
878
                        entities.add(entity);
879
                } else {
880
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
881
                        blk.add(entity);
882
                }
883
        }
884
        public void createBlock(DxfGroupVector grp) throws Exception {
885
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
886
                blk = new DxfBlock(proj);
887
                
888
                Point2D basePoint = new Point2D.Double();
889
                String blockName = "";
890
                //System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
891
                
892
                addingToBlock = true;
893
                //System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
894
                blkList.add(iterator, blk);
895
                
896
                //System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
897
                if (grp.hasCode(1)) {
898
                        blockName = grp.getDataAsString(1);
899
                        blk.setBlkName(blockName);
900
                }
901
                if (grp.hasCode(2)) {
902
                        blockName = grp.getDataAsString(2);
903
                        blk.setBlkName(blockName);
904
                }
905
                if (grp.hasCode(3)) {
906
                        blockName = grp.getDataAsString(3);
907
                        blk.setBlkName(blockName);
908
                }
909
                if (grp.hasCode(10)) {
910
                        basePoint = new Point2D.Double(grp.getDataAsDouble(10), basePoint.getY());
911
                        blk.setBPoint(basePoint);
912
                }
913
                if (grp.hasCode(20)) {
914
                        basePoint = new Point2D.Double(basePoint.getX(), grp.getDataAsDouble(20));
915
                        blk.setBPoint(basePoint);
916
                }
917
                if (grp.hasCode(30)) {
918
                        // TODO Contemplar la coordenada z
919
                }
920
                if (grp.hasCode(70)) {
921
                        blk.flags = grp.getDataAsInt(70);                        
922
                }
923
        }
924
        public void endBlk(DxfGroupVector grp) throws Exception {
925
                //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
926
                setAddingToBlock(false);
927
                iterator = iterator + 1;
928
        }
929

    
930
        public void testBlocks() {
931
                Vector blkList = getBlkList();
932
                DxfBlock dxfBlock = null;
933
                DxfEntity dxfEntity = null;
934
                DxfLine dxfLine = null;
935
                DxfInsert dxfInsert = null;
936
                Point2D point1 = new Point2D.Double();
937
                Point2D point2 = new Point2D.Double();
938
                for (int i=0; i<blkList.size(); i++) {
939
                        dxfBlock = (DxfBlock)blkList.get(i);
940
                        int aux = dxfBlock.getBlkElements().size();
941
                        for (int j=0; j<aux; j++) {
942
                                dxfEntity = (DxfEntity)dxfBlock.getBlkElements().get(j);
943
                                if (dxfEntity instanceof DxfLine) {
944
                                        dxfLine = (DxfLine)dxfEntity;
945
                                        point1 = dxfLine.getPts()[0];
946
                                        point2 = dxfLine.getPts()[1];
947
                                        //System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", vertice1 = " + point1 + ", vertice2 = " + point2);
948
                                } else if (dxfEntity instanceof DxfInsert){
949
                                        dxfInsert = (DxfInsert)dxfEntity;
950
                                        String nomBlock = dxfInsert.getBlockName();
951
                                        //System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", inserta el bloque = " + nomBlock);
952
                                        //System.out.println("compruebaBloques(): dxfInsert.pt = " + dxfInsert.getPt());
953
                                        //System.out.println("compruebaBloques(): dxfInsert.rotAngle = " + dxfInsert.getRotAngle());
954
                                        //System.out.println("compruebaBloques(): dxfInsert.scaleFactor = " + dxfInsert.getScaleFactor());
955
                                        
956
                                        if (dxfInsert.getBlockFound() == false) {
957
                                                //System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock);
958
                                                boolean aux_bool = dxfInsert.encuentraBloque(nomBlock);
959
                                                gestionaInsert(dxfInsert, dxfInsert.getDxfLayer());
960
                                                dxfBlock.add(dxfInsert);
961
                                        }
962
                                        
963
                                }
964
                        }
965
                }
966
        }
967
        
968
        public void setProjection(IProjection proj) { this.proj = proj;}
969
        public IProjection getProjection() { return proj;}
970

    
971
        public void reProject(ICoordTrans rp) {
972
                entities.reProject(rp);
973
                setProjection(rp.getPDest());
974
        }
975
        
976
        public DxfEntityList getEntities() { return entities;}
977
        public DxfTable getLayers() { return layers;}
978
        
979
        public DxfBlock getBlk() {
980
                return blk;
981
        }
982
        
983
        public void gestionaInsert(DxfInsert entity, DxfLayer layer) {
984
                DxfEntity dxfEntity = null;
985
                DxfLine dxfLine = null;
986
                DxfInsert dxfInsert = null;
987
                DxfPolyline dxfPolyline = null;
988
                DxfArc dxfArc = null;
989
                DxfCircle dxfCircle = null;
990
                DxfLwPolyline dxfLwPolyline = null;
991
                DxfPoint dxfPoint = null;
992
                DxfText dxfText = null;
993
                DxfSolid dxfSolid = null;
994
                // jmorell, 050406: intentando corregir cosas que salen fuera de sitio ...
995
                double bPointX = 0.0;
996
                double bPointY = 0.0;
997
                //if (entity.getBlockFound() == true) {
998
                        bPointX = entity.block.bPoint.getX();
999
                        bPointY = entity.block.bPoint.getY();
1000
                //}
1001
                double sFactorX = entity.getScaleFactor().getX();
1002
                double sFactorY = entity.getScaleFactor().getY();
1003
                double rAngleGra = entity.getRotAngle();
1004
                double rAngleRad = rAngleGra*Math.PI/180.0;
1005
                for (int i=0; i<entity.block.size(); i++) {
1006
                        //System.out.println("gestionaInserts: entity.block.blkElements.size() = " + entity.block.blkElements.size());
1007
                        dxfEntity = (DxfEntity)entity.block.get(i);
1008
                        
1009
                        Point2D point1 = new Point2D.Double();
1010
                        Point2D point2 = new Point2D.Double();
1011
                        Point2D point11 = new Point2D.Double();
1012
                        Point2D point22 = new Point2D.Double();
1013
                        Point2D pointAux = null;
1014
                        if (dxfEntity instanceof DxfLine) {
1015
                                dxfLine = (DxfLine)dxfEntity;
1016
                                point1 = dxfLine.getPts()[0];
1017
                                //double laX = entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX());
1018
                                //double laY = entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY());
1019
                                pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY);
1020
                                double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1021
                                double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1022
                                point11.setLocation(laX, laY);
1023
                                point2 = dxfLine.getPts()[1];
1024
                                pointAux = new Point2D.Double(point2.getX() - bPointX, point2.getY() - bPointY);
1025
                                laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1026
                                laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1027
                                point22.setLocation(laX, laY);
1028
                                DxfLine dxfLinee = new DxfLine(proj, layer, point11, point22);
1029
                                if (addingToBlock == false) {
1030
                                        entities.add(dxfLinee);
1031
                                }
1032
                        } else if (dxfEntity instanceof DxfInsert){
1033
                                dxfInsert = (DxfInsert)dxfEntity;
1034
                                point1 = dxfInsert.pt;
1035
                                pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY);
1036
                                //point11.setLocation(entity.pt.getX() - entity.block.bPoint.getX() + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - entity.block.bPoint.getY() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1037
                                //point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1038
                                double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1039
                                double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1040
                                point11.setLocation(laX, laY);
1041
                                DxfInsert dxfInsertt = new DxfInsert(proj, layer);
1042
                                
1043
                                dxfInsertt.pt = point11;
1044
                                
1045
                                dxfInsertt.blkList = dxfInsert.blkList;
1046
                                dxfInsertt.block = dxfInsert.block;
1047
                                dxfInsertt.blockName = dxfInsert.blockName;
1048
                                dxfInsertt.rotAngle = dxfInsert.rotAngle;
1049
                                dxfInsertt.layer = dxfInsert.layer;
1050
                                dxfInsertt.proj = dxfInsert.proj;
1051
                                Point2D newScale = new Point2D.Double(dxfInsert.getScaleFactor().getX() * sFactorX, dxfInsert.getScaleFactor().getY() * sFactorY);
1052
                                dxfInsertt.setScaleFactor(newScale);
1053
                                //dxfInsertt.scaleFactor = new Point2D.Double(dxfInsert.scaleFactor.getX() * entity.scaleFactor.getX(), dxfInsert.scaleFactor.getY() * entity.scaleFactor.getY());
1054
                                
1055
                                gestionaInsert(dxfInsertt, layer);
1056
                        } else if (dxfEntity instanceof DxfPolyline) {
1057
                                dxfPolyline = (DxfPolyline)dxfEntity;
1058
                                DxfPolyline dxfPolylinee = new DxfPolyline(proj, layer);
1059
                                if (dxfPolyline.closed) dxfPolylinee.closed = true;
1060
                                Point2D[] points = new Point2D[dxfPolyline.pts.size()];
1061
                                Point2D[] pointss = new Point2D[dxfPolyline.pts.size()];
1062
                                for (int j=0; j<dxfPolyline.pts.size(); j++) {
1063
                                        points[j] = (Point2D)dxfPolyline.pts.get(j);
1064
                                        pointss[j] = new Point2D.Double();                                        
1065
                                        //pointss[j].setLocation(entity.pt.getX() - entity.block.bPoint.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - entity.block.bPoint.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1066
                                        //pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1067
                                        pointAux = new Point2D.Double(points[j].getX() - bPointX, points[j].getY() - bPointY);
1068
                                        double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1069
                                        double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1070
                                        pointss[j].setLocation(laX, laY);
1071
                                        //pointss[j].setLocation(entity.pt.getX() + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1072
                                        dxfPolylinee.add(pointss[j]);
1073
                                        // jmorell, 050405: Bulges en Dxfpolyline para el piloto
1074
                                        dxfPolylinee.addBulge((Double)dxfPolyline.getBulges().get(j));
1075
                                }
1076
                                if (addingToBlock == false) entities.add(dxfPolylinee);
1077
                        } else if (dxfEntity instanceof DxfArc) {
1078
                                dxfArc = (DxfArc)dxfEntity;
1079
                                Point2D[] points = new Point2D[dxfArc.pts.length];
1080
                                Point2D[] pointss = new Point2D[dxfArc.pts.length];
1081
                                for (int j=0; j<dxfArc.pts.length; j++) {
1082
                                        points[j] = (Point2D)dxfArc.pts[j];
1083
                                        pointss[j] = new Point2D.Double();
1084
                                        pointAux = new Point2D.Double(points[j].getX() - bPointX, points[j].getY() - bPointY);
1085
                                        double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1086
                                        double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1087
                                        pointss[j].setLocation(laX, laY);
1088
                                        //pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1089
                                }
1090
                                DxfArc dxfArcc = new DxfArc(proj, layer, pointss);
1091
                                // 050315, jmorell: Para que no se pierdan las propiedades en el
1092
                                //                                        caso de objetos dentro de bloques.
1093
                                pointAux = new Point2D.Double(dxfArc.getCentralPoint().getX() - bPointX, dxfArc.getCentralPoint().getY() - bPointY);
1094
                                double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1095
                                double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1096
                                pointAux.setLocation(laX, laY);
1097
                                dxfArcc.setCentralPoint(pointAux);
1098
                                pointAux = new Point2D.Double(dxfArc.getInit().getX() - bPointX, dxfArc.getInit().getY() - bPointY);
1099
                                laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1100
                                laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1101
                                pointAux.setLocation(laX, laY);
1102
                                dxfArcc.setInit(pointAux);
1103
                                pointAux = new Point2D.Double(dxfArc.getEnd().getX() - bPointX, dxfArc.getEnd().getY() - bPointY);
1104
                                laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1105
                                laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1106
                                pointAux.setLocation(laX, laY);
1107
                                dxfArcc.setEnd(pointAux);
1108
                                pointAux = new Point2D.Double(dxfArc.getCenter().getX() - bPointX, dxfArc.getCenter().getY() - bPointY);
1109
                                laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1110
                                laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1111
                                pointAux.setLocation(laX, laY);
1112
                                dxfArcc.setCenter(pointAux);
1113
                                dxfArcc.setRadius(dxfArc.getRadius()*sFactorX);
1114
                                // TODO ?Como afectan las rotaciones del insert al init y el end angle?
1115
                                dxfArcc.setInitAngle(dxfArc.getInitAngle());
1116
                                dxfArcc.setEndAngle(dxfArc.getEndAngle());
1117
                                if (addingToBlock == false) entities.add(dxfArcc);
1118
                        } else if (dxfEntity instanceof DxfCircle) {
1119
                                dxfCircle = (DxfCircle)dxfEntity;
1120
                                Point2D[] points = new Point2D[dxfCircle.pts.length];
1121
                                Point2D[] pointss = new Point2D[dxfCircle.pts.length];
1122
                                for (int j=0; j<dxfCircle.pts.length; j++) {
1123
                                        points[j] = (Point2D)dxfCircle.pts[j];
1124
                                        pointss[j] = new Point2D.Double();
1125
                                        pointAux = new Point2D.Double(points[j].getX() - bPointX, points[j].getY() - bPointY);
1126
                                        double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1127
                                        double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1128
                                        pointss[j].setLocation(laX, laY);
1129
                                        //pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1130
                                }
1131
                                DxfCircle dxfCirclee = new DxfCircle(proj, layer, pointss);
1132
                                // 050315, jmorell: Para que no se pierdan las propiedades en el
1133
                                //                                        caso de objetos dentro de bloques.
1134
                                pointAux = new Point2D.Double(dxfCircle.getCenter().getX() - bPointX, dxfCircle.getCenter().getY() - bPointY);
1135
                                double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1136
                                double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1137
                                pointAux.setLocation(laX, laY);
1138
                                dxfCirclee.setCenter(pointAux);
1139
                                // Escala en X = escala en Y ...
1140
                                dxfCirclee.setRadius(dxfCircle.getRadius()*sFactorX);
1141
                                if (addingToBlock == false) entities.add(dxfCirclee);
1142
                        } else if (dxfEntity instanceof DxfLwPolyline) {
1143
                                dxfLwPolyline = (DxfLwPolyline)dxfEntity;
1144
                                DxfLwPolyline dxfLwPolylinee = new DxfLwPolyline(proj, layer);
1145
                                Point2D[] points = new Point2D[dxfLwPolyline.pts.size()];
1146
                                Point2D[] pointss = new Point2D[dxfLwPolyline.pts.size()];
1147
                                for (int j=0; j<dxfLwPolyline.pts.size(); j++) {
1148
                                        points[j] = (Point2D)dxfLwPolyline.pts.get(j);
1149
                                        pointss[j] = new Point2D.Double();                                        
1150
                                        pointAux = new Point2D.Double(points[j].getX() - bPointX, points[j].getY() - bPointY);
1151
                                        double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1152
                                        double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1153
                                        pointss[j].setLocation(laX, laY);
1154
                                        //pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1155
                                        dxfLwPolylinee.add(pointss[j]);
1156
                                        // jmorell, 050405: Bulges en Dxfpolyline para el piloto
1157
                                        dxfLwPolylinee.addBulge((Double)dxfPolyline.getBulges().get(j));
1158
                                }
1159
                                if (addingToBlock == false) entities.add(dxfLwPolylinee);
1160
                        } else if (dxfEntity instanceof DxfPoint) {
1161
                                dxfPoint = (DxfPoint)dxfEntity;
1162
                                point1 = dxfPoint.getPt();
1163
                                pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY);
1164
                                double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1165
                                double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1166
                                point11.setLocation(laX, laY);
1167
                                //point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1168
                                DxfPoint dxfPointt = new DxfPoint(proj, layer);
1169
                                //dxfPointt.pt = point11;
1170
                                dxfPointt.setPt(point11);
1171
                                if (addingToBlock == false) entities.add(dxfPointt);
1172
                        } else if (dxfEntity instanceof DxfText) {
1173
                                dxfText = (DxfText)dxfEntity;
1174
                                if (dxfText.getTwoPointsFlag()) {
1175
                                        point1 = dxfText.pts[0];
1176
                                        pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY);
1177
                                        double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1178
                                        double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1179
                                        point11.setLocation(laX, laY);
1180
                                        //point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1181
                                        point2 = dxfText.pts[1];
1182
                                        pointAux = new Point2D.Double(point2.getX() - bPointX, point2.getY() - bPointY);
1183
                                        laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1184
                                        laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1185
                                        point22.setLocation(laX, laY);
1186
                                        //point22.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point2.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point2.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point2.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point2.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1187
                                        DxfText dxfTextt = new DxfText(proj, layer, dxfText.getText());
1188
                                        dxfTextt.pts[0] = point11;
1189
                                        dxfTextt.pts[1] = point22;
1190
                                        if (addingToBlock == false) entities.add(dxfTextt);
1191
                                } else {
1192
                                        point1 = dxfText.getPt();
1193
                                        pointAux = new Point2D.Double(point1.getX() - bPointX, point1.getY() - bPointY);
1194
                                        double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1195
                                        double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1196
                                        point11.setLocation(laX, laY);
1197
                                        //point11.setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((point1.getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + point1.getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1198
                                        DxfText dxfTextt = new DxfText(proj, layer, dxfText.getText());
1199
                                        dxfTextt.setPt(point11);
1200
                                        if (addingToBlock == false) entities.add(dxfTextt);
1201
                                }
1202
                        } else if (dxfEntity instanceof DxfSolid) {
1203
                                dxfSolid = (DxfSolid)dxfEntity;
1204
                                Point2D[] points = new Point2D[dxfSolid.pts.length];
1205
                                Point2D[] pointss = new Point2D[dxfSolid.pts.length];
1206
                                for (int j=0; j<dxfSolid.pts.length; j++) {
1207
                                        points[j] = (Point2D)dxfSolid.pts[j];
1208
                                        pointss[j] = new Point2D.Double();
1209
                                        pointAux = new Point2D.Double(points[j].getX() - bPointX, points[j].getY() - bPointY);
1210
                                        double laX = entity.pt.getX() + ((pointAux.getX()*sFactorX)*Math.cos(rAngleRad) + (pointAux.getY()*sFactorY)*(-1)*Math.sin(rAngleRad));
1211
                                        double laY = entity.pt.getY() + ((pointAux.getX()*sFactorX)*Math.sin(rAngleRad) + (pointAux.getY()*sFactorY)*Math.cos(rAngleRad));
1212
                                        pointss[j].setLocation(laX, laY);
1213
                                        //pointss[j].setLocation(entity.pt.getX() - (entity.block.bPoint.getX() * entity.getScaleFactor().getX()) + ((points[j].getX()*Math.cos((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*(-1)*Math.sin((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getX()), entity.pt.getY() - (entity.block.bPoint.getY() * entity.getScaleFactor().getY()) + ((points[j].getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + points[j].getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1214
                                }
1215
                                DxfSolid dxfSolidd = new DxfSolid(proj, layer, pointss);
1216
                                Point2D aux = dxfSolidd.pts[2];
1217
                                dxfSolidd.pts[2] = dxfSolidd.pts[3];
1218
                                dxfSolidd.pts[3] = aux;
1219
                                if (addingToBlock == false) entities.add(dxfSolidd);
1220
                        } else {
1221
                                System.out.println("gestionaInserts: Encontrado elemento desconocido");
1222
                        }
1223
                }
1224
        }
1225

    
1226
        public void createAttdef(DxfGroupVector grp) throws Exception {
1227
                DxfGroup g = null;
1228
                
1229
                String defaultValue = "";
1230
                String tagString = "";
1231
                String textStyleName = "";
1232
                String attribute[] = new String[2];
1233
                boolean tagDefined = false;
1234
                boolean defValDefined = false;
1235
                
1236
                if (grp.hasCode(1)) {
1237
                        defaultValue = grp.getDataAsString(1);                        
1238
                        attribute[1] = DxfConvTexts.ConvertText(defaultValue);
1239
                        defValDefined = true;
1240
                        if (tagDefined) attributes.add(attribute);
1241
                }
1242
                if (grp.hasCode(2)) {
1243
                        tagString = grp.getDataAsString(2);                        
1244
                        attribute[0] = DxfConvTexts.ConvertText(tagString);
1245
                        tagDefined = true;
1246
                        if (defValDefined) attributes.add(attribute);
1247
                }
1248
                if (grp.hasCode(7)) {
1249
                        textStyleName = grp.getDataAsString(7);                        
1250
                        textStyleName = DxfConvTexts.ConvertText(textStyleName);
1251
                }
1252
                // TODO setNewAttributes();
1253
        }
1254
        public void createAttrib(DxfGroupVector grp) throws Exception {
1255
                double x = 0.0, y = 0.0, z = 0.0, h= 0.0, rot= 0.0;
1256
                DxfGroup g = null;
1257
                Point2D pt = null;
1258
                
1259
                String defaultValue = "";
1260
                String tagString = "";
1261
                String textStyleName = "";
1262
                String att[] = new String[2];
1263
                boolean tagDefined = false;
1264
                boolean defValDefined = false;
1265
                int attributeFlags = 0;
1266
                
1267
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
1268
                DxfAttrib entity = new DxfAttrib(proj, layer);
1269
                
1270
                if (grp.hasCode(1)) {
1271
                        String strAux1 = grp.getDataAsString(1);                        
1272
                        strAux1 = DxfConvTexts.ConvertText(strAux1);
1273
                        defaultValue = strAux1;
1274
                        att[1] = DxfConvTexts.ConvertText(defaultValue);
1275
                        defValDefined = true;
1276
                        /*if (tagDefined) {
1277
                                insFea.setProp(att[0], att[1]);
1278
                                ptFea.setProp(att[0], att[1]);
1279
                        }
1280
                        feature.setProp("text", strAux1);*/
1281
                }
1282
                if (grp.hasCode(2)) {
1283
                        String strAux2 = grp.getDataAsString(2);                        
1284
                        strAux2 = DxfConvTexts.ConvertText(strAux2);
1285
                        tagString = strAux2;                        
1286
                        att[0] = DxfConvTexts.ConvertText(tagString);
1287
                        tagDefined = true;
1288
                        /*if (defValDefined) {
1289
                                insFea.setProp(att[0], att[1]);
1290
                                ptFea.setProp(att[0], att[1]);
1291
                        }*/
1292
                }
1293
                if (grp.hasCode(7)) {
1294
                        textStyleName = grp.getDataAsString(7);                        
1295
                        textStyleName = DxfConvTexts.ConvertText(textStyleName);
1296
                }
1297
                x = grp.getDataAsDouble(10);
1298
                y = grp.getDataAsDouble(20);
1299
                entity.setPt(proj.createPoint(x, y));
1300
                if (grp.hasCode(40)) {
1301
                        Double heightD = new Double(grp.getDataAsDouble(40));
1302
                        String heightS = heightD.toString();
1303
                        //feature.setProp("textHeight", heightS);
1304
                } else {
1305
                        //feature.setProp("textHeight", "20.0");
1306
                }
1307
                if (grp.hasCode(50)) {
1308
                        Double rotD = new Double(grp.getDataAsDouble(50));
1309
                        String rotS = rotD.toString();
1310
                        //feature.setProp("textRotation", rotS);
1311
                } else {
1312
                        //feature.setProp("textRotation", "0.0");
1313
                }
1314
                if (grp.hasCode(62)) {
1315
                        entity.dxfColor = grp.getDataAsInt(62);
1316
                } else {
1317
                        //entity.dxfColor = 0;
1318
                }
1319
                if (grp.hasCode(70)) {
1320
                        attributeFlags = grp.getDataAsInt(70);
1321
                }
1322
                
1323
                if (attributeFlags==8) {
1324
                        if (addingToBlock == false) {
1325
                                entities.add(entity);
1326
                        } else {
1327
                                blk.add(entity);
1328
                        }
1329
                }
1330
        }
1331

    
1332
        public Vector getAttributes() {
1333
                return attributes;
1334
        }
1335

    
1336
        /* (non-Javadoc)
1337
         * @see org.cresques.io.DxfFile.EntityFactory#depureAttributes()
1338
         */
1339
        public void depureAttributes() {
1340
                // TODO Auto-generated method stub
1341
                
1342
        }
1343

    
1344
    /* (non-Javadoc)
1345
     * @see org.cresques.io.DxfFile.EntityFactory#isDxf3DFile()
1346
     */
1347
    public boolean isDxf3DFile() {
1348
        // TODO Auto-generated method stub
1349
        return false;
1350
    }
1351
        
1352
}