Statistics
| Revision:

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

History | View | Annotate | Download (43.5 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
//import org.cresques.px.gml.Feature;
17

    
18
public class DxfEntityMaker implements DxfFile.EntityFactory, Projected {
19
        IProjection proj = null;
20
        DxfEntity lastEntity = null;
21
        DxfEntityList entities = null;
22
        Vector blkList = null;
23
        DxfBlock blk = null;
24
        DxfTable layers = null;
25
        double bulge = 0.0;
26

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

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

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

    
261
                x = grp.getDataAsDouble(10);
262
                y = grp.getDataAsDouble(20);
263
                if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30);
264
                pt1 = proj.createPoint(x, y);
265
                x = grp.getDataAsDouble(11);
266
                y = grp.getDataAsDouble(21);
267
                if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31);
268
                pt2 = proj.createPoint(x, y);
269
                if (grp.hasCode(210))
270
                        xtruX = grp.getDataAsDouble(210);
271
                if (grp.hasCode(220))
272
                        xtruY = grp.getDataAsInt(220);
273
                if (grp.hasCode(230))
274
                        xtruZ = grp.getDataAsInt(230);
275
                Point3D point_in1 = new Point3D(pt1.getX(), pt1.getY(), z1);
276
                Point3D point_in2 = new Point3D(pt2.getX(), pt2.getY(), z2);
277
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
278
                Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
279
                Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
280
                pt1.setLocation(point_out1);
281
                pt2.setLocation(point_out2);
282
                DxfLine entity = new DxfLine(proj, layer, pt1, pt2);
283
                if (grp.hasCode(62)) {
284
                        entity.dxfColor = grp.getDataAsInt(62);
285
                } else {
286
                        //entity.dxfColor = 0;
287
                }
288
                if (addingToBlock == false) {
289
                        //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
290
                        entities.add(entity);
291
                } else {
292
                        //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
293
                        blk.add(entity);
294
                }
295
        }
296
        public void createText(DxfGroupVector grp) throws Exception {
297
                double x = 0.0, y = 0.0, h= 0.0, rot= 0.0;
298
                DxfGroup g = null;
299
                Point2D pt1 = null, pt2 = null;
300
                String txt = null;
301
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
302

    
303
                txt = grp.getDataAsString(1);
304
                DxfText entity = new DxfText(proj, layer, txt);
305

    
306
                x = grp.getDataAsDouble(10);
307
                y = grp.getDataAsDouble(20);
308
                entity.setPt1(proj.createPoint(x, y));
309
                if (grp.hasCode(11)) {
310
                        x = grp.getDataAsDouble(11);
311
                        y = grp.getDataAsDouble(21);
312
                        entity.setPt2(proj.createPoint(x, y));
313
                }
314
                entity.setHeight(grp.getDataAsDouble(40));
315
                if (grp.hasCode(50)) {
316
                        entity.setRotation(grp.getDataAsDouble(50));                        
317
                        //System.out.println("AAAAAA: entity.getRotation = " + entity.getRotation());
318
                }
319
                if (grp.hasCode(62)) {
320
                        entity.dxfColor = grp.getDataAsInt(62);
321
                } else {
322
                        //entity.dxfColor = 0;
323
                }
324
                if (grp.hasCode(72))
325
                        entity.align = grp.getDataAsInt(72);
326
                if (addingToBlock == false) {
327
                        entities.add(entity);
328
                } else {
329
                        //System.out.println("createText(): A?adimos un text al bloque " + iterator);
330
                        blk.add(entity);
331
                }
332
        }
333
        /* (non-Javadoc)
334
         * @see org.cresques.io.DxfFile.EntityFactory#createMText(org.cresques.io.DxfGroupVector)
335
         */
336
        public void createMText(DxfGroupVector v) throws Exception {
337
                // TODO Auto-generated method stub
338
                
339
        }
