use of org.bimserver.plugins.ObjectAlreadyExistsException in project BIMserver by opensourceBIM.
the class ClientIfcModel method create.
@SuppressWarnings("unchecked")
@Override
public <T extends IdEObject> T create(EClass eClass) throws IfcModelInterfaceException, ObjectAlreadyExistsException {
final IdEObjectImpl idEObject = (IdEObjectImpl) eClass.getEPackage().getEFactoryInstance().create(eClass);
idEObject.setModel(this);
if (recordChanges) {
idEObject.eAdapters().add(adapter);
try {
Long oid = bimServerClient.getLowLevelInterface().createObject(tid, eClass.getName(), eClass.getEStructuralFeature("GlobalId") != null);
idEObject.setOid(oid);
} catch (Exception e) {
LOGGER.error("", e);
}
add(idEObject.getOid(), idEObject);
}
return (T) idEObject;
}
use of org.bimserver.plugins.ObjectAlreadyExistsException in project BIMserver by opensourceBIM.
the class ClientIfcModel method processGeometryInputStream.
private void processGeometryInputStream(InputStream inputStream, Map<Long, Long> geometryInfoOidToOid) throws IOException, GeometryException, IfcModelInterfaceException {
try (LittleEndianDataInputStream dataInputStream = new LittleEndianDataInputStream(inputStream)) {
boolean done = false;
while (!done) {
byte type = dataInputStream.readByte();
if (type == 0) {
String protocol = dataInputStream.readUTF();
if (!protocol.equals("BGS")) {
throw new GeometryException("Protocol != BGS (" + protocol + ")");
}
byte formatVersion = dataInputStream.readByte();
if (formatVersion != 11) {
throw new GeometryException("Unsupported version " + formatVersion + " / 11");
}
int skip = 4 - (7 % 4);
if (skip != 0 && skip != 4) {
dataInputStream.readFully(new byte[skip]);
}
for (int i = 0; i < 6; i++) {
dataInputStream.readDouble();
}
} else if (type == 5) {
dataInputStream.readFully(new byte[7]);
// roid
dataInputStream.readLong();
long geometryInfoOid = dataInputStream.readLong();
GeometryInfo geometryInfo = (GeometryInfo) get(geometryInfoOid);
if (geometryInfo == null) {
geometryInfo = create(GeometryInfo.class);
}
((IdEObjectImpl) geometryInfo).setOid(geometryInfoOid);
((IdEObjectImpl) geometryInfo).setLoadingState(State.LOADING);
add(geometryInfoOid, geometryInfo);
Long ifcProductOid = geometryInfoOidToOid.get(geometryInfoOid);
if (ifcProductOid == null) {
throw new GeometryException("Missing geometry info id: " + geometryInfoOid);
}
IdEObject ifcProduct = get(ifcProductOid);
EStructuralFeature geometryFeature = getPackageMetaData().getEClass("IfcProduct").getEStructuralFeature("geometry");
ifcProduct.eSet(geometryFeature, geometryInfo);
org.bimserver.models.geometry.Vector3f minBounds = GeometryFactory.eINSTANCE.createVector3f();
minBounds.setX(dataInputStream.readDouble());
minBounds.setY(dataInputStream.readDouble());
minBounds.setZ(dataInputStream.readDouble());
org.bimserver.models.geometry.Vector3f maxBounds = GeometryFactory.eINSTANCE.createVector3f();
maxBounds.setX(dataInputStream.readDouble());
maxBounds.setY(dataInputStream.readDouble());
maxBounds.setZ(dataInputStream.readDouble());
geometryInfo.setMinBounds(minBounds);
geometryInfo.setMaxBounds(maxBounds);
byte[] transformation = new byte[16 * 8];
dataInputStream.readFully(transformation);
geometryInfo.setTransformation(transformation);
long geometryDataOid = dataInputStream.readLong();
GeometryData geometryData = (GeometryData) get(geometryDataOid);
if (geometryData == null) {
geometryData = GeometryFactory.eINSTANCE.createGeometryData();
add(geometryDataOid, geometryData);
}
geometryInfo.setData(geometryData);
((IdEObjectImpl) geometryData).setLoadingState(State.LOADED);
} else if (type == 3) {
throw new GeometryException("Parts not supported");
} else if (type == 1) {
dataInputStream.readFully(new byte[7]);
long geometryDataOid = dataInputStream.readLong();
GeometryData geometryData = (GeometryData) get(geometryDataOid);
if (geometryData == null) {
geometryData = GeometryFactory.eINSTANCE.createGeometryData();
add(geometryDataOid, geometryData);
}
((IdEObjectImpl) geometryData).setOid(geometryDataOid);
((IdEObjectImpl) geometryData).setLoadingState(State.LOADING);
int nrIndices = dataInputStream.readInt();
byte[] indices = new byte[nrIndices * 4];
dataInputStream.readFully(indices);
geometryData.setIndices(indices);
int colorType = dataInputStream.readInt();
if (colorType == 1) {
dataInputStream.readFloat();
dataInputStream.readFloat();
dataInputStream.readFloat();
dataInputStream.readFloat();
}
int nrVertices = dataInputStream.readInt();
byte[] vertices = new byte[nrVertices * 4];
dataInputStream.readFully(vertices);
geometryData.setVertices(vertices);
int nrNormals = dataInputStream.readInt();
byte[] normals = new byte[nrNormals * 4];
dataInputStream.readFully(normals);
geometryData.setNormals(normals);
int nrMaterials = dataInputStream.readInt();
byte[] materials = new byte[nrMaterials * 4];
dataInputStream.readFully(materials);
geometryData.setMaterials(materials);
((IdEObjectImpl) geometryData).setLoadingState(State.LOADED);
} else if (type == 6) {
done = true;
} else {
throw new GeometryException("Unimplemented type: " + type);
}
}
} catch (EOFException e) {
//
} catch (ObjectAlreadyExistsException e) {
e.printStackTrace();
}
}
Aggregations