Statistics
| Revision:

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

History | View | Annotate | Download (48 KB)

1
package org.cresques.px.dxf;
2

    
3
import java.awt.geom.Point2D;
4
import java.util.Vector;
5

    
6
import org.cresques.cts.ICoordTrans;
7
import org.cresques.cts.IProjection;
8
import org.cresques.geo.Point3D;
9
import org.cresques.geo.Projected;
10
import org.cresques.io.DxfFile;
11
import org.cresques.io.DxfGroup;
12
import org.cresques.io.DxfGroupVector;
13
import org.cresques.px.Extent;
14
import org.cresques.px.IObjList;
15
import org.cresques.px.PxObj;
16

    
17
/**
18
 * jmorell: Implementaci?n de la creaci?n de entidades DXF2000.
19
 */
20
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected {
21
        IProjection proj = null;
22
        DxfEntity lastEntity = null;
23
        DxfEntityList entities = null;
24
        Vector blkList = null;
25
        DxfBlock blk = null;
26
        DxfTable layers = null;
27
        double bulge = 0.0;
28

    
29
    double xtruX=0.0, xtruY=0.0, xtruZ=1.0;
30
    
31
    int polylineFlag = 0;
32
    Point2D firstPt = new Point2D.Double();
33
    
34
    boolean addingToBlock = false;
35
    int iterator = 0;
36
            
37
        public DxfEntityMaker (IProjection proj) {
38
                this.proj = proj;
39
                layers = new DxfTable();
40
                entities = new DxfEntityList(proj);
41
                blkList = new Vector();
42
        }
43
        
44
        public Vector getBlkList() { return blkList; }
45
        
46
        public IObjList getObjects() { return entities; }
47
        public Extent getExtent() { return entities.getExtent(); }
48

    
49
        public void setAddingToBlock(boolean a) { addingToBlock = a; }
50
        
51
        public void createLayer(DxfGroupVector grp) throws Exception {
52
                int color = grp.getDataAsInt(62);
53
                DxfLayer layer = new DxfLayer(grp.getDataAsString(2), Math.abs(grp.getDataAsInt(62)));
54
                if (color < 0) {
55
                        layer.isOff = true;
56
                }
57
                layer.lType = grp.getDataAsString(6);
58
                layer.setFlags(grp.getDataAsInt(70));
59
                // compruebo flags
60
                if ((layer.flags & 0x01) == 0x01) {
61
                        layer.frozen = true;
62
                }
63
                if ((layer.flags & 0x02) == 0x02) {
64
                        layer.frozen = true;
65
                }
66
                System.out.println("LAYER color="+layer.getColor());
67

    
68
                layers.add(layer);
69
        }
70
        
71
        public void createPolyline(DxfGroupVector grp) throws Exception {
72
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
73
                DxfPolyline entity = new DxfPolyline(proj, layer);
74
                if (grp.hasCode(5)) {
75
                        String hexS = grp.getDataAsString(5);
76
                        Integer hexI = Integer.decode("0x" + hexS);
77
                        int hexi = hexI.intValue();
78
                        entity.setHandle(hexi);
79
                } else {
80
                        entity.setHandle(entities.size()+40);
81
                }
82

    
83
                double x = 0.0, y = 0.0, z = 0.0;
84
                double thickness = 0;
85
                
86
                if (grp.hasCode(10))
87
                        x = grp.getDataAsDouble(10);
88
                if (grp.hasCode(20))
89
                        y = grp.getDataAsDouble(20);
90
                if (grp.hasCode(30))
91
                        z = grp.getDataAsDouble(30);
92
                /*if (grp.hasCode(39))
93
                        System.out.println("Leer el thickness provoca un error");
94
                        thickness = grp.getDataAsDouble(39);*/
95
                if (grp.hasCode(62)) {
96
                        entity.dxfColor = grp.getDataAsInt(62);
97
                } else {
98
                        //entity.dxfColor = 0;
99
                }
100
                if (grp.hasCode(66)) {
101
                        entity.entitiesFollow = grp.getDataAsInt(66);
102
                }
103
                if (grp.hasCode(70)) {
104
                        entity.flags = grp.getDataAsInt(70);                        
105
                }
106
                if (grp.hasCode(210))
107
                        xtruX = grp.getDataAsDouble(210);
108
                if (grp.hasCode(220))
109
                        xtruY = grp.getDataAsDouble(220);
110
                if (grp.hasCode(230))
111
                        xtruZ = grp.getDataAsDouble(230);
112
                        
113
                if ((entity.flags & 0x01) == 0x01) {
114
                        entity.closed = true;
115
                }
116
                lastEntity = entity;
117
        }
118
        
119
        public void endSeq() throws Exception {
120
                DxfPolyline polyline = (DxfPolyline)lastEntity;
121
                if (polyline.closed) {
122
                        ((DxfPolyline) lastEntity).add(firstPt);
123
                        if (!(bulge==0)) {
124
                                int cnt = ((DxfPolyline) lastEntity).pts.size();
125
                                Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
126
                                ((DxfPolyline) lastEntity).pts.remove(cnt-1);
127
                                for (int i=0; i<arc.size(); i++) {
128
                                        Point2D pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
129
                                        ((DxfPolyline) lastEntity).add(pt);
130
                                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
131
                                }
132
                                bulge = 0.0;
133
                        }
134
                }
135
                //lastEntity.setHandle(entities.size()+40);
136
                if (addingToBlock == false) {
137
                        //System.out.println("createPolyline: A?adimos una polilinea a la lista de entidades");
138
                        entities.add(lastEntity);
139
                } else {
140
                        //System.out.println("createPolyline: A?adimos una polilinea al bloque " + iterator);
141
                        blk.add(lastEntity);
142
                        //System.out.println("PLINE color="+polyline.getColor());
143
                }
144
                lastEntity = null;
145
                xtruX = 0.0;
146
                xtruY = 0.0;
147
                xtruZ = 1.0;
148
                bulge = 0.0;
149
        }
150
        
151
        public void addVertex(DxfGroupVector grp) throws Exception {
152
                double x = 0.0, y = 0.0, z = 0.0;
153
                int flags = 0;
154
                x  = grp.getDataAsDouble(10);
155
                y  = grp.getDataAsDouble(20);
156
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
157
                if (grp.hasCode(70)) {
158
                        flags = grp.getDataAsInt(70);
159
                }
160
                //bulge = 0.0;
161
                if (bulge == 0.0) {
162
                        if (grp.hasCode(42)) {
163
                                bulge = grp.getDataAsDouble(42);
164
                                //bulge = 0.0;
165
                        } else { bulge = 0.0; }
166
                        Point3D point_in = new Point3D(x, y, z);
167
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
168
                        Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
169
                        if ((flags & 0x80) == 0x80 && (flags & 0x40) == 0) {
170
                                int [] face = {0,0,0,0};
171
                                face[0] = grp.getDataAsInt(71);
172
                                face[1] = grp.getDataAsInt(72);
173
                                face[2] = grp.getDataAsInt(73);
174
                                face[3] = grp.getDataAsInt(74);
175
                                ((DxfPolyline) lastEntity).addFace(face);
176
                        } else {
177
                                x = point_out.getX();
178
                                y = point_out.getY();
179
                                Point2D pt = proj.createPoint( x, y);
180
                                ((DxfPolyline) lastEntity).add(pt);
181
                                if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
182
                        }
183
                } else if (bulge > 0.0) {
184
                        double bulge_aux = 0.0;
185
                        if (grp.hasCode(42)) {
186
                                bulge_aux = grp.getDataAsDouble(42);
187
                        } else { bulge_aux = 0.0; }
188
                        Point3D point_in = new Point3D(x, y, z);
189
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
190
                        Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
191
                        x = point_out.getX();
192
                        y = point_out.getY();
193
                        Point2D pt = proj.createPoint( x, y);
194
                        ((DxfPolyline) lastEntity).add(pt);
195
                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
196
                        int cnt = ((DxfPolyline) lastEntity).pts.size();
197
                        Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
198
                        ((DxfPolyline) lastEntity).pts.remove(cnt-1);
199
                        for (int i=0; i<arc.size(); i++) {
200
                                pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
201
                                ((DxfPolyline) lastEntity).add(pt);
202
                                if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
203
                        }
204
                        bulge = bulge_aux;
205
                } else { //si el bulge es menor que cero.
206
                        double bulge_aux = 0.0;
207
                        if (grp.hasCode(42)) {
208
                                bulge_aux = grp.getDataAsDouble(42); // * (-1.0);
209
                        } else { bulge_aux = 0.0; }
210
                        Point3D point_in = new Point3D(x, y, z);
211
                        Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
212
                        Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
213
                        x = point_out.getX();
214
                        y = point_out.getY();
215
                        Point2D pt = proj.createPoint( x, y);
216
                        ((DxfPolyline) lastEntity).add(pt);
217
                        if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
218
                        int cnt = ((DxfPolyline) lastEntity).pts.size();
219
                        Vector arc = DxfPolyline.createArc((Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-2)), (Point2D)(((DxfPolyline) lastEntity).pts.get(cnt-1)), bulge);
220
                        ((DxfPolyline) lastEntity).pts.remove(cnt-1);
221
                        for (int i=0; i<arc.size(); i++) {
222
                                pt = proj.createPoint(((Point2D)arc.get(i)).getX(), ((Point2D)arc.get(i)).getY());
223
                                ((DxfPolyline) lastEntity).add(pt);
224
                                if (((DxfPolyline)lastEntity).pts.size() == 1) firstPt = pt;
225
                        }
226
                        bulge = bulge_aux;                        
227
                }
228
                /*if (grp.hasCode(5)) {
229
                        String hexS = grp.getDataAsString(5);
230
                        Integer hexI = Integer.decode("0x" + hexS);
231
                        int hexi = hexI.intValue();
232
                        lastEntity.setHandle(hexi);
233
                } else {
234
                        lastEntity.setHandle(entities.size()+40);
235
                }*/
236
        }
