Statistics
| Revision:

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

History | View | Annotate | Download (57 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
                        Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
254
                        ((DxfPolyline) lastEntity).pts.remove(cnt-1);
255
                        for (int i=0; i<arc.size(); i++) {
256
                                pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
257
                                ((DxfPolyline) lastEntity).add(pt);
258
                                if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
259
                        }
260
                        bulge = bulge_aux;
261
                } else { //si el bulge es menor que cero.
262
                        double bulge_aux = 0.0;
263
                        if (grp.hasCode(42)) {
264
                                bulge_aux = grp.getDataAsDouble(42); // * (-1.0);
265
                        } else { bulge_aux = 0.0; }
266
                        Point3D point_in = new Point3D(x, y, z);
267
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
268
                        Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
269
                        x = point_out.getX();
270
                        y = point_out.getY();
271
                        Point2D pt = proj.createPoint( x, y);
272
                        ((DxfPolyline) lastEntity).add(pt);
273
                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
274
                        int cnt = ((DxfPolyline) lastEntity).pts.size();
275
                        Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
276
                        ((DxfPolyline) lastEntity).pts.remove(cnt-1);
277
                        for (int i=0; i<arc.size(); i++) {
278
                                pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
279
                                ((DxfPolyline) lastEntity).add(pt);
280
                                if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
281
                        }
282
                        bulge = bulge_aux;                        
283
                }
284
                /*if (grp.hasCode(5)) {
285
                        String hexS = grp.getDataAsString(5);
286
                        Integer hexI = Integer.decode("0x" + hexS);
287
                        int hexi = hexI.intValue();
288
                        lastEntity.setHandle(hexi);
289
                } else {
290
                        lastEntity.setHandle(entities.size()+40);
291
                }*/
292
        }
293
        
294
        public void createLwPolyline(DxfGroupVector grp) throws Exception {
295
                double x = 0.0, y = 0.0, elev=0.0;
296
                DxfGroup g = null;
297
                
298
                if (grp.hasCode(38))
299
                        elev = grp.getDataAsDouble(38);
300
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
301
                DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
302
                if (grp.hasCode(5)) {
303
                        String hexS = grp.getDataAsString(5);
304
                        Integer hexI = Integer.decode("0x" + hexS);
305
                        int hexi = hexI.intValue();
306
                        entity.setHandle(hexi);
307
                } else {
308
                        entity.setHandle(entities.size()+40);
309
                }
310
                double bulge = 0;
311
                boolean isNewCoord = false;
312
                for (int i=0; i<grp.size(); i++) {
313
                        bulge = 0;
314
                        isNewCoord = false;
315
                        g = (DxfGroup) grp.get(i);
316
                        if (g.getCode() == 10) {
317
                                x = ((Double) g.getData()).doubleValue();
318
                        } else if (g.getCode() == 20) {
319
                                y = ((Double) g.getData()).doubleValue();
320
                                //if (y <= 1.0) throw new Exception("Y == "+y);
321
                                entity.add( proj.createPoint( x, y ) );
322
                                entity.addBulge(new Double(0));
323
                                x = 0.0; y = 0.0;
324
                                isNewCoord = true;
325
                        } else if (g.getCode() == 42) {
326
                                //entity.addBulge((Double)g.getData());
327
                                entity.getBulges().remove(entity.getBulges().size()-1);
328
                                entity.getBulges().add((Double)g.getData());
329
                                bulge = ((Double) g.getData()).doubleValue();
330
                        }
331
                        /*if (bulge == 0 && isNewCoord) {
332
                                entity.addBulge(new Double(0));
333
                        }*/
334
                }
335
                //System.out.println("entity.getPts().size() = " + entity.getPts().size());
336
                //System.out.println("entity.getBulges().size() = " + entity.getBulges().size());
337
                if (grp.hasCode(62)) {
338
                        entity.dxfColor = grp.getDataAsInt(62);
339
                } else {
340
                        //entity.dxfColor = 0;
341
                }
342
                if (grp.hasCode(70)) {
343
                        entity.flags = grp.getDataAsInt(70);
344
                        //System.out.println("entity.flags = " + entity.flags);
345
                }
346
                if ((entity.flags & 0x01) == 0x01) {
347
                        entity.closed = true;
348
                }
349
                if (addingToBlock == false) {
350
                        entities.add(entity);
351
                } else {
352
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
353
                        blk.add(entity);
354
                }
355
        }
356
        public void createLine(DxfGroupVector grp) throws Exception {
357
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0;
358
                DxfGroup g = null;
359
                Point2D pt1 = null, pt2 = null;
360
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
361

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

    
413
                txt = grp.getDataAsString(1);
414
                DxfText entity = new DxfText(proj, layer, txt);
415

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

    
459
                DxfPoint entity = new DxfPoint(proj, layer);
460
                
461
                if (grp.hasCode(5)) {
462
                        String hexS = grp.getDataAsString(5);
463
                        Integer hexI = Integer.decode("0x" + hexS);
464
                        int hexi = hexI.intValue();
465
                        entity.setHandle(hexi);
466
                } else {
467
                        entity.setHandle(entities.size()+40);
468
                }
469

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

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

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

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

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

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

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

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

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

    
1324
        public Vector getAttributes() {
1325
                return attributes;
1326
        }
1327

    
1328
        /* (non-Javadoc)
1329
         * @see org.cresques.io.DxfFile.EntityFactory#depureAttributes()
1330
         */
1331
        public void depureAttributes() {
1332
                // TODO Auto-generated method stub
1333
                
1334
        }
1335

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