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