Search in sources :

Example 1 with IntegerType

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

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

the class Express2EMF method x.

private EAttribute x(DefinedType type, EClass testType) {
    EAttribute wrapperAttrib = eFactory.createEAttribute();
    wrapperAttrib.setName("wrappedValue");
    if (type.getDomain() instanceof IntegerType) {
        wrapperAttrib.setEType(ePackage.getELong());
    } else if (type.getDomain() instanceof RealType) {
        wrapperAttrib.setEType(ePackage.getEDouble());
    } else if (type.getDomain() instanceof StringType) {
        wrapperAttrib.setEType(ePackage.getEString());
    } else if (type.getDomain() instanceof BooleanType) {
        wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate"));
    } else if (type.getDomain() instanceof NumberType) {
        wrapperAttrib.setEType(ePackage.getEDouble());
    } else if (type.getDomain() instanceof BinaryType) {
        wrapperAttrib.setEType(ePackage.getEByteArray());
    } else if (type.getDomain() instanceof LogicalType) {
        wrapperAttrib.setEType(schemaPack.getEClassifier("Tristate"));
    }
    wrapperAttrib.setUnsettable(true);
    testType.getEStructuralFeatures().add(wrapperAttrib);
    if (wrapperAttrib.getEType() == ePackage.getEDouble()) {
        EAttribute doubleStringAttribute = eFactory.createEAttribute();
        doubleStringAttribute.setEType(ePackage.getEString());
        doubleStringAttribute.setName("wrappedValueAsString");
        doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
        doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
        doubleStringAttribute.setUnsettable(true);
        testType.getEStructuralFeatures().add(doubleStringAttribute);
    }
    return wrapperAttrib;
}
Also used : IntegerType(nl.tue.buildingsmart.schema.IntegerType) EAttribute(org.eclipse.emf.ecore.EAttribute) NumberType(nl.tue.buildingsmart.schema.NumberType) BinaryType(nl.tue.buildingsmart.schema.BinaryType) StringType(nl.tue.buildingsmart.schema.StringType) BooleanType(nl.tue.buildingsmart.schema.BooleanType) LogicalType(nl.tue.buildingsmart.schema.LogicalType) RealType(nl.tue.buildingsmart.schema.RealType)

Example 3 with IntegerType

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

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

the class Express2EMF method processAttribute.

