Statistics
| Revision:

root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgObjectFactory.java @ 10482

History | View | Annotate | Download (12 KB)

1
/*
2
 * Created on 27-dic-2006
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
/* CVS MESSAGES:
45
 *
46
 * $Id: DwgObjectFactory.java 10482 2007-02-22 20:45:51Z azabala $
47
 * $Log$
48
 * Revision 1.14  2007-02-22 20:45:51  azabala
49
 * changes to add dwg 12 entities creation
50
 *
51
 * Revision 1.13  2007/02/14 09:20:32  fdiaz
52
 * Eliminado un comentario y habilitado de nuevo el else del final del metodo create.
53
 *
54
 * Revision 1.12  2007/02/08 20:27:06  azabala
55
 * solved bug with lwpolylines
56
 *
57
 * Revision 1.11  2007/02/08 10:27:35  azabala
58
 * if the type is unknown it returns NULL
59
 *
60
 * Revision 1.10  2007/02/06 20:17:29  azabala
61
 * *** empty log message ***
62
 *
63
 * Revision 1.9  2007/02/02 12:39:52  azabala
64
 * Added new dwg entities
65
 *
66
 * Revision 1.8  2007/02/01 20:00:27  azabala
67
 * *** empty log message ***
68
 *
69
 * Revision 1.7  2007/01/31 18:20:58  fdiaz
70
 * A?adido un return null al final de metodo create por si no entra en ninguna de las condiciones.
71
 *
72
 * Revision 1.6  2007/01/31 10:01:11  fdiaz
73
 * A?adido el DwgDictionary.
74
 *
75
 * Revision 1.5  2007/01/30 19:40:23  azabala
76
 * *** empty log message ***
77
 *
78
 * Revision 1.4  2007/01/30 12:37:18  azabala
79
 * *** empty log message ***
80
 *
81
 * Revision 1.3  2007/01/24 20:14:31  azabala
82
 * implementation of reader of V14
83
 *
84
 * Revision 1.2  2007/01/12 19:35:00  azabala
85
 * *** empty log message ***
86
 *
87
 * Revision 1.1  2007/01/09 15:39:15  azabala
88
 * *** empty log message ***
89
 *
90
 *
91
 */
92
package com.iver.cit.jdwglib.dwg;
93

    
94
import com.iver.cit.jdwglib.dwg.objects.DwgArc;
95
import com.iver.cit.jdwglib.dwg.objects.DwgAttdef;
96
import com.iver.cit.jdwglib.dwg.objects.DwgAttrib;
97
import com.iver.cit.jdwglib.dwg.objects.DwgBlock;
98
import com.iver.cit.jdwglib.dwg.objects.DwgBlockControl;
99
import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader;
100
import com.iver.cit.jdwglib.dwg.objects.DwgCircle;
101
import com.iver.cit.jdwglib.dwg.objects.DwgDictionary;
102
import com.iver.cit.jdwglib.dwg.objects.DwgDictionaryVar;
103
import com.iver.cit.jdwglib.dwg.objects.DwgDimOrd;
104
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse;
105
import com.iver.cit.jdwglib.dwg.objects.DwgEndblk;
106
import com.iver.cit.jdwglib.dwg.objects.DwgFace3D;
107
import com.iver.cit.jdwglib.dwg.objects.DwgHatch;
108
import com.iver.cit.jdwglib.dwg.objects.DwgIdBuffer;
109
import com.iver.cit.jdwglib.dwg.objects.DwgImage;
110
import com.iver.cit.jdwglib.dwg.objects.DwgImageDef;
111
import com.iver.cit.jdwglib.dwg.objects.DwgImageDefReactor;
112
import com.iver.cit.jdwglib.dwg.objects.DwgInsert;
113
import com.iver.cit.jdwglib.dwg.objects.DwgLayer;
114
import com.iver.cit.jdwglib.dwg.objects.DwgLayerControl;
115
import com.iver.cit.jdwglib.dwg.objects.DwgLayerIndex;
116
import com.iver.cit.jdwglib.dwg.objects.DwgLine;
117
import com.iver.cit.jdwglib.dwg.objects.DwgLinearDimension;
118
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
119
import com.iver.cit.jdwglib.dwg.objects.DwgMText;
120
import com.iver.cit.jdwglib.dwg.objects.DwgOle2Frame;
121
import com.iver.cit.jdwglib.dwg.objects.DwgPoint;
122
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D;
123
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D;
124
import com.iver.cit.jdwglib.dwg.objects.DwgRasterVariables;
125
import com.iver.cit.jdwglib.dwg.objects.DwgSeqend;
126
import com.iver.cit.jdwglib.dwg.objects.DwgSolid;
127
import com.iver.cit.jdwglib.dwg.objects.DwgSortEntStable;
128
import com.iver.cit.jdwglib.dwg.objects.DwgSpatialFilter;
129
import com.iver.cit.jdwglib.dwg.objects.DwgSpatialIndex;
130
import com.iver.cit.jdwglib.dwg.objects.DwgSpline;
131
import com.iver.cit.jdwglib.dwg.objects.DwgText;
132
import com.iver.cit.jdwglib.dwg.objects.DwgVertex2D;
133
import com.iver.cit.jdwglib.dwg.objects.DwgVertex3D;
134
import com.iver.cit.jdwglib.dwg.objects.DwgXRecord;
135

    
136

    
137
/**
138
 * Factory that creates dwg entities from its code (int value).
139
 * 
140
 * Some DWG entities dont have a fixed "type code". Instead, their type
141
 * is specified in the CLASSES section of the dwg file.
142
 * 
143
 * 
144
 * 
145
 * It's a singleton
146
 *  
147
 */
