Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / DxfFile.java @ 2709

History | View | Annotate | Download (66.8 KB)

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

    
26
import java.io.BufferedReader;
27
import java.io.FileNotFoundException;
28
import java.io.FileReader;
29
import java.io.FileWriter;
30
import java.io.IOException;
31
import java.io.InputStream;
32
import java.io.InputStreamReader;
33
import java.io.Reader;
34
import java.util.Date;
35
import java.util.Hashtable;
36
import java.util.Vector;
37
import org.cresques.cts.ICoordTrans;
38
import org.cresques.cts.IProjection;
39
import org.cresques.geo.Projected;
40
import org.cresques.px.Extent;
41
import org.cresques.px.IObjList;
42
import org.cresques.px.dxf.DxfEntityMaker;
43
import org.cresques.px.dxf.DxfHeaderManager;
44
import org.cresques.px.dxf.DxfHeaderVariables;
45

    
46
/**
47
 * Clase que representa un fichero en formato DXF. Contiene los interfaces y m?todos
48
 * necesarios para acceder a la informaci?n almacenada en su interior.
49
 * 
50
 * @author jmorell
51
 */
52
public class DxfFile extends GeoFile {
53
        
54
        private boolean cadFlag = true;
55
        
56
        long lineNr = 0;
57

    
58
        String buf = null;
59
        
60
        BufferedReader fi;
61
        long l = 0;
62
        int count = 0;
63
        DxfGroup grp = null;
64
        
65
        EntityFactory entityMaker = null;
66
        VarSettings headerManager;
67
        
68
        /**
69
         * Crea los objetos en el Modelo correspondiente.
70
         * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
71
         */
72
        public interface EntityFactory extends Projected {
73
        
74
                /**
75
         * Permite saber si se est?n a?adiendo elementos a un bloque
76
         * @param booleano que indica si se est?n a?adiendo elementos a un bloque
77
                 */
78
        public void setAddingToBlock(boolean a);
79
        
80
        /**
81
         * Crea una nueva capa partiendo de la informaci?n almacenada en el DXF
82
         * @param DxfGroupVector con informaci?n para la construcci?n de la nueva capa
83
         * @throws Exception
84
         */
85
                public void createLayer(DxfGroupVector v) throws Exception ;
86
        
87
        /**
88
         * Crea una nueva polil?nea partiendo de la informaci?n almacenada en el DXF
89
         * @param DxfGroupVector con informaci?n para la construcci?n de la nueva polil?nea
90
         * @throws Exception
91
         */
92
                public void createPolyline(DxfGroupVector v) throws Exception ;
93
        
94
        /**
95
         * A?ade un v?rtice a la polil?nea que se est? creando
96
         * @param DxfGroupVector con la informaci?n necesaria para la adici?n del v?rtice
97
         * @throws Exception
98
         */
99
                public void addVertex(DxfGroupVector v) throws Exception ;
100
                
101
        /**
102
         * Fin de secuencia
103
         * @throws Exception
104
         */
105
        public void endSeq() throws Exception ;
106
        
107
        /**
108
         * Crea una nueva LwPolyline partiendo de la informaci?n almacenada en el DXF
109
         * @param DxfGroupVector con informaci?n para la construcci?n de la nueva polil?nea
110
         * @throws Exception
111
         */
112
                public void createLwPolyline(DxfGroupVector v) throws Exception ;
113
                
114
        /**
115
         * Crea una nueva l?nea partiendo de la informaci?n almacenada en el DXF
116
         * @param DxfGroupVector con informaci?n para la construcci?n de la nueva l?nea
117
         * @throws Exception
118
         */
119
        public void createLine(DxfGroupVector v) throws Exception ;
120
                
121
        /**
122
         * Crea un nuevo texto partiendo de la informaci?n almacenada en el DXF
123
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo texto
124
         * @throws Exception
125
         */
126
        public void createText(DxfGroupVector v) throws Exception ;
127
                
128
        /**
129
         * Crea un nuevo MText partiendo de la informaci?n almacenada en el DXF
130
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo MText
131
         * @throws Exception
132
         */
133
        public void createMText(DxfGroupVector v) throws Exception ;
134
                
135
        /**
136
         * Crea un nuevo punto partiendo de la informaci?n almacenada en el DXF
137
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo punto
138
         * @throws Exception
139
         */
140
        public void createPoint(DxfGroupVector v) throws Exception ;
141
                
142
        /**
143
         * Crea un nuevo c?rculo partiendo de la informaci?n almacenada en el DXF
144
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo c?rculo
145
         * @throws Exception
146
         */
147
        public void createCircle(DxfGroupVector v) throws Exception ;
148
                
149
        /**
150
         * Crea una nueva elipse partiendo de la informaci?n almacenada en el DXF
151
         * @param DxfGroupVector con informaci?n para la construcci?n de la nueva elipse
152
         * @throws Exception
153
         */
154
        public void createEllipse(DxfGroupVector v) throws Exception ;
155
                
156
        /**
157
         * Crea un nuevo arco partiendo de la informaci?n almacenada en el DXF
158
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo arco
159
         * @throws Exception
160
         */
161
        public void createArc(DxfGroupVector v) throws Exception ;
162
                
163
        /**
164
         * Crea un nuevo punto de inserci?n partiendo de la informaci?n almacenada en el DXF
165
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo punto de inserci?n
166
         * @throws Exception
167
         */
168
        public void createInsert(DxfGroupVector v) throws Exception ;
169
                
170
        /**
171
         * Crea un nuevo s?lido 2D partiendo de la informaci?n almacenada en el DXF
172
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo s?lido
173
         * @throws Exception
174
         */
175
        public void createSolid(DxfGroupVector v) throws Exception ;
176
                
177
        /**
178
         * Crea un nuevo Spline partiendo de la informaci?n almacenada en el DXF
179
         * @param DxfGroupVector con informaci?n para la construcci?n del nuevo Spline
180
         * @throws Exception
181
         */
182
        public void createSpline(DxfGroupVector v) throws Exception ;
183
                
184
        /**
185
         * Construye la definici?n de un nuevo atributo partiendo de la informaci?n almacenada en el DXF
186
         * @param DxfGroupVector con informaci?n para la construcci?n de la definici?n del nuevo atributo
187
         * @throws Exception
188
         */
189
        public void createAttdef(DxfGroupVector v) throws Exception ;
190
                
191
        /**
192
         * Crea un nuevo atributo partiendo de la informaci?n almacenada en el DXF
193
         * @param DxfGroupVector con informaci?n para la creaci?n del nuevo atributo
194
         * @throws Exception
195
         */
196
        public void createAttrib(DxfGroupVector v) throws Exception ;
197
                
198
        /**
199
         * Crea un bloque
200
         * @param DxfGroupVector con informaci?n para la creaci?n del nuevo elemento
201
         * @throws Exception
202
         */
203
        public void createBlock(DxfGroupVector v) throws Exception ;
204
                
205
        /**
206
         * Fin de la definici?n de un bloqe
207
         * @param DxfGroupVector con informaci?n referente al final de un bloque
208
         * @throws Exception
209
         */
210
        public void endBlk(DxfGroupVector v) throws Exception ;
211
                
212
        /**
213
         * Gestiona los bloques que no se han tratado en la primera vuelta
214
         */
215
        void testBlocks();
216
                
217
        /**
218
         * Devuelve el extent
219
         * @return el extent
220
         */
221
        public Extent getExtent();
222
                
223
        /**
224
         * Devuelve la lista de bloques
225
         * @return la lista de bloques
226
         */
227
        public Vector getBlkList();
228
                
229
                /**
230
         * Permite la gesti?n de los atributos almacenados en unn DXF
231
         * @return un Vector con la lista de atributos
232
                 */
233
        public Vector getAttributes();
234
                
235
        /**
236
         * Borra los atributos repetidos
237
         */
238
        public void depureAttributes();
239
                
240
        /**
241
         * Devuelve los objetos almacenados en el DXF
242
         * @return IObjList con los objetos procedentes del DXF
243
         */
244
        public IObjList getObjects();
245
                
246
        /**
247
         * Permite saber si se trata de un fichero DXF en 2D o en 3D
248
         * @return booleano que indica si se trata de un fichero DXF 3D
249
         */
250
        public boolean isDxf3DFile();
251
        };
252
        
253
        /**
254
         * Establece el estado de las variables propias de un DXF que est?n definidas
255
         * en la secci?n HEADER. Por ejemplo, la versi?n del DXF.
256
         * @author jmorell (jose.morell@gmail.com)
257
         * @version 15-dic-2004
258
         */
259
        public interface VarSettings {
260
                
261
                /**
262
                 * Establece la versi?n de Autocad en la que fue generado el DXF.
263
                 * @param informaci?n de base
264
                 * @throws Exception
265
                 */
266
                public void setAcadVersion(DxfGroupVector v) throws Exception ;
267
                
268
                /**
269
                 * Devuelve la versi?n de Autocad en la que fue generado el DXF.
270
                 * @return
271
                 */
272
                public String getAcadVersion();
273
                
274
                /**
275
                 * Devuelve el estado de las variables propias de un DXF
276
                 * @return
277
                 */
278
                public DxfHeaderVariables getDxfHeaderVars();
279
                
280
        };
281
        
282
    /**
283
     * Constructor de la clase
284
     * @param proj, la proyecci?n cartogr?fica
285
     * @param name, el path absoluto hasta el fichero DXF
286
     * @param maker, el interface que permite la construcci?n de las entidades procedentes del DXF
287
     */
288
        public DxfFile(IProjection proj, String name, EntityFactory maker) {
289
                super(proj, name);
290
                entityMaker = maker;
291
                headerManager = new DxfHeaderManager();
292
        }
293
        
294
    /**
295
     * Constructor de la clase que adem?s incorpora la capacidad de leer una porci?n del HEADER
296
     * @param proj, la proyecci?n cartogr?fica
297
     * @param name, el path absoluto hasta el fichero DXF
298
     * @param maker, el interface que permite la construcci?n de las entidades procedentes del DXF
299
     * @param dxfVars, el interface que permite la lectura del HEADER de un DXF
300
     */
301
    public DxfFile(IProjection proj, String name, EntityFactory maker, VarSettings dxfVars) {
302
                super(proj, name);
303
                entityMaker = maker;
304
                headerManager = dxfVars;
305
        }
306
        
307
        /**
308
         * Carga un fichero en formato DXF
309
         */
310
        public GeoFile load() {
311
                System.out.println("Dxf: Cargando "+name+" ...");
312
                try {
313
                        if (ZipFileFolder.isUrl(name)) {
314
                                ZipFileFolder zFolder = new ZipFileFolder(name);
315
                                InputStream is = zFolder.getInputStream(name);
316
                                return load(new InputStreamReader(is));
317
                        } else 
318
                                return load(new FileReader(name));
319
                } catch (FileNotFoundException fnfe) {
320
                        fnfe.printStackTrace();
321
                } catch (Exception e) {
322
                        System.err.println("Dxf: ERROR."+l+"lineas leidas");
323
                        e.printStackTrace();
324
                }
325
                return this;
326
        }
327
        
328
    /**
329
     * Carga un fichero en formato DXF tomando un Reader como par?metro
330
     * @param fr, Reader que se le pasa como par?metro
331
     * @return devuelve un objeto GeoFile, padre de DxfFile
332
     * @throws NumberFormatException
333
     * @throws Exception
334
     */
335
        public GeoFile load(Reader fr) throws NumberFormatException, Exception {
336
                System.out.println("Dxf: Cargando '"+name+"' ...");
337
                fi = new BufferedReader(fr);
338
                while ((grp = readGrp()) != null) {
339
                        l+=2;
340
                        
341
                        if (grp.equals(0, "EOF"))                break;
342
                        if (grp.equals(0, "SECTION"))
343
                                readSection();
344
                }
345
                fi.close();
346
                extent.add(entityMaker.getExtent());
347
                System.out.println("Dxf: '"+name+"' cargado. ("+l+" l?neas).");
348
                this.lineNr = l;
349
                return this;
350
        }
351
        
352
    /**
353
     * El fichero DXF se divide en grupos. Este m?todo permite leer cada grupo individualmente
354
     * @return devuelve la informaci?n del DXF en forma de objetos de la clase DxfGroup
355
     * @throws NumberFormatException
356
     * @throws IOException
357
     */
358
        private DxfGroup readGrp() throws NumberFormatException, IOException {
359
                DxfGroup g = DxfGroup.read(fi);
360
                if (g != null) l += 2;
361
                /*if (g.code == 8)
362
                        if (((String) g.data).length() < 1) {
363
                                System.err.println("a que un layer no puede ser ''?");
364
                                System.exit(1);
365
                        }*/
366
                return g;
367
        }
368
        
369
    /**
370
     * El fichero DXF se divide en varias secciones. Este m?todo se encarga de leer cada
371
     * una de ellas
372
     * @throws NumberFormatException
373
     * @throws Exception
374
     */
375
        private void readSection() throws NumberFormatException, Exception {
376
                while (true) {
377
                        grp = readGrp(); System.out.print("-1:"+grp);
378
                        if (grp.code == 2)
379
                                if (((String) grp.data).compareTo("HEADER") == 0)
380
                                        readHeader();
381
                                else if (((String) grp.data).compareTo("CLASSES") == 0)
382
                                        readAnySection();
383
                                else if (((String) grp.data).compareTo("TABLES") == 0)
384
                                        readTables();
385
                                else if (((String) grp.data).compareTo("BLOCKS") == 0)
386
                                        readBlocks();
387
                                else if (((String) grp.data).compareTo("ENTITIES") == 0)
388
                                        readEntities();
389
                                else if (((String) grp.data).compareTo("OBJECTS") == 0)
390
                                        readAnySection();
391
                                else {
392
                                        System.out.println("DxfRead: Seccion "+grp.data);
393
                                        readAnySection();
394
                                }
395
                        else
396
                                System.err.println("Dxf: Codigo/Seccion desconocidos" + grp);
397
                        if (grp.equals(0, "EOF")) break;
398
                        if (grp.equals(0, "ENDSEC")) break;
399
                }                
400
        }
401
        
402
    /**
403
     * Habilita la lectura de la secci?n de TABLES
404
     * @throws NumberFormatException
405
     * @throws Exception
406
     */
407
        private void readTables() throws NumberFormatException, Exception {
408
                System.out.println("Dxf: Seccion TABLAS, linea "+ l+ "grp ="+ grp);
409
                int layerCnt = 0;
410
                String tableAct = "NONAME";
411
                
412
                Hashtable tables = new Hashtable();
413
                Vector table = new Vector();
414
                DxfGroupVector v = new DxfGroupVector();
415
                
416
                grp = readGrp();// System.out.print("0:"+grp);
417
                while (true) {
418
                        if (grp.code == 0) {
419
                                String data = (String) grp.getData();
420
                                if (data.compareTo("ENDSEC") == 0 || data.compareTo("EOF") == 0)
421
                                        break;
422
                                else if (data.compareTo("ENDTAB") == 0) {
423
                                        tables.put(tableAct, table);
424
                                        table = new Vector();
425
                                        grp = readGrp();// System.out.print("1:"+grp);
426
                                        
427
                                        /**/if (tableAct.compareTo("LAYER") == 0 && v.size()>0) {
428
                                                entityMaker.createLayer(v);
429
                                                System.out.println("Dxf: Layer "+v.getDataAsString(2));
430
                                                layerCnt++;
431
                                                v.clear();
432
                                        }/**/
433
                                        continue;
434
                                } else {
435
                                        if (table.size()==1) {
436
                                                tableAct = v.getDataAsString(2);
437
                                                System.out.println("Dxf: Tabla "+tableAct);
438
                                        } else
439
                                                if (tableAct.compareTo("LAYER") == 0 && v.size()>0) {
440
                                                        entityMaker.createLayer(v);
441
                                                        System.out.println("Dxf: Layer "+v.getDataAsString(2));
442
                                                        layerCnt++;
443
                                                }
444

    
445
                                        v.clear();
446
                                        v.add(grp);
447
                                }
448
                                while (true) {
449
                                        grp = readGrp();// System.out.print("2:"+grp);
450
                                        if (grp.code == 0)        break;
451
                                        v.add(grp);
452
                                }
453
                                table.add(v);
454
                        } else {
455
                                System.err.println("Dxf: Error de secuencia");
456
                                grp = readGrp(); //System.out.print("3:"+grp);        
457
                        }
458
                }
459
                System.out.println("Dxf: Seccion TABLAS: " + layerCnt + " Capas. ");
460
        }
461
        
462
    /**
463
     * M?todo de lectura de secci?n por defecto. Se utiliza mientras se realiza la
464
     * implementaci?n correspondiente
465
     * @throws NumberFormatException
466
     * @throws IOException
467
     */
468
        private void readAnySection() throws NumberFormatException, IOException {
469
                System.out.println("Dxf: Seccion '"+((String) grp.getData())+"', linea "+ l);
470
                while (true) {
471
                        grp = readGrp();
472
                        if (grp.equals(0, "ENDSEC")) break;
473
                        else if (grp.equals(0, "EOF")) break;
474
                }
475
        }
476
        
477
        /**
478
         * Primera aproximaci?n a la implementaci?n de la lectura del HEADER. En principio
479
         * interesa que se lea la versi?n del DXF.
480
         * Para implementar esta parte del lector se ha optado por incluir el m?todo
481
         * setAcadVersion en el interface EntityFactory. A lo mejor conviene implementar
482
         * un nuevo interface VarSettings.
483
         * @throws NumberFormatException
484
         * @throws Exception
485
         */
486
        private void readHeader() throws NumberFormatException, Exception {
487
                System.out.println("Dxf: Seccion HEADER, linea "+ l);
488
                int variableCnt = 0;
489
                int cntVeces = 0;
490
                DxfGroupVector v = new DxfGroupVector();
491
                grp = readGrp();
492
                while (true) {
493
                        if (grp.equals(0, "EOF")) {
494
                                break;
495
                        }
496
                        else if (grp.code==9 || grp.code==0) {
497
                                if (v.size() > 0) {
498
                                        String lastVariable = (String) ((DxfGroup) v.get(0)).data;
499
                                        //System.out.println(lastVariable);
500
                                        if (lastVariable.compareTo("$ACADVER") == 0) {
501
                                                //System.out.println("Aqui llega.");
502
                                                headerManager.setAcadVersion(v);
503
                                        } else if (lastVariable.compareTo("ENDSEC") == 0) {
504
                                                //System.out.println("Llega al ENDSEC.");
505
                                                break;
506
                                        } else
507
                                                System.err.println("Dxf: Variable "+lastVariable+" desconocida.");
508
                                }
509
                                v.clear();
510
                                v.add(grp);
511
                                while (true) {
512
                                        grp = readGrp();
513
                                        if (grp.code == 9 || grp.code==0)        break;
514
                                        v.add(grp);
515
                                }
516
                                variableCnt++;
517
                        }
518
                        cntVeces++;
519
                }
520
                System.out.println("Dxf: Seccion HEADER, " + variableCnt + " variables, "+ cntVeces + " veces.");
521
                //System.out.println("Seccion HEADER, linea "+ l+ " (SALGO)");
522
                System.out.println("readHeader: ACAD Version: " + headerManager.getDxfHeaderVars().getAcadVersion());
523
        }        
524
        
525
    /**
526
     * Permite leer la secci?n ENTITIES del DXF, donde se encuentran las entidades
527
     * geom?tricas del DXF que no aparecen dentro de ning?n bloque
528
     * @throws NumberFormatException
529
     * @throws Exception
530
     */
531
        private void readEntities() throws NumberFormatException, Exception {
532
                System.out.println("Dxf: Seccion ENTITIES, linea "+ l);
533
                int entityCnt = 0;
534
                int cntVeces = 0;
535
                DxfGroupVector v = new DxfGroupVector();
536
                grp = readGrp();
537
                while (true) {
538
                        if (grp.equals(0, "EOF")) break;
539
                        else if (grp.code == 0) {
540
                                if (v.size() > 0) {
541
                                        String lastEntity = (String) ((DxfGroup) v.get(0)).data;
542
                                        if (lastEntity.compareTo("POLYLINE") == 0) {
543
                                                entityMaker.createPolyline(v);
544
                                        } else if (lastEntity.compareTo("VERTEX") == 0) {
545
                                                entityMaker.addVertex(v);
546
                                        } else if (lastEntity.compareTo("SEQEND") == 0) {
547
                                                entityMaker.endSeq();
548
                                        } else if (lastEntity.compareTo("LWPOLYLINE") == 0) {
549
                                                entityMaker.createLwPolyline(v);
550
                                        } else if (lastEntity.compareTo("LINE") == 0) {
551
                                                entityMaker.createLine(v);
552
                                        } else if (lastEntity.compareTo("TEXT") == 0) {
553
                                                entityMaker.createText(v);
554
                                        } else if (lastEntity.compareTo("MTEXT") == 0) {
555
                                                entityMaker.createMText(v);
556
                                        } else if (lastEntity.compareTo("POINT") == 0) {
557
                                                entityMaker.createPoint(v);
558
                                        } else if (lastEntity.compareTo("CIRCLE") == 0) {
559
                                                entityMaker.createCircle(v);
560
                                        } else if (lastEntity.compareTo("ELLIPSE") == 0) {
561
                                                entityMaker.createEllipse(v);
562
                                        } else if (lastEntity.compareTo("ARC") == 0) {
563
                                                entityMaker.createArc(v);
564
                                        } else if (lastEntity.compareTo("INSERT") == 0) {
565
                                                entityMaker.createInsert(v);
566
                                        } else if (lastEntity.compareTo("SOLID") == 0) {
567
                                                entityMaker.createSolid(v);
568
                                        } else if (lastEntity.compareTo("SPLINE") == 0) {
569
                                                entityMaker.createSpline(v);
570
                                        } else if (lastEntity.compareTo("ATTRIB") == 0) {
571
                                                entityMaker.createAttrib(v);
572
                                        } else if (lastEntity.compareTo("ENDSEC") == 0) {
573
                                                break;
574
                                        } else
575
                                                System.err.println("Dxf: Entidad "+lastEntity+" desconocida.");
576
                                }
577
                                v.clear();
578
                                v.add(grp);
579
                                while (true) {
580
                                        grp = readGrp();
581
                                        if (grp.code == 0)        break;
582
                                        v.add(grp);
583
                                }
584
                                entityCnt++;
585
                        }
586
                        cntVeces++;
587
                }
588
                System.out.println("Dxf: Seccion ENTITIES, " + entityCnt + " entidades, "+ cntVeces + " veces.");
589
                //System.out.println("Seccion ENTITIES, linea "+ l+ " (SALGO)");
590
        }
591
        
592
    /**
593
     * Permite la secci?n BLOCKS del DXF, donde se encuentran las definiciones de los
594
     * bloques que componen el DXF
595
     * @throws NumberFormatException
596
     * @throws Exception
597
     */
598
        private void readBlocks() throws NumberFormatException, Exception {
599
                System.out.println("Dxf: Seccion BLOCKS, linea "+ l);
600
                int blkCnt = 0;
601
                int cntVeces = 0;
602
                DxfGroupVector v = new DxfGroupVector();
603
                grp = readGrp();
604
                while (true) {
605
                        if (grp.equals(0, "EOF")) break;
606
                        else if (grp.code == 0) {
607
                                if (v.size() > 0) {
608
                                        String lastEntity = (String) ((DxfGroup) v.get(0)).data;
609
                                        if (lastEntity.compareTo("BLOCK") == 0) {
610
                                                //System.out.println("readBlocks(): Empezamos a leer un bloque");
611
                                                entityMaker.createBlock(v);
612
                                        } else if (lastEntity.compareTo("POLYLINE") == 0) {
613
                                                //System.out.println("readBlocks(): A?adimos una polilinea al bloque");
614
                                                entityMaker.createPolyline(v);
615
                                        } else if (lastEntity.compareTo("VERTEX") == 0) {
616
                                                //System.out.println("readBlocks(): A?adimos un vertice a la polilinea");
617
                                                entityMaker.addVertex(v);
618
                                        } else if (lastEntity.compareTo("SEQEND") == 0) {
619
                                                //System.out.println("readBlocks(): Cerramos una polilinea");
620
                                                entityMaker.endSeq();
621
                                        } else if (lastEntity.compareTo("LWPOLYLINE") == 0) {
622
                                                //System.out.println("readBlocks(): A?adimos una lwpolilinea al bloque");
623
                                                entityMaker.createLwPolyline(v);
624
                                        } else if (lastEntity.compareTo("LINE") == 0) {
625
                                                //System.out.println("readBlocks(): A?adimos una linea al bloque");
626
                                                entityMaker.createLine(v);
627
                                        } else if (lastEntity.compareTo("TEXT") == 0) {
628
                                                //System.out.println("readBlocks(): A?adimos un texto al bloque");
629
                                                entityMaker.createText(v);
630
                                        } else if (lastEntity.compareTo("MTEXT") == 0) {
631
                                                //System.out.println("readBlocks(): A?adimos un m-texto al bloque");
632
                                                entityMaker.createMText(v);
633
                                        } else if (lastEntity.compareTo("POINT") == 0) {
634
                                                //System.out.println("readBlocks(): A?adimos un punto al bloque");
635
                                                entityMaker.createPoint(v);
636
                                        } else if (lastEntity.compareTo("CIRCLE") == 0) {
637
                                                //System.out.println("readBlocks(): A?adimos un circulo al bloque");
638
                                                entityMaker.createCircle(v);
639
                                        } else if (lastEntity.compareTo("ARC") == 0) {
640
                                                //System.out.println("readBlocks(): A?adimos un arco al bloque");
641
                                                entityMaker.createArc(v);
642
                                        } else if (lastEntity.compareTo("INSERT") == 0) {
643
                                                //System.out.println("readBlocks(): A?adimos un insert al bloque");
644
                                                entityMaker.createInsert(v);
645
                                        } else if (lastEntity.compareTo("SOLID") == 0) {
646
                                                //System.out.println("readBlocks(): A?adimos un solido al bloque");
647
                                                entityMaker.createSolid(v);
648
                                        } else if (lastEntity.compareTo("SPLINE") == 0) {
649
                                                entityMaker.createSpline(v);
650
                                        } else if (lastEntity.compareTo("ATTDEF") == 0) {
651
                                                entityMaker.createAttdef(v);
652
                                        } else if (lastEntity.compareTo("ENDBLK") == 0) {
653
                                                //System.out.println("readBlocks(): Cerramos un bloque"+v);
654
                                                entityMaker.endBlk(v);
655
                                        } else if (lastEntity.compareTo("ENDSEC") == 0) {
656
                                                break;
657
                                        } else
658
                                                System.err.println("Dxf: Entidad de bloque "+lastEntity+" desconocida.");
659
                                }
660
                                v.clear();
661
                                v.add(grp);
662
                                while (true) {
663
                                        grp = readGrp();
664
                                        if (grp.code == 0)        break;
665
                                        v.add(grp);
666
                                }
667
                                blkCnt++;
668
                        }
669
                        cntVeces++;
670
                }
671
                
672
                entityMaker.testBlocks();
673
                // Cuando termina de leer la secci?n de bloques se asegura de que todos los campos
674
                // son distintos.
675
                //System.out.println("readBlocks(): entityMaker.getAttributes().size() = " + entityMaker.getAttributes().size());
676
                entityMaker.depureAttributes();
677
                //System.out.println("readBlocks(): entityMaker.getAttributes().size() = " + entityMaker.getAttributes().size());
678
                System.out.println("Dxf: Seccion BLOCKS, " + blkCnt + " elementos de bloque. "+ cntVeces + " veces.");
679
        }
680
        
681
    /**
682
     * Devuelve los objetos geom?tricos obtenidos de un DXF
683
     */
684
        public IObjList getObjects() {
685
                return this.entityMaker.getObjects();
686
        }
687
        
688
        /**
689
         * jmorell: M?todo que permite salvar capas al formato DXF2000.
690
         * Este m?todo ha sido actualizado en el proceso de implementaci?n del piloto
691
         * de CAD. En este piloto deb?a existir soporte para elipses, y este es uno de
692
         * los motivos que nos llevan a implementar ahora para DXF2000, puesto que el
693
         * DXF R12 no soporta elipses.
694
         * @param fName
695
         * @throws IOException
696
         */
697
        public void save(String fName) throws IOException {
698
                System.out.println("save: fName = " + fName);
699
                long t2, t1;
700
                t1 = getTime();
701
                fName = DataSource.normalize(fName);
702
                FileWriter fw = new FileWriter(fName);
703
                // COMMENTAIRES DU TRADUCTEUR
704
//                fw.write(DxfGroup.toString(999, Integer.toString(features.size()) + " features")); 
705
                fw.write(DxfGroup.toString(999, "TRANSLATION BY geo.cresques.io.DxfFile"));
706
                fw.write(DxfGroup.toString(999, "DATE : " + (new Date()).toString()));
707
                writeHeader(fw);
708
                writeTables(fw);
709
                writeBlocks(fw);
710
                writeEntities(fw);
711
                writeObjects(fw);
712
                fw.write(DxfGroup.toString(0, "EOF"));
713
                fw.flush();
714
                fw.close();
715
                t2 = getTime();
716
                System.out.println("DxfFile.save(): Tiempo salvando: " + (t2-t1)/1000 + " seg.");
717
        }
718
    
719
        /**
720
         * Escritor de la cabecera de un DXF.
721
         * jmorell: Actualizaci?n del escritor de DXF de R12 a 2000.
722
         * @param fw, un FileWriter para escribir ficheros
723
         * @throws IOException
724
         */
725
        public void writeHeader(FileWriter fw) throws IOException {
726
                fw.write(DxfGroup.toString(0, "SECTION"));
727
                fw.write(DxfGroup.toString(2, "HEADER"));
728
                fw.write(DxfGroup.toString(9, "$ACADVER"));
729
                        //fw.write(DxfGroup.toString(1, "AC1009"));                        // DXF R12
730
                        fw.write(DxfGroup.toString(1, "AC1015"));                        // DXF 2000
731
                fw.write(DxfGroup.toString(9, "$INSBASE"));
732
                        fw.write(DxfGroup.toString(10, 0.0, 1));
733
                        fw.write(DxfGroup.toString(20, 0.0, 1));
734
                        fw.write(DxfGroup.toString(30, 0.0, 1));
735
                fw.write(DxfGroup.toString(9, "$EXTMIN"));
736
                        fw.write(DxfGroup.toString(10, extent.minX(), 6));
737
                        fw.write(DxfGroup.toString(20, extent.minY(), 6));
738
                        fw.write(DxfGroup.toString(30, 0.0, 6));
739
                fw.write(DxfGroup.toString(9, "$EXTMAX"));
740
                        fw.write(DxfGroup.toString(10, extent.maxX(), 6));
741
                        fw.write(DxfGroup.toString(20, extent.maxY(), 6));
742
                        fw.write(DxfGroup.toString(30, 0.0, 6));
743
                fw.write(DxfGroup.toString(9, "$LIMMIN"));
744
                        fw.write(DxfGroup.toString(10, extent.minX(), 6));
745
                        fw.write(DxfGroup.toString(20, extent.minY(), 6));
746
                fw.write(DxfGroup.toString(9, "$LIMMAX"));
747
                        fw.write(DxfGroup.toString(10, extent.maxX(), 6));
748
                        fw.write(DxfGroup.toString(20, extent.maxY(), 6));
749
                fw.write(DxfGroup.toString(9, "$ORTHOMODE")+DxfGroup.toString(70, 0));
750
                fw.write(DxfGroup.toString(9, "$REGENMODE")+DxfGroup.toString(70, 1));
751
                fw.write(DxfGroup.toString(9, "$FILLMODE")+        DxfGroup.toString(70, 1));
752
                fw.write(DxfGroup.toString(9, "$QTEXTMODE")+DxfGroup.toString(70, 0));
753
                fw.write(DxfGroup.toString(9, "$MIRRTEXT")+        DxfGroup.toString(70, 1));
754
                fw.write(DxfGroup.toString(9, "$DRAGMODE")+        DxfGroup.toString(70, 2));
755
                fw.write(DxfGroup.toString(9, "$LTSCALE")+        DxfGroup.toString(40, 1.0, 1));
756
                fw.write(DxfGroup.toString(9, "$OSMODE")+        DxfGroup.toString(70, 0));
757
                fw.write(DxfGroup.toString(9, "$ATTMODE")+        DxfGroup.toString(70, 1));
758
                fw.write(DxfGroup.toString(9, "$TEXTSIZE")+        DxfGroup.toString(40, 0.2, 1));
759
                fw.write(DxfGroup.toString(9, "$TRACEWID")+        DxfGroup.toString(40, 0.05, 2));
760
                fw.write(DxfGroup.toString(9, "$TEXTSTYLE")+        DxfGroup.toString(7, "STANDARD"));
761
                fw.write(DxfGroup.toString(9, "$CLAYER")+        DxfGroup.toString(8, "0"));
762
                fw.write(DxfGroup.toString(9, "$CELTYPE")+        DxfGroup.toString(6, "CONTINUOUS"));
763
                fw.write(DxfGroup.toString(9, "$CECOLOR")+        DxfGroup.toString(62, 256));
764
                fw.write(DxfGroup.toString(9, "$DIMSCALE")+        DxfGroup.toString(40, 1.0, 1));
765
                fw.write(DxfGroup.toString(9, "$DIMASZ")+        DxfGroup.toString(40, 0.18, 2));
766
                fw.write(DxfGroup.toString(9, "$DIMEXO")+        DxfGroup.toString(40, 0.0625, 4));
767
                fw.write(DxfGroup.toString(9, "$DIMDLI")+        DxfGroup.toString(40, 0.38, 2));
768
                fw.write(DxfGroup.toString(9, "$DIMRND")+        DxfGroup.toString(40, 0.0, 1));
769
                fw.write(DxfGroup.toString(9, "$DIMDLE")+        DxfGroup.toString(40, 0.0, 1));
770
                fw.write(DxfGroup.toString(9, "$DIMEXE")+        DxfGroup.toString(40, 0.18, 2));
771
                fw.write(DxfGroup.toString(9, "$DIMTP")+        DxfGroup.toString(40, 0.0, 1));
772
                fw.write(DxfGroup.toString(9, "$DIMTM")+        DxfGroup.toString(40, 0.0, 1));
773
                fw.write(DxfGroup.toString(9, "$DIMTXT")+        DxfGroup.toString(40, 0.18, 2));
774
                fw.write(DxfGroup.toString(9, "$DIMCEN")+        DxfGroup.toString(40, 0.09, 2));
775
                fw.write(DxfGroup.toString(9, "$DIMTSZ")+        DxfGroup.toString(40, 0.0, 1));
776
                fw.write(DxfGroup.toString(9,"$DIMTOL")+        DxfGroup.toString(70,0));
777
                fw.write(DxfGroup.toString(9,"$DIMLIM")+        DxfGroup.toString(70,0));
778
                fw.write(DxfGroup.toString(9,"$DIMTIH")+        DxfGroup.toString(70,1));
779
                fw.write(DxfGroup.toString(9,"$DIMTOH")+        DxfGroup.toString(70,1));
780
                fw.write(DxfGroup.toString(9,"$DIMSE1")+        DxfGroup.toString(70,0));
781
                fw.write(DxfGroup.toString(9,"$DIMSE2")+        DxfGroup.toString(70,0));
782
                fw.write(DxfGroup.toString(9,"$DIMTAD")+        DxfGroup.toString(70,0));
783
                fw.write(DxfGroup.toString(9,"$DIMZIN")+        DxfGroup.toString(70,0));
784
                fw.write(DxfGroup.toString(9,"$DIMBLK")+        DxfGroup.toString(1,""));
785
                fw.write(DxfGroup.toString(9,"$DIMASO")+        DxfGroup.toString(70,1));
786
                fw.write(DxfGroup.toString(9,"$DIMSHO")+        DxfGroup.toString(70,1));
787
                fw.write(DxfGroup.toString(9,"$DIMPOST")+        DxfGroup.toString(1,""));
788
                fw.write(DxfGroup.toString(9,"$DIMAPOST")+        DxfGroup.toString(1,""));
789
                fw.write(DxfGroup.toString(9,"$DIMALT")+        DxfGroup.toString(70,0));
790
                fw.write(DxfGroup.toString(9,"$DIMALTD")+        DxfGroup.toString(70,2));
791
                fw.write(DxfGroup.toString(9,"$DIMALTF")+        DxfGroup.toString(40,25.4,1));
792
                fw.write(DxfGroup.toString(9,"$DIMLFAC")+        DxfGroup.toString(40,1.0,1));
793
                fw.write(DxfGroup.toString(9,"$DIMTOFL")+        DxfGroup.toString(70,0));
794
                fw.write(DxfGroup.toString(9,"$DIMTVP")+        DxfGroup.toString(40,0.0,1));
795
                fw.write(DxfGroup.toString(9,"$DIMTIX")+        DxfGroup.toString(70,0));
796
                fw.write(DxfGroup.toString(9,"$DIMSOXD")+        DxfGroup.toString(70,0));
797
                fw.write(DxfGroup.toString(9,"$DIMSAH")+        DxfGroup.toString(70,0));
798
                fw.write(DxfGroup.toString(9,"$DIMBLK1")+        DxfGroup.toString(1,""));
799
                fw.write(DxfGroup.toString(9,"$DIMBLK2")+        DxfGroup.toString(1,""));
800
                fw.write(DxfGroup.toString(9,"$DIMSTYLE")+        DxfGroup.toString(2,"STANDARD"));
801
                fw.write(DxfGroup.toString(9,"$DIMCLRD")+        DxfGroup.toString(70,0));
802
                fw.write(DxfGroup.toString(9,"$DIMCLRE")+        DxfGroup.toString(70,0));
803
                fw.write(DxfGroup.toString(9,"$DIMCLRT")+        DxfGroup.toString(70,0));
804
                fw.write(DxfGroup.toString(9,"$DIMTFAC")+        DxfGroup.toString(40,1.0,1));
805
                fw.write(DxfGroup.toString(9,"$DIMGAP")+        DxfGroup.toString(40,0.09,2));
806
                fw.write(DxfGroup.toString(9,"$LUNITS")+        DxfGroup.toString(70,2));
807
                fw.write(DxfGroup.toString(9,"$LUPREC")+        DxfGroup.toString(70,4));
808
                fw.write(DxfGroup.toString(9,"$AXISMODE")+        DxfGroup.toString(70,0));
809
                fw.write(DxfGroup.toString(9,"$AXISUNIT"));
810
                fw.write(DxfGroup.toString(10,0.0,1));
811
                fw.write(DxfGroup.toString(20,0.0,1));
812
                fw.write(DxfGroup.toString(9,"$SKETCHINC")+        DxfGroup.toString(40,0.1,1));
813
                fw.write(DxfGroup.toString(9,"$FILLETRAD")+        DxfGroup.toString(40,0.0,1));
814
                fw.write(DxfGroup.toString(9,"$AUNITS")+        DxfGroup.toString(70,0));
815
                fw.write(DxfGroup.toString(9,"$AUPREC")+        DxfGroup.toString(70,0));
816
                fw.write(DxfGroup.toString(9,"$MENU")+                DxfGroup.toString(1,"acad"));
817
                fw.write(DxfGroup.toString(9,"$ELEVATION")+        DxfGroup.toString(40,0.0,1));
818
                fw.write(DxfGroup.toString(9,"$PELEVATION")+DxfGroup.toString(40,0.0,1));
819
                fw.write(DxfGroup.toString(9,"$THICKNESS")+        DxfGroup.toString(40,0.0,1));
820
                fw.write(DxfGroup.toString(9,"$LIMCHECK")+        DxfGroup.toString(70,0));
821
                fw.write(DxfGroup.toString(9,"$BLIPMODE")+        DxfGroup.toString(70,1));
822
                fw.write(DxfGroup.toString(9,"$CHAMFERA")+        DxfGroup.toString(40,0.0,1));
823
                fw.write(DxfGroup.toString(9,"$CHAMFERB")+        DxfGroup.toString(40,0.0,1));
824
                fw.write(DxfGroup.toString(9,"$SKPOLY")+        DxfGroup.toString(70,0));
825
                fw.write(DxfGroup.toString(9,"$TDCREATE")+        DxfGroup.toString(40,2453116.436828704,9));
826
                fw.write(DxfGroup.toString(9,"$TDUPDATE")+        DxfGroup.toString(40,2453116.436828704,9));
827
                fw.write(DxfGroup.toString(9,"$TDINDWG")+        DxfGroup.toString(40,0.0000000000,10));
828
                fw.write(DxfGroup.toString(9,"$TDUSRTIMER")+DxfGroup.toString(40,0.0000000000,10));
829
                fw.write(DxfGroup.toString(9,"$USRTIMER")+        DxfGroup.toString(70,1));
830
                fw.write(DxfGroup.toString(9,"$ANGBASE")+        DxfGroup.toString(50,0.0,1));
831
                fw.write(DxfGroup.toString(9,"$ANGDIR")+        DxfGroup.toString(70,0));
832
                fw.write(DxfGroup.toString(9,"$PDMODE")+        DxfGroup.toString(70,0));
833
                fw.write(DxfGroup.toString(9,"$PDSIZE")+        DxfGroup.toString(40,0.0,1));
834
                fw.write(DxfGroup.toString(9,"$PLINEWID")+        DxfGroup.toString(40,0.0,1));
835
                fw.write(DxfGroup.toString(9,"$COORDS")+        DxfGroup.toString(70,0));
836
                fw.write(DxfGroup.toString(9,"$SPLFRAME")+        DxfGroup.toString(70,0));
837
                fw.write(DxfGroup.toString(9,"$SPLINETYPE")+DxfGroup.toString(70,6));
838
                fw.write(DxfGroup.toString(9,"$SPLINESEGS")+DxfGroup.toString(70,10));
839
                fw.write(DxfGroup.toString(9,"$ATTDIA")+        DxfGroup.toString(70,0));
840
                fw.write(DxfGroup.toString(9,"$ATTREQ")+        DxfGroup.toString(70,1));
841
                fw.write(DxfGroup.toString(9,"$HANDLING")+        DxfGroup.toString(70,1));
842
                fw.write(DxfGroup.toString(9,"$HANDSEED")+        DxfGroup.toString(5,"394B"));
843
                fw.write(DxfGroup.toString(9,"$SURFTAB1")+        DxfGroup.toString(70,6));
844
                fw.write(DxfGroup.toString(9,"$SURFTAB2")+        DxfGroup.toString(70,6));
845
                fw.write(DxfGroup.toString(9,"$SURFTYPE")+        DxfGroup.toString(70,6));
846
                fw.write(DxfGroup.toString(9,"$SURFU")+                DxfGroup.toString(70,6));
847
                fw.write(DxfGroup.toString(9,"$SURFV")+                DxfGroup.toString(70,6));
848
                fw.write(DxfGroup.toString(9,"$UCSNAME")+        DxfGroup.toString(2,""));
849
                fw.write(DxfGroup.toString(9,"$UCSORG"));
850
                fw.write(DxfGroup.toString(10,0.0,1));
851
                fw.write(DxfGroup.toString(20,0.0,1));
852
                fw.write(DxfGroup.toString(30,0.0,1));
853
                fw.write(DxfGroup.toString(9,"$UCSXDIR"));
854
                fw.write(DxfGroup.toString(10,1.0,1));
855
                fw.write(DxfGroup.toString(20,0.0,1));
856
                fw.write(DxfGroup.toString(30,0.0,1));
857
                fw.write(DxfGroup.toString(9,"$UCSYDIR"));
858
                fw.write(DxfGroup.toString(10,0.0,1));
859
                fw.write(DxfGroup.toString(20,1.0,1));
860
                fw.write(DxfGroup.toString(30,0.0,1));
861
                fw.write(DxfGroup.toString(9,"$PUCSNAME")+        DxfGroup.toString(2,""));
862
                fw.write(DxfGroup.toString(9,"$PUCSORG"));
863
                fw.write(DxfGroup.toString(10,0.0,1));
864
                fw.write(DxfGroup.toString(20,0.0,1));
865
                fw.write(DxfGroup.toString(30,0.0,1));
866
                fw.write(DxfGroup.toString(9,"$PUCSXDIR"));
867
                fw.write(DxfGroup.toString(10,1.0,1));
868
                fw.write(DxfGroup.toString(20,0.0,1));
869
                fw.write(DxfGroup.toString(30,0.0,1));
870
                fw.write(DxfGroup.toString(9,"$PUCSYDIR"));
871
                fw.write(DxfGroup.toString(10,0.0,1));
872
                fw.write(DxfGroup.toString(20,1.0,1));
873
                fw.write(DxfGroup.toString(30,0.0,1));
874
                fw.write(DxfGroup.toString(9,"$USERI1")+        DxfGroup.toString(70,0));
875
                fw.write(DxfGroup.toString(9,"$USERI2")+        DxfGroup.toString(70,0));
876
                fw.write(DxfGroup.toString(9,"$USERI3")+        DxfGroup.toString(70,0));
877
                fw.write(DxfGroup.toString(9,"$USERI4")+        DxfGroup.toString(70,0));
878
                fw.write(DxfGroup.toString(9,"$USERI5")+        DxfGroup.toString(70,0));
879
                fw.write(DxfGroup.toString(9,"$USERR1")+        DxfGroup.toString(40,0.0,1));
880
                fw.write(DxfGroup.toString(9,"$USERR2")+        DxfGroup.toString(40,0.0,1));
881
                fw.write(DxfGroup.toString(9,"$USERR3")+        DxfGroup.toString(40,0.0,1));
882
                fw.write(DxfGroup.toString(9,"$USERR4")+        DxfGroup.toString(40,0.0,1));
883
                fw.write(DxfGroup.toString(9,"$USERR5")+        DxfGroup.toString(40,0.0,1));
884
                fw.write(DxfGroup.toString(9,"$WORLDVIEW")+        DxfGroup.toString(70,1));
885
                fw.write(DxfGroup.toString(9,"$SHADEDGE")+        DxfGroup.toString(70,3));
886
                fw.write(DxfGroup.toString(9,"$SHADEDIF")+        DxfGroup.toString(70,70));
887
                fw.write(DxfGroup.toString(9,"$TILEMODE")+        DxfGroup.toString(70,1));
888
                fw.write(DxfGroup.toString(9,"$MAXACTVP")+        DxfGroup.toString(70,16));
889
                fw.write(DxfGroup.toString(9,"$PINSBASE"));
890
                fw.write(DxfGroup.toString(10,0.0,1));
891
                fw.write(DxfGroup.toString(20,0.0,1));
892
                fw.write(DxfGroup.toString(30,0.0,1));
893
                fw.write(DxfGroup.toString(9,"$PLIMCHECK")+        DxfGroup.toString(70,0));
894
                fw.write(DxfGroup.toString(9,"$PEXTMIN"));
895
                fw.write(DxfGroup.toString(10,"-1.000000E+20"));
896
                fw.write(DxfGroup.toString(20,"-1.000000E+20"));
897
                fw.write(DxfGroup.toString(30,"-1.000000E+20"));
898
                fw.write(DxfGroup.toString(9,"$PEXTMAX"));
899
                fw.write(DxfGroup.toString(10,"-1.000000E+20"));
900
                fw.write(DxfGroup.toString(20,"-1.000000E+20"));
901
                fw.write(DxfGroup.toString(30,"-1.000000E+20"));
902
                fw.write(DxfGroup.toString(9,"$PLIMMIN"));
903
                fw.write(DxfGroup.toString(10,0.0,1));
904
                fw.write(DxfGroup.toString(20,0.0,1));
905
                fw.write(DxfGroup.toString(9,"$PLIMMAX"));
906
                fw.write(DxfGroup.toString(10,12.0,1));
907
                fw.write(DxfGroup.toString(20,9.0,1));
908
                fw.write(DxfGroup.toString(9,"$UNITMODE")+        DxfGroup.toString(70,0));
909
                fw.write(DxfGroup.toString(9,"$VISRETAIN")+        DxfGroup.toString(70,0));
910
                fw.write(DxfGroup.toString(9,"$PLINEGEN")+        DxfGroup.toString(70,1));
911
                fw.write(DxfGroup.toString(9,"$PSLTSCALE")+        DxfGroup.toString(70,0));
912
                fw.write(DxfGroup.toString(9,"$TREEDEPTH")+        DxfGroup.toString(70,3020));
913
                fw.write(DxfGroup.toString(9,"$DWGCODEPAGE")+DxfGroup.toString(3,"ansi_1252"));
914
/*                
915
                fw.write(DxfGroup.toString(9, "$ELEVATION"));
916
                        fw.write(DxfGroup.toString(40, 0.0, 3));
917
                fw.write(DxfGroup.toString(9, "$LIMCHECK"));
918
                        fw.write(DxfGroup.toString(70, 1));
919
                fw.write(DxfGroup.toString(9, "$LUNITS"));
920
                        fw.write(DxfGroup.toString(70, 2));
921
                fw.write(DxfGroup.toString(9, "$LUPREC"));
922
                        fw.write(DxfGroup.toString(70, 2));*/
923
                fw.write(DxfGroup.toString(0, "ENDSEC"));
924
        }
925
        
926
        /**
927
         * Escritor de la secci?n TABLES de un DXF.
928
         * @param fw, FileWriter
929
         * @throws IOException
930
         */
931
        public void writeTables(FileWriter fw) throws IOException {
932
                fw.write(DxfGroup.toString(0, "SECTION"));
933
                fw.write(DxfGroup.toString(2, "TABLES"));
934
                // esta tampoco.
935
                writeVPortTable(fw);
936
                writeLTypeTable(fw);
937
                writeLayerTable(fw);
938
                writeStyleTable(fw);
939
                // estas no son las provocan el pete.
940
                writeViewTable(fw);
941
                writeUCSTable(fw);
942
                // esta provoca el pete. Y si no se pone las tablas aparecen
943
                // incompletas y acad no abre el fichero ...
944
                writeAppidTable(fw);
945
                writeDimStyleTable(fw);
946
                // esta no provoca pete.
947
                writeBlockRecordTable(fw);
948
                fw.write(DxfGroup.toString(0, "ENDSEC"));
949
        }
950
    
951
        /**
952
         * Escritor de la tabla VPORT.
953
         * @param fw
954
         * @throws IOException
955
         */
956
        public void writeVPortTable(FileWriter fw) throws IOException {
957
                fw.write(DxfGroup.toString(0, "TABLE"));
958
                fw.write(DxfGroup.toString(2, "VPORT"));
959
                fw.write(DxfGroup.toString(5, 8));
960
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
961
                fw.write(DxfGroup.toString(70, 0));
962
                /*fw.write(DxfGroup.toString(70, 1));
963
                fw.write(DxfGroup.toString(0, "VPORT"));
964
                fw.write(DxfGroup.toString(5, 30));
965
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
966
                fw.write(DxfGroup.toString(100, "AcDbViewportTableRecord"));
967
                fw.write(DxfGroup.toString(2, "*Active"));
968
                fw.write(DxfGroup.toString(70, 0));
969
                fw.write(DxfGroup.toString(10, 0.0, 4));
970
                fw.write(DxfGroup.toString(20, 0.0, 4));
971
                fw.write(DxfGroup.toString(11, 1.0, 4));
972
                fw.write(DxfGroup.toString(21, 1.0, 4));
973
                fw.write(DxfGroup.toString(12, 286.30555555555549, 10));
974
                fw.write(DxfGroup.toString(22, 148.5, 4));
975
                fw.write(DxfGroup.toString(13, 0.0, 4));
976
                fw.write(DxfGroup.toString(23, 0.0, 4));
977
                fw.write(DxfGroup.toString(14, 10.0, 4));
978
                fw.write(DxfGroup.toString(24, 10.0, 4));
979
                fw.write(DxfGroup.toString(15, 10.0, 4));
980
                fw.write(DxfGroup.toString(25, 10.0, 4));
981
                fw.write(DxfGroup.toString(16, 0.0, 4));
982
                fw.write(DxfGroup.toString(26, 0.0, 4));
983
                fw.write(DxfGroup.toString(36, 1.0, 4));
984
                fw.write(DxfGroup.toString(17, 0.0, 4));
985
                fw.write(DxfGroup.toString(27, 0.0, 4));
986
                fw.write(DxfGroup.toString(37, 0.0, 4));
987
                fw.write(DxfGroup.toString(40, 297.0, 4));
988
                fw.write(DxfGroup.toString(41, 1.92798353909465, 10));
989
                fw.write(DxfGroup.toString(42, 50.0, 4));
990
                fw.write(DxfGroup.toString(43, 0.0, 4));
991
                fw.write(DxfGroup.toString(44, 0.0, 4));
992
                fw.write(DxfGroup.toString(50, 0.0, 4));
993
                fw.write(DxfGroup.toString(51, 0.0, 4));
994
                fw.write(DxfGroup.toString(71, 0));
995
                fw.write(DxfGroup.toString(72, 100));
996
                fw.write(DxfGroup.toString(73, 1));
997
                fw.write(DxfGroup.toString(74, 3));
998
                fw.write(DxfGroup.toString(75, 1));
999
                fw.write(DxfGroup.toString(76, 1));
1000
                fw.write(DxfGroup.toString(77, 0));
1001
                fw.write(DxfGroup.toString(78, 0));
1002
                fw.write(DxfGroup.toString(281, 0));
1003
                fw.write(DxfGroup.toString(65, 1));
1004
                fw.write(DxfGroup.toString(110, 0.0, 4));
1005
                fw.write(DxfGroup.toString(120, 0.0, 4));
1006
                fw.write(DxfGroup.toString(130, 0.0, 4));
1007
                fw.write(DxfGroup.toString(111, 1.0, 4));
1008
                fw.write(DxfGroup.toString(121, 0.0, 4));
1009
                fw.write(DxfGroup.toString(131, 0.0, 4));
1010
                fw.write(DxfGroup.toString(112, 0.0, 4));
1011
                fw.write(DxfGroup.toString(122, 1.0, 4));
1012
                fw.write(DxfGroup.toString(132, 0.0, 4));
1013
                fw.write(DxfGroup.toString(79, 0));
1014
                fw.write(DxfGroup.toString(146, 0.0, 4));*/
1015
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1016
        }
1017
    
1018
        /**
1019
         * Escritor de la tabla LTYPE.
1020
         * @param fw
1021
         * @throws IOException
1022
         */
1023
        public void writeLTypeTable(FileWriter fw) throws IOException {
1024
                fw.write(DxfGroup.toString(0, "TABLE"));
1025
                fw.write(DxfGroup.toString(2, "LTYPE"));
1026
                fw.write(DxfGroup.toString(5, 5));
1027
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1028
                fw.write(DxfGroup.toString(70, 1));
1029
                // Aqui hay que crear un objeto DxfLType como el DxfLayer tambi?n basado en
1030
                // el lector de DXF de Mich.
1031
                /*DxfTABLE_LTYPE_ITEM ltype =
1032
                        new DxfTABLE_LTYPE_ITEM("CONTINUE", 0, "", 65, 0f, new float[0]);
1033
                fw.write(ltype.toString());*/
1034
                fw.write(DxfGroup.toString(0, "LTYPE"));
1035
                fw.write(DxfGroup.toString(5, 14));
1036
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1037
                fw.write(DxfGroup.toString(100, "AcDbLinetypeTableRecord"));
1038
                fw.write(DxfGroup.toString(2, "ByBlock"));
1039
                fw.write(DxfGroup.toString(70, 0));
1040
                fw.write(DxfGroup.toString(3, ""));
1041
                fw.write(DxfGroup.toString(72, 65));
1042
                fw.write(DxfGroup.toString(73, 0));
1043
                fw.write(DxfGroup.toString(40, 0.0, 4));
1044
                fw.write(DxfGroup.toString(0, "LTYPE"));
1045
                fw.write(DxfGroup.toString(5, 15));
1046
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1047
                fw.write(DxfGroup.toString(100, "AcDbLinetypeTableRecord"));
1048
                fw.write(DxfGroup.toString(2, "ByLayer"));
1049
                fw.write(DxfGroup.toString(70, 0));
1050
                fw.write(DxfGroup.toString(3, ""));
1051
                fw.write(DxfGroup.toString(72, 65));
1052
                fw.write(DxfGroup.toString(73, 0));
1053
                fw.write(DxfGroup.toString(40, 0.0, 4));
1054
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1055
        }
1056
    
1057
        /**
1058
         * Escritor de la tabla LAYER.
1059
         * @param fw
1060
         * @throws IOException
1061
         */
1062
        public void writeLayerTable(FileWriter fw) throws IOException {
1063
                fw.write(DxfGroup.toString(0, "TABLE"));
1064
                fw.write(DxfGroup.toString(2, "LAYER"));
1065
                fw.write(DxfGroup.toString(5, 2));
1066
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1067
                fw.write(DxfGroup.toString(70, 1));
1068
                //layer = new DxfLayer(layerName, 0, 131, "CONTINUOUS");
1069
                //fw.write(layer.toString());
1070
                //fw.write(((DxfEntityMaker) entityMaker).getLayers().toDxfString());
1071
                fw.write(DxfGroup.toString(0, "LAYER"));
1072
                fw.write(DxfGroup.toString(5, 10));
1073
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1074
                fw.write(DxfGroup.toString(100, "AcDbLayerTableRecord"));
1075
                fw.write(DxfGroup.toString(2, "0"));
1076
                fw.write(DxfGroup.toString(70, 0));
1077
                fw.write(DxfGroup.toString(62, 7));
1078
                fw.write(DxfGroup.toString(6, "CONTINUOUS"));
1079
                fw.write(DxfGroup.toString(390, "F"));
1080
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1081
        }
1082
    
1083
        /**
1084
         * Escritor de la tabla STYLE.
1085
         * @param fw
1086
         * @throws IOException
1087
         */
1088
        public void writeStyleTable(FileWriter fw) throws IOException {
1089
                fw.write(DxfGroup.toString(0, "TABLE"));
1090
                fw.write(DxfGroup.toString(2, "STYLE"));
1091
                fw.write(DxfGroup.toString(5, 3));
1092
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1093
                fw.write(DxfGroup.toString(70, 0));
1094
                /*fw.write(DxfGroup.toString(70, 1));
1095
                DxfTABLE_STYLE_ITEM style =
1096
                        new DxfTABLE_STYLE_ITEM("STANDARD", 0, 0f, 1f, 0f, 0, 1.0f, "xxx.txt", "yyy.txt");
1097
                fw.write(style.toString());*/
1098
                fw.write(DxfGroup.toString(0, "STYLE"));
1099
                fw.write(DxfGroup.toString(5, 11));
1100
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1101
                fw.write(DxfGroup.toString(100, "AcDbTextStyleTableRecord"));
1102
                fw.write(DxfGroup.toString(2, "Standard"));
1103
                fw.write(DxfGroup.toString(70, 0));
1104
                fw.write(DxfGroup.toString(71, 0));
1105
                fw.write(DxfGroup.toString(40, 0.0, 4));
1106
                fw.write(DxfGroup.toString(41, 1.0, 4));
1107
                fw.write(DxfGroup.toString(42, 2.5, 4));
1108
                fw.write(DxfGroup.toString(50, 0.0, 4));
1109
                fw.write(DxfGroup.toString(3, "txt"));
1110
                fw.write(DxfGroup.toString(4, ""));
1111
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1112
        }
1113
    
1114
        /**
1115
         * Escritor de la tabla VIEW.
1116
         * @param fw
1117
         * @throws IOException
1118
         */
1119
        public void writeViewTable(FileWriter fw) throws IOException {
1120
                fw.write(DxfGroup.toString(0, "TABLE"));
1121
                fw.write(DxfGroup.toString(2, "VIEW"));
1122
                fw.write(DxfGroup.toString(5, 6));
1123
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1124
                fw.write(DxfGroup.toString(70, 0));
1125
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1126
        }
1127
    
1128
        /**
1129
         * Escritor de la tabla UCS.
1130
         * @param fw
1131
         * @throws IOException
1132
         */
1133
        public void writeUCSTable(FileWriter fw) throws IOException {
1134
                fw.write(DxfGroup.toString(0, "TABLE"));
1135
                fw.write(DxfGroup.toString(2, "UCS"));
1136
                fw.write(DxfGroup.toString(5, 7));
1137
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1138
                fw.write(DxfGroup.toString(70, 0));
1139
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1140
        }
1141
    
1142
        /**
1143
         * Escritor de la tabla APPID.
1144
         * @param fw
1145
         * @throws IOException
1146
         */
1147
        public void writeAppidTable(FileWriter fw) throws IOException {
1148
                fw.write(DxfGroup.toString(0, "TABLE"));
1149
                fw.write(DxfGroup.toString(2, "APPID"));
1150
                fw.write(DxfGroup.toString(5, 9));
1151
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1152
                fw.write(DxfGroup.toString(70, 1));
1153
                fw.write(DxfGroup.toString(0, "APPID"));
1154
                fw.write(DxfGroup.toString(5, 12));
1155
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1156
                fw.write(DxfGroup.toString(100, "AcDbRegAppTableRecord"));
1157
                fw.write(DxfGroup.toString(2, "ACAD"));
1158
                fw.write(DxfGroup.toString(70, 1));
1159
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1160
        }
1161
    
1162
        /**
1163
         * Escritor de la tabla DIMSTYLE.
1164
         * @param fw
1165
         * @throws IOException
1166
         */
1167
        public void writeDimStyleTable(FileWriter fw) throws IOException {
1168
                fw.write(DxfGroup.toString(0, "TABLE"));
1169
                fw.write(DxfGroup.toString(2, "DIMSTYLE"));
1170
                fw.write(DxfGroup.toString(5, "A"));
1171
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1172
                fw.write(DxfGroup.toString(70, 0));
1173
                fw.write(DxfGroup.toString(100, "AcDbDimStyleTable"));
1174
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1175
        }
1176
    
1177
        /**
1178
         * Escritor de la tabla BLOCK_RECORD.
1179
         * @param fw
1180
         * @throws IOException
1181
         */
1182
        public void writeBlockRecordTable(FileWriter fw) throws IOException {
1183
                fw.write(DxfGroup.toString(0, "TABLE"));
1184
                fw.write(DxfGroup.toString(2, "BLOCK_RECORD"));
1185
                fw.write(DxfGroup.toString(5, 1));
1186
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
1187
                fw.write(DxfGroup.toString(70, 1));
1188
                fw.write(DxfGroup.toString(0, "BLOCK_RECORD"));
1189
                fw.write(DxfGroup.toString(5, "1F"));
1190
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1191
                fw.write(DxfGroup.toString(100, "AcDbBlockTableRecord"));
1192
                fw.write(DxfGroup.toString(2, "*Model_Space"));
1193
                fw.write(DxfGroup.toString(340, "22"));
1194
                fw.write(DxfGroup.toString(0, "BLOCK_RECORD"));
1195
                fw.write(DxfGroup.toString(5, "1B"));
1196
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1197
                fw.write(DxfGroup.toString(100, "AcDbBlockTableRecord"));
1198
                fw.write(DxfGroup.toString(2, "*Paper_Space"));
1199
                fw.write(DxfGroup.toString(340, "1E"));
1200
                fw.write(DxfGroup.toString(0, "BLOCK_RECORD"));
1201
                fw.write(DxfGroup.toString(5, "23"));
1202
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
1203
                fw.write(DxfGroup.toString(100, "AcDbBlockTableRecord"));
1204
                fw.write(DxfGroup.toString(2, "*Paper_Space0"));
1205
                fw.write(DxfGroup.toString(340, "26"));
1206
                fw.write(DxfGroup.toString(0, "ENDTAB"));
1207
        }
1208
    
1209
        /**
1210
         * Escritor de la secci?n de bloques por defecto de un DXF2000.
1211
         * @param fw
1212
         * @throws IOException
1213
         */
1214
        public void writeBlocks(FileWriter fw) throws IOException {
1215
                fw.write(DxfGroup.toString(0, "SECTION"));
1216
                fw.write(DxfGroup.toString(2, "BLOCKS"));
1217
                fw.write(DxfGroup.toString(0, "BLOCK"));
1218
                fw.write(DxfGroup.toString(5, "20"));
1219
                fw.write(DxfGroup.toString(100, "AcDbEntity"));
1220
                fw.write(DxfGroup.toString(8, "0"));
1221
                fw.write(DxfGroup.toString(100, "AcDbBlockBegin"));
1222
                fw.write(DxfGroup.toString(2, "*Model_Space"));
1223
                fw.write(DxfGroup.toString(70, 0));
1224
                fw.write(DxfGroup.toString(10, 0.0, 4));
1225
                fw.write(DxfGroup.toString(20, 0.0, 4));
1226
                fw.write(DxfGroup.toString(30, 0.0, 4));
1227
                fw.write(DxfGroup.toString(3, "*Model_Space"));
1228
                fw.write(DxfGroup.toString(1, ""));
1229
                fw.write(DxfGroup.toString(0, "ENDBLK"));
1230
                fw.write(DxfGroup.toString(5, "21"));
1231
                fw.write(DxfGroup.toString(100, "AcDbEntity"));
1232
                fw.write(DxfGroup.toString(8, "0"));
1233
                fw.write(DxfGroup.toString(100, "AcDbBlockEnd"));
1234
                fw.write(DxfGroup.toString(0, "BLOCK"));
1235
                fw.write(DxfGroup.toString(5, "1C"));
1236
                fw.write(DxfGroup.toString(100, "AcDbEntity"));
1237
                fw.write(DxfGroup.toString(67, 1));
1238
                fw.write(DxfGroup.toString(8, "0"));
1239
                fw.write(DxfGroup.toString(100, "AcDbBlockBegin"));
1240
                fw.write(DxfGroup.toString(2, "*Paper_Space"));
1241
                fw.write(DxfGroup.toString(70, 0));
1242
                fw.write(DxfGroup.toString(10, 0.0, 4));
1243
                fw.write(DxfGroup.toString(20, 0.0, 4));
1244
                fw.write(DxfGroup.toString(30, 0.0, 4));
1245
                fw.write(DxfGroup.toString(3, "*Paper_Space"));
1246
                fw.write(DxfGroup.toString(1, ""));
1247
                fw.write(DxfGroup.toString(0, "ENDBLK"));
1248
                fw.write(DxfGroup.toString(5, "1D"));
1249
                fw.write(DxfGroup.toString(100, "AcDbEntity"));
1250
                fw.write(DxfGroup.toString(67, 1));
1251
                fw.write(DxfGroup.toString(8, "0"));
1252
                fw.write(DxfGroup.toString(100, "AcDbBlockEnd"));
1253
                fw.write(DxfGroup.toString(0, "BLOCK"));
1254
                fw.write(DxfGroup.toString(5, "24"));
1255
                fw.write(DxfGroup.toString(100, "AcDbEntity"));
1256
                fw.write(DxfGroup.toString(8, "0"));
1257
                fw.write(DxfGroup.toString(100, "AcDbBlockBegin"));
1258
                fw.write(DxfGroup.toString(2, "*Paper_Space0"));
1259
                fw.write(DxfGroup.toString(70, 0));
1260
                fw.write(DxfGroup.toString(10, 0.0, 4));
1261
                fw.write(DxfGroup.toString(20, 0.0, 4));
1262
                fw.write(DxfGroup.toString(30, 0.0, 4));
1263
                fw.write(DxfGroup.toString(3, "*Paper_Space0"));
1264
                fw.write(DxfGroup.toString(1, ""));
1265
                fw.write(DxfGroup.toString(0, "ENDBLK"));
1266
                fw.write(DxfGroup.toString(5, "25"));
1267
                fw.write(DxfGroup.toString(100, "AcDbEntity"));
1268
                fw.write(DxfGroup.toString(8, "0"));
1269
                fw.write(DxfGroup.toString(100, "AcDbBlockEnd"));
1270
                fw.write(DxfGroup.toString(0, "ENDSEC"));
1271
        }
1272
    
1273
        /**
1274
         * Escritor de la secci?n ENTITIES de entidades.
1275
         * @param fw
1276
         * @throws IOException
1277
         */
1278
        public void writeEntities(FileWriter fw) throws IOException {
1279
                // ECRITURE DES FEATURES
1280
                fw.write(DxfGroup.toString(0, "SECTION"));
1281
                fw.write(DxfGroup.toString(2, "ENTITIES"));                
1282
                if (cadFlag) {
1283
                        fw.write(((DxfEntityMaker) entityMaker).getEntities().toDxfString());
1284
                } else {
1285
                        //fw.write(((DxfFeatureMaker) entityMaker).getObjects().toDxfString());                        
1286
                }
1287
                fw.write(DxfGroup.toString(0, "ENDSEC"));
1288
        }
1289
        
1290
        /**
1291
         * 050224, jmorell: Escritura de la secci?n OBJECTS seg?n QCAD.
1292
         * Writes a objects section. This section is needed in VER_R13.
1293
         * Note that this method currently only writes a faked OBJECTS section
1294
         * to make the file readable by Aut*cad.
1295
         */
1296
        public void writeObjects(FileWriter fw) throws IOException {
1297
            //int dicId, dicId2, dicId3, dicId4, dicId5;
1298
            //int dicId5;
1299

    
1300
            fw.write(DxfGroup.toString(  0, "SECTION"));
1301
            fw.write(DxfGroup.toString(  2, "OBJECTS"));
1302
            fw.write(DxfGroup.toString(  0, "DICTIONARY"));
1303
            //fw.write(DxfGroup.toString(5, 0xC);                            // C
1304
            fw.write(DxfGroup.toString(  5, "C"));
1305
            //fw.write(DxfGroup.toString(330, 0);
1306
            fw.write(DxfGroup.toString(100, "AcDbDictionary"));
1307
            fw.write(DxfGroup.toString(280, 0));
1308
            fw.write(DxfGroup.toString(281, 1));
1309
            fw.write(DxfGroup.toString(  3, "ACAD_GROUP"));
1310
            //fw.write(DxfGroup.toString(350, dw.getNextHandle());          // D
1311
            fw.write(DxfGroup.toString(350, "D"));          // D
1312
            fw.write(DxfGroup.toString(  3, "ACAD_LAYOUT"));
1313
            fw.write(DxfGroup.toString(350, "1A"));
1314
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+0);        // 1A
1315
            fw.write(DxfGroup.toString(  3, "ACAD_MLINESTYLE"));
1316
            fw.write(DxfGroup.toString(350, "17"));
1317
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+1);        // 17
1318
            fw.write(DxfGroup.toString(  3, "ACAD_PLOTSETTINGS"));