237
        
238
        public void createLwPolyline(DxfGroupVector grp) throws Exception {
239
                double x = 0.0, y = 0.0, elev=0.0;
240
                DxfGroup g = null;
241
                
242
                if (grp.hasCode(38))
243
                        elev = grp.getDataAsDouble(38);
244
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
245
                DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
246
                if (grp.hasCode(5)) {
247
                        String hexS = grp.getDataAsString(5);
248
                        Integer hexI = Integer.decode("0x" + hexS);
249
                        int hexi = hexI.intValue();
250
                        entity.setHandle(hexi);
251
                } else {
252
                        entity.setHandle(entities.size()+40);
253
                }
254
                double bulge = 0;
255
                boolean isNewCoord = false;
256
                for (int i=0; i<grp.size(); i++) {
257
                        bulge = 0;
258
                        isNewCoord = false;
259
                        g = (DxfGroup) grp.get(i);
260
                        if (g.getCode() == 10) {
261
                                x = ((Double) g.getData()).doubleValue();
262
                        } else if (g.getCode() == 20) {
263
                                y = ((Double) g.getData()).doubleValue();
264
                                //if (y <= 1.0) throw new Exception("Y == "+y);
265
                                entity.add( proj.createPoint( x, y ) );
266
                                entity.addBulge(new Double(0));
267
                                x = 0.0; y = 0.0;
268
                                isNewCoord = true;
269
                        } else if (g.getCode() == 42) {
270
                                //entity.addBulge((Double)g.getData());
271
                                entity.getBulges().remove(entity.getBulges().size()-1);
272
                                entity.getBulges().add((Double)g.getData());
273
                                bulge = ((Double) g.getData()).doubleValue();
274
                        }
275
                        /*if (bulge == 0 && isNewCoord) {
276
                                entity.addBulge(new Double(0));
277
                        }*/
278
                }
279
                System.out.println("entity.getPts().size() = " + entity.getPts().size());
280
                System.out.println("entity.getBulges().size() = " + entity.getBulges().size());
281
                if (grp.hasCode(62)) {
282
                        entity.dxfColor = grp.getDataAsInt(62);
283
                } else {
284
                        //entity.dxfColor = 0;
285
                }
286
                if (grp.hasCode(70)) {
287
                        entity.flags = grp.getDataAsInt(70);
288
                        System.out.println("entity.flags = " + entity.flags);
289
                }
290
                if ((entity.flags & 0x01) == 0x01) {
291
                        entity.closed = true;
292
                }
293
                if (addingToBlock == false) {
294
                        entities.add(entity);
295
                } else {
296
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
297
                        blk.add(entity);
298
                }
299
        }