private void processAttribute(EntityDefinition ent, Attribute attrib) {
    if (attrib.getName().equals("RasterCode")) {
        System.out.println();
    }
    ExplicitAttribute expAttrib = (ExplicitAttribute) attrib;
    BaseType domain = expAttrib.getDomain();
    if (ent.getName().equals("IfcRelConnectsPathElements") && (attrib.getName().equals("RelatingPriorities") || attrib.getName().equals("RelatedPriorities"))) {
        // HACK, express parser does not recognize LIST [0:?] OF NUMBER
        EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
        EAttribute eAttribute = eFactory.createEAttribute();
        eAttribute.setName(attrib.getName());
        eAttribute.setUpperBound(-1);
        eAttribute.setUnique(false);
        eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
        eAttribute.setUnsettable(expAttrib.isOptional());
        cls.getEStructuralFeatures().add(eAttribute);
        return;
    }
    if (domain instanceof NamedType) {
        NamedType nt = (NamedType) domain;
        if (nt instanceof EnumerationType) {
            EAttribute enumAttrib = eFactory.createEAttribute();
            enumAttrib.setUnsettable(expAttrib.isOptional());
            enumAttrib.setName(attrib.getName());
            EClassifier eType = schemaPack.getEClassifier(nt.getName());
            enumAttrib.setEType(eType);
            EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
            cls.getEStructuralFeatures().add(enumAttrib);
        } else {
            EClass eType = (EClass) schemaPack.getEClassifier(nt.getName());
            EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
            // If the DEFINED type is already a wrapped value, we prefer not to use wrappedValue indirection
            boolean wrapped = superTypeIsWrapped(eType);
            if (wrapped) {
                EAttribute eAttribute = eFactory.createEAttribute();
                eAttribute.setUnsettable(expAttrib.isOptional());
                eAttribute.setName(attrib.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);
                cls.getEStructuralFeatures().add(eAttribute);
                if (type == EcorePackage.eINSTANCE.getEDouble()) {
                    EAttribute doubleStringAttribute = eFactory.createEAttribute();
                    doubleStringAttribute.setName(attrib.getName() + "AsString");
                    doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
                    doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
                    doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
                    doubleStringAttribute.setUnsettable(expAttrib.isOptional());
                    cls.getEStructuralFeatures().add(doubleStringAttribute);
                }
            } else {
                EReference eRef = eFactory.createEReference();
                eRef.setName(attrib.getName());
                // Hardcoded hack to fix multiplicity for
                // IfcSpatialStructureElement which references
                // RefLatitude and RefLongitude
                eRef.setUnsettable(expAttrib.isOptional());
                eRef.setEType(eType);
                cls.getEStructuralFeatures().add(eRef);
            }
        }
    } else if (domain instanceof AggregationType) {
        BaseType bt = ((AggregationType) domain).getElement_type();
        EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
        if (bt instanceof NamedType) {
            NamedType nt = (NamedType) bt;
            EClassifier eType = schemaPack.getEClassifier(nt.getName());
            if (superTypeIsWrapped((EClass) eType)) {
                EAttribute eAttribute = eFactory.createEAttribute();
                eAttribute.setName(attrib.getName());
                if (eAttribute.getName().equals("RefLatitude") || eAttribute.getName().equals("RefLongitude")) {
                    eAttribute.setUpperBound(3);
                } else {
                    eAttribute.setUpperBound(-1);
                }
                EClassifier type = ((EClass) eType).getEStructuralFeature("wrappedValue").getEType();
                eAttribute.setEType(type);
                eAttribute.setUnsettable(expAttrib.isOptional());
                eAttribute.setUnique(false);
                cls.getEStructuralFeatures().add(eAttribute);
                if (type == EcorePackage.eINSTANCE.getEDouble()) {
                    EAttribute doubleStringAttribute = eFactory.createEAttribute();
                    doubleStringAttribute.setName(attrib.getName() + "AsString");
                    doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
                    doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
                    doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
                    doubleStringAttribute.setUpperBound(-1);
                    doubleStringAttribute.setUnsettable(expAttrib.isOptional());
                    doubleStringAttribute.setUpperBound(eAttribute.getUpperBound());
                    doubleStringAttribute.setUnique(false);
                    cls.getEStructuralFeatures().add(doubleStringAttribute);
                }
            } else if (eType == EcorePackage.eINSTANCE.getEDouble()) {
                EAttribute eAttribute = eFactory.createEAttribute();
                eAttribute.setName(attrib.getName());
                eAttribute.setUnsettable(expAttrib.isOptional());
                eAttribute.setUnique(false);
                eAttribute.setEType(EcorePackage.eINSTANCE.getEAttribute());
                cls.getEStructuralFeatures().add(eAttribute);
                EAttribute doubleStringAttribute = eFactory.createEAttribute();
                doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
                doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
                doubleStringAttribute.setName(attrib.getName() + "AsString");
                doubleStringAttribute.setUpperBound(-1);
                doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
                doubleStringAttribute.setUnsettable(expAttrib.isOptional());
                doubleStringAttribute.setUpperBound(eAttribute.getUpperBound());
                doubleStringAttribute.setUnique(false);
                cls.getEStructuralFeatures().add(doubleStringAttribute);
            } else {
                EReference eRef = eFactory.createEReference();
                eRef.setUpperBound(-1);
                eRef.setName(attrib.getName());
                // Hardcoded hack to fix multiplicity for
                // IfcSpatialStructureElement which references
                // RefLatitude and RefLongitude
                eRef.setUnsettable(expAttrib.isOptional());
                eRef.setEType(eType);
                eRef.setUnique(false);
                // EClass cls = (EClass)
                // schemaPack.getEClassifier(ent.getName());
                cls.getEStructuralFeatures().add(eRef);
            }
        // EClassifier eType = schemaPack.getEClassifier(nt.getName());
        // eRef.setEType(eType);
        // cls.getEStructuralFeatures().add(eRef);
        } else if (bt instanceof RealType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getEDouble());
            cls.getEStructuralFeatures().add(eAttribute);
            EAttribute doubleStringAttribute = eFactory.createEAttribute();
            doubleStringAttribute.getEAnnotations().add(createHiddenAnnotation());
            doubleStringAttribute.getEAnnotations().add(createAsStringAnnotation());
            doubleStringAttribute.setName(attrib.getName() + "AsString");
            doubleStringAttribute.setUpperBound(-1);
            doubleStringAttribute.setEType(EcorePackage.eINSTANCE.getEString());
            doubleStringAttribute.setUnsettable(expAttrib.isOptional());
            doubleStringAttribute.setUpperBound(eAttribute.getUpperBound());
            doubleStringAttribute.setUnique(false);
            cls.getEStructuralFeatures().add(doubleStringAttribute);
        } else if (bt instanceof IntegerType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
            eAttribute.setUnsettable(expAttrib.isOptional());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt instanceof NumberType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
            eAttribute.setUnsettable(expAttrib.isOptional());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt instanceof LogicalType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setName(attrib.getName());
            eAttribute.setUpperBound(-1);
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getEBoolean());
            eAttribute.setUnsettable(expAttrib.isOptional());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt instanceof BinaryType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setUpperBound(-1);
            eAttribute.setName(attrib.getName());
            eAttribute.setUnique(false);
            eAttribute.setEType(EcorePackage.eINSTANCE.getEByteArray());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (bt == null) {
            // These are the new 2-dimensional arrays in IFC4, there are 10 of them (more in add2)
            addTwoDimensionalArray(ent.getName(), attrib.getName());
        }
        if (domain instanceof ArrayType) {
        // TODO this is not yet implmented in simpelSDAI
        // eAttrib.setLowerBound(((nl.tue.buildingsmart.express.dictionary
        // .ArrayType)domain).getLower_index());
        // One fix for this has been implemented in addHackedTypes
        }
    } else {
        EClass cls = (EClass) schemaPack.getEClassifier(ent.getName());
        if (domain == null) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(tristate);
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof IntegerType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getELong());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof LogicalType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEBoolean());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof RealType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEDouble());
            cls.getEStructuralFeatures().add(eAttribute);
            EAttribute eAttributeAsString = eFactory.createEAttribute();
            eAttributeAsString.getEAnnotations().add(createAsStringAnnotation());
            eAttributeAsString.getEAnnotations().add(createHiddenAnnotation());
            eAttributeAsString.setUnsettable(expAttrib.isOptional());
            eAttributeAsString.setName(attrib.getName() + "AsString");
            eAttributeAsString.setEType(EcorePackage.eINSTANCE.getEString());
            cls.getEStructuralFeatures().add(eAttributeAsString);
        } else if (domain instanceof StringType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEString());
            cls.getEStructuralFeatures().add(eAttribute);
        } else if (domain instanceof BinaryType) {
            EAttribute eAttribute = eFactory.createEAttribute();
            eAttribute.setUnsettable(expAttrib.isOptional());
            eAttribute.setName(attrib.getName());
            eAttribute.setEType(EcorePackage.eINSTANCE.getEByteArray());
            cls.getEStructuralFeatures().add(eAttribute);
        } else {
            throw new RuntimeException("Unknown type: " + domain);
        }
    }
}
Also used : BinaryType(nl.tue.buildingsmart.schema.BinaryType) StringType(nl.tue.buildingsmart.schema.StringType) NamedType(nl.tue.buildingsmart.schema.NamedType) EnumerationType(nl.tue.buildingsmart.schema.EnumerationType) EClassifier(org.eclipse.emf.ecore.EClassifier) LogicalType(nl.tue.buildingsmart.schema.LogicalType) AggregationType(nl.tue.buildingsmart.schema.AggregationType) RealType(nl.tue.buildingsmart.schema.RealType) IntegerType(nl.tue.buildingsmart.schema.IntegerType) ArrayType(nl.tue.buildingsmart.schema.ArrayType) EClass(org.eclipse.emf.ecore.EClass) EAttribute(org.eclipse.emf.ecore.EAttribute) NumberType(nl.tue.buildingsmart.schema.NumberType) BaseType(nl.tue.buildingsmart.schema.BaseType) EReference(org.eclipse.emf.ecore.EReference) ExplicitAttribute(nl.tue.buildingsmart.schema.ExplicitAttribute)