1319
            fw.write(DxfGroup.toString(350, "19"));
1320
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+2);        // 19
1321
            fw.write(DxfGroup.toString(  3, "ACAD_PLOTSTYLENAME"));
1322
            fw.write(DxfGroup.toString(350, "E"));
1323
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+3);        // E
1324
            fw.write(DxfGroup.toString(  3, "AcDbVariableDictionary"));
1325
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()));        // 2C
1326
            fw.write(DxfGroup.toString(350, "2C"));        // 2C
1327
            fw.write(DxfGroup.toString(  0, "DICTIONARY"));
1328
            fw.write(DxfGroup.toString(5, "D"));
1329
            //dw.handle();                                    // D
1330
            //fw.write(DxfGroup.toString(330, 0xC);
1331
            fw.write(DxfGroup.toString(100, "AcDbDictionary"));
1332
            fw.write(DxfGroup.toString(280, 0));
1333
            fw.write(DxfGroup.toString(281, 1));
1334
            fw.write(DxfGroup.toString(  0, "ACDBDICTIONARYWDFLT"));
1335
            fw.write(DxfGroup.toString(5, "E"));
1336
            //dicId4 = dw.handle();                           // E
1337
            //fw.write(DxfGroup.toString(330, 0xC);                       // C
1338
            fw.write(DxfGroup.toString(100, "AcDbDictionary"));
