root / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgObjectFactory.java @ 10820
History | View | Annotate | Download (12.8 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 10820 2007-03-20 19:57:09Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.18 2007-03-20 19:55:27 azabala
|
49 |
* source code cleaning
|
50 |
*
|
51 |
* Revision 1.17 2007/03/06 19:39:38 azabala
|
52 |
* Changes to adapt dwg 12 to general architecture
|
53 |
*
|
54 |
* Revision 1.16 2007/03/02 20:31:22 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.15 2007/03/01 19:59:46 azabala
|
58 |
* source code cleaning
|
59 |
*
|
60 |
* Revision 1.14 2007/02/22 20:45:51 azabala
|
61 |
* changes to add dwg 12 entities creation
|
62 |
*
|
63 |
* Revision 1.13 2007/02/14 09:20:32 fdiaz
|
64 |
* Eliminado un comentario y habilitado de nuevo el else del final del metodo create.
|
65 |
*
|
66 |
* Revision 1.12 2007/02/08 20:27:06 azabala
|
67 |
* solved bug with lwpolylines
|
68 |
*
|
69 |
* Revision 1.11 2007/02/08 10:27:35 azabala
|
70 |
* if the type is unknown it returns NULL
|
71 |
*
|
72 |
* Revision 1.10 2007/02/06 20:17:29 azabala
|
73 |
* *** empty log message ***
|
74 |
*
|
75 |
* Revision 1.9 2007/02/02 12:39:52 azabala
|
76 |
* Added new dwg entities
|
77 |
*
|
78 |
* Revision 1.8 2007/02/01 20:00:27 azabala
|
79 |
* *** empty log message ***
|
80 |
*
|
81 |
* Revision 1.7 2007/01/31 18:20:58 fdiaz
|
82 |
* A?adido un return null al final de metodo create por si no entra en ninguna de las condiciones.
|
83 |
*
|
84 |
* Revision 1.6 2007/01/31 10:01:11 fdiaz
|
85 |
* A?adido el DwgDictionary.
|
86 |
*
|
87 |
* Revision 1.5 2007/01/30 19:40:23 azabala
|
88 |
* *** empty log message ***
|
89 |
*
|
90 |
* Revision 1.4 2007/01/30 12:37:18 azabala
|
91 |
* *** empty log message ***
|
92 |
*
|
93 |
* Revision 1.3 2007/01/24 20:14:31 azabala
|
94 |
* implementation of reader of V14
|
95 |
*
|
96 |
* Revision 1.2 2007/01/12 19:35:00 azabala
|
97 |
* *** empty log message ***
|
98 |
*
|
99 |
* Revision 1.1 2007/01/09 15:39:15 azabala
|
100 |
* *** empty log message ***
|
101 |
*
|
102 |
*
|
103 |
*/
|
104 |
package com.iver.cit.jdwglib.dwg; |
105 |
|
106 |
import com.iver.cit.jdwglib.dwg.objects.DwgArc; |
107 |
import com.iver.cit.jdwglib.dwg.objects.DwgAttdef; |
108 |
import com.iver.cit.jdwglib.dwg.objects.DwgAttrib; |
109 |
import com.iver.cit.jdwglib.dwg.objects.DwgBlock; |
110 |
import com.iver.cit.jdwglib.dwg.objects.DwgBlockControl; |
111 |
import com.iver.cit.jdwglib.dwg.objects.DwgBlockHeader; |
112 |
import com.iver.cit.jdwglib.dwg.objects.DwgCircle; |
113 |
import com.iver.cit.jdwglib.dwg.objects.DwgDictionary; |
114 |
import com.iver.cit.jdwglib.dwg.objects.DwgDictionaryVar; |
115 |
import com.iver.cit.jdwglib.dwg.objects.DwgDimOrd; |
116 |
import com.iver.cit.jdwglib.dwg.objects.DwgEllipse; |
117 |
import com.iver.cit.jdwglib.dwg.objects.DwgEndblk; |
118 |
import com.iver.cit.jdwglib.dwg.objects.DwgFace3D; |
119 |
import com.iver.cit.jdwglib.dwg.objects.DwgHatch; |
120 |
import com.iver.cit.jdwglib.dwg.objects.DwgIdBuffer; |
121 |
import com.iver.cit.jdwglib.dwg.objects.DwgImage; |
122 |
import com.iver.cit.jdwglib.dwg.objects.DwgImageDef; |
123 |
import com.iver.cit.jdwglib.dwg.objects.DwgImageDefReactor; |
124 |
import com.iver.cit.jdwglib.dwg.objects.DwgInsert; |
125 |
import com.iver.cit.jdwglib.dwg.objects.DwgLayer; |
126 |
import com.iver.cit.jdwglib.dwg.objects.DwgLayerControl; |
127 |
import com.iver.cit.jdwglib.dwg.objects.DwgLayerIndex; |
128 |
import com.iver.cit.jdwglib.dwg.objects.DwgLine; |
129 |
import com.iver.cit.jdwglib.dwg.objects.DwgLwPolyline; |
130 |
import com.iver.cit.jdwglib.dwg.objects.DwgMText; |
131 |
import com.iver.cit.jdwglib.dwg.objects.DwgMeshPolyline; |
132 |
import com.iver.cit.jdwglib.dwg.objects.DwgOle2Frame; |
133 |
import com.iver.cit.jdwglib.dwg.objects.DwgPFacePolyline; |
134 |
import com.iver.cit.jdwglib.dwg.objects.DwgPoint; |
135 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline2D; |
136 |
import com.iver.cit.jdwglib.dwg.objects.DwgPolyline3D; |
137 |
import com.iver.cit.jdwglib.dwg.objects.DwgRasterVariables; |
138 |
import com.iver.cit.jdwglib.dwg.objects.DwgSeqend; |
139 |
import com.iver.cit.jdwglib.dwg.objects.DwgSolid; |
140 |
import com.iver.cit.jdwglib.dwg.objects.DwgSortEntStable; |
141 |
import com.iver.cit.jdwglib.dwg.objects.DwgSpatialFilter; |
142 |
import com.iver.cit.jdwglib.dwg.objects.DwgSpatialIndex; |
143 |
import com.iver.cit.jdwglib.dwg.objects.DwgSpline; |
144 |
import com.iver.cit.jdwglib.dwg.objects.DwgText; |
145 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertex2D; |
146 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertex3D; |
147 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertexMesh; |
148 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFace; |
149 |
import com.iver.cit.jdwglib.dwg.objects.DwgVertexPFaceFace; |
150 |
import com.iver.cit.jdwglib.dwg.objects.DwgXRecord; |
151 |
|
152 |
|
153 |
/**
|
154 |
* Factory that creates dwg entities from its code (int value).
|
155 |
*
|
156 |
* Some DWG entities dont have a fixed "type code". Instead, their type
|
157 |
* is specified in the CLASSES section of the dwg file.
|
158 |
*
|
159 |
*
|
160 |
*
|
161 |
* It's a singleton
|
162 |
*
|
163 |
*/
|
164 |
public class DwgObjectFactory { |
165 |
|
166 |
private static DwgObjectFactory _instance = new DwgObjectFactory(); |
167 |
|
168 |
private DwgObjectFactory() {
|
169 |
} |
170 |
|
171 |
/*
|
172 |
* Constants to represent polyline2d, polyline3d,
|
173 |
* vertex2d and vertex3d.
|
174 |
* */
|
175 |
// public static final byte POLYLINE2D = 40;
|
176 |
// public static final byte POLYLINE3D = 41;
|
177 |
// public static final byte VERTEX2D = 50;
|
178 |
// public static final byte VERTEX3D = 51;
|
179 |
|
180 |
public static final DwgObjectFactory getInstance() { |
181 |
return _instance;
|
182 |
} |
183 |
|
184 |
|
185 |
/**
|
186 |
* Creates a Dwg object instance from its type.
|
187 |
*
|
188 |
* This method is used for DWG 13, 14 and 2000 files.
|
189 |
*
|
190 |
* */
|
191 |
public DwgObject create(int type, int index) { |
192 |
DwgObject obj = null;
|
193 |
|
194 |
if (type == 0x11) { |
195 |
obj = new DwgArc(index);
|
196 |
obj.setGraphicsFlag(true);
|
197 |
} else if (type == 0x1D) { |
198 |
obj = new DwgPFacePolyline(index);
|
199 |
obj.setGraphicsFlag(true);
|
200 |
} else if (type == 0x1E) { |
201 |
obj = new DwgMeshPolyline(index);
|
202 |
obj.setGraphicsFlag(true);
|
203 |
} |
204 |
else if (type == 0x12) { |
205 |
obj = new DwgCircle(index);
|
206 |
obj.setGraphicsFlag(true);
|
207 |
} else if (type == 0x13) { |
208 |
obj = new DwgLine(index);
|
209 |
obj.setGraphicsFlag(true);
|
210 |
} else if (type == 0x1B) { |
211 |
obj = new DwgPoint(index);
|
212 |
obj.setGraphicsFlag(true);
|
213 |
} else if (type == 0x0F) { |
214 |
obj = new DwgPolyline2D(index);
|
215 |
obj.setGraphicsFlag(true);
|
216 |
} else if (type == 0x10) { |
217 |
obj = new DwgPolyline3D(index);
|
218 |
obj.setGraphicsFlag(true);
|
219 |
} else if (type == 0x0A) { |
220 |
obj = new DwgVertex2D(index);
|
221 |
obj.setGraphicsFlag(true);
|
222 |
} else if (type == 0x0B) { |
223 |
obj = new DwgVertex3D(index);
|
224 |
obj.setGraphicsFlag(true);
|
225 |
} else if (type == 0x0C) { |
226 |
obj = new DwgVertexMesh(index);
|
227 |
obj.setGraphicsFlag(true);
|
228 |
}else if (type == 0x0D) { |
229 |
obj = new DwgVertexPFace(index);
|
230 |
obj.setGraphicsFlag(true);
|
231 |
}else if (type == 0x0E) { |
232 |
obj = new DwgVertexPFaceFace(index);
|
233 |
obj.setGraphicsFlag(true);
|
234 |
} |
235 |
else if (type == 0x6) { |
236 |
obj = new DwgSeqend(index);
|
237 |
obj.setGraphicsFlag(true);
|
238 |
} else if (type == 0x1) { |
239 |
obj = new DwgText(index);
|
240 |
obj.setGraphicsFlag(true);
|
241 |
} else if (type == 0x2) { |
242 |
obj = new DwgAttrib(index);
|
243 |
obj.setGraphicsFlag(true);
|
244 |
} else if (type == 0x3) { |
245 |
obj = new DwgAttdef(index);
|
246 |
obj.setGraphicsFlag(true);
|
247 |
} else if (type == 0x4) { |
248 |
obj = new DwgBlock(index);
|
249 |
obj.setGraphicsFlag(true);
|
250 |
} else if (type == 0x5) { |
251 |
obj = new DwgEndblk(index);
|
252 |
obj.setGraphicsFlag(true);
|
253 |
} else if (type == 0x2A) { |
254 |
obj = new DwgDictionary(index);
|
255 |
obj.setGraphicsFlag(false);
|
256 |
} else if (type == 0x30) { |
257 |
obj = new DwgBlockControl(index);
|
258 |
obj.setGraphicsFlag(false);
|
259 |
} else if (type == 0x31) { |
260 |
obj = new DwgBlockHeader(index);
|
261 |
obj.setGraphicsFlag(false);
|
262 |
} else if (type == 0x32) { |
263 |
obj = new DwgLayerControl(index);
|
264 |
obj.setGraphicsFlag(false);
|
265 |
} else if (type == 0x33) { |
266 |
obj = new DwgLayer(index);
|
267 |
obj.setGraphicsFlag(false);
|
268 |
} else if (type == 0x7) { |
269 |
obj = new DwgInsert(index);
|
270 |
obj.setGraphicsFlag(true);
|
271 |
} else if (type == 0x2C) { |
272 |
obj = new DwgMText(index);
|
273 |
obj.setGraphicsFlag(true);
|
274 |
} |
275 |
// else if (type == 0x1F) {
|
276 |
// obj = new DwgSolid(index);
|
277 |
// obj.setGraphicsFlag(true);
|
278 |
// }
|
279 |
else if (type == 0x23) { |
280 |
obj = new DwgEllipse(index);
|
281 |
obj.setGraphicsFlag(true);
|
282 |
} else if (type == 0x24) { |
283 |
obj = new DwgSpline(index);
|
284 |
obj.setGraphicsFlag(true);
|
285 |
} |
286 |
// else if (type == 0x15) {
|
287 |
// obj = new DwgLinearDimension(index);
|
288 |
// obj.setGraphicsFlag(true);
|
289 |
// }
|
290 |
/*
|
291 |
* Segun los foros de OpenDWG:
|
292 |
* OLE2FRAME - 74 -> 0X4A
|
293 |
LWPOLYLINE - 77 -> 0X4D
|
294 |
HATCH - 78 -> 0X4E
|
295 |
*
|
296 |
*
|
297 |
* */
|
298 |
|
299 |
else if (type == 0x4D) { |
300 |
obj = new DwgLwPolyline(index);
|
301 |
obj.setGraphicsFlag(true);
|
302 |
} |
303 |
/*
|
304 |
else if (type == 0x4A){
|
305 |
obj = new DwgOle2Frame(index);
|
306 |
obj.setGraphicsFlag(false);
|
307 |
}
|
308 |
|
309 |
|
310 |
else if (type == 0x4E){
|
311 |
obj = new DwgHatch(index);
|
312 |
obj.setGraphicsFlag(true);
|
313 |
}
|
314 |
|
315 |
else if (type == 0x4E) {
|
316 |
obj = new DwgLwPolyline(index);
|
317 |
obj.setGraphicsFlag(true);
|
318 |
} else if (type == 0x4F) {
|
319 |
obj = new DwgLwPolyline(index);
|
320 |
obj.setGraphicsFlag(true);
|
321 |
} else if (type == 0x50) {
|
322 |
obj = new DwgLwPolyline(index);
|
323 |
obj.setGraphicsFlag(true);
|
324 |
} else if (type == 0x51) {
|
325 |
obj = new DwgLwPolyline(index);
|
326 |
obj.setGraphicsFlag(true);
|
327 |
} else if (type == 0x52) {
|
328 |
obj = new DwgLwPolyline(index);
|
329 |
obj.setGraphicsFlag(true);
|
330 |
} else if (type == 0x53) {
|
331 |
obj = new DwgLwPolyline(index);
|
332 |
obj.setGraphicsFlag(true);
|
333 |
}
|
334 |
*/
|
335 |
|
336 |
else {
|
337 |
// obj = new DwgObject(index);
|
338 |
return null; |
339 |
} |
340 |
obj.setType(type); |
341 |
return obj;
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* Creates a DwgObject from its DXF name.
|
346 |
*
|
347 |
* This method is used to create entities without a fixed dwg code type
|
348 |
* (entities whose type is > 500)
|
349 |
*
|
350 |
* This method is used for DWG 13, 14 and 2000 files.
|
351 |
*
|
352 |
*/
|
353 |
public DwgObject create(String dxfName, int index) { |
354 |
//TODO De todas estas ver cuales son graficas,
|
355 |
//para poner su graphicsFlag a true
|
356 |
//ESTO MEJOR VA A SER CADA CLASE QUIEN LO HAGA, EN VEZ
|
357 |
//DE LA FACTORIA
|
358 |
|
359 |
if (dxfName.equalsIgnoreCase("DICTIONARYVAR")) |
360 |
return new DwgDictionaryVar(index); |
361 |
else if (dxfName.equalsIgnoreCase("HATCH")) |
362 |
return new DwgHatch(index); |
363 |
else if (dxfName.equalsIgnoreCase("IDBUFFER")) |
364 |
return new DwgIdBuffer(index); |
365 |
else if (dxfName.equalsIgnoreCase("IMAGE")) |
366 |
return new DwgImage(index); |
367 |
else if (dxfName.equalsIgnoreCase("IMAGEDEF")) |
368 |
return new DwgImageDef(index); |
369 |
else if (dxfName.equalsIgnoreCase("IMAGEDEFREACTOR")) |
370 |
return new DwgImageDefReactor(index); |
371 |
else if (dxfName.equalsIgnoreCase("LAYER_INDEX")) |
372 |
return new DwgLayerIndex(index); |
373 |
else if (dxfName.equalsIgnoreCase("LWPOLYLINE")){ |
374 |
DwgLwPolyline solution = new DwgLwPolyline(index);
|
375 |
solution.setGraphicsFlag(true);
|
376 |
return solution;
|
377 |
}else if (dxfName.equalsIgnoreCase("OLE2FRAME")) |
378 |
return new DwgOle2Frame(index); |
379 |
else if (dxfName.equalsIgnoreCase("RASTERVARIABLES")) |
380 |
return new DwgRasterVariables(index); |
381 |
else if (dxfName.equalsIgnoreCase("SORTENTSTABLE")) |
382 |
return new DwgSortEntStable(index); |
383 |
else if (dxfName.equalsIgnoreCase("SPATIALFILTER")) |
384 |
return new DwgSpatialFilter(index); |
385 |
else if (dxfName.equalsIgnoreCase("SPATIALINDEX")) |
386 |
return new DwgSpatialIndex(index); |
387 |
else if (dxfName.equalsIgnoreCase("XRECORD")) |
388 |
return new DwgXRecord(index); |
389 |
return null; |
390 |
} |
391 |
|
392 |
/**
|
393 |
* Creates a DWG object for DWG 12 files.
|
394 |
*
|
395 |
* */
|
396 |
public DwgObject create(byte kind, int index){ |
397 |
switch(kind){
|
398 |
case 1: |
399 |
return new DwgLine(index); |
400 |
case 2: |
401 |
return new DwgPoint(index); |
402 |
case 3: |
403 |
return new DwgCircle(index); |
404 |
// case 4://un dxf shape es un fichero externo que define una forma
|
405 |
//(un tipo rudimentario de svg)
|
406 |
// return new DwgShape()
|
407 |
case 7: |
408 |
return new DwgText(index); |
409 |
case 8: |
410 |
return new DwgArc(index); |
411 |
// case 9: //It is a 3D quad
|
412 |
// return new DwgTrace(index);
|
413 |
|
414 |
case 11: |
415 |
return new DwgSolid(index); |
416 |
case 12: |
417 |
return new DwgBlockHeader(index); |
418 |
case 13: |
419 |
return new DwgEndblk(index); |
420 |
case 14: |
421 |
return new DwgInsert(index); |
422 |
case 15: |
423 |
return new DwgAttdef(index); |
424 |
case 16: |
425 |
return new DwgAttrib(index); |
426 |
case 17://no estoy seguro de q esto sea SbEnd |
427 |
return new DwgSeqend(index); |
428 |
case 19://polyline is a particular case. Creation responsability is of Reader |
429 |
return null; |
430 |
case 20://vertex like polyline |
431 |
return null; |
432 |
case 22: |
433 |
return new DwgFace3D(index); |
434 |
case 23: //esto es Dim ?? |
435 |
return new DwgDimOrd(index); |
436 |
// case 25://no implementado
|
437 |
// return new DwgVPort(index);
|
438 |
default:
|
439 |
return null; |
440 |
} |
441 |
} |
442 |
} |