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