1339
            fw.write(DxfGroup.toString(281, 1));
1340
            fw.write(DxfGroup.toString(  3, "Normal"));
1341
            fw.write(DxfGroup.toString(350, "F"));
1342
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+5);        // F
1343
            fw.write(DxfGroup.toString(100, "AcDbDictionaryWithDefault"));
1344
            fw.write(DxfGroup.toString(340, "F"));
1345
            //fw.write(DxfGroup.toString(340, dw.getNextHandle()+5);        // F
1346
            fw.write(DxfGroup.toString(  0, "ACDBPLACEHOLDER"));
1347
            fw.write(DxfGroup.toString(5, "F"));
1348
            //dw.handle();                                    // F
1349
            //fw.write(DxfGroup.toString(330, dicId4);                      // E
1350
            fw.write(DxfGroup.toString(  0, "DICTIONARY"));
1351
            //dicId3 = dw.handle();                           // 17
1352
            fw.write(DxfGroup.toString(5, "17"));
1353
            //fw.write(DxfGroup.toString(330, 0xC);                       // C
1354
            fw.write(DxfGroup.toString(100, "AcDbDictionary"));
1355
            fw.write(DxfGroup.toString(280, 0));
1356
            fw.write(DxfGroup.toString(281, 1));
1357
            fw.write(DxfGroup.toString(  3, "Standard"));
