com.onespatial.dwglib.objects.BlockHeader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dwg-lib Show documentation
Show all versions of dwg-lib Show documentation
dwg-lib is a Java library for reading AutoCad files version 2010 and later
The newest version!
package com.onespatial.dwglib.objects;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import com.onespatial.dwglib.FileVersion;
import com.onespatial.dwglib.bitstreams.BitBuffer;
import com.onespatial.dwglib.bitstreams.Handle;
import com.onespatial.dwglib.bitstreams.Point3D;
/**
* parent is BLOCK HEADER
*
* @author Nigel Westbury
*
*/
public class BlockHeader extends NonEntityObject {
public String entryName;
public boolean sixtyFourFlag;
private boolean blockIsXref;
private boolean xrefOverlaid;
public boolean loadedBit;
public Point3D basePoint;
public String xrefPName;
public String blockDescription;
private int[] previewData;
public int insertUnits;
public boolean explodable;
public int blockScaling;
private Handle firstEntityHandle;
private Handle lastEntityHandle;
private Handle[] ownedObjectHandles;
private Handle endBlockHandle;
private List> insertHandles;
private Handle layoutHandle;
public BlockHeader(ObjectMap objectMap) {
super(objectMap);
}
@Override
public void readObjectTypeSpecificData(BitBuffer dataStream, BitBuffer stringStream, BitBuffer handleStream,
FileVersion fileVersion) {
// 19.4.50 BLOCK HEADER (49) page 155
entryName = stringStream.getTU();
sixtyFourFlag = dataStream.getB();
/*
* At this point we always seem to be three bits prior to a word that
* best matches the expected flags. We get there reliably if we don't
* read the xrefindex value. TODO investigate this as this code may not
* be correct.
*/
// int xrefordinal = dataStream.getBS();
boolean xdep = dataStream.getB();
boolean anonymous = dataStream.getB();
boolean hasAttributes = dataStream.getB();
blockIsXref = dataStream.getB();
xrefOverlaid = dataStream.getB();
loadedBit = dataStream.getB();
int ownedObjectCount = dataStream.getBL();
basePoint = dataStream.get3BD();
xrefPName = stringStream.getTU();
List insertCounts = new ArrayList<>();
int thisInsertCount = dataStream.getRC();
while (thisInsertCount != 0) {
insertCounts.add(thisInsertCount);
thisInsertCount = dataStream.getRC();
}
blockDescription = stringStream.getTU();
int sizeOfPreviewData = dataStream.getBL();
previewData = dataStream.getBytes(sizeOfPreviewData);
insertUnits = dataStream.getBS();
explodable = dataStream.getB();
blockScaling = dataStream.getRC();
// The handles
if (!blockIsXref && !xrefOverlaid) {
firstEntityHandle = handleStream.getHandle(handleOfThisObject);
lastEntityHandle = handleStream.getHandle(handleOfThisObject);
}
ownedObjectHandles = new Handle[ownedObjectCount];
for (int i = 0; i < ownedObjectCount; i++) {
ownedObjectHandles[i] = handleStream.getHandle();
}
endBlockHandle = handleStream.getHandle();
insertHandles = new ArrayList<>();
for (Integer insertCount : insertCounts) {
List thisList = new ArrayList<>();
for (int i = 0; i < insertCount; i++) {
Handle insertHandle = handleStream.getHandle();
thisList.add(insertHandle);
}
insertHandles.add(thisList);
}
layoutHandle = handleStream.getHandle();
handleStream.advanceToByteBoundary();
dataStream.assertEndOfStream();
stringStream.assertEndOfStream();
handleStream.assertEndOfStream();
}
@Override
public String toString() {
return "BLOCK HEADER";
}
public CadObject getFirstEntity() {
if (firstEntityHandle == null) {
return null;
} else {
CadObject result = objectMap.parseObjectPossiblyNull(firstEntityHandle);
return result;
}
}
public CadObject getLastEntity() {
if (lastEntityHandle == null) {
return null;
} else {
CadObject result = objectMap.parseObjectPossiblyNull(lastEntityHandle);
return result;
}
}
public List getOwnedObjects() {
return new AbstractList() {
@Override
public CadObject get(int index) {
CadObject result = objectMap.parseObject(ownedObjectHandles[index]);
return result;
}
@Override
public int size() {
return ownedObjectHandles.length;
}
};
}
public CadObject getEndBlock() {
CadObject result = objectMap.parseObject(endBlockHandle);
return result;
}
/**
* This method returns all inserts in a flat list. This no doubt needs to be
* changed to return a two dimensional list in case consumers need the extra
* information.
*/
public List getInserts() {
List result = new ArrayList<>();
for (List x : insertHandles) {
for (Handle y : x) {
CadObject insert = objectMap.parseObjectPossiblyOrphaned(y);
result.add((Insert) insert);
}
}
return result;
}
public CadObject getLayout() {
CadObject result = objectMap.parseObjectPossiblyNull(layoutHandle);
return result;
}
}