Search in sources :

Example 6 with EntityDefinition

use of nl.tue.buildingsmart.schema.EntityDefinition in project BIMserver by opensourceBIM.

the class Express2EMF method addAttributes.

private void addAttributes() {
    Iterator<EntityDefinition> entIter = schema.getEntities().iterator();
    while (entIter.hasNext()) {
        EntityDefinition ent = (EntityDefinition) entIter.next();
        Iterator<Attribute> attribIter = ent.getAttributes(false).iterator();
        while (attribIter.hasNext()) {
            Attribute attrib = (Attribute) attribIter.next();
            if (attrib instanceof ExplicitAttribute) {
                processAttribute(ent, attrib);
            }
        }
    }
}
Also used : EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EAttribute(org.eclipse.emf.ecore.EAttribute) Attribute(nl.tue.buildingsmart.schema.Attribute) ExplicitAttribute(nl.tue.buildingsmart.schema.ExplicitAttribute) ExplicitAttribute(nl.tue.buildingsmart.schema.ExplicitAttribute)

Example 7 with EntityDefinition

use of nl.tue.buildingsmart.schema.EntityDefinition in project BIMserver by opensourceBIM.

the class Express2EMF method doRealDerivedAttributes.

private void doRealDerivedAttributes() {
    for (EntityDefinition entityDefinition : schema.getEntities()) {
        for (DerivedAttribute2 attributeName : entityDefinition.getDerivedAttributes().values()) {
            EClass eClass = (EClass) schemaPack.getEClassifier(entityDefinition.getName());
            // eFactory.createEReference();
            if (attributeName.getType() != null && !attributeName.hasSuper()) {
                // derivedAttribute.setEType(schemaPack.getEClassifier("IfcLogical"));
                if (attributeName.getType() instanceof DefinedType) {
                    EClassifier eType = schemaPack.getEClassifier(((DefinedType) attributeName.getType()).getName());
                    boolean found = false;
                    for (EClass eSuperType : eClass.getEAllSuperTypes()) {
                        if (eSuperType.getEStructuralFeature(attributeName.getName()) != null) {
                            found = true;
                            break;
                        }
                    }
                    if (eType.getEAnnotation("wrapped") != null) {
                        if (!found) {
                            EAttribute eAttribute = eFactory.createEAttribute();
                            eAttribute.setDerived(true);
                            eAttribute.setName(attributeName.getName());
                            if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) {
                                eAttribute.setUpperBound(3);
                                eAttribute.setUnique(false);
                            }
                            EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType();
                            eAttribute.setEType(type);
                            // TODO find out
                            eAttribute.setUnsettable(true);
                            // if its
                            // optional
                            eClass.getEStructuralFeatures().add(eAttribute);
                            if (type == EcorePackage.eINSTANCE.getEDouble()) {
                                EAttribute doubleStringAttribute = eFactory.createEAttribute();
                                doubleStringAttribute.setName(attributeName.getName() + "AsString");
                                doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
                                doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
                                // TODO
                                doubleStringAttribute.setUnsettable(true);
                                // find
                                // out
                                // if
                                // its
                                // optional
                                doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
                                eClass.getEStructuralFeatures().add(doubleStringAttribute);
                            }
                        }
                    } else {
                        if (!found) {
                            EReference eReference = eFactory.createEReference();
                            eReference.setName(attributeName.getName());
                            eReference.setDerived(true);
                            eReference.setUnsettable(true);
                            eReference.setEType(eType);
                            eClass.getEStructuralFeatures().add(eReference);
                        }
                    }
                // derivedAttribute.setEType(eType);
                }
            }
        // derivedAttribute.setName(attributeName.getName());
        // derivedAttribute.setDerived(true);
        // derivedAttribute.setTransient(true);
        // derivedAttribute.setVolatile(true);
        // if (attributeName.isCollection()) {
        // derivedAttribute.setUpperBound(-1);
        // }
        // EAnnotation annotation = eFactory.createEAnnotation();
        // annotation.setSource("http://www.iso.org/iso10303-11/EXPRESS");
        // annotation.getDetails().put("code",
        // attributeName.getExpressCode());
        // derivedAttribute.getEAnnotations().add(annotation);
        // if (eClass.getEStructuralFeature(derivedAttribute.getName())
        // == null) {
        // eClass.getEStructuralFeatures().add(derivedAttribute);
        // }
        }
    }
}
Also used : EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EClassifier(org.eclipse.emf.ecore.EClassifier) DerivedAttribute2(nl.tue.buildingsmart.schema.DerivedAttribute2) DefinedType(nl.tue.buildingsmart.schema.DefinedType) EReference(org.eclipse.emf.ecore.EReference)