300
        public void createLine(DxfGroupVector grp) throws Exception {
301
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0;
302
                DxfGroup g = null;
303
                Point2D pt1 = null, pt2 = null;
304
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
305

    
306
                x = grp.getDataAsDouble(10);
307
                y = grp.getDataAsDouble(20);
308
                if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30);
309
                pt1 = proj.createPoint(x, y);
310
                x = grp.getDataAsDouble(11);
311
                y = grp.getDataAsDouble(21);
312
                if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31);
313
                pt2 = proj.createPoint(x, y);
314
                if (grp.hasCode(210))
315
                        xtruX = grp.getDataAsDouble(210);
316
                if (grp.hasCode(220))
317
                        xtruY = grp.getDataAsInt(220);
318
                if (grp.hasCode(230))
319
                        xtruZ = grp.getDataAsInt(230);
320
                Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
321
                Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
322
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
323
                Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
324
                Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
325
                pt1.setLocation(point_out1);
326
                pt2.setLocation(point_out2);
327
                DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
328
                if (grp.hasCode(5)) {
329
                        String hexS = grp.getDataAsString(5);
330
                        Integer hexI = Integer.decode("0x" + hexS);
331
                        int hexi = hexI.intValue();
332
                        entity.setHandle(hexi);
333
                } else {
334
                        entity.setHandle(entities.size()+40);
335
                }
336
                if (grp.hasCode(62)) {
337
                        entity.dxfColor = grp.getDataAsInt(62);
338
                } else {
339
                        //entity.dxfColor = 0;
340
                }
341
                if (addingToBlock == false) {
342
                        //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
343
                        entities.add(entity);
344
                } else {
345
                        //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
346
                        blk.add(entity);
347
                }
348
        }
349
        public void createText(DxfGroupVector grp) throws Exception {
350
                double x = 0.0, y = 0.0, h= 0.0, rot= 0.0;
351
                DxfGroup g = null;
352
                Point2D pt1 = null, pt2 = null;
353
                String txt = null;
354
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
355

    
356
                txt = grp.getDataAsString(1);
357
                DxfText entity = new DxfText(proj, layer, txt);
358

    
359
                x = grp.getDataAsDouble(10);
360
                y = grp.getDataAsDouble(20);
361
                entity.setPt1(proj.createPoint(x, y));
362
                if (grp.hasCode(11)) {
363
                        x = grp.getDataAsDouble(11);
364
                        y = grp.getDataAsDouble(21);
365
                        entity.setPt2(proj.createPoint(x, y));
366
                }
367
                entity.setHeight(grp.getDataAsDouble(40));
368
                if (grp.hasCode(50)) {
369
                        entity.setRotation(grp.getDataAsDouble(50));                        
370
                        //System.out.println("AAAAAA: entity.getRotation = " + entity.getRotation());
371
                }
372
                if (grp.hasCode(62)) {
373
                        entity.dxfColor = grp.getDataAsInt(62);
374
                } else {
375
                        //entity.dxfColor = 0;
376
                }
377
                if (grp.hasCode(72))
378
                        entity.align = grp.getDataAsInt(72);
379
                if (addingToBlock == false) {
380
                        entities.add(entity);
381
                } else {
382
                        //System.out.println("createText(): A?adimos un text al bloque " + iterator);
383
                        blk.add(entity);
384
                }
385
        }
386
        /* (non-Javadoc)
387
         * @see org.cresques.io.DxfFile.EntityFactory#createMText(org.cresques.io.DxfGroupVector)
388
         */
389
        public void createMText(DxfGroupVector v) throws Exception {
390
                // TODO Auto-generated method stub
391
                
392
        }
393
        public void createPoint(DxfGroupVector grp) throws Exception {
394
                double x = 0.0, y = 0.0, z = 0.0; //, h= 0.0, rot= 0.0;
395
                DxfGroup g = null;
396
                Point2D pt = null;
397
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
398

    
399
                DxfPoint entity = new DxfPoint(proj, layer);
400
                
401
                if (grp.hasCode(5)) {
402
                        String hexS = grp.getDataAsString(5);
403
                        Integer hexI = Integer.decode("0x" + hexS);
404
                        int hexi = hexI.intValue();
405
                        entity.setHandle(hexi);
406
                } else {
407
                        entity.setHandle(entities.size()+40);
408
                }
409

    
410
                x = grp.getDataAsDouble(10);
411
                y = grp.getDataAsDouble(20);
412
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
413
                if (grp.hasCode(62)) {
414
                        entity.dxfColor = grp.getDataAsInt(62);
415
                } else {
416
                        //entity.dxfColor = 0;
417
                }
418
                if (grp.hasCode(210))
419
                        xtruX = grp.getDataAsDouble(210);
420
                if (grp.hasCode(220))
421
                        xtruY = grp.getDataAsInt(220);
422
                if (grp.hasCode(230))
423
                        xtruZ = grp.getDataAsInt(230);
424
                Point3D point_in = new Point3D(x, y, z);
425
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
426
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
427
                x = point_out.getX();
428
                y = point_out.getY();
429
                entity.setPt(proj.createPoint(x, y));
430
                if (addingToBlock == false) {
431
                        entities.add(entity);
432
                } else {
433
                        //System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
434
                        blk.add(entity);
435
                }
436
        }
