Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgObjectFactory.java @ 10091

History | View | Annotate | Download (9 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 10091 2007-02-02 12:39:52Z azabala $
47
 * $Log$
48
 * Revision 1.9  2007-02-02 12:39:52  azabala
49
 * Added new dwg entities
50
 *
51
 * Revision 1.8  2007/02/01 20:00:27  azabala
52
 * *** empty log message ***
53
 *
54
 * Revision 1.7  2007/01/31 18:20:58  fdiaz
55
 * A?adido un return null al final de metodo create por si no entra en ninguna de las condiciones.
56
 *
57
 * Revision 1.6  2007/01/31 10:01:11  fdiaz
58
 * A?adido el DwgDictionary.
59
 *
60
 * Revision 1.5  2007/01/30 19:40:23  azabala
61
 * *** empty log message ***
62
 *
63
 * Revision 1.4  2007/01/30 12:37:18  azabala
64
 * *** empty log message ***
65
 *
66
 * Revision 1.3  2007/01/24 20:14:31  azabala
67
 * implementation of reader of V14
68
 *
69
 * Revision 1.2  2007/01/12 19:35:00  azabala
70
 * *** empty log message ***
71
 *
72
 * Revision 1.1  2007/01/09 15:39:15  azabala
73
 * *** empty log message ***
74
 *
75
 *
76
 */
77
package com.iver.cit.jdwglib.dwg;
78

    
79
import com.iver.cit.jdwglib.dwg.objects.DwgArc;
80
import com.iver.cit.jdwglib.dwg.objects.DwgAttdef;
81
import com.iver.cit.jdwglib.dwg.objects.DwgAttrib;
82
import com.iver.cit.jdwglib.dwg.objects.DwgBlock;
83
import com.iver.cit.jdwglib.dwg.objects.DwgBlockControl;
84
import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader;
85
import com.iver.cit.jdwglib.dwg.objects.DwgCircle;
86
import com.iver.cit.jdwglib.dwg.objects.DwgDictionary;
87
import com.iver.cit.jdwglib.dwg.objects.DwgDictionaryVar;
88
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse;
89
import com.iver.cit.jdwglib.dwg.objects.DwgEndblk;
90
import com.iver.cit.jdwglib.dwg.objects.DwgHatch;
91
import com.iver.cit.jdwglib.dwg.objects.DwgIdBuffer;
92
import com.iver.cit.jdwglib.dwg.objects.DwgImage;
93
import com.iver.cit.jdwglib.dwg.objects.DwgImageDef;
94
import com.iver.cit.jdwglib.dwg.objects.DwgImageDefReactor;
95
import com.iver.cit.jdwglib.dwg.objects.DwgInsert;
96
import com.iver.cit.jdwglib.dwg.objects.DwgLayer;
97
import com.iver.cit.jdwglib.dwg.objects.DwgLayerControl;
98
import com.iver.cit.jdwglib.dwg.objects.DwgLayerIndex;
99
import com.iver.cit.jdwglib.dwg.objects.DwgLine;
100
import com.iver.cit.jdwglib.dwg.objects.DwgLinearDimension;
101
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline;
102
import com.iver.cit.jdwglib.dwg.objects.DwgMText;
103
import com.iver.cit.jdwglib.dwg.objects.DwgOle2Frame;
104
import com.iver.cit.jdwglib.dwg.objects.DwgPoint;
105
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D;
106
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D;
107
import com.iver.cit.jdwglib.dwg.objects.DwgRasterVariables;
108
import com.iver.cit.jdwglib.dwg.objects.DwgSeqend;
109
import com.iver.cit.jdwglib.dwg.objects.DwgSolid;
110
import com.iver.cit.jdwglib.dwg.objects.DwgSortEntStable;
111
import com.iver.cit.jdwglib.dwg.objects.DwgSpatialFilter;
112
import com.iver.cit.jdwglib.dwg.objects.DwgSpatialIndex;
113
import com.iver.cit.jdwglib.dwg.objects.DwgSpline;
114
import com.iver.cit.jdwglib.dwg.objects.DwgText;
115
import com.iver.cit.jdwglib.dwg.objects.DwgVertex2D;
116
import com.iver.cit.jdwglib.dwg.objects.DwgVertex3D;
117
import com.iver.cit.jdwglib.dwg.objects.DwgXRecord;
118

    
119
/**
120
 * Factory that creates dwg entities from its code.
121
 * 
122
 * It's a singleton
123
 *  
124
 */
125
public class DwgObjectFactory {
126

    
127
        private static DwgObjectFactory _instance = new DwgObjectFactory();
128

    
129
        private DwgObjectFactory() {
130
        }
131

    
132
        public static final DwgObjectFactory getInstance() {
133
                return _instance;
134
        }
135

    
136
        public DwgObject create(int type, int index) {
137
                DwgObject obj = null;
138

    
139
                if (type == 0x11) {
140
                        obj = new DwgArc(index);
141
                        obj.setGraphicsFlag(true);
142
                } else if (type == 0x12) {
143
                        obj = new DwgCircle(index);
144
                        obj.setGraphicsFlag(true);
145
                } else if (type == 0x13) {
146
                        obj = new DwgLine(index);
147
                        obj.setGraphicsFlag(true);
148
                } else if (type == 0x1B) {
149
                        obj = new DwgPoint(index);
150
                        obj.setGraphicsFlag(true);
151
                } else if (type == 0x0F) {
152
                        obj = new DwgPolyline2D(index);
153
                        obj.setGraphicsFlag(true);
154
                } else if (type == 0x10) {
155
                        obj = new DwgPolyline3D(index);
156
                        obj.setGraphicsFlag(true);
157
                } else if (type == 0x0A) {
158
                        obj = new DwgVertex2D(index);
159
                        obj.setGraphicsFlag(true);
160
                } else if (type == 0x0B) {
161
                        obj = new DwgVertex3D(index);
162
                        obj.setGraphicsFlag(true);
163
                } else if (type == 0x6) {
164
                        obj = new DwgSeqend(index);
165
                        obj.setGraphicsFlag(true);
166
                } else if (type == 0x1) {
167
                        obj = new DwgText(index);
168
                        obj.setGraphicsFlag(true);
169
                } else if (type == 0x2) {
170
                        obj = new DwgAttrib(index);
171
                        obj.setGraphicsFlag(true);
172
                } else if (type == 0x3) {
173
                        obj = new DwgAttdef(index);
174
                        obj.setGraphicsFlag(true);
175
                } else if (type == 0x4) {
176
                        obj = new DwgBlock(index);
177
                        obj.setGraphicsFlag(true);
178
                } else if (type == 0x5) {
179
                        obj = new DwgEndblk(index);
180
                        obj.setGraphicsFlag(true);
181
                } else if (type == 0x2A) {
182
                        obj = new DwgDictionary(index);
183
                        //                        System.out.println("DwgObjectFactory.create: CREANDO UN
184
                        // DICTIONARY");
185
                        obj.setGraphicsFlag(false);
186
                } else if (type == 0x30) {
187
                        obj = new DwgBlockControl(index);
188
                        obj.setGraphicsFlag(false);
189
                } else if (type == 0x31) {
190
                        obj = new DwgBlockHeader(index);
191
                        obj.setGraphicsFlag(false);
192
                } else if (type == 0x32) {
193
                        obj = new DwgLayerControl(index);
194
                        obj.setGraphicsFlag(false);
195
                } else if (type == 0x33) {
196
                        obj = new DwgLayer(index);
197
                        obj.setGraphicsFlag(false);
198
                } else if (type == 0x7) {
199
                        obj = new DwgInsert(index);
200
                        obj.setGraphicsFlag(true);
201
                } else if (type == 0x2C) {
202
                        obj = new DwgMText(index);
203
                        obj.setGraphicsFlag(true);
204
                } else if (type == 0x1F) {
205
                        obj = new DwgSolid(index);
206
                        obj.setGraphicsFlag(true);
207
                } else if (type == 0x23) {
208
                        obj = new DwgEllipse(index);
209
                        obj.setGraphicsFlag(true);
210
                } else if (type == 0x24) {
211
                        obj = new DwgSpline(index);
212
                        obj.setGraphicsFlag(true);
213
                } else if (type == 0x15) {
214
                        obj = new DwgLinearDimension(index);
215
                        obj.setGraphicsFlag(true);
216
                } else if (type == 0x4D) {
217
                        obj = new DwgLwPolyline(index);
218
                        obj.setGraphicsFlag(true);
219
                } else if (type == 0x4E) {
220
                        obj = new DwgLwPolyline(index);
221
                        obj.setGraphicsFlag(true);
222
                } else if (type == 0x4F) {
223
                        obj = new DwgLwPolyline(index);
224
                        obj.setGraphicsFlag(true);
225
                } else if (type == 0x50) {
226
                        obj = new DwgLwPolyline(index);
227
                        obj.setGraphicsFlag(true);
228
                } else if (type == 0x51) {
229
                        obj = new DwgLwPolyline(index);
230
                        obj.setGraphicsFlag(true);
231
                } else if (type == 0x52) {
232
                        obj = new DwgLwPolyline(index);
233
                        obj.setGraphicsFlag(true);
234
                } else if (type == 0x53) {
235
                        obj = new DwgLwPolyline(index);
236
                        obj.setGraphicsFlag(true);
237
                } else {
238
                        //                        System.out.println("Type=" + Integer.toHexString(type)
239
                        //                                        + " desconocido");
240
                        obj = new DwgObject(index);
241
                }
242
                obj.setType(type);
243
                return obj;
244
        }
245

    
246
        /**
247
         * Creates a DwgObject from its DXF name.
248
         * 
249
         * This method is used to create entities without a fixed dwg code type
250
         * (entities whose type is > 500)
251
         *  
252
         */
253
        public DwgObject create(String dxfName, int index) {
254
                if (dxfName.equalsIgnoreCase("DICTIONARYVAR"))
255
                        return new DwgDictionaryVar(index);
256
                else if (dxfName.equalsIgnoreCase("HATCH"))
257
                        return new DwgHatch(index);
258
                else if (dxfName.equalsIgnoreCase("IDBUFFER"))
259
                        return new DwgIdBuffer(index);
260
                else if (dxfName.equalsIgnoreCase("IMAGE"))
261
                        return new DwgImage(index);
262
                else if (dxfName.equalsIgnoreCase("IMAGEDEF"))
263
                        return new DwgImageDef(index);
264
                else if (dxfName.equalsIgnoreCase("IMAGEDEFREACTOR"))
265
                        return new DwgImageDefReactor(index);
266
                else if (dxfName.equalsIgnoreCase("LAYER_INDEX"))
267
                        return new DwgLayerIndex(index);
268
                else if (dxfName.equalsIgnoreCase("LWPLINE"))
269
                        return new DwgLwPolyline(index);
270
                else if (dxfName.equalsIgnoreCase("OLE2FRAME"))
271
                        return new DwgOle2Frame(index);
272
                else if (dxfName.equalsIgnoreCase("RASTERVARIABLES"))
273
                        return new DwgRasterVariables(index);
274
                else if (dxfName.equalsIgnoreCase("SORTENTSTABLE"))
275
                        return new DwgSortEntStable(index);
276
                else if (dxfName.equalsIgnoreCase("SPATIALFILTER"))
277
                        return new DwgSpatialFilter(index);
278
                else if (dxfName.equalsIgnoreCase("SPATIALINDEX"))
279
                        return new DwgSpatialIndex(index);
280
                else if (dxfName.equalsIgnoreCase("XRECORD"))
281
                        return new DwgXRecord(index);
282
                return null;
283
        }
284
}