Statistics
| Revision:

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

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

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

    
145

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

    
159
        private static DwgObjectFactory _instance = new DwgObjectFactory();
160

    
161
        private DwgObjectFactory() {
162
        }
163
        
164
        /*
165
         * Constants to represent polyline2d, polyline3d,
166
         * vertex2d and vertex3d.
167
         * */
168
//        public static final byte POLYLINE2D = 40;
169
//        public static final byte POLYLINE3D = 41;
170
//        public static final byte VERTEX2D = 50;
171
//        public static final byte VERTEX3D = 51;
172

    
173
        public static final DwgObjectFactory getInstance() {
174
                return _instance;
175
        }
176

    
177
        
178
        /**
179
         * Creates a Dwg object instance from its type.
180
         * 
181
         * This method is used for DWG 13, 14 and 2000 files.
182
         * 
183
         * */
184
        public DwgObject create(int type, int index) {
185
                DwgObject obj = null;
186

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

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