Search in sources :

Example 46 with IdEObject

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

the class DownloadCompareDatabaseAction method setColor.

@SuppressWarnings("unchecked")
private void setColor(IfcModelInterface model, IdEObject product, IdEObject color) throws IfcModelInterfaceException {
    EStructuralFeature representationFeature = product.eClass().getEStructuralFeature("Representation");
    IdEObject representation = (IdEObject) product.eGet(representationFeature);
    if (representation != null) {
        EStructuralFeature representationsFeature = representation.eClass().getEStructuralFeature("Representations");
        List<IdEObject> representations = (EList<IdEObject>) representation.eGet(representationsFeature);
        for (IdEObject ifcRepresentation : representations) {
            EStructuralFeature itemsFeature = ifcRepresentation.eClass().getEStructuralFeature("Items");
            List<IdEObject> representationItems = (EList<IdEObject>) ifcRepresentation.eGet(itemsFeature);
            EStructuralFeature representationIdentifierFeature = ifcRepresentation.eClass().getEStructuralFeature("RepresentationIdentifier");
            String identifier = (String) ifcRepresentation.eGet(representationIdentifierFeature);
            for (IdEObject ifcRepresentationItem : representationItems) {
                EStructuralFeature styledByItemFeature = ifcRepresentationItem.eClass().getEStructuralFeature("StyledByItem");
                List<IdEObject> styledByItems = (EList<IdEObject>) ifcRepresentationItem.eGet(styledByItemFeature);
                if (styledByItems.isEmpty()) {
                    createStyledByItems(model, ifcRepresentationItem, identifier, color);
                } else {
                    for (IdEObject ifcStyledItem : styledByItems) {
                        EStructuralFeature stylesFeature = ifcStyledItem.eClass().getEStructuralFeature("Styles");
                        List<IdEObject> styledItemStyles = (List<IdEObject>) ifcStyledItem.eGet(stylesFeature);
                        if (styledItemStyles.isEmpty()) {
                            createStyledItemStyles(model, identifier, ifcStyledItem, color);
                        } else {
                            for (IdEObject ifcPresentationStyleAssignment : styledItemStyles) {
                                EStructuralFeature stylesFeature2 = ifcPresentationStyleAssignment.eClass().getEStructuralFeature("Styles");
                                List<IdEObject> presentationStyleAssignmentStyles = (List<IdEObject>) ifcPresentationStyleAssignment.eGet(stylesFeature2);
                                if (presentationStyleAssignmentStyles.isEmpty()) {
                                    createPresentationStyleAssignmentStyles(model, identifier, ifcPresentationStyleAssignment, color);
                                } else {
                                    for (IdEObject ifcPresentationStyleSelect : presentationStyleAssignmentStyles) {
                                        if (ifcPresentationStyleSelect.eClass().getName().equals("IfcSurfaceStyle")) {
                                            EStructuralFeature stylesFeature3 = ifcPresentationStyleSelect.eClass().getEStructuralFeature("Styles");
                                            List<IdEObject> surfaceStyleStyles = (List<IdEObject>) ifcPresentationStyleSelect.eGet(stylesFeature3);
                                            if (surfaceStyleStyles.isEmpty()) {
                                                createSurfaceStyleStyles(model, identifier, ifcPresentationStyleSelect, color);
                                            } else {
                                                boolean renderingFound = false;
                                                for (IdEObject ifcSurfaceStyleElementSelect : surfaceStyleStyles) {
                                                    if (ifcSurfaceStyleElementSelect.eClass().getName().equals("IfcSurfaceStyleRendering")) {
                                                        renderingFound = true;
                                                        IdEObject ifcSurfaceStyleRendering = (IdEObject) ifcSurfaceStyleElementSelect;
                                                        setColour(color, ifcSurfaceStyleRendering);
                                                    }
                                                }
                                                if (!renderingFound) {
                                                    createSurfaceStyleStyles(model, identifier, ifcPresentationStyleSelect, color);
                                                }
                                            }
                                        } else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcTextStyle")) {
                                            EStructuralFeature textCharacterAppearanceFeature = ifcPresentationStyleSelect.eClass().getEStructuralFeature("TextCharacterAppearance");
                                            IdEObject textCharacterAppearance = (IdEObject) ifcPresentationStyleSelect.eGet(textCharacterAppearanceFeature);
                                            if (textCharacterAppearance.eClass().getName().equals("IfcTextStyleForDefinedFont")) {
                                                // IfcTextStyleForDefinedFont is the only subclass of IfcCharacterStyleSelect
                                                textCharacterAppearance.eSet(textCharacterAppearance.eClass().getEStructuralFeature("Colour"), color);
                                            }
                                        } else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcCurveStyle")) {
                                            ifcPresentationStyleSelect.eSet(ifcPresentationStyleSelect.eClass().getEStructuralFeature("CurveColour"), color);
                                        } else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcFillAreaStyle")) {
                                            EStructuralFeature fillStylesFeature = ifcPresentationStyleSelect.eClass().getEStructuralFeature("FillStyles");
                                            List<IdEObject> list = (List<IdEObject>) ifcPresentationStyleSelect.eGet(fillStylesFeature);
                                            list.clear();
                                            list.add(color);
                                        } else if (ifcPresentationStyleSelect.eClass().getName().equals("IfcSymbolStyle")) {
                                            ifcPresentationStyleSelect.eSet(ifcPresentationStyleSelect.eClass().getEStructuralFeature("StyleOfSymbol"), color);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : EList(org.eclipse.emf.common.util.EList) IdEObject(org.bimserver.emf.IdEObject) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) EList(org.eclipse.emf.common.util.EList) List(java.util.List)

Example 47 with IdEObject

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

the class GetAllReadableProjectsDatabaseAction method execute.

@Override
public Set<Project> execute() throws UserException, BimserverLockConflictException, BimserverDatabaseException {
    User user = getUserByUoid(authorization.getUoid());
    IfcModelInterface projectsModel = getDatabaseSession().getAllOfType(StorePackage.eINSTANCE.getProject(), OldQuery.getDefault());
    Set<Project> result = new HashSet<Project>();
    for (IdEObject idEObject : projectsModel.getValues()) {
        if (idEObject instanceof Project) {
            Project project = (Project) idEObject;
            if ((user.getUserType() == UserType.ADMIN || (project.getState() == ObjectState.ACTIVE) && authorization.hasRightsOnProjectOrSuperProjectsOrSubProjects(user, project))) {
                result.add(project);
            }
        }
    }
    return result;
}
Also used : Project(org.bimserver.models.store.Project) User(org.bimserver.models.store.User) IdEObject(org.bimserver.emf.IdEObject) IfcModelInterface(org.bimserver.emf.IfcModelInterface) HashSet(java.util.HashSet)

Example 48 with IdEObject

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

the class DatabaseSession method getAvailableClassesInRevision.

public Set<String> getAvailableClassesInRevision(IfcModelInterface ifcModel, QueryInterface query) throws BimserverDatabaseException {
    checkOpen();
    try {
        getMap(ifcModel, query);
        Set<String> classes = new HashSet<String>();
        for (IdEObject idEObject : ifcModel.getValues()) {
            classes.add(idEObject.eClass().getName());
        }
        return classes;
    } catch (BimserverDatabaseException e) {
        LOGGER.error("", e);
    }
    return null;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) IdEObject(org.bimserver.emf.IdEObject) HashSet(java.util.HashSet)

Example 49 with IdEObject

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

the class DatabaseSession method convertObjectToByteArray.

private ByteBuffer convertObjectToByteArray(IdEObject object, ByteBuffer buffer, PackageMetaData packageMetaData) throws BimserverDatabaseException {
    int bufferSize = getExactSize(object, packageMetaData, true);
    if (bufferSize > buffer.capacity()) {
        LOGGER.debug("Buffer too small (" + bufferSize + ")");
        buffer = ByteBuffer.allocate(bufferSize);
    }
    int unsettedLength = packageMetaData.getUnsettedLength(object.eClass());
    byte[] unsetted = new byte[unsettedLength];
    int fieldCounter = 0;
    for (EStructuralFeature feature : object.eClass().getEAllStructuralFeatures()) {
        if (packageMetaData.useForDatabaseStorage(object.eClass(), feature)) {
            if (useUnsetBit(feature, object)) {
                unsetted[fieldCounter / 8] |= (1 << (fieldCounter % 8));
            }
            fieldCounter++;
        }
    }
    buffer.put(unsetted);
    EClass eClass = getEClassForOid(object.getOid());
    if (!eClass.isSuperTypeOf(object.eClass())) {
        throw new BimserverDatabaseException("Object with oid " + object.getOid() + " is a " + object.eClass().getName() + " but it's cid-part says it's a " + eClass.getName());
    }
    for (EStructuralFeature feature : object.eClass().getEAllStructuralFeatures()) {
        if (packageMetaData.useForDatabaseStorage(object.eClass(), feature)) {
            if (!useUnsetBit(feature, object)) {
                if (feature.isMany()) {
                    writeList(object, buffer, packageMetaData, feature);
                } else {
                    Object value = object.eGet(feature);
                    if (feature.getEType() instanceof EEnum) {
                        if (value == null) {
                            buffer.putInt(-1);
                        } else {
                            EEnum eEnum = (EEnum) feature.getEType();
                            EEnumLiteral eEnumLiteral = eEnum.getEEnumLiteralByLiteral(((Enum<?>) value).toString());
                            if (eEnumLiteral != null) {
                                buffer.putInt(eEnumLiteral.getValue());
                            } else {
                                LOGGER.error(((Enum<?>) value).toString() + " not found");
                                buffer.putInt(-1);
                            }
                        }
                    } else if (feature.getEType() instanceof EClass) {
                        if (value == null) {
                            buffer.order(ByteOrder.LITTLE_ENDIAN);
                            buffer.putShort((short) -1);
                            buffer.order(ByteOrder.BIG_ENDIAN);
                        } else {
                            IdEObject referencedObject = (IdEObject) value;
                            EClass referencedClass = referencedObject.eClass();
                            if (feature.getEAnnotation("dbembed") != null) {
                                writeEmbeddedValue(object.getPid(), object.getRid(), value, buffer, packageMetaData);
                            } else if (referencedClass.getEAnnotation("wrapped") != null) {
                                writeWrappedValue(object.getPid(), object.getRid(), value, buffer, packageMetaData);
                            } else {
                                writeReference(object, value, buffer, feature);
                            }
                        }
                    } else if (feature.getEType() instanceof EDataType) {
                        writePrimitiveValue(feature, value, buffer);
                    }
                }
            }
        }
    }
    if (buffer.position() != bufferSize) {
        throw new BimserverDatabaseException("Value buffer sizes do not match for " + object.eClass().getName() + " " + buffer.position() + "/" + bufferSize);
    }
    return buffer;
}
Also used : EEnum(org.eclipse.emf.ecore.EEnum) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) EClass(org.eclipse.emf.ecore.EClass) IdEObject(org.bimserver.emf.IdEObject) EDataType(org.eclipse.emf.ecore.EDataType) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) VirtualObject(org.bimserver.shared.VirtualObject) HashMapVirtualObject(org.bimserver.shared.HashMapVirtualObject) EObject(org.eclipse.emf.ecore.EObject) IdEObject(org.bimserver.emf.IdEObject) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) EEnum(org.eclipse.emf.ecore.EEnum)

Example 50 with IdEObject

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

the class DatabaseSession method readReference.

private IdEObject readReference(EClass originalQueryClass, ByteBuffer buffer, IfcModelInterface model, IdEObject object, EStructuralFeature feature, EClass eClass, QueryInterface query, TodoList todoList) throws BimserverDatabaseException {
    // TODO next bit seems to make no sense, why detect a deleted record when reading a reference??
    if (buffer.capacity() == 1 && buffer.get(0) == -1) {
        buffer.position(buffer.position() + 1);
        return null;
    }
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    long oid = buffer.getLong();
    buffer.order(ByteOrder.BIG_ENDIAN);
    IdEObject foundInCache = objectCache.get(oid);
    if (foundInCache != null) {
        return foundInCache;
    }
    if (model.contains(oid)) {
        return model.get(oid);
    }
    IdEObjectImpl newObject = createInternal(eClass, query);
    newObject.setOid(oid);
    if (perRecordVersioning(newObject)) {
        newObject.setPid(Database.STORE_PROJECT_ID);
    } else {
        newObject.setPid(query.getPid());
    }
    newObject.setRid(query.getRid());
    try {
        newObject.setModel(model);
    } catch (IfcModelInterfaceException e) {
        LOGGER.error("", e);
    }
    objectCache.put(oid, newObject);
    if (query.isDeep() && object.eClass().getEAnnotation("wrapped") == null) {
        if (feature.getEAnnotation("nolazyload") == null) {
            todoList.add(newObject);
        }
    } else {
        if (object.eClass().getEAnnotation("wrapped") == null) {
            try {
                model.addAllowMultiModel(oid, newObject);
            } catch (IfcModelInterfaceException e) {
                throw new BimserverDatabaseException(e);
            }
        }
    }
    return newObject;
}
Also used : IdEObjectImpl(org.bimserver.emf.IdEObjectImpl) IfcModelInterfaceException(org.bimserver.emf.IfcModelInterfaceException) BimserverDatabaseException(org.bimserver.BimserverDatabaseException) IdEObject(org.bimserver.emf.IdEObject)

Aggregations

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