340
        public void createPoint(DxfGroupVector grp) throws Exception {
341
                double x = 0.0, y = 0.0, z = 0.0; //, h= 0.0, rot= 0.0;
342
                DxfGroup g = null;
343
                Point2D pt = null;
344
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
345

    
346
                DxfPoint entity = new DxfPoint(proj, layer);
347

    
348
                x = grp.getDataAsDouble(10);
349
                y = grp.getDataAsDouble(20);
350
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
351
                if (grp.hasCode(62)) {
352
                        entity.dxfColor = grp.getDataAsInt(62);
353
                } else {
354
                        //entity.dxfColor = 0;
355
                }
356
                if (grp.hasCode(210))
357
                        xtruX = grp.getDataAsDouble(210);
358
                if (grp.hasCode(220))
359
                        xtruY = grp.getDataAsInt(220);
360
                if (grp.hasCode(230))
361
                        xtruZ = grp.getDataAsInt(230);
362
                Point3D point_in = new Point3D(x, y, z);
363
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
364
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
365
                x = point_out.getX();
366
                y = point_out.getY();
367
                entity.setPt(proj.createPoint(x, y));
368
                if (addingToBlock == false) {
369
                        entities.add(entity);
370
                } else {
371
                        //System.out.println("createPoint(): A?adimos un punto al bloque " + iterator);
372
                        blk.add(entity);
373
                }
374
        }
375
        public void createCircle(DxfGroupVector grp) throws Exception {
376
                double x = 0.0, y = 0.0, z = 0.0;
377
                double r = 0.0;
378
                DxfGroup g = null;
379
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
380

    
381
                x = grp.getDataAsDouble(10);
382
                y = grp.getDataAsDouble(20);
383
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
384
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
385
                if (grp.hasCode(210))
386
                        xtruX = grp.getDataAsDouble(210);
387
                if (grp.hasCode(220))
388
                        xtruY = grp.getDataAsDouble(220);
389
                if (grp.hasCode(230))
390
                        xtruZ = grp.getDataAsDouble(230);
391
                Point3D point_in = new Point3D(x, y, z);
392
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
393
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
394
                x = point_out.getX();
395
                y = point_out.getY();
396
                
397
                Point2D center = proj.createPoint( x, y);
398
                Point2D[] pts = new Point2D[360];
399
                int angulo = 0;
400
                for (angulo=0; angulo<360; angulo++) {
401
                        pts[angulo] = new Point2D.Double(center.getX(), center.getY());
402
                        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));
403
                        if (pts.length == 1) {
404
                                firstPt = pts[angulo];
405
                        }
406
                }
407
                DxfCircle entity = new DxfCircle(proj, layer, pts);
408
                if (grp.hasCode(62)) {
409
                        entity.dxfColor = grp.getDataAsInt(62);
410
                } else {
411
                        //entity.dxfColor = 0;
412
                }
413
                if (addingToBlock == false) {
414
                        //System.out.println("createCircle(): A?ade un circulo a la lista de entidades");
415
                        entities.add(entity);
416
                } else {
417
                        //System.out.println("createCircle(): A?adimos un circulo al bloque " + iterator);
418
                        blk.add(entity);
419
                }
420
        }
421
        public void createArc(DxfGroupVector grp) throws Exception {
422
                double x = 0.0, y = 0.0, z = 0.0;
423
                double r = 0.0, empieza = 0.0, acaba = 0.0;
424
                DxfGroup g = null;
425
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
426

    
427
                x = grp.getDataAsDouble(10);
428
                y = grp.getDataAsDouble(20);
429
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
430
                if (grp.hasCode(40)) r = grp.getDataAsDouble(40);
431
                if (grp.hasCode(50)) empieza = grp.getDataAsDouble(50);
432
                if (grp.hasCode(51)) acaba = grp.getDataAsDouble(51);
433
                if (grp.hasCode(210))
434
                        xtruX = grp.getDataAsDouble(210);
435
                if (grp.hasCode(220))
436
                        xtruY = grp.getDataAsDouble(220);
437
                if (grp.hasCode(230))
438
                        xtruZ = grp.getDataAsDouble(230);
439
                Point3D point_in = new Point3D(x, y, z);
440
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
441
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
442
                x = point_out.getX();
443
                y = point_out.getY();
444
                
445
                Point2D center = proj.createPoint( x, y);
446
                //System.out.println("empieza = " + empieza + ", acaba = " + acaba);
447
                int iempieza = (int)empieza;
448
                int iacaba = (int)acaba;
449
                //System.out.println("iempieza = " + iempieza + ", iacaba = " + iacaba);
450
                double angulo = 0;
451
                Point2D[] pts = null;
452
                if (empieza <= acaba) {
453
                        pts = new Point2D[(iacaba-iempieza)+2];
454
                        angulo = empieza;
455
                        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));
