Search in sources :

Example 1 with DefinedType

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

the class Express2EMF method addHackedTypes.

private void addHackedTypes() {
    Iterator<DefinedType> typeIter = schema.getTypes().iterator();
    while (typeIter.hasNext()) {
        DefinedType type = typeIter.next();
        if (type.getName().equals("IfcCompoundPlaneAngleMeasure")) {
        // IfcCompoundPlaneAngleMeasure is a type of LIST [3..4] OF INTEGER (http://www.steptools.com/support/stdev_docs/express/ifc2x3/html/t_ifcco-03.html)
        // We model this by using a wrapper class
        // EClass ifcCompoundPlaneAngleMeasure = getOrCreateEClass(type.getName());
        // DefinedType integerType = new DefinedType("Integer");
        // integerType.setDomain(new IntegerType());
        // EAttribute attribute = modifySimpleType(integerType, ifcCompoundPlaneAngleMeasure);
        // attribute.setUpperBound(4);
        // ifcCompoundPlaneAngleMeasure.getEAnnotations().add(createWrappedAnnotation());
        } else if (type.getName().equals("IfcComplexNumber")) {
            // IfcComplexNumber is a type of ARRAY [1..2] OF REAL (http://www.steptools.com/support/stdev_docs/express/ifc2x3/html/t_ifcco-07.html)
            // We model this by using a wrapper class
            EClass ifcComplexNumber = getOrCreateEClass(type.getName());
            DefinedType realType = new DefinedType("Real");
            realType.setDomain(new RealType());
            EAttribute attribute = modifySimpleType(realType, ifcComplexNumber);
            ifcComplexNumber.getEStructuralFeature("wrappedValueAsString").setUpperBound(2);
            attribute.setUpperBound(2);
            ifcComplexNumber.getEAnnotations().add(createWrappedAnnotation());
        } else if (type.getName().equals("IfcNullStyle")) {
            // IfcNullStyle is a type of ENUMERATION OF NULL (http://www.steptools.com/support/stdev_docs/express/ifc2x3/html/t_ifcnu-02.html)
            // We cannot simply make this an enum because it is defined as a subtype(select) of IfcPresentationStyleSelect, so we use a wrapper here, both the wrapper and
            EClassifier ifcNullStyleEnum = schemaPack.getEClassifier("IfcNullStyle");
            ifcNullStyleEnum.setName("IfcNullStyleEnum");
            EClass ifcNullStyleWrapper = getOrCreateEClass(type.getName());
            EAttribute wrappedValue = eFactory.createEAttribute();
            wrappedValue.setName("wrappedValue");
            wrappedValue.setEType(ifcNullStyleEnum);
            ifcNullStyleWrapper.getEAnnotations().add(createWrappedAnnotation());
            ifcNullStyleWrapper.getEStructuralFeatures().add(wrappedValue);
        }
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) EClassifier(org.eclipse.emf.ecore.EClassifier) DefinedType(nl.tue.buildingsmart.schema.DefinedType) RealType(nl.tue.buildingsmart.schema.RealType)

Example 2 with DefinedType

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

the class Express2EMF method addSimpleTypes.

private void addSimpleTypes() {
    Iterator<DefinedType> typeIter = schema.getTypes().iterator();
    while (typeIter.hasNext()) {
        DefinedType type = typeIter.next();
        if (type.getDomain() instanceof SimpleType) {
            EClass testType = getOrCreateEClass(type.getName());
            testType.getEAnnotations().add(createWrappedAnnotation());
            modifySimpleType(type, testType);
        }
    }
}
Also used : SimpleType(nl.tue.buildingsmart.schema.SimpleType) EClass(org.eclipse.emf.ecore.EClass) DefinedType(nl.tue.buildingsmart.schema.DefinedType)

Example 3 with DefinedType

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

the class Express2EMF method addDerivedTypes.

/**
 * constructs the EXPRESS TYPEs like IfcPositiveLength measure that are not
 * simple types but derived types: <code>
 * TYPE IfcPositiveLengthMeasure = IfcLengthMeasure;
 * WHERE
 *  WR1 : SELF > 0.;
 * END_TYPE;
 * </code>
 */
private void addDerivedTypes() {
    Iterator<DefinedType> typeIter = schema.getTypes().iterator();
    while (typeIter.hasNext()) {
        DefinedType type = typeIter.next();
        /*
			 * one of the hard things TODO : TYPE IfcCompoundPlaneAngleMeasure =
			 * LIST [3:3] OF INTEGER; WHERE WR1 : { -360 <= SELF[1] < 360 }; WR2
			 * : { -60 <= SELF[2] < 60 }; WR3 : { -60 <= SELF[3] < 60 }; WR4 :
			 * ((SELF[1] >= 0) AND (SELF[2] >= 0) AND (SELF[3] >= 0)) OR
			 * ((SELF[1] <= 0) AND (SELF[2] <= 0) AND (SELF[3] <= 0)); END_TYPE;
			 * 
			 * I am skipping this for now, it only occurs once in the model
			 * future versions should definitely find an answer to this
			 * 
			 * A fix for this has been implemented in addHackedTypes
			 */
        if (type.getName().equalsIgnoreCase("IfcCompoundPlaneAngleMeasure")) {
            EClass testType = getOrCreateEClass(type.getName());
            DefinedType type2 = new DefinedType("Integer");
            type2.setDomain(new IntegerType());
            modifySimpleType(type2, testType);
            testType.getEAnnotations().add(createWrappedAnnotation());
        } else if (type.getDomain() instanceof DefinedType) {
            if (schemaPack.getEClassifier(type.getName()) != null) {
                EClass testType = (EClass) schemaPack.getEClassifier(type.getName());
                DefinedType domain = (DefinedType) type.getDomain();
                EClassifier classifier = schemaPack.getEClassifier(domain.getName());
                testType.getESuperTypes().add((EClass) classifier);
                testType.setInstanceClass(classifier.getInstanceClass());
            } else {
                EClass testType = getOrCreateEClass(type.getName());
                DefinedType domain = (DefinedType) type.getDomain();
                if (simpleTypeReplacementMap.containsKey(domain.getName())) {
                    // We can't subclass because it's a 'primitive' type
                    simpleTypeReplacementMap.put(type.getName(), simpleTypeReplacementMap.get(domain.getName()));
                } else {
                    EClass classifier = getOrCreateEClass(domain.getName());
                    testType.getESuperTypes().add((EClass) classifier);
                    if (classifier.getEAnnotation("wrapped") != null) {
                        testType.getEAnnotations().add(createWrappedAnnotation());
                    }
                    testType.setInstanceClass(classifier.getInstanceClass());
                }
            }
        }
    }
}
Also used : IntegerType(nl.tue.buildingsmart.schema.IntegerType) EClass(org.eclipse.emf.ecore.EClass) EClassifier(org.eclipse.emf.ecore.EClassifier) DefinedType(nl.tue.buildingsmart.schema.DefinedType)

Example 4 with DefinedType

use of nl.tue.buildingsmart.schema.DefinedType 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 5 with DefinedType

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

the class Express2EMF method addEnumerations.

private void addEnumerations() {
    Iterator<DefinedType> typeIter = schema.getTypes().iterator();
    while (typeIter.hasNext()) {
        DefinedType type = typeIter.next();
        if (type instanceof EnumerationType) {
            EEnum enumeration = eFactory.createEEnum();
            enumeration.setName(type.getName());
            EEnumLiteral nullValue = eFactory.createEEnumLiteral();
            nullValue.setName("NULL");
            nullValue.setLiteral("NULL");
            nullValue.setValue(0);
            enumeration.getELiterals().add(nullValue);
            int counter = 1;
            Iterator<String> values = ((EnumerationType) type).getElements().iterator();
            while (values.hasNext()) {
                String stringVal = values.next();
                if (!stringVal.equals("NULL")) {
                    EEnumLiteral value = eFactory.createEEnumLiteral();
                    value.setName(stringVal);
                    value.setLiteral(stringVal);
                    value.setValue(counter);
                    counter++;
                    enumeration.getELiterals().add(value);
                }
            }
            schemaPack.getEClassifiers().add(enumeration);
        }
    }
}
Also used : EnumerationType(nl.tue.buildingsmart.schema.EnumerationType) EEnumLiteral(org.eclipse.emf.ecore.EEnumLiteral) DefinedType(nl.tue.buildingsmart.schema.DefinedType) EEnum(org.eclipse.emf.ecore.EEnum)

Aggregations

DefinedType (nl.tue.buildingsmart.schema.DefinedType)6 EClass (org.eclipse.emf.ecore.EClass)5 EClassifier (org.eclipse.emf.ecore.EClassifier)3 EntityDefinition (nl.tue.buildingsmart.schema.EntityDefinition)2 IntegerType (nl.tue.buildingsmart.schema.IntegerType)2 RealType (nl.tue.buildingsmart.schema.RealType)2 EAttribute (org.eclipse.emf.ecore.EAttribute)2 DerivedAttribute2 (nl.tue.buildingsmart.schema.DerivedAttribute2)1 EnumerationType (nl.tue.buildingsmart.schema.EnumerationType)1 LogicalType (nl.tue.buildingsmart.schema.LogicalType)1 NamedType (nl.tue.buildingsmart.schema.NamedType)1 NumberType (nl.tue.buildingsmart.schema.NumberType)1 SelectType (nl.tue.buildingsmart.schema.SelectType)1 SimpleType (nl.tue.buildingsmart.schema.SimpleType)1 StringType (nl.tue.buildingsmart.schema.StringType)1 UnderlyingType (nl.tue.buildingsmart.schema.UnderlyingType)1 EEnum (org.eclipse.emf.ecore.EEnum)1 EEnumLiteral (org.eclipse.emf.ecore.EEnumLiteral)1 EReference (org.eclipse.emf.ecore.EReference)1