Statistics
| Revision:

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

History | View | Annotate | Download (30.4 KB)

1 2 luisw
package org.cresques.io;
2
3
import java.io.BufferedReader;
4
import java.io.FileNotFoundException;
5
import java.io.FileReader;
6 12 luisw
import java.io.FileWriter;
7 2 luisw
import java.io.IOException;
8
import java.io.InputStream;
9
import java.io.InputStreamReader;
10
import java.io.Reader;
11 12 luisw
import java.util.Date;
12 2 luisw
import java.util.Hashtable;
13
import java.util.Vector;
14 94 luisw
import org.cresques.cts.ICoordTrans;
15
import org.cresques.cts.IProjection;
16
import org.cresques.geo.Projected;
17 13 luisw
import org.cresques.px.Extent;
18 96 luisw
import org.cresques.px.IObjList;
19 13 luisw
import org.cresques.px.dxf.DxfEntityMaker;
20 502 jmorell
import org.cresques.px.dxf.DxfHeaderManager;
21
import org.cresques.px.dxf.DxfHeaderVariables;
22 2 luisw
23
public class DxfFile extends GeoFile {
24
25 111 jmorell
        private boolean cadFlag = true;
26
27 2 luisw
        long lineNr = 0;
28
29
        String buf = null;
30
31
        BufferedReader fi;
32
        long l = 0;
33
        int count = 0;
34
        DxfGroup grp = null;
35
36 9 luisw
        EntityFactory entityMaker = null;
37 502 jmorell
        VarSettings headerManager;
38 2 luisw
39 11 luisw
        /**
40
         * Crea los objetos en el Modelo correspondiente.
41
         * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
42
         */
43 94 luisw
        public interface EntityFactory extends Projected {
44 57 jmorell
                public void setAddingToBlock(boolean a);
45 9 luisw
                public void createLayer(DxfGroupVector v) throws Exception ;
46
                public void createPolyline(DxfGroupVector v) throws Exception ;
47
                public void addVertex(DxfGroupVector v) throws Exception ;
48
                public void endSeq() throws Exception ;
49
                public void createLwPolyline(DxfGroupVector v) throws Exception ;
50
                public void createLine(DxfGroupVector v) throws Exception ;
51
                public void createText(DxfGroupVector v) throws Exception ;
52 218 jmorell
                public void createMText(DxfGroupVector v) throws Exception ;
53 31 jmorell
                public void createPoint(DxfGroupVector v) throws Exception ;
54 35 jmorell
                public void createCircle(DxfGroupVector v) throws Exception ;
55 38 jmorell
                public void createArc(DxfGroupVector v) throws Exception ;
56 41 jmorell
                public void createInsert(DxfGroupVector v) throws Exception ;
57 9 luisw
                public void createSolid(DxfGroupVector v) throws Exception ;
58 90 jmorell
                public void createSpline(DxfGroupVector v) throws Exception ;
59 171 jmorell
                public void createAttdef(DxfGroupVector v) throws Exception ;
60
                public void createAttrib(DxfGroupVector v) throws Exception ;
61 57 jmorell
                public void createBlock(DxfGroupVector v) throws Exception ;
62
                public void endBlk(DxfGroupVector v) throws Exception ;
63 78 luisw
                void testBlocks();
64 13 luisw
                public Extent getExtent();
65 62 jmorell
                public Vector getBlkList();
66 301 jmorell
                // Para manejar los atributos almacenados en DXFs.
67
                public Vector getAttributes();
68
                public void depureAttributes();
69 96 luisw
                public IObjList getObjects();
70 9 luisw
        };
71
72 502 jmorell
        /**
73
         * Establece el estado de las variables propias de un DXF que est?n definidas
74
         * en la secci?n HEADER. Por ejemplo, la versi?n del DXF.
75
         * @author jmorell (jose.morell@gmail.com)
76
         * @version 15-dic-2004
77
         */
78
        public interface VarSettings {
79
80
                /**
81
                 * Establece la versi?n de Autocad en la que fue generado el DXF.
82
                 * @param v
83
                 * @throws Exception
84
                 */
85
                public void setAcadVersion(DxfGroupVector v) throws Exception ;
86
87
                /**
88
                 * Devuelve la versi?n de Autocad en la que fue generado el DXF.
89
                 * @return
90
                 */
91
                public String getAcadVersion();
92
93
                /**
94
                 * Devuelve el estado de las variables propias de un DXF
95
                 * @return
96
                 */
97
                public DxfHeaderVariables getDxfHeaderVars();
98
99
        };
100
101 94 luisw
        public DxfFile(IProjection proj, String name, EntityFactory maker) {
102 13 luisw
                super(proj, name);
103 2 luisw
                entityMaker = maker;
104 502 jmorell
                headerManager = new DxfHeaderManager();
105 2 luisw
        }
106
107 502 jmorell
        // 041215: Metiendole el interface VarSettings. No me gusta pero no se como
108
        // evitar que pierda el objeto.
109
        public DxfFile(IProjection proj, String name, EntityFactory maker, VarSettings dxfVars) {
110
                super(proj, name);
111
                entityMaker = maker;
112
                headerManager = dxfVars;
113
        }
114
115 2 luisw
        /**
116 96 luisw
         * Carga un .dxf
117 2 luisw
         */
118
        public GeoFile load() {
119
                System.out.println("Dxf: Cargando "+name+" ...");
120
                try {
121
                        if (ZipFileFolder.isUrl(name)) {
122
                                ZipFileFolder zFolder = new ZipFileFolder(name);
123
                                InputStream is = zFolder.getInputStream(name);
124
                                return load(new InputStreamReader(is));
125
                        } else
126
                                return load(new FileReader(name));
127
                } catch (FileNotFoundException fnfe) {
128
                        fnfe.printStackTrace();
129
                } catch (Exception e) {
130
                        System.err.println("Dxf: ERROR."+l+"lineas leidas");
131
                        e.printStackTrace();
132
                }
133
                return this;
134
        }
135
136
        public GeoFile load(Reader fr) throws NumberFormatException, Exception {
137
                System.out.println("Dxf: Cargando '"+name+"' ...");
138
                fi = new BufferedReader(fr);
139
                while ((grp = readGrp()) != null) {
140
                        l+=2;
141
142
                        if (grp.equals(0, "EOF"))                break;
143
                        if (grp.equals(0, "SECTION"))
144
                                readSection();
145
                }
146
                fi.close();
147 13 luisw
                extent.add(entityMaker.getExtent());
148 2 luisw
                System.out.println("Dxf: '"+name+"' cargado. ("+l+" l?neas).");
149
                this.lineNr = l;
150
                return this;
151
        }
152
153
        private DxfGroup readGrp() throws NumberFormatException, IOException {
154
                DxfGroup g = DxfGroup.read(fi);
155
                if (g != null) l += 2;
156 102 jmorell
                /*if (g.code == 8)
157
                        if (((String) g.data).length() < 1) {
158
                                System.err.println("a que un layer no puede ser ''?");
159
                                System.exit(1);
160
                        }*/
161 2 luisw
                return g;
162
        }
163
164
        private void readSection() throws NumberFormatException, Exception {
165
                while (true) {
166 96 luisw
                        grp = readGrp(); System.out.print("-1:"+grp);
167 2 luisw
                        if (grp.code == 2)
168
                                if (((String) grp.data).compareTo("HEADER") == 0)
169 502 jmorell
                                        readHeader();
170 2 luisw
                                else if (((String) grp.data).compareTo("CLASSES") == 0)
171
                                        readAnySection();
172
                                else if (((String) grp.data).compareTo("TABLES") == 0)
173
                                        readTables();
174
                                else if (((String) grp.data).compareTo("BLOCKS") == 0)
175 57 jmorell
                                        readBlocks();
176 2 luisw
                                else if (((String) grp.data).compareTo("ENTITIES") == 0)
177
                                        readEntities();
178
                                else if (((String) grp.data).compareTo("OBJECTS") == 0)
179
                                        readAnySection();
180
                                else {
181
                                        System.out.println("DxfRead: Seccion "+grp.data);
182
                                        readAnySection();
183
                                }
184
                        else
185
                                System.err.println("Dxf: Codigo/Seccion desconocidos" + grp);
186
                        if (grp.equals(0, "EOF")) break;
187
                        if (grp.equals(0, "ENDSEC")) break;
188
                }
189
        }
190
191
        private void readTables() throws NumberFormatException, Exception {
192 96 luisw
                System.out.println("Dxf: Seccion TABLAS, linea "+ l+ "grp ="+ grp);
193 2 luisw
                int layerCnt = 0;
194
                String tableAct = "NONAME";
195
196
                Hashtable tables = new Hashtable();
197
                Vector table = new Vector();
198
                DxfGroupVector v = new DxfGroupVector();
199
200 96 luisw
                grp = readGrp();// System.out.print("0:"+grp);
201 2 luisw
                while (true) {
202
                        if (grp.code == 0) {
203
                                String data = (String) grp.getData();
204
                                if (data.compareTo("ENDSEC") == 0 || data.compareTo("EOF") == 0)
205
                                        break;
206
                                else if (data.compareTo("ENDTAB") == 0) {
207
                                        tables.put(tableAct, table);
208
                                        table = new Vector();
209 96 luisw
                                        grp = readGrp();// System.out.print("1:"+grp);
210
211
                                        /**/if (tableAct.compareTo("LAYER") == 0 && v.size()>0) {
212
                                                entityMaker.createLayer(v);
213
                                                System.out.println("Dxf: Layer "+v.getDataAsString(2));
214
                                                layerCnt++;
215
                                                v.clear();
216
                                        }/**/
217 2 luisw
                                        continue;
218
                                } else {
219
                                        if (table.size()==1) {
220
                                                tableAct = v.getDataAsString(2);
221
                                                System.out.println("Dxf: Tabla "+tableAct);
222
                                        } else
223
                                                if (tableAct.compareTo("LAYER") == 0 && v.size()>0) {
224
                                                        entityMaker.createLayer(v);
225 96 luisw
                                                        System.out.println("Dxf: Layer "+v.getDataAsString(2));
226 2 luisw
                                                        layerCnt++;
227
                                                }
228
229
                                        v.clear();
230
                                        v.add(grp);
231
                                }
232
                                while (true) {
233 96 luisw
                                        grp = readGrp();// System.out.print("2:"+grp);
234 2 luisw
                                        if (grp.code == 0)        break;
235
                                        v.add(grp);
236
                                }
237
                                table.add(v);
238
                        } else {
239
                                System.err.println("Dxf: Error de secuencia");
240 96 luisw
                                grp = readGrp(); //System.out.print("3:"+grp);
241 2 luisw
                        }
242
                }
243
                System.out.println("Dxf: Seccion TABLAS: " + layerCnt + " Capas. ");
244
        }
245
246
        private void readAnySection() throws NumberFormatException, IOException {
247
                System.out.println("Dxf: Seccion '"+((String) grp.getData())+"', linea "+ l);
248
                while (true) {
249
                        grp = readGrp();
250
                        if (grp.equals(0, "ENDSEC")) break;
251
                        else if (grp.equals(0, "EOF")) break;
252
                }
253
        }
254
255 502 jmorell
        /**
256
         * Primera aproximaci?n a la implementaci?n de la lectura del HEADER. En principio
257
         * interesa que se lea la versi?n del DXF.
258
         * Para implementar esta parte del lector se ha optado por incluir el m?todo
259
         * setAcadVersion en el interface EntityFactory. A lo mejor conviene implementar
260
         * un nuevo interface VarSettings.
261
         * @throws NumberFormatException
262
         * @throws Exception
263
         */
264
        private void readHeader() throws NumberFormatException, Exception {
265
                System.out.println("Dxf: Seccion HEADER, linea "+ l);
266
                int variableCnt = 0;
267
                int cntVeces = 0;
268
                DxfGroupVector v = new DxfGroupVector();
269
                grp = readGrp();
270
                while (true) {
271
                        if (grp.equals(0, "EOF")) {
272
                                break;
273
                        }
274
                        else if (grp.code==9 || grp.code==0) {
275
                                if (v.size() > 0) {
276
                                        String lastVariable = (String) ((DxfGroup) v.get(0)).data;
277
                                        //System.out.println(lastVariable);
278
                                        if (lastVariable.compareTo("$ACADVER") == 0) {
279 689 jmorell
                                                //System.out.println("Aqui llega.");
280 502 jmorell
                                                headerManager.setAcadVersion(v);
281
                                        } else if (lastVariable.compareTo("ENDSEC") == 0) {
282 689 jmorell
                                                //System.out.println("Llega al ENDSEC.");
283 502 jmorell
                                                break;
284
                                        } else
285
                                                System.err.println("Dxf: Variable "+lastVariable+" desconocida.");
286
                                }
287
                                v.clear();
288
                                v.add(grp);
289
                                while (true) {
290
                                        grp = readGrp();
291
                                        if (grp.code == 9 || grp.code==0)        break;
292
                                        v.add(grp);
293
                                }
294
                                variableCnt++;
295
                        }
296
                        cntVeces++;
297
                }
298
                System.out.println("Dxf: Seccion HEADER, " + variableCnt + " variables, "+ cntVeces + " veces.");
299
                //System.out.println("Seccion HEADER, linea "+ l+ " (SALGO)");
300 689 jmorell
                System.out.println("readHeader: ACAD Version: " + headerManager.getDxfHeaderVars().getAcadVersion());
301 502 jmorell
        }
302
303 2 luisw
        private void readEntities() throws NumberFormatException, Exception {
304
                System.out.println("Dxf: Seccion ENTITIES, linea "+ l);
305
                int entityCnt = 0;
306
                int cntVeces = 0;
307
                DxfGroupVector v = new DxfGroupVector();
308
                grp = readGrp();
309
                while (true) {
310 69 jmorell
                        if (grp.equals(0, "EOF")) break;
311 2 luisw
                        else if (grp.code == 0) {
312
                                if (v.size() > 0) {
313
                                        String lastEntity = (String) ((DxfGroup) v.get(0)).data;
314
                                        if (lastEntity.compareTo("POLYLINE") == 0) {
315
                                                entityMaker.createPolyline(v);
316
                                        } else if (lastEntity.compareTo("VERTEX") == 0) {
317
                                                entityMaker.addVertex(v);
318
                                        } else if (lastEntity.compareTo("SEQEND") == 0) {
319
                                                entityMaker.endSeq();
320
                                        } else if (lastEntity.compareTo("LWPOLYLINE") == 0) {
321
                                                entityMaker.createLwPolyline(v);
322
                                        } else if (lastEntity.compareTo("LINE") == 0) {
323
                                                entityMaker.createLine(v);
324
                                        } else if (lastEntity.compareTo("TEXT") == 0) {
325
                                                entityMaker.createText(v);
326 218 jmorell
                                        } else if (lastEntity.compareTo("MTEXT") == 0) {
327
                                                entityMaker.createMText(v);
328 31 jmorell
                                        } else if (lastEntity.compareTo("POINT") == 0) {
329
                                                entityMaker.createPoint(v);
330 35 jmorell
                                        } else if (lastEntity.compareTo("CIRCLE") == 0) {
331
                                                entityMaker.createCircle(v);
332 38 jmorell
                                        } else if (lastEntity.compareTo("ARC") == 0) {
333
                                                entityMaker.createArc(v);
334 41 jmorell
                                        } else if (lastEntity.compareTo("INSERT") == 0) {
335
                                                entityMaker.createInsert(v);
336 2 luisw
                                        } else if (lastEntity.compareTo("SOLID") == 0) {
337
                                                entityMaker.createSolid(v);
338 90 jmorell
                                        } else if (lastEntity.compareTo("SPLINE") == 0) {
339
                                                entityMaker.createSpline(v);
340 171 jmorell
                                        } else if (lastEntity.compareTo("ATTRIB") == 0) {
341
                                                entityMaker.createAttrib(v);
342 59 jmorell
                                        } else if (lastEntity.compareTo("ENDSEC") == 0) {
343
                                                break;
344 2 luisw
                                        } else
345
                                                System.err.println("Dxf: Entidad "+lastEntity+" desconocida.");
346
                                }
347
                                v.clear();
348
                                v.add(grp);
349
                                while (true) {
350
                                        grp = readGrp();
351
                                        if (grp.code == 0)        break;
352
                                        v.add(grp);
353
                                }
354
                                entityCnt++;
355
                        }
356
                        cntVeces++;
357
                }
358 71 jmorell
                System.out.println("Dxf: Seccion ENTITIES, " + entityCnt + " entidades, "+ cntVeces + " veces.");
359 2 luisw
                //System.out.println("Seccion ENTITIES, linea "+ l+ " (SALGO)");
360
        }
361 8 luisw
362 57 jmorell
        private void readBlocks() throws NumberFormatException, Exception {
363
                System.out.println("Dxf: Seccion BLOCKS, linea "+ l);
364
                int blkCnt = 0;
365
                int cntVeces = 0;
366
                DxfGroupVector v = new DxfGroupVector();
367
                grp = readGrp();
368
                while (true) {
369 69 jmorell
                        if (grp.equals(0, "EOF")) break;
370 57 jmorell
                        else if (grp.code == 0) {
371
                                if (v.size() > 0) {
372
                                        String lastEntity = (String) ((DxfGroup) v.get(0)).data;
373
                                        if (lastEntity.compareTo("BLOCK") == 0) {
374 219 jmorell
                                                //System.out.println("readBlocks(): Empezamos a leer un bloque");
375 57 jmorell
                                                entityMaker.createBlock(v);
376
                                        } else if (lastEntity.compareTo("POLYLINE") == 0) {
377 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos una polilinea al bloque");
378 57 jmorell
                                                entityMaker.createPolyline(v);
379
                                        } else if (lastEntity.compareTo("VERTEX") == 0) {
380 96 luisw
                                                //System.out.println("readBlocks(): A?adimos un vertice a la polilinea");
381 57 jmorell
                                                entityMaker.addVertex(v);
382
                                        } else if (lastEntity.compareTo("SEQEND") == 0) {
383 96 luisw
                                                //System.out.println("readBlocks(): Cerramos una polilinea");
384 57 jmorell
                                                entityMaker.endSeq();
385
                                        } else if (lastEntity.compareTo("LWPOLYLINE") == 0) {
386 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos una lwpolilinea al bloque");
387 57 jmorell
                                                entityMaker.createLwPolyline(v);
388
                                        } else if (lastEntity.compareTo("LINE") == 0) {
389 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos una linea al bloque");
390 57 jmorell
                                                entityMaker.createLine(v);
391
                                        } else if (lastEntity.compareTo("TEXT") == 0) {
392 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos un texto al bloque");
393 57 jmorell
                                                entityMaker.createText(v);
394 218 jmorell
                                        } else if (lastEntity.compareTo("MTEXT") == 0) {
395
                                                //System.out.println("readBlocks(): A?adimos un m-texto al bloque");
396
                                                entityMaker.createMText(v);
397 57 jmorell
                                        } else if (lastEntity.compareTo("POINT") == 0) {
398 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos un punto al bloque");
399 57 jmorell
                                                entityMaker.createPoint(v);
400
                                        } else if (lastEntity.compareTo("CIRCLE") == 0) {
401 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos un circulo al bloque");
402 57 jmorell
                                                entityMaker.createCircle(v);
403
                                        } else if (lastEntity.compareTo("ARC") == 0) {
404 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos un arco al bloque");
405 57 jmorell
                                                entityMaker.createArc(v);
406
                                        } else if (lastEntity.compareTo("INSERT") == 0) {
407 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos un insert al bloque");
408 57 jmorell
                                                entityMaker.createInsert(v);
409
                                        } else if (lastEntity.compareTo("SOLID") == 0) {
410 186 jmorell
                                                //System.out.println("readBlocks(): A?adimos un solido al bloque");
411 57 jmorell
                                                entityMaker.createSolid(v);
412 171 jmorell
                                        } else if (lastEntity.compareTo("SPLINE") == 0) {
413
                                                entityMaker.createSpline(v);
414
                                        } else if (lastEntity.compareTo("ATTDEF") == 0) {
415
                                                entityMaker.createAttdef(v);
416 57 jmorell
                                        } else if (lastEntity.compareTo("ENDBLK") == 0) {
417 219 jmorell
                                                //System.out.println("readBlocks(): Cerramos un bloque"+v);
418 57 jmorell
                                                entityMaker.endBlk(v);
419 59 jmorell
                                        } else if (lastEntity.compareTo("ENDSEC") == 0) {
420
                                                break;
421 57 jmorell
                                        } else
422
                                                System.err.println("Dxf: Entidad de bloque "+lastEntity+" desconocida.");
423
                                }
424
                                v.clear();
425
                                v.add(grp);
426
                                while (true) {
427
                                        grp = readGrp();
428
                                        if (grp.code == 0)        break;
429
                                        v.add(grp);
430
                                }
431
                                blkCnt++;
432
                        }
433
                        cntVeces++;
434
                }
435 62 jmorell
436 78 luisw
                entityMaker.testBlocks();
437 301 jmorell
                // Cuando termina de leer la secci?n de bloques se asegura de que todos los campos
438
                // son distintos.
439 440 jmorell
                //System.out.println("readBlocks(): entityMaker.getAttributes().size() = " + entityMaker.getAttributes().size());
440 301 jmorell
                entityMaker.depureAttributes();
441 440 jmorell
                //System.out.println("readBlocks(): entityMaker.getAttributes().size() = " + entityMaker.getAttributes().size());
442 59 jmorell
                System.out.println("Dxf: Seccion BLOCKS, " + blkCnt + " elementos de bloque. "+ cntVeces + " veces.");
443 57 jmorell
        }
444
445 96 luisw
        public IObjList getObjects() {
446
                return this.entityMaker.getObjects();
447
        }
448 79 jmorell
449 12 luisw
        public void save(String fName) throws IOException {
450 14 luisw
                long t2, t1;
451
                t1 = getTime();
452 12 luisw
                fName = DataSource.normalize(fName);
453
                FileWriter fw = new FileWriter(fName);
454 13 luisw
                // COMMENTAIRES DU TRADUCTEUR
455
//                fw.write(DxfGroup.toString(999, Integer.toString(features.size()) + " features"));
456
                fw.write(DxfGroup.toString(999, "TRANSLATION BY geo.cresques.io.DxfFile"));
457
                fw.write(DxfGroup.toString(999, "DATE : " + (new Date()).toString()));
458 19 luisw
                //writeHeader(fw);
459
                //writeTables(fw);
460 12 luisw
                writeEntities(fw);
461 13 luisw
                fw.write(DxfGroup.toString(0, "EOF"));
462
                fw.flush();
463 12 luisw
                fw.close();
464 14 luisw
                t2 = getTime();
465
                System.out.println("DxfFile.save(): Tiempo salvando: " + (t2-t1)/1000 + " seg.");
466 8 luisw
        }
467
468 12 luisw
        public void writeHeader(FileWriter fw) throws IOException {
469 13 luisw
                fw.write(DxfGroup.toString(0, "SECTION"));
470
                fw.write(DxfGroup.toString(2, "HEADER"));
471
                fw.write(DxfGroup.toString(9, "$ACADVER"));
472 17 luisw
                        fw.write(DxfGroup.toString(1, "AC1009"));
473
                fw.write(DxfGroup.toString(9, "$INSBASE"));
474
                        fw.write(DxfGroup.toString(10, 0.0, 1));
475
                        fw.write(DxfGroup.toString(20, 0.0, 1));
476
                        fw.write(DxfGroup.toString(30, 0.0, 1));
477
                fw.write(DxfGroup.toString(9, "$EXTMIN"));
478
                        fw.write(DxfGroup.toString(10, extent.minX(), 6));
479
                        fw.write(DxfGroup.toString(20, extent.minY(), 6));
480
                        fw.write(DxfGroup.toString(30, 0.0, 6));
481 13 luisw
                fw.write(DxfGroup.toString(9, "$EXTMAX"));
482
                        fw.write(DxfGroup.toString(10, extent.maxX(), 6));
483
                        fw.write(DxfGroup.toString(20, extent.maxY(), 6));
484
                        fw.write(DxfGroup.toString(30, 0.0, 6));
485 17 luisw
                fw.write(DxfGroup.toString(9, "$LIMMIN"));
486 13 luisw
                        fw.write(DxfGroup.toString(10, extent.minX(), 6));
487
                        fw.write(DxfGroup.toString(20, extent.minY(), 6));
488
                fw.write(DxfGroup.toString(9, "$LIMMAX"));
489
                        fw.write(DxfGroup.toString(10, extent.maxX(), 6));
490
                        fw.write(DxfGroup.toString(20, extent.maxY(), 6));
491 17 luisw
                fw.write(DxfGroup.toString(9, "$ORTHOMODE")+DxfGroup.toString(70, 0));
492
                fw.write(DxfGroup.toString(9, "$REGENMODE")+DxfGroup.toString(70, 1));
493
                fw.write(DxfGroup.toString(9, "$FILLMODE")+        DxfGroup.toString(70, 1));
494
                fw.write(DxfGroup.toString(9, "$QTEXTMODE")+DxfGroup.toString(70, 0));
495
                fw.write(DxfGroup.toString(9, "$MIRRTEXT")+        DxfGroup.toString(70, 1));
496
                fw.write(DxfGroup.toString(9, "$DRAGMODE")+        DxfGroup.toString(70, 2));
497
                fw.write(DxfGroup.toString(9, "$LTSCALE")+        DxfGroup.toString(40, 1.0, 1));
498
                fw.write(DxfGroup.toString(9, "$OSMODE")+        DxfGroup.toString(70, 0));
499
                fw.write(DxfGroup.toString(9, "$ATTMODE")+        DxfGroup.toString(70, 1));
500 19 luisw
                fw.write(DxfGroup.toString(9, "$TEXTSIZE")+        DxfGroup.toString(40, 0.2, 1));
501
                fw.write(DxfGroup.toString(9, "$TRACEWID")+        DxfGroup.toString(40, 0.05, 2));
502
                fw.write(DxfGroup.toString(9, "$TEXTSTYLE")+        DxfGroup.toString(7, "STANDARD"));
503 17 luisw
                fw.write(DxfGroup.toString(9, "$CLAYER")+        DxfGroup.toString(8, "0"));
504
                fw.write(DxfGroup.toString(9, "$CELTYPE")+        DxfGroup.toString(6, "CONTINUOUS"));
505
                fw.write(DxfGroup.toString(9, "$CECOLOR")+        DxfGroup.toString(62, 256));
506
                fw.write(DxfGroup.toString(9, "$DIMSCALE")+        DxfGroup.toString(40, 1.0, 1));
507
                fw.write(DxfGroup.toString(9, "$DIMASZ")+        DxfGroup.toString(40, 0.18, 2));
508
                fw.write(DxfGroup.toString(9, "$DIMEXO")+        DxfGroup.toString(40, 0.0625, 4));
509
                fw.write(DxfGroup.toString(9, "$DIMDLI")+        DxfGroup.toString(40, 0.38, 2));
510
                fw.write(DxfGroup.toString(9, "$DIMRND")+        DxfGroup.toString(40, 0.0, 1));
511
                fw.write(DxfGroup.toString(9, "$DIMDLE")+        DxfGroup.toString(40, 0.0, 1));
512
                fw.write(DxfGroup.toString(9, "$DIMEXE")+        DxfGroup.toString(40, 0.18, 2));
513
                fw.write(DxfGroup.toString(9, "$DIMTP")+        DxfGroup.toString(40, 0.0, 1));
514
                fw.write(DxfGroup.toString(9, "$DIMTM")+        DxfGroup.toString(40, 0.0, 1));
515
                fw.write(DxfGroup.toString(9, "$DIMTXT")+        DxfGroup.toString(40, 0.18, 2));
516
                fw.write(DxfGroup.toString(9, "$DIMCEN")+        DxfGroup.toString(40, 0.09, 2));
517
                fw.write(DxfGroup.toString(9, "$DIMTSZ")+        DxfGroup.toString(40, 0.0, 1));
518 18 luisw
                fw.write(DxfGroup.toString(9,"$DIMTOL")+        DxfGroup.toString(70,0));
519
                fw.write(DxfGroup.toString(9,"$DIMLIM")+        DxfGroup.toString(70,0));
520
                fw.write(DxfGroup.toString(9,"$DIMTIH")+        DxfGroup.toString(70,1));
521
                fw.write(DxfGroup.toString(9,"$DIMTOH")+        DxfGroup.toString(70,1));
522
                fw.write(DxfGroup.toString(9,"$DIMSE1")+        DxfGroup.toString(70,0));
523
                fw.write(DxfGroup.toString(9,"$DIMSE2")+        DxfGroup.toString(70,0));
524
                fw.write(DxfGroup.toString(9,"$DIMTAD")+        DxfGroup.toString(70,0));
525
                fw.write(DxfGroup.toString(9,"$DIMZIN")+        DxfGroup.toString(70,0));
526
                fw.write(DxfGroup.toString(9,"$DIMBLK")+        DxfGroup.toString(1,""));
527
                fw.write(DxfGroup.toString(9,"$DIMASO")+        DxfGroup.toString(70,1));
528
                fw.write(DxfGroup.toString(9,"$DIMSHO")+        DxfGroup.toString(70,1));
529
                fw.write(DxfGroup.toString(9,"$DIMPOST")+        DxfGroup.toString(1,""));
530
                fw.write(DxfGroup.toString(9,"$DIMAPOST")+        DxfGroup.toString(1,""));
531
                fw.write(DxfGroup.toString(9,"$DIMALT")+        DxfGroup.toString(70,0));
532
                fw.write(DxfGroup.toString(9,"$DIMALTD")+        DxfGroup.toString(70,2));
533
                fw.write(DxfGroup.toString(9,"$DIMALTF")+        DxfGroup.toString(40,25.4,1));
534
                fw.write(DxfGroup.toString(9,"$DIMLFAC")+        DxfGroup.toString(40,1.0,1));
535
                fw.write(DxfGroup.toString(9,"$DIMTOFL")+        DxfGroup.toString(70,0));
536
                fw.write(DxfGroup.toString(9,"$DIMTVP")+        DxfGroup.toString(40,0.0,1));
537
                fw.write(DxfGroup.toString(9,"$DIMTIX")+        DxfGroup.toString(70,0));
538
                fw.write(DxfGroup.toString(9,"$DIMSOXD")+        DxfGroup.toString(70,0));
539
                fw.write(DxfGroup.toString(9,"$DIMSAH")+        DxfGroup.toString(70,0));
540
                fw.write(DxfGroup.toString(9,"$DIMBLK1")+        DxfGroup.toString(1,""));
541
                fw.write(DxfGroup.toString(9,"$DIMBLK2")+        DxfGroup.toString(1,""));
542
                fw.write(DxfGroup.toString(9,"$DIMSTYLE")+        DxfGroup.toString(2,"STANDARD"));
543
                fw.write(DxfGroup.toString(9,"$DIMCLRD")+        DxfGroup.toString(70,0));
544
                fw.write(DxfGroup.toString(9,"$DIMCLRE")+        DxfGroup.toString(70,0));
545
                fw.write(DxfGroup.toString(9,"$DIMCLRT")+        DxfGroup.toString(70,0));
546
                fw.write(DxfGroup.toString(9,"$DIMTFAC")+        DxfGroup.toString(40,1.0,1));
547
                fw.write(DxfGroup.toString(9,"$DIMGAP")+        DxfGroup.toString(40,0.09,2));
548
                fw.write(DxfGroup.toString(9,"$LUNITS")+        DxfGroup.toString(70,2));
549
                fw.write(DxfGroup.toString(9,"$LUPREC")+        DxfGroup.toString(70,4));
550
                fw.write(DxfGroup.toString(9,"$AXISMODE")+        DxfGroup.toString(70,0));
551
                fw.write(DxfGroup.toString(9,"$AXISUNIT"));
552
                fw.write(DxfGroup.toString(10,0.0,1));
553
                fw.write(DxfGroup.toString(20,0.0,1));
554
                fw.write(DxfGroup.toString(9,"$SKETCHINC")+        DxfGroup.toString(40,0.1,1));
555
                fw.write(DxfGroup.toString(9,"$FILLETRAD")+        DxfGroup.toString(40,0.0,1));
556
                fw.write(DxfGroup.toString(9,"$AUNITS")+        DxfGroup.toString(70,0));
557
                fw.write(DxfGroup.toString(9,"$AUPREC")+        DxfGroup.toString(70,0));
558
                fw.write(DxfGroup.toString(9,"$MENU")+                DxfGroup.toString(1,"acad"));
559
                fw.write(DxfGroup.toString(9,"$ELEVATION")+        DxfGroup.toString(40,0.0,1));
560
                fw.write(DxfGroup.toString(9,"$PELEVATION")+DxfGroup.toString(40,0.0,1));
561
                fw.write(DxfGroup.toString(9,"$THICKNESS")+        DxfGroup.toString(40,0.0,1));
562
                fw.write(DxfGroup.toString(9,"$LIMCHECK")+        DxfGroup.toString(70,0));
563
                fw.write(DxfGroup.toString(9,"$BLIPMODE")+        DxfGroup.toString(70,1));
564
                fw.write(DxfGroup.toString(9,"$CHAMFERA")+        DxfGroup.toString(40,0.0,1));
565
                fw.write(DxfGroup.toString(9,"$CHAMFERB")+        DxfGroup.toString(40,0.0,1));
566
                fw.write(DxfGroup.toString(9,"$SKPOLY")+        DxfGroup.toString(70,0));
567
                fw.write(DxfGroup.toString(9,"$TDCREATE")+        DxfGroup.toString(40,2453116.436828704,9));
568
                fw.write(DxfGroup.toString(9,"$TDUPDATE")+        DxfGroup.toString(40,2453116.436828704,9));
569
                fw.write(DxfGroup.toString(9,"$TDINDWG")+        DxfGroup.toString(40,0.0000000000,10));
570
                fw.write(DxfGroup.toString(9,"$TDUSRTIMER")+DxfGroup.toString(40,0.0000000000,10));
571
                fw.write(DxfGroup.toString(9,"$USRTIMER")+        DxfGroup.toString(70,1));
572
                fw.write(DxfGroup.toString(9,"$ANGBASE")+        DxfGroup.toString(50,0.0,1));
573
                fw.write(DxfGroup.toString(9,"$ANGDIR")+        DxfGroup.toString(70,0));
574
                fw.write(DxfGroup.toString(9,"$PDMODE")+        DxfGroup.toString(70,0));
575
                fw.write(DxfGroup.toString(9,"$PDSIZE")+        DxfGroup.toString(40,0.0,1));
576
                fw.write(DxfGroup.toString(9,"$PLINEWID")+        DxfGroup.toString(40,0.0,1));
577
                fw.write(DxfGroup.toString(9,"$COORDS")+        DxfGroup.toString(70,0));
578
                fw.write(DxfGroup.toString(9,"$SPLFRAME")+        DxfGroup.toString(70,0));
579
                fw.write(DxfGroup.toString(9,"$SPLINETYPE")+DxfGroup.toString(70,6));
580
                fw.write(DxfGroup.toString(9,"$SPLINESEGS")+DxfGroup.toString(70,10));
581
                fw.write(DxfGroup.toString(9,"$ATTDIA")+        DxfGroup.toString(70,0));
582
                fw.write(DxfGroup.toString(9,"$ATTREQ")+        DxfGroup.toString(70,1));
583
                fw.write(DxfGroup.toString(9,"$HANDLING")+        DxfGroup.toString(70,1));
584
                fw.write(DxfGroup.toString(9,"$HANDSEED")+        DxfGroup.toString(5,"394B"));
585
                fw.write(DxfGroup.toString(9,"$SURFTAB1")+        DxfGroup.toString(70,6));
586
                fw.write(DxfGroup.toString(9,"$SURFTAB2")+        DxfGroup.toString(70,6));
587
                fw.write(DxfGroup.toString(9,"$SURFTYPE")+        DxfGroup.toString(70,6));
588
                fw.write(DxfGroup.toString(9,"$SURFU")+                DxfGroup.toString(70,6));
589
                fw.write(DxfGroup.toString(9,"$SURFV")+                DxfGroup.toString(70,6));
590
                fw.write(DxfGroup.toString(9,"$UCSNAME")+        DxfGroup.toString(2,""));
591
                fw.write(DxfGroup.toString(9,"$UCSORG"));
592
                fw.write(DxfGroup.toString(10,0.0,1));
593
                fw.write(DxfGroup.toString(20,0.0,1));
594
                fw.write(DxfGroup.toString(30,0.0,1));
595
                fw.write(DxfGroup.toString(9,"$UCSXDIR"));
596
                fw.write(DxfGroup.toString(10,1.0,1));
597
                fw.write(DxfGroup.toString(20,0.0,1));
598
                fw.write(DxfGroup.toString(30,0.0,1));
599
                fw.write(DxfGroup.toString(9,"$UCSYDIR"));
600
                fw.write(DxfGroup.toString(10,0.0,1));
601
                fw.write(DxfGroup.toString(20,1.0,1));
602
                fw.write(DxfGroup.toString(30,0.0,1));
603
                fw.write(DxfGroup.toString(9,"$PUCSNAME")+        DxfGroup.toString(2,""));
604
                fw.write(DxfGroup.toString(9,"$PUCSORG"));
605
                fw.write(DxfGroup.toString(10,0.0,1));
606
                fw.write(DxfGroup.toString(20,0.0,1));
607
                fw.write(DxfGroup.toString(30,0.0,1));
608
                fw.write(DxfGroup.toString(9,"$PUCSXDIR"));
609
                fw.write(DxfGroup.toString(10,1.0,1));
610
                fw.write(DxfGroup.toString(20,0.0,1));
611
                fw.write(DxfGroup.toString(30,0.0,1));
612
                fw.write(DxfGroup.toString(9,"$PUCSYDIR"));
613
                fw.write(DxfGroup.toString(10,0.0,1));
614
                fw.write(DxfGroup.toString(20,1.0,1));
615
                fw.write(DxfGroup.toString(30,0.0,1));
616
                fw.write(DxfGroup.toString(9,"$USERI1")+        DxfGroup.toString(70,0));
617
                fw.write(DxfGroup.toString(9,"$USERI2")+        DxfGroup.toString(70,0));
618
                fw.write(DxfGroup.toString(9,"$USERI3")+        DxfGroup.toString(70,0));
619
                fw.write(DxfGroup.toString(9,"$USERI4")+        DxfGroup.toString(70,0));
620
                fw.write(DxfGroup.toString(9,"$USERI5")+        DxfGroup.toString(70,0));
621
                fw.write(DxfGroup.toString(9,"$USERR1")+        DxfGroup.toString(40,0.0,1));
622
                fw.write(DxfGroup.toString(9,"$USERR2")+        DxfGroup.toString(40,0.0,1));
623
                fw.write(DxfGroup.toString(9,"$USERR3")+        DxfGroup.toString(40,0.0,1));
624
                fw.write(DxfGroup.toString(9,"$USERR4")+        DxfGroup.toString(40,0.0,1));
625
                fw.write(DxfGroup.toString(9,"$USERR5")+        DxfGroup.toString(40,0.0,1));
626
                fw.write(DxfGroup.toString(9,"$WORLDVIEW")+        DxfGroup.toString(70,1));
627
                fw.write(DxfGroup.toString(9,"$SHADEDGE")+        DxfGroup.toString(70,3));
628
                fw.write(DxfGroup.toString(9,"$SHADEDIF")+        DxfGroup.toString(70,70));
629
                fw.write(DxfGroup.toString(9,"$TILEMODE")+        DxfGroup.toString(70,1));
630
                fw.write(DxfGroup.toString(9,"$MAXACTVP")+        DxfGroup.toString(70,16));
631
                fw.write(DxfGroup.toString(9,"$PINSBASE"));
632
                fw.write(DxfGroup.toString(10,0.0,1));
633
                fw.write(DxfGroup.toString(20,0.0,1));
634
                fw.write(DxfGroup.toString(30,0.0,1));
635
                fw.write(DxfGroup.toString(9,"$PLIMCHECK")+        DxfGroup.toString(70,0));
636
                fw.write(DxfGroup.toString(9,"$PEXTMIN"));
637
                fw.write(DxfGroup.toString(10,"-1.000000E+20"));
638
                fw.write(DxfGroup.toString(20,"-1.000000E+20"));
639
                fw.write(DxfGroup.toString(30,"-1.000000E+20"));
640
                fw.write(DxfGroup.toString(9,"$PEXTMAX"));
641
                fw.write(DxfGroup.toString(10,"-1.000000E+20"));
642
                fw.write(DxfGroup.toString(20,"-1.000000E+20"));
643
                fw.write(DxfGroup.toString(30,"-1.000000E+20"));
644
                fw.write(DxfGroup.toString(9,"$PLIMMIN"));
645
                fw.write(DxfGroup.toString(10,0.0,1));
646
                fw.write(DxfGroup.toString(20,0.0,1));
647
                fw.write(DxfGroup.toString(9,"$PLIMMAX"));
648
                fw.write(DxfGroup.toString(10,12.0,1));
649
                fw.write(DxfGroup.toString(20,9.0,1));
650
                fw.write(DxfGroup.toString(9,"$UNITMODE")+        DxfGroup.toString(70,0));
651
                fw.write(DxfGroup.toString(9,"$VISRETAIN")+        DxfGroup.toString(70,0));
652
                fw.write(DxfGroup.toString(9,"$PLINEGEN")+        DxfGroup.toString(70,1));
653
                fw.write(DxfGroup.toString(9,"$PSLTSCALE")+        DxfGroup.toString(70,0));
654
                fw.write(DxfGroup.toString(9,"$TREEDEPTH")+        DxfGroup.toString(70,3020));
655
                fw.write(DxfGroup.toString(9,"$DWGCODEPAGE")+DxfGroup.toString(3,"ansi_1252"));
656
/*
657 17 luisw
                fw.write(DxfGroup.toString(9, "$ELEVATION"));
658
                        fw.write(DxfGroup.toString(40, 0.0, 3));
659
                fw.write(DxfGroup.toString(9, "$LIMCHECK"));
660
                        fw.write(DxfGroup.toString(70, 1));
661 13 luisw
                fw.write(DxfGroup.toString(9, "$LUNITS"));
662
                        fw.write(DxfGroup.toString(70, 2));
663
                fw.write(DxfGroup.toString(9, "$LUPREC"));
664 18 luisw
                        fw.write(DxfGroup.toString(70, 2));*/
665 13 luisw
                fw.write(DxfGroup.toString(0, "ENDSEC"));
666 12 luisw
        }
667
668 13 luisw
        public void writeTables(FileWriter fw) throws IOException {
669
                fw.write(DxfGroup.toString(0, "SECTION"));
670
                fw.write(DxfGroup.toString(2, "TABLES"));
671
                //writeStyleTable(fw);
672
                //writeLTypeTable(fw);
673 17 luisw
                //writeAppidTable(fw);
674 13 luisw
                writeLayerTable(fw);
675
                fw.write(DxfGroup.toString(0, "ENDSEC"));
676
677
                fw.write(DxfGroup.toString(0, "ENDBLK"));
678 12 luisw
        }
679 16 luisw
        /*
680
         *   0
681
TABLE
682
  2
683
APPID
684
  5
685
14
686
100
687
AcDbSymbolTable
688
 70
689
     1
690
  0
691
APPID
692
  5
693
15
694
100
695
AcDbSymbolTableRecord
696
100
697
AcDbRegAppTableRecord
698
  2
699
ACAD
700
 70
701
     0
702
  0
703
ENDTAB
704
         */
705
        public void writeAppidTable(FileWriter fw) throws IOException {
706
                fw.write(DxfGroup.toString(0, "TABLE"));
707
                fw.write(DxfGroup.toString(2, "APPID"));
708
                fw.write(DxfGroup.toString(5, 14));
709
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
710
                fw.write(DxfGroup.toString(0, "APPID"));
711
                fw.write(DxfGroup.toString(5, 15));
712
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
713
                fw.write(DxfGroup.toString(100, "AcDbRegAppTableRecord"));
714
                fw.write(DxfGroup.toString(2, "ACAD"));
715
                fw.write(DxfGroup.toString(70, 1));
716
                fw.write(DxfGroup.toString(0, "ENDTAB"));
717
        }
718 12 luisw
719 13 luisw
        /*public void writeStyleTable(FileWriter fw) throws IOException {
720
                fw.write(DxfGroup.toString(0, "TABLE"));
721
                fw.write(DxfGroup.toString(2, "STYLE"));
722
                fw.write(DxfGroup.toString(70, 1));
723
                DxfTABLE_STYLE_ITEM style =
724
                        new DxfTABLE_STYLE_ITEM("STANDARD", 0, 0f, 1f, 0f, 0, 1.0f, "xxx.txt", "yyy.txt");
725
                fw.write(style.toString());
726
                fw.write(DxfGroup.toString(0, "ENDTAB"));
727
        }*/
728
729
        /*public void writeLTypeTable(FileWriter fw) throws IOException {
730
                fw.write(DxfGroup.toString(0, "TABLE"));
731
                fw.write(DxfGroup.toString(2, "LTYPE"));
732
                fw.write(DxfGroup.toString(70, 1));
733
                DxfTABLE_LTYPE_ITEM ltype =
734
                        new DxfTABLE_LTYPE_ITEM("CONTINUE", 0, "", 65, 0f, new float[0]);
735
                fw.write(ltype.toString());
736
                fw.write(DxfGroup.toString(0, "ENDTAB"));
737
        }*/
738
739
        public void writeLayerTable(FileWriter fw) throws IOException {
740
                fw.write(DxfGroup.toString(0, "TABLE"));
741
                fw.write(DxfGroup.toString(2, "LAYER"));
742
                //                fw.write(DxfGroup.toString(70, 2));
743
744
745
                //layer = new DxfLayer(layerName, 0, 131, "CONTINUOUS");
746
                //fw.write(layer.toString());
747 14 luisw
                fw.write(((DxfEntityMaker) entityMaker).getLayers().toDxfString());
748 13 luisw
749
                fw.write(DxfGroup.toString(0, "ENDTAB"));
750 12 luisw
        }
751
752
        public void writeEntities(FileWriter fw) throws IOException {
753 13 luisw
                // ECRITURE DES FEATURES
754
                fw.write(DxfGroup.toString(0, "SECTION"));
755
                fw.write(DxfGroup.toString(2, "ENTITIES"));
756 111 jmorell
                if (cadFlag) {
757
                        fw.write(((DxfEntityMaker) entityMaker).getEntities().toDxfString());
758
                } else {
759
                        //fw.write(((DxfFeatureMaker) entityMaker).getObjects().toDxfString());
760
                }
761 13 luisw
                fw.write(DxfGroup.toString(0, "ENDSEC"));
762
                fw.write(DxfGroup.toString(0, "ENDBLK"));
763 12 luisw
        }
764
765 94 luisw
        public void reProject(ICoordTrans rp) {
766 2 luisw
                System.out.println("Dxf: reproyectando ...");
767
                entityMaker.reProject(rp);
768
        }
769 210 luisw
770
        /* (non-Javadoc)
771
         * @see org.cresques.io.GeoFile#close()
772
         */
773
        public void close() {
774
                // TODO Auto-generated method stub
775
776
        }
777 2 luisw
}