456
                        for (int i=1; i<=(iacaba-iempieza)+1; i++) {
457
                                angulo = (double)(iempieza+i);
458
                                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));
459
                        }
460
                        angulo = acaba;
461
                        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));
462
                } else {
463
                        pts = new Point2D[(360-iempieza)+iacaba+2];
464
                        angulo = empieza;
465
                        //System.out.println("pts[0] = " + pts[0] + ", center = " + center + ", angulo = " + angulo);
466
                        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));
467
                        for (int i=1; i<=(360-iempieza); i++) {
468
                                angulo = (double)(iempieza+i);
469
                                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));
470
                        }
471
                        for (int i=(360-iempieza)+1; i<=(360-iempieza)+iacaba; i++) {
472
                                angulo = (double)(i-(360-iempieza));
473
                                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));
474
                        }
475
                        angulo = acaba;
476
                        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));
477
                }
478
                DxfArc entity = new DxfArc(proj, layer, pts);
479
                if (grp.hasCode(62)) {
480
                        entity.dxfColor = grp.getDataAsInt(62);
481
                } else {
482
                        //entity.dxfColor = 0;
483
                }
484
                //System.out.println("createArc(): A?adimos un arco al bloque");
485
                if (addingToBlock == false) {
486
                        entities.add(entity);
487
                } else {
488
                        //System.out.println("createArc(): A?adimos un arco al bloque " + iterator);
489
                        blk.add(entity);
490
                }
491
        }
492
        
493
        /**
494
         * TODO Detectados fallos en las rotaciones de bloques. Hoja 72231.
495
         *      Detectado en los bloques correspondientes a campos de futbol,
496
         *      de tipo solid.
497
         */
498
        public void createInsert(DxfGroupVector grp) throws Exception {
499
                double x = 0.0, y = 0.0, z = 0.0;
500
                DxfGroup g = null;
501
                Point2D pt = new Point2D.Double(0.0, 0.0);
502
                Point2D scaleFactor = new Point2D.Double(1.0, 1.0);
503
                double rotAngle = 0.0;
504
                String blockName = "";
505
                
506
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
507
                
508
                DxfInsert entity = new DxfInsert(proj, layer);
509
                DxfPoint secondEntity = new DxfPoint(proj, layer);
510

    
511
                if (grp.hasCode(2)) {
512
                        blockName = grp.getDataAsString(2);
513
                        entity.setBlockName(blockName);
514
                }
515
                if (grp.hasCode(10)) x = grp.getDataAsDouble(10);
516
                if (grp.hasCode(20)) y = grp.getDataAsDouble(20);
517
                if (grp.hasCode(30)) z = grp.getDataAsDouble(30);
518
                if (grp.hasCode(41)) {
519
                        scaleFactor.setLocation(grp.getDataAsDouble(41), scaleFactor.getY());
520
                        entity.setScaleFactor(scaleFactor);
521
                } else {
522
                        entity.setScaleFactor(scaleFactor);                        
523
                }
524
                if (grp.hasCode(42)) {
525
                        scaleFactor.setLocation(scaleFactor.getX(), grp.getDataAsDouble(42));
526
                        entity.setScaleFactor(scaleFactor);
527
                } else {
528
                        entity.setScaleFactor(scaleFactor);
529
                }
530
                if (grp.hasCode(43)) {
531
                        // TODO La coordenada z
532
                }
533
                if (grp.hasCode(50)) {
534
                        rotAngle = grp.getDataAsDouble(50);
535
                        entity.setRotAngle(rotAngle);
536
                }
537
                if (grp.hasCode(62)) {
538
                        entity.dxfColor = grp.getDataAsInt(62);
539
                } else {
540
                        //entity.dxfColor = 0;
541
                }
542
                if (grp.hasCode(210))
543
                        xtruX = grp.getDataAsDouble(210);
544
                if (grp.hasCode(220))
545
                        xtruY = grp.getDataAsDouble(220);
546
                if (grp.hasCode(230))
547
                        xtruZ = grp.getDataAsDouble(230);
548
                Point3D point_in = new Point3D(x, y, z);
549
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
550
                Point2D point_out = DxfCalXtru.CalculateXtru(point_in, xtru);
551
                x = point_out.getX();
552
                y = point_out.getY();
553
                                
554
                entity.setBlkList(blkList);
555
                                
556
                entity.encuentraBloque(blockName);
557
                
558
                entity.setPt(proj.createPoint(x, y));
559
                secondEntity.setPt(proj.createPoint(x, y));
560
                
561
                gestionaInsert(entity, layer);
562
                
563
                //System.out.println("createInsert: entity.getBlockName = " + entity.getBlockName());
564
                //System.out.println("createInsert: entity.getRotAngle = " + entity.getRotAngle());
565
                
566
                if (addingToBlock == false) {
567
                        entities.add(secondEntity);
568
                } else if (addingToBlock == true && entity.blockFound == true) {
569
                        //System.out.println("createArc(): A?adimos un insert al bloque " + iterator);
570
                        blk.add(entity);
571
                }
572
        }
