/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _DAI_SCHEMA_INSTANCE_H #define _DAI_SCHEMA_INSTANCE_H #include "daiDictionaryInstance.h" #include "daiSessionInstance.h" #include "daiAnchor.h" #include "daiReference.h" #include "daiPrimitive.h" #include "daiValidation/daiValidationNotifier.h" #include "daiAggr/daiList.h" #include "sdai.h" #include "OdStreamBuf.h" #include "OdArray.h" #include "SmartPtr.h" #include "TD_PackPush.h" /** \details Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format. */ namespace OdDAI { class Model; typedef OdSmartPtr ModelPtr; class Schema; typedef OdSmartPtr SchemaPtr; class Repository; typedef OdSmartPtr RepositoryPtr; class Entity; typedef OdSmartPtr EntityPtr; class GlobalRule; class UniquenessRule; class Attribute; class ApplicationInstance; /** \details A class which contains result of validation tasks. */ class SimpleValidationNotifier : public OdDAI::ValidationNotifier { //DOM-IGNORE-BEGIN ODRX_DECLARE_MEMBERS(SimpleValidationNotifier); //DOM-IGNORE-END Logical m_result; public: /** \details Creates a new validation notifier object with default parameters. */ SimpleValidationNotifier() : m_result(Logical::True) {} /** \details Returns result of all validations. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical result() const; /** \details Updates total validation result with latest validation. \param instanceId [in] of the entity instance. \param validationTask [in] A smart pointer to validation class definition. \param invalidParams [in] A struct which contains attributes and WR with validation problems. \param result [in] Result of validation. */ virtual void onValidationResult(OdDAIObjectId instanceId, OdDAI::ValidationTaskPtr validationTask, OdSharedPtr invalidParams, OdDAI::Logical result) override; /** \details Updates total validation result with latest validation. \param validationTask [in] A smart pointer to validation class definition. \param invalidObjects [in] An array of of the entity instances with validation problems. \param result [in] Result of validation. */ virtual void onValidationResult(OdDAI::ValidationTaskPtr validationTask, const OdDAIObjectIds& invalidObjects, OdDAI::Logical result) override; }; /** \details A data type that represents a smart pointer to an object. */ typedef OdSmartPtr SimpleValidationNotifierPtr; /** \details A class that implements functionality for working with a schema instance within the Data Access Interface. */ class DAI_EXPORT SchemaInstance : public SessionInstance { /** \details Creates a new schema instance. \param repository [in] A raw pointer to a object. \returns A smart pointer to the created schema instance object. */ static OdSmartPtr createObject(Repository* repository); public: //DOM-IGNORE-BEGIN ODRX_DECLARE_MEMBERS(SchemaInstance); //DOM-IGNORE-END /** \details Creates a new schema instance object with default parameters. */ SchemaInstance(); /** Retrieves the current name of the schema instance. \returns A string that contains the name. */ const OdAnsiString& name() const { return m_name; } /** \details Assigns a name to the schema instance. \param name [in] A string that contains the name. */ void rename(const OdAnsiString& name); /** Retrieves the native schema name of the schema instance. \returns A string that contains the name. */ const OdAnsiString& nativeSchema() const; /** \details Retrieves the array of associated with the schema instance. \returns An array of pointer to associated with the schema instance. */ const OdArray& associatedModels() const { return m_associatedModels; }; /* \details Adds a to the schema instance. \param model [in] A smart pointer to the to add to the schema instance. */ void addModel(const ModelPtr& model); /* \details Removes a from the schema instance. \param model [in] A smart pointer to the to remove from the schema instance. */ void removeModel(const ModelPtr& model); /** \details Retrieves change date of the schema instance. \returns Change date as OdTimeStamp class. */ const OdTimeStamp& changeDate() const { return m_changeDate; } /** \details Retrieves validation date of the schema instance. \returns Validation date as OdTimeStamp class. */ const OdTimeStamp& validationDate() const { return m_validationDate; } /** \details Retrieves validation result of the schema instance. \returns Result of the most recent validate operation or unset if such operation was not performed. */ Logical validationResult() const { return m_validationResult; } /** \details Retrieves validation level of the schema instance. \returns Level of the most recent validate operation. */ int validationLevel() const { return m_validationLevel; } /** \details Returns the containing the schema instance. \returns A constant raw pointer to the object that contains the schema instance. */ const Repository* repository() const { return m_repository; } /** \details Returns the containing the schema instance. \returns A raw pointer to the object that contains the schema instance. */ Repository* repository() { return m_repository; } /** \details Retrieves the current value of an attribute specified by its name. \param attrName [in] An ANSI string that contains the attribute name. \returns An OdRxValue object that contains the current value of the attribute. \remarks The method provides the late binding access to the attribute value by its name. */ virtual OdRxValue getAttr(const char* attrName) const; /** \details Checks the constraint (Global-Rule) for the schema instance. \param ruleName [in] A null-terminated string that contains the name of the constraint (Global-Rule) to be validated. \param aggr [out] A list of ANSI strings that contains the names of Where Rules associated with the Global Rule which were violated. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateGlobalRule(const char* ruleName, ListOfOdAnsiString& aggr) const; /** \details Checks the constraint (Global-Rule) for the schema instance. \param ruleName [in] A null-terminated string that contains the name of the constraint (Global-Rule) to be validated. \param aggr [out] A list of Where Rules associated with the Global Rule which were violated. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateGlobalRule(const char* ruleName, ListOfWhereRule& aggr) const; /** \details Checks the constraint (Global-Rule) for the schema instance. \param globalRule [in] A raw pointer to the constraint (Global-Rule) object. \param aggr [out] A list of Where Rules associated with the Global Rule which were violated. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateGlobalRule(const GlobalRule* globalRule, ListOfWhereRule& aggr) const; /** \details Checks the constraint (Uniqueness-Rule) for the schema instance. \param ruleName [in] A null-terminated string that contains the name of the constraint (Uniqueness-Rule) to be validated. \param entity [in] A raw pointer to the entity definition. \param aggr [out] A list of entity instances that contains the instances with false validation result. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateUniquenessRule(const char* ruleName, Entity* entity, NonPersistentList &aggr) const; /** \details Checks the constraint (Uniqueness-Rule) for the schema instance. \param ruleName [in] A null-terminated string that contains the name of the constraint (Uniqueness-Rule) to be validated. \param entity [in] A raw pointer to the entity definition. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateUniquenessRule(const char* ruleName, Entity* entity) const; /** \details Checks the constraint (Uniqueness-Rule) for the schema instance. \param rule [in] A raw pointer to the constraint (Uniqueness-Rule) object. \param entity [in] A raw pointer to the entity definition. \param aggr [out] A list of entity instances that contains the instances with false validation result. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateUniquenessRule(const UniquenessRule* rule, Entity* entity, NonPersistentList& aggr) const; /** \details Checks the constraint (Uniqueness-Rule) for the schema instance. \param rule [in] A raw pointer to the constraint (Uniqueness-Rule) object. \param entity [in] A raw pointer to the entity definition. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateUniquenessRule(const UniquenessRule* rule, Entity* entity) const; /** \details Checks whether all the attributes in the specified application instance with a reference to an entity instance refer to entity instance from SDAI-models in the schema instance. \param app [in] A raw pointer to the application instance object. \param aggr [out] An array of pointers to instances for attributes which violate any constraint. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateInstanceReferenceDomain(const ApplicationInstance* app, OdArray& aggr) const; /** \details Checks whether all the attributes in the specified application instance with a reference to an entity instance refer to entity instance from SDAI-models in the schema instance. \param app [in] A raw pointer to the application instance object. \param aggr [out] A list of ANSI strings that contains the names of instances for attributes which violate any constraint. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateInstanceReferenceDomain(const ApplicationInstance* app, ListOfOdAnsiString& aggr) const; /** \details Checks whether the population of schema instance conforms to all constrains specified in the native schema. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateSchemaInstance(); /** \details Checks if any SDAI-models were added or removed to the schema instance since last validation and last validation was successful. \returns * true if the constraint is satisfied and last validation result was true. * false if the constraint is violated or last validation result was not true. */ Boolean isValidationCurrent() const; /** \details This operation populates an existing non-persistent list by executing query over all models in the schema instance. \param expression [in] A string which contains expression to evaluate. \param theEntity [in] A raw pointer to entity (SELF), isn't taken into account by this implementation. \param destination [in] An existing non-persistent list to collect application instances satisfying expression. \returns An integer count of the number of entity instance meeting the specified criteria are appended. \remarks Single line query format: VALUE OPERATOR entity{.attr_spec}.attr_spec * VALUE can be UNSET to check, if attribute is set or not. * An entity extent for defined entity is taken as the source for query. * {.attr_spec} is the any sequence of possible attributes to filter a value. Examples:
    2 = IfcBSplineCurve.Degree
    UNSET <> IfcRoot.GlobalId
    UNSET = IfcRelContainedInSpatialStructure.RelatingStructure.GlobalId
    