Example 8 with EntityDefinition

use of nl.tue.buildingsmart.schema.EntityDefinition in project BIMserver by opensourceBIM.

the class Express2EMF method addSelects.

private void addSelects() {
    Iterator<DefinedType> typeIter = schema.getTypes().iterator();
    while (typeIter.hasNext()) {
        DefinedType type = typeIter.next();
        if (type instanceof SelectType) {
            EClass selectType = getOrCreateEClass(type.getName());
            selectType.setInterface(true);
            selectType.setAbstract(true);
            Iterator<NamedType> entIter = ((SelectType) type).getSelections().iterator();
            while (entIter.hasNext()) {
                NamedType nt = entIter.next();
                if (nt instanceof EntityDefinition) {
                    EClass choice = getOrCreateEClass(nt.getName());
                    choice.getESuperTypes().add(selectType);
                } else if (nt instanceof DefinedType) {
                    UnderlyingType domain = ((DefinedType) nt).getDomain();
                    if (domain instanceof RealType || domain instanceof StringType || domain instanceof IntegerType || domain instanceof NumberType || domain instanceof LogicalType) {
                        EClass choice = getOrCreateEClass(nt.getName());
                        choice.getESuperTypes().add(selectType);
                    } else if (domain instanceof DefinedType) {
                        DefinedType dt2 = (DefinedType) (domain);
                        if (dt2.getDomain() instanceof RealType) {
                            EClass choice = getOrCreateEClass(nt.getName());
                            choice.getESuperTypes().add(selectType);
                        }
                    } else if (nt instanceof SelectType) {
                    } else {
                        if (nt.getName().equals("IfcComplexNumber") || nt.getName().equals("IfcCompoundPlaneAngleMeasure") || nt.getName().equals("IfcBoolean") || nt.getName().equals("IfcNullStyle")) {
                            EClass choice = getOrCreateEClass(nt.getName());
                            choice.getESuperTypes().add(selectType);
                        } else {
                            System.out.println("The domain is null for " + selectType.getName() + " " + nt.getName());
                        }
                    }
                }
            }
        }
    }
    typeIter = schema.getTypes().iterator();
    while (typeIter.hasNext()) {
        DefinedType type = typeIter.next();
        if (type instanceof SelectType) {
            EClass selectType = (EClass) schemaPack.getEClassifier(type.getName());
            Iterator<NamedType> entIter = ((SelectType) type).getSelections().iterator();
            while (entIter.hasNext()) {
                NamedType nt = entIter.next();
                if (nt instanceof SelectType) {
                    EClass choice = getOrCreateEClass(nt.getName());
                    choice.getESuperTypes().add(selectType);
                }
            }
        }
    }
}
Also used : StringType(nl.tue.buildingsmart.schema.StringType) NamedType(nl.tue.buildingsmart.schema.NamedType) SelectType(nl.tue.buildingsmart.schema.SelectType) LogicalType(nl.tue.buildingsmart.schema.LogicalType) DefinedType(nl.tue.buildingsmart.schema.DefinedType) RealType(nl.tue.buildingsmart.schema.RealType) IntegerType(nl.tue.buildingsmart.schema.IntegerType) EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) EClass(org.eclipse.emf.ecore.EClass) NumberType(nl.tue.buildingsmart.schema.NumberType) UnderlyingType(nl.tue.buildingsmart.schema.UnderlyingType)

Example 9 with EntityDefinition

use of nl.tue.buildingsmart.schema.EntityDefinition in project BIMserver by opensourceBIM.

the class Express2EMF method addInverses.

private void addInverses() {
    Iterator<EntityDefinition> entIter = schema.getEntities().iterator();
    while (entIter.hasNext()) {
        EntityDefinition ent = (EntityDefinition) entIter.next();
        Iterator<Attribute> attribIter = ent.getAttributes(false).iterator();
        EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
        // }
        while (attribIter.hasNext()) {
            Attribute attrib = (Attribute) attribIter.next();
            // } else {
            if (attrib instanceof InverseAttribute) {
                addInverseAttribute(attrib, cls);
            }
        // }
        }
    }
}
Also used : EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) EClass(org.eclipse.emf.ecore.EClass) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EAttribute(org.eclipse.emf.ecore.EAttribute) Attribute(nl.tue.buildingsmart.schema.Attribute) ExplicitAttribute(nl.tue.buildingsmart.schema.ExplicitAttribute) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute)

