(*
Copyright by:
buildingSMART International Limited, 1996-2019

Any technical documentation made available by buildingSMART International Limited
is the copyrighted work of buildingSMART International Limited and is owned by the 
buildingSMART International Limited. It may be photocopied, used in software development, 
or translated into another computer language without prior written consent from 
buildingSMART International Limited provided that full attribution is given. 
Prior written consent is required if changes are made to the technical specification.

This material is delivered to you as is and buildingSMART International Limited makes 
no warranty of any kind with regard to it, including, but not limited to, the implied 
warranties as to its accuracy or fitness for a particular purpose. Any use of the 
technical documentation or the information contained therein is at the risk of the user. 
Documentation may include technical or other inaccuracies or typographical errors. 
buildingSMART International Limited shall not be liable for errors contained therein or 
for incidental consequential damages in connection with the furnishing, performance or use 
of the material. The information contained in this document is subject to change without notice.

Issue date:
Friday, July 26, 2019

*)

SCHEMA IFCKERNEL;

REFERENCE FROM IFCACTORRESOURCE
(
  IfcActorSelect,
  IfcPerson,
  IfcOrganization,
  IfcPersonAndOrganization,
  IfcActorRole,
  IfcPostalAddress,
  IfcTelecomAddress
);

REFERENCE FROM IFCUTILITYRESOURCE
(
  IfcGloballyUniqueId,
  IfcOwnerHistory,
  IfcStateEnum
);

REFERENCE FROM IFCMEASURERESOURCE
(
  IfcUnit,
  IfcDerivedUnit,
  IfcNamedUnit,
  IfcSiUnit,
  IfcConversionBasedUnit,
  IfcContextDependentUnit,
  IfcMeasureWithUnit,
  IfcLabel,
  IfcIdentifier,
  IfcText,
  IfcUnitAssignment,
  IfcRatioMeasure
);

REFERENCE FROM IFCGEOMETRYRESOURCE
(
  IfcAxis2Placement2D,
  IfcAxis2Placement3D,
  IfcRepresentationMap
);

REFERENCE FROM IFCPROPERTYRESOURCE
(
  IfcProperty,
  IfcPropertySingleValue,
  IfcUniquePropertyName,
  IfcPropertyEnumeration
);

REFERENCE FROM IFCEXTERNALREFERENCERESOURCE
(
  IfcClassificationSelect,
  IfcClassificationReference,
  IfcDocumentInformation,
  IfcDocumentSelect,
  IfcLibrarySelect,
  IfcLibraryReference,
  IfcLibraryInformation
);

REFERENCE FROM IFCREPRESENTATIONRESOURCE
(
  IfcProductRepresentation,
  IfcProductDefinitionShape,
  IfcRepresentationContext,
  IfcGeometricRepresentationContext
);

REFERENCE FROM IFCPROCESSEXTENSION
(
  IfcRelSequence
);

REFERENCE FROM IFCGEOMETRICCONSTRAINTRESOURCE
(
  IfcObjectPlacement,
  IfcLocalPlacement
);

REFERENCE FROM IFCPRESENTATIONAPPEARANCERESOURCE
(
  IfcNullStyle
);

REFERENCE FROM IFCGEOMETRICMODELRESOURCE
(
  IfcGeometricSet
);

TYPE IfcPropertySetDefinitionSet = SET [1:?] OF IfcPropertySetDefinition;
END_TYPE;

TYPE IfcComplexPropertyTemplateTypeEnum = ENUMERATION OF
	(P_COMPLEX
	,Q_COMPLEX);
END_TYPE;

TYPE IfcObjectTypeEnum = ENUMERATION OF
	(PRODUCT
	,PROCESS
	,CONTROL
	,RESOURCE
	,ACTOR
	,GROUP
	,PROJECT
	,NOTDEFINED);
END_TYPE;

