svn-gvsig-desktop / trunk / libraries / libDwg / src / com / iver / cit / jdwglib / dwg / DwgObject.java @ 10111
History | View | Annotate | Download (10.5 KB)
1 |
/* jdwglib. Java Library for reading Dwg files.
|
---|---|
2 |
*
|
3 |
* Author: Jose Morell Rama (jose.morell@gmail.com).
|
4 |
* Port from the Pythoncad Dwg library by Art Haas.
|
5 |
*
|
6 |
* Copyright (C) 2005 Jose Morell, IVER TI S.A. 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 |
* Jose Morell (jose.morell@gmail.com)
|
25 |
*
|
26 |
* or
|
27 |
*
|
28 |
* IVER TI S.A.
|
29 |
* C/Salamanca, 50
|
30 |
* 46005 Valencia
|
31 |
* Spain
|
32 |
* +34 963163400
|
33 |
* dac@iver.es
|
34 |
*/
|
35 |
package com.iver.cit.jdwglib.dwg; |
36 |
|
37 |
import java.util.ArrayList; |
38 |
import java.util.Iterator; |
39 |
import java.util.LinkedList; |
40 |
import java.util.List; |
41 |
|
42 |
import com.iver.cit.jdwglib.dwg.objects.DwgLayer; |
43 |
|
44 |
/**
|
45 |
* The DwgObject class represents a DWG object
|
46 |
*
|
47 |
* @author jmorell
|
48 |
*/
|
49 |
public class DwgObject { |
50 |
protected int type; |
51 |
|
52 |
protected DwgHandleReference handle;
|
53 |
|
54 |
protected String version; |
55 |
|
56 |
protected int mode; |
57 |
|
58 |
/**
|
59 |
* code of the layer handle
|
60 |
*/
|
61 |
//protected int layerHandleCode;
|
62 |
|
63 |
/**
|
64 |
* layer handle as an integer
|
65 |
*/
|
66 |
protected DwgHandleReference layerHandle;
|
67 |
|
68 |
protected int color; |
69 |
|
70 |
protected int numReactors; |
71 |
|
72 |
protected boolean noLinks; |
73 |
|
74 |
protected int linetypeFlags; |
75 |
|
76 |
protected int plotstyleFlags; |
77 |
|
78 |
protected int sizeInBits; |
79 |
|
80 |
protected List extendedData; |
81 |
|
82 |
protected int graphicData; |
83 |
|
84 |
protected DwgHandleReference plotStyleHandle = null; |
85 |
|
86 |
protected DwgHandleReference subEntityHandle = null; |
87 |
|
88 |
protected DwgHandleReference xDicObjHandle = null; |
89 |
|
90 |
protected boolean graphicsFlag; |
91 |
|
92 |
private DwgFile dwgFile = null; |
93 |
|
94 |
/**
|
95 |
* Index of the dwg object in the object's map section
|
96 |
*
|
97 |
*/
|
98 |
protected int index = 0; |
99 |
|
100 |
/*
|
101 |
* Previous and Next Handle (this stuff has allowed us to solve the problem
|
102 |
* of layer handles
|
103 |
*/
|
104 |
private DwgHandleReference nextHandle = null; |
105 |
|
106 |
private DwgHandleReference previousHandle = null; |
107 |
|
108 |
//private ArrayList reactorsHandlesCodes = new ArrayList();
|
109 |
|
110 |
private ArrayList reactorsHandles = new ArrayList(); |
111 |
|
112 |
public DwgObject(int index) { |
113 |
this.index = index;
|
114 |
} |
115 |
|
116 |
public void setNextHandle(DwgHandleReference hr) { |
117 |
this.nextHandle = hr;
|
118 |
|
119 |
} |
120 |
|
121 |
public void setPreviousHandle(DwgHandleReference hr) { |
122 |
this.previousHandle = hr;
|
123 |
} |
124 |
|
125 |
/*
|
126 |
public void setReactorsHandles(ArrayList reactorsHandles) {
|
127 |
this.reactorsHandlesCodes=reactorsHandles;
|
128 |
}
|
129 |
*/
|
130 |
|
131 |
public void addReactorHandle(DwgHandleReference hr) { |
132 |
if (this.reactorsHandles == null){ |
133 |
this.reactorsHandles = new ArrayList(); |
134 |
} |
135 |
this.reactorsHandles.add(hr);
|
136 |
} |
137 |
|
138 |
|
139 |
public DwgHandleReference getNextHandle() {
|
140 |
return this.nextHandle; |
141 |
|
142 |
} |
143 |
|
144 |
public DwgHandleReference getPreviousHandle() {
|
145 |
return this.previousHandle; |
146 |
} |
147 |
|
148 |
public ArrayList getReactorsHandles() { |
149 |
return this.reactorsHandles; |
150 |
} |
151 |
|
152 |
//TODO Todo esto no vale si handle puede tomar valor -1
|
153 |
public boolean hasNextHandle() { |
154 |
return this.nextHandle != null; |
155 |
} |
156 |
|
157 |
public boolean hasPreviousHandle() { |
158 |
return this.previousHandle != null; |
159 |
} |
160 |
|
161 |
public boolean hasSubEntityHandle(){ |
162 |
return this.subEntityHandle != null; |
163 |
} |
164 |
|
165 |
public boolean hasXDicObjHandle(){ |
166 |
return this.xDicObjHandle != null; |
167 |
} |
168 |
|
169 |
public boolean hasReactorsHandles(){ |
170 |
return this.reactorsHandles.size() != 0; |
171 |
} |
172 |
|
173 |
public int reactorsHandlesQuantity(){ |
174 |
return this.reactorsHandles.size(); |
175 |
} |
176 |
|
177 |
public int getIndex() { |
178 |
return index;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* @return Returns the sizeInBits.
|
183 |
*/
|
184 |
public int getSizeInBits() { |
185 |
return sizeInBits;
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* @param sizeInBits
|
190 |
* The sizeInBits to set.
|
191 |
*/
|
192 |
public void setSizeInBits(int sizeInBits) { |
193 |
this.sizeInBits = sizeInBits;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @return Returns the extendedData.
|
198 |
*/
|
199 |
public List getExtendedData() { |
200 |
return extendedData;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* @param extData
|
205 |
* The extendedData to set.
|
206 |
*/
|
207 |
public void setExtendedData(List extData) { |
208 |
this.extendedData = extData;
|
209 |
} |
210 |
|
211 |
/**
|
212 |
* @return Returns the graphicData.
|
213 |
*/
|
214 |
public int getGraphicData() { |
215 |
return graphicData;
|
216 |
} |
217 |
|
218 |
/**
|
219 |
* @param graphicData
|
220 |
* The graphicData to set.
|
221 |
*/
|
222 |
public void setGraphicData(int graphicData) { |
223 |
this.graphicData = graphicData;
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* @return Returns the version.
|
228 |
*/
|
229 |
public String getVersion() { |
230 |
return version;
|
231 |
} |
232 |
|
233 |
/**
|
234 |
* @param linetypeFlags
|
235 |
* The linetypeFlags to set.
|
236 |
*/
|
237 |
public void setLinetypeFlags(int linetypeFlags) { |
238 |
this.linetypeFlags = linetypeFlags;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* @param plotstyleFlags
|
243 |
* The plotstyleFlags to set.
|
244 |
*/
|
245 |
public void setPlotstyleFlags(int plotstyleFlags) { |
246 |
this.plotstyleFlags = plotstyleFlags;
|
247 |
} |
248 |
|
249 |
/**
|
250 |
* @return Returns the subEntityHandle.
|
251 |
*/
|
252 |
public DwgHandleReference getSubEntityHandle() {
|
253 |
return subEntityHandle;
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* @param subEntityHandle
|
258 |
* The subEntityHandle to set.
|
259 |
*/
|
260 |
public void setSubEntityHandle(DwgHandleReference subEntityHandle) { |
261 |
this.subEntityHandle = subEntityHandle;
|
262 |
} |
263 |
|
264 |
/**
|
265 |
* @return Returns the xDicObjHandle.
|
266 |
*/
|
267 |
public DwgHandleReference getXDicObjHandle() {
|
268 |
return xDicObjHandle;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* @param dicObjHandle
|
273 |
* The xDicObjHandle to set.
|
274 |
*/
|
275 |
public void setXDicObjHandle(DwgHandleReference dicObjHandle) { |
276 |
xDicObjHandle = dicObjHandle; |
277 |
} |
278 |
|
279 |
/**
|
280 |
* @return Returns the color.
|
281 |
*/
|
282 |
public int getColor() { |
283 |
return color;
|
284 |
} |
285 |
|
286 |
/**
|
287 |
* @param color
|
288 |
* The color to set.
|
289 |
*/
|
290 |
public void setColor(int color) { |
291 |
this.color = color;
|
292 |
} |
293 |
|
294 |
/**
|
295 |
* @return Returns the handle.
|
296 |
*/
|
297 |
public DwgHandleReference getHandle() {
|
298 |
return handle;
|
299 |
} |
300 |
|
301 |
/**
|
302 |
* @param handle
|
303 |
* The handle to set.
|
304 |
*/
|
305 |
public void setHandle(DwgHandleReference handle) { |
306 |
this.handle = handle;
|
307 |
} |
308 |
|
309 |
/**
|
310 |
* @return Returns the layerHandle.
|
311 |
*/
|
312 |
public DwgHandleReference getLayerHandle() {
|
313 |
return layerHandle;
|
314 |
} |
315 |
|
316 |
/**
|
317 |
* @param layerHandle
|
318 |
* The layerHandle to set.
|
319 |
*/
|
320 |
public void setLayerHandle(DwgHandleReference layerHandle) { |
321 |
this.layerHandle = layerHandle;
|
322 |
} |
323 |
|
324 |
/**
|
325 |
* @return Returns the mode.
|
326 |
*/
|
327 |
public int getMode() { |
328 |
return mode;
|
329 |
} |
330 |
|
331 |
/**
|
332 |
* @param mode
|
333 |
* The mode to set.
|
334 |
*/
|
335 |
public void setMode(int mode) { |
336 |
this.mode = mode;
|
337 |
} |
338 |
|
339 |
/**
|
340 |
* @return Returns the noLinks.
|
341 |
*/
|
342 |
public boolean isNoLinks() { |
343 |
return noLinks;
|
344 |
} |
345 |
|
346 |
/**
|
347 |
* @param noLinks
|
348 |
* The noLinks to set.
|
349 |
*/
|
350 |
public void setNoLinks(boolean noLinks) { |
351 |
this.noLinks = noLinks;
|
352 |
} |
353 |
|
354 |
/**
|
355 |
* @return Returns the numReactors.
|
356 |
*/
|
357 |
public int getNumReactors() { |
358 |
return numReactors;
|
359 |
} |
360 |
|
361 |
/**
|
362 |
* @param numReactors
|
363 |
* The numReactors to set.
|
364 |
*/
|
365 |
public void setNumReactors(int numReactors) { |
366 |
this.numReactors = numReactors;
|
367 |
} |
368 |
|
369 |
/**
|
370 |
* @return Returns the type.
|
371 |
*/
|
372 |
public int getType() { |
373 |
return type;
|
374 |
} |
375 |
|
376 |
/**
|
377 |
* @param type
|
378 |
* The type to set.
|
379 |
*/
|
380 |
public void setType(int type) { |
381 |
this.type = type;
|
382 |
} |
383 |
|
384 |
/**
|
385 |
* @return Returns the linetypeFlags.
|
386 |
*/
|
387 |
public int getLinetypeFlags() { |
388 |
return linetypeFlags;
|
389 |
} |
390 |
|
391 |
/**
|
392 |
* @return Returns the plotstyleFlags.
|
393 |
*/
|
394 |
public int getPlotstyleFlags() { |
395 |
return plotstyleFlags;
|
396 |
} |
397 |
|
398 |
/**
|
399 |
* @param version
|
400 |
* The version to set.
|
401 |
*/
|
402 |
public void setVersion(String version) { |
403 |
this.version = version;
|
404 |
} |
405 |
|
406 |
/**
|
407 |
* @return Returns the graphicsFlag.
|
408 |
*/
|
409 |
public boolean isGraphicsFlag() { |
410 |
return graphicsFlag;
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* @param graphicsFlag
|
415 |
* The graphicsFlag to set.
|
416 |
*/
|
417 |
public void setGraphicsFlag(boolean graphicsFlag) { |
418 |
this.graphicsFlag = graphicsFlag;
|
419 |
} |
420 |
|
421 |
/*
|
422 |
* This property exists in 13-14 versions, but not in 2000 version
|
423 |
*/
|
424 |
private boolean lyrByLineType = false; |
425 |
|
426 |
public void setLyrByLineType(boolean lyrByLineType) { |
427 |
this.lyrByLineType = lyrByLineType;
|
428 |
} |
429 |
|
430 |
public boolean isLyrByLineType() { |
431 |
return lyrByLineType;
|
432 |
} |
433 |
|
434 |
public void setPlotStyleHandle(DwgHandleReference hr) { |
435 |
this.plotStyleHandle = hr;
|
436 |
|
437 |
} |
438 |
|
439 |
public boolean hasPlotStyleHandle() { |
440 |
return this.plotStyleHandle != null; |
441 |
} |
442 |
|
443 |
/*
|
444 |
* Esto solo se usa para la version 13-14
|
445 |
*/
|
446 |
private DwgHandleReference lineTypeHandle = null; |
447 |
|
448 |
/**
|
449 |
* Sets the handle of the line type of this drawing entity.
|
450 |
*
|
451 |
* TODO Ver si conviene guardar tambien el handleCode de este handle
|
452 |
*
|
453 |
* @param handle2
|
454 |
*/
|
455 |
public void setLineTypeHandle(DwgHandleReference hr) { |
456 |
this.lineTypeHandle = hr;
|
457 |
|
458 |
} |
459 |
|
460 |
public DwgHandleReference getLineTypeHandle() {
|
461 |
return this.lineTypeHandle; |
462 |
} |
463 |
|
464 |
public boolean hasLineTypeHandle() { |
465 |
return this.lineTypeHandle != null; |
466 |
} |
467 |
|
468 |
public DwgObject getSuperEntity() {
|
469 |
if(this.hasSubEntityHandle()){ |
470 |
int handleCode = this.subEntityHandle.getCode(); |
471 |
int offset = this.subEntityHandle.getOffset(); |
472 |
int handle = -1; |
473 |
|
474 |
DwgObject object; |
475 |
|
476 |
switch(handleCode){
|
477 |
// case 0x4:
|
478 |
// case 0x8:
|
479 |
// if (entity.hasNextHandle()){
|
480 |
// int nextHandleCode = entity.getNextHandle().getCode();
|
481 |
// if (nextHandleCode == 0x5) {
|
482 |
// layerHandle = entity.getNextHandle().getOffset();
|
483 |
// } else {
|
484 |
// //TODO No se han previsto nextHandleCode != 0x5
|
485 |
// System.out.println ("DwgFile.getDwgLayer: handleCode "+handleCode+
|
486 |
// " con nextHandleCode "+ nextHandleCode +" no implementado.");
|
487 |
// }
|
488 |
// }
|
489 |
// break;
|
490 |
case 0x5: |
491 |
handle = offset; |
492 |
break;
|
493 |
case 0xC: |
494 |
handle = this.getHandle().getOffset() - offset + 1; |
495 |
break;
|
496 |
default:
|
497 |
System.out.println ("DwgObejct.getDwgSuperEntity: handleCode "+handleCode+" no implementado. offset = "+offset); |
498 |
} |
499 |
if(handle != -1){ |
500 |
LinkedList objects = this.dwgFile.getDwgObjects(); |
501 |
Iterator objsIterator = objects.iterator();
|
502 |
while(objsIterator.hasNext()){
|
503 |
object = (DwgObject) objsIterator.next(); |
504 |
int objHdl = object.getHandle().getOffset();
|
505 |
if (objHdl == handle){
|
506 |
return object;
|
507 |
} |
508 |
} |
509 |
} |
510 |
System.out.println(" NO SE HA ENCONTRADO UN OBJETO CON HANDLE " + handle + ". handleCode = " + handleCode + " dwgObject.index = "+this.index +" dwgObject.type = " + this.type + " dwgObjectClassName = "+ this.getClass().getName()); |
511 |
} |
512 |
return null; |
513 |
} |
514 |
|
515 |
public void setDwgFile(DwgFile dwgFile){ |
516 |
this.dwgFile = dwgFile;
|
517 |
} |
518 |
|
519 |
public DwgFile getDwgFile(){
|
520 |
return this.dwgFile; |
521 |
} |
522 |
} |