Search in sources :

Example 1 with ObjectAlreadyExistsException

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;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) QueryException(org.bimserver.database.queries.om.QueryException) EOFException(java.io.EOFException) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) UserException(org.bimserver.shared.exceptions.UserException) ServiceException(org.bimserver.shared.exceptions.ServiceException) ObjectAlreadyExistsException(org.bimserver.plugins.ObjectAlreadyExistsException) PublicInterfaceNotFoundException(org.bimserver.shared.exceptions.PublicInterfaceNotFoundException) IOException(java.io.IOException) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) ServerException(org.bimserver.shared.exceptions.ServerException)

Example 2 with ObjectAlreadyExistsException

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();
    }
}
Also used : IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GeometryData(org.bimserver.models.geometry.GeometryData) LittleEndianDataInputStream(com.google.common.io.LittleEndianDataInputStream) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) EOFException(java.io.EOFException) ObjectAlreadyExistsException(org.bimserver.plugins.ObjectAlreadyExistsException)

Aggregations

EOFException (java.io.EOFException)2 ObjectAlreadyExistsException (org.bimserver.plugins.ObjectAlreadyExistsException)2 LittleEndianDataInputStream (com.google.common.io.LittleEndianDataInputStream)1 IOException (java.io.IOException)1 QueryException (org.bimserver.database.queries.om.QueryException)1 IdEObject (org.bimserver.emf.IdEObject)1 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)1 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)1 GeometryData (org.bimserver.models.geometry.GeometryData)1 GeometryInfo (org.bimserver.models.geometry.GeometryInfo)1 DeserializeException (org.bimserver.plugins.deserializers.DeserializeException)1 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)1 ServerException (org.bimserver.shared.exceptions.ServerException)1 ServiceException (org.bimserver.shared.exceptions.ServiceException)1 UserException (org.bimserver.shared.exceptions.UserException)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1