437
        public void createCircle(DxfGroupVector grp) throws Exception {
438
                double x = 0.0, y = 0.0, z = 0.0;
439
                double r = 0.0;
440
                DxfGroup g = null;
441
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
442

    
443
                x = grp.getDataAsDouble(10);
444
                y = grp.getDataAsDouble(20);
445
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
446
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
447
                if (grp.hasCode(210))
448
                        xtruX = grp.getDataAsDouble(210);
449
                if (grp.hasCode(220))
450
                        xtruY = grp.getDataAsDouble(220);
451
                if (grp.hasCode(230))
452
                        xtruZ = grp.getDataAsDouble(230);
453
                Point3D point_in = new Point3D(x, y, z);
454
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
455
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
456
                x = point_out.getX();
457
                y = point_out.getY();
458
                
459
                Point2D center = proj.createPoint( x, y);
460
                Point2D[] pts = new Point2D[360];
461
                int angulo = 0;
462
                for (angulo=0; angulo<360; angulo++) {
463
                        pts[angulo] = new Point2D.Double(center.getX(), center.getY());
464
                        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));
465
                        if (pts.length == 1) {
466
                                firstPt = pts[angulo];
467
                        }
468
                }
469
                DxfCircle entity = new DxfCircle(proj, layer, pts);
470
                if (grp.hasCode(5)) {
471
                        String hexS = grp.getDataAsString(5);
472
                        Integer hexI = Integer.decode("0x" + hexS);
473
                        int hexi = hexI.intValue();
474
                        entity.setHandle(hexi);
475
                } else {
476
                        entity.setHandle(entities.size()+40);
477
                }
478
                entity.setCenter(new Point2D.Double(x,y));
479
                entity.setRadius(r);
480
                if (grp.hasCode(62)) {
481
                        entity.dxfColor = grp.getDataAsInt(62);
482
                } else {
483
                        //entity.dxfColor = 0;
484
                }
485
                if (addingToBlock == false) {
486
                        //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
487
                        entities.add(entity);
488
                } else {
489
                        //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
490
                        blk.add(entity);
491
                }
492
        }
493
        public void createEllipse(DxfGroupVector grp) throws Exception {
494
                double incX = 0.0, incY = 0.0, incZ = 0.0;
495
                double xc = 0.0, yc = 0.0, zc = 0.0;
496
                double mMAxisRatio = 0.0;
497
                DxfGroup g = null;
498
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
499

    
500
                xc = grp.getDataAsDouble(10);
501
                yc = grp.getDataAsDouble(20);
502
                if (grp.hasCode(30)) zc = grp.getDataAsDouble(30);
503
                incX = grp.getDataAsDouble(11);
504
                incY = grp.getDataAsDouble(21);
505
                if (grp.hasCode(30)) incZ = grp.getDataAsDouble(31);
506
                if (grp.hasCode(40)) mMAxisRatio = grp.getDataAsDouble(40);
507
                
508
                Point2D pt2 = new Point2D.Double(xc+incX, yc+incY);
509
                Point2D pt1 = new Point2D.Double(xc-incX, yc-incY);
510
                double majorAxisLength = pt1.distance(pt2);
511
                double minorAxisLength = majorAxisLength*mMAxisRatio;
512
                
513
                DxfEllipse entity = new DxfEllipse(proj, layer, pt1, pt2, minorAxisLength);
514
                if (grp.hasCode(5)) {
515
                        String hexS = grp.getDataAsString(5);
516
                        Integer hexI = Integer.decode("0x" + hexS);
517
                        int hexi = hexI.intValue();
518
                        entity.setHandle(hexi);
519
                } else {
520
                        entity.setHandle(entities.size()+40);
521
                }
522
                if (grp.hasCode(62)) {
523
                        entity.dxfColor = grp.getDataAsInt(62);
524
                } else {
525
                        //entity.dxfColor = 0;
526
                }
527
                if (addingToBlock == false) {
528
                        //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
529
                        entities.add(entity);
530
                } else {
531
                        //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
532
                        blk.add(entity);
533
                }
534
        }
535
        public void createArc(DxfGroupVector grp) throws Exception {
536
                double x = 0.0, y = 0.0, z = 0.0;
537
                double r = 0.0, empieza = 0.0, acaba = 0.0;
538
                DxfGroup g = null;
539
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
540

    
541
                x = grp.getDataAsDouble(10);
542
                y = grp.getDataAsDouble(20);
543
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
544
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
545
                if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50);
546
                if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51);
547
                if (grp.hasCode(210))
548
                        xtruX = grp.getDataAsDouble(210);
549
                if (grp.hasCode(220))
550
                        xtruY = grp.getDataAsDouble(220);
551
                if (grp.hasCode(230))
552
                        xtruZ = grp.getDataAsDouble(230);
553
                Point3D point_in = new Point3D(x, y, z);
554
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
555
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
556
                x = point_out.getX();
557
                y = point_out.getY();
558
                
559
                Point2D center = proj.createPoint( x, y);
560
                //System.out.println("empieza = " + empieza + ", acaba = " + acaba);
561
                int iempieza = (int)empieza;
562
                int iacaba = (int)acaba;
563
                //System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
564
                double angulo = 0;
565
                Point2D[] pts = null;
