/////////////////////////////////////////////////////////////////////////////// // 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_VALIDATION_TASK_H #define _DAI_VALIDATION_TASK_H #include "OdaCommon.h" #include "daiBuildOptions.h" #include "Common/daiValidationCommon.h" #include "RxObject.h" #include "daiAttribute.h" #include "daiRules/daiWhereRule.h" #include "daiHostAppServicesBase.h" #include "daiStepFile.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 ApplicationInstance; class Model; /** \details A base class that stores and handles the context information for validation check. */ class ValidationContext { protected: //SWIG-1558 /** \details Creates a new validation context instance for a specified . \param _pModel [in] A raw pointer to a object to validate. */ ValidationContext(OdDAI::Model* _pModel) : pModel(_pModel) {} /** \details Destroys the validation context object. */ virtual ~ValidationContext() {}; public: /**A raw pointer to the object to be validated.*/ OdDAI::Model* pModel; friend class InstanceValidationContext; }; /** \details A data type that represents a shared pointer to an object. */ typedef OdSharedPtr ValidationContextPtr; /** \details A class that stores and handles the context information for and extents validation check. */ class InstanceValidationContext : public ValidationContext { public: /**A raw pointer to the object to be validated.*/ OdDAI::ApplicationInstance* pInstance; /**A raw pointer to the object to be validated.*/ OdStepFile* pFile; /** \details Creates a new validation context instance with default parameters. */ InstanceValidationContext() : ValidationContext(nullptr) , pInstance(nullptr) , pFile(nullptr) {} /** \details Creates a new validation context instance for a specified , and . \param _model [in] A raw pointer to an object. \param _pInstance [in] A raw pointer to an object. \param _pFile [in] A raw pointer to an object. */ InstanceValidationContext(OdDAI::Model *_model, OdDAI::ApplicationInstance* _pInstance = nullptr, OdStepFile* _pFile = nullptr) : ValidationContext(_model) , pInstance(_pInstance) , pFile(_pFile) {} }; /** \details A data type that represents a shared pointer to an object. */ typedef OdSharedPtr InstanceValidationContextPtr; /** \details An abstract class that provides an interface for validation tasks. */ class DAI_EXPORT ValidationTask : public OdRxObject { //DOM-IGNORE-BEGIN ODRX_DECLARE_MEMBERS(ValidationTask); //DOM-IGNORE-END public: /** \details The base structure that stores and handles information about objects that failed the validation check and (or) about constraints that were violated. */ struct InvalidValidationParamsBase { /** \details Destroys the storage with information about unsuccessful validation check results. */ virtual ~InvalidValidationParamsBase() {}; /** \details Retrieves the number of items that didn't pass the validation. \returns An integer value that contains the number of invalid items in the structure instance. */ virtual int invalidItemsCount() = 0; }; /** \details A structure that encapsulates storing and handling information about that failed the validation check and Where-Rules constraints which these attributes violates. */ struct InvalidValidationParams : InvalidValidationParamsBase { /**An array of raw pointers to instances that violates constraints.*/ OdArray invalidAttributes; /**An array of raw pointers to Where-Rule constraints that were violated.*/ OdArray invalidWhereRules; /** \details Retrieves the number of invalid stored in the structure instance. \returns An integer value that represents the number of invalid stored in the structure instance. */ virtual int invalidItemsCount() override { return invalidAttributes.size(); } }; /** \details A structure that stores references to that failed the validation check while containing attributes and Where-Rules which coursed this failure. */ struct InvalidRulesValidationParams : InvalidValidationParams { /**A pointer to the object.*/ OdDAI::ApplicationInstancePtr invalidInst; }; /** \details A structure that stores references to and that didn't pass the validation check and text that contains additional information about validation problems. */ struct InvalidInstanceValidationParams : InvalidValidationParamsBase { /** \details An auxiliary structure that stores information about and its that failed the validation and additional text data about related to violate constraints. */ struct InvalidParams { /**A pointer to the object.*/ OdDAI::ApplicationInstance* invalidInstance; /**A pointer to the object.*/ OdDAI::Attribute* invalidAttribute; /**An ANSI string that contains additional validation information.*/ OdAnsiString instruction; }; /**An array of pointers to instances to store the information about instances and attributes which violate constraints.*/ OdArray invalidParams; /** \details Adds a new item into the array with validation information. \param inst [in] A pointer to the object. \param attr [in] A pointer to the object. \param instr [in] An ANSI string that contains additional validation information. */ void addData(OdDAI::ApplicationInstance* inst, OdDAI::Attribute* attr, const OdAnsiString& instr) { invalidParams.push_back(InvalidParams({ inst, attr, instr })); } /** \details Retrieves the number of items in the array with validation information. \returns An integer value that contains the number of elements in the validation information array. */ virtual int invalidItemsCount() override { return invalidParams.size(); } }; /** \details A structure that contains an array of pointers to OdRxObject instances that store information about constraints violation. */ struct InvalidRxObjectsValidationParams : InvalidValidationParamsBase { /**An array of smart pointer to OdRxObject instances that contain references to objects, constraints, data type values or some other validation related information like that.*/ OdRxObjectPtrArray invalidObjects; /**An ANSI string that contains additional text information about constraint violation.*/ OdAnsiString textMessage; /**The of the constraints check.*/ OdDAI::Logical validationResult; /** \details Creates a new instance with information related to the validation results. \param objects [in] An initializer list with smart pointers to objects that violate constraints. \param message [in] An ANSI string with additional text information about objects which violate constraints or about the validation task status. \param result [in] The of the validation. */ InvalidRxObjectsValidationParams(std::initializer_list objects, const OdAnsiString& message, OdDAI::Logical result) :textMessage(message), validationResult(result) { invalidObjects.reserve((unsigned int)objects.size()); for (auto obj : objects) invalidObjects.push_back(obj); } /** \details Retrieves the number of objects that violate constraints. \returns An integer value that contains the number of invalid objects. */ virtual int invalidItemsCount() override { return invalidObjects.size(); } }; /** \details A structure that stores an array with information about results of several validation checks. */ struct InvalidRxArrayValidationParams : InvalidValidationParamsBase { /**An array of validation results.*/ OdArray invalidParams; /** \details Adds new item to the array of validation results. \param invalidObjects [in] An item with validation result to be added. */ void addData(const InvalidRxObjectsValidationParams& invalidObjects) { invalidParams.push_back(invalidObjects); } /** \details Retrieves the number of item in the array of validation results. \returns An integer value that contains the number of items in the array of validation results. */ virtual int invalidItemsCount() override { return invalidParams.size(); } }; /** \details A structure that stores an with of objects which failed the constraints check. */ struct InvalidObjectIdsValidationParams : InvalidValidationParamsBase { /**An array of object .*/ OdDAIObjectIds invalidObjects; /** Smart pointer to a object that has created this structure.*/ ValidationTaskPtr parentTask; /** \details Creates a new structure instance with default parameters. */ InvalidObjectIdsValidationParams() {} /** \details Creates a new structure instance with a specified . \param _invalidObjects [in] An array of object identifiers. */ InvalidObjectIdsValidationParams(OdDAIObjectIds _invalidObjects) : invalidObjects(_invalidObjects) {} /** \details Adds a new invalid into the array. \param id [in] An invalid to be added. */ void addData(OdDAIObjectId id) { invalidObjects.push_back(id); } /** \details Assigns parent task object that has created this structure. \param validationTask [in] smart pointer to a object to be added. */ void setValidationTask(ValidationTaskPtr validationTask) { parentTask = validationTask; } /** \details Retrieves the number of invalid . \returns An integer value that contains the number of invalid . */ virtual int invalidItemsCount() override { return invalidObjects.size(); } }; /** \details Creates a new validation task object with default parameters. */ ValidationTask(); /** \details Destroys the validation task object. */ virtual ~ValidationTask(); /** \details Initializes the validation task. This method is called by the validator object before the validation starts. Virtual function which is called by Validator before validation process starts. \param validationContext [in] A raw pointer to the object. \param pServices [in] A raw pointer to an appropriate instance of the class. \param invalidParams [out] A shared pointer to an object. After the method execution this object contains the list of model's instances that violate constraints. \returns * if the validation initialization is successful (default return value). * if the validation initialization failed. * in other cases. */ virtual OdDAI::Logical initializeValidation(OdDAI::ValidationContext* validationContext, OdDAIHostAppServicesBase* pServices, OdSharedPtr& invalidParams); /** \details Stops the validation task. This method is called by the validator object after the validation ends. \param invalidParams [out] A shared pointer to an object. After the method execution this object contains the list of model's instances that violate constraints. \returns * if the validation finalization is successful (default return value). * if the validation finalization failed. * in other cases. */ virtual OdDAI::Logical finishValidation(OdSharedPtr& invalidParams); /** \details Retrieves the description of the validation task. \returns An ANSI string that contains the description of the validation task. */ virtual OdAnsiString description() const = 0; /** \details Retrieves additional information about the validation task (like date, author, copyright, version, etc). \returns A raw pointer to an STL Map object that contains additional information. Each element in this map consists of a pair "Name" — "Description" that contains name and description of the data element respectively. */ virtual const std::map* additionalInformation() const; /** \details Retrieves the current value of the healing flag. When this flag equals to true, the validation task object tries to heal found validation errors (if the object has an appropriated healer class). \returns true if the healing of the validation errors is enabled; otherwise, the method returns false. */ bool isHealingEnable(); /** \details Sets a new value of the healing flag. When this flag equals to true, the validation task object tries to heal found validation errors (if the object has an appropriated healer class). Otherwise, this flag equals to false. \param healingEnable [in] A new value of the flag. */ void setHealingEnable(bool healingEnable); //DOM-IGNORE-BEGIN //static void rxInit(ValidationTasksHolder& tasksHolder); //static void rxUninit(ValidationTasksHolder& tasksHolder); //DOM-IGNORE-END protected: bool m_healingEnable; }; /** \details A data type that represents a smart pointer to a object. */ typedef OdSmartPtr ValidationTaskPtr; } #include "TD_PackPop.h" #endif //_DAI_VALIDATION_TASK_H