1358
            fw.write(DxfGroup.toString(350, "18"));
1359
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+5);        // 18
1360
            fw.write(DxfGroup.toString(  0, "MLINESTYLE"));
1361
            fw.write(DxfGroup.toString(5, "18"));
1362
            //dw.handle();                                    // 18
1363
            //fw.write(DxfGroup.toString(330, dicId3);                      // 17
1364
            fw.write(DxfGroup.toString(100, "AcDbMlineStyle"));
1365
            fw.write(DxfGroup.toString(  2, "STANDARD"));
1366
            fw.write(DxfGroup.toString( 70, 0));
1367
            fw.write(DxfGroup.toString(  3, ""));
1368
            fw.write(DxfGroup.toString( 62, 256));
1369
            //dw.dxfReal( 51, 90.0);
1370
            fw.write(DxfGroup.toString( 51, 90.0, 4));
1371
            fw.write(DxfGroup.toString( 52, 90.0, 4));
1372
            fw.write(DxfGroup.toString( 71, 2));
1373
            fw.write(DxfGroup.toString( 49, 0.5, 4));
1374
            fw.write(DxfGroup.toString( 62, 256));
1375
            fw.write(DxfGroup.toString(  6, "BYLAYER"));
1376
            fw.write(DxfGroup.toString( 49, -0.5, 4));