566
                if (empieza <= acaba) {
567
                        pts = new Point2D[(iacaba-iempieza)+2];
568
                        angulo = empieza;
569
                        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));
570
                        for (int i=1; i<=(iacaba-iempieza)+1; i++) {
571
                                angulo = (double)(iempieza+i);
572
                                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));
573
                        }
574
                        angulo = acaba;
575
                        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));
576
                } else {
577
                        pts = new Point2D[(360-iempieza)+iacaba+2];
578
                        angulo = empieza;
579
                        //System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
580
                        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));
581
                        for (int i=1; i<=(360-iempieza); i++) {
582
                                angulo = (double)(iempieza+i);
583
                                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));
584
                        }
585
                        for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) {
586
                                angulo = (double)(i-(360-iempieza));
587
                                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));
588
                        }
589
                        angulo = acaba;
590
                        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));
591
                }
592
                DxfArc entity = new DxfArc(proj, layer, pts);
593
                if (grp.hasCode(5)) {
594
                        String hexS = grp.getDataAsString(5);
595
                        Integer hexI = Integer.decode("0x" + hexS);
596
                        int hexi = hexI.intValue();
597
                        entity.setHandle(hexi);
598
                } else {
599
                        entity.setHandle(entities.size()+40);
600
                }
601
                // 050223, jmorell: Establecimiento de los par?metros del arco.
602
                entity.setCentralPoint(pts[(pts.length)/2]);
603
                entity.setInit(pts[0]);
604
                entity.setEnd(pts[pts.length-1]);
605
                entity.setCenter(center);
606
                entity.setRadius(r);
607
                entity.setInitAngle(empieza);
608
                entity.setEndAngle(acaba);
609
                if (grp.hasCode(62)) {
610
                        entity.dxfColor = grp.getDataAsInt(62);
611
                } else {
612
                        //entity.dxfColor = 0;
613
                }
614
                //System.out.println("createArc(): A?adimos un arco al bloque");
615
                if (addingToBlock == false) {
616
                        entities.add(entity);
617
                } else {
618
                        //System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
619
                        blk.add(entity);
620
                }
621
        }
622
        
623
        /**
624
         * TODO Detectados fallos en las rotaciones de bloques. Hoja 72231.
625
         *      Detectado en los bloques correspondientes a campos de futbol,
626
         *      de tipo solid.
627
         */
628
        public void createInsert(DxfGroupVector grp) throws Exception {
629
                double x = 0.0, y = 0.0, z = 0.0;
630
                DxfGroup g = null;
631
                Point2D pt = new Point2D.Double(0.0, 0.0);
632
                Point2D scaleFactor = new Point2D.Double(1.0, 1.0);
633
                double rotAngle = 0.0;
634
                String blockName = "";
635
                
636
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
637
                
638
                DxfInsert entity = new DxfInsert(proj, layer);
639
                DxfPoint secondEntity = new DxfPoint(proj, layer);
640

    
641
                if (grp.hasCode(2)) {
642
                        blockName = grp.getDataAsString(2);
643
                        entity.setBlockName(blockName);
644
                }
645
                if (grp.hasCode(10)) x = grp.getDataAsDouble(10);
646
                if (grp.hasCode(20)) y = grp.getDataAsDouble(20);
647
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
648
                if (grp.hasCode(41)) {
649
                        scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
650
                        entity.setScaleFactor(scaleFactor);
651
                } else {
652
                        entity.setScaleFactor(scaleFactor);                        
653
                }
654
                if (grp.hasCode(42)) {
655
                        scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
656
                        entity.setScaleFactor(scaleFactor);
657
                } else {
658
                        entity.setScaleFactor(scaleFactor);
659
                }
660
                if (grp.hasCode(43)) {
661
                        // TODO La coordenada z
662
                }
663
                if (grp.hasCode(50)) {
664
                        rotAngle = grp.getDataAsDouble(50);
665
                        entity.setRotAngle(rotAngle);
666
                }
667
                if (grp.hasCode(62)) {
668
                        entity.dxfColor = grp.getDataAsInt(62);
669
                } else {
670
                        //entity.dxfColor = 0;
671
                }
672
                if (grp.hasCode(210))
673
                        xtruX = grp.getDataAsDouble(210);
674
                if (grp.hasCode(220))
675
                        xtruY = grp.getDataAsDouble(220);
676
                if (grp.hasCode(230))
677
                        xtruZ = grp.getDataAsDouble(230);
678
                Point3D point_in = new Point3D(x, y, z);
679
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
680
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
681
                x = point_out.getX();
682
                y = point_out.getY();
683
                                
684
                entity.setBlkList(blkList);
685
                                
686
                entity.encuentraBloque(blockName);
687
                
688
                entity.setPt(proj.createPoint(x, y));
689
                secondEntity.setPt(proj.createPoint(x, y));
690
                
691
                gestionaInsert(entity, layer);
692
                
693
                //System.out.println("createInsert: entity.getBlockName = " + entity.getBlockName());
694
                //System.out.println("createInsert: entity.getRotAngle = " + entity.getRotAngle());
695
                
696
                if (addingToBlock == false) {
697
                        entities.add(secondEntity);
698
                } else if (addingToBlock == true && entity.blockFound == true) {
699
                        //System.out.println("createArc(): A?adimos un insert al bloque " + iterator);
700
                        blk.add(entity);
701
                }
702
        }
703
        
704
        public void createSolid(DxfGroupVector grp) throws Exception {
705
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0;
706
                DxfGroup g = null;
707
                //Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
708
                Point2D[] pts = new Point2D[4];
709
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
710

    
711
                x = grp.getDataAsDouble(10);
712
                y = grp.getDataAsDouble(20);
713
                if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30);
714
                pts[0] = proj.createPoint(x, y);
715
                x = grp.getDataAsDouble(11);
716
                y = grp.getDataAsDouble(21);
717
                if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31);
