Statistics
| Revision:

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

History | View | Annotate | Download (12.1 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 10590 2007-03-01 19:59:46Z azabala $
47
 * $Log$
48
 * Revision 1.15  2007-03-01 19:59:46  azabala
49
 * source code cleaning
50
 *
51
 * Revision 1.14  2007/02/22 20:45:51  azabala
52
 * changes to add dwg 12 entities creation
53
 *
54
 * Revision 1.13  2007/02/14 09:20:32  fdiaz
55
 * Eliminado un comentario y habilitado de nuevo el else del final del metodo create.
56
 *
57
 * Revision 1.12  2007/02/08 20:27:06  azabala
58
 * solved bug with lwpolylines
59
 *
60
 * Revision 1.11  2007/02/08 10:27:35  azabala
61
 * if the type is unknown it returns NULL
62
 *
63
 * Revision 1.10  2007/02/06 20:17:29  azabala
64
 * *** empty log message ***
65
 *
66
 * Revision 1.9  2007/02/02 12:39:52  azabala
67
 * Added new dwg entities
68
 *
69
 * Revision 1.8  2007/02/01 20:00:27  azabala
70
 * *** empty log message ***
71
 *
72
 * Revision 1.7  2007/01/31 18:20:58  fdiaz
73
 * A?adido un return null al final de metodo create por si no entra en ninguna de las condiciones.
74
 *
75
 * Revision 1.6  2007/01/31 10:01:11  fdiaz
76
 * A?adido el DwgDictionary.
77
 *
78
 * Revision 1.5  2007/01/30 19:40:23  azabala
79
 * *** empty log message ***
80
 *
81
 * Revision 1.4  2007/01/30 12:37:18  azabala
82
 * *** empty log message ***
83
 *
84
 * Revision 1.3  2007/01/24 20:14:31  azabala
85
 * implementation of reader of V14
86
 *
87
 * Revision 1.2  2007/01/12 19:35:00  azabala
88
 * *** empty log message ***
89
 *
90
 * Revision 1.1  2007/01/09 15:39:15  azabala
91
 * *** empty log message ***
92
 *
93
 *
94
 */
95
package com.iver.cit.jdwglib.dwg;
96

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

    
139

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

    
153
        private static DwgObjectFactory _instance = new DwgObjectFactory();
154

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

    
167
        public static final DwgObjectFactory getInstance() {
168
                return _instance;
169
        }
170

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

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

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