TYPE IfcPropertySetTemplateTypeEnum = ENUMERATION OF
	(PSET_TYPEDRIVENONLY
	,PSET_TYPEDRIVENOVERRIDE
	,PSET_OCCURRENCEDRIVEN
	,PSET_PERFORMANCEDRIVEN
	,QTO_TYPEDRIVENONLY
	,QTO_TYPEDRIVENOVERRIDE
	,QTO_OCCURRENCEDRIVEN
	,NOTDEFINED);
END_TYPE;

TYPE IfcSimplePropertyTemplateTypeEnum = ENUMERATION OF
	(P_SINGLEVALUE
	,P_ENUMERATEDVALUE
	,P_BOUNDEDVALUE
	,P_LISTVALUE
	,P_TABLEVALUE
	,P_REFERENCEVALUE
	,Q_LENGTH
	,Q_AREA
	,Q_VOLUME
	,Q_COUNT
	,Q_WEIGHT
	,Q_TIME);
END_TYPE;

TYPE IfcDefinitionSelect = SELECT
	(IfcObjectDefinition
	,IfcPropertyDefinition);
END_TYPE;

TYPE IfcProcessSelect = SELECT
	(IfcProcess
	,IfcTypeProcess);
END_TYPE;

TYPE IfcProductSelect = SELECT
	(IfcProduct
	,IfcTypeProduct);
END_TYPE;

TYPE IfcPropertySetDefinitionSelect = SELECT
	(IfcPropertySetDefinition
	,IfcPropertySetDefinitionSet);
END_TYPE;

TYPE IfcResourceSelect = SELECT
	(IfcResource
	,IfcTypeResource);
END_TYPE;

ENTITY IfcActor
 SUPERTYPE OF (ONEOF
    (IfcOccupant))
 SUBTYPE OF (IfcObject);
	TheActor : IfcActorSelect;
 INVERSE
	IsActingUpon : SET [0:?] OF IfcRelAssignsToActor FOR RelatingActor;
END_ENTITY;

ENTITY IfcComplexPropertyTemplate
 SUBTYPE OF (IfcPropertyTemplate);
	UsageName : OPTIONAL IfcLabel;
	TemplateType : OPTIONAL IfcComplexPropertyTemplateTypeEnum;
	HasPropertyTemplates : OPTIONAL SET [1:?] OF IfcPropertyTemplate;
 WHERE
	UniquePropertyNames : IfcUniquePropertyTemplateNames(HasPropertyTemplates);
	NoSelfReference : SIZEOF(QUERY(temp <* HasPropertyTemplates | SELF :=: temp)) = 0;
END_ENTITY;

ENTITY IfcContext
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcProject
    ,IfcProjectLibrary))
 SUBTYPE OF (IfcObjectDefinition);
	ObjectType : OPTIONAL IfcLabel;
	LongName : OPTIONAL IfcLabel;
	Phase : OPTIONAL IfcLabel;
	RepresentationContexts : OPTIONAL SET [1:?] OF IfcRepresentationContext;
	UnitsInContext : OPTIONAL IfcUnitAssignment;
 INVERSE
	IsDefinedBy : SET [0:?] OF IfcRelDefinesByProperties FOR RelatedObjects;
	Declares : SET [0:?] OF IfcRelDeclares FOR RelatingContext;
END_ENTITY;

ENTITY IfcControl
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcActionRequest
    ,IfcCostItem
    ,IfcCostSchedule
    ,IfcPerformanceHistory
    ,IfcPermit
    ,IfcProjectOrder
    ,IfcWorkCalendar
    ,IfcWorkControl))
 SUBTYPE OF (IfcObject);
	Identification : OPTIONAL IfcIdentifier;
 INVERSE
	Controls : SET [0:?] OF IfcRelAssignsToControl FOR RelatingControl;
END_ENTITY;

ENTITY IfcGroup
 SUPERTYPE OF (ONEOF
    (IfcAsset
    ,IfcInventory
    ,IfcStructuralLoadGroup
    ,IfcStructuralResultGroup
    ,IfcSystem))
 SUBTYPE OF (IfcObject);
 INVERSE
	IsGroupedBy : SET [0:?] OF IfcRelAssignsToGroup FOR RelatingGroup;