718
                pts[1] = proj.createPoint(x, y);
719
                x = grp.getDataAsDouble(12);
720
                y = grp.getDataAsDouble(22);
721
                if (grp.hasCode(32)) z3 = grp.getDataAsDouble(32);
722
                pts[2] = proj.createPoint(x, y);
723
                x = grp.getDataAsDouble(13);
724
                y = grp.getDataAsDouble(23);
725
                if (grp.hasCode(33)) z2 = grp.getDataAsDouble(33);
726
                pts[3] = proj.createPoint(x, y);
727
                if (grp.hasCode(210))
728
                        xtruX = grp.getDataAsDouble(210);
729
                if (grp.hasCode(220))
730
                        xtruY = grp.getDataAsDouble(220);
731
                if (grp.hasCode(230))
732
                        xtruZ = grp.getDataAsDouble(230);
733
                Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1);
734
                Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2);
735
                Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3);
736
                Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4);
737
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
738
                Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
739
                Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
740
                Point2D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
741
                Point2D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
742
                pts[0].setLocation(point_out1);
743
                pts[1].setLocation(point_out2);
744
                pts[2].setLocation(point_out3);
745
                pts[3].setLocation(point_out4);
746
                DxfSolid entity = new DxfSolid(proj, layer, pts);
747
                if (grp.hasCode(62)) {
748
                        entity.dxfColor = grp.getDataAsInt(62);
749
                } else {
750
                        //entity.dxfColor = 0;
751
                }
752
                if (addingToBlock == false) {
753
                        //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
754
                        entities.add(entity);
755
                } else {
756
                        //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
757
                        blk.add(entity);
758
                }
759
        }
760
        /**
761
         * Los Splines estan implementados como LwPolylines. Se pintan las lineas
762
         * entre los vertices pero no se aplica la curvatura Spline.
763
         * TODO Contemplar la curvatura spline para Splines.
764
         */
765
        public void createSpline(DxfGroupVector grp) throws Exception {
766
                double x = 0.0, y = 0.0, elev=0.0;
767
                DxfGroup g = null;
768
                
769
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
770
                DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
771
                for (int i=0; i<grp.size(); i++) {
772
                        g = (DxfGroup) grp.get(i);
773
                        if (g.getCode() == 10)
774
                                x = ((Double) g.getData()).doubleValue();
775
                        else if (g.getCode() == 20) {
776
                                y = ((Double) g.getData()).doubleValue();
777
                                //if (y <= 1.0) throw new Exception("Y == "+y);
778
                                entity.add( proj.createPoint( x, y ) );
779
                                x = 0.0; y = 0.0;
780
                        }
781
                }
782
                if (grp.hasCode(62)) {
783
                        entity.dxfColor = grp.getDataAsInt(62);
784
                } else {
785
                        //entity.dxfColor = 0;
786
                }
787
                if (grp.hasCode(70))
788
                        entity.flags = grp.getDataAsInt(70);
789
                if ((entity.flags & 0x01) == 0x01) {
790
                        entity.closed = true;
791
                }
792
                if (addingToBlock == false) {
793
                        entities.add(entity);
794
                } else {
795
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
796
                        blk.add(entity);
797
                }
798
        }
799
        public void createBlock(DxfGroupVector grp) throws Exception {
800
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
801
                blk = new DxfBlock(proj);
802
                
803
                Point2D basePoint = new Point2D.Double();
804
                String blockName = "";
805
                //System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
806
                
807
                addingToBlock = true;
808
                //System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
809
                blkList.add(iterator, blk);
810
                
811
                //System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
812
                if (grp.hasCode(1)) {
813
                        blockName = grp.getDataAsString(1);
814
                        blk.setBlkName(blockName);
815
                }
816
                if (grp.hasCode(2)) {
817
                        blockName = grp.getDataAsString(2);
818
                        blk.setBlkName(blockName);
819
                }
820
                if (grp.hasCode(3)) {
821
                        blockName = grp.getDataAsString(3);
822
                        blk.setBlkName(blockName);
823
                }
824
                if (grp.hasCode(10)) {
825
                        basePoint.setLocation(grp.getDataAsDouble(10), basePoint.getY());
826
                        blk.setBPoint(basePoint);
827
                }
828
                if (grp.hasCode(20)) {
829
                        basePoint.setLocation(basePoint.getX(), grp.getDataAsDouble(20));
830
                        blk.setBPoint(basePoint);
831
                }
832
                if (grp.hasCode(30)) {
833
                        // TODO Contemplar la coordenada z
834
                }
835
                if (grp.hasCode(70)) {
836
                        blk.flags = grp.getDataAsInt(70);                        
837
                }
838
        }
839
        public void endBlk(DxfGroupVector grp) throws Exception {
840
                //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
841
                setAddingToBlock(false);
842
                iterator = iterator + 1;
843
        }