573
        
574
        public void createSolid(DxfGroupVector grp) throws Exception {
575
                double x = 0.0, y = 0.0, z1 = 0.0, z2 = 0.0, z3 = 0.0, z4 = 0.0;
576
                DxfGroup g = null;
577
                //Point2D pt1 = null, pt2 = null, pt3 = null, pt4 = null;
578
                Point2D[] pts = new Point2D[4];
579
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
580

    
581
                x = grp.getDataAsDouble(10);
582
                y = grp.getDataAsDouble(20);
583
                if (grp.hasCode(30)) z1 = grp.getDataAsDouble(30);
584
                pts[0] = proj.createPoint(x, y);
585
                x = grp.getDataAsDouble(11);
586
                y = grp.getDataAsDouble(21);
587
                if (grp.hasCode(31)) z2 = grp.getDataAsDouble(31);
588
                pts[1] = proj.createPoint(x, y);
589
                x = grp.getDataAsDouble(12);
590
                y = grp.getDataAsDouble(22);
591
                if (grp.hasCode(32)) z3 = grp.getDataAsDouble(32);
592
                pts[2] = proj.createPoint(x, y);
593
                x = grp.getDataAsDouble(13);
594
                y = grp.getDataAsDouble(23);
595
                if (grp.hasCode(33)) z2 = grp.getDataAsDouble(33);
596
                pts[3] = proj.createPoint(x, y);
597
                if (grp.hasCode(210))
598
                        xtruX = grp.getDataAsDouble(210);
599
                if (grp.hasCode(220))
600
                        xtruY = grp.getDataAsDouble(220);
601
                if (grp.hasCode(230))
602
                        xtruZ = grp.getDataAsDouble(230);
603
                Point3D point_in1 = new Point3D(pts[0].getX(), pts[0].getY(), z1);
604
                Point3D point_in2 = new Point3D(pts[1].getX(), pts[1].getY(), z2);
605
                Point3D point_in3 = new Point3D(pts[2].getX(), pts[2].getY(), z3);
606
                Point3D point_in4 = new Point3D(pts[3].getX(), pts[3].getY(), z4);
607
                Point3D xtru = new Point3D(xtruX, xtruY, xtruZ);
608
                Point2D point_out1 = DxfCalXtru.CalculateXtru(point_in1, xtru);
609
                Point2D point_out2 = DxfCalXtru.CalculateXtru(point_in2, xtru);
610
                Point2D point_out3 = DxfCalXtru.CalculateXtru(point_in3, xtru);
611
                Point2D point_out4 = DxfCalXtru.CalculateXtru(point_in4, xtru);
612
                pts[0].setLocation(point_out1);
613
                pts[1].setLocation(point_out2);
614
                pts[2].setLocation(point_out3);
615
                pts[3].setLocation(point_out4);
616
                DxfSolid entity = new DxfSolid(proj, layer, pts);
617
                if (grp.hasCode(62)) {
618
                        entity.dxfColor = grp.getDataAsInt(62);
619
                } else {
620
                        //entity.dxfColor = 0;
621
                }
622
                if (addingToBlock == false) {
623
                        //System.out.println("createLine(): A?adimos una linea a la lista de entidades");
624
                        entities.add(entity);
625
                } else {
626
                        //System.out.println("createLine(): A?adimos una linea al bloque " + iterator);
627
                        blk.add(entity);
628
                }
629
        }