148
public class DwgObjectFactory {
149

    
150
        private static DwgObjectFactory _instance = new DwgObjectFactory();
151

    
152
        private DwgObjectFactory() {
153
        }
154
        
155
        /*
156
         * Constants to represent polyline2d, polyline3d,
157
         * vertex2d and vertex3d.
158
         * */
159
        public static final byte POLYLINE2D = 40;
160
        public static final byte POLYLINE3D = 41;
161
        public static final byte VERTEX2D = 50;
162
        public static final byte VERTEX3D = 51;
163

    
164
        public static final DwgObjectFactory getInstance() {
165
                return _instance;
166
        }
167

    
168
        
169
        /**
170
         * Creates a Dwg object instance from its type.
171
         * 
172
         * This method is used for DWG 13, 14 and 2000 files.
173
         * 
174
         * */
175
        public DwgObject create(int type, int index) {
176
                DwgObject obj = null;
177

    
178
                if (type == 0x11) {
179
                        obj = new DwgArc(index);
180
                        obj.setGraphicsFlag(true);
181
                } else if (type == 0x12) {
182
                        obj = new DwgCircle(index);
183
                        obj.setGraphicsFlag(true);
184
                } else if (type == 0x13) {
185
                        obj = new DwgLine(index);
186
                        obj.setGraphicsFlag(true);
187
                } else if (type == 0x1B) {
188
                        obj = new DwgPoint(index);
189
                        obj.setGraphicsFlag(true);
190
                } else if (type == 0x0F) {
191
                        obj = new DwgPolyline2D(index);
192
                        obj.setGraphicsFlag(true);
193
                } else if (type == 0x10) {
194
                        obj = new DwgPolyline3D(index);
195
                        obj.setGraphicsFlag(true);
196
                } else if (type == 0x0A) {
197
                        obj = new DwgVertex2D(index);
198
                        obj.setGraphicsFlag(true);
199
                } else if (type == 0x0B) {
200
                        obj = new DwgVertex3D(index);
201
                        obj.setGraphicsFlag(true);
202
                } else if (type == 0x6) {
203
                        obj = new DwgSeqend(index);
204
                        obj.setGraphicsFlag(true);
205
                } else if (type == 0x1) {
206
                        obj = new DwgText(index);
207
                        obj.setGraphicsFlag(true);
208
                } else if (type == 0x2) {
209
                        obj = new DwgAttrib(index);
210
                        obj.setGraphicsFlag(true);
211
                } else if (type == 0x3) {
212
                        obj = new DwgAttdef(index);
213
                        obj.setGraphicsFlag(true);
214
                } else if (type == 0x4) {
215
                        obj = new DwgBlock(index);
216
                        obj.setGraphicsFlag(true);
217
                } else if (type == 0x5) {
218
                        obj = new DwgEndblk(index);
219
                        obj.setGraphicsFlag(true);
220
                } else if (type == 0x2A) {
221
                        obj = new DwgDictionary(index);
222
                        obj.setGraphicsFlag(false);
223
                } else if (type == 0x30) {
224
                        obj = new DwgBlockControl(index);
225
                        obj.setGraphicsFlag(false);
226
                } else if (type == 0x31) {
227
                        obj = new DwgBlockHeader(index);
228
                        obj.setGraphicsFlag(false);
229
                } else if (type == 0x32) {
230
                        obj = new DwgLayerControl(index);
231
                        obj.setGraphicsFlag(false);
232
                } else if (type == 0x33) {
233
                        obj = new DwgLayer(index);
234
                        obj.setGraphicsFlag(false);
235
                } else if (type == 0x7) {
236
                        obj = new DwgInsert(index);
237
                        obj.setGraphicsFlag(true);
238
                } else if (type == 0x2C) {
239
                        obj = new DwgMText(index);
240
                        obj.setGraphicsFlag(true);
241
                } else if (type == 0x1F) {
242
                        obj = new DwgSolid(index);
243
                        obj.setGraphicsFlag(true);
244
                } else if (type == 0x23) {
245
                        obj = new DwgEllipse(index);
246
                        obj.setGraphicsFlag(true);
247
                } else if (type == 0x24) {
248
                        obj = new DwgSpline(index);
249
                        obj.setGraphicsFlag(true);
250
                } else if (type == 0x15) {
251
                        obj = new DwgLinearDimension(index);
252
                        obj.setGraphicsFlag(true);
253
                } 
254
                /*
255
                 * Segun los foros de OpenDWG:
256
                 * OLE2FRAME - 74 -> 0X4A
257
                   LWPOLYLINE - 77 -> 0X4D 
258
                   HATCH - 78 -> 0X4E
259
                 * 
260
                 * 
261
                 * */
262
                
263
                else if (type == 0x4D) {
264
                        obj = new DwgLwPolyline(index);
265
                        obj.setGraphicsFlag(true);
266
                } else if (type == 0x4A){
267
                        obj = new DwgOle2Frame(index);
268
                        obj.setGraphicsFlag(false);
269
                }else if (type == 0x4E){
270
                        obj = new DwgHatch(index);
271
                        obj.setGraphicsFlag(true);
272
                }
273
                /*
274
                else if (type == 0x4E) {
275
                        obj = new DwgLwPolyline(index);
276
                        obj.setGraphicsFlag(true);
277
                } else if (type == 0x4F) {
278
                        obj = new DwgLwPolyline(index);
279
                        obj.setGraphicsFlag(true);
280
                } else if (type == 0x50) {
281
                        obj = new DwgLwPolyline(index);
282
                        obj.setGraphicsFlag(true);
283
                } else if (type == 0x51) {
284
                        obj = new DwgLwPolyline(index);
285
                        obj.setGraphicsFlag(true);
286
                } else if (type == 0x52) {
287
                        obj = new DwgLwPolyline(index);
288
                        obj.setGraphicsFlag(true);
289
                } else if (type == 0x53) {
290
                        obj = new DwgLwPolyline(index);
291
                        obj.setGraphicsFlag(true);
292
                } 
293
                */
294
                
295
                else {
296
                        obj = new DwgObject(index);
297
                }
298
                obj.setType(type);
299
                return obj;
300
        }
301

    
302
        /**
303
         * Creates a DwgObject from its DXF name.
304
         * 
305
         * This method is used to create entities without a fixed dwg code type
306
         * (entities whose type is > 500)
307
         * 
308
         * This method is used for DWG 13, 14 and 2000 files.
309
         *  
310
         */
311
        public DwgObject create(String dxfName, int index) {
312
                //TODO De todas estas ver cuales son graficas,
313
                //para poner su graphicsFlag a true
314
                //ESTO MEJOR VA A SER CADA CLASE QUIEN LO HAGA, EN VEZ
315
                //DE LA FACTORIA
316
                
317
                if (dxfName.equalsIgnoreCase("DICTIONARYVAR"))
318
                        return new DwgDictionaryVar(index);
319
                else if (dxfName.equalsIgnoreCase("HATCH"))
320
                        return new DwgHatch(index);
321
                else if (dxfName.equalsIgnoreCase("IDBUFFER"))
322
                        return new DwgIdBuffer(index);
323
                else if (dxfName.equalsIgnoreCase("IMAGE"))
324
                        return new DwgImage(index);
325
                else if (dxfName.equalsIgnoreCase("IMAGEDEF"))
326
                        return new DwgImageDef(index);
327
                else if (dxfName.equalsIgnoreCase("IMAGEDEFREACTOR"))
328
                        return new DwgImageDefReactor(index);
329
                else if (dxfName.equalsIgnoreCase("LAYER_INDEX"))
330
                        return new DwgLayerIndex(index);
331
                else if (dxfName.equalsIgnoreCase("LWPOLYLINE")){
332
                        DwgLwPolyline solution = new DwgLwPolyline(index);
333
                        solution.setGraphicsFlag(true);
334
                        return solution;
335
                }else if (dxfName.equalsIgnoreCase("OLE2FRAME"))
336
                        return new DwgOle2Frame(index);
337
                else if (dxfName.equalsIgnoreCase("RASTERVARIABLES"))
338
                        return new DwgRasterVariables(index);
339
                else if (dxfName.equalsIgnoreCase("SORTENTSTABLE"))
340
                        return new DwgSortEntStable(index);
341
                else if (dxfName.equalsIgnoreCase("SPATIALFILTER"))
342
                        return new DwgSpatialFilter(index);
343
                else if (dxfName.equalsIgnoreCase("SPATIALINDEX"))
344
                        return new DwgSpatialIndex(index);
345
                else if (dxfName.equalsIgnoreCase("XRECORD"))
346
                        return new DwgXRecord(index);
347
                return null;
348
        }
349
        
350
        /**
351
         * Creates a DWG object for DWG 12 files.
352
         *  
353
         * */
354
        //TODO REVISAR POLYLINE Y VERTEX
355
        public DwgObject create(byte kind, int index){
356
                switch(kind){
357
                case 1:
358
                        return new DwgLine(index);
359
                case 2:
360
                        return new DwgPoint(index);
361
                case 3:
362
                        return new DwgCircle(index);
363
//                case 4://un dxf shape es un fichero externo que define una forma
364
                        //(un tipo rudimentario de svg)
365
//                        return new DwgShape()
366
                case 7:
367
                        return new DwgText(index);
368
                case 8:
369
                        return new DwgArc(index);
370
//                case 9: //It is a 3D quad
371
//                        return new DwgTrace(index);
372
                        
373
                case 12:
374
                        return new DwgSolid(index);
375
                case 13:
376
                        return new DwgBlock(index);
377
                case 14:
378
                        return new DwgEndblk(index);
379
                case 15:
380
                        return new DwgInsert(index);
381
                case 16:
382
                        return new DwgAttdef(index);
383
                case 17:
384
                        return new DwgAttrib(index);        
385
                case 18://no estoy seguro de q esto sea SbEnd
386
                        return new DwgSeqend(index);
387
//                case 20://la polilinea es un caso especial
388
//                        return new DwgPolyline3D(index);
389
//                case 21://los vertices tb
390
//                        return new DwgVertex3D(index);
391
                case 23:
392
                        return new DwgFace3D(index);
393
                case 24: //esto es Dim ??
394
                        return new DwgDimOrd(index);
395
//                case 25://no implementado
396
//                        return new DwgVPort(index);
397
                case POLYLINE2D:
398
                        return new DwgPolyline2D(index);
399
                case POLYLINE3D: 
400
                        return new DwgPolyline3D(index);
401
                case VERTEX2D:
402
                        return new DwgVertex2D(index);
403
                case VERTEX3D:
404
                        return new DwgVertex3D(index);
405
                        default:
406
                                return null;
407
                }
408
        }
409
}