Search in sources :

Example 36 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class GetGeometryInfoDatabaseAction method execute.

@Override
public SGeometryInfo execute() throws UserException, BimserverDatabaseException, BimserverLockConflictException {
    Revision revision = getDatabaseSession().get(roid, OldQuery.getDefault());
    Project project = revision.getProject();
    PackageMetaData packageMetaData = bimServer.getMetaDataManager().getPackageMetaData(project.getSchema());
    IdEObject ifcProduct = getDatabaseSession().get(oid, new OldQuery(packageMetaData, project.getId(), revision.getId(), revision.getOid()));
    if (ifcProduct == null) {
        throw new UserException("Object with oid " + oid + " not found");
    }
    EStructuralFeature geometryFeature = packageMetaData.getEClass("IfcProduct").getEStructuralFeature("geometry");
    GeometryInfo geometry = (GeometryInfo) ifcProduct.eGet(geometryFeature);
    SGeometryInfo convertToSObject = bimServer.getSConverter().convertToSObject(geometry);
    return convertToSObject;
}
Also used : SGeometryInfo(org.bimserver.interfaces.objects.SGeometryInfo) Project(org.bimserver.models.store.Project) Revision(org.bimserver.models.store.Revision) IdEObject(org.bimserver.emf.IdEObject) PackageMetaData(org.bimserver.emf.PackageMetaData) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) GeometryInfo(org.bimserver.models.geometry.GeometryInfo) SGeometryInfo(org.bimserver.interfaces.objects.SGeometryInfo) UserException(org.bimserver.shared.exceptions.UserException) OldQuery(org.bimserver.database.OldQuery)

Example 37 with IdEObject

use of org.bimserver.emf.IdEObject 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)

Example 38 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class ClientIfcModel method getByGuid.

@Override
public IdEObject getByGuid(String guid) {
    IdEObject idEObject = super.getByGuid(guid);
    if (idEObject == null) {
        try {
            modelState = ModelState.LOADING;
            Query query = new Query(getPackageMetaData());
            QueryPart queryPart = query.createQueryPart();
            queryPart.addGuid(guid);
            JsonQueryObjectModelConverter converter = new JsonQueryObjectModelConverter(getPackageMetaData());
            long topicId = bimServerClient.getServiceInterface().download(Collections.singleton(roid), converter.toJson(query).toString(), getJsonSerializerOid(), false);
            waitForDonePreparing(topicId);
            processDownload(topicId);
            bimServerClient.getServiceInterface().cleanupLongAction(topicId);
            modelState = ModelState.NONE;
            return super.getByGuid(guid);
        } catch (Exception e) {
            LOGGER.error("", e);
        }
    }
    return idEObject;
}
Also used : JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) Query(org.bimserver.database.queries.om.Query) IdEObject(org.bimserver.emf.IdEObject) QueryPart(org.bimserver.database.queries.om.QueryPart) 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 39 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class DatabaseSession method commit.