630
        /**
631
         * Los Splines estan implementados como LwPolylines. Se pintan las lineas
632
         * entre los vertices pero no se aplica la curvatura Spline.
633
         * TODO Contemplar la curvatura spline para Splines.
634
         */
635
        public void createSpline(DxfGroupVector grp) throws Exception {
636
                double x = 0.0, y = 0.0, elev=0.0;
637
                DxfGroup g = null;
638
                
639
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
640
                DxfLwPolyline entity = new DxfLwPolyline(proj, layer);
641
                for (int i=0; i<grp.size(); i++) {
642
                        g = (DxfGroup) grp.get(i);
643
                        if (g.getCode() == 10)
644
                                x = ((Double) g.getData()).doubleValue();
645
                        else if (g.getCode() == 20) {
646
                                y = ((Double) g.getData()).doubleValue();
647
                                //if (y <= 1.0) throw new Exception("Y == "+y);
648
                                entity.add( proj.createPoint( x, y ) );
649
                                x = 0.0; y = 0.0;
650
                        }
651
                }
652
                if (grp.hasCode(62)) {
653
                        entity.dxfColor = grp.getDataAsInt(62);
654
                } else {
655
                        //entity.dxfColor = 0;
656
                }
657
                if (grp.hasCode(70))
658
                        entity.flags = grp.getDataAsInt(70);
659
                if ((entity.flags & 0x01) == 0x01) {
660
                        entity.closed = true;
661
                }
662
                if (addingToBlock == false) {
663
                        entities.add(entity);
664
                } else {
665
                        //System.out.println("createLwPolyline(): A?adimos una lwpolilinea al bloque " + iterator);
666
                        blk.add(entity);
667
                }
668
        }
669
        public void createBlock(DxfGroupVector grp) throws Exception {
670
                DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
671
                blk = new DxfBlock(proj);
672
                
673
                Point2D basePoint = new Point2D.Double();
674
                String blockName = "";
675
                //System.out.println("createBlock(): Creamos nuevo bloque, el bloque " + iterator);
676
                
677
                addingToBlock = true;
678
                //System.out.println("createBlock(): A?adimos el bloque " + iterator + " a la lista de bloques");
679
                blkList.add(iterator, blk);
680
                
681
                //System.out.println("createBlock(): Rellenamos la informacion del bloque " + iterator);
682
                if (grp.hasCode(1)) {
683
                        blockName = grp.getDataAsString(1);
684
                        blk.setBlkName(blockName);
685
                }
686
                if (grp.hasCode(2)) {
687
                        blockName = grp.getDataAsString(2);
688
                        blk.setBlkName(blockName);
689
                }
690
                if (grp.hasCode(3)) {
691
                        blockName = grp.getDataAsString(3);
692
                        blk.setBlkName(blockName);
693
                }
694
                if (grp.hasCode(10)) {
695
                        basePoint.setLocation(grp.getDataAsDouble(10), basePoint.getY());
696
                        blk.setBPoint(basePoint);
697
                }
698
                if (grp.hasCode(20)) {
699
                        basePoint.setLocation(basePoint.getX(), grp.getDataAsDouble(20));
700
                        blk.setBPoint(basePoint);
701
                }
702
                if (grp.hasCode(30)) {
703
                        // TODO Contemplar la coordenada z
704
                }
705
                if (grp.hasCode(70)) {
706
                        blk.flags = grp.getDataAsInt(70);                        
707
                }
708
        }
