Search in sources :

Example 16 with QueryPart

use of org.bimserver.database.queries.om.QueryPart 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 17 with QueryPart

use of org.bimserver.database.queries.om.QueryPart 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 18 with QueryPart

use of org.bimserver.database.queries.om.QueryPart 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 19 with QueryPart

use of org.bimserver.database.queries.om.QueryPart 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)

Example 20 with QueryPart

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

the class StreamingGeometryGenerator method generateGeometry.

@SuppressWarnings("unchecked")
public GenerateGeometryResult generateGeometry(long uoid, final DatabaseSession databaseSession, QueryContext queryContext) throws BimserverDatabaseException, GeometryGeneratingException {
    GenerateGeometryResult generateGeometryResult = new GenerateGeometryResult();
    packageMetaData = queryContext.getPackageMetaData();
    productClass = packageMetaData.getEClass("IfcProduct");
    geometryFeature = productClass.getEStructuralFeature("geometry");
    representationFeature = productClass.getEStructuralFeature("Representation");
    representationsFeature = packageMetaData.getEClass("IfcProductDefinitionShape").getEStructuralFeature("Representations");
    itemsFeature = packageMetaData.getEClass("IfcShapeRepresentation").getEStructuralFeature("Items");
    mappingSourceFeature = packageMetaData.getEClass("IfcMappedItem").getEStructuralFeature("MappingSource");
    GregorianCalendar now = new GregorianCalendar();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
    debugIdentifier = dateFormat.format(now.getTime());
    long start = System.nanoTime();
    String pluginName = "";
    if (queryContext.getPackageMetaData().getSchema() == Schema.IFC4) {
        pluginName = "org.bimserver.ifc.step.serializer.Ifc4StepStreamingSerializerPlugin";
    } else if (queryContext.getPackageMetaData().getSchema() == Schema.IFC2X3TC1) {
        pluginName = "org.bimserver.ifc.step.serializer.Ifc2x3tc1StepStreamingSerializerPlugin";
    } else {
        throw new GeometryGeneratingException("Unknown schema " + queryContext.getPackageMetaData().getSchema());
    }
    reuseGeometry = bimServer.getServerSettingsCache().getServerSettings().isReuseGeometry();
    optimizeMappedItems = bimServer.getServerSettingsCache().getServerSettings().isOptimizeMappedItems();
    report.setStart(new GregorianCalendar());
    report.setIfcSchema(queryContext.getPackageMetaData().getSchema());
    report.setMaxPerFile(maxObjectsPerFile);
    report.setUseMappingOptimization(optimizeMappedItems);
    report.setReuseGeometry(reuseGeometry);
    try {
        final StreamingSerializerPlugin ifcSerializerPlugin = (StreamingSerializerPlugin) bimServer.getPluginManager().getPlugin(pluginName, true);
        if (ifcSerializerPlugin == null) {
            throw new UserException("No IFC serializer found");
        }
        User user = (User) databaseSession.get(uoid, org.bimserver.database.OldQuery.getDefault());
        UserSettings userSettings = user.getUserSettings();
        report.setUserName(user.getName());
        report.setUserUserName(user.getUsername());
        RenderEnginePluginConfiguration renderEngine = null;
        if (eoid != -1) {
            renderEngine = databaseSession.get(eoid, OldQuery.getDefault());
        } else {
            renderEngine = userSettings.getDefaultRenderEngine();
        }
        if (renderEngine == null) {
            throw new UserException("No default render engine has been selected for this user");
        }
        renderEngineName = renderEngine.getName();
        int availableProcessors = Runtime.getRuntime().availableProcessors();
        report.setAvailableProcessors(availableProcessors);
        int maxSimultanousThreads = Math.min(bimServer.getServerSettingsCache().getServerSettings().getRenderEngineProcesses(), availableProcessors);
        if (maxSimultanousThreads < 1) {
            maxSimultanousThreads = 1;
        }
        final RenderEngineSettings settings = new RenderEngineSettings();
        settings.setPrecision(Precision.SINGLE);
        settings.setIndexFormat(IndexFormat.AUTO_DETECT);
        settings.setGenerateNormals(true);
        settings.setGenerateTriangles(true);
        settings.setGenerateWireFrame(false);
        final RenderEngineFilter renderEngineFilter = new RenderEngineFilter();
        RenderEnginePool renderEnginePool = bimServer.getRenderEnginePools().getRenderEnginePool(packageMetaData.getSchema(), renderEngine.getPluginDescriptor().getPluginClassName(), new PluginConfiguration(renderEngine.getSettings()));
        report.setRenderEngineName(renderEngine.getName());
        report.setRenderEnginePluginVersion(renderEngine.getPluginDescriptor().getPluginBundleVersion().getVersion());
        try (RenderEngine engine = renderEnginePool.borrowObject()) {
            report.setRenderEngineVersion(engine.getVersion());
        }
        ThreadPoolExecutor executor = new ThreadPoolExecutor(maxSimultanousThreads, maxSimultanousThreads, 24, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(10000000));
        JsonQueryObjectModelConverter jsonQueryObjectModelConverter = new JsonQueryObjectModelConverter(packageMetaData);
        String queryNameSpace = "validifc";
        if (packageMetaData.getSchema() == Schema.IFC4) {
            queryNameSpace = "ifc4stdlib";
        }
        Include objectPlacement = jsonQueryObjectModelConverter.getDefineFromFile(queryNameSpace + ":ObjectPlacement");
        // TODO these are cached, so f'ing em up by doing this...
        objectPlacement.makeDirectRecursive(new HashSet<>());
        Set<EClass> classes = null;
        if (queryContext.getOidCounters() != null) {
            classes = queryContext.getOidCounters().keySet();
        } else {
            classes = packageMetaData.getEClasses();
        }
        for (EClass eClass : classes) {
            if (packageMetaData.getEClass("IfcProduct").isSuperTypeOf(eClass)) {
                Query query2 = new Query(eClass.getName() + "Main query", packageMetaData);
                QueryPart queryPart2 = query2.createQueryPart();
                queryPart2.addType(eClass, false);
                Include representationInclude = queryPart2.createInclude();
                representationInclude.addType(eClass, false);
                representationInclude.addFieldDirect("Representation");
                Include representationsInclude = representationInclude.createInclude();
                representationsInclude.addType(packageMetaData.getEClass("IfcProductRepresentation"), true);
                representationsInclude.addFieldDirect("Representations");
                Include itemsInclude = representationsInclude.createInclude();
                itemsInclude.addType(packageMetaData.getEClass("IfcShapeRepresentation"), false);
                itemsInclude.addFieldDirect("Items");
                Include mappingSourceInclude = itemsInclude.createInclude();
                mappingSourceInclude.addType(packageMetaData.getEClass("IfcMappedItem"), false);
                mappingSourceInclude.addFieldDirect("MappingSource");
                mappingSourceInclude.addFieldDirect("MappingTarget");
                Include representationMap = mappingSourceInclude.createInclude();
                representationMap.addType(packageMetaData.getEClass("IfcRepresentationMap"), false);
                Include targetInclude = mappingSourceInclude.createInclude();
                targetInclude.addType(packageMetaData.getEClass("IfcCartesianTransformationOperator3D"), false);
                targetInclude.addFieldDirect("Axis1");
                targetInclude.addFieldDirect("Axis2");
                targetInclude.addFieldDirect("Axis3");
                targetInclude.addFieldDirect("LocalOrigin");
                queryPart2.addInclude(objectPlacement);
                Map<Long, Map<Long, ProductDef>> representationMapToProduct = new HashMap<>();
                QueryObjectProvider queryObjectProvider2 = new QueryObjectProvider(databaseSession, bimServer, query2, Collections.singleton(queryContext.getRoid()), packageMetaData);
                HashMapVirtualObject next = queryObjectProvider2.next();
                while (next != null) {
                    if (next.eClass() == eClass) {
                        HashMapVirtualObject representation = next.getDirectFeature(representationFeature);
                        if (representation != null) {
                            List<HashMapVirtualObject> representations = representation.getDirectListFeature(representationsFeature);
                            if (representations != null) {
                                for (HashMapVirtualObject representationItem : representations) {
                                    String representationIdentifier = (String) representationItem.get("RepresentationIdentifier");
                                    if (representationIdentifier.equals("Body") || representationIdentifier.equals("Facetation")) {
                                        List<HashMapVirtualObject> items = representationItem.getDirectListFeature(itemsFeature);
                                        for (HashMapVirtualObject item : items) {
                                            report.addRepresentationItem(item.eClass().getName());
                                            HashMapVirtualObject mappingTarget = item.getDirectFeature(packageMetaData.getEReference("IfcMappedItem", "MappingTarget"));
                                            double[] mappingMatrix = Matrix.identity();
                                            double[] productMatrix = Matrix.identity();
                                            if (mappingTarget != null) {
                                                HashMapVirtualObject axis1 = mappingTarget.getDirectFeature(packageMetaData.getEReference("IfcCartesianTransformationOperator", "Axis1"));
                                                HashMapVirtualObject axis2 = mappingTarget.getDirectFeature(packageMetaData.getEReference("IfcCartesianTransformationOperator", "Axis2"));
                                                HashMapVirtualObject axis3 = mappingTarget.getDirectFeature(packageMetaData.getEReference("IfcCartesianTransformationOperator", "Axis3"));
                                                HashMapVirtualObject localOrigin = mappingTarget.getDirectFeature(packageMetaData.getEReference("IfcCartesianTransformationOperator", "LocalOrigin"));
                                                double[] a1 = null;
                                                double[] a2 = null;
                                                double[] a3 = null;
                                                if (axis3 != null) {
                                                    List<Double> list = (List<Double>) axis3.get("DirectionRatios");
                                                    a3 = new double[] { list.get(0), list.get(1), list.get(2) };
                                                } else {
                                                    a3 = new double[] { 0, 0, 1, 1 };
                                                    Vector.normalize(a3);
                                                }
                                                if (axis1 != null) {
                                                    List<Double> list = (List<Double>) axis1.get("DirectionRatios");
                                                    a1 = new double[] { list.get(0), list.get(1), list.get(2) };
                                                    Vector.normalize(a1);
                                                } else {
                                                    // if (a3[0] == 1 && a3[1] == 0 && a3[2] == 0) {
                                                    a1 = new double[] { 1, 0, 0, 1 };
                                                // } else {
                                                // a1 = new double[]{0, 1, 0, 1};
                                                // }
                                                }
                                                double[] xVec = Vector.scalarProduct(Vector.dot(a1, a3), a3);
                                                double[] xAxis = Vector.subtract(a1, xVec);
                                                Vector.normalize(xAxis);
                                                if (axis2 != null) {
                                                    List<Double> list = (List<Double>) axis2.get("DirectionRatios");
                                                    a2 = new double[] { list.get(0), list.get(1), list.get(2) };
                                                    Vector.normalize(a2);
                                                } else {
                                                    a2 = new double[] { 0, 1, 0, 1 };
                                                }
                                                double[] tmp = Vector.scalarProduct(Vector.dot(a2, a3), a3);
                                                double[] yAxis = Vector.subtract(a2, tmp);
                                                tmp = Vector.scalarProduct(Vector.dot(a2, xAxis), xAxis);
                                                yAxis = Vector.subtract(yAxis, tmp);
                                                Vector.normalize(yAxis);
                                                a2 = yAxis;
                                                a1 = xAxis;
                                                List<Double> t = (List<Double>) localOrigin.get("Coordinates");
                                                mappingMatrix = new double[] { a1[0], a1[1], a1[2], 0, a2[0], a2[1], a2[2], 0, a3[0], a3[1], a3[2], 0, t.get(0).doubleValue(), t.get(1).doubleValue(), t.get(2).doubleValue(), 1 };
                                            }
                                            HashMapVirtualObject placement = next.getDirectFeature(packageMetaData.getEReference("IfcProduct", "ObjectPlacement"));
                                            if (placement != null) {
                                                productMatrix = placementToMatrix(placement);
                                            }
                                            HashMapVirtualObject mappingSource = item.getDirectFeature(mappingSourceFeature);
                                            if (mappingSource != null) {
                                                Map<Long, ProductDef> map = representationMapToProduct.get(mappingSource.getOid());
                                                if (map == null) {
                                                    map = new LinkedHashMap<>();
                                                    representationMapToProduct.put(mappingSource.getOid(), map);
                                                }
                                                ProductDef pd = new ProductDef(next.getOid());
                                                pd.setObject(next);
                                                pd.setProductMatrix(productMatrix);
                                                pd.setMappingMatrix(mappingMatrix);
                                                map.put(next.getOid(), pd);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    next = queryObjectProvider2.next();
                }
                Set<Long> done = new HashSet<>();
                for (Long repMapId : representationMapToProduct.keySet()) {
                    Map<Long, ProductDef> map = representationMapToProduct.get(repMapId);
                    if (map.size() > 1) {
                        Query query = new Query("Reuse query " + eClass.getName(), packageMetaData);
                        QueryPart queryPart = query.createQueryPart();
                        queryPart.addType(eClass, false);
                        long masterOid = map.values().iterator().next().getOid();
                        for (ProductDef pd : map.values()) {
                            done.add(pd.getOid());
                            if (!optimizeMappedItems) {
                                queryPart.addOid(pd.getOid());
                            } else {
                                pd.setMasterOid(masterOid);
                            }
                        }
                        if (optimizeMappedItems) {
                            queryPart.addOid(masterOid);
                        }
                        LOGGER.debug("Running " + map.size() + " objects in one batch because of reused geometry " + (eClass.getName()));
                        processX(databaseSession, queryContext, generateGeometryResult, ifcSerializerPlugin, settings, renderEngineFilter, renderEnginePool, executor, eClass, query, queryPart, true, map, map.size());
                    }
                }
                Query query3 = new Query("Remaining " + eClass.getName(), packageMetaData);
                QueryPart queryPart3 = query3.createQueryPart();
                queryPart3.addType(eClass, false);
                Include include3 = queryPart3.createInclude();
                include3.addType(eClass, false);
                include3.addFieldDirect("Representation");
                Include rInclude = include3.createInclude();
                rInclude.addType(packageMetaData.getEClass("IfcProductRepresentation"), false);
                rInclude.addFieldDirect("Representations");
                Include representationsInclude2 = rInclude.createInclude();
                representationsInclude2.addType(packageMetaData.getEClass("IfcShapeModel"), false);
                queryObjectProvider2 = new QueryObjectProvider(databaseSession, bimServer, query3, Collections.singleton(queryContext.getRoid()), packageMetaData);
                next = queryObjectProvider2.next();
                while (next != null) {
                    if (next.eClass() == eClass && !done.contains(next.getOid())) {
                        HashMapVirtualObject representation = next.getDirectFeature(representationFeature);
                        if (representation != null) {
                            List<HashMapVirtualObject> list = representation.getDirectListFeature(packageMetaData.getEReference("IfcProductRepresentation", "Representations"));
                            boolean goForIt = goForIt(list);
                            if (goForIt) {
                                Query query = new Query("Main " + eClass.getName(), packageMetaData);
                                QueryPart queryPart = query.createQueryPart();
                                queryPart.addType(eClass, false);
                                int x = 1;
                                queryPart.addOid(next.getOid());
                                while (next != null && x < maxObjectsPerFile) {
                                    next = queryObjectProvider2.next();
                                    if (next != null) {
                                        if (next.eClass() == eClass && !done.contains(next.getOid())) {
                                            representation = next.getDirectFeature(representationFeature);
                                            if (representation != null) {
                                                list = representation.getDirectListFeature(packageMetaData.getEReference("IfcProductRepresentation", "Representations"));
                                                boolean goForIt2 = goForIt(list);
                                                if (goForIt2) {
                                                    queryPart.addOid(next.getOid());
                                                    x++;
                                                }
                                            }
                                        }
                                    }
                                }
                                processX(databaseSession, queryContext, generateGeometryResult, ifcSerializerPlugin, settings, renderEngineFilter, renderEnginePool, executor, eClass, query, queryPart, false, null, x);
                            }
                        }
                    }
                    next = queryObjectProvider2.next();
                }
            }
        }
        // for (Long l : counters.keySet()) {
        // LOGGER.info(databaseSession.getEClassForOid(l).getName() + "(" + l + "): " + counters.get(l));
        // }
        allJobsPushed = true;
        executor.shutdown();
        executor.awaitTermination(24, TimeUnit.HOURS);
        long end = System.nanoTime();
        long total = totalBytes.get() - (bytesSavedByHash.get() + bytesSavedByTransformation.get() + bytesSavedByMapping.get());
        LOGGER.info("Rendertime: " + Formatters.nanosToString(end - start) + ", " + "Reused (by hash): " + Formatters.bytesToString(bytesSavedByHash.get()) + ", Reused (by transformation): " + Formatters.bytesToString(bytesSavedByTransformation.get()) + ", Reused (by mapping): " + Formatters.bytesToString(bytesSavedByMapping.get()) + ", Total: " + Formatters.bytesToString(totalBytes.get()) + ", Final: " + Formatters.bytesToString(total));
    } catch (Exception e) {
        running = false;
        LOGGER.error("", e);
        report.setEnd(new GregorianCalendar());
        throw new GeometryGeneratingException(e);
    }
    report.setEnd(new GregorianCalendar());
    try {
        writeDebugFile();
    } catch (IOException e) {
        LOGGER.debug("", e);
    }
    return generateGeometryResult;
}
Also used : User(org.bimserver.models.store.User) RenderEnginePool(org.bimserver.renderengine.RenderEnginePool) JsonQueryObjectModelConverter(org.bimserver.database.queries.om.JsonQueryObjectModelConverter) OldQuery(org.bimserver.database.OldQuery) Query(org.bimserver.database.queries.om.Query) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) QueryPart(org.bimserver.database.queries.om.QueryPart) Include(org.bimserver.database.queries.om.Include) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) EClass(org.eclipse.emf.ecore.EClass) QueryObjectProvider(org.bimserver.database.queries.QueryObjectProvider) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) PluginConfiguration(org.bimserver.plugins.PluginConfiguration) List(java.util.List) UserException(org.bimserver.shared.exceptions.UserException) RenderEngine(org.bimserver.plugins.renderengine.RenderEngine) HashSet(java.util.HashSet) UserSettings(org.bimserver.models.store.UserSettings) GregorianCalendar(java.util.GregorianCalendar) IOException(java.io.IOException) StreamingSerializerPlugin(org.bimserver.plugins.serializers.StreamingSerializerPlugin) QueryException(org.bimserver.database.queries.om.QueryException) GeometryGeneratingException(org.bimserver.GeometryGeneratingException) UserException(org.bimserver.shared.exceptions.UserException) IOException(java.io.IOException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) RenderEnginePluginConfiguration(org.bimserver.models.store.RenderEnginePluginConfiguration) RenderEngineFilter(org.bimserver.plugins.renderengine.RenderEngineFilter) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) GenerateGeometryResult(org.bimserver.GenerateGeometryResult) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) AtomicLong(java.util.concurrent.atomic.AtomicLong) ProductDef(org.bimserver.ProductDef) RenderEngineSettings(org.bimserver.plugins.renderengine.RenderEngineSettings) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) SimpleDateFormat(java.text.SimpleDateFormat) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

QueryPart (org.bimserver.database.queries.om.QueryPart)23 Query (org.bimserver.database.queries.om.Query)22 UserException (org.bimserver.shared.exceptions.UserException)16 QueryObjectProvider (org.bimserver.database.queries.QueryObjectProvider)15 HashMapVirtualObject (org.bimserver.shared.HashMapVirtualObject)15 EClass (org.eclipse.emf.ecore.EClass)13 PackageMetaData (org.bimserver.emf.PackageMetaData)11 IOException (java.io.IOException)9 List (java.util.List)8 QueryException (org.bimserver.database.queries.om.QueryException)7 JsonQueryObjectModelConverter (org.bimserver.database.queries.om.JsonQueryObjectModelConverter)6 EReference (org.eclipse.emf.ecore.EReference)6 Include (org.bimserver.database.queries.om.Include)5 IfcModelInterfaceException (org.bimserver.emf.IfcModelInterfaceException)5 PublicInterfaceNotFoundException (org.bimserver.shared.exceptions.PublicInterfaceNotFoundException)5 ServiceException (org.bimserver.shared.exceptions.ServiceException)5 EOFException (java.io.EOFException)4 HashMap (java.util.HashMap)4 EAttribute (org.eclipse.emf.ecore.EAttribute)4 HashSet (java.util.HashSet)3