Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / DxfFile.java @ 199

History | View | Annotate | Download (26.9 KB)

1
package org.cresques.io;
2

    
3
import java.io.BufferedReader;
4
import java.io.FileNotFoundException;
5
import java.io.FileReader;
6
import java.io.FileWriter;
7
import java.io.IOException;
8
import java.io.InputStream;
9
import java.io.InputStreamReader;
10
import java.io.Reader;
11
import java.util.Date;
12
import java.util.Hashtable;
13
import java.util.Vector;
14
import org.cresques.cts.ICoordTrans;
15
import org.cresques.cts.IProjection;
16
import org.cresques.geo.Projected;
17
import org.cresques.px.Extent;
18
import org.cresques.px.IObjList;
19
import org.cresques.px.dxf.DxfEntityMaker;
20

    
21
public class DxfFile extends GeoFile {
22
        
23
        private boolean cadFlag = true;
24
        
25
        long lineNr = 0;
26

    
27
        String buf = null;
28
        
29
        BufferedReader fi;
30
        long l = 0;
31
        int count = 0;
32
        DxfGroup grp = null;
33
        
34
        EntityFactory entityMaker = null;
35
        
36
        /**
37
         * Crea los objetos en el Modelo correspondiente.
38
         * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
39
         */
40
        public interface EntityFactory extends Projected {
41
                public void setAddingToBlock(boolean a);
42
                public void createLayer(DxfGroupVector v) throws Exception ;
43
                public void createPolyline(DxfGroupVector v) throws Exception ;
44
                public void addVertex(DxfGroupVector v) throws Exception ;
45
                public void endSeq() throws Exception ;
46
                public void createLwPolyline(DxfGroupVector v) throws Exception ;
47
                public void createLine(DxfGroupVector v) throws Exception ;
48
                public void createText(DxfGroupVector v) throws Exception ;
49
                public void createPoint(DxfGroupVector v) throws Exception ;
50
                public void createCircle(DxfGroupVector v) throws Exception ;
51
                public void createArc(DxfGroupVector v) throws Exception ;
52
                public void createInsert(DxfGroupVector v) throws Exception ;
53
                public void createSolid(DxfGroupVector v) throws Exception ;
54
                public void createSpline(DxfGroupVector v) throws Exception ;
55
                public void createAttdef(DxfGroupVector v) throws Exception ;
56
                public void createAttrib(DxfGroupVector v) throws Exception ;
57
                public void createBlock(DxfGroupVector v) throws Exception ;
58
                public void endBlk(DxfGroupVector v) throws Exception ;
59
                void testBlocks();
60
                public Extent getExtent();
61
                public Vector getBlkList();
62
                public IObjList getObjects();
63
        };
64
        
65
        public DxfFile(IProjection proj, String name, EntityFactory maker) {
66
                super(proj, name);
67
                entityMaker = maker;
68
        }
69
        
70
        /**
71
         * Carga un .dxf
72
         */
73
        public GeoFile load() {
74
                System.out.println("Dxf: Cargando "+name+" ...");
75
                try {
76
                        if (ZipFileFolder.isUrl(name)) {
77
                                ZipFileFolder zFolder = new ZipFileFolder(name);
78
                                InputStream is = zFolder.getInputStream(name);
79
                                return load(new InputStreamReader(is));
80
                        } else 
81
                                return load(new FileReader(name));
82
                } catch (FileNotFoundException fnfe) {
83
                        fnfe.printStackTrace();
84
                } catch (Exception e) {
85
                        System.err.println("Dxf: ERROR."+l+"lineas leidas");
86
                        e.printStackTrace();
87
                }
88
                return this;
89
        }
90
        
91
        public GeoFile load(Reader fr) throws NumberFormatException, Exception {
92
                System.out.println("Dxf: Cargando '"+name+"' ...");
93
                fi = new BufferedReader(fr);
94
                while ((grp = readGrp()) != null) {
95
                        l+=2;
96
                        
97
                        if (grp.equals(0, "EOF"))                break;
98
                        if (grp.equals(0, "SECTION"))
99
                                readSection();
100
                }
101
                fi.close();
102
                extent.add(entityMaker.getExtent());
103
                System.out.println("Dxf: '"+name+"' cargado. ("+l+" l?neas).");
104
                this.lineNr = l;
105
                return this;
106
        }
107
        
108
        private DxfGroup readGrp() throws NumberFormatException, IOException {
109
                DxfGroup g = DxfGroup.read(fi);
110
                if (g != null) l += 2;
111
                /*if (g.code == 8)
112
                        if (((String) g.data).length() < 1) {
113
                                System.err.println("a que un layer no puede ser ''?");
114
                                System.exit(1);
115
                        }*/
116
                return g;
117
        }
118
        
119
        private void readSection() throws NumberFormatException, Exception {
120
                while (true) {
121
                        grp = readGrp(); System.out.print("-1:"+grp);
122
                        if (grp.code == 2)
123
                                if (((String) grp.data).compareTo("HEADER") == 0)
124
                                        readAnySection();
125
                                else if (((String) grp.data).compareTo("CLASSES") == 0)
126
                                        readAnySection();
127
                                else if (((String) grp.data).compareTo("TABLES") == 0)
128
                                        readTables();
129
                                else if (((String) grp.data).compareTo("BLOCKS") == 0)
130
                                        readBlocks();
131
                                else if (((String) grp.data).compareTo("ENTITIES") == 0)
132
                                        readEntities();
133
                                else if (((String) grp.data).compareTo("OBJECTS") == 0)
134
                                        readAnySection();
135
                                else {
136
                                        System.out.println("DxfRead: Seccion "+grp.data);
137
                                        readAnySection();
138
                                }
139
                        else
140
                                System.err.println("Dxf: Codigo/Seccion desconocidos" + grp);
141
                        if (grp.equals(0, "EOF")) break;
142
                        if (grp.equals(0, "ENDSEC")) break;
143
                }                
144
        }
145
        
146
        private void readTables() throws NumberFormatException, Exception {
147
                System.out.println("Dxf: Seccion TABLAS, linea "+ l+ "grp ="+ grp);
148
                int layerCnt = 0;
149
                String tableAct = "NONAME";
150
                
151
                Hashtable tables = new Hashtable();
152
                Vector table = new Vector();
153
                DxfGroupVector v = new DxfGroupVector();
154
                
155
                grp = readGrp();// System.out.print("0:"+grp);
156
                while (true) {
157
                        if (grp.code == 0) {
158
                                String data = (String) grp.getData();
159
                                if (data.compareTo("ENDSEC") == 0 || data.compareTo("EOF") == 0)
160
                                        break;
161
                                else if (data.compareTo("ENDTAB") == 0) {
162
                                        tables.put(tableAct, table);
163
                                        table = new Vector();
164
                                        grp = readGrp();// System.out.print("1:"+grp);
165
                                        
166
                                        /**/if (tableAct.compareTo("LAYER") == 0 && v.size()>0) {
167
                                                entityMaker.createLayer(v);
168
                                                System.out.println("Dxf: Layer "+v.getDataAsString(2));
169
                                                layerCnt++;
170
                                                v.clear();
171
                                        }/**/
172
                                        continue;
173
                                } else {
174
                                        if (table.size()==1) {
175
                                                tableAct = v.getDataAsString(2);
176
                                                System.out.println("Dxf: Tabla "+tableAct);
177
                                        } else
178
                                                if (tableAct.compareTo("LAYER") == 0 && v.size()>0) {
179
                                                        entityMaker.createLayer(v);
180
                                                        System.out.println("Dxf: Layer "+v.getDataAsString(2));
181
                                                        layerCnt++;
182
                                                }
183

    
184
                                        v.clear();
185
                                        v.add(grp);
186
                                }
187
                                while (true) {
188
                                        grp = readGrp();// System.out.print("2:"+grp);
189
                                        if (grp.code == 0)        break;
190
                                        v.add(grp);
191
                                }
192
                                table.add(v);
193
                        } else {
194
                                System.err.println("Dxf: Error de secuencia");
195
                                grp = readGrp(); //System.out.print("3:"+grp);        
196
                        }
197
                }
198
                System.out.println("Dxf: Seccion TABLAS: " + layerCnt + " Capas. ");
199
        }
200
        
201
        private void readAnySection() throws NumberFormatException, IOException {
202
                System.out.println("Dxf: Seccion '"+((String) grp.getData())+"', linea "+ l);
203
                while (true) {
204
                        grp = readGrp();
205
                        if (grp.equals(0, "ENDSEC")) break;
206
                        else if (grp.equals(0, "EOF")) break;
207
                }
208
        }
209
        
210
        private void readEntities() throws NumberFormatException, Exception {
211
                System.out.println("Dxf: Seccion ENTITIES, linea "+ l);
212
                int entityCnt = 0;
213
                int cntVeces = 0;
214
                DxfGroupVector v = new DxfGroupVector();
215
                grp = readGrp();
216
                while (true) {
217
                        if (grp.equals(0, "EOF")) break;
218
                        else if (grp.code == 0) {
219
                                if (v.size() > 0) {
220
                                        String lastEntity = (String) ((DxfGroup) v.get(0)).data;
221
                                        if (lastEntity.compareTo("POLYLINE") == 0) {
222
                                                entityMaker.createPolyline(v);
223
                                        } else if (lastEntity.compareTo("VERTEX") == 0) {
224
                                                entityMaker.addVertex(v);
225
                                        } else if (lastEntity.compareTo("SEQEND") == 0) {
226
                                                entityMaker.endSeq();
227
                                        } else if (lastEntity.compareTo("LWPOLYLINE") == 0) {
228
                                                entityMaker.createLwPolyline(v);
229
                                        } else if (lastEntity.compareTo("LINE") == 0) {
230
                                                entityMaker.createLine(v);
231
                                        } else if (lastEntity.compareTo("TEXT") == 0) {
232
                                                entityMaker.createText(v);
233
                                        } else if (lastEntity.compareTo("POINT") == 0) {
234
                                                entityMaker.createPoint(v);
235
                                        } else if (lastEntity.compareTo("CIRCLE") == 0) {
236
                                                entityMaker.createCircle(v);
237
                                        } else if (lastEntity.compareTo("ARC") == 0) {
238
                                                entityMaker.createArc(v);
239
                                        } else if (lastEntity.compareTo("INSERT") == 0) {
240
                                                entityMaker.createInsert(v);
241
                                        } else if (lastEntity.compareTo("SOLID") == 0) {
242
                                                entityMaker.createSolid(v);
243
                                        } else if (lastEntity.compareTo("SPLINE") == 0) {
244
                                                entityMaker.createSpline(v);
245
                                        } else if (lastEntity.compareTo("ATTRIB") == 0) {
246
                                                entityMaker.createAttrib(v);
247
                                        } else if (lastEntity.compareTo("ENDSEC") == 0) {
248
                                                break;
249
                                        } else
250
                                                System.err.println("Dxf: Entidad "+lastEntity+" desconocida.");
251
                                }
252
                                v.clear();
253
                                v.add(grp);
254
                                while (true) {
255
                                        grp = readGrp();
256
                                        if (grp.code == 0)        break;
257
                                        v.add(grp);
258
                                }
259
                                entityCnt++;
260
                        }
261
                        cntVeces++;
262
                }
263
                System.out.println("Dxf: Seccion ENTITIES, " + entityCnt + " entidades, "+ cntVeces + " veces.");
264
                //System.out.println("Seccion ENTITIES, linea "+ l+ " (SALGO)");
265
        }
266
        
267
        private void readBlocks() throws NumberFormatException, Exception {
268
                System.out.println("Dxf: Seccion BLOCKS, linea "+ l);
269
                int blkCnt = 0;
270
                int cntVeces = 0;
271
                DxfGroupVector v = new DxfGroupVector();
272
                grp = readGrp();
273
                while (true) {
274
                        if (grp.equals(0, "EOF")) break;
275
                        else if (grp.code == 0) {
276
                                if (v.size() > 0) {
277
                                        String lastEntity = (String) ((DxfGroup) v.get(0)).data;
278
                                        if (lastEntity.compareTo("BLOCK") == 0) {
279
                                                System.out.println("readBlocks(): Empezamos a leer un bloque");
280
                                                entityMaker.createBlock(v);
281
                                        } else if (lastEntity.compareTo("POLYLINE") == 0) {
282
                                                //System.out.println("readBlocks(): A?adimos una polilinea al bloque");
283
                                                entityMaker.createPolyline(v);
284
                                        } else if (lastEntity.compareTo("VERTEX") == 0) {
285
                                                //System.out.println("readBlocks(): A?adimos un vertice a la polilinea");
286
                                                entityMaker.addVertex(v);
287
                                        } else if (lastEntity.compareTo("SEQEND") == 0) {
288
                                                //System.out.println("readBlocks(): Cerramos una polilinea");
289
                                                entityMaker.endSeq();
290
                                        } else if (lastEntity.compareTo("LWPOLYLINE") == 0) {
291
                                                //System.out.println("readBlocks(): A?adimos una lwpolilinea al bloque");
292
                                                entityMaker.createLwPolyline(v);
293
                                        } else if (lastEntity.compareTo("LINE") == 0) {
294
                                                //System.out.println("readBlocks(): A?adimos una linea al bloque");
295
                                                entityMaker.createLine(v);
296
                                        } else if (lastEntity.compareTo("TEXT") == 0) {
297
                                                //System.out.println("readBlocks(): A?adimos un texto al bloque");
298
                                                entityMaker.createText(v);
299
                                        } else if (lastEntity.compareTo("POINT") == 0) {
300
                                                //System.out.println("readBlocks(): A?adimos un punto al bloque");
301
                                                entityMaker.createPoint(v);
302
                                        } else if (lastEntity.compareTo("CIRCLE") == 0) {
303
                                                //System.out.println("readBlocks(): A?adimos un circulo al bloque");
304
                                                entityMaker.createCircle(v);
305
                                        } else if (lastEntity.compareTo("ARC") == 0) {
306
                                                //System.out.println("readBlocks(): A?adimos un arco al bloque");
307
                                                entityMaker.createArc(v);
308
                                        } else if (lastEntity.compareTo("INSERT") == 0) {
309
                                                //System.out.println("readBlocks(): A?adimos un insert al bloque");
310
                                                entityMaker.createInsert(v);
311
                                        } else if (lastEntity.compareTo("SOLID") == 0) {
312
                                                //System.out.println("readBlocks(): A?adimos un solido al bloque");
313
                                                entityMaker.createSolid(v);
314
                                        } else if (lastEntity.compareTo("SPLINE") == 0) {
315
                                                entityMaker.createSpline(v);
316
                                        } else if (lastEntity.compareTo("ATTDEF") == 0) {
317
                                                entityMaker.createAttdef(v);
318
                                        } else if (lastEntity.compareTo("ENDBLK") == 0) {
319
                                                System.out.println("readBlocks(): Cerramos un bloque"+v);
320
                                                entityMaker.endBlk(v);
321
                                        } else if (lastEntity.compareTo("ENDSEC") == 0) {
322
                                                break;
323
                                        } else
324
                                                System.err.println("Dxf: Entidad de bloque "+lastEntity+" desconocida.");
325
                                }
326
                                v.clear();
327
                                v.add(grp);
328
                                while (true) {
329
                                        grp = readGrp();
330
                                        if (grp.code == 0)        break;
331
                                        v.add(grp);
332
                                }
333
                                blkCnt++;
334
                        }
335
                        cntVeces++;
336
                }
337
                
338
                entityMaker.testBlocks();
339
                
340
                System.out.println("Dxf: Seccion BLOCKS, " + blkCnt + " elementos de bloque. "+ cntVeces + " veces.");
341
        }
342
        
343
        public IObjList getObjects() {
344
                return this.entityMaker.getObjects();
345
        }
346
        
347
        public void save(String fName) throws IOException {
348
                long t2, t1;
349
                t1 = getTime();
350
                fName = DataSource.normalize(fName);
351
                FileWriter fw = new FileWriter(fName);
352
                // COMMENTAIRES DU TRADUCTEUR
353
//                fw.write(DxfGroup.toString(999, Integer.toString(features.size()) + " features")); 
354
                fw.write(DxfGroup.toString(999, "TRANSLATION BY geo.cresques.io.DxfFile"));
355
                fw.write(DxfGroup.toString(999, "DATE : " + (new Date()).toString()));
356
                //writeHeader(fw);
357
                //writeTables(fw);
358
                writeEntities(fw);
359
                fw.write(DxfGroup.toString(0, "EOF"));
360
                fw.flush();
361
                fw.close();
362
                t2 = getTime();
363
                System.out.println("DxfFile.save(): Tiempo salvando: " + (t2-t1)/1000 + " seg.");
364
        }
365
        
366
        public void writeHeader(FileWriter fw) throws IOException {
367
                fw.write(DxfGroup.toString(0, "SECTION"));
368
                fw.write(DxfGroup.toString(2, "HEADER"));
369
                fw.write(DxfGroup.toString(9, "$ACADVER"));
370
                        fw.write(DxfGroup.toString(1, "AC1009"));
371
                fw.write(DxfGroup.toString(9, "$INSBASE"));
372
                        fw.write(DxfGroup.toString(10, 0.0, 1));
373
                        fw.write(DxfGroup.toString(20, 0.0, 1));
374
                        fw.write(DxfGroup.toString(30, 0.0, 1));
375
                fw.write(DxfGroup.toString(9, "$EXTMIN"));
376
                        fw.write(DxfGroup.toString(10, extent.minX(), 6));
377
                        fw.write(DxfGroup.toString(20, extent.minY(), 6));
378
                        fw.write(DxfGroup.toString(30, 0.0, 6));
379
                fw.write(DxfGroup.toString(9, "$EXTMAX"));
380
                        fw.write(DxfGroup.toString(10, extent.maxX(), 6));
381
                        fw.write(DxfGroup.toString(20, extent.maxY(), 6));
382
                        fw.write(DxfGroup.toString(30, 0.0, 6));
383
                fw.write(DxfGroup.toString(9, "$LIMMIN"));
384
                        fw.write(DxfGroup.toString(10, extent.minX(), 6));
385
                        fw.write(DxfGroup.toString(20, extent.minY(), 6));
386
                fw.write(DxfGroup.toString(9, "$LIMMAX"));
387
                        fw.write(DxfGroup.toString(10, extent.maxX(), 6));
388
                        fw.write(DxfGroup.toString(20, extent.maxY(), 6));
389
                fw.write(DxfGroup.toString(9, "$ORTHOMODE")+DxfGroup.toString(70, 0));
390
                fw.write(DxfGroup.toString(9, "$REGENMODE")+DxfGroup.toString(70, 1));
391
                fw.write(DxfGroup.toString(9, "$FILLMODE")+        DxfGroup.toString(70, 1));
392
                fw.write(DxfGroup.toString(9, "$QTEXTMODE")+DxfGroup.toString(70, 0));
393
                fw.write(DxfGroup.toString(9, "$MIRRTEXT")+        DxfGroup.toString(70, 1));
394
                fw.write(DxfGroup.toString(9, "$DRAGMODE")+        DxfGroup.toString(70, 2));
395
                fw.write(DxfGroup.toString(9, "$LTSCALE")+        DxfGroup.toString(40, 1.0, 1));
396
                fw.write(DxfGroup.toString(9, "$OSMODE")+        DxfGroup.toString(70, 0));
397
                fw.write(DxfGroup.toString(9, "$ATTMODE")+        DxfGroup.toString(70, 1));
398
                fw.write(DxfGroup.toString(9, "$TEXTSIZE")+        DxfGroup.toString(40, 0.2, 1));
399
                fw.write(DxfGroup.toString(9, "$TRACEWID")+        DxfGroup.toString(40, 0.05, 2));
400
                fw.write(DxfGroup.toString(9, "$TEXTSTYLE")+        DxfGroup.toString(7, "STANDARD"));
401
                fw.write(DxfGroup.toString(9, "$CLAYER")+        DxfGroup.toString(8, "0"));
402
                fw.write(DxfGroup.toString(9, "$CELTYPE")+        DxfGroup.toString(6, "CONTINUOUS"));
403
                fw.write(DxfGroup.toString(9, "$CECOLOR")+        DxfGroup.toString(62, 256));
404
                fw.write(DxfGroup.toString(9, "$DIMSCALE")+        DxfGroup.toString(40, 1.0, 1));
405
                fw.write(DxfGroup.toString(9, "$DIMASZ")+        DxfGroup.toString(40, 0.18, 2));
406
                fw.write(DxfGroup.toString(9, "$DIMEXO")+        DxfGroup.toString(40, 0.0625, 4));
407
                fw.write(DxfGroup.toString(9, "$DIMDLI")+        DxfGroup.toString(40, 0.38, 2));
408
                fw.write(DxfGroup.toString(9, "$DIMRND")+        DxfGroup.toString(40, 0.0, 1));
409
                fw.write(DxfGroup.toString(9, "$DIMDLE")+        DxfGroup.toString(40, 0.0, 1));
410
                fw.write(DxfGroup.toString(9, "$DIMEXE")+        DxfGroup.toString(40, 0.18, 2));
411
                fw.write(DxfGroup.toString(9, "$DIMTP")+        DxfGroup.toString(40, 0.0, 1));
412
                fw.write(DxfGroup.toString(9, "$DIMTM")+        DxfGroup.toString(40, 0.0, 1));
413
                fw.write(DxfGroup.toString(9, "$DIMTXT")+        DxfGroup.toString(40, 0.18, 2));
414
                fw.write(DxfGroup.toString(9, "$DIMCEN")+        DxfGroup.toString(40, 0.09, 2));
415
                fw.write(DxfGroup.toString(9, "$DIMTSZ")+        DxfGroup.toString(40, 0.0, 1));
416
                fw.write(DxfGroup.toString(9,"$DIMTOL")+        DxfGroup.toString(70,0));
417
                fw.write(DxfGroup.toString(9,"$DIMLIM")+        DxfGroup.toString(70,0));
418
                fw.write(DxfGroup.toString(9,"$DIMTIH")+        DxfGroup.toString(70,1));
419
                fw.write(DxfGroup.toString(9,"$DIMTOH")+        DxfGroup.toString(70,1));
420
                fw.write(DxfGroup.toString(9,"$DIMSE1")+        DxfGroup.toString(70,0));
421
                fw.write(DxfGroup.toString(9,"$DIMSE2")+        DxfGroup.toString(70,0));
422
                fw.write(DxfGroup.toString(9,"$DIMTAD")+        DxfGroup.toString(70,0));
423
                fw.write(DxfGroup.toString(9,"$DIMZIN")+        DxfGroup.toString(70,0));
424
                fw.write(DxfGroup.toString(9,"$DIMBLK")+        DxfGroup.toString(1,""));
425
                fw.write(DxfGroup.toString(9,"$DIMASO")+        DxfGroup.toString(70,1));
426
                fw.write(DxfGroup.toString(9,"$DIMSHO")+        DxfGroup.toString(70,1));
427
                fw.write(DxfGroup.toString(9,"$DIMPOST")+        DxfGroup.toString(1,""));
428
                fw.write(DxfGroup.toString(9,"$DIMAPOST")+        DxfGroup.toString(1,""));
429
                fw.write(DxfGroup.toString(9,"$DIMALT")+        DxfGroup.toString(70,0));
430
                fw.write(DxfGroup.toString(9,"$DIMALTD")+        DxfGroup.toString(70,2));
431
                fw.write(DxfGroup.toString(9,"$DIMALTF")+        DxfGroup.toString(40,25.4,1));
432
                fw.write(DxfGroup.toString(9,"$DIMLFAC")+        DxfGroup.toString(40,1.0,1));
433
                fw.write(DxfGroup.toString(9,"$DIMTOFL")+        DxfGroup.toString(70,0));
434
                fw.write(DxfGroup.toString(9,"$DIMTVP")+        DxfGroup.toString(40,0.0,1));
435
                fw.write(DxfGroup.toString(9,"$DIMTIX")+        DxfGroup.toString(70,0));
436
                fw.write(DxfGroup.toString(9,"$DIMSOXD")+        DxfGroup.toString(70,0));
437
                fw.write(DxfGroup.toString(9,"$DIMSAH")+        DxfGroup.toString(70,0));
438
                fw.write(DxfGroup.toString(9,"$DIMBLK1")+        DxfGroup.toString(1,""));
439
                fw.write(DxfGroup.toString(9,"$DIMBLK2")+        DxfGroup.toString(1,""));
440
                fw.write(DxfGroup.toString(9,"$DIMSTYLE")+        DxfGroup.toString(2,"STANDARD"));
441
                fw.write(DxfGroup.toString(9,"$DIMCLRD")+        DxfGroup.toString(70,0));
442
                fw.write(DxfGroup.toString(9,"$DIMCLRE")+        DxfGroup.toString(70,0));
443
                fw.write(DxfGroup.toString(9,"$DIMCLRT")+        DxfGroup.toString(70,0));
444
                fw.write(DxfGroup.toString(9,"$DIMTFAC")+        DxfGroup.toString(40,1.0,1));
445
                fw.write(DxfGroup.toString(9,"$DIMGAP")+        DxfGroup.toString(40,0.09,2));
446
                fw.write(DxfGroup.toString(9,"$LUNITS")+        DxfGroup.toString(70,2));
447
                fw.write(DxfGroup.toString(9,"$LUPREC")+        DxfGroup.toString(70,4));
448
                fw.write(DxfGroup.toString(9,"$AXISMODE")+        DxfGroup.toString(70,0));
449
                fw.write(DxfGroup.toString(9,"$AXISUNIT"));
450
                fw.write(DxfGroup.toString(10,0.0,1));
451
                fw.write(DxfGroup.toString(20,0.0,1));
452
                fw.write(DxfGroup.toString(9,"$SKETCHINC")+        DxfGroup.toString(40,0.1,1));
453
                fw.write(DxfGroup.toString(9,"$FILLETRAD")+        DxfGroup.toString(40,0.0,1));
454
                fw.write(DxfGroup.toString(9,"$AUNITS")+        DxfGroup.toString(70,0));
455
                fw.write(DxfGroup.toString(9,"$AUPREC")+        DxfGroup.toString(70,0));
456
                fw.write(DxfGroup.toString(9,"$MENU")+                DxfGroup.toString(1,"acad"));
457
                fw.write(DxfGroup.toString(9,"$ELEVATION")+        DxfGroup.toString(40,0.0,1));
458
                fw.write(DxfGroup.toString(9,"$PELEVATION")+DxfGroup.toString(40,0.0,1));
459
                fw.write(DxfGroup.toString(9,"$THICKNESS")+        DxfGroup.toString(40,0.0,1));
460
                fw.write(DxfGroup.toString(9,"$LIMCHECK")+        DxfGroup.toString(70,0));
461
                fw.write(DxfGroup.toString(9,"$BLIPMODE")+        DxfGroup.toString(70,1));
462
                fw.write(DxfGroup.toString(9,"$CHAMFERA")+        DxfGroup.toString(40,0.0,1));
463
                fw.write(DxfGroup.toString(9,"$CHAMFERB")+        DxfGroup.toString(40,0.0,1));
464
                fw.write(DxfGroup.toString(9,"$SKPOLY")+        DxfGroup.toString(70,0));
465
                fw.write(DxfGroup.toString(9,"$TDCREATE")+        DxfGroup.toString(40,2453116.436828704,9));
466
                fw.write(DxfGroup.toString(9,"$TDUPDATE")+        DxfGroup.toString(40,2453116.436828704,9));
467
                fw.write(DxfGroup.toString(9,"$TDINDWG")+        DxfGroup.toString(40,0.0000000000,10));
468
                fw.write(DxfGroup.toString(9,"$TDUSRTIMER")+DxfGroup.toString(40,0.0000000000,10));
469
                fw.write(DxfGroup.toString(9,"$USRTIMER")+        DxfGroup.toString(70,1));
470
                fw.write(DxfGroup.toString(9,"$ANGBASE")+        DxfGroup.toString(50,0.0,1));
471
                fw.write(DxfGroup.toString(9,"$ANGDIR")+        DxfGroup.toString(70,0));
472
                fw.write(DxfGroup.toString(9,"$PDMODE")+        DxfGroup.toString(70,0));
473
                fw.write(DxfGroup.toString(9,"$PDSIZE")+        DxfGroup.toString(40,0.0,1));
474
                fw.write(DxfGroup.toString(9,"$PLINEWID")+        DxfGroup.toString(40,0.0,1));
475
                fw.write(DxfGroup.toString(9,"$COORDS")+        DxfGroup.toString(70,0));
476
                fw.write(DxfGroup.toString(9,"$SPLFRAME")+        DxfGroup.toString(70,0));
477
                fw.write(DxfGroup.toString(9,"$SPLINETYPE")+DxfGroup.toString(70,6));
478
                fw.write(DxfGroup.toString(9,"$SPLINESEGS")+DxfGroup.toString(70,10));
479
                fw.write(DxfGroup.toString(9,"$ATTDIA")+        DxfGroup.toString(70,0));
480
                fw.write(DxfGroup.toString(9,"$ATTREQ")+        DxfGroup.toString(70,1));
481
                fw.write(DxfGroup.toString(9,"$HANDLING")+        DxfGroup.toString(70,1));
482
                fw.write(DxfGroup.toString(9,"$HANDSEED")+        DxfGroup.toString(5,"394B"));
483
                fw.write(DxfGroup.toString(9,"$SURFTAB1")+        DxfGroup.toString(70,6));
484
                fw.write(DxfGroup.toString(9,"$SURFTAB2")+        DxfGroup.toString(70,6));
485
                fw.write(DxfGroup.toString(9,"$SURFTYPE")+        DxfGroup.toString(70,6));
486
                fw.write(DxfGroup.toString(9,"$SURFU")+                DxfGroup.toString(70,6));
487
                fw.write(DxfGroup.toString(9,"$SURFV")+                DxfGroup.toString(70,6));
488
                fw.write(DxfGroup.toString(9,"$UCSNAME")+        DxfGroup.toString(2,""));
489
                fw.write(DxfGroup.toString(9,"$UCSORG"));
490
                fw.write(DxfGroup.toString(10,0.0,1));
491
                fw.write(DxfGroup.toString(20,0.0,1));
492
                fw.write(DxfGroup.toString(30,0.0,1));
493
                fw.write(DxfGroup.toString(9,"$UCSXDIR"));
494
                fw.write(DxfGroup.toString(10,1.0,1));
495
                fw.write(DxfGroup.toString(20,0.0,1));
496
                fw.write(DxfGroup.toString(30,0.0,1));
497
                fw.write(DxfGroup.toString(9,"$UCSYDIR"));
498
                fw.write(DxfGroup.toString(10,0.0,1));
499
                fw.write(DxfGroup.toString(20,1.0,1));
500
                fw.write(DxfGroup.toString(30,0.0,1));
501
                fw.write(DxfGroup.toString(9,"$PUCSNAME")+        DxfGroup.toString(2,""));
502
                fw.write(DxfGroup.toString(9,"$PUCSORG"));
503
                fw.write(DxfGroup.toString(10,0.0,1));
504
                fw.write(DxfGroup.toString(20,0.0,1));
505
                fw.write(DxfGroup.toString(30,0.0,1));
506
                fw.write(DxfGroup.toString(9,"$PUCSXDIR"));
507
                fw.write(DxfGroup.toString(10,1.0,1));
508
                fw.write(DxfGroup.toString(20,0.0,1));
509
                fw.write(DxfGroup.toString(30,0.0,1));
510
                fw.write(DxfGroup.toString(9,"$PUCSYDIR"));
511
                fw.write(DxfGroup.toString(10,0.0,1));
512
                fw.write(DxfGroup.toString(20,1.0,1));
513
                fw.write(DxfGroup.toString(30,0.0,1));
514
                fw.write(DxfGroup.toString(9,"$USERI1")+        DxfGroup.toString(70,0));
515
                fw.write(DxfGroup.toString(9,"$USERI2")+        DxfGroup.toString(70,0));
516
                fw.write(DxfGroup.toString(9,"$USERI3")+        DxfGroup.toString(70,0));
517
                fw.write(DxfGroup.toString(9,"$USERI4")+        DxfGroup.toString(70,0));
518
                fw.write(DxfGroup.toString(9,"$USERI5")+        DxfGroup.toString(70,0));
519
                fw.write(DxfGroup.toString(9,"$USERR1")+        DxfGroup.toString(40,0.0,1));
520
                fw.write(DxfGroup.toString(9,"$USERR2")+        DxfGroup.toString(40,0.0,1));
521
                fw.write(DxfGroup.toString(9,"$USERR3")+        DxfGroup.toString(40,0.0,1));
522
                fw.write(DxfGroup.toString(9,"$USERR4")+        DxfGroup.toString(40,0.0,1));
523
                fw.write(DxfGroup.toString(9,"$USERR5")+        DxfGroup.toString(40,0.0,1));
524
                fw.write(DxfGroup.toString(9,"$WORLDVIEW")+        DxfGroup.toString(70,1));
525
                fw.write(DxfGroup.toString(9,"$SHADEDGE")+        DxfGroup.toString(70,3));
526
                fw.write(DxfGroup.toString(9,"$SHADEDIF")+        DxfGroup.toString(70,70));
527
                fw.write(DxfGroup.toString(9,"$TILEMODE")+        DxfGroup.toString(70,1));
528
                fw.write(DxfGroup.toString(9,"$MAXACTVP")+        DxfGroup.toString(70,16));
529
                fw.write(DxfGroup.toString(9,"$PINSBASE"));
530
                fw.write(DxfGroup.toString(10,0.0,1));
531
                fw.write(DxfGroup.toString(20,0.0,1));
532
                fw.write(DxfGroup.toString(30,0.0,1));
533
                fw.write(DxfGroup.toString(9,"$PLIMCHECK")+        DxfGroup.toString(70,0));
534
                fw.write(DxfGroup.toString(9,"$PEXTMIN"));
535
                fw.write(DxfGroup.toString(10,"-1.000000E+20"));
536
                fw.write(DxfGroup.toString(20,"-1.000000E+20"));
537
                fw.write(DxfGroup.toString(30,"-1.000000E+20"));
538
                fw.write(DxfGroup.toString(9,"$PEXTMAX"));
539
                fw.write(DxfGroup.toString(10,"-1.000000E+20"));
540
                fw.write(DxfGroup.toString(20,"-1.000000E+20"));
541
                fw.write(DxfGroup.toString(30,"-1.000000E+20"));
542
                fw.write(DxfGroup.toString(9,"$PLIMMIN"));
543
                fw.write(DxfGroup.toString(10,0.0,1));
544
                fw.write(DxfGroup.toString(20,0.0,1));
545
                fw.write(DxfGroup.toString(9,"$PLIMMAX"));
546
                fw.write(DxfGroup.toString(10,12.0,1));
547
                fw.write(DxfGroup.toString(20,9.0,1));
548
                fw.write(DxfGroup.toString(9,"$UNITMODE")+        DxfGroup.toString(70,0));
549
                fw.write(DxfGroup.toString(9,"$VISRETAIN")+        DxfGroup.toString(70,0));
550
                fw.write(DxfGroup.toString(9,"$PLINEGEN")+        DxfGroup.toString(70,1));
551
                fw.write(DxfGroup.toString(9,"$PSLTSCALE")+        DxfGroup.toString(70,0));
552
                fw.write(DxfGroup.toString(9,"$TREEDEPTH")+        DxfGroup.toString(70,3020));
553
                fw.write(DxfGroup.toString(9,"$DWGCODEPAGE")+DxfGroup.toString(3,"ansi_1252"));
554
/*                
555
                fw.write(DxfGroup.toString(9, "$ELEVATION"));
556
                        fw.write(DxfGroup.toString(40, 0.0, 3));
557
                fw.write(DxfGroup.toString(9, "$LIMCHECK"));
558
                        fw.write(DxfGroup.toString(70, 1));
559
                fw.write(DxfGroup.toString(9, "$LUNITS"));
560
                        fw.write(DxfGroup.toString(70, 2));
561
                fw.write(DxfGroup.toString(9, "$LUPREC"));
562
                        fw.write(DxfGroup.toString(70, 2));*/
563
                fw.write(DxfGroup.toString(0, "ENDSEC"));
564
        }
565
        
566
        public void writeTables(FileWriter fw) throws IOException {
567
                fw.write(DxfGroup.toString(0, "SECTION"));
568
                fw.write(DxfGroup.toString(2, "TABLES"));
569
                //writeStyleTable(fw);
570
                //writeLTypeTable(fw);
571
                //writeAppidTable(fw);
572
                writeLayerTable(fw);
573
                fw.write(DxfGroup.toString(0, "ENDSEC"));
574

    
575
                fw.write(DxfGroup.toString(0, "ENDBLK"));
576
        }
577
        /*
578
         *   0
579
TABLE
580
  2
581
APPID
582
  5
583
14
584
100
585
AcDbSymbolTable
586
 70
587
     1
588
  0
589
APPID
590
  5
591
15
592
100
593
AcDbSymbolTableRecord
594
100
595
AcDbRegAppTableRecord
596
  2
597
ACAD
598
 70
599
     0
600
  0
601
ENDTAB
602
         */
603
        public void writeAppidTable(FileWriter fw) throws IOException {
604
                fw.write(DxfGroup.toString(0, "TABLE"));
605
                fw.write(DxfGroup.toString(2, "APPID"));
606
                fw.write(DxfGroup.toString(5, 14));
607
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
608
                fw.write(DxfGroup.toString(0, "APPID"));
609
                fw.write(DxfGroup.toString(5, 15));
610
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
611
                fw.write(DxfGroup.toString(100, "AcDbRegAppTableRecord"));
612
                fw.write(DxfGroup.toString(2, "ACAD"));
613
                fw.write(DxfGroup.toString(70, 1));
614
                fw.write(DxfGroup.toString(0, "ENDTAB"));
615
        }
616
        
617
        /*public void writeStyleTable(FileWriter fw) throws IOException {
618
                fw.write(DxfGroup.toString(0, "TABLE"));
619
                fw.write(DxfGroup.toString(2, "STYLE"));
620
                fw.write(DxfGroup.toString(70, 1));
621
                DxfTABLE_STYLE_ITEM style =
622
                        new DxfTABLE_STYLE_ITEM("STANDARD", 0, 0f, 1f, 0f, 0, 1.0f, "xxx.txt", "yyy.txt");
623
                fw.write(style.toString());
624
                fw.write(DxfGroup.toString(0, "ENDTAB"));
625
        }*/
626
        
627
        /*public void writeLTypeTable(FileWriter fw) throws IOException {
628
                fw.write(DxfGroup.toString(0, "TABLE"));
629
                fw.write(DxfGroup.toString(2, "LTYPE"));
630
                fw.write(DxfGroup.toString(70, 1));
631
                DxfTABLE_LTYPE_ITEM ltype =
632
                        new DxfTABLE_LTYPE_ITEM("CONTINUE", 0, "", 65, 0f, new float[0]);
633
                fw.write(ltype.toString());
634
                fw.write(DxfGroup.toString(0, "ENDTAB"));
635
        }*/
636
        
637
        public void writeLayerTable(FileWriter fw) throws IOException {
638
                fw.write(DxfGroup.toString(0, "TABLE"));
639
                fw.write(DxfGroup.toString(2, "LAYER"));
640
                //                fw.write(DxfGroup.toString(70, 2));
641
                
642

    
643
                //layer = new DxfLayer(layerName, 0, 131, "CONTINUOUS");
644
                //fw.write(layer.toString());
645
                fw.write(((DxfEntityMaker) entityMaker).getLayers().toDxfString());
646
                                
647
                fw.write(DxfGroup.toString(0, "ENDTAB"));
648
        }
649

    
650
        public void writeEntities(FileWriter fw) throws IOException {
651
                // ECRITURE DES FEATURES
652
                fw.write(DxfGroup.toString(0, "SECTION"));
653
                fw.write(DxfGroup.toString(2, "ENTITIES"));                
654
                if (cadFlag) {
655
                        fw.write(((DxfEntityMaker) entityMaker).getEntities().toDxfString());
656
                } else {
657
                        //fw.write(((DxfFeatureMaker) entityMaker).getObjects().toDxfString());                        
658
                }
659
                fw.write(DxfGroup.toString(0, "ENDSEC"));
660
                fw.write(DxfGroup.toString(0, "ENDBLK"));
661
        }
662
        
663
        public void reProject(ICoordTrans rp) {
664
                System.out.println("Dxf: reproyectando ...");
665
                entityMaker.reProject(rp);
666
        }
667

    
668
        /* (non-Javadoc)
669
         * @see org.cresques.io.GeoFile#close()
670
         */
671
        public void close() {
672
                // TODO Auto-generated method stub
673
                
674
        }
675
}