public void commit(ProgressHandler progressHandler) throws BimserverDatabaseException, ServiceException {
    checkOpen();
    try {
        if (progressHandler != null) {
            progressHandler.progress(0, objectsToCommit == null ? 0 : objectsToCommit.size());
        }
        int current = 0;
        long writes = 0;
        ByteBuffer keyBuffer = ByteBuffer.wrap(new byte[16]);
        if (objectsToDelete != null) {
            for (RecordIdentifierPlusType recordIdentifier : objectsToDelete) {
                fillKeyBuffer(keyBuffer, recordIdentifier);
                database.getKeyValueStore().storeNoOverwrite(recordIdentifier.getPackageName() + "_" + recordIdentifier.getClassName(), keyBuffer.array(), new byte[] { -1 }, this);
                writes++;
            }
        }
        // This buffer is reused for the values, it's position must be reset at the end of the loop, and the convertObjectToByteArray function is responsible for setting the buffer's position to the end of the (used part of the) buffer
        ByteBuffer reusableBuffer = ByteBuffer.allocate(32768);
        if (objectsToCommit != null) {
            for (IdEObject object : objectsToCommit) {
                if (object.getOid() == -1) {
                    throw new BimserverDatabaseException("Cannot store object with oid -1");
                }
                fillKeyBuffer(keyBuffer, object);
                if (DEVELOPER_DEBUG) {
                    LOGGER.info("Write: " + object.eClass().getName() + " " + "pid=" + object.getPid() + " oid=" + object.getOid() + " rid=" + object.getRid());
                }
                ByteBuffer valueBuffer = convertObjectToByteArray(object, reusableBuffer, getMetaDataManager().getPackageMetaData(object.eClass().getEPackage().getName()));
                int valueBufferPosition = valueBuffer.position();
                processPossibleIndices(keyBuffer, object.getPid(), object.getRid(), object.getOid(), object.eClass(), valueBuffer);
                if (object.eClass().getEAnnotation("nolazyload") == null && !overwriteEnabled) {
                    database.getKeyValueStore().storeNoOverwrite(object.eClass().getEPackage().getName() + "_" + object.eClass().getName(), keyBuffer.array(), valueBuffer.array(), 0, valueBufferPosition, this);
                } else {
                    database.getKeyValueStore().store(object.eClass().getEPackage().getName() + "_" + object.eClass().getName(), keyBuffer.array(), valueBuffer.array(), 0, valueBuffer.position(), this);
                }
                if (progressHandler != null) {
                    progressHandler.progress(++current, objectsToCommit.size());
                }
                writes++;
                // bimServerClient may have increased the size of the buffer by creating a new one, we keep using it for other objects
                reusableBuffer = valueBuffer;
                reusableBuffer.position(0);
            }
        }
        if (bimTransaction != null) {
            bimTransaction.commit();
            database.getKeyValueStore().sync();
        }
        database.incrementCommittedWrites(writes);
        close();
        if (postCommitActions != null) {
            for (PostCommitAction postCommitAction : postCommitActions) {
                postCommitAction.execute();
            }
        }
    } catch (BimserverDatabaseException e) {
        throw e;
    } catch (ServiceException e) {
        throw e;
    }
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) ServiceException(org.bimserver.shared.exceptions.ServiceException) IdEObject(org.bimserver.emf.IdEObject) ByteBuffer(java.nio.ByteBuffer)

Example 40 with IdEObject

use of org.bimserver.emf.IdEObject in project BIMserver by opensourceBIM.

the class DatabaseSession method get.

@SuppressWarnings("unchecked")
public <T extends IdEObject> T get(long oid, QueryInterface query) throws BimserverDatabaseException {
    checkOpen();
    TodoList todoList = new TodoList();
    IfcModelInterface model = createModel(query);
    IdEObject idEObject = get(null, oid, model, query, todoList);
    processTodoList(model, todoList, query);
    return (T) idEObject;
}
Also used : IdEObject(org.bimserver.emf.IdEObject) IfcModelInterface(org.bimserver.emf.IfcModelInterface)

Aggregations

IdEObject (org.bimserver.emf.IdEObject)68 List (java.util.List)25 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)25 EClass (org.eclipse.emf.ecore.EClass)20 EReference (org.eclipse.emf.ecore.EReference)18 IdEObjectImpl (org.bimserver.emf.IdEObjectImpl)15 UserException (org.bimserver.shared.exceptions.UserException)15 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)14 EList (org.eclipse.emf.common.util.EList)14 EObject (org.eclipse.emf.ecore.EObject)14 ArrayList (java.util.ArrayList)12 AbstractEList (org.eclipse.emf.common.util.AbstractEList)12 HashSet (java.util.HashSet)10 IfcModelInterface (org.bimserver.emf.IfcModelInterface)10 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)10 OldQuery (org.bimserver.database.OldQuery)9 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)9 VirtualObject (org.bimserver.shared.VirtualObject)9 EAttribute (org.eclipse.emf.ecore.EAttribute)9 Project (org.bimserver.models.store.Project)8