root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgObjectFactory.java @ 10482
History | View | Annotate | Download (12 KB)
1 | 9602 | azabala | /*
|
---|---|---|---|
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$
|
||
47 | * $Log$
|
||
48 | 10482 | azabala | * 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 | 10314 | fdiaz | * 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 | 10223 | azabala | * solved bug with lwpolylines
|
56 | *
|
||
57 | * Revision 1.11 2007/02/08 10:27:35 azabala
|
||
58 | 10199 | azabala | * if the type is unknown it returns NULL
|
59 | *
|
||
60 | * Revision 1.10 2007/02/06 20:17:29 azabala
|
||
61 | 10156 | azabala | * *** empty log message ***
|
62 | *
|
||
63 | * Revision 1.9 2007/02/02 12:39:52 azabala
|
||
64 | 10091 | azabala | * Added new dwg entities
|
65 | *
|
||
66 | * Revision 1.8 2007/02/01 20:00:27 azabala
|
||
67 | 10054 | azabala | * *** empty log message ***
|
68 | *
|
||
69 | * Revision 1.7 2007/01/31 18:20:58 fdiaz
|
||
70 | 10013 | fdiaz | * 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 | 9995 | fdiaz | * A?adido el DwgDictionary.
|
74 | *
|
||
75 | * Revision 1.5 2007/01/30 19:40:23 azabala
|
||
76 | 9977 | azabala | * *** empty log message ***
|
77 | *
|
||
78 | 9986 | azabala | * Revision 1.4 2007/01/30 12:37:18 azabala
|
79 | * *** empty log message ***
|
||
80 | *
|
||
81 | 9977 | azabala | * Revision 1.3 2007/01/24 20:14:31 azabala
|
82 | 9894 | azabala | * implementation of reader of V14
|
83 | *
|
||
84 | * Revision 1.2 2007/01/12 19:35:00 azabala
|
||
85 | 9602 | azabala | * *** empty log message ***
|
86 | *
|
||
87 | 9720 | azabala | * Revision 1.1 2007/01/09 15:39:15 azabala
|
88 | * *** empty log message ***
|
||
89 | 9602 | azabala | *
|
90 | 9720 | azabala | *
|
91 | 9602 | azabala | */
|
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 | 9995 | fdiaz | import com.iver.cit.jdwglib.dwg.objects.DwgDictionary; |
102 | 9986 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgDictionaryVar; |
103 | 10482 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgDimOrd; |
104 | 9602 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgEllipse; |
105 | import com.iver.cit.jdwglib.dwg.objects.DwgEndblk; |
||
106 | 10482 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgFace3D; |
107 | 9986 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgHatch; |
108 | 10091 | azabala | 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 | 9602 | azabala | 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 | 10091 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgLayerIndex; |
116 | 9602 | azabala | 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 | 10091 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgOle2Frame; |
121 | 9602 | azabala | 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 | 10091 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgRasterVariables; |
125 | 9602 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgSeqend; |
126 | import com.iver.cit.jdwglib.dwg.objects.DwgSolid; |
||
127 | 10091 | azabala | 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 | 9602 | azabala | 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 | 10091 | azabala | import com.iver.cit.jdwglib.dwg.objects.DwgXRecord; |
135 | 9602 | azabala | |
136 | 10482 | azabala | |
137 | 9602 | azabala | /**
|
138 | 10482 | azabala | * Factory that creates dwg entities from its code (int value).
|
139 | 9602 | azabala | *
|
140 | 10482 | azabala | * 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 | 9602 | azabala | * It's a singleton
|
146 | 10091 | azabala | *
|
147 | 9602 | azabala | */
|
148 | public class DwgObjectFactory { |
||
149 | |||
150 | private static DwgObjectFactory _instance = new DwgObjectFactory(); |
||
151 | |||
152 | private DwgObjectFactory() {
|
||
153 | } |
||
154 | 10482 | azabala | |
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 | 9602 | azabala | |
164 | public static final DwgObjectFactory getInstance() { |
||
165 | return _instance;
|
||
166 | } |
||
167 | 10091 | azabala | |
168 | 10482 | azabala | |
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 | 9720 | azabala | public DwgObject create(int type, int index) { |
176 | 9602 | azabala | DwgObject obj = null;
|
177 | 10091 | azabala | |
178 | 9602 | azabala | if (type == 0x11) { |
179 | 9720 | azabala | obj = new DwgArc(index);
|
180 | 9602 | azabala | obj.setGraphicsFlag(true);
|
181 | } else if (type == 0x12) { |
||
182 | 9720 | azabala | obj = new DwgCircle(index);
|
183 | 9602 | azabala | obj.setGraphicsFlag(true);
|
184 | } else if (type == 0x13) { |
||
185 | 9720 | azabala | obj = new DwgLine(index);
|
186 | 9602 | azabala | obj.setGraphicsFlag(true);
|
187 | } else if (type == 0x1B) { |
||
188 | 9720 | azabala | obj = new DwgPoint(index);
|
189 | 9602 | azabala | obj.setGraphicsFlag(true);
|
190 | } else if (type == 0x0F) { |
||
191 | 9720 | azabala | obj = new DwgPolyline2D(index);
|
192 | 9602 | azabala | obj.setGraphicsFlag(true);
|
193 | } else if (type == 0x10) { |
||
194 | 9720 | azabala | obj = new DwgPolyline3D(index);
|
195 | 9602 | azabala | obj.setGraphicsFlag(true);
|
196 | } else if (type == 0x0A) { |
||
197 | 9720 | azabala | obj = new DwgVertex2D(index);
|
198 | 9602 | azabala | obj.setGraphicsFlag(true);
|
199 | } else if (type == 0x0B) { |
||
200 | 9720 | azabala | obj = new DwgVertex3D(index);
|
201 | 9602 | azabala | obj.setGraphicsFlag(true);
|
202 | } else if (type == 0x6) { |
||
203 | 9720 | azabala | obj = new DwgSeqend(index);
|
204 | 9602 | azabala | obj.setGraphicsFlag(true);
|
205 | } else if (type == 0x1) { |
||
206 | 9720 | azabala | obj = new DwgText(index);
|
207 | 9602 | azabala | obj.setGraphicsFlag(true);
|
208 | } else if (type == 0x2) { |
||
209 | 9720 | azabala | obj = new DwgAttrib(index);
|
210 | 9602 | azabala | obj.setGraphicsFlag(true);
|
211 | } else if (type == 0x3) { |
||
212 | 9720 | azabala | obj = new DwgAttdef(index);
|
213 | 9602 | azabala | obj.setGraphicsFlag(true);
|
214 | } else if (type == 0x4) { |
||
215 | 9720 | azabala | obj = new DwgBlock(index);
|
216 | 9602 | azabala | obj.setGraphicsFlag(true);
|
217 | } else if (type == 0x5) { |
||
218 | 9720 | azabala | obj = new DwgEndblk(index);
|
219 | 9602 | azabala | obj.setGraphicsFlag(true);
|
220 | 9995 | fdiaz | } else if (type == 0x2A) { |
221 | obj = new DwgDictionary(index);
|
||
222 | obj.setGraphicsFlag(false);
|
||
223 | 9602 | azabala | } else if (type == 0x30) { |
224 | 9720 | azabala | obj = new DwgBlockControl(index);
|
225 | 9602 | azabala | obj.setGraphicsFlag(false);
|
226 | } else if (type == 0x31) { |
||
227 | 9720 | azabala | obj = new DwgBlockHeader(index);
|
228 | 9602 | azabala | obj.setGraphicsFlag(false);
|
229 | } else if (type == 0x32) { |
||
230 | 9720 | azabala | obj = new DwgLayerControl(index);
|
231 | 9602 | azabala | obj.setGraphicsFlag(false);
|
232 | } else if (type == 0x33) { |
||
233 | 9720 | azabala | obj = new DwgLayer(index);
|
234 | 9602 | azabala | obj.setGraphicsFlag(false);
|
235 | } else if (type == 0x7) { |
||
236 | 9720 | azabala | obj = new DwgInsert(index);
|
237 | 9602 | azabala | obj.setGraphicsFlag(true);
|
238 | } else if (type == 0x2C) { |
||
239 | 9720 | azabala | obj = new DwgMText(index);
|
240 | 9602 | azabala | obj.setGraphicsFlag(true);
|
241 | } else if (type == 0x1F) { |
||
242 | 9720 | azabala | obj = new DwgSolid(index);
|
243 | 9602 | azabala | obj.setGraphicsFlag(true);
|
244 | } else if (type == 0x23) { |
||
245 | 9720 | azabala | obj = new DwgEllipse(index);
|
246 | 9602 | azabala | obj.setGraphicsFlag(true);
|
247 | } else if (type == 0x24) { |
||
248 | 9720 | azabala | obj = new DwgSpline(index);
|
249 | 9602 | azabala | obj.setGraphicsFlag(true);
|
250 | } else if (type == 0x15) { |
||
251 | 9720 | azabala | obj = new DwgLinearDimension(index);
|
252 | 9602 | azabala | obj.setGraphicsFlag(true);
|
253 | 10156 | azabala | } |
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 | 9720 | azabala | obj = new DwgLwPolyline(index);
|
265 | 9602 | azabala | obj.setGraphicsFlag(true);
|
266 | 10156 | azabala | } 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 | 9720 | azabala | obj = new DwgLwPolyline(index);
|
276 | 9602 | azabala | obj.setGraphicsFlag(true);
|
277 | } else if (type == 0x4F) {
|
||
278 | 9720 | azabala | obj = new DwgLwPolyline(index);
|
279 | 9602 | azabala | obj.setGraphicsFlag(true);
|
280 | } else if (type == 0x50) {
|
||
281 | 9720 | azabala | obj = new DwgLwPolyline(index);
|
282 | 9602 | azabala | obj.setGraphicsFlag(true);
|
283 | } else if (type == 0x51) {
|
||
284 | 9720 | azabala | obj = new DwgLwPolyline(index);
|
285 | 9602 | azabala | obj.setGraphicsFlag(true);
|
286 | } else if (type == 0x52) {
|
||
287 | 9720 | azabala | obj = new DwgLwPolyline(index);
|
288 | 9602 | azabala | obj.setGraphicsFlag(true);
|
289 | } else if (type == 0x53) {
|
||
290 | 9720 | azabala | obj = new DwgLwPolyline(index);
|
291 | 9602 | azabala | obj.setGraphicsFlag(true);
|
292 | 10156 | azabala | }
|
293 | */
|
||
294 | |||
295 | else {
|
||
296 | 9720 | azabala | obj = new DwgObject(index);
|
297 | 9602 | azabala | } |
298 | obj.setType(type); |
||
299 | return obj;
|
||
300 | } |
||
301 | 9995 | fdiaz | |
302 | 10091 | azabala | /**
|
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 | 10482 | azabala | *
|
308 | * This method is used for DWG 13, 14 and 2000 files.
|
||
309 | 10091 | azabala | *
|
310 | */
|
||
311 | public DwgObject create(String dxfName, int index) { |
||
312 | 10223 | azabala | //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 | 10091 | azabala | if (dxfName.equalsIgnoreCase("DICTIONARYVAR")) |
318 | 9986 | azabala | return new DwgDictionaryVar(index); |
319 | 10091 | azabala | else if (dxfName.equalsIgnoreCase("HATCH")) |
320 | 9986 | azabala | return new DwgHatch(index); |
321 | 10091 | azabala | 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 | 10223 | azabala | 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 | 10091 | azabala | 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 | 10013 | fdiaz | return null; |
348 | 10091 | azabala | } |
349 | 10482 | azabala | |
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 | 10091 | azabala | } |