/////////////////////////////////////////////////////////////////////////////// // 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 DbImpAssocVariable_INCLUDED_ #define DbImpAssocVariable_INCLUDED_ /*!DOM*/ #include"DbImpAssocAction.h" #include "DbAssocVariable.h" #include "DbEvalVariant.h" #include "BoolArray.h" #include "Int16Array.h" #include "TD_PackPush.h" /** \details This class represents the custom implementation of the variable which stores a scalar value of following types: double, int, or string. Library: Source code provided. */ class DBCONSTRAINTS_EXPORT OdDbImpAssocVariable : public OdDbImpAssocAction { public: /** \details Constructor creates an instance of this class. */ OdDbImpAssocVariable(); /** \details Destructor destroys an instance of this class. */ virtual ~OdDbImpAssocVariable(); /** \details Returns the variable name as an arbitrary string. */ const OdString name() const; /** \details Returns the expression as an arbitrary string or an empty string if the variable is a constant. */ const OdString expression() const; /** \details Returns the evaluated value of the variable. */ const OdDbEvalVariantPtr value() const; /** \details Returns the variable description as an arbitrary string. */ const OdString description() const; /** \details Evaluates this variable for an action. */ virtual void evaluate(OdDbAssocAction* pAction, OdDbAssocEvaluationCallback* pEvaluationCallback); /** \details Sets the name for this variable using a given string. */ OdResult setName(OdDbAssocVariable* pVariable, const OdString& newName, bool updateReferencingExpressions); /** \details Sets the constant value for this variable. */ OdResult fixVariable(const OdString& name, const OdDbEvalVariant* value); /** \details Renames the variable. */ OdResult renameVariable(const OdString& oldName, const OdString& newName); /** \details Checks the cyclic dependencies for specified names and reactors. */ static OdResult checkCyclicDependencies(OdArray& names, OdDbObjectIdArray& reactors); /** \details Creating a shallow copy of the variable which is not connected to anything but has same name, expression, etc. */ static OdDbAssocVariablePtr createVariableCopy(const OdDbAssocVariable* originalVar); /** \details Searches the object using its name and returns an object ID if the object is found or kNull if the object is not found. */ OdDbObjectId findObjectByName(const OdString& objectName, const OdRxClass* pObjectClass) const; /** \details Validates the given name, expression or both, to check whether they can be used for this variable. */ OdResult validateNameAndExpression(const OdDbAssocVariable* pThis, const OdString& nameToValidate, const OdString& expressionToValidate, OdString* errorMessage = 0) const; /** \details Sets the expression as a string and syntactically checks it. */ OdResult setExpression(OdDbAssocVariable* pVariable, const OdString& newExpression, const OdString& evaluatorId, bool checkForCyclicalDependencies, bool updateDependenciesOnReferencedSymbols, OdString* errorMessage = 0, bool silentMode = false); /** \details Returns the ID of the expression evaluator for parsing the expression. */ const OdString evaluatorId() const; /** \details Sets the given ID of the expression evaluator to be used for parsing the expression. An empty string sets the default evaluator. */ OdResult setEvaluatorId(const OdString evalId); /** \details Sets the evaluated value. If the expression is not empty, this value will be overwritten and the expression will be evaluated. */ OdResult setValue(OdDbAssocAction* pAction, const OdDbEvalVariant& newValue); /** \details Sets the description for this variable as a string value. */ OdResult setDescription(const OdString newDescription); /** \details For internal use. */ bool isMergeable () const; /** \details For internal use. */ bool mustMerge () const; /** \details For internal use. */ OdString mergeableVariableName() const; /** \details For internal use. */ void setIsMergeable(bool isMerg, bool mustMerg = false, const OdString& mergeableVariableName = OdString::kEmpty); /** \details Evaluates the expression without modifying the variable. \param evaluatedExpressionValue [out] result of evaluation. \param errorMessage [out] optional pointer to string that contains error description if the function failed. */ OdResult evaluateExpression(const OdDbAssocVariable* pThis, OdDbEvalVariant* evaluatedExpressionValue, OdString* errorMessage = 0) const; /** \details Evaluates the expression without modifying the variable using explicitly providing values of the referenced value-providing objects. \param objectIds [in/out] value-providing objects ids. May be empty on input. \param objectValues [in/out] values of value-providing objects. May be empty on input. \param evaluatedExpressionValue [out] result of evaluation. \param errorMessage [out] optional pointer to string that contains error description if the function failed. \remarks The expression is evaluated using the provided values of the referenced objects. The objectIds array is an array of ids of value-providing objects (such as OdDbAssocVariables) and objectValues is an array of provided values of these objects. These arrays have the same lengths. If id of this variable is already in objectIds array, then the corresponding value from objectValues is returned. Otherwise the expression of this variable is evaluated, the variable id is added to objectIds array and value is added to objectValues array so the same variable not evaluated again during the expression evaluation. This function is recursively called for every symbol referenced by the expression. */ OdResult evaluateExpression(const OdDbAssocVariable* pThis, OdDbObjectIdArray& objectIds, OdArray& objectValues, OdDbEvalVariant* evaluatedExpressionValue, OdString* errorMessage = 0) const; /** \details Reads the .dwg file data of this object. \param pFiler [in] Filer object from which data are read. \remarks Returns the filer status. */ OdResult dwgInFields(OdDbAssocAction *self, OdDbDwgFiler* filer); /** \details Writes the .dwg file data of this object. \param pFiler [in] Pointer to the filer to which data are written. */ void dwgOutFields(OdDbDwgFiler* pFiler, OdDbObjectId objectId) const; /** \details Reads the .dxf file data of this object. \param pFiler [in] Filer object from which data are read. \remarks Returns the filer status. */ OdResult dxfInFields(OdDbDxfFiler* pFiler, OdDbObjectId objectId); /** \details Writes the .dxf file data of this object. \param pFiler [in] Pointer to the filer to which data are written. */ void dxfOutFields(OdDbDxfFiler* pFiler, OdDbObjectId objectId) const; virtual OdResult postProcessAfterDeepClone(OdDbAssocAction *pAction, OdDbIdMapping& idMap); virtual bool isRelevantDependencyChange(const OdDbAssocDependency* pDependency) const; protected: /*!DOM*/ OdResult checkForCyclicalDependencies(const OdDbAssocVariable *pThis, const OdString& newExpr, bool &bCyclicalDependenciesFound, OdString* errorMessage = 0) const; /*!DOM*/ OdString m_varName; /*!DOM*/ OdString m_expression; /*!DOM*/ OdString m_description; /*!DOM*/ OdString m_evaluatorId; /*!DOM*/ OdBool m_isMergeable; /*!DOM*/ OdBool m_mustMerge; /*!DOM*/ OdString m_mergeableVariableName; /*!DOM*/ OdDbEvalVariantPtr m_value; /*!DOM*/ OdInt16Array m_arrValueDependenciesIdx; }; #include "TD_PackPop.h" #endif