*/ int SDAIQuery(const char* expression, const OdDAIObjectSDAI*& theEntity, NonPersistentList& destination); private: /** \details Assigns a name to the schema instance. \param name [in] A string that contains the name. */ void name(const OdAnsiString& name); /** \details Assigns a native schema to the schema instance. \param name [in] A string that contains the name. */ void nativeSchema(const OdAnsiString& nativeSchema); /** \details Assigns the change date to the schema instance. \param changeDate [in] A time stamp that contains the change date. */ void changeDate(const OdTimeStamp& changeDate); /** \details Assigns the validation date to the schema instance. \param validationDate [in] A time stamp that contains the validation date. */ void validationDate(const OdTimeStamp& validationDate); /** \details Assigns the validation result to the schema instance. \param validationResult [in] A Logical value that contains the validation result. */ void validationResult(Logical validationResult); /** \details Assigns the validation level to the schema instance. \param validationLevel [in] An integer value that contains the validation level. */ void validationLevel(int validationLevel); /** \details Checks the constraint (Global-Rule) for the schema instance. \param globalRule [in] A raw pointer to the constraint (Global-Rule) object. \param aggr [out] A list of ANSI strings that contains the names of Where Rules associated with the Global Rule which were violated. \returns * true if the constraint is satisfied. * false if the constraint is violated. * unknown if the constraint is not defined or can not be evaluated for any reason (an EXPRESS error, incorrectly filled data, mandatory data is unset, etc.). */ Logical validateGlobalRule(const GlobalRule* globalRule, ListOfOdAnsiString& aggr) const; /** \details Prints the time stamp as a string according to the specification. \param date [in] A time stamp that contains the date. \returns Date as OdAnsiString. */ OdAnsiString printDate(const OdTimeStamp& date) const; protected: OdAnsiString m_name; SchemaPtr m_nativeSchema; OdTimeStamp m_changeDate; OdAnsiString m_changeDateStr; OdTimeStamp m_validationDate; OdAnsiString m_validationDateStr; Logical m_validationResult; int m_validationLevel; OdArray m_associatedModels; Repository* m_repository; friend class Repository; }; /** \details A data type that represents a smart pointer to a object. */ typedef OdSmartPtr SchemaInstancePtr; } #include "TD_PackPop.h" #endif // _DAI_SCHEMA_INSTANCE_H