709
        public void endBlk(DxfGroupVector grp) throws Exception {
710
                //DxfLayer layer = (DxfLayer) layers.getByName(grp.getDataAsString(8));
711
                setAddingToBlock(false);
712
                iterator = iterator + 1;
713
        }
714

    
715
        public void testBlocks() {
716
                Vector blkList = getBlkList();
717
                DxfBlock dxfBlock = null;
718
                DxfEntity dxfEntity = null;
719
                DxfLine dxfLine = null;
720
                DxfInsert dxfInsert = null;
721
                Point2D point1 = new Point2D.Double();
722
                Point2D point2 = new Point2D.Double();
723
                for (int i=0; i<blkList.size(); i++) {
724
                        dxfBlock = (DxfBlock)blkList.get(i);
725
                        int aux = dxfBlock.getBlkElements().size();
726
                        for (int j=0; j<aux; j++) {
727
                                dxfEntity = (DxfEntity)dxfBlock.getBlkElements().get(j);
728
                                if (dxfEntity instanceof DxfLine) {
729
                                        dxfLine = (DxfLine)dxfEntity;
730
                                        point1 = dxfLine.getPts()[0];
731
                                        point2 = dxfLine.getPts()[1];
732
                                        //System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", vertice1 = " + point1 + ", vertice2 = " + point2);
733
                                } else if (dxfEntity instanceof DxfInsert){
734
                                        dxfInsert = (DxfInsert)dxfEntity;
735
                                        String nomBlock = dxfInsert.getBlockName();
736
                                        //System.out.println("compruebaBloques(): Bloque = " + i + ", elemento = " + j + ", inserta el bloque = " + nomBlock);
737
                                        //System.out.println("compruebaBloques(): dxfInsert.pt = " + dxfInsert.getPt());
738
                                        //System.out.println("compruebaBloques(): dxfInsert.rotAngle = " + dxfInsert.getRotAngle());
739
                                        //System.out.println("compruebaBloques(): dxfInsert.scaleFactor = " + dxfInsert.getScaleFactor());
740
                                        
741
                                        if (dxfInsert.getBlockFound() == false) {
742
                                                //System.out.println("compruebaBloques(): Ahora se ocupa del DxfInsert " + nomBlock);
743
                                                boolean aux_bool = dxfInsert.encuentraBloque(nomBlock);
744
                                                gestionaInsert(dxfInsert, dxfInsert.getDxfLayer());
745
                                                dxfBlock.add(dxfInsert);
746
                                        }
747
                                        
748
                                }
749
                        }
750
                }
751
        }
752
        
753
        public void setProjection(IProjection proj) { this.proj = proj;}
754
        public IProjection getProjection() { return proj;}
755

    
756
        public void reProject(ICoordTrans rp) {
757
                entities.reProject(rp);
758
                setProjection(rp.getPDest());
759
        }
760
        
761
        public DxfEntityList getEntities() { return entities;}
762
        public DxfTable getLayers() { return layers;}
763
        
764
        public DxfBlock getBlk() {
765
                return blk;
766
        }
767
        
768
        public void gestionaInsert(DxfInsert entity, DxfLayer layer) {
769
                DxfEntity dxfEntity = null;
770
                DxfLine dxfLine = null;
771
                DxfInsert dxfInsert = null;
772
                DxfPolyline dxfPolyline = null;
773
                DxfArc dxfArc = null;
774
                DxfCircle dxfCircle = null;
775
                DxfLwPolyline dxfLwPolyline = null;
776
                DxfPoint dxfPoint = null;
777
                DxfText dxfText = null;
778
                DxfSolid dxfSolid = null;
779
                for (int i=0; i<entity.block.size(); i++) {
780
                        //System.out.println("gestionaInserts: entity.block.blkElements.size() = " + entity.block.blkElements.size());
781
                        dxfEntity = (DxfEntity)entity.block.get(i);
782
                        
783
                        Point2D point1 = new Point2D.Double();
784
                        Point2D point2 = new Point2D.Double();
785
                        Point2D point11 = new Point2D.Double();
786
                        Point2D point22 = new Point2D.Double();
787
                        if (dxfEntity instanceof DxfLine) {
788
                                dxfLine = (DxfLine)dxfEntity;
789
                                point1 = dxfLine.getPts()[0];
790
                                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());
791
                                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());
792
                                point11.setLocation(laX, laY);
793
                                point2 = dxfLine.getPts()[1];
794
                                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()));