Example 10 with EntityDefinition

use of nl.tue.buildingsmart.schema.EntityDefinition in project BIMserver by opensourceBIM.

the class SharedJsonDeserializer method processObject.

@SuppressWarnings({ "rawtypes", "unchecked" })
private IdEObject processObject(IfcModelInterface model, WaitingList<Long> waitingList, JsonReader jsonReader, EClass eClass) throws IOException, DeserializeException, IfcModelInterfaceException {
    IdEObjectImpl object = null;
    jsonReader.beginObject();
    if (jsonReader.nextName().equals("_i")) {
        long oid = jsonReader.nextLong();
        if (jsonReader.nextName().equals("_t")) {
            String type = jsonReader.nextString();
            if (eClass == null) {
                eClass = model.getPackageMetaData().getEClassIncludingDependencies(type);
            }
            if (eClass == null) {
                throw new DeserializeException("No class found with name " + type);
            }
            if (model.containsNoFetch(oid)) {
                object = (IdEObjectImpl) model.getNoFetch(oid);
            } else {
                if (eClass == StorePackage.eINSTANCE.getIfcHeader()) {
                    object = (IdEObjectImpl) StoreFactory.eINSTANCE.createIfcHeader();
                } else {
                    object = (IdEObjectImpl) model.create(eClass, oid);
                }
            }
            if (jsonReader.nextName().equals("_s")) {
                int state = jsonReader.nextInt();
                if (state == 1) {
                    object.setLoadingState(State.LOADING);
                    while (jsonReader.hasNext()) {
                        String featureName = jsonReader.nextName();
                        boolean embedded = false;
                        if (featureName.startsWith("_r")) {
                            featureName = featureName.substring(2);
                        } else if (featureName.startsWith("_e")) {
                            embedded = true;
                            featureName = featureName.substring(2);
                        }
                        EStructuralFeature eStructuralFeature = eClass.getEStructuralFeature(featureName);
                        if (eStructuralFeature == null) {
                            throw new DeserializeException("Unknown field (" + featureName + ") on class " + eClass.getName());
                        }
                        if (eStructuralFeature.isMany()) {
                            jsonReader.beginArray();
                            if (eStructuralFeature instanceof EAttribute) {
                                List list = (List) object.eGet(eStructuralFeature);
                                List<String> stringList = null;
                                if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDoubleObject() || eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                                    EStructuralFeature asStringFeature = eClass.getEStructuralFeature(eStructuralFeature.getName() + "AsString");
                                    stringList = (List<String>) object.eGet(asStringFeature);
                                }
                                while (jsonReader.hasNext()) {
                                    Object e = readPrimitive(jsonReader, eStructuralFeature);
                                    list.add(e);
                                    if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                                        double val = (Double) e;
                                        // TODO
                                        stringList.add("" + val);
                                    // this
                                    // is
                                    // losing
                                    // precision,
                                    // maybe
                                    // also
                                    // send
                                    // the
                                    // string
                                    // value?
                                    }
                                }
                            } else if (eStructuralFeature instanceof EReference) {
                                int index = 0;
                                AbstractEList list = (AbstractEList) object.eGet(eStructuralFeature);
                                while (jsonReader.hasNext()) {
                                    if (embedded) {
                                        JsonToken peek = jsonReader.peek();
                                        if (peek == JsonToken.NUMBER) {
                                            long refOid = jsonReader.nextLong();
                                            processRef(model, waitingList, object, eStructuralFeature, index, list, refOid);
                                        } else {
                                            // TODO: another case for two-dimensional arrays
                                            jsonReader.beginObject();
                                            String nextName = jsonReader.nextName();
                                            if (nextName.equals("_t")) {
                                                String t = jsonReader.nextString();
                                                IdEObject wrappedObject = (IdEObject) model.create(model.getPackageMetaData().getEClass(t), -1);
                                                if (jsonReader.nextName().equals("_v")) {
                                                    EStructuralFeature wv = wrappedObject.eClass().getEStructuralFeature("wrappedValue");
                                                    wrappedObject.eSet(wv, readPrimitive(jsonReader, wv));
                                                    list.add(wrappedObject);
                                                } else {
                                                    throw new DeserializeException("Expected _v");
                                                }
                                            } else if (nextName.equals("_i")) {
                                                // Not all are embedded...
                                                long refOid = jsonReader.nextLong();
                                                if (jsonReader.nextName().equals("_t")) {
                                                    String refType = jsonReader.nextString();
                                                    IdEObject refObject = (IdEObject) model.create(model.getPackageMetaData().getEClassIncludingDependencies(refType), refOid);
                                                    ((IdEObjectImpl) refObject).setLoadingState(State.OPPOSITE_SETTING);
                                                    model.add(refObject.getOid(), refObject);
                                                    addToList(eStructuralFeature, index, list, refObject);
                                                    ((IdEObjectImpl) refObject).setLoadingState(State.TO_BE_LOADED);
                                                } else {
                                                    processRef(model, waitingList, object, eStructuralFeature, index, list, refOid);
                                                }
                                            }
                                            jsonReader.endObject();
                                        }
                                    } else {
                                        jsonReader.beginObject();
                                        if (jsonReader.nextName().equals("_i")) {
                                            long refOid = jsonReader.nextLong();
                                            if (jsonReader.nextName().equals("_t")) {
                                                String refType = jsonReader.nextString();
                                                EClass referenceEClass = model.getPackageMetaData().getEClassIncludingDependencies(refType);
                                                if (model.getNoFetch(refOid) != null) {
                                                    processRef(model, waitingList, object, eStructuralFeature, index, list, refOid);
                                                } else {
                                                    IdEObject refObject = (IdEObject) model.create(referenceEClass, refOid);
                                                    ((IdEObjectImpl) refObject).setLoadingState(State.OPPOSITE_SETTING);
                                                    model.add(refObject.getOid(), refObject);
                                                    addToList(eStructuralFeature, index, list, refObject);
                                                    ((IdEObjectImpl) refObject).setLoadingState(State.TO_BE_LOADED);
                                                }
                                            }
                                        }
                                        jsonReader.endObject();
                                    }
                                    index++;
                                }
                            }
                            jsonReader.endArray();
                        } else {
                            if (eStructuralFeature instanceof EAttribute) {
                                Object x = readPrimitive(jsonReader, eStructuralFeature);
                                if (eStructuralFeature.getEType() == EcorePackage.eINSTANCE.getEDouble()) {
                                    EStructuralFeature asStringFeature = object.eClass().getEStructuralFeature(eStructuralFeature.getName() + "AsString");
                                    if (asStringFeature != null) {
                                        // TODO
                                        object.eSet(asStringFeature, "" + x);
                                    }
                                // this
                                // is
                                // losing
                                // precision,
                                // maybe
                                // also
                                // send
                                // the
                                // string
                                // value?
                                }
                                object.eSet(eStructuralFeature, x);
                            } else if (eStructuralFeature instanceof EReference) {
                                if (eStructuralFeature.getName().equals("GlobalId")) {
                                    IfcGloballyUniqueId globallyUniqueId = Ifc2x3tc1Factory.eINSTANCE.createIfcGloballyUniqueId();
                                    globallyUniqueId.setWrappedValue(jsonReader.nextString());
                                    object.eSet(eStructuralFeature, globallyUniqueId);
                                } else if (embedded) {
                                    jsonReader.beginObject();
                                    if (jsonReader.nextName().equals("_t")) {
                                        String t = jsonReader.nextString();
                                        IdEObject wrappedObject = (IdEObject) model.create(model.getPackageMetaData().getEClassIncludingDependencies(t), -1);
                                        ((IdEObjectImpl) wrappedObject).setLoadingState(State.LOADING);
                                        if (eStructuralFeature.getEAnnotation("dbembed") != null) {
                                            for (EStructuralFeature eStructuralFeature2 : wrappedObject.eClass().getEAllStructuralFeatures()) {
                                                String fn = jsonReader.nextName();
                                                if (fn.equals(eStructuralFeature2.getName())) {
                                                    wrappedObject.eSet(eStructuralFeature2, readPrimitive(jsonReader, eStructuralFeature2));
                                                } else {
                                                    throw new DeserializeException(fn + " / " + eStructuralFeature2.getName());
                                                }
                                            }
                                            object.eSet(eStructuralFeature, wrappedObject);
                                        } else {
                                            if (jsonReader.nextName().equals("_v")) {
                                                EStructuralFeature wv = wrappedObject.eClass().getEStructuralFeature("wrappedValue");
                                                wrappedObject.eSet(wv, readPrimitive(jsonReader, wv));
                                                object.eSet(eStructuralFeature, wrappedObject);
                                            }
                                        }
                                        ((IdEObjectImpl) wrappedObject).setLoadingState(State.LOADED);
                                    }
                                    jsonReader.endObject();
                                } else {
                                    jsonReader.beginObject();
                                    if (jsonReader.nextName().equals("_i")) {
                                        long refOid = jsonReader.nextLong();
                                        if (jsonReader.nextName().equals("_t")) {
                                            String refType = jsonReader.nextString();
                                            boolean isInverse = false;
                                            EntityDefinition entityBN = model.getPackageMetaData().getSchemaDefinition().getEntityBN(object.eClass().getName());
                                            if (entityBN != null) {
                                                // Some entities like GeometryInfo/Data are not in IFC schema, but valid
                                                Attribute attributeBN = entityBN.getAttributeBNWithSuper(eStructuralFeature.getName());
                                                if (attributeBN != null) {
                                                    if (attributeBN instanceof InverseAttribute) {
                                                        isInverse = true;
                                                    }
                                                }
                                            }
                                            // if (!isInverse) {
                                            if (model.getNoFetch(refOid) != null) {
                                                object.eSet(eStructuralFeature, model.getNoFetch(refOid));
                                            } else {
                                                IdEObject refObject = (IdEObject) model.create(model.getPackageMetaData().getEClassIncludingDependencies(refType), refOid);
                                                ((IdEObjectImpl) refObject).setLoadingState(State.OPPOSITE_SETTING);
                                                model.add(refObject.getOid(), refObject);
                                                object.eSet(eStructuralFeature, refObject);
                                                ((IdEObjectImpl) refObject).setLoadingState(State.TO_BE_LOADED);
                                            }
                                        // }
                                        }
                                    }
                                    jsonReader.endObject();
                                }
                            }
                        }
                    }
                    object.setLoadingState(State.LOADED);
                } else {
                    // state not_loaded
                    object.setLoadingState(State.TO_BE_LOADED);
                }
                if (waitingList.containsKey(oid)) {
                    waitingList.updateNode(oid, eClass, object);
                }
                model.add(object.getOid(), object);
            } else {
                LOGGER.info("_s expected");
            }
        } else {
            LOGGER.info("_t expected");
        }
    } else {
        LOGGER.info("_i expected");
    }
    jsonReader.endObject();
    return object;
}
Also used : AbstractEList(org.eclipse.emf.common.util.AbstractEList) EAttribute(org.eclipse.emf.ecore.EAttribute) Attribute(nl.tue.buildingsmart.schema.Attribute) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IfcGloballyUniqueId(org.bimserver.models.ifc2x3tc1.IfcGloballyUniqueId) DeserializeException(org.bimserver.plugins.deserializers.DeserializeException) EntityDefinition(nl.tue.buildingsmart.schema.EntityDefinition) EAttribute(org.eclipse.emf.ecore.EAttribute) EClass(org.eclipse.emf.ecore.EClass) AbstractEList(org.eclipse.emf.common.util.AbstractEList) WaitingList(org.bimserver.shared.WaitingList) List(java.util.List) ListWaitingObject(org.bimserver.shared.ListWaitingObject) EObject(org.eclipse.emf.ecore.EObject) JsonToken(com.google.gson.stream.JsonToken) InverseAttribute(nl.tue.buildingsmart.schema.InverseAttribute) EReference(org.eclipse.emf.ecore.EReference)