END_ENTITY;

ENTITY IfcObject
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcActor
    ,IfcControl
    ,IfcGroup
    ,IfcProcess
    ,IfcProduct
    ,IfcResource))
 SUBTYPE OF (IfcObjectDefinition);
	ObjectType : OPTIONAL IfcLabel;
 INVERSE
	IsDeclaredBy : SET [0:1] OF IfcRelDefinesByObject FOR RelatedObjects;
	Declares : SET [0:?] OF IfcRelDefinesByObject FOR RelatingObject;
	IsTypedBy : SET [0:1] OF IfcRelDefinesByType FOR RelatedObjects;
	IsDefinedBy : SET [0:?] OF IfcRelDefinesByProperties FOR RelatedObjects;
 WHERE
	UniquePropertySetNames : ((SIZEOF(IsDefinedBy) = 0) OR IfcUniqueDefinitionNames(IsDefinedBy));
END_ENTITY;

ENTITY IfcObjectDefinition
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcContext
    ,IfcObject
    ,IfcTypeObject))
 SUBTYPE OF (IfcRoot);
 INVERSE
	HasAssignments : SET [0:?] OF IfcRelAssigns FOR RelatedObjects;
	Nests : SET [0:1] OF IfcRelNests FOR RelatedObjects;
	IsNestedBy : SET [0:?] OF IfcRelNests FOR RelatingObject;
	HasContext : SET [0:1] OF IfcRelDeclares FOR RelatedDefinitions;
	IsDecomposedBy : SET [0:?] OF IfcRelAggregates FOR RelatingObject;
	Decomposes : SET [0:1] OF IfcRelAggregates FOR RelatedObjects;
	HasAssociations : SET [0:?] OF IfcRelAssociates FOR RelatedObjects;
END_ENTITY;

ENTITY IfcPreDefinedPropertySet
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcDoorLiningProperties
    ,IfcDoorPanelProperties
    ,IfcPermeableCoveringProperties
    ,IfcReinforcementDefinitionProperties
    ,IfcWindowLiningProperties
    ,IfcWindowPanelProperties))
 SUBTYPE OF (IfcPropertySetDefinition);
END_ENTITY;

ENTITY IfcProcess
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcEvent
    ,IfcProcedure
    ,IfcTask))
 SUBTYPE OF (IfcObject);
	Identification : OPTIONAL IfcIdentifier;
	LongDescription : OPTIONAL IfcText;
 INVERSE
	IsPredecessorTo : SET [0:?] OF IfcRelSequence FOR RelatingProcess;
	IsSuccessorFrom : SET [0:?] OF IfcRelSequence FOR RelatedProcess;
	OperatesOn : SET [0:?] OF IfcRelAssignsToProcess FOR RelatingProcess;
END_ENTITY;

ENTITY IfcProduct
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcAnnotation
    ,IfcElement
    ,IfcGrid
    ,IfcPort
    ,IfcProxy
    ,IfcSpatialElement
    ,IfcStructuralActivity
    ,IfcStructuralItem))
 SUBTYPE OF (IfcObject);
	ObjectPlacement : OPTIONAL IfcObjectPlacement;
	Representation : OPTIONAL IfcProductRepresentation;
 INVERSE
	ReferencedBy : SET [0:?] OF IfcRelAssignsToProduct FOR RelatingProduct;
 WHERE
	PlacementForShapeRepresentation : (EXISTS(Representation) AND EXISTS(ObjectPlacement))
            OR (EXISTS(Representation) AND 
			   (SIZEOF(QUERY(temp <* Representation.Representations | 'IFCREPRESENTATIONRESOURCE.IFCSHAPEREPRESENTATION' IN TYPEOF(temp))) = 0))
            OR (NOT(EXISTS(Representation)));
END_ENTITY;

ENTITY IfcProject
 SUBTYPE OF (IfcContext);
 WHERE
	HasName : EXISTS(SELF\IfcRoot.Name);
	CorrectContext : NOT(EXISTS(SELF\IfcContext.RepresentationContexts)) OR