844

    
845
        public void testBlocks() {
846
                Vector blkList = getBlkList();
847
                DxfBlock dxfBlock = null;
848
                DxfEntity dxfEntity = null;
849
                DxfLine dxfLine = null;
850
                DxfInsert dxfInsert = null;
851
                Point2D point1 = new Point2D.Double();
852
                Point2D point2 = new Point2D.Double();
853
                for (int i=0; i<blkList.size(); i++) {
854
                        dxfBlock = (DxfBlock)blkList.get(i);
855
                        int aux = dxfBlock.getBlkElements().size();
856
                        for (int j=0; j<aux; j++) {
857
                                dxfEntity = (DxfEntity)dxfBlock.getBlkElements().get(j);
858
                                if (dxfEntity instanceof DxfLine) {
859
                                        dxfLine = (DxfLine)dxfEntity;
860
                                        point1 = dxfLine.getPts()[0];
861
                                        point2 = dxfLine.getPts()[1];
862
                                        //System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", vertice1 = " + point1 + ", vertice2 = " + point2);
863
                                } else if (dxfEntity instanceof DxfInsert){
864
                                        dxfInsert = (DxfInsert)dxfEntity;
865
                                        String nomBlock = dxfInsert.getBlockName();
866
                                        //System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", inserta el bloque = " + nomBlock);
867
                                        //System.out.println("compruebaBloques(): dxfInsert.pt = " + dxfInsert.getPt());
868
                                        //System.out.println("compruebaBloques(): dxfInsert.rotAngle = " + dxfInsert.getRotAngle());
869
                                        //System.out.println("compruebaBloques(): dxfInsert.scaleFactor = " + dxfInsert.getScaleFactor());
870
                                        
871
                                        if (dxfInsert.getBlockFound() == false) {
872
                                                //System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock);
873
                                                boolean aux_bool = dxfInsert.encuentraBloque(nomBlock);
874
                                                gestionaInsert(dxfInsert, dxfInsert.getDxfLayer());
875
                                                dxfBlock.add(dxfInsert);
876
                                        }
877
                                        
878
                                }
879
                        }
880
                }
881
        }
882
        
883
        public void setProjection(IProjection proj) { this.proj = proj;}
884
        public IProjection getProjection() { return proj;}
885

    
886
        public void reProject(ICoordTrans rp) {
887
                entities.reProject(rp);
888
                setProjection(rp.getPDest());
889
        }
890
        
891
        public DxfEntityList getEntities() { return entities;}
892
        public DxfTable getLayers() { return layers;}
893
        
894
        public DxfBlock getBlk() {
895
                return blk;
896
        }
897
        
898
        public void gestionaInsert(DxfInsert entity, DxfLayer layer) {
899
                DxfEntity dxfEntity = null;
900
                DxfLine dxfLine = null;
901
                DxfInsert dxfInsert = null;
902
                DxfPolyline dxfPolyline = null;
903
                DxfArc dxfArc = null;
904
                DxfCircle dxfCircle = null;
905
                DxfLwPolyline dxfLwPolyline = null;
906
                DxfPoint dxfPoint = null;
907
                DxfText dxfText = null;
908
                DxfSolid dxfSolid = null;
909
                for (int i=0; i<entity.block.size(); i++) {
910
                        //System.out.println("gestionaInserts: entity.block.blkElements.size() = " + entity.block.blkElements.size());
911
                        dxfEntity = (DxfEntity)entity.block.get(i);
912
                        
913
                        Point2D point1 = new Point2D.Double();
914
                        Point2D point2 = new Point2D.Double();
915
                        Point2D point11 = new Point2D.Double();
916
                        Point2D point22 = new Point2D.Double();
917
                        if (dxfEntity instanceof DxfLine) {
918
                                dxfLine = (DxfLine)dxfEntity;
919
                                point1 = dxfLine.getPts()[0];
920
                                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());
921
                                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());
922
                                point11.setLocation(laX, laY);
923
                                point2 = dxfLine.getPts()[1];
924
                                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()));
925
                                DxfLine dxfLinee = new DxfLine(proj, layer, point11, point22);
926
                                if (addingToBlock == false) {
927
                                        entities.add(dxfLinee);
928
                                }
929
                        } else if (dxfEntity instanceof DxfInsert){
930
                                dxfInsert = (DxfInsert)dxfEntity;
931
                                point1 = dxfInsert.pt;
932
                                //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()));
933
                                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()));
934
                                DxfInsert dxfInsertt = new DxfInsert(proj, layer);
935
                                
936
                                dxfInsertt.pt = point11;
937
                                
938
                                dxfInsertt.blkList = dxfInsert.blkList;
939
                                dxfInsertt.block = dxfInsert.block;
940
                                dxfInsertt.blockName = dxfInsert.blockName;
941
                                dxfInsertt.layer = dxfInsert.layer;
942
                                dxfInsertt.proj = dxfInsert.proj;
943
                                dxfInsertt.rotAngle = dxfInsert.rotAngle; // * entity.rotAngle;
944

    
945
                                dxfInsertt.scaleFactor = new Point2D.Double(dxfInsert.scaleFactor.getX() * entity.scaleFactor.getX(), dxfInsert.scaleFactor.getY() * entity.scaleFactor.getY());
946
                                
947
                                gestionaInsert(dxfInsertt, layer);
948
                        } else if (dxfEntity instanceof DxfPolyline) {
949
                                dxfPolyline = (DxfPolyline)dxfEntity;
950
                                DxfPolyline dxfPolylinee = new DxfPolyline(proj, layer);
951
                                if (dxfPolyline.closed) dxfPolylinee.closed = true;
952
                                Point2D[] points = new Point2D[dxfPolyline.pts.size()];
953
                                Point2D[] pointss = new Point2D[dxfPolyline.pts.size()];
954
                                for (int j=0; j<dxfPolyline.pts.size(); j++) {
955
                                        points[j] = (Point2D)dxfPolyline.pts.get(j);
956
                                        pointss[j] = new Point2D.Double();                                        
957
                                        //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()));
958
                                        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()));
959
                                        //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()));
960
                                        dxfPolylinee.add(pointss[j]);
961
                                }
962
                                if (addingToBlock == false) entities.add(dxfPolylinee);
963
                        } else if (dxfEntity instanceof DxfArc) {
964
                                dxfArc = (DxfArc)dxfEntity;
965
                                Point2D[] points = new Point2D[dxfArc.pts.length];
966
                                Point2D[] pointss = new Point2D[dxfArc.pts.length];
967
                                for (int j=0; j<dxfArc.pts.length; j++) {
968
                                        points[j] = (Point2D)dxfArc.pts[j];
969
                                        pointss[j] = new Point2D.Double();
970
                                        //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()));
971
                                        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()));
972
                                        //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()));
973
                                }