1377
            fw.write(DxfGroup.toString( 62, 256));
1378
            fw.write(DxfGroup.toString(  6, "BYLAYER"));
1379
            fw.write(DxfGroup.toString(  0, "DICTIONARY"));
1380
            fw.write(DxfGroup.toString(5, "19"));
1381
            //dw.handle();                           // 17
1382
            //fw.write(DxfGroup.toString(330, 0xC);                       // C
1383
            fw.write(DxfGroup.toString(100, "AcDbDictionary"));
1384
            fw.write(DxfGroup.toString(280, 0));
1385
            fw.write(DxfGroup.toString(281, 1));
1386
            fw.write(DxfGroup.toString(  0, "DICTIONARY"));
1387
            //dicId2 = dw.handle();                           // 1A
1388
            fw.write(DxfGroup.toString(5, "1A"));
1389
            //fw.write(DxfGroup.toString(330, 0xC);
1390
            fw.write(DxfGroup.toString(100, "AcDbDictionary"));
1391
            fw.write(DxfGroup.toString(281, 1));
1392
            fw.write(DxfGroup.toString(  3, "Layout1"));
1393
            fw.write(DxfGroup.toString(350, "1E"));
1394
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+2);        // 1E
1395
            fw.write(DxfGroup.toString(  3, "Layout2"));
