Statistics
| Revision:

root / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / DxfFile.java @ 72

History | View | Annotate | Download (27.4 KB)

1
package org.cresques.io;
2

    
3
import java.awt.geom.Point2D;
4
import java.io.BufferedReader;
5
import java.io.FileNotFoundException;
6
import java.io.FileReader;
7
import java.io.FileWriter;
8
import java.io.IOException;
9
import java.io.InputStream;
10
import java.io.InputStreamReader;
11
import java.io.Reader;
12
import java.util.Date;
13
import java.util.Hashtable;
14
import java.util.Iterator;
15
import java.util.Vector;
16
import org.cresques.geo.Projection;
17
import org.cresques.geo.ReProjection;
18
import org.cresques.px.Extent;
19
import org.cresques.px.dxf.DxfBlock;
20
import org.cresques.px.dxf.DxfEntity;
21
import org.cresques.px.dxf.DxfEntityList;
22
import org.cresques.px.dxf.DxfEntityMaker;
23
import org.cresques.px.dxf.DxfInsert;
24
import org.cresques.px.dxf.DxfLayer;
25
import org.cresques.px.dxf.DxfLine;
26

    
27
public class DxfFile extends GeoFile {
28
        
29
        long lineNr = 0;
30

    
31
        String buf = null;
32
        
33
        BufferedReader fi;
34
        long l = 0;
35
        int count = 0;
36
        DxfGroup grp = null;
37
        
38
        EntityFactory entityMaker = null;
39
        
40
        /**
41
         * Crea los objetos en el Modelo correspondiente.
42
         * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
43
         */
44
        public interface EntityFactory {
45
                public void setAddingToBlock(boolean a);
46
                public void createLayer(DxfGroupVector v) throws Exception ;
47
                public void createPolyline(DxfGroupVector v) throws Exception ;
48
                public void addVertex(DxfGroupVector v) throws Exception ;
49
                public void endSeq() throws Exception ;
50
                public void createLwPolyline(DxfGroupVector v) throws Exception ;
51
                public void createLine(DxfGroupVector v) throws Exception ;
52
                public void createText(DxfGroupVector v) throws Exception ;
53
                public void createPoint(DxfGroupVector v) throws Exception ;
54
                public void createCircle(DxfGroupVector v) throws Exception ;
55
                public void createArc(DxfGroupVector v) throws Exception ;
56
                public void createInsert(DxfGroupVector v) throws Exception ;
57
                public void createSolid(DxfGroupVector v) throws Exception ;
58
                public void createBlock(DxfGroupVector v) throws Exception ;
59
                public void endBlk(DxfGroupVector v) throws Exception ;
60
                public void gestionaInsert(DxfInsert entity, DxfLayer layer);
61
                public DxfBlock getBlk();
62
                public Extent getExtent();
63
                public Vector getBlkList();
64
                public DxfEntityList getDxfEntityList();
65
                public Projection getProjection();
66
                public void reProject(ReProjection rp);
67
        };
68
        
69
        public DxfFile(Projection proj, String name, EntityFactory maker) {
70
                super(proj, name);
71
                entityMaker = maker;
72
        }
73
        
74
        /**
75
         * Carga un .gml
76
         */
77
        public GeoFile load() {
78
                System.out.println("Dxf: Cargando "+name+" ...");
79
                try {
80
                        if (ZipFileFolder.isUrl(name)) {
81
                                ZipFileFolder zFolder = new ZipFileFolder(name);
82
                                InputStream is = zFolder.getInputStream(name);
83
                                return load(new InputStreamReader(is));
84
                        } else 
85
                                return load(new FileReader(name));
86
                } catch (FileNotFoundException fnfe) {
87
                        fnfe.printStackTrace();
88
                } catch (Exception e) {
89
                        System.err.println("Dxf: ERROR."+l+"lineas leidas");
90
                        e.printStackTrace();
91
                }
92
                return this;
93
        }
94
        
95
        public GeoFile load(Reader fr) throws NumberFormatException, Exception {
96
                System.out.println("Dxf: Cargando '"+name+"' ...");
97
                fi = new BufferedReader(fr);
98
                while ((grp = readGrp()) != null) {
99
                        l+=2;
100
                        
101
                        if (grp.equals(0, "EOF"))                break;
102
                        if (grp.equals(0, "SECTION"))
103
                                readSection();
104
                }
105
                fi.close();
106
                extent.add(entityMaker.getExtent());
107
                System.out.println("Dxf: '"+name+"' cargado. ("+l+" l?neas).");
108
                this.lineNr = l;
109
                return this;
110
        }
111
        
112
        private DxfGroup readGrp() throws NumberFormatException, IOException {
113
                DxfGroup g = DxfGroup.read(fi);
114
                if (g != null) l += 2;
115
                return g;
116
        }
117
        
118
        private void readSection() throws NumberFormatException, Exception {
119
                while (true) {
120
                        grp = readGrp();
121
                        if (grp.code == 2)
122
                                if (((String) grp.data).compareTo("HEADER") == 0)
123
                                        readAnySection();
124
                                else if (((String) grp.data).compareTo("CLASSES") == 0)
125
                                        readAnySection();
126
                                else if (((String) grp.data).compareTo("TABLES") == 0)
127
                                        readTables();
128
                                else if (((String) grp.data).compareTo("BLOCKS") == 0)
129
                                        //readAnySection();
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);
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();
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();
165
                                        continue;
166
                                } else {
167
                                        if (table.size()==1) {
168
                                                tableAct = v.getDataAsString(2);
169
                                                System.out.println("Dxf: Tabla "+tableAct);
170
                                        } else
171
                                                if (tableAct.compareTo("LAYER") == 0 && v.size()>0) {
172
                                                        entityMaker.createLayer(v);
173
                                                        layerCnt++;
174
                                                }
175

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

    
593
                fw.write(DxfGroup.toString(0, "ENDBLK"));
594
        }
595
        /*
596
         *   0
597
TABLE
598
  2
599
APPID
600
  5
601
14
602
100
603
AcDbSymbolTable
604
 70
605
     1
606
  0
607
APPID
608
  5
609
15
610
100
611
AcDbSymbolTableRecord
612
100
613
AcDbRegAppTableRecord
614
  2
615
ACAD
616
 70
617
     0
618
  0
619
ENDTAB
620
         */
621
        public void writeAppidTable(FileWriter fw) throws IOException {
622
                fw.write(DxfGroup.toString(0, "TABLE"));
623
                fw.write(DxfGroup.toString(2, "APPID"));
624
                fw.write(DxfGroup.toString(5, 14));
625
                fw.write(DxfGroup.toString(100, "AcDbSymbolTable"));
626
                fw.write(DxfGroup.toString(0, "APPID"));
627
                fw.write(DxfGroup.toString(5, 15));
628
                fw.write(DxfGroup.toString(100, "AcDbSymbolTableRecord"));
629
                fw.write(DxfGroup.toString(100, "AcDbRegAppTableRecord"));
630
                fw.write(DxfGroup.toString(2, "ACAD"));
631
                fw.write(DxfGroup.toString(70, 1));
632
                fw.write(DxfGroup.toString(0, "ENDTAB"));
633
        }
634
        
635
        /*public void writeStyleTable(FileWriter fw) throws IOException {
636
                fw.write(DxfGroup.toString(0, "TABLE"));
637
                fw.write(DxfGroup.toString(2, "STYLE"));
638
                fw.write(DxfGroup.toString(70, 1));
639
                DxfTABLE_STYLE_ITEM style =
640
                        new DxfTABLE_STYLE_ITEM("STANDARD", 0, 0f, 1f, 0f, 0, 1.0f, "xxx.txt", "yyy.txt");
641
                fw.write(style.toString());
642
                fw.write(DxfGroup.toString(0, "ENDTAB"));
643
        }*/
644
        
645
        /*public void writeLTypeTable(FileWriter fw) throws IOException {
646
                fw.write(DxfGroup.toString(0, "TABLE"));
647
                fw.write(DxfGroup.toString(2, "LTYPE"));
648
                fw.write(DxfGroup.toString(70, 1));
649
                DxfTABLE_LTYPE_ITEM ltype =
650
                        new DxfTABLE_LTYPE_ITEM("CONTINUE", 0, "", 65, 0f, new float[0]);
651
                fw.write(ltype.toString());
652
                fw.write(DxfGroup.toString(0, "ENDTAB"));
653
        }*/
654
        
655
        public void writeLayerTable(FileWriter fw) throws IOException {
656
                fw.write(DxfGroup.toString(0, "TABLE"));
657
                fw.write(DxfGroup.toString(2, "LAYER"));
658
                //                fw.write(DxfGroup.toString(70, 2));
659
                
660

    
661
                //layer = new DxfLayer(layerName, 0, 131, "CONTINUOUS");
662
                //fw.write(layer.toString());
663
                fw.write(((DxfEntityMaker) entityMaker).getLayers().toDxfString());
664
                                
665
                fw.write(DxfGroup.toString(0, "ENDTAB"));
666
        }
667

    
668
        public void writeEntities(FileWriter fw) throws IOException {
669
                // ECRITURE DES FEATURES
670
                fw.write(DxfGroup.toString(0, "SECTION"));
671
                fw.write(DxfGroup.toString(2, "ENTITIES"));                
672
                fw.write(((DxfEntityMaker) entityMaker).getEntities().toDxfString());
673
                fw.write(DxfGroup.toString(0, "ENDSEC"));
674
                fw.write(DxfGroup.toString(0, "ENDBLK"));
675
        }
676
        
677
        public void reProject(ReProjection rp) {
678
                System.out.println("Dxf: reproyectando ...");
679
                entityMaker.reProject(rp);
680
        }
681
}