795
                                DxfLine dxfLinee = new DxfLine(proj, layer, point11, point22);
796
                                if (addingToBlock == false) {
797
                                        entities.add(dxfLinee);
798
                                }
799
                        } else if (dxfEntity instanceof DxfInsert){
800
                                dxfInsert = (DxfInsert)dxfEntity;
801
                                point1 = dxfInsert.pt;
802
                                //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()));
803
                                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()));
804
                                DxfInsert dxfInsertt = new DxfInsert(proj, layer);
805
                                
806
                                dxfInsertt.pt = point11;
807
                                
808
                                dxfInsertt.blkList = dxfInsert.blkList;
809
                                dxfInsertt.block = dxfInsert.block;
810
                                dxfInsertt.blockName = dxfInsert.blockName;
811
                                dxfInsertt.layer = dxfInsert.layer;
812
                                dxfInsertt.proj = dxfInsert.proj;
813
                                dxfInsertt.rotAngle = dxfInsert.rotAngle; // * entity.rotAngle;
814

    
815
                                dxfInsertt.scaleFactor = new Point2D.Double(dxfInsert.scaleFactor.getX() * entity.scaleFactor.getX(), dxfInsert.scaleFactor.getY() * entity.scaleFactor.getY());
816
                                
817
                                gestionaInsert(dxfInsertt, layer);
818
                        } else if (dxfEntity instanceof DxfPolyline) {
819
                                dxfPolyline = (DxfPolyline)dxfEntity;
820
                                DxfPolyline dxfPolylinee = new DxfPolyline(proj, layer);
821
                                if (dxfPolyline.closed) dxfPolylinee.closed = true;
822
                                Point2D[] points = new Point2D[dxfPolyline.pts.size()];
823
                                Point2D[] pointss = new Point2D[dxfPolyline.pts.size()];
824
                                for (int j=0; j<dxfPolyline.pts.size(); j++) {
825
                                        points[j] = (Point2D)dxfPolyline.pts.get(j);
826
                                        pointss[j] = new Point2D.Double();                                        
827
                                        //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()));
828
                                        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()));
829
                                        //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()));
830
                                        dxfPolylinee.add(pointss[j]);
831
                                }
832
                                if (addingToBlock == false) entities.add(dxfPolylinee);
833
                        } else if (dxfEntity instanceof DxfArc) {
834
                                dxfArc = (DxfArc)dxfEntity;
835
                                Point2D[] points = new Point2D[dxfArc.pts.length];
836
                                Point2D[] pointss = new Point2D[dxfArc.pts.length];
837
                                for (int j=0; j<dxfArc.pts.length; j++) {
838
                                        points[j] = (Point2D)dxfArc.pts[j];
839
                                        pointss[j] = new Point2D.Double();
840
                                        //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()));
841
                                        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()));
842
                                        //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()));
843
                                }
844
                                DxfArc dxfArcc = new DxfArc(proj, layer, pointss);
845
                                if (addingToBlock == false) entities.add(dxfArcc);
846
                        } else if (dxfEntity instanceof DxfCircle) {
847
                                dxfCircle = (DxfCircle)dxfEntity;
848
                                Point2D[] points = new Point2D[dxfCircle.pts.length];
849
                                Point2D[] pointss = new Point2D[dxfCircle.pts.length];
850
                                for (int j=0; j<dxfCircle.pts.length; j++) {
851
                                        points[j] = (Point2D)dxfCircle.pts[j];
852
                                        pointss[j] = new Point2D.Double();
853
                                        //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()));
854
                                        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()));
