Search in sources :

Example 11 with QueryObjectProvider

use of org.bimserver.database.queries.QueryObjectProvider in project BIMserver by opensourceBIM.

the class RemoveAttributeChange method execute.

@SuppressWarnings("rawtypes")
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    if (transaction.getDatabaseSession().getEClassForOid(oid).getName().equals("IfcFurnishingElement")) {
        System.out.println();
    }
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        Query query = new Query(packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addOid(oid);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
    if (eAttribute == null) {
        throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (eAttribute.isMany()) {
        List list = (List) object.get(eAttribute.getName());
        list.remove(index);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException)

Example 12 with QueryObjectProvider

use of org.bimserver.database.queries.QueryObjectProvider in project BIMserver by opensourceBIM.

the class SetAttributeChange method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        Query query = new Query(packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        queryPart.addOid(oid);
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    EAttribute eAttribute = packageMetaData.getEAttribute(eClass.getName(), attributeName);
    if (eAttribute == null) {
        throw new UserException("No attribute with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (value instanceof List && eAttribute.isMany()) {
        List sourceList = (List) value;
        if (!eAttribute.isMany()) {
            throw new UserException("Attribute is not of type 'many'");
        }
        List list = (List) object.eGet(eAttribute);
        list.clear();
        List asStringList = null;
        if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
            asStringList = (List) object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
            asStringList.clear();
        }
        for (Object o : sourceList) {
            if (eAttribute.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                asStringList.add(String.valueOf(o));
            }
            list.add(o);
        }
    } else {
        if (eAttribute.isMany()) {
            throw new UserException("Attribute is not of type 'single'");
        }
        if (eAttribute.getEType() instanceof EEnum) {
            EEnum eEnum = (EEnum) eAttribute.getEType();
            object.set(eAttribute.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
        } else {
            object.set(eAttribute.getName(), value);
        }
        if (value instanceof Double) {
            object.set(object.eClass().getEStructuralFeature(attributeName + "AsString").getName(), String.valueOf((Double) value));
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) Query(org.bimserver.database.queries.om.Query) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) List(java.util.List) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) UserException(org.bimserver.shared.exceptions.UserException) EEnum(org.eclipse.emf.ecore.EEnum)

Example 13 with QueryObjectProvider

use of org.bimserver.database.queries.QueryObjectProvider in project BIMserver by opensourceBIM.

the class SetReferenceChange method execute.

@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    Query query = new Query(packageMetaData);
    QueryPart queryPart = query.createQueryPart();
    queryPart.addOid(oid);
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    EReference eReference = packageMetaData.getEReference(eClass.getName(), referenceName);
    if (eReference == null) {
        throw new UserException("No reference with the name \"" + referenceName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (eReference.isMany()) {
        throw new UserException("Attribute is not of type 'single'");
    }
    object.setReference(eReference, referenceOid, 0);
}
Also used : EClass(org.eclipse.emf.ecore.EClass) Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) UserException(org.bimserver.shared.exceptions.UserException) EReference(org.eclipse.emf.ecore.EReference)

Example 14 with QueryObjectProvider

use of org.bimserver.database.queries.QueryObjectProvider in project BIMserver by opensourceBIM.

the class SetWrappedAttributeChange method execute.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Transaction transaction) throws UserException, BimserverLockConflictException, BimserverDatabaseException, IOException, QueryException {
    PackageMetaData packageMetaData = transaction.getDatabaseSession().getMetaDataManager().getPackageMetaData(transaction.getProject().getSchema());
    Query query = new Query(packageMetaData);
    QueryPart queryPart = query.createQueryPart();
    queryPart.addOid(oid);
    HashMapVirtualObject object = transaction.get(oid);
    if (object == null) {
        QueryObjectProvider queryObjectProvider = new QueryObjectProvider(transaction.getDatabaseSession(), transaction.getBimServer(), query, Collections.singleton(transaction.getPreviousRevision().getOid()), packageMetaData);
        object = queryObjectProvider.next();
        transaction.updated(object);
    }
    EClass eClass = transaction.getDatabaseSession().getEClassForOid(oid);
    if (!ChangeHelper.canBeChanged(eClass)) {
        throw new UserException("Only objects from the following schemas are allowed to be changed: Ifc2x3tc1 and IFC4, this object (" + eClass.getName() + ") is from the \"" + eClass.getEPackage().getName() + "\" package");
    }
    if (object == null) {
        throw new UserException("No object of type \"" + eClass.getName() + "\" with oid " + oid + " found in project with pid " + transaction.getProject().getId());
    }
    EReference eReference = packageMetaData.getEReference(eClass.getName(), attributeName);
    if (eReference == null) {
        throw new UserException("No reference with the name \"" + attributeName + "\" found in class \"" + eClass.getName() + "\"");
    }
    if (value instanceof List && eReference.isMany()) {
        List sourceList = (List) value;
        if (!eReference.isMany()) {
            throw new UserException("Attribute is not of type 'many'");
        }
        List list = (List) object.eGet(eReference);
        for (Object o : sourceList) {
            if (eReference.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                List asStringList = (List) object.eGet(object.eClass().getEStructuralFeature(attributeName + "AsString"));
                asStringList.add(String.valueOf(o));
            }
            list.add(o);
        }
    } else {
        if (eReference.isMany()) {
            throw new UserException("Attribute is not of type 'single'");
        }
        if (eReference.getEType() instanceof EEnum) {
            EEnum eEnum = (EEnum) eReference.getEType();
            object.set(eReference.getName(), eEnum.getEEnumLiteral(((String) value).toUpperCase()).getInstance());
        } else {
            EClass typeEClass = (EClass) packageMetaData.getEClassifier(type);
            if (typeEClass.getEAnnotation("wrapped") == null) {
                throw new UserException("Not a wrapped type");
            }
            HashMapWrappedVirtualObject wrappedObject = new HashMapWrappedVirtualObject(typeEClass);
            if (typeEClass == Ifc2x3tc1Package.eINSTANCE.getIfcBoolean()) {
                if ((Boolean) value == true) {
                    value = Tristate.TRUE;
                } else {
                    value = Tristate.FALSE;
                }
            }
            wrappedObject.set(wrappedObject.eClass().getEStructuralFeature("wrappedValue").getName(), value);
            object.set(eReference.getName(), wrappedObject);
        }
    // if (value instanceof Double) {
    // idEObject.eSet(idEObject.eClass().getEStructuralFeature(attributeName + "AsString"), String.valueOf((Double)value));
    // }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) Query(org.bimserver.database.queries.om.Query) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) PackageMetaData(org.bimserver.emf.PackageMetaData) QueryPart(org.bimserver.database.queries.om.QueryPart) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) List(java.util.List) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) UserException(org.bimserver.shared.exceptions.UserException) EEnum(org.eclipse.emf.ecore.EEnum) EReference(org.eclipse.emf.ecore.EReference)

Example 15 with QueryObjectProvider

use of org.bimserver.database.queries.QueryObjectProvider in project BIMserver by opensourceBIM.

the class GeometryRunner method run.

@Override
public void run() {
    long start = System.nanoTime();
    job.setStartNanos(start);
    try {
        HashMapVirtualObject next = objectProvider.next();
        Query query = new Query("Double buffer query " + eClass.getName(), this.streamingGeometryGenerator.packageMetaData);
        QueryPart queryPart = query.createQueryPart();
        while (next != null) {
            queryPart.addOid(next.getOid());
            if (this.streamingGeometryGenerator.packageMetaData.getEClass("IfcProduct").isSuperTypeOf(next.eClass())) {
                job.addObject(next.getOid(), next.eClass().getName());
            }
            next = objectProvider.next();
        }
        objectProvider = new QueryObjectProvider(databaseSession, this.streamingGeometryGenerator.bimServer, query, Collections.singleton(queryContext.getRoid()), this.streamingGeometryGenerator.packageMetaData);
        StreamingSerializer ifcSerializer = ifcSerializerPlugin.createSerializer(new PluginConfiguration());
        RenderEngine renderEngine = null;
        byte[] bytes = null;
        try {
            final Set<HashMapVirtualObject> objects = new HashSet<>();
            ObjectProviderProxy proxy = new ObjectProviderProxy(objectProvider, new ObjectListener() {

                @Override
                public void newObject(HashMapVirtualObject next) {
                    if (eClass.isSuperTypeOf(next.eClass())) {
                        if (next.eGet(GeometryRunner.this.streamingGeometryGenerator.representationFeature) != null) {
                            objects.add(next);
                        }
                    }
                }
            });
            ifcSerializer.init(proxy, null, null, this.streamingGeometryGenerator.bimServer.getPluginManager(), this.streamingGeometryGenerator.packageMetaData);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(ifcSerializer.getInputStream(), baos);
            bytes = baos.toByteArray();
            InputStream in = new ByteArrayInputStream(bytes);
            Map<Integer, String> notFoundObjects = new HashMap<>();
            Set<Range> reusableGeometryData = new HashSet<>();
            Map<Long, Q> productToData = new HashMap<>();
            try {
                if (!objects.isEmpty()) {
                    renderEngine = renderEnginePool.borrowObject();
                    try (RenderEngineModel renderEngineModel = renderEngine.openModel(in, bytes.length)) {
                        renderEngineModel.setSettings(renderEngineSettings);
                        renderEngineModel.setFilter(renderEngineFilter);
                        try {
                            renderEngineModel.generateGeneralGeometry();
                        } catch (RenderEngineException e) {
                            if (e.getCause() instanceof java.io.EOFException) {
                                if (objects.isEmpty() || eClass.getName().equals("IfcAnnotation")) {
                                // SKIP
                                } else {
                                    StreamingGeometryGenerator.LOGGER.error("Error in " + eClass.getName(), e);
                                }
                            }
                        }
                        OidConvertingSerializer oidConvertingSerializer = (OidConvertingSerializer) ifcSerializer;
                        Map<Long, Integer> oidToEid = oidConvertingSerializer.getOidToEid();
                        Map<Long, double[]> matrices = new HashMap<>();
                        for (HashMapVirtualObject ifcProduct : objects) {
                            if (!this.streamingGeometryGenerator.running) {
                                return;
                            }
                            if (ifcProduct.get("GlobalId").equals("1sZn$z_i91bPOCQJOkOibU")) {
                                System.out.println();
                            }
                            Integer expressId = oidToEid.get(ifcProduct.getOid());
                            try {
                                RenderEngineInstance renderEngineInstance = renderEngineModel.getInstanceFromExpressId(expressId);
                                RenderEngineGeometry geometry = renderEngineInstance.generateGeometry();
                                boolean translate = true;
                                if (geometry != null && geometry.getNrIndices() > 0) {
                                    VirtualObject geometryInfo = new HashMapVirtualObject(queryContext, GeometryPackage.eINSTANCE.getGeometryInfo());
                                    WrappedVirtualObject minBounds = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                    WrappedVirtualObject maxBounds = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                    minBounds.set("x", Double.POSITIVE_INFINITY);
                                    minBounds.set("y", Double.POSITIVE_INFINITY);
                                    minBounds.set("z", Double.POSITIVE_INFINITY);
                                    maxBounds.set("x", -Double.POSITIVE_INFINITY);
                                    maxBounds.set("y", -Double.POSITIVE_INFINITY);
                                    maxBounds.set("z", -Double.POSITIVE_INFINITY);
                                    geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MinBounds(), minBounds);
                                    geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MaxBounds(), maxBounds);
                                    WrappedVirtualObject minBoundsUntranslated = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                    WrappedVirtualObject maxBoundsUntranslated = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                    minBoundsUntranslated.set("x", Double.POSITIVE_INFINITY);
                                    minBoundsUntranslated.set("y", Double.POSITIVE_INFINITY);
                                    minBoundsUntranslated.set("z", Double.POSITIVE_INFINITY);
                                    maxBoundsUntranslated.set("x", -Double.POSITIVE_INFINITY);
                                    maxBoundsUntranslated.set("y", -Double.POSITIVE_INFINITY);
                                    maxBoundsUntranslated.set("z", -Double.POSITIVE_INFINITY);
                                    geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MinBoundsUntranslated(), minBoundsUntranslated);
                                    geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MaxBoundsUntranslated(), maxBoundsUntranslated);
                                    geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Area(), renderEngineInstance.getArea());
                                    geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Volume(), renderEngineInstance.getVolume());
                                    VirtualObject geometryData = new HashMapVirtualObject(queryContext, GeometryPackage.eINSTANCE.getGeometryData());
                                    int[] indices = geometry.getIndices();
                                    geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Indices(), GeometryUtils.intArrayToByteArray(indices));
                                    float[] vertices = geometry.getVertices();
                                    geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Vertices(), GeometryUtils.floatArrayToByteArray(vertices));
                                    geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Normals(), GeometryUtils.floatArrayToByteArray(geometry.getNormals()));
                                    geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_PrimitiveCount(), indices.length / 3);
                                    job.setTrianglesGenerated(indices.length / 3);
                                    job.getReport().incrementTriangles(indices.length / 3);
                                    Set<Color4f> usedColors = new HashSet<>();
                                    if (geometry.getMaterialIndices() != null && geometry.getMaterialIndices().length > 0) {
                                        boolean hasMaterial = false;
                                        float[] vertex_colors = new float[vertices.length / 3 * 4];
                                        for (int i = 0; i < geometry.getMaterialIndices().length; ++i) {
                                            int c = geometry.getMaterialIndices()[i];
                                            for (int j = 0; j < 3; ++j) {
                                                int k = indices[i * 3 + j];
                                                if (c > -1) {
                                                    hasMaterial = true;
                                                    Color4f color = new Color4f();
                                                    for (int l = 0; l < 4; ++l) {
                                                        float val = geometry.getMaterials()[4 * c + l];
                                                        vertex_colors[4 * k + l] = val;
                                                        color.set(l, val);
                                                    }
                                                    usedColors.add(color);
                                                }
                                            }
                                        }
                                        if (usedColors.size() == 1) {
                                            WrappedVirtualObject color = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector4f());
                                            Color4f firstColor = usedColors.iterator().next();
                                            color.set("x", firstColor.getR());
                                            color.set("y", firstColor.getG());
                                            color.set("z", firstColor.getB());
                                            color.set("w", firstColor.getA());
                                            geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Color(), color);
                                            hasMaterial = false;
                                        }
                                        if (hasMaterial) {
                                            geometryData.setAttribute(GeometryPackage.eINSTANCE.getGeometryData_Materials(), GeometryUtils.floatArrayToByteArray(vertex_colors));
                                        }
                                    }
                                    double[] productTranformationMatrix = new double[16];
                                    if (translate && renderEngineInstance.getTransformationMatrix() != null) {
                                        productTranformationMatrix = renderEngineInstance.getTransformationMatrix();
                                    } else {
                                        Matrix.setIdentityM(productTranformationMatrix, 0);
                                    }
                                    geometryInfo.setReference(GeometryPackage.eINSTANCE.getGeometryInfo_Data(), geometryData.getOid(), 0);
                                    long size = this.streamingGeometryGenerator.getSize(geometryData);
                                    for (int i = 0; i < indices.length; i++) {
                                        this.streamingGeometryGenerator.processExtends(geometryInfo, productTranformationMatrix, vertices, indices[i] * 3, generateGeometryResult);
                                        this.streamingGeometryGenerator.processExtendsUntranslated(geometryInfo, vertices, indices[i] * 3, generateGeometryResult);
                                    }
                                    double[] mibu = new double[] { (double) minBoundsUntranslated.eGet(GeometryPackage.eINSTANCE.getVector3f_X()), (double) minBoundsUntranslated.eGet(GeometryPackage.eINSTANCE.getVector3f_Y()), (double) minBoundsUntranslated.eGet(GeometryPackage.eINSTANCE.getVector3f_Z()), 1d };
                                    double[] mabu = new double[] { (double) maxBoundsUntranslated.eGet(GeometryPackage.eINSTANCE.getVector3f_X()), (double) maxBoundsUntranslated.eGet(GeometryPackage.eINSTANCE.getVector3f_Y()), (double) maxBoundsUntranslated.eGet(GeometryPackage.eINSTANCE.getVector3f_Z()), 1d };
                                    if (reuseGeometry) {
                                        int hash = this.streamingGeometryGenerator.hash(geometryData);
                                        float[] firstVertex = new float[] { vertices[indices[0]], vertices[indices[0] + 1], vertices[indices[0] + 2] };
                                        float[] lastVertex = new float[] { vertices[indices[indices.length - 1] * 3], vertices[indices[indices.length - 1] * 3 + 1], vertices[indices[indices.length - 1] * 3 + 2] };
                                        Range range = new Range(firstVertex, lastVertex);
                                        if (this.streamingGeometryGenerator.hashes.containsKey(hash)) {
                                            geometryInfo.setReference(GeometryPackage.eINSTANCE.getGeometryInfo_Data(), this.streamingGeometryGenerator.hashes.get(hash), 0);
                                            this.streamingGeometryGenerator.bytesSavedByHash.addAndGet(size);
                                        } else if (geometryReused) {
                                            boolean found = false;
                                            // }
                                            if (!found) {
                                                range.setGeometryDataOid(geometryData.getOid());
                                                reusableGeometryData.add(range);
                                                geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Area(), renderEngineInstance.getArea());
                                                geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Volume(), renderEngineInstance.getVolume());
                                                geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_PrimitiveCount(), indices.length / 3);
                                                productToData.put(ifcProduct.getOid(), new Q(geometryData.getOid(), renderEngineInstance.getArea(), renderEngineInstance.getVolume(), indices.length / 3, size, mibu, mabu));
                                                geometryData.save();
                                            }
                                        } else {
                                            // }
                                            if (geometryReused) {
                                                range.setGeometryDataOid(geometryData.getOid());
                                                reusableGeometryData.add(range);
                                                productToData.put(ifcProduct.getOid(), new Q(geometryData.getOid(), renderEngineInstance.getArea(), renderEngineInstance.getVolume(), indices.length / 3, size, mibu, mabu));
                                            }
                                            this.streamingGeometryGenerator.hashes.put(hash, geometryData.getOid());
                                            geometryData.save();
                                        // sizes.put(size, ifcProduct);
                                        }
                                    } else {
                                        geometryData.save();
                                    }
                                    calculateObb(geometryInfo, productTranformationMatrix, indices, vertices, generateGeometryResult);
                                    this.streamingGeometryGenerator.setTransformationMatrix(geometryInfo, productTranformationMatrix);
                                    matrices.put(ifcProduct.getOid(), productTranformationMatrix);
                                    geometryInfo.save();
                                    this.streamingGeometryGenerator.totalBytes.addAndGet(size);
                                    ifcProduct.setReference(this.streamingGeometryGenerator.geometryFeature, geometryInfo.getOid(), 0);
                                    ifcProduct.saveOverwrite();
                                // Doing a sync here because probably
                                // writing large amounts of data, and db
                                // only syncs every 100.000 writes by
                                // default
                                // databaseSession.getKeyValueStore().sync();
                                } else {
                                // TODO
                                }
                            } catch (EntityNotFoundException e) {
                                // e.printStackTrace();
                                // As soon as we find a representation that
                                // is not Curve2D, then we should show a
                                // "INFO" message in the log to indicate
                                // there could be something wrong
                                boolean ignoreNotFound = eClass.getName().equals("IfcAnnotation");
                                // }
                                if (!ignoreNotFound) {
                                    // LOGGER.warn("Entity not found " +
                                    // ifcProduct.eClass().getName() + " " +
                                    // (expressId) + "/" +
                                    // ifcProduct.getOid());
                                    notFoundObjects.put(expressId, ifcProduct.eClass().getName());
                                }
                            } catch (BimserverDatabaseException | RenderEngineException e) {
                                StreamingGeometryGenerator.LOGGER.error("", e);
                            }
                        }
                        if (geometryReused && map != null) {
                            long firstKey = map.keySet().iterator().next();
                            ProductDef masterProductDef = map.get(firstKey);
                            for (long key : map.keySet()) {
                                if (key != firstKey) {
                                    ProductDef productDef = map.get(key);
                                    HashMapVirtualObject ifcProduct = productDef.getObject();
                                    Q q = productToData.get(productDef.getMasterOid());
                                    if (q != null) {
                                        VirtualObject geometryInfo = new HashMapVirtualObject(queryContext, GeometryPackage.eINSTANCE.getGeometryInfo());
                                        WrappedVirtualObject minBounds = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                        WrappedVirtualObject maxBounds = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                        double[] mibu = q.getMibu();
                                        double[] mabu = q.getMibu();
                                        double[] mibt = new double[4];
                                        double[] mabt = new double[4];
                                        // TODO
                                        Matrix.multiplyMV(mibt, 0, productDef.getProductMatrix(), 0, mibu, 0);
                                        Matrix.multiplyMV(mabt, 0, productDef.getProductMatrix(), 0, mabu, 0);
                                        minBounds.set("x", mibt[0]);
                                        minBounds.set("y", mibt[1]);
                                        minBounds.set("z", mibt[2]);
                                        maxBounds.set("x", mabt[0]);
                                        maxBounds.set("y", mabt[1]);
                                        maxBounds.set("z", mabt[2]);
                                        geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MinBounds(), minBounds);
                                        geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MaxBounds(), maxBounds);
                                        WrappedVirtualObject minBoundsUntranslated = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                        WrappedVirtualObject maxBoundsUntranslated = new HashMapWrappedVirtualObject(GeometryPackage.eINSTANCE.getVector3f());
                                        minBoundsUntranslated.set("x", mibu[0]);
                                        minBoundsUntranslated.set("y", mibu[1]);
                                        minBoundsUntranslated.set("z", mibu[2]);
                                        maxBoundsUntranslated.set("x", mabu[0]);
                                        maxBoundsUntranslated.set("y", mabu[1]);
                                        maxBoundsUntranslated.set("z", mabu[2]);
                                        geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MinBoundsUntranslated(), minBoundsUntranslated);
                                        geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_MaxBoundsUntranslated(), maxBoundsUntranslated);
                                        geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Area(), q.getArea());
                                        geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_Volume(), q.getVolume());
                                        geometryInfo.setAttribute(GeometryPackage.eINSTANCE.getGeometryInfo_PrimitiveCount(), q.getNrPrimitives());
                                        this.streamingGeometryGenerator.bytesSavedByMapping.addAndGet(q.getSize());
                                        this.streamingGeometryGenerator.totalBytes.addAndGet(q.getSize());
                                        double[] inverted = Matrix.identity();
                                        if (!Matrix.invertM(inverted, 0, masterProductDef.getMappingMatrix(), 0)) {
                                            System.out.println("No inverse");
                                        }
                                        double[] finalMatrix = Matrix.identity();
                                        double[] totalTranformationMatrix = Matrix.identity();
                                        Matrix.multiplyMM(finalMatrix, 0, productDef.getMappingMatrix(), 0, inverted, 0);
                                        Matrix.multiplyMM(totalTranformationMatrix, 0, productDef.getProductMatrix(), 0, finalMatrix, 0);
                                        if (matrices.containsKey(ifcProduct.getOid())) {
                                            if (!Arrays.equals(matrices.get(ifcProduct.getOid()), totalTranformationMatrix)) {
                                                System.out.println("Not the same " + ifcProduct.get("GlobalId"));
                                                Matrix.dump(matrices.get(ifcProduct.getOid()));
                                                System.out.println();
                                                Matrix.dump(totalTranformationMatrix);
                                            }
                                        }
                                        geometryInfo.setReference(GeometryPackage.eINSTANCE.getGeometryInfo_Data(), q.getOid(), 0);
                                        // for (int i = 0; i <
                                        // indices.length; i++) {
                                        // processExtends(geometryInfo,
                                        // productTranformationMatrix,
                                        // vertices, indices[i] * 3,
                                        // generateGeometryResult);
                                        // processExtendsUntranslated(geometryInfo,
                                        // vertices, indices[i] * 3,
                                        // generateGeometryResult);
                                        // }
                                        // calculateObb(geometryInfo,
                                        // productTranformationMatrix,
                                        // indices, vertices,
                                        // generateGeometryResult);
                                        this.streamingGeometryGenerator.setTransformationMatrix(geometryInfo, totalTranformationMatrix);
                                        geometryInfo.save();
                                        // totalBytes.addAndGet(size);
                                        ifcProduct.setReference(this.streamingGeometryGenerator.geometryFeature, geometryInfo.getOid(), 0);
                                        ifcProduct.saveOverwrite();
                                    }
                                }
                            }
                        }
                    }
                }
            } finally {
                if (renderEngine != null) {
                    renderEnginePool.returnObject(renderEngine);
                }
                try {
                    if (!notFoundObjects.isEmpty()) {
                        int debugId = writeDebugFile(bytes, false, notFoundObjects);
                        job.setException(new Exception("Missing objects in model (" + Joiner.on(", ").join(notFoundObjects.keySet()) + ")"), debugId);
                    } else if (writeOutputFiles) {
                        int debugId = writeDebugFile(bytes, false, null);
                        job.setDebugFile(debugId);
                    }
                    in.close();
                } catch (Throwable e) {
                } finally {
                }
                this.streamingGeometryGenerator.jobsDone.incrementAndGet();
                this.streamingGeometryGenerator.updateProgress();
            }
        } catch (Exception e) {
            StreamingGeometryGenerator.LOGGER.error("", e);
            int debugId = writeDebugFile(bytes, true, null);
            job.setException(e, debugId);
        // LOGGER.error("Original query: " + originalQuery, e);
        }
    } catch (Exception e) {
        StreamingGeometryGenerator.LOGGER.error("", e);
    // LOGGER.error("Original query: " + originalQuery, e);
    }
    long end = System.nanoTime();
    job.setEndNanos(end);
}
Also used : Query(org.bimserver.database.queries.om.Query) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) HashMap(java.util.HashMap) QueryPart(org.bimserver.database.queries.om.QueryPart) RenderEngineGeometry(org.bimserver.plugins.renderengine.RenderEngineGeometry) RenderEngineModel(org.bimserver.plugins.renderengine.RenderEngineModel) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) WrappedVirtualObject(org.bimserver.shared.WrappedVirtualObject) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) HashSet(java.util.HashSet) OidConvertingSerializer(org.bimserver.plugins.serializers.OidConvertingSerializer) StreamingSerializer(org.bimserver.plugins.serializers.StreamingSerializer) EntityNotFoundException(org.bimserver.plugins.renderengine.EntityNotFoundException) Range(org.bimserver.Range) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectListener(org.bimserver.ObjectListener) Q(org.bimserver.Q) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) RenderEngine(org.bimserver.plugins.renderengine.RenderEngine) HashMapWrappedVirtualObject(org.bimserver.shared.HashMapWrappedVirtualObject) WrappedVirtualObject(org.bimserver.shared.WrappedVirtualObject) Color4f(org.bimserver.Color4f) ObjectProviderProxy(org.bimserver.ObjectProviderProxy) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileNotFoundException(java.io.FileNotFoundException) EntityNotFoundException(org.bimserver.plugins.renderengine.EntityNotFoundException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) RenderEngineException(org.bimserver.plugins.renderengine.RenderEngineException) RenderEngineInstance(org.bimserver.plugins.renderengine.RenderEngineInstance) ProductDef(org.bimserver.ProductDef)

Aggregations

QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)17 Query (org.bimserver.database.queries.om.Query)16 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)16 QueryPart (org.bimserver.database.queries.om.QueryPart)15 UserException (org.bimserver.shared.exceptions.UserException)13 PackageMetaData (org.bimserver.emf.PackageMetaData)12 EClass (org.eclipse.emf.ecore.EClass)11 List (java.util.List)9 EReference (org.eclipse.emf.ecore.EReference)7 EAttribute (org.eclipse.emf.ecore.EAttribute)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 OldQuery (org.bimserver.database.OldQuery)4 HashSet (java.util.HashSet)3 Include (org.bimserver.database.queries.om.Include)3 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)3 HashMapWrappedVirtualObject (org.bimserver.shared.HashMapWrappedVirtualObject)3 EEnum (org.eclipse.emf.ecore.EEnum)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)2