1396
            fw.write(DxfGroup.toString(350, "26"));
1397
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+4);        // 26
1398
            fw.write(DxfGroup.toString(  3, "Model"));
1399
            fw.write(DxfGroup.toString(350, "22"));
1400
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+5);        // 22
1401

    
1402
            fw.write(DxfGroup.toString(  0, "LAYOUT"));
1403
            fw.write(DxfGroup.toString(5, "1E"));
1404
            //dw.handle();                                    // 1E
1405
            //fw.write(DxfGroup.toString(330, dicId2);                      // 1A
1406
            fw.write(DxfGroup.toString(100, "AcDbPlotSettings"));
1407
            fw.write(DxfGroup.toString(  1, ""));
1408
            fw.write(DxfGroup.toString(  2, "C:\\Program Files\\AutoCAD 2002\\plotters\\DWF ePlot (optimized for plotting).pc3"));
1409
            fw.write(DxfGroup.toString(  4, ""));
1410
            fw.write(DxfGroup.toString(  6, ""));
1411
            fw.write(DxfGroup.toString( 40, 0.0, 4));
1412
            fw.write(DxfGroup.toString( 41, 0.0, 4));
1413
            fw.write(DxfGroup.toString( 42, 0.0, 4));
1414
            fw.write(DxfGroup.toString( 43, 0.0, 4));