Aggregations

EntityDefinition (nl.tue.buildingsmart.schema.EntityDefinition)12 Attribute (nl.tue.buildingsmart.schema.Attribute)9 InverseAttribute (nl.tue.buildingsmart.schema.InverseAttribute)9 EAttribute (org.eclipse.emf.ecore.EAttribute)8 ExplicitAttribute (nl.tue.buildingsmart.schema.ExplicitAttribute)5 EClass (org.eclipse.emf.ecore.EClass)5 EReference (org.eclipse.emf.ecore.EReference)5 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)3 HashSet (java.util.HashSet)2 List (java.util.List)2 DefinedType (nl.tue.buildingsmart.schema.DefinedType)2 ListWaitingObject (org.bimserver.shared.ListWaitingObject)2 EObject (org.eclipse.emf.ecore.EObject)2 JsonToken (com.google.gson.stream.JsonToken)1 DerivedAttribute2 (nl.tue.buildingsmart.schema.DerivedAttribute2)1 IntegerType (nl.tue.buildingsmart.schema.IntegerType)1 LogicalType (nl.tue.buildingsmart.schema.LogicalType)1 NamedType (nl.tue.buildingsmart.schema.NamedType)1 NumberType (nl.tue.buildingsmart.schema.NumberType)1 RealType (nl.tue.buildingsmart.schema.RealType)1