/////////////////////////////////////////////////////////////////////////////// // 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 "DbAssocArrayModifyActionBody.h" #include "DbBlockReference.h" #include "DbBlockTableRecord.h" #include "DbBlockTable.h" #include "DbAssocDependency.h" #include "DbAssocGeomDependency.h" #include "DbLinetypeTable.h" #include "DbImpAssocMLeaderActionBody.h" #include "DbImpAssocRotatedDimActionBody.h" #include "DbObjectId.h" #include "DbAssocNetwork.h" //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// OdDbImpAssocMLeaderActionBody::OdDbImpAssocMLeaderActionBody() { // CORE-14828 m_version = 0; m_leaderLineIndex2OSnapPointRefParamId[0] = OdDbObjectId::kNull; // m_ActionBodyType = kMleader; m_paramBasedActionBody = new OdDbImpAssocParamBasedActionBody(true); } OdDbImpAssocMLeaderActionBody::~OdDbImpAssocMLeaderActionBody() { } OdResult OdDbImpAssocMLeaderActionBody::dwgInFields(OdDbDwgFiler* pFiler) { OdResult res = OdDbImpAssocAnnotationActionBody::dwgInFields(pFiler); if (res != eOk) return res; m_version = pFiler->rdInt16(); ODA_ASSERT_ONCE_X(MDSO, !m_version); // CORE-14828 OdUInt32 mapSize = pFiler->rdInt32(); ODA_ASSERT_ONCE_X(MDSO, mapSize); for (OdUInt32 idx = 0; idx < mapSize; idx++) { OdUInt32 index = pFiler->rdInt32(); m_leaderLineIndex2OSnapPointRefParamId[index] = pFiler->rdSoftPointerId(); } return res; } void OdDbImpAssocMLeaderActionBody::dwgOutFields(OdDbDwgFiler* pFiler) const { OdDbImpAssocAnnotationActionBody::dwgOutFields(pFiler); //m_paramBasedActionBody->dwgOutFields(pFiler); ODA_ASSERT_ONCE_X(MDSO, !m_version); pFiler->wrInt16(m_version); // CORE-14828 pFiler->wrInt32(OdUInt32(m_leaderLineIndex2OSnapPointRefParamId.size())); for (const auto& item : m_leaderLineIndex2OSnapPointRefParamId) { pFiler->wrInt32(item.first); pFiler->wrSoftPointerId(item.second); } } OdResult OdDbImpAssocMLeaderActionBody::dxfInFields(OdDbDxfFiler* pFiler) { OdResult res = OdDbImpAssocAnnotationActionBody::dxfInFields(pFiler); if (res != eOk) return res; if (!pFiler->atSubclassData(OdDbAssocMLeaderActionBody::desc()->dxfName())) { ODA_FAIL_ONCE(); return eMakeMeProxy; } NEXT_CODE(90); m_version = OdUInt16(pFiler->rdUInt32()); ODA_ASSERT_ONCE_X(MDSO, !m_version); // CORE-14828 NEXT_CODE(90); OdUInt32 mapSize = pFiler->rdUInt32(); for (OdUInt32 idx = 0; idx < mapSize; idx++) { NEXT_CODE(90); OdUInt32 index = pFiler->rdInt32(); NEXT_CODE(330); m_leaderLineIndex2OSnapPointRefParamId[index] = pFiler->rdObjectId(); } return eOk; } void OdDbImpAssocMLeaderActionBody::dxfOutFields(OdDbDxfFiler* pFiler) const { OdDbImpAssocAnnotationActionBody::dxfOutFields(pFiler); pFiler->wrSubclassMarker(OdDbAssocMLeaderActionBody::desc()->dxfName()); ODA_ASSERT_ONCE_X(MDSO, !m_version); pFiler->wrUInt32(90, m_version); // CORE-14828 pFiler->wrUInt32(90, OdUInt32(m_leaderLineIndex2OSnapPointRefParamId.size())); for (const auto& item : m_leaderLineIndex2OSnapPointRefParamId) { pFiler->wrUInt32(90, item.first); pFiler->wrObjectId(330, item.second); } } OdDbObjectId OdDbImpAssocMLeaderActionBody::leaderPointRefActionParam(int index) const { auto it = m_leaderLineIndex2OSnapPointRefParamId.find(index); if (it != m_leaderLineIndex2OSnapPointRefParamId.end()) return it->second; return OdDbObjectId::kNull; } OdResult OdDbImpAssocMLeaderActionBody::setLeaderPointRefActionParam(int index, OdDbObjectId pointRefActionParamId) { m_leaderLineIndex2OSnapPointRefParamId[index] = pointRefActionParamId; return eOk; } //void OdDbImpAssocMLeaderActionBody::composeForLoad(OdDbObject *pObject, // OdDb::SaveType format, // OdDb::DwgVersion version, // OdDbAuditInfo* pAuditInfo) //{ // OdDbAssocRotatedDimActionBody *Body = static_cast(pObject); // //m_matrix = OdDbBlockReference::cast(getArrayEntity(Body->parentAction()).safeOpenObject())->blockTransform(); //} void OdDbImpAssocMLeaderActionBody::evaluateOverride(OdDbObjectId parentActionId) { OdResult res = eOk; OdDbAssocActionPtr action = OdDbAssocAction::cast(parentActionId.openObject(OdDb::kForWrite)); OdDbAssocDependencyPtr dimDep = m_annotationEntDepId.openObject(); if (dimDep.isNull()) { res = action->setStatus(kErasedAssocStatus); return; } OdDbMLeaderPtr mLeader = dimDep->dependentOnObject().openObject(OdDb::kForWrite); OdUInt32 numParams = action->paramCount(); if (mLeader.isNull() || numParams == 0) { res = action->setStatus(kErasedAssocStatus); return; } bool dimModified = isEvaluationRequest(dimDep->status()); // dim modified, check associativity for (const auto& item : m_leaderLineIndex2OSnapPointRefParamId) { OdDbAssocOsnapPointRefActionParamPtr osnapPointRefParam = item.second.openObject(); if (osnapPointRefParam.get()) { OdDbOsnapPointRefPtr pRefPt = osnapPointRefParam->asOsnapPointRef(); if (isEvaluationRequest(osnapPointRefParam->status(true))) { OdGePoint3d ptVal; osnapPointRefParam->evaluatePointOverride(ptVal); //res = pRefPt->evalPoint(ptVal); if (dimModified) { OdGePoint3d leaderPt; mLeader->getVertex(item.first, 0, leaderPt); if (!leaderPt.isEqualTo(ptVal)) { res = breakAssociativity(action, dimDep); res = mLeader->removeLeaderLineRefAssoc(item.first); } continue; } res = mLeader->setVertex(item.first, 0, ptVal); } } } res = action->evaluateDependencies(); res = action->setStatus(kIsUpToDateAssocStatus); } OdResult OdDbImpAssocMLeaderActionBody::createInstance( const OdDbFullSubentPathArray &entPathArray, const OdDbObjectId bodyId, OdGePoint3dArray &ptsSelected, const OdString mText, OdDbObjectId& actionBodyId) { OdResult res = eOk; OdDbDatabase *pDb = NULL; OdDbObjectIdArray pathArray = entPathArray[0].objectIds(); if (pathArray.length() < 1) return eInvalidInput; OdDbFullSubentPath pathDep0(pathArray, entPathArray[0].subentId()); if ( bodyId.isNull() ) return eInvalidInput; OdDbObjectPtr ptObj1; OdDbSmartCenterActionBodyPtr smartObj1; if (!bodyId.isNull()) { ptObj1 = bodyId.openObject(); smartObj1 = OdDbSmartCenterActionBody::cast(ptObj1); } if ( smartObj1.isNull() ) return eInvalidInput; OdDbObjectId ownerBTRId; if (!bodyId.isNull()) { pDb = bodyId.database(); ownerBTRId = bodyId.openObject()->ownerId(); if (!smartObj1.isNull()) { ownerBTRId = ownerBTRId.openObject()->ownerId(); ownerBTRId = ownerBTRId.openObject()->ownerId(); ownerBTRId = ownerBTRId.openObject()->ownerId(); ownerBTRId = ownerBTRId.openObject()->ownerId(); } } OdDbBlockTableRecordPtr pOwnerSpace = ownerBTRId.safeOpenObject(OdDb::kForWrite); OdDbObjectId networkId = OdDbAssocNetwork::getInstanceFromObject(pOwnerSpace->objectId(), true); //create action and action body //BEGIN OdString pClassName = OD_T("AcDbAssocMLeaderActionBody"); OdRxClass* pClass; pClass = (OdRxClass*)odrxClassDictionary()->getAt(pClassName).get(); OdDbObjectId actionId; if (eOk != createActionAndActionBodyAndPostToDatabase(pClass, networkId, actionId, actionBodyId)) { return eInvalidInput; } OdDbAssocMLeaderActionBodyPtr pActionBody = OdDbAssocMLeaderActionBody::cast(actionBodyId.openObject(OdDb::kForWrite)); ODA_ASSERT(!pActionBody.isNull()); OdDbAssocActionPtr pAction = OdDbAssocAction::cast(actionId.openObject(OdDb::kForWrite)); pAction->setActionBody(actionBodyId); /**********************************************************************/ /* Create an rotated dimension and dimension the ends of the line */ /**********************************************************************/ pClassName = OD_T("AcDbMLeader"); pClass = (OdRxClass*)odrxClassDictionary()->getAt(pClassName).get(); OdDbMLeaderPtr pDimension = OdDbMLeader::cast(pClass->create()); /**********************************************************************/ /* Add the DimStyle */ /**********************************************************************/ //OdDbObjectId odaDimStyleId = pDb->getDimStyleStandardId(); //OdDbObjectId spaceId = ExCommandsUtils::activeBlockTableRecord(pDb); //OdDbBlockTableRecordPtr pSpace = spaceId.safeOpenObject(OdDb::kForWrite); if (!pDimension.isNull()) { int llIndex; pDimension->setDatabaseDefaults(pDb); pOwnerSpace->appendOdDbEntity(pDimension); OdDbMTextPtr pMText = OdDbMText::createObject(); pMText->setDatabaseDefaults(pDb); pDimension->setEnableFrameText(true); pMText->setContents(mText); pMText->setLocation(ptsSelected[1]); pDimension->setMText(pMText); pDimension->addLeaderLine(ptsSelected[0], llIndex); } OdDbObjectId anchorId; PointPositionOnBlockLine isStartPoint1 = kUndefined; OdDbAssocGeomDependencyPtr pGeomDependency1, pGeomDependency2, pGeomDependency3, pGeomDependency4; if (!bodyId.isNull()) { CreateGeomDependencies(pathDep0, actionId, bodyId, pGeomDependency1, pGeomDependency2, isStartPoint1); } OdDbObjectId snapParamID1; OdDbAssocDependencyPtr pDependency = OdDbAssocDependency::createObject(); pDb->addOdDbObject(pDependency); pDependency->setIsReadDependency(true); pDependency->setIsWriteDependency(true); OdDbCompoundObjectId compoundObjectId; compoundObjectId.set(pDimension->objectId()); pDependency->attachToObject(compoundObjectId); pAction->addDependency(pDependency->objectId(), true); pActionBody->setAnnotationEntDepId(pDependency->objectId()); if (!bodyId.isNull()) { snapParamID1 = createOdDbAssocOSnapPointRefActionParam(actionId, bodyId, ptsSelected[0], pGeomDependency1, pGeomDependency2, anchorId, isStartPoint1, 0); pActionBody->setLeaderPointRefActionParam(0, snapParamID1); } return res; }