1415
            fw.write(DxfGroup.toString( 44, 0.0, 4));
1416
            fw.write(DxfGroup.toString( 45, 0.0, 4));
1417
            fw.write(DxfGroup.toString( 46, 0.0, 4));
1418
            fw.write(DxfGroup.toString( 47, 0.0, 4));
1419
            fw.write(DxfGroup.toString( 48, 0.0, 4));
1420
            fw.write(DxfGroup.toString( 49, 0.0, 4));
1421
            fw.write(DxfGroup.toString(140, 0.0, 4));
1422
            fw.write(DxfGroup.toString(141, 0.0, 4));
1423
            fw.write(DxfGroup.toString(142, 1.0, 4));
1424
            fw.write(DxfGroup.toString(143, 1.0, 4));
1425
            fw.write(DxfGroup.toString( 70, 688));
1426
            fw.write(DxfGroup.toString( 72, 0));
1427
            fw.write(DxfGroup.toString( 73, 0));
1428
            fw.write(DxfGroup.toString( 74, 5));
1429
            fw.write(DxfGroup.toString(  7, ""));
1430
            fw.write(DxfGroup.toString( 75, 16));
1431
            fw.write(DxfGroup.toString(147, 1.0, 4));
1432
            fw.write(DxfGroup.toString(148, 0.0, 4));
1433
            fw.write(DxfGroup.toString(149, 0.0, 4));
1434
            fw.write(DxfGroup.toString(100, "AcDbLayout"));
1435
            fw.write(DxfGroup.toString(  1, "Layout1"));
1436
            fw.write(DxfGroup.toString( 70, 1));
1437
            fw.write(DxfGroup.toString( 71, 1));
1438
            fw.write(DxfGroup.toString( 10, 0.0, 4));
1439
            fw.write(DxfGroup.toString( 20, 0.0, 4));
1440
            fw.write(DxfGroup.toString( 11, 420.0, 4));
1441
            fw.write(DxfGroup.toString( 21, 297.0, 4));
1442
            fw.write(DxfGroup.toString( 12, 0.0, 4));
1443
            fw.write(DxfGroup.toString( 22, 0.0, 4));
1444
            fw.write(DxfGroup.toString( 32, 0.0, 4));
1445
            fw.write(DxfGroup.toString( 14, 1.000000000000000E+20, 4));
1446
            fw.write(DxfGroup.toString( 24, 1.000000000000000E+20, 4));
1447
            fw.write(DxfGroup.toString( 34, 1.000000000000000E+20, 4));
1448
            fw.write(DxfGroup.toString( 15, -1.000000000000000E+20, 4));
1449
            fw.write(DxfGroup.toString( 25, -1.000000000000000E+20, 4));
1450
            fw.write(DxfGroup.toString( 35, -1.000000000000000E+20, 4));
1451
            fw.write(DxfGroup.toString(146, 0.0, 4));
1452
            fw.write(DxfGroup.toString( 13, 0.0, 4));
1453
            fw.write(DxfGroup.toString( 23, 0.0, 4));
1454
            fw.write(DxfGroup.toString( 33, 0.0, 4));
1455
            fw.write(DxfGroup.toString( 16, 1.0, 4));
1456
            fw.write(DxfGroup.toString( 26, 0.0, 4));
1457
            fw.write(DxfGroup.toString( 36, 0.0, 4));
1458
            fw.write(DxfGroup.toString( 17, 0.0, 4));
1459
            fw.write(DxfGroup.toString( 27, 1.0, 4));
1460
            fw.write(DxfGroup.toString( 37, 0.0, 4));
1461
            fw.write(DxfGroup.toString( 76, 0));
1462
            //fw.write(DxfGroup.toString(330, dw.getPaperSpaceHandle());    // 1B
1463
            fw.write(DxfGroup.toString(330, "1B"));
1464
            fw.write(DxfGroup.toString(  0, "LAYOUT"));
1465
            fw.write(DxfGroup.toString(5, "22"));
1466
            //dw.handle();                                    // 22
1467
            //fw.write(DxfGroup.toString(330, dicId2);                      // 1A
1468
            fw.write(DxfGroup.toString(100, "AcDbPlotSettings"));
1469
            fw.write(DxfGroup.toString(  1, ""));
1470
            fw.write(DxfGroup.toString(  2, "C:\\Program Files\\AutoCAD 2002\\plotters\\DWF ePlot (optimized for plotting).pc3"));
1471
            fw.write(DxfGroup.toString(  4, ""));
1472
            fw.write(DxfGroup.toString(  6, ""));
1473
            fw.write(DxfGroup.toString( 40, 0.0, 4));
