Statistics
| Revision:

svn-gvsig-desktop / tags / Root_piloto3d / libraries / libCq CMS for java.old / src / org / cresques / io / DxfFile.java @ 9537

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

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

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

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

    
1639
        /* (non-Javadoc)
1640
         * @see org.cresques.io.GeoFile#close()
1641
         */
1642
        public void close() {
1643
                // TODO Auto-generated method stub
1644
                
1645
        }
1646
    
1647
        /**
1648
     * Informa sobre si estamos trabajando con el modelo de datos GIS o con el de CAD
1649
         * @return Returns the cadFlag.
1650
         */
1651
        public boolean isCadFlag() {
1652
                return cadFlag;
1653
        }
1654
    
1655
        /**
1656
     * Establece si trabajamos con el modelo de datos GIS o con el de CAD
1657
         * @param cadFlag The cadFlag to set.
1658
         */
1659
        public void setCadFlag(boolean cadFlag) {
1660
                this.cadFlag = cadFlag;
1661
        }
1662

    
1663
    /**
1664
     * @return Returns the dxf3DFlag.
1665
     */
1666
    public boolean isDxf3DFlag() {
1667
        return dxf3DFlag;
1668
    }
1669

    
1670
    /**
1671
     * @param dxf3DFlag The dxf3DFlag to set.
1672
     */
1673
    public void setDxf3DFlag(boolean dxf3DFlag) {
1674
        this.dxf3DFlag = dxf3DFlag;
1675
    }
1676
}