855
                                        //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()));
856
                                }
857
                                DxfCircle dxfCirclee = new DxfCircle(proj, layer, pointss);
858
                                if (addingToBlock == false) entities.add(dxfCirclee);
859
                        } else if (dxfEntity instanceof DxfLwPolyline) {
860
                                dxfLwPolyline = (DxfLwPolyline)dxfEntity;
861
                                DxfLwPolyline dxfLwPolylinee = new DxfLwPolyline(proj, layer);
862
                                Point2D[] points = new Point2D[dxfLwPolyline.pts.size()];
863
                                Point2D[] pointss = new Point2D[dxfLwPolyline.pts.size()];
864
                                for (int j=0; j<dxfLwPolyline.pts.size(); j++) {
865
                                        points[j] = (Point2D)dxfLwPolyline.pts.get(j);
866
                                        pointss[j] = new Point2D.Double();                                        
867
                                        //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()));
868
                                        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()));
869
                                        //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()));
870
                                        dxfLwPolylinee.add(pointss[j]);
871
                                }
872
                                if (addingToBlock == false) entities.add(dxfLwPolylinee);
873
                        } else if (dxfEntity instanceof DxfPoint) {
874
                                dxfPoint = (DxfPoint)dxfEntity;
875
                                point1 = dxfPoint.pt;
876
                                //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()));
877
                                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()));
878
                                //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()));
879
                                DxfPoint dxfPointt = new DxfPoint(proj, layer);
880
                                dxfPointt.pt = point11;
881
                                if (addingToBlock == false) entities.add(dxfPointt);
882
                        } else if (dxfEntity instanceof DxfText) {
883
                                dxfText = (DxfText)dxfEntity;
884
                                point1 = dxfText.pts[0];
885
                                //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()));
886
                                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()));
887
                                //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()));
888
                                point2 = dxfText.pts[1];
889
                                //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()));
890
                                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()));
891
                                //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()));
892
                                DxfText dxfTextt = new DxfText(proj, layer, dxfText.getText());
893
                                dxfTextt.pts[0] = point11;
894
                                dxfTextt.pts[1] = point22;
895
                                if (addingToBlock == false) entities.add(dxfTextt);
896
                        } else if (dxfEntity instanceof DxfSolid) {
897
                                dxfSolid = (DxfSolid)dxfEntity;
898
                                Point2D[] points = new Point2D[dxfSolid.pts.length];
899
                                Point2D[] pointss = new Point2D[dxfSolid.pts.length];
900
                                for (int j=0; j<dxfSolid.pts.length; j++) {
901
                                        points[j] = (Point2D)dxfSolid.pts[j];
902
                                        pointss[j] = new Point2D.Double();
903
                                        //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()));
904
                                        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()));
905
                                        //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()));
906
                                }
907
                                DxfSolid dxfSolidd = new DxfSolid(proj, layer, pointss);
908
                                Point2D aux = dxfSolidd.pts[2];
909
                                dxfSolidd.pts[2] = dxfSolidd.pts[3];
910
                                dxfSolidd.pts[3] = aux;
911
                                if (addingToBlock == false) entities.add(dxfSolidd);
912
                        } else {
913
                                System.out.println("gestionaInserts: Encontrado elemento desconocido");
914
                        }
915
                }
916
        }
917

    
918
        /* (non-Javadoc)
919
         * @see org.cresques.io.DxfFile.EntityFactory#createAttdef(org.cresques.io.DxfGroupVector)
920
         */
921
        public void createAttdef(DxfGroupVector v) throws Exception {
922
                // TODO Auto-generated method stub
923
                
924
        }
925

    
926
        /* (non-Javadoc)
927
         * @see org.cresques.io.DxfFile.EntityFactory#createAttrib(org.cresques.io.DxfGroupVector)
928
         */
929
        public void createAttrib(DxfGroupVector v) throws Exception {
930
                // TODO Auto-generated method stub
931
                
932
        }
933
        
934
}