1474
            fw.write(DxfGroup.toString( 41, 0.0, 4));
1475
            fw.write(DxfGroup.toString( 42, 0.0, 4));
1476
            fw.write(DxfGroup.toString( 43, 0.0, 4));
1477
            fw.write(DxfGroup.toString( 44, 0.0, 4));
1478
            fw.write(DxfGroup.toString( 45, 0.0, 4));
1479
            fw.write(DxfGroup.toString( 46, 0.0, 4));
1480
            fw.write(DxfGroup.toString( 47, 0.0, 4));
1481
            fw.write(DxfGroup.toString( 48, 0.0, 4));
1482
            fw.write(DxfGroup.toString( 49, 0.0, 4));
1483
            fw.write(DxfGroup.toString(140, 0.0, 4));
1484
            fw.write(DxfGroup.toString(141, 0.0, 4));
1485
            fw.write(DxfGroup.toString(142, 1.0, 4));
1486
            fw.write(DxfGroup.toString(143, 1.0, 4));
1487
            fw.write(DxfGroup.toString( 70, 1712));
1488
            fw.write(DxfGroup.toString( 72, 0));
1489
            fw.write(DxfGroup.toString( 73, 0));
1490
            fw.write(DxfGroup.toString( 74, 0));
1491
            fw.write(DxfGroup.toString(  7, ""));
1492
            fw.write(DxfGroup.toString( 75, 0));
1493
            fw.write(DxfGroup.toString(147, 1.0, 4));
1494
            fw.write(DxfGroup.toString(148, 0.0, 4));
1495
            fw.write(DxfGroup.toString(149, 0.0, 4));
1496
            fw.write(DxfGroup.toString(100, "AcDbLayout"));
1497
            fw.write(DxfGroup.toString(  1, "Model"));
1498
            fw.write(DxfGroup.toString( 70, 1));
1499
            fw.write(DxfGroup.toString( 71, 0));
1500
            fw.write(DxfGroup.toString( 10, 0.0, 4));
1501
            fw.write(DxfGroup.toString( 20, 0.0, 4));
1502
            fw.write(DxfGroup.toString( 11, 12.0, 4));
1503
            fw.write(DxfGroup.toString( 21, 9.0, 4));
1504
            fw.write(DxfGroup.toString( 12, 0.0, 4));
1505
            fw.write(DxfGroup.toString( 22, 0.0, 4));
1506
            fw.write(DxfGroup.toString( 32, 0.0, 4));
1507
            fw.write(DxfGroup.toString( 14, 0.0, 4));
1508
            fw.write(DxfGroup.toString( 24, 0.0, 4));
1509
            fw.write(DxfGroup.toString( 34, 0.0, 4));
1510
            fw.write(DxfGroup.toString( 15, 0.0, 4));
1511
            fw.write(DxfGroup.toString( 25, 0.0, 4));
1512
            fw.write(DxfGroup.toString( 35, 0.0, 4));
1513
            fw.write(DxfGroup.toString(146, 0.0, 4));
1514
            fw.write(DxfGroup.toString( 13, 0.0, 4));
1515
            fw.write(DxfGroup.toString( 23, 0.0, 4));
1516
            fw.write(DxfGroup.toString( 33, 0.0, 4));
1517
            fw.write(DxfGroup.toString( 16, 1.0, 4));
1518
            fw.write(DxfGroup.toString( 26, 0.0, 4));
1519
            fw.write(DxfGroup.toString( 36, 0.0, 4));
1520
            fw.write(DxfGroup.toString( 17, 0.0, 4));
1521
            fw.write(DxfGroup.toString( 27, 1.0, 4));
1522
            fw.write(DxfGroup.toString( 37, 0.0, 4));
1523
            fw.write(DxfGroup.toString( 76, 0));
1524
            //fw.write(DxfGroup.toString(330, dw.getModelSpaceHandle());    // 1F
1525
            fw.write(DxfGroup.toString(330, "1F"));
1526
            fw.write(DxfGroup.toString(  0, "LAYOUT"));
1527
            //dw.handle();                                    // 26
1528
            fw.write(DxfGroup.toString(5, "26"));
1529
            //fw.write(DxfGroup.toString(330, dicId2);                      // 1A
1530
            fw.write(DxfGroup.toString(100, "AcDbPlotSettings"));
1531
            fw.write(DxfGroup.toString(  1, ""));
1532
            fw.write(DxfGroup.toString(  2, "C:\\Program Files\\AutoCAD 2002\\plotters\\DWF ePlot (optimized for plotting).pc3"));
1533
            fw.write(DxfGroup.toString(  4, ""));
1534
            fw.write(DxfGroup.toString(  6, ""));
1535
            fw.write(DxfGroup.toString( 40, 0.0, 4));
1536
            fw.write(DxfGroup.toString( 41, 0.0, 4));
1537
            fw.write(DxfGroup.toString( 42, 0.0, 4));
1538
            fw.write(DxfGroup.toString( 43, 0.0, 4));
1539
            fw.write(DxfGroup.toString( 44, 0.0, 4));
1540
            fw.write(DxfGroup.toString( 45, 0.0, 4));
1541
            fw.write(DxfGroup.toString( 46, 0.0, 4));
1542
            fw.write(DxfGroup.toString( 47, 0.0, 4));
1543
            fw.write(DxfGroup.toString( 48, 0.0, 4));
1544
            fw.write(DxfGroup.toString( 49, 0.0, 4));
1545
            fw.write(DxfGroup.toString(140, 0.0, 4));
1546
            fw.write(DxfGroup.toString(141, 0.0, 4));
1547
            fw.write(DxfGroup.toString(142, 1.0, 4));
1548
            fw.write(DxfGroup.toString(143, 1.0, 4));
1549
            fw.write(DxfGroup.toString( 70, 688));
1550
            fw.write(DxfGroup.toString( 72, 0));
1551
            fw.write(DxfGroup.toString( 73, 0));
1552
            fw.write(DxfGroup.toString( 74, 5));
1553
            fw.write(DxfGroup.toString(  7, ""));
1554
            fw.write(DxfGroup.toString( 75, 16));
1555
            fw.write(DxfGroup.toString(147, 1.0, 4));
1556
            fw.write(DxfGroup.toString(148, 0.0, 4));
1557
            fw.write(DxfGroup.toString(149, 0.0, 4));
1558
            fw.write(DxfGroup.toString(100, "AcDbLayout"));
1559
            fw.write(DxfGroup.toString(  1, "Layout2"));
1560
            fw.write(DxfGroup.toString( 70, 1));
1561
            fw.write(DxfGroup.toString( 71, 2));
1562
            fw.write(DxfGroup.toString( 10, 0.0, 4));
1563
            fw.write(DxfGroup.toString( 20, 0.0, 4));
1564
            fw.write(DxfGroup.toString( 11, 12.0, 4));
1565
            fw.write(DxfGroup.toString( 21, 9.0, 4));
1566
            fw.write(DxfGroup.toString( 12, 0.0, 4));
1567
            fw.write(DxfGroup.toString( 22, 0.0, 4));
1568
            fw.write(DxfGroup.toString( 32, 0.0, 4));
1569
            fw.write(DxfGroup.toString( 14, 0.0, 4));
1570
            fw.write(DxfGroup.toString( 24, 0.0, 4));
1571
            fw.write(DxfGroup.toString( 34, 0.0, 4));
1572
            fw.write(DxfGroup.toString( 15, 0.0, 4));
1573
            fw.write(DxfGroup.toString( 25, 0.0, 4));
1574
            fw.write(DxfGroup.toString( 35, 0.0, 4));
1575
            fw.write(DxfGroup.toString(146, 0.0, 4));
1576
            fw.write(DxfGroup.toString( 13, 0.0, 4));
1577
            fw.write(DxfGroup.toString( 23, 0.0, 4));
1578
            fw.write(DxfGroup.toString( 33, 0.0, 4));
1579
            fw.write(DxfGroup.toString( 16, 1.0, 4));
1580
            fw.write(DxfGroup.toString( 26, 0.0, 4));
1581
            fw.write(DxfGroup.toString( 36, 0.0, 4));
1582
            fw.write(DxfGroup.toString( 17, 0.0, 4));
1583
            fw.write(DxfGroup.toString( 27, 1.0, 4));
1584
            fw.write(DxfGroup.toString( 37, 0.0, 4));
1585
            fw.write(DxfGroup.toString( 76, 0));
1586
            //fw.write(DxfGroup.toString(330, dw.getPaperSpace0Handle());   // 23
1587
            fw.write(DxfGroup.toString(330, "23"));
1588
            fw.write(DxfGroup.toString(  0, "DICTIONARY"));
1589
            fw.write(DxfGroup.toString(5, 0x2E));
1590
            //dicId5 =
1591
            //dw.handle();                           // 2C
1592
            //fw.write(DxfGroup.toString(330, 0xC);                       // C
1593
            fw.write(DxfGroup.toString(100, "AcDbDictionary"));
1594
            fw.write(DxfGroup.toString(281, 1));
1595
            fw.write(DxfGroup.toString(  3, "DIMASSOC"));
1596
            //fw.write(DxfGroup.toString(350, 0x2F);
1597
            //fw.write(DxfGroup.toString(350, dw.getNextHandle()+1);        // 2E
1598
            fw.write(DxfGroup.toString(350, 0x30));        // 2E
1599
            fw.write(DxfGroup.toString(  3, "HIDETEXT"));
1600
            //fw.write(DxfGroup.toString(350, 0x2E);
1601
            //fw.write(DxfGroup.toString(350, dw.getNextHandle());        // 2D
1602
            fw.write(DxfGroup.toString(350, 0x2F));        // 2D
1603
            fw.write(DxfGroup.toString(  0, "DICTIONARYVAR"));
1604
            fw.write(DxfGroup.toString(5, 0x2F));
1605
            //dw.handle();                                    // 2E
1606
            //fw.write(DxfGroup.toString(330, dicId5);                      // 2C
1607
            fw.write(DxfGroup.toString(100, "DictionaryVariables"));
1608
            fw.write(DxfGroup.toString(280, 0));
1609
            fw.write(DxfGroup.toString(  1, 2));
1610
            fw.write(DxfGroup.toString(  0, "DICTIONARYVAR"));
1611
            fw.write(DxfGroup.toString(5, 0x30));
1612
            //dw.handle();                                    // 2D
1613
            //fw.write(DxfGroup.toString(330, dicId5);                      // 2C
1614
            fw.write(DxfGroup.toString(100, "DictionaryVariables"));
1615
            fw.write(DxfGroup.toString(280, 0));
1616
            fw.write(DxfGroup.toString(  1, 1));
1617
                fw.write(DxfGroup.toString(0, "ENDSEC"));
1618
        }
1619
        
1620
    /**
1621
     * Habilita la reproyecci?n cartogr?fica
1622
     */
1623
        public void reProject(ICoordTrans rp) {
1624
                System.out.println("Dxf: reproyectando ...");
1625
                entityMaker.reProject(rp);
1626
        }
1627

    
1628
        /* (non-Javadoc)
1629
         * @see org.cresques.io.GeoFile#close()
1630
         */
1631
        public void close() {
1632
                // TODO Auto-generated method stub
1633
                
1634
        }
1635
    
1636
        /**
1637
     * Informa sobre si estamos trabajando con el modelo de datos GIS o con el de CAD
1638
         * @return Returns the cadFlag.
1639
         */
1640
        public boolean isCadFlag() {
1641
                return cadFlag;
1642
        }
1643
    
1644
        /**
1645
     * Establece si trabajamos con el modelo de datos GIS o con el de CAD
1646
         * @param cadFlag The cadFlag to set.
1647
         */
1648
        public void setCadFlag(boolean cadFlag) {
1649
                this.cadFlag = cadFlag;
1650
        }
1651
}