Aggregations

IntegerType (nl.tue.buildingsmart.schema.IntegerType)4 LogicalType (nl.tue.buildingsmart.schema.LogicalType)3 NumberType (nl.tue.buildingsmart.schema.NumberType)3 RealType (nl.tue.buildingsmart.schema.RealType)3 StringType (nl.tue.buildingsmart.schema.StringType)3 EClass (org.eclipse.emf.ecore.EClass)3 BinaryType (nl.tue.buildingsmart.schema.BinaryType)2 DefinedType (nl.tue.buildingsmart.schema.DefinedType)2 NamedType (nl.tue.buildingsmart.schema.NamedType)2 EAttribute (org.eclipse.emf.ecore.EAttribute)2 EClassifier (org.eclipse.emf.ecore.EClassifier)2 AggregationType (nl.tue.buildingsmart.schema.AggregationType)1 ArrayType (nl.tue.buildingsmart.schema.ArrayType)1 BaseType (nl.tue.buildingsmart.schema.BaseType)1 BooleanType (nl.tue.buildingsmart.schema.BooleanType)1 EntityDefinition (nl.tue.buildingsmart.schema.EntityDefinition)1 EnumerationType (nl.tue.buildingsmart.schema.EnumerationType)1 ExplicitAttribute (nl.tue.buildingsmart.schema.ExplicitAttribute)1 SelectType (nl.tue.buildingsmart.schema.SelectType)1 UnderlyingType (nl.tue.buildingsmart.schema.UnderlyingType)1