/////////////////////////////////////////////////////////////////////////////// // 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_APPLICATION_INSTANCE_H_ #define _DAI_APPLICATION_INSTANCE_H_ #include "daiObjectId.h" #include "daiObjectSDAI.h" #include "daiRTTI.h" #include "daiAttribute/AttributeCollection.h" #include "daiAttribute.h" #include "TD_PackPush.h" class OdStepFile; /** \details Implements the Data Access Interface (DAI) that provides functionality for manipulating data that is defined within the EXPRESS SCHEMA format. */ namespace OdDAI { class OdSpfFilerBase; class ApplicationInstance; /** \details A data type that represents a smart pointer to an object. */ typedef OdSmartPtr ApplicationInstancePtr; class ExplicitAttribute; class Model; typedef OdSmartPtr ModelPtr; /** \details The base class for application instances that can be manipulated with the Data Access Interface (DAI). */ class DAI_EXPORT ApplicationInstance : public OdDAIObjectSDAI { public: //DOM-IGNORE-BEGIN ODRX_DECLARE_MEMBERS(ApplicationInstance); //DOM-IGNORE-END /** \details Creates a new application instance with default parameters. */ ApplicationInstance() : m_id(NULL) {}; /** \details Retrieves the model that contains the application instance. \returns A raw pointer to the owning model; if the application instance is not appended to any model, the method returns a NULL pointer. */ virtual Model* owningModel() const; /** \details Retrieves the file that contains the model with this application instance. \returns A raw pointer to the owning file; if the application instance is not appended to any model or file, the method returns a NULL pointer. */ OdStepFile* owningStepFile() const; /** \details Reads values of the instance's explicit attribute fields from a file buffer that is associated with a specified filer object. \param rdFiler [in] A raw pointer to the filer object associated with the file buffer to read data from. \returns eOk if the attribute field values are successfully read; otherwise, the method returns an appropriate error. \remarks The method's default implementation returns the eNotImplemented value. */ virtual OdResult inFields(OdSpfFilerBase* /*rdFiler*/) { return eNotImplemented; }; /** \details Writes values of the instance's explicit attribute fields to a file buffer that is assigned to a specified filer object. \param wrFiler [in] A raw pointer to the filer object assigned with the file buffer to write data to. \returns eOk if the attribute field values are successfully written; otherwise, the method returns an appropriate error. \remarks The method's default implementation returns the eNotImplemented value. */ virtual OdResult outFields(OdSpfFilerBase* /*wrFiler*/) { return eNotImplemented; }; /** \details Retrieves whether the application instance is an instance of an instance type with a specified name. \param entityName [in] An entity's type name. \returns true if the application instance is an instance of the specified type; otherwise, the method returns false. */ virtual bool isInstanceOf(const char *entityName) const; /** \details Retrieves whether the application instance is an instance of a specified EXPRESS type. \param entityDef [in] An instance of the class that represents the entity type. \returns true if the application instance is an instance of the specified EXPRESS type; otherwise, the method returns false. */ virtual bool isInstanceOf(const Entity *entityDef) const; /** \details Retrieves whether the application instance belongs to or is derived from a certain entity type with a specified name. \param entityName [in] A name of entities type. \returns true if the application instance belongs to or is derived from the type of entity with the specified name; otherwise, the method returns false. */ virtual bool isKindOf(const char *entityName) const; /** \details Retrieves whether the application instance belongs to or is derived from a specified entity type. \param entityDef [in] An instance of the class that represents the entity type. \returns true if the application instance belongs to or is derived from the specified type; otherwise, the method returns false. */ virtual bool isKindOf(const Entity *entityDef) const; /** \details Sets inverse attributes to related application instances. */ virtual void setInverseCounterParts(); /** \details Removes inverse attributes from related application instances. */ virtual void resetInverseCounterParts(); /** \details Retrieves the current value of an inverse attribute with a specified name. \param attrName [in] A null-terminated string that contains the inverse attribute's name. \returns An OdRxValue object that contains the inverse attribute value. */ OdRxValue getInverseAttr(const char* attrName) const; /** \details Cleans dynamic attributes. */ void cleanDynamicAttributes(); /** \details Retrieves the type name of the application instance. \returns An ANSI string that contains the type name. */ const OdAnsiString& typeName() const; /** \details Retrieves the current value of an attribute specified by its name. \param attrName [in] An ANSI string that contains the 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; #ifndef SWIG /** \details Retrieves the current value of an attribute. \param attDef [in] A smart pointer to attribute definition. \returns The current value of the attribute. \remarks The method provides the late binding access to the attribute value by its definition. */ virtual OdRxValue getAttr(const AttributePtr& attDef) const; #endif /** \details Retrieves whether the value is set or is unset. \param attrName [in] An ANSI string that contains the name. \returns true if the has a value; otherwise, the method returns false (it means that the value is not set). */ virtual bool testAttr(const char * attrName) const; /** \details Retrieves whether the value is set or is unset. \param attribute [in] An type. \returns true if the has a value; otherwise, the method returns false (it means that the value is not set). */ virtual bool testAttr(const AttributePtr& attribute) const; /** \details Sets a new value of an that is specified by its name. \param explicitAttrName [in] An ANSI string that contains the attribute name. \param val [in] A new value to be set. \returns true if the value was successfully set; otherwise, the method returns false. */ virtual bool putAttr(const char* explicitAttrName, const OdRxValue& val); /** \details Sets a new value of an that is specified by its definition. \param explicitAttr [in] A smart pointer to the attribute definition. \param val [in] A new attribute value to be set. \returns true if the value was successfully set; otherwise, the method returns false. */ virtual bool putAttr(const ExplicitAttributePtr &explicitAttr, const OdRxValue& val); /** \details Sets a new value of an specified with its name after the validation is performed. \param explicitAttrName [in] An ANSI string that contains the name. \param newValue [in] A new value to be set. \returns true if the validation was passed and the value was successfully set; otherwise, the method returns false. */ bool putAttrWithValidation(const char* explicitAttrName, const OdRxValue& newValue); /** \details Sets a new value of an that is specified by its name in the case insensitive mode. \param explicitAttrName [in] An ANSI string that contains the attribute name. \param val [in] A new value to be set. \returns true if the value was successfully set; otherwise, the method returns false. */ bool putAttrCaseInsensitive(const char * explicitAttrName, const OdRxValue &val); /** \details Checks whether the value of a specified is set. \param explicitAttrName [in] A null-terminated ANSI string that contains the attribute name. \returns true if the has a value; otherwise, the method returns false (it means that the value is not set). */ void unsetAttrCaseInsensitive(const char * explicitAttrName); /** \details Clears the value. \param explicitAttrName [in] An ANSI string that contains the name. */ virtual void unsetAttr(const char * explicitAttrName); /** \details Clears the value. \param attribute [in] A smart pointer to the to unset. */ void unsetAttr(const AttributePtr& attribute); /** \details Retrieves the database object identifier of the application instance. \returns The application instance's database identifier represented with a raw pointer to an OdDbStub object. \remarks The method returns a NULL pointer if the application instance is not persistent (i.e. not stored in a database). */ virtual OdDbStub* id() const { return m_id; }; /** \details Compares the application instance object with another object. \param pOther [in] A raw pointer to the object to be compared. \returns An OdRx::Ordering value that represents the result of the comparison operation. \remarks The method returns one of the following:
NameValueDescription
_kLessThan_-1This object is less than Other Object.
_kEqual_0This object equals Other Object.
_kGreaterThan_1This object is greater than Other Object.
_kNotOrderable_2This class is not orderable.
The default implementation of this method returns _kNotOrderable_. \sa * Comparing the Value of Rx Objects. * Comparing Rx-Objects */ OdRx::Ordering comparedTo(const OdRxObject* pOther) const override; /** \details Compares the application instance object with another object by comparing their inverse attributes. \param pOther [in] A raw pointer to the object to be compared. \returns An OdRx::Ordering value that represents the result of the comparison operation. \remarks This method returns one of the following:
NameValueDescription
_kLessThan_-1This object is less than Other Object.
_kEqual_0This object equals Other Object.
_kGreaterThan_1This object is greater than Other Object.
_kNotOrderable_2This class is not orderable.
*/ OdRx::Ordering comparedToInverse(const OdRxObject* pOther) const; /** details Copies the contents of the specified object into this object. \param pSource [in] A raw pointer to the source object. \remarks The default implementation of this function does nothing but throws the eNotApplicable exception. */ virtual void copyFrom(const OdRxObject* pSource); /** \details Checks whether the instance has unset mandatory attributes and retrieves the list of such attributes. \param unsetAttrs [out] An array of pointers to instances which are unset for the application instance. \returns true if all mandatory attributes of an instance are set; the method returns false if at least one mandatory attribute of an instance is unset. */ bool validateRequiredExplicitAttrsAssigned(OdArray &unsetAttrs) const; /** \details Checks whether the instance has with violated size constraints and retrieves the list of such attributes. \param aggr [out] An array of pointers to instances which have violated size constraints for the application instance. \returns true if all constraints are satisfied or if the instance has no inverse attributes; otherwise, the method returns false. */ bool validateInverseAttrs(OdArray& aggr) const; /** \details Checks the constraint (Where-Rule) for the application instance. The constraint (Where-Rule) is defined within the application entity definition or within a parent application entity definition. \param ruleName [in] A null-terminated string that contains the name of the constraint (Where-Rule) to be validated. \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 validateWhereRule(const char *ruleName) const; /** \details Checks the constraint (Where-Rule) for the application instance. The constraint (Where-Rule) is defined within the application entity definition or within a parent application entity definition. \param ruleDef [in] A raw pointer to the constraint (Where-Rule) object. \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 validateWhereRule(const WhereRule *ruleDef) const; /** \details Checks whether the instance has aggregate attributes, which violate size constraints and retrieves the list of such . \param aggr [out] An array of pointers to instances which are violating size constraints for the application instance. \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 validateAggrSize(OdArray& aggr) const; /** \details Checks whether the instance has string attributes with incorrect width and retrieves the list of such attributes. \param aggr [out] An array of pointers to instances which have incorrect width for the application instance. \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 validateStringWidth(OdArray& aggr) const; /** \details Checks whether the instance has binary attributes with incorrect width and retrieves the list of such attributes. \param aggr [out] An array of pointers to instances which have incorrect width for the application instance. \returns * true if all attribute binary values have correct width * false if any width constraint is violated * unknown if the constraint expression evaluation value is unknown or is not defined. */ Logical validateBinaryWidth(OdArray& aggr) const; /** \details Checks whether application instance aggregate attributes has unique items in the case if aggregation type of attribute UNIQUE flag is turned on. \param aggr [out] An array of pointers to instances for attributes which violate the aggregate uniqueness check. \returns * true if all appropriate attributes of application instance have passed the check. * false if at least one attribute violates the uniqueness constraint; */ Boolean validateAggrUniqueness(OdArray& aggr) const; /** \details Checks whether each entity instance that represents the value of a specified instance attribute has a valid entity data type. \param aggr [out] An array of pointers to instances for attributes which violate any constraint. \returns * true if all entity-valued attributes have instance values of a correct type. * false if any entity-valued attribute has an instance value of an incorrect type. * unknown if any required explicit attribute value is unset that could reference an entity instance. */ Logical validateExplicitAttrsReferences(OdArray& aggr) const; /** \details Checks whether each entity instance that represents the value of a specified instance attribute is stored within one of the models specified by a calling subroutine. \param models [in] An array of pointers to to search within. \param aggr [out] An array of pointers to instances for attributes which violate any constraint. \returns * true if all entity-valued attributes have instance values within specified models. * false if any entity-valued attribute has an instance value outside of specified models. * unknown if any required explicit attribute value is unset that could reference an entity instance. */ Logical validateInstanceReferenceDomain(const OdArray& models, OdArray& aggr) const; /** \details Checks whether a specified array instances which don't assume optional attributes (i.e. attributes that can't have unset value) have attribute values. \param aggr [out] An array of pointers to instances for attributes which violate constraints. \returns True if all instances from the array don't contain attributes with unset values; otherwise, the method returns False. */ Boolean validateArrayNotOptional(OdArray& aggr) const; /** \details Calculates a value of a derived attribute specified by its name. \param attrName [in] An ANSI string that contains the derived attribute name. \returns The calculated value of the attribute. \remarks The method provides the late binding access to the derived attribute value by its name. */ OdRxValue getDerivedAttr(const char *attrName) const; /** \details Retrieves the Named/Defined data types of the entity instance according to the schema types hierarchy. \param resultList [in/out] A raw pointer to a non-persistent list that contains identifiers of entity instance data types. \returns A raw pointer to a non-persistent list that contains identifiers of Named/Defined data types of the entity instance. */ OdDAI::NonPersistentList* findDataTypes(OdDAI::NonPersistentList* resultList); /** \details Retrieves the identifiers of the attributes of entity instances which refer to the current entity instance within the model. \param resultList [in/out] A raw pointer to a non-persistent list that contains identifiers of attributes which refer to the current entity instance. \returns A raw pointer to a non-persistent list that contains identifiers of attributes which refer to the current entity instance. */ OdDAI::NonPersistentList* findRolesOf(OdDAI::NonPersistentList* resultList); /** \details Retrieves the identifiers of all the entity instances in the model that refer to the current entity instance. \param resultList [in/out] A raw pointer to a non-persistent list that contains identifiers of entity instances which have any attribute that refers to the current entity instance. \returns A raw pointer to a non-persistent list that contains identifiers of entity instances which have any attribute that refers to the current entity instance. */ OdDAI::NonPersistentList* findUsers(OdDAI::NonPersistentList* resultList); /** \details Retrieves the identifiers of all the entity instances in the model which refer to the entity instance through the specified attribute name. \param roleName [in] An ANSI string that contains a fully qualified attribute name, for example, "ifcplacement.location". \param resultList [in/out] A raw pointer to a non-persistent list that contains identifiers of entity instances which have any attribute that refers to the current entity instance through a specified attribute name. \returns A raw pointer to a non-persistent list that contains identifiers of entity instances which have any attribute that refers to the current entity instance through a specified attribute name. */ OdDAI::NonPersistentList* findUsedInBN(const OdAnsiString& roleName, OdDAI::NonPersistentList* resultList); /** \details Retrieves the identifiers of all entity instances in the model which refer to the entity instance through the specified attribute. \param role [in] An that refers to the entity instance (in other words, that plays the requested role in the relation between entities). \param resultList [in/out] A raw pointer to a non-persistent list that contains identifiers of entity instances which have the specified attribute that refers to the current entity instance. \returns A raw pointer to a non-persistent list that contains identifiers of entity instances which have the specified attribute that refers to the current entity instance. */ OdDAI::NonPersistentList* findUsedIn(const OdDAI::Attribute& role, OdDAI::NonPersistentList* resultList); /** \details Draws a graphical entity representation that is independent of any viewport context. \param wd [in] A raw pointer to the object that encapsulates parameters of viewport-independent vectorization. \returns true if the drawing was successful; otherwise, the method returns false. */ virtual bool subWorldDraw(OdGiWorldDraw* wd) const; /** \details Sets a new Gs node cache for the entity. \param pGsNode [in] A raw pointer to an OdGsCache object. */ virtual void setGsNode(OdGsCache* pGsNode); /** \details Retrieves the current Gs node object of the entity. \returns A raw pointer to the OdGsCache object associated with the entity. */ virtual OdGsCache* gsNode() const; /** \details Sets the values of the entity's sub-entity traits. \param traits [out] A raw pointer to the traits to be filled and returned to a calling subroutine. \returns The result of setting the values. */ virtual OdUInt32 subSetAttributes(OdGiDrawableTraits* traits) const; public: /** \details A template function that sets a new value of attributes set, which is specified by attribute and value. \param explicitAttribute [in] An ANSI string that contains the attribute name or attribute definition pointer. \param attrValue [in] A new attribute value to be set. \returns true if the attributes values were successfully set; otherwise, the method returns false. */ template bool putAttrs(TAttr explicitAttribute, TValue attrValue); /** \details A template function that sets a new value of variable number attributes set, which is specified by pairs of attribute and value. \param explicitAttribute [in] An ANSI string that contains the attribute name or attribute definition pointer. \param attrValue [in] A new attribute value to be set. \param attributesData... [in] A set of pairs of attribute and value. \returns true if the attributes values were successfully set; otherwise, the method returns false. */ template bool putAttrs(TAttr explicitAttribute, TValue attrValue, args... attributesData); protected: virtual OdRx::Ordering comparedToLateImpl(const ApplicationInstance* otherInstance) const ; virtual bool comparedToEarlyImpl(const ApplicationInstance* otherInstance, OdRx::Ordering& result) const; virtual void copyFromLateImpl(const OdDAI::ApplicationInstance* otherInstance); virtual bool copyFromEarlyImpl(const OdDAI::ApplicationInstance* otherInstance); virtual const OdDAI::AttributeKeyCollection* getDynamicAttributesKeyData() const; template inline TType* getInverseAttr(const char* attrName); bool putInverseAttr(const char* explicitAttrName, const OdRxValue& val); void resetInverseAttributes(OdDAI::ApplicationInstancePtr &referencedInstance, const OdDAI::ExplicitAttributePtr &explicitAttribute); void cleanInverseAttributes(); /** \details Evaluates an expression to retrieve derived attribute value. \param derivedAttribute [in] A raw pointer to the derived attribute instance to be returned. \returns The value of the attribute represented with an OdRxValue object. */ OdRxValue getDerivedAttr(OdDAI::DerivedAttribute* derivedAttribute) const; /** \details Retrieves inverse or derived attribute value by its name. \param attrName [in] A null-terminated ANSI string that contains the attribute name. \returns The value of the attribute represented with an OdRxValue object. */ OdRxValue getDynamicAttr(const char *attrName) const; void processAttributeValue(OdRxValue& idInstance, const OdDAIObjectId& idCurrent, const OdDAI::Entity* pEntity, const OdDAI::ExplicitAttribute* pAttribute) const; protected: OdDbStub *m_id; mutable DynamicAttributeHolder m_dynamicAttributes; friend class FilerBase; friend class ModelContents; friend class OdSpfFilerBase; friend class Pager; friend class InverseAttributeCalculator; friend class InverseHelper; }; /** \details A template function that retrieves an inverse attribute with a specified name. \param attrName [in] A null-terminated ANSI string that contains the attribute name. \returns A raw pointer to the inverse attribute. */ template TType* ApplicationInstance::getInverseAttr(const char* attrName) { auto dynamicAttributesData = getDynamicAttributesKeyData(); if (dynamicAttributesData) { return m_dynamicAttributes.getTypedAttr(attrName, *dynamicAttributesData, true); } return nullptr; } /** \details A template function that sets a new value of attributes set, which is specified by attribute and value. \param explicitAttribute [in] An ANSI string that contains the attribute name or attribute definition pointer. \param attrValue [in] A new attribute value to be set. \returns true if the attributes values were successfully set; otherwise, the method returns false. */ template bool ApplicationInstance::putAttrs(TAttr explicitAttribute, TValue attrValue) { OdRxValue value; value << attrValue; return putAttr(explicitAttribute, value); } /** \details A template function that sets a new value of variable number attributes set, which is specified by pairs of attribute and value. \param explicitAttribute [in] An ANSI string that contains the attribute name or attribute definition pointer. \param attrValue [in] A new attribute value to be set. \param args... [in] A set of pairs of attribute and value. \returns true if the attributes values were successfully set; otherwise, the method returns false. */ template bool ApplicationInstance::putAttrs(TAttr explicitAttribute, TValue attrValue, args... attributesData) { OdRxValue value; value << attrValue; auto result = putAttr(explicitAttribute, value); return result && putAttrs(attributesData...); } } #include "TD_PackPop.h" #endif // _DAI_APPLICATION_INSTANCE_H_