974
                                DxfArc dxfArcc = new DxfArc(proj, layer, pointss);
975
                                if (addingToBlock == false) entities.add(dxfArcc);
976
                        } else if (dxfEntity instanceof DxfCircle) {
977
                                dxfCircle = (DxfCircle)dxfEntity;
978
                                Point2D[] points = new Point2D[dxfCircle.pts.length];
979
                                Point2D[] pointss = new Point2D[dxfCircle.pts.length];
980
                                for (int j=0; j<dxfCircle.pts.length; j++) {
981
                                        points[j] = (Point2D)dxfCircle.pts[j];
982
                                        pointss[j] = new Point2D.Double();
983
                                        //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()));
984
                                        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()));
985
                                        //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()));
986
                                }
987
                                DxfCircle dxfCirclee = new DxfCircle(proj, layer, pointss);
988
                                if (addingToBlock == false) entities.add(dxfCirclee);
989
                        } else if (dxfEntity instanceof DxfLwPolyline) {
990
                                dxfLwPolyline = (DxfLwPolyline)dxfEntity;
991
                                DxfLwPolyline dxfLwPolylinee = new DxfLwPolyline(proj, layer);
992
                                Point2D[] points = new Point2D[dxfLwPolyline.pts.size()];
993
                                Point2D[] pointss = new Point2D[dxfLwPolyline.pts.size()];
994
                                for (int j=0; j<dxfLwPolyline.pts.size(); j++) {
995
                                        points[j] = (Point2D)dxfLwPolyline.pts.get(j);
996
                                        pointss[j] = new Point2D.Double();                                        
997
                                        //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()));
998
                                        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()));
999
                                        //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() - (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()));
1000
                                        dxfLwPolylinee.add(pointss[j]);
1001
                                }
1002
                                if (addingToBlock == false) entities.add(dxfLwPolylinee);
1003
                        } else if (dxfEntity instanceof DxfPoint) {
1004
                                dxfPoint = (DxfPoint)dxfEntity;
1005
                                point1 = dxfPoint.getPt();
1006
                                //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()));
1007
                                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()));
1008
                                //point11.setLocation(entity.pt.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() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1009
                                DxfPoint dxfPointt = new DxfPoint(proj, layer);
1010
                                //dxfPointt.pt = point11;
1011
                                dxfPointt.setPt(point11);
1012
                                if (addingToBlock == false) entities.add(dxfPointt);
1013
                        } else if (dxfEntity instanceof DxfText) {
1014
                                dxfText = (DxfText)dxfEntity;
1015
                                point1 = dxfText.pts[0];
1016
                                //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()));
1017
                                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()));
1018
                                //point11.setLocation(entity.pt.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() + ((point1.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point1.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1019
                                point2 = dxfText.pts[1];
1020
                                //point22.setLocation(entity.pt.getX() - entity.block.bPoint.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() + ((point2.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point2.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1021
                                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()));
1022
                                //point22.setLocation(entity.pt.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() + ((point2.getX()*Math.sin((entity.rotAngle*Math.PI)/180.0) + point2.getY()*Math.cos((entity.rotAngle*Math.PI)/180.0)) * entity.scaleFactor.getY()));
1023
                                DxfText dxfTextt = new DxfText(proj, layer, dxfText.getText());
1024
                                dxfTextt.pts[0] = point11;
1025
                                dxfTextt.pts[1] = point22;
1026
                                if (addingToBlock == false) entities.add(dxfTextt);
1027
                        } else if (dxfEntity instanceof DxfSolid) {
1028
                                dxfSolid = (DxfSolid)dxfEntity;
1029
                                Point2D[] points = new Point2D[dxfSolid.pts.length];
1030
                                Point2D[] pointss = new Point2D[dxfSolid.pts.length];
1031
                                for (int j=0; j<dxfSolid.pts.length; j++) {
1032
                                        points[j] = (Point2D)dxfSolid.pts[j];
1033
                                        pointss[j] = new Point2D.Double();
1034
                                        //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()));
1035
                                        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()));
1036
                                        //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()));
1037
                                }
1038
                                DxfSolid dxfSolidd = new DxfSolid(proj, layer, pointss);
1039
                                Point2D aux = dxfSolidd.pts[2];
1040
                                dxfSolidd.pts[2] = dxfSolidd.pts[3];
1041
                                dxfSolidd.pts[3] = aux;
1042
                                if (addingToBlock == false) entities.add(dxfSolidd);
1043
                        } else {
1044
                                System.out.println("gestionaInserts: Encontrado elemento desconocido");
1045
                        }
1046
                }
1047
        }
1048

    
1049
        /* (non-Javadoc)
1050
         * @see org.cresques.io.DxfFile.EntityFactory#createAttdef(org.cresques.io.DxfGroupVector)
1051
         */
1052
        public void createAttdef(DxfGroupVector v) throws Exception {
1053
                // TODO Auto-generated method stub
1054
                
1055
        }
1056

    
1057
        /* (non-Javadoc)
1058
         * @see org.cresques.io.DxfFile.EntityFactory#createAttrib(org.cresques.io.DxfGroupVector)
1059
         */
1060
        public void createAttrib(DxfGroupVector v) throws Exception {
1061
                // TODO Auto-generated method stub
1062
                
1063
        }
1064

    
1065
        /* (non-Javadoc)
1066
         * @see org.cresques.io.DxfFile.EntityFactory#getAttributes()
1067
         */
1068
        public Vector getAttributes() {
1069
                // TODO Auto-generated method stub
1070
                return null;
1071
        }
1072

    
1073
        /* (non-Javadoc)
1074
         * @see org.cresques.io.DxfFile.EntityFactory#depureAttributes()
1075
         */
1076
        public void depureAttributes() {
1077
                // TODO Auto-generated method stub
1078
                
1079
        }
1080
        
1081
}