(SIZEOF(QUERY(Temp <* SELF\IfcContext.RepresentationContexts |
 'IFCREPRESENTATIONRESOURCE.IFCGEOMETRICREPRESENTATIONSUBCONTEXT' IN TYPEOF(Temp)
  )) = 0);
	NoDecomposition : SIZEOF(SELF\IfcObjectDefinition.Decomposes) = 0;
END_ENTITY;

ENTITY IfcProjectLibrary
 SUBTYPE OF (IfcContext);
END_ENTITY;

ENTITY IfcPropertyDefinition
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcPropertySetDefinition
    ,IfcPropertyTemplateDefinition))
 SUBTYPE OF (IfcRoot);
 INVERSE
	HasContext : SET [0:1] OF IfcRelDeclares FOR RelatedDefinitions;
	HasAssociations : SET [0:?] OF IfcRelAssociates FOR RelatedObjects;
END_ENTITY;

ENTITY IfcPropertySet
 SUBTYPE OF (IfcPropertySetDefinition);
	HasProperties : SET [1:?] OF IfcProperty;
 WHERE
	ExistsName : EXISTS(SELF\IfcRoot.Name);
	UniquePropertyNames : IfcUniquePropertyName(HasProperties);
END_ENTITY;

ENTITY IfcPropertySetDefinition
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcPreDefinedPropertySet
    ,IfcPropertySet
    ,IfcQuantitySet))
 SUBTYPE OF (IfcPropertyDefinition);
 INVERSE
	DefinesType : SET [0:?] OF IfcTypeObject FOR HasPropertySets;
	IsDefinedBy : SET [0:?] OF IfcRelDefinesByTemplate FOR RelatedPropertySets;
	DefinesOccurrence : SET [0:?] OF IfcRelDefinesByProperties FOR RelatingPropertyDefinition;
END_ENTITY;

ENTITY IfcPropertySetTemplate
 SUBTYPE OF (IfcPropertyTemplateDefinition);
	TemplateType : OPTIONAL IfcPropertySetTemplateTypeEnum;
	ApplicableEntity : OPTIONAL IfcIdentifier;
	HasPropertyTemplates : SET [1:?] OF IfcPropertyTemplate;
 INVERSE
	Defines : SET [0:?] OF IfcRelDefinesByTemplate FOR RelatingTemplate;
 WHERE
	ExistsName : EXISTS(SELF\IfcRoot.Name);
	UniquePropertyNames : IfcUniquePropertyTemplateNames(HasPropertyTemplates);
END_ENTITY;

ENTITY IfcPropertyTemplate
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcComplexPropertyTemplate
    ,IfcSimplePropertyTemplate))
 SUBTYPE OF (IfcPropertyTemplateDefinition);
 INVERSE
	PartOfComplexTemplate : SET [0:?] OF IfcComplexPropertyTemplate FOR HasPropertyTemplates;
	PartOfPsetTemplate : SET [0:?] OF IfcPropertySetTemplate FOR HasPropertyTemplates;
END_ENTITY;

ENTITY IfcPropertyTemplateDefinition
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcPropertySetTemplate
    ,IfcPropertyTemplate))
 SUBTYPE OF (IfcPropertyDefinition);
END_ENTITY;

ENTITY IfcProxy
 SUBTYPE OF (IfcProduct);
	ProxyType : IfcObjectTypeEnum;
	Tag : OPTIONAL IfcLabel;
 WHERE
	WR1 : EXISTS(SELF\IfcRoot.Name);
END_ENTITY;

ENTITY IfcQuantitySet
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcElementQuantity))
 SUBTYPE OF (IfcPropertySetDefinition);
END_ENTITY;

ENTITY IfcRelAggregates
 SUBTYPE OF (IfcRelDecomposes);
	RelatingObject : IfcObjectDefinition;
	RelatedObjects : SET [1:?] OF IfcObjectDefinition;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* RelatedObjects | RelatingObject :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelAssigns
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcRelAssignsToActor
    ,IfcRelAssignsToControl
    ,IfcRelAssignsToGroup
    ,IfcRelAssignsToProcess
    ,IfcRelAssignsToProduct
    ,IfcRelAssignsToResource))
 SUBTYPE OF (IfcRelationship);
	RelatedObjects : SET [1:?] OF IfcObjectDefinition;
	RelatedObjectsType : OPTIONAL IfcObjectTypeEnum;
 WHERE
	WR1 : IfcCorrectObjectAssignment(RelatedObjectsType, RelatedObjects);
END_ENTITY;

ENTITY IfcRelAssignsToActor
 SUBTYPE OF (IfcRelAssigns);
	RelatingActor : IfcActor;
	ActingRole : OPTIONAL IfcActorRole;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* SELF\IfcRelAssigns.RelatedObjects | RelatingActor :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelAssignsToControl
 SUBTYPE OF (IfcRelAssigns);
	RelatingControl : IfcControl;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* SELF\IfcRelAssigns.RelatedObjects | RelatingControl :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelAssignsToGroup
 SUPERTYPE OF (ONEOF
    (IfcRelAssignsToGroupByFactor))
 SUBTYPE OF (IfcRelAssigns);
	RelatingGroup : IfcGroup;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* SELF\IfcRelAssigns.RelatedObjects | RelatingGroup :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelAssignsToGroupByFactor
 SUBTYPE OF (IfcRelAssignsToGroup);
	Factor : IfcRatioMeasure;
END_ENTITY;

ENTITY IfcRelAssignsToProcess
 SUBTYPE OF (IfcRelAssigns);
	RelatingProcess : IfcProcessSelect;
	QuantityInProcess : OPTIONAL IfcMeasureWithUnit;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* SELF\IfcRelAssigns.RelatedObjects | RelatingProcess :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelAssignsToProduct
 SUBTYPE OF (IfcRelAssigns);
	RelatingProduct : IfcProductSelect;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* SELF\IfcRelAssigns.RelatedObjects | RelatingProduct :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelAssignsToResource
 SUBTYPE OF (IfcRelAssigns);
	RelatingResource : IfcResourceSelect;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* SELF\IfcRelAssigns.RelatedObjects | RelatingResource :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelAssociates
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcRelAssociatesApproval
    ,IfcRelAssociatesClassification
    ,IfcRelAssociatesConstraint
    ,IfcRelAssociatesDocument
    ,IfcRelAssociatesLibrary
    ,IfcRelAssociatesMaterial))
 SUBTYPE OF (IfcRelationship);
	RelatedObjects : SET [1:?] OF IfcDefinitionSelect;
END_ENTITY;

ENTITY IfcRelAssociatesClassification
 SUBTYPE OF (IfcRelAssociates);
	RelatingClassification : IfcClassificationSelect;
END_ENTITY;

ENTITY IfcRelAssociatesDocument
 SUBTYPE OF (IfcRelAssociates);
	RelatingDocument : IfcDocumentSelect;
END_ENTITY;

ENTITY IfcRelAssociatesLibrary
 SUBTYPE OF (IfcRelAssociates);
	RelatingLibrary : IfcLibrarySelect;
END_ENTITY;

ENTITY IfcRelConnects
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcRelConnectsElements
    ,IfcRelConnectsPortToElement
    ,IfcRelConnectsPorts
    ,IfcRelConnectsStructuralActivity
    ,IfcRelConnectsStructuralMember
    ,IfcRelContainedInSpatialStructure
    ,IfcRelCoversBldgElements
    ,IfcRelCoversSpaces
    ,IfcRelFillsElement
    ,IfcRelFlowControlElements
    ,IfcRelInterferesElements
    ,IfcRelReferencedInSpatialStructure
    ,IfcRelSequence
    ,IfcRelServicesBuildings
    ,IfcRelSpaceBoundary))
 SUBTYPE OF (IfcRelationship);
END_ENTITY;

ENTITY IfcRelDeclares
 SUBTYPE OF (IfcRelationship);
	RelatingContext : IfcContext;
	RelatedDefinitions : SET [1:?] OF IfcDefinitionSelect;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* RelatedDefinitions | RelatingContext :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelDecomposes
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcRelAggregates
    ,IfcRelNests
    ,IfcRelProjectsElement
    ,IfcRelVoidsElement))
 SUBTYPE OF (IfcRelationship);
END_ENTITY;

ENTITY IfcRelDefines
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcRelDefinesByObject
    ,IfcRelDefinesByProperties
    ,IfcRelDefinesByTemplate
    ,IfcRelDefinesByType))
 SUBTYPE OF (IfcRelationship);
END_ENTITY;

ENTITY IfcRelDefinesByObject
 SUBTYPE OF (IfcRelDefines);
	RelatedObjects : SET [1:?] OF IfcObject;
	RelatingObject : IfcObject;
END_ENTITY;

ENTITY IfcRelDefinesByProperties
 SUBTYPE OF (IfcRelDefines);
	RelatedObjects : SET [1:?] OF IfcObjectDefinition;
	RelatingPropertyDefinition : IfcPropertySetDefinitionSelect;
 WHERE
	NoRelatedTypeObject : SIZEOF(QUERY(Types <* SELF\IfcRelDefinesByProperties.RelatedObjects |  'IFCKERNEL.IFCTYPEOBJECT' IN TYPEOF(Types))) = 0;
END_ENTITY;

ENTITY IfcRelDefinesByTemplate
 SUBTYPE OF (IfcRelDefines);
	RelatedPropertySets : SET [1:?] OF IfcPropertySetDefinition;
	RelatingTemplate : IfcPropertySetTemplate;
END_ENTITY;

ENTITY IfcRelDefinesByType
 SUBTYPE OF (IfcRelDefines);
	RelatedObjects : SET [1:?] OF IfcObject;
	RelatingType : IfcTypeObject;
END_ENTITY;

ENTITY IfcRelNests
 SUBTYPE OF (IfcRelDecomposes);
	RelatingObject : IfcObjectDefinition;
	RelatedObjects : LIST [1:?] OF IfcObjectDefinition;
 WHERE
	NoSelfReference : SIZEOF(QUERY(Temp <* RelatedObjects | RelatingObject :=: Temp)) = 0;
END_ENTITY;

ENTITY IfcRelationship
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcRelAssigns
    ,IfcRelAssociates
    ,IfcRelConnects
    ,IfcRelDeclares
    ,IfcRelDecomposes
    ,IfcRelDefines))
 SUBTYPE OF (IfcRoot);
END_ENTITY;

ENTITY IfcResource
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcConstructionResource))
 SUBTYPE OF (IfcObject);
	Identification : OPTIONAL IfcIdentifier;
	LongDescription : OPTIONAL IfcText;
 INVERSE
	ResourceOf : SET [0:?] OF IfcRelAssignsToResource FOR RelatingResource;
END_ENTITY;

ENTITY IfcRoot
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcObjectDefinition
    ,IfcPropertyDefinition
    ,IfcRelationship));
	GlobalId : IfcGloballyUniqueId;
	OwnerHistory : OPTIONAL IfcOwnerHistory;
	Name : OPTIONAL IfcLabel;
	Description : OPTIONAL IfcText;
 UNIQUE
	UR1 : GlobalId;
END_ENTITY;

ENTITY IfcSimplePropertyTemplate
 SUBTYPE OF (IfcPropertyTemplate);
	TemplateType : OPTIONAL IfcSimplePropertyTemplateTypeEnum;
	PrimaryMeasureType : OPTIONAL IfcLabel;
	SecondaryMeasureType : OPTIONAL IfcLabel;
	Enumerators : OPTIONAL IfcPropertyEnumeration;
	PrimaryUnit : OPTIONAL IfcUnit;
	SecondaryUnit : OPTIONAL IfcUnit;
	Expression : OPTIONAL IfcLabel;
	AccessState : OPTIONAL IfcStateEnum;
END_ENTITY;

ENTITY IfcTypeObject
 SUPERTYPE OF (ONEOF
    (IfcTypeProcess
    ,IfcTypeProduct
    ,IfcTypeResource))
 SUBTYPE OF (IfcObjectDefinition);
	ApplicableOccurrence : OPTIONAL IfcIdentifier;
	HasPropertySets : OPTIONAL SET [1:?] OF IfcPropertySetDefinition;
 INVERSE
	Types : SET [0:1] OF IfcRelDefinesByType FOR RelatingType;
 WHERE
	NameRequired : EXISTS(SELF\IfcRoot.Name);
	UniquePropertySetNames : (NOT(EXISTS(HasPropertySets))) OR IfcUniquePropertySetNames(HasPropertySets);
END_ENTITY;

ENTITY IfcTypeProcess
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcEventType
    ,IfcProcedureType
    ,IfcTaskType))
 SUBTYPE OF (IfcTypeObject);
	Identification : OPTIONAL IfcIdentifier;
	LongDescription : OPTIONAL IfcText;
	ProcessType : OPTIONAL IfcLabel;
 INVERSE
	OperatesOn : SET [0:?] OF IfcRelAssignsToProcess FOR RelatingProcess;
END_ENTITY;

ENTITY IfcTypeProduct
 SUPERTYPE OF (ONEOF
    (IfcDoorStyle
    ,IfcElementType
    ,IfcSpatialElementType
    ,IfcWindowStyle))
 SUBTYPE OF (IfcTypeObject);
	RepresentationMaps : OPTIONAL LIST [1:?] OF IfcRepresentationMap;
	Tag : OPTIONAL IfcLabel;
 INVERSE
	ReferencedBy : SET [0:?] OF IfcRelAssignsToProduct FOR RelatingProduct;
 WHERE
	ApplicableOccurrence : NOT(EXISTS(SELF\IfcTypeObject.Types[1])) OR
(SIZEOF(QUERY(temp <* SELF\IfcTypeObject.Types[1].RelatedObjects |
  NOT('IFCKERNEL.IFCPRODUCT' IN TYPEOF(temp)))
) = 0);
END_ENTITY;

ENTITY IfcTypeResource
 ABSTRACT SUPERTYPE OF (ONEOF
    (IfcConstructionResourceType))
 SUBTYPE OF (IfcTypeObject);
	Identification : OPTIONAL IfcIdentifier;
	LongDescription : OPTIONAL IfcText;
	ResourceType : OPTIONAL IfcLabel;
 INVERSE
	ResourceOf : SET [0:?] OF IfcRelAssignsToResource FOR RelatingResource;
END_ENTITY;

FUNCTION IfcCorrectObjectAssignment
  (Constraint: IfcObjectTypeEnum; Objects : SET[1:?] OF IfcObjectDefinition)
  : LOGICAL ;
  
LOCAL
  Count : INTEGER := 0;
END_LOCAL;

    IF NOT(EXISTS(Constraint)) THEN 
      RETURN(TRUE);
    END_IF;
  
    CASE Constraint OF
      IfcObjectTypeEnum.NOTDEFINED : RETURN(TRUE);
      IfcObjectTypeEnum.PRODUCT :
        BEGIN
          Count := SIZEOF(QUERY(temp <* Objects | NOT('IFCKERNEL.IFCPRODUCT' IN TYPEOF(temp))));
          RETURN(Count = 0);
        END;
      IfcObjectTypeEnum.PROCESS :
        BEGIN
          Count := SIZEOF(QUERY(temp <* Objects | NOT('IFCKERNEL.IFCPROCESS' IN TYPEOF(temp))));
          RETURN(Count = 0);
        END;
      IfcObjectTypeEnum.CONTROL :
        BEGIN
          Count := SIZEOF(QUERY(temp <* Objects | NOT('IFCKERNEL.IFCCONTROL' IN TYPEOF(temp))));
          RETURN(Count = 0);
        END;
      IfcObjectTypeEnum.RESOURCE :
        BEGIN
          Count := SIZEOF(QUERY(temp <* Objects | NOT('IFCKERNEL.IFCRESOURCE' IN TYPEOF(temp))));
          RETURN(Count = 0);
        END;
      IfcObjectTypeEnum.ACTOR :
        BEGIN
          Count := SIZEOF(QUERY(temp <* Objects | NOT('IFCKERNEL.IFCACTOR' IN TYPEOF(temp))));
          RETURN(Count = 0);
        END;
      IfcObjectTypeEnum.GROUP :
        BEGIN
          Count := SIZEOF(QUERY(temp <* Objects | NOT('IFCKERNEL.IFCGROUP' IN TYPEOF(temp))));
          RETURN(Count = 0);
        END;
      IfcObjectTypeEnum.PROJECT :
        BEGIN
          Count := SIZEOF(QUERY(temp <* Objects | NOT('IFCKERNEL.IFCPROJECT' IN TYPEOF(temp))));
          RETURN(Count = 0);
        END;
      OTHERWISE : RETURN(?);
    END_CASE;

END_FUNCTION;

FUNCTION IfcUniqueDefinitionNames
(Relations : SET [1:?] OF IfcRelDefinesByProperties)
:LOGICAL;

LOCAL
  Definition : IfcPropertySetDefinitionSelect;
  DefinitionSet : IfcPropertySetDefinitionSet;
  Properties : SET OF IfcPropertySetDefinition := [];
  Result : LOGICAL;
END_LOCAL;

IF SIZEOF(Relations) = 0 THEN
  RETURN(TRUE);
END_IF;

REPEAT i:=1 TO HIINDEX(Relations);
  Definition := Relations[i].RelatingPropertyDefinition;
  IF 'IFC4.IFCPROPERTYSETDEFINITION' IN TYPEOF(Definition) THEN
    Properties := Properties + Definition;
  ELSE 
    IF 'IFC4.IFCPROPERTYSETDEFINITIONSET' IN TYPEOF(Definition) THEN
      BEGIN
        DefinitionSet := Definition;
        REPEAT j:= 1 TO HIINDEX(DefinitionSet);
          Properties := Properties + DefinitionSet[j];
        END_REPEAT;
      END;
	END_IF;
  END_IF;
END_REPEAT;

Result := IfcUniquePropertySetNames(Properties);
RETURN (Result);
END_FUNCTION;

FUNCTION IfcUniquePropertyName
(Properties : SET [1:?] OF IfcProperty)
 :LOGICAL;

 LOCAL
   Names : SET OF IfcIdentifier := [];
 END_LOCAL;

 REPEAT i:=1 TO HIINDEX(Properties);
   Names := Names + Properties[i].Name;
 END_REPEAT;

 RETURN (SIZEOF(Names) = SIZEOF(Properties));   
 
END_FUNCTION;

FUNCTION IfcUniquePropertySetNames
(Properties : SET [1:?] OF IfcPropertySetDefinition)
:LOGICAL;

LOCAL
  Names : SET OF IfcLabel := [];
  Unnamed : INTEGER := 0;
END_LOCAL;

REPEAT i:=1 TO HIINDEX(Properties);
  IF 'IFC4.IFCPROPERTYSET' IN TYPEOF(Properties[i]) THEN
    Names := Names + Properties[i]\IfcRoot.Name;
  ELSE
    Unnamed := Unnamed + 1;
  END_IF;
END_REPEAT;

RETURN (SIZEOF(Names) + Unnamed = SIZEOF(Properties));
END_FUNCTION;

FUNCTION IfcUniquePropertyTemplateNames
(Properties : SET [1:?] OF IfcPropertyTemplate)
:LOGICAL;

LOCAL
  Names : SET OF IfcLabel := [];
END_LOCAL;

REPEAT i:=1 TO HIINDEX(Properties);
  Names := Names + Properties[i].Name;
END_REPEAT;
RETURN (SIZEOF(Names) = SIZEOF(Properties));
END_FUNCTION;

RULE IfcSingleProjectInstance FOR
	(IfcProject);

    WHERE
      WR1 : SIZEOF(IfcProject) <= 1;
END_RULE;

END_SCHEMA;
