/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// #include "OdaCommon.h" #include "DbAssocActionBody.h" #include "DbImpAssocActionBody.h" #include "DbAssocGeomDependency.h" #include "DbAssocValueDependency.h" ODRX_NO_CONS_DEFINE_MEMBERS_ALTNAME(OdDbAssocActionBody, OdDbObject, L"AcDbAssocActionBody"); OdDbAssocActionBody::OdDbAssocActionBody() : OdDbObject() , m_pImpObj(NULL) { } OdDbAssocActionBody::~OdDbAssocActionBody() { if (m_pImpObj) { delete m_pImpObj; m_pImpObj = NULL; } } OdDbAssocStatus OdDbAssocActionBody::status() const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject(); return pAction->status(); } OdResult OdDbAssocActionBody::setStatus(OdDbAssocStatus newStatus, bool notifyOwningNetwork, bool setInOwnedActions) { OdDbObjectPtr parentObject; OdResult res = parentAction().openObject(parentObject, OdDb::kForWrite); if(res!=eOk) return res; OdDbAssocActionPtr parentAction = OdDbAssocAction::cast(parentObject); if(parentAction.get()) return parentAction->setStatus(newStatus, notifyOwningNetwork, setInOwnedActions); return eNotThatKindOfClass; } OdDbObjectId OdDbAssocActionBody::owningNetwork() const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject(); return pAction->owningNetwork(); } OdResult OdDbAssocActionBody::getDependencies(bool readDependenciesWanted, bool writeDependenciesWanted, OdDbObjectIdArray& dependencyIds) const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject(); return pAction->getDependencies(readDependenciesWanted, writeDependenciesWanted, dependencyIds); } OdResult OdDbAssocActionBody::addDependency(const OdDbObjectId& dependencyId, bool setThisActionAsOwningAction) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->addDependency( dependencyId, setThisActionAsOwningAction ); } OdResult OdDbAssocActionBody::addDependency(OdRxClass* pDependencyClass, OdRxClass* pDependencyBodyClass, bool isReadDep, bool isWriteDep, int order, OdDbObjectId& dependencyId) { assertWriteEnabled(true, false); OdDbAssocActionPtr pAction = parentAction().openObject(OdDb::kForWrite); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNotInitializedYet; } return pAction->addDependency(pDependencyClass, pDependencyBodyClass, isReadDep, isWriteDep, order, dependencyId); } OdResult OdDbAssocActionBody::removeDependency(const OdDbObjectId& dependencyId, bool alsoEraseIt) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->removeDependency( dependencyId, alsoEraseIt ); } OdResult OdDbAssocActionBody::removeAllDependencies(bool alsoEraseThem) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->removeAllDependencies( alsoEraseThem ); } OdResult OdDbAssocActionBody::evaluateDependencies() { return OdDbAssocActionPtr( parentAction().safeOpenObject( OdDb::kForWrite ) ) ->evaluateDependencies(); } bool OdDbAssocActionBody::hasAnyErasedOrBrokenDependencies() const { OdDbObjectIdArray dependencyIds; OdResult res = OdDbAssocActionBody::getDependencies(true, true, dependencyIds); if (res == eOk) { for (auto depId : dependencyIds) { if (depId.objectClass()->isDerivedFrom(OdDbAssocValueDependency::desc())) continue; OdDbAssocDependencyPtr dep = depId.openObject(); if (dep.isNull()) return true; if (dep->status()==kErasedAssocStatus) return true; OdDbCompoundObjectId compId; if (dep->getDependentOnCompoundObject(compId)!=eOk || compId.isEmpty() || compId.leafId().openObject().isNull()) return true; } } return false; } bool OdDbAssocActionBody::isActionEvaluationInProgress() const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForRead ); return pAction->isActionEvaluationInProgress(); } OdDbAssocEvaluationCallback* OdDbAssocActionBody::currentEvaluationCallback() const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.get()) return pAction->currentEvaluationCallback(); return NULL; } OdResult OdDbAssocActionBody::dependentObjectClonedOverride( const OdDbAssocDependency* dependency, const OdDbObject* original, const OdDbObject* clone) { assertReadEnabled(); if (!m_pImpObj) return eNotImplemented; return m_pImpObj->dependentObjectClonedOverride(this, dependency, original, clone); } OdResult OdDbAssocActionBody::addMoreObjectsToDeepCloneOverride( OdDbIdMapping& idMap, OdDbObjectIdArray& additionalObjectsToClone) const { assertReadEnabled(); if (!m_pImpObj) return eNotImplemented; return m_pImpObj->addMoreObjectsToDeepCloneOverride(this, idMap, additionalObjectsToClone); } OdResult OdDbAssocActionBody::dwgInFields(OdDbDwgFiler* pFiler) { ODA_ASSERT_ONCE(m_pImpObj); if (!m_pImpObj) return eMakeMeProxy; OdResult res = OdDbObject::dwgInFields(pFiler); if (res != eOk) return res; return m_pImpObj->dwgInFields(pFiler); } void OdDbAssocActionBody::auditAssociativeDataOverride(OdDbAssocStatus& parentActionHandling) { m_pImpObj->auditAssociativeDataOverride(this, parentActionHandling); } void OdDbAssocActionBody::collectPersSubentNamingDataOverride(OdDbPersStepIdArray& stepIds, OdDbPersSubentIdArray& subentIds) const { m_pImpObj->collectPersSubentNamingDataOverride(this, stepIds, subentIds); } void OdDbAssocActionBody::clonePersSubentNamingDataOverride(OdDbAssocPersSubentManagerCloner* apsmc) { m_pImpObj->clonePersSubentNamingDataOverride(this, apsmc); } void OdDbAssocActionBody::composeForLoad(OdDb::SaveType format, OdDb::DwgVersion version, OdDbAuditInfo* pAuditInfo) { OdDbObject::composeForLoad(format, version, pAuditInfo); m_pImpObj->composeForLoad(this, format, version, pAuditInfo); } void OdDbAssocActionBody::dwgOutFields(OdDbDwgFiler* pFiler) const { ODA_ASSERT_ONCE(m_pImpObj); if (!m_pImpObj) throw OdError(eNotImplementedYet); OdDbObject::dwgOutFields(pFiler); m_pImpObj->dwgOutFields(pFiler); } OdResult OdDbAssocActionBody::dxfInFields(OdDbDxfFiler* pFiler) { ODA_ASSERT_ONCE(m_pImpObj); if (!m_pImpObj) return eMakeMeProxy; OdResult res = OdDbObject::dxfInFields(pFiler); if (res != eOk) return res; return m_pImpObj->dxfInFields(pFiler); } void OdDbAssocActionBody::dxfOutFields(OdDbDxfFiler* pFiler) const { ODA_ASSERT_ONCE(m_pImpObj); if (!m_pImpObj) throw OdError(eNotImplementedYet); OdDbObject::dxfOutFields(pFiler); m_pImpObj->dxfOutFields(pFiler); } OdResult OdDbAssocActionBody::setValueParam( const OdString& paramName, const OdDbEvalVariant& value, const OdString& expression, const OdString& evaluatorId, OdString& errorMessage, bool silentMode, int valueIndex ) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->setValueParam( paramName, value, expression, evaluatorId, errorMessage, silentMode, valueIndex); } OdResult OdDbAssocActionBody::getValueParam( const OdString& paramName, OdDbEvalVariant& value, OdString& expression, OdString& evaluatorId, int valueIndex ) const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForRead ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->getValueParam(paramName, value, expression, evaluatorId, valueIndex); } OdDbObjectId OdDbAssocActionBody::paramAtName( const OdString& paramName, int index /*= 0*/ ) const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForRead ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return OdDbObjectId(); } return pAction->paramAtName( paramName, index ); } OdValue::UnitType OdDbAssocActionBody::valueParamUnitType( const OdString& paramName ) const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForRead ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return OdValue::kUnitless; } return pAction->valueParamUnitType( paramName ); } OdResult OdDbAssocActionBody::setValueParamUnitType( const OdString& paramName, OdValue::UnitType unitType ) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->setValueParamUnitType( paramName, unitType ); } OdResult OdDbAssocActionBody::getValueParamArray(const OdString& paramName, OdArray& values, OdArray& expressions, OdArray& evaluatorIds) const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.isNull()) return eNotInitializedYet; return pAction->getValueParamArray(paramName, values, expressions, evaluatorIds); } OdResult OdDbAssocActionBody::setValueParamArray(const OdString& paramName, const OdArray& values, const OdStringArray& expressions, const OdStringArray& evaluatorIds, OdStringArray& errorMessages, bool silentMode) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject(OdDb::kForWrite); if (pAction.isNull()) return eNotInitializedYet; return pAction->setValueParamArray(paramName, values, expressions, evaluatorIds, errorMessages, silentMode); } OdResult OdDbAssocActionBody::addParam( const OdString& paramName, OdRxClass* pParamClass, OdDbObjectId& paramId, int& paramIndex ) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForWrite ); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->addParam( paramName, pParamClass, paramId, paramIndex ); } OdResult OdDbAssocActionBody::addParam(const OdDbObjectId& paramId, int& paramIndex) { assertWriteEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject(OdDb::kForWrite); if (pAction.isNull()) { ODA_FAIL_ONCE(); return eNullPtr; } return pAction->addParam(paramId, paramIndex); } void OdDbAssocActionBody::ownedValueParamNames( OdStringArray& paramNames ) const { assertReadEnabled(); OdDbAssocActionPtr pAction = parentAction().openObject( OdDb::kForRead ); pAction->ownedValueParamNames( paramNames ); } OdResult OdDbAssocActionBody::createActionAndActionBodyAndPostToDatabase( OdRxClass* pActionBodyClass, const OdDbObjectId& objectId, OdDbObjectId& createdActionId, OdDbObjectId& createdActionBodyId ) { return OdDbImpAssocActionBody::createActionAndActionBodyAndPostToDatabase(pActionBodyClass, objectId, createdActionId, createdActionBodyId); } OdStringArray OdDbAssocActionBody::compareWith(const OdDbObjectId bodyIDToCompare, OdDb::DwgVersion /*filerVersion*/ /*OdDb::kDHL_CURRENT*/) const { OdStringArray retArray; OdDbAssocActionBodyPtr comparedBodyPtr = OdDbAssocActionBody::cast(bodyIDToCompare.openObject()); if (comparedBodyPtr.isNull()) { retArray.append(CS_OBJECT_ERROR); return retArray; } OdDbImpAssocActionBody* pImpObjCompared = static_cast(comparedBodyPtr->m_pImpObj); return static_cast (m_pImpObj)->compareWith(pImpObjCompared); } OdResult OdDbAssocActionBody::getActionBodiesOnObject(const OdDbObject* pObj, bool /*bIgnoreInternalActions*/, bool bIgnoreSuppressedActions, OdDbObjectId* pWriteOnlyActionBodyId, OdDbObjectIdArray* pReadWriteActionBodyIds, OdDbObjectIdArray* pReadOnlyActionBodyIds) { if (!pObj) { return eNullObjectPointer; } if (pWriteOnlyActionBodyId) { *pWriteOnlyActionBodyId = NULL; } if (pReadWriteActionBodyIds) { pReadWriteActionBodyIds->clear(); } if (pReadOnlyActionBodyIds) { pReadOnlyActionBodyIds->clear(); } OdDbObjectId id = pObj->objectId(); if (id.isErased()) { return eOk; } bool readDependenciesWanted = pReadWriteActionBodyIds || pWriteOnlyActionBodyId; bool writeDependenciesWanted(false); if (pWriteOnlyActionBodyId || pReadWriteActionBodyIds) { writeDependenciesWanted = true; } OdDbObjectIdArray dependencyIds; OdDbAssocDependency::getDependenciesOnObject(pObj, readDependenciesWanted, writeDependenciesWanted, dependencyIds); if (dependencyIds.isEmpty()) { return eOk; } for (OdDbObjectIdArray::size_type i = 0; i < dependencyIds.length(); i++) { OdDbObjectPtr pDepObj = dependencyIds[i].openObject(); if (!pDepObj->isKindOf(OdDbAssocDependency::desc())) { continue; } OdDbAssocDependencyPtr pDep = OdDbAssocDependency::cast(pDepObj); if (bIgnoreSuppressedActions && pDep->status() == kSuppressedAssocStatus) { continue; } OdDbAssocDependencyPtr pAssocDepObj = OdDbAssocDependency::cast(pDepObj); OdDbObjectId assocActionId = pAssocDepObj->ownerId(); if (assocActionId.isErased()) { continue; } OdDbAssocActionPtr pAssocObj = assocActionId.openObject(); OdDbObjectId pAssocObjId; if (!pAssocObj.isNull()) { pAssocObjId = pAssocObj->actionBody(); } if(pAssocObjId.objectClass()->isA()->isDerivedFrom(OdDbAssocActionBody::desc())){ continue; } //TODO: OdDbAssocImpliedSurfaceOrSolidActionBody and OdDbAssocRestoreEntityStateActionBody not implemented //if (bIgnoreInternalActions) //{ // if (pAssocObjId.objectClass()->isA()->isKindOf(OdDbAssocImpliedSurfaceOrSolidActionBody::desc())) { // continue; // } // if (pAssocObjId.objectClass()->isA()->isKindOf(OdDbAssocRestoreEntityStateActionBody::desc())) { // continue; // } //} if (pDep->isReadDependency()) { pDep->isWriteDependency() ? pReadWriteActionBodyIds->append(pAssocObjId) : pReadOnlyActionBodyIds->append(pAssocObjId); } else if (pDep->isWriteDependency()) { *pWriteOnlyActionBodyId = pAssocObjId; } } return eOk; }