/////////////////////////////////////////////////////////////////////////////// // 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 "DbBlockTableRecord.h" #include "DbAssocDependency.h" #include "DbImpAssocRotatedDimActionBody.h" #include "DbObjectId.h" #include "Ge/GeLineSeg3d.h" #include "Ge/GeCircArc3d.h" #include "Ge/Ge.h" #include "DbAssocNetwork.h" #include "DbDimStyleTable.h" #include "DbLine.h" #include "DbSubentId.h" #include #include "DbImpAssocActionParam.h" #include "OdDbAssocPersSubentIdPE.h" #include "ExDimAssoc.h" #include "ShHistory/DbAssocPersSubentManager.h" #include "DbAssocAlignedDimActionBody.h" #if _MSC_VER OD_DISABLE_WARNING(4100) #endif ////////////////////////////////////////////////////////////////////////// OdDbImpAssocAnnotationActionBody::OdDbImpAssocAnnotationActionBody() { m_undefined2 = 0; //m_ActionBodyType = kUnDefined; TODO m_paramBasedActionBody = NULL; } OdDbImpAssocAnnotationActionBody::~OdDbImpAssocAnnotationActionBody() { delete m_paramBasedActionBody; } OdResult OdDbImpAssocAnnotationActionBody::dwgInFields(OdDbDwgFiler* pFiler) { const OdResult res = OdDbImpAssocActionBody::dwgInFields(pFiler); if (res != eOk) return res; if (pFiler->dwgVersion() > OdDb::vAC24) { m_undefined2 = pFiler->rdInt16(); m_annotationEntDepId = pFiler->rdSoftPointerId(); } else if (m_paramBasedActionBody != NULL) { m_paramBasedActionBody->dwgInFields(pFiler); m_arrParams = m_paramBasedActionBody->m_arrParams; m_arrValueParams = m_paramBasedActionBody->m_arrValueParams; m_annotationEntDepId = m_paramBasedActionBody->assocDependencyID(); } return eOk; } void OdDbImpAssocAnnotationActionBody::dwgOutFields(OdDbDwgFiler* pFiler) const { OdDbImpAssocActionBody::dwgOutFields(pFiler); if (pFiler->dwgVersion() > OdDb::vAC24) { pFiler->wrInt16(m_undefined2); pFiler->wrSoftPointerId(m_annotationEntDepId); } else if (m_paramBasedActionBody != NULL) { m_paramBasedActionBody->m_arrParams = m_arrParams; m_paramBasedActionBody->m_arrValueParams = m_arrValueParams; m_paramBasedActionBody->assocDependencyID() = m_annotationEntDepId; m_paramBasedActionBody->dwgOutFields(pFiler); } } OdResult OdDbImpAssocAnnotationActionBody::dxfInFields(OdDbDxfFiler* pFiler) { //OdResult res = OdDbImpAssocActionBody::dxfInFields(pFiler); //if (res != eOk) // return res; if (!pFiler->atSubclassData(OdDbAssocActionBody::desc()->name())) { ODA_FAIL_ONCE(); return eMakeMeProxy; } NEXT_CODE(90) m_version = OdUInt16(pFiler->rdUInt32()); if (m_version != (pFiler->dwgVersion() > OdDb::vAC24 ? 2U : 1U)) { ODA_FAIL_ONCE(); return eMakeMeProxy; } if (pFiler->dwgVersion() > OdDb::vAC24) { NEXT_CODE(90) m_undefined2 = static_cast(pFiler->rdUInt32()); NEXT_CODE(330) m_annotationEntDepId = pFiler->rdObjectId(); } else if (m_paramBasedActionBody != NULL) { //if (pFiler->atSubclassData(OdDbAssocParamBasedActionBody::desc()->name()) && m_paramBasedActionBody != NULL) const OdResult res = m_paramBasedActionBody->dxfInFields(pFiler); if (res != eOk) return res; m_arrParams = m_paramBasedActionBody->m_arrParams; m_arrValueParams = m_paramBasedActionBody->m_arrValueParams; m_annotationEntDepId = m_paramBasedActionBody->assocDependencyID(); } ODA_ASSERT_ONCE(pFiler->atEOF()); // TODO return eOk; } void OdDbImpAssocAnnotationActionBody::dxfOutFields(OdDbDxfFiler* pFiler) const { //OdDbImpAssocActionBody::dxfOutFields(pFiler); pFiler->wrSubclassMarker(OdDbAssocActionBody::desc()->name()); pFiler->wrUInt32(90, pFiler->dwgVersion() > OdDb::vAC24 ? 2 : 1); if (pFiler->dwgVersion() > OdDb::vAC24) { pFiler->wrUInt32(90, m_undefined2); pFiler->wrObjectId(330, m_annotationEntDepId); } else if (m_paramBasedActionBody != NULL) { //pFiler->wrSubclassMarker(OdDbAssocParamBasedActionBody::desc()->name()); m_paramBasedActionBody->m_arrParams = m_arrParams; m_paramBasedActionBody->m_arrValueParams = m_arrValueParams; m_paramBasedActionBody->assocDependencyID() = m_annotationEntDepId; m_paramBasedActionBody->dxfOutFields(pFiler); } } void OdDbImpAssocAnnotationActionBody::evaluateOverride(OdDbObjectId /*parentActionId*/) { //OdDbAssocActionPtr pAction = OdDbAssocAction::cast(parentActionId.safeOpenObject(OdDb::kForWrite)); //OdDbObjectIdArray objIDs; ////Array entity dependency check ////BEGIN //pAction->getDependencies(true, true, objIDs); } OdDbObjectId OdDbImpAssocAnnotationActionBody::getIdForFirstWriteDependency(OdDbObjectIdArray depIDs) { for (unsigned int i = 0; i < depIDs.length(); i++) { OdDbAssocDependencyPtr pDepEntity = depIDs[i].openObject(); if (pDepEntity.isNull()) continue; if (pDepEntity->isWriteDependency()) { return pDepEntity->objectId(); } } ODA_ASSERT_ONCE(!"Entity dep not found"); return OdDbObjectId(); } OdResult OdDbImpAssocAnnotationActionBody::setDataToActionParam(OdGeCurve3d* geometry, OdDbObjectId snapPointParamId, OdGePoint3d& ptPoint, OdGePoint3d ptDimPoint, OdDbObjectId parentActionId/*, OdDbBlockReferencePtr pBlockRef, OdDbViewportPtr pViewport*/) { OdDbAssocOsnapPointRefActionParamPtr pSnapPointParam = OdDbAssocOsnapPointRefActionParam::cast(snapPointParamId.openObject(OdDb::kForWrite)); if (!pSnapPointParam.isNull()) { OdGeLineSeg3d line; OdDbObjectIdArray edgeParams = pSnapPointParam->ownedParams(); OdDbObjectId assocActionParam = pSnapPointParam->paramAtIndex(0); OdDbAssocVertexActionParamPtr pVertexParam = OdDbAssocVertexActionParam::cast(assocActionParam.openObject(OdDb::kForWrite)); if (!pVertexParam.isNull()) { line = *((OdGeLineSeg3d*)geometry); if (!ptPoint.isEqualTo(ptDimPoint)) ptPoint = line.startPoint(); pSnapPointParam->setOsnapMode(OdDb::kOsModeEnd); pSnapPointParam->setParam(-1); //if (!pBlockRef.isNull()) //{ // ptPoint.set(ptPoint.x + pBlockRef->position().x, ptPoint.y + pBlockRef->position().y, ptPoint.z + pBlockRef->position().z); //} //if (!pViewport.isNull()) //{ // transformPositionByViewPort(pViewport, ptPoint); //} pVertexParam->setVertexRef(OdDbVertexRef(ptPoint), false, false, 0); } else { OdGeCircArc3d arc; OdDbEdgeRef edgeRef; OdDbEdgeRef edgeRefNext; OdResult ret; OdSharedPtr pCurve3d; OdDbAssocEdgeActionParamPtr pEdgeParam = OdDbAssocEdgeActionParam::cast(assocActionParam.openObject(OdDb::kForWrite)); { OdArray edgeRefs; pEdgeParam->setOwnerId(parentActionId); OdResult res = pEdgeParam->getEdgeRef(edgeRefs); ODA_VERIFY_ONCE(res); if (edgeRefs.length() > 0) { edgeRef = edgeRefs[0]; } if (edgeRef.curve() == NULL) { if (geometry->isKindOf(OdGe::kLine3d)) pCurve3d = new OdGeLineSeg3d(); if (geometry->isKindOf(OdGe::kLineSeg3d)) pCurve3d = new OdGeLineSeg3d(); if (geometry->isKindOf(OdGe::kCircArc3d)) pCurve3d = new OdGeCircArc3d(); ODA_ASSERT(!pCurve3d.isNull()); if (pCurve3d.isNull()) return eInvalidDrawing; edgeRef.setCurve(pCurve3d); } if (edgeRef.curve()->type() == OdGe::kLineSeg3d && geometry->isKindOf(OdGe::kLineSeg3d))// any point on line { line = *((OdGeLineSeg3d*)geometry); double ratio = 1.0; OdGePoint3d ptPointStGeometry = line.startPoint(); //if (!pBlockRef.isNull()) //{ // ptPointStGeometry.set(ptPointStGeometry.x + pBlockRef->position().x, ptPointStGeometry.y + pBlockRef->position().y, ptPointStGeometry.z + pBlockRef->position().z); //} OdGePoint3d ptPointEnd = line.endPoint(); //if (!pBlockRef.isNull()) //{ // ptPointEnd.set(ptPointEnd.x + pBlockRef->position().x, ptPointEnd.y + pBlockRef->position().y, ptPointEnd.z + pBlockRef->position().z); //} OdGeLineSeg3d* lineGeom = (OdGeLineSeg3d*)geometry; OdGeVector3d vecGeomLine = ptPointEnd - ptPointStGeometry; lineGeom->set(ptPointStGeometry, vecGeomLine); //if (!pViewport.isNull()) //{ // transformPositionByViewPort(pViewport, ptPointStGeometry); // transformPositionByViewPort(pViewport, ptPointEnd); // vecGeomLine = ptPointEnd - ptPointStGeometry; //} if (!pCurve3d.isNull()) { ret = resetEdgeRefs(pEdgeParam, geometry,/* ptPoint,*/ parentActionId, edgeRef); if (ret != eOk) return ret; } OdGeLineSeg3d lineRef = *(OdGeLineSeg3d*)edgeRef.curve(); OdGePoint3d ptPointSt = lineRef.startPoint(); ptPointEnd = lineRef.endPoint(); //if (!pViewport.isNull()) //{ // transformPositionByViewPort(pViewport, ptPointSt); // transformPositionByViewPort(pViewport, ptPointEnd); //} OdGeLineSeg3d lineRefView(ptPointSt, ptPointEnd); ODA_ASSERT(lineRefView.isOn(ptDimPoint)); OdGeVector3d vec = ptDimPoint - ptPointSt; OdGeVector3d vecLineRf = ptPointEnd - ptPointSt; ratio = vec.length() / vecLineRf.length(); OdGePlane plane; if (lineRef.startPoint().isEqualTo(ptDimPoint)) { pSnapPointParam->setOsnapMode(OdDb::kOsModeStart); pSnapPointParam->setParam(0); } else if (lineRef.endPoint().isEqualTo(ptDimPoint)) { pSnapPointParam->setOsnapMode(OdDb::kOsModeEnd); pSnapPointParam->setParam(1.0); } else { pSnapPointParam->setOsnapMode(OdDb::kOsModeNear); pSnapPointParam->setParam(ratio); } if (pCurve3d.isNull()) // pCurve3d was set ( pCurve3d.IsNull( ) == fals ) if evaluate of existing (not created here) edgeRef { vecGeomLine.setLength(vecGeomLine.length() * ratio); ptPoint = ptPointStGeometry + vecGeomLine; } else ptPoint = ptDimPoint; //try //{ // //line.getPerpPlane(ptDimPoint, plane); // //line.intersectWith(plane, ptPoint); //} //catch (OdError &) //{ // ODA_ASSERT(!L"Geometry is wrong"); //} } if (pCurve3d.isNull()) { ret = resetEdgeRefs(pEdgeParam, geometry,/* ptPoint,*/ parentActionId, edgeRef); if (ret != eOk) return ret; } //arc = *(OdGeCircArc3d*)edgeRef.curve(); if (edgeRef.curve()->type() == OdGe::kCircArc3d && geometry->isKindOf(OdGe::kCircArc3d) || edgeRef.curve()->type() == OdGe::kCircArc2d && geometry->isKindOf(OdGe::kCircArc2d)) { arc = *((OdGeCircArc3d*)geometry); } } // the case of two edgeRefs (the point on the arc and line of center mark) if (edgeParams.length() > 1) { OdDbObjectId assocActionParamNext = pSnapPointParam->paramAtIndex(1); pEdgeParam = OdDbAssocEdgeActionParam::cast(assocActionParamNext.openObject(OdDb::kForWrite)); if (pCurve3d.get()) { ODA_ASSERT(!edgeRefNext.curve()); edgeRefNext.setCurve(pCurve3d); // CORE-16527 ret = resetEdgeRefs(pEdgeParam, geometry, /*ptPoint,*/ parentActionId, edgeRefNext); } else ret = eNotApplicable; if (ret == eOk) { ODA_ASSERT(edgeRefNext.curve()->type() == OdGe::kLineSeg3d); line = *(OdGeLineSeg3d*)edgeRefNext.curve(); OdGePoint3d p2; int numInt = 0; arc.intersectWith(line, numInt, ptPoint, p2); ODA_ASSERT(numInt == 1); } } // recalculate the point of dimension for the arc segment else if (edgeParams.length() == 1) { if (edgeRef.curve()->type() == OdGe::kCircArc2d || edgeRef.curve()->type() == OdGe::kCircArc3d)// any point on Arc { OdGePoint3d cen = arc.center(); if (!cen.isEqualTo(ptDimPoint))// point of dimension is not a center of arc { OdGeVector3d vec = ptDimPoint - cen; OdGePoint3d p2; int numInt = 0; vec.setLength(arc.radius() * 100); line.set(cen, vec); arc.intersectWith(line, numInt, ptPoint, p2); ODA_ASSERT(numInt == 1); } } } } } return eOk; } OdResult OdDbImpAssocAnnotationActionBody::resetEdgeRefs(OdDbAssocEdgeActionParamPtr pEdgeParam, OdGeCurve3d* geometry, /*OdGePoint3d ptPoint,*/ OdDbObjectId /*parentActionId*/, OdDbEdgeRef& edgeRef) { if (!edgeRef.curve()) return eNotApplicable; // CORE-16527 OdResult ret = eOk; OdGeCircArc3d* arc = NULL; OdGeLineSeg3d* line = NULL;; const OdInt32 entId = edgeRef.curve()->type(); switch (entId) { case OdGe::kLineSeg3d: // to regenerate DbLine in m_dbEntIds case OdGe::kLineSeg2d: { ODA_ASSERT(geometry->isKindOf(OdGe::kLineSeg3d)); OdGeLineSeg3d* lineGeom = (OdGeLineSeg3d*)geometry; const OdGePoint3d ptSG = lineGeom->startPoint(); const OdGePoint3d ptEG = lineGeom->endPoint(); const OdGeVector3d vec = ptEG - ptSG; line = (OdGeLineSeg3d*)edgeRef.curve(); line->set(ptSG, vec); //edgeRefs[0] = OdDbEdgeRef(lineGeom); } break; case OdGe::kEllipArc3d: // to regenerate DbEllipse in m_dbEntIds // x3a8 //OdGeDxfIO::outFields(pFiler, *(OdGeEllipArc3d*)m_edgeRef.curve()); break; case OdGe::kCircArc3d: // to regenerate DbArc in m_dbEntIds // budweiser2013.dwg case OdGe::kCircArc2d: // to regenerate DbArc in m_dbEntIds // budweiser2013.dwg { ODA_ASSERT(geometry->isKindOf(OdGe::kCircArc3d)); OdGeCircArc3d refCircle = *((OdGeCircArc3d*)geometry); OdGePoint3d center = refCircle.center(); //ODA_ASSERT(ptPoint.isEqualTo(refCircle.center())); //arc = (OdGeCircArc3d*)edgeRefs[0].curve(); arc = (OdGeCircArc3d*)edgeRef.curve(); arc->setCenter(center); arc->setRadius(refCircle.radius()); //arc->setCenter(ptPoint); //arc->setRadius(refCircle.radius()); } break; case OdGe::kNurbCurve3d: // to regenerate DbSpline in m_dbEntIds // budweiser2013.dwg x12fa8 // TODO move kSpunSurface and kSegmentChain2d to end of enum // via //OdGeDxfIO::outFields(pFiler, *(OdGeNurbCurve3d*)m_edgeRef.curve()); break; case OdGe::kLine3d: // to regenerate DbLine in m_dbEntIds //OdGeDxfIO::outFields(pFiler, *(OdGeLine3d*)m_edgeRef.curve()); break; case 47:// kCompositeCrv3d //OdGeDxfIO::outFields(pFiler, *(OdGeCompositeCurve3d*)m_edgeRef.curve()); break; default: ODA_FAIL_ONCE(); // TODO ret = eInvalidDrawing; //throw OdError(eNotImplementedYet); } pEdgeParam->setEdgeRef(edgeRef, false, false, 0); return ret; } OdDbObjectId OdDbImpAssocAnnotationActionBody::createOdDbAssocOSnapPointRefActionParam(const OdDbObjectId actionId, const OdDbObjectId source, const OdGePoint3d& /*ptPoint1*/, const OdDbAssocGeomDependencyPtr pGeomDependency1, const OdDbAssocGeomDependencyPtr /*pGeomDependency2*/, OdDbObjectId& anchorId, const PointPositionOnBlockLine isStartPoint, int paramIndex) { OdDbObjectPtr ptObj; OdDbSmartCenterActionBodyPtr smartObj; if (!source.isNull()) { ptObj = source.openObject(); smartObj = OdDbSmartCenterActionBody::cast(ptObj); } OdDbObjectId paramId; const OdString paramName = OD_T(" "); //OdString paramName = OD_T(""); OdRxClass* pClass = (OdRxClass*)odrxClassDictionary()->getAt(OD_T("ACDBASSOCOSNAPPOINTREFACTIONPARAM")).get(); OdDbAssocOsnapPointRefActionParamPtr pOSnapActionParam; OdDbAssocActionPtr pAction = OdDbAssocAction::cast(actionId.openObject(OdDb::kForWrite)); switch (pAction->addParam(paramName, pClass, paramId, paramIndex)) { case eOk: pOSnapActionParam = OdDbAssocOsnapPointRefActionParam::cast(paramId.openObject(OdDb::kForWrite)); break; case eAlreadyInDb: pOSnapActionParam = OdDbAssocOsnapPointRefActionParam::cast(paramId.openObject(OdDb::kForRead)); break; default: ODA_FAIL_ONCE(); } if (!pOSnapActionParam.isNull()) { OdDbAssocActionParamPtr pAssocActionParam; int addParamIndex = 0; OdDbObjectId addParamId; //OdString addParamName = OD_T(""); OdString addParamName = OD_T(" "); if (smartObj.isNull() || isStartPoint == kOnLine) { //addParamName = OD_T(" "); pClass = (OdRxClass*)odrxClassDictionary()->getAt(OD_T("AcDbAssocEdgeActionParam")).get(); } else { pClass = (OdRxClass*)odrxClassDictionary()->getAt(OD_T("AcDbAssocVertexActionParam")).get(); } switch (OdDbImpAssocCompoundActionParam::addParam_IfNotExistsAtIndex(pOSnapActionParam, addParamName, pClass, anchorId, addParamId, addParamIndex)) { case eOk: { pAssocActionParam = OdDbAssocActionParam::cast(addParamId.openObject(OdDb::kForWrite)); } break; case eAlreadyInDb: pAssocActionParam = OdDbAssocActionParam::cast(addParamId.openObject(OdDb::kForRead)); break; default: ODA_FAIL_ONCE(); } if (!pAssocActionParam.isNull()) { OdDbCompoundObjectId compoundObjectId; compoundObjectId.set(pGeomDependency1->objectId()); OdResult res = pAssocActionParam->setObjectOnly( compoundObjectId, true, false); ODA_VERIFY_ONCE(res == eOk); } anchorId = pOSnapActionParam->objectId(); } ODA_ASSERT(!paramId.isNull()); return paramId; } OdDbObjectId OdDbImpAssocAnnotationActionBody::getAssocDependencyForAction(const OdDbObjectId parentActionId) { OdDbObjectIdArray objIDs; OdDbAssocActionPtr pAction = OdDbAssocAction::cast(parentActionId.safeOpenObject(OdDb::kForRead)); pAction->getDependencies(false, true, objIDs); return OdDbAssocDependency::cast(getIdForFirstWriteDependency(objIDs).openObject())->dependentOnObject(); } void OdDbImpAssocAnnotationActionBody::CreateGeomDependencies(const OdDbFullSubentPath entPath, const OdDbObjectId actionId, const OdDbObjectId source, OdDbAssocGeomDependencyPtr& pGeomDependency1, OdDbAssocGeomDependencyPtr& /*pGeomDependency2*/, PointPositionOnBlockLine& /*isStartPoint*/) { OdDbSmartCenterActionBodyPtr smartObj; if (!source.isNull()) { smartObj = OdDbSmartCenterActionBody::cast(source.openObject()); } else { return; } OdDbDatabase *pDb = source.database(); OdDbObjectId compoundObjID = source;// .openObject()->objectId(); OdDbBlockReferencePtr bRef; if (!smartObj.isNull()) { OdDbObjectId sourceActionID = smartObj->ownerId(); OdDbAssocActionPtr pSourceAction = OdDbAssocAction::cast(sourceActionID.openObject()); bRef = OdDbBlockReference::cast(getAssocDependencyForAction(sourceActionID).safeOpenObject()); if (!bRef.isNull()) { compoundObjID = bRef->objectId(); } else return; } OdDbObjectId paramId; OdString paramName; OdRxClass* pClass = static_cast(odrxClassDictionary()->getAt(OD_T("ACDBASSOCOSNAPPOINTREFACTIONPARAM")).get()); ODA_VERIFY_ONCE(pClass); OdDbAssocOsnapPointRefActionParamPtr pOSnapActionParam; OdDbAssocActionPtr pAction = OdDbAssocAction::cast(actionId.openObject(OdDb::kForWrite)); const OdDbObjectIdArray& path = entPath.objectIds(); pGeomDependency1 = OdDbAssocGeomDependency::createObject(); pDb->addOdDbObject(pGeomDependency1); pGeomDependency1->setIsReadDependency(true); pGeomDependency1->setIsWriteDependency(false); pGeomDependency1->setOrder(2147483647u); OdDbCompoundObjectId compoundObjectId; compoundObjectId.setFullPath(path); if (!pGeomDependency1.isNull()) { pGeomDependency1->attachToObject(compoundObjectId); pGeomDependency1->setSubentity(entPath.subentId()); pAction->addDependency(pGeomDependency1->objectId(), true); } ODA_ASSERT(!pGeomDependency1.isNull()); } OdDbObjectId OdDbImpAssocAnnotationActionBody::GetLineIDByPoint(OdDbBlockReferencePtr bRef, OdGePoint3d ptPoint, PointPositionOnBlockLine& isStartPoint) { OdDbBlockTableRecordPtr pBR = bRef->blockTableRecord().openObject(); OdGePoint3d blockPosition = bRef->position(); OdGeMatrix3d matrix = bRef->blockTransform(); OdDbObjectIteratorPtr pObjIt = pBR->newIterator(); for (; !pObjIt->done(); pObjIt->step()) { OdDbObjectId tempId = pObjIt->entity()->objectId(); OdDbLinePtr pLineInBlock = OdDbLine::cast(tempId.openObject(OdDb::kForWrite)); if (!pLineInBlock.isNull()) { OdGePoint3d tempStartPoint = pLineInBlock->startPoint(); OdGePoint3d tempEndPoint = pLineInBlock->endPoint(); tempStartPoint.transformBy(matrix); tempEndPoint.transformBy(matrix); OdGeLineSeg3d segLine(tempStartPoint, tempEndPoint); if (tempStartPoint.isEqualTo(ptPoint)) { isStartPoint = kStartPoint; return tempId; } else { if (tempEndPoint.isEqualTo(ptPoint)) { isStartPoint = kEndPoint; return tempId; } else if (segLine.isOn(ptPoint)) { isStartPoint = kOnLine; return tempId; } } } } return NULL; } bool isCloned(OdDbIdMapping& idMap, OdDbObjectId id) { OdDbIdPair pair(id); return idMap.compute(pair) && pair.isCloned(); } bool isDependentOnObjectCloned(OdDbIdMapping& idMap, OdDbObjectId depid) { OdDbAssocDependencyPtr dep = depid.openObject(); if (dep.get()) return isCloned(idMap, dep->dependentOnObject()); return false; } OdResult OdDbImpAssocAnnotationActionBody::addMoreObjectsToDeepCloneOverride(const OdDbAssocActionBody* thisBody, OdDbIdMapping& idMap, OdDbObjectIdArray& additionalObjectsToClone) const { OdDbObjectId actionId = thisBody->ownerId(); { OdDbIdPair actionPair(actionId); if (idMap.compute(actionPair)) return eOk; idMap.assign(actionPair); } if (!isDependentOnObjectCloned(idMap, m_annotationEntDepId)) return eOk; OdDbObjectIdArray deps; OdResult res = thisBody->getDependencies(true, false, deps); for (OdDbObjectId depid : deps) { if (depid.objectClass()->isDerivedFrom(OdDbAssocGeomDependency::desc())) { if (isDependentOnObjectCloned(idMap, depid)) { additionalObjectsToClone.append(thisBody->ownerId()); break; } } } return res; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// OdDbImpAssocRotatedDimActionBody::OdDbImpAssocRotatedDimActionBody() { // m_ActionBodyType = kRotatedDim; m_paramBasedActionBody = new OdDbImpAssocParamBasedActionBody(true); } OdDbImpAssocRotatedDimActionBody::~OdDbImpAssocRotatedDimActionBody() { } OdResult OdDbImpAssocRotatedDimActionBody::dwgInFields(OdDbDwgFiler* pFiler) { const OdResult res = OdDbImpAssocAnnotationActionBody::dwgInFields(pFiler); if (res != eOk) return res; m_undefinedAnnotationActionBody = pFiler->rdInt16(); m_xline1PointRefActionParamId = pFiler->rdSoftPointerId(); m_xline2PointRefActionParamId = pFiler->rdSoftPointerId(); return res; } void OdDbImpAssocRotatedDimActionBody::dwgOutFields(OdDbDwgFiler* pFiler) const { OdDbImpAssocAnnotationActionBody::dwgOutFields(pFiler); pFiler->wrInt16(m_undefinedAnnotationActionBody); pFiler->wrSoftPointerId(m_xline1PointRefActionParamId); pFiler->wrSoftPointerId(m_xline2PointRefActionParamId); } OdResult OdDbImpAssocRotatedDimActionBody::dxfInFields(OdDbDxfFiler* pFiler) { const OdResult res = OdDbImpAssocAnnotationActionBody::dxfInFields(pFiler); if (res != eOk) return res; if (!pFiler->atSubclassData(OdDbAssocRotatedDimActionBody::desc()->dxfName())) { ODA_FAIL_ONCE(); return eMakeMeProxy; } NEXT_CODE(90); m_undefinedAnnotationActionBody = static_cast(pFiler->rdUInt32()); NEXT_CODE(330); m_xline1PointRefActionParamId = pFiler->rdObjectId(); NEXT_CODE(330); m_xline2PointRefActionParamId = pFiler->rdObjectId(); return eOk; } void OdDbImpAssocRotatedDimActionBody::dxfOutFields(OdDbDxfFiler* pFiler) const { OdDbImpAssocAnnotationActionBody::dxfOutFields(pFiler); pFiler->wrSubclassMarker(OdDbAssocRotatedDimActionBody::desc()->dxfName()); pFiler->wrUInt32(90, m_undefinedAnnotationActionBody); pFiler->wrObjectId(330, m_xline1PointRefActionParamId); pFiler->wrObjectId(330, m_xline2PointRefActionParamId); } //const OdDbSmartCenterMarkParametersPtr OdDbImpAssocRotatedDimActionBody::parameters() const //{ // return m_pParams; //} // //OdDbSmartCenterMarkParametersPtr& OdDbImpAssocRotatedDimActionBody::parameters() //{ // return m_pParams; //} // void OdDbImpAssocRotatedDimActionBody::composeForLoad(OdDbObject*, OdDb::SaveType, OdDb::DwgVersion, OdDbAuditInfo*) { //OdDbObjectId actionID = Body->ownerId(); //OdDbAssocActionPtr assocAct = OdDbAssocAction::cast(actionID.openObject(OdDb::kForWrite)); OdDbAssocOsnapPointRefActionParamPtr param1, param2; if (!m_xline1PointRefActionParamId.isNull()) param1 = OdDbAssocOsnapPointRefActionParam::cast(m_xline1PointRefActionParamId.openObject(OdDb::kForWrite)); if (!m_xline2PointRefActionParamId.isNull()) param2 = OdDbAssocOsnapPointRefActionParam::cast(m_xline2PointRefActionParamId.openObject(OdDb::kForWrite)); if (!param1.isNull()) { if ( m_arrParams.size() == 0) { m_arrParams.append(param1->id()); } } if (!param2.isNull()) { if (m_arrParams.size() < 2 ) { m_arrParams.append(param2->id()); } } } OdResult breakAssociativity(OdDbAssocAction* action, OdDbAssocOsnapPointRefActionParam* osnapParam) { if (!action || !osnapParam) return eNullObjectPointer; OdDbAssocActionParamPtr param = osnapParam->paramAtIndex(0).openObject(); OdResult res = eOk; OdDbObjectIdArray dependencyIds; if (param.get()) res = param->getDependencies(true, true, dependencyIds); for (auto id : dependencyIds) res = action->removeDependency(id, true); res = action->removeParam(osnapParam->objectId(), true); return res; } OdResult breakAssociativity(OdDbAssocAction* action, OdDbAssocOsnapPointRefActionParam* osnapParam, const OdString& rotRefEdgeParamName) { OdResult res = breakAssociativity(action, osnapParam); if (res!=eOk) return res; OdDbObjectId rotRefEdgeParamId = action->paramAtName(rotRefEdgeParamName); if (!rotRefEdgeParamId.isNull()) { OdDbAssocActionParamPtr rotRefEdgeParam = rotRefEdgeParamId.openObject(); OdDbObjectIdArray dependencyIds; if (rotRefEdgeParam.get()) res = rotRefEdgeParam->getDependencies(true, true, dependencyIds); for (auto id : dependencyIds) res = action->removeDependency(id, true); res = action->removeParam(rotRefEdgeParamId, true); } return res; } OdResult OdDbImpAssocAnnotationActionBody::breakAssociativity(OdDbAssocAction* action, OdDbAssocDependency* dimDep) { if (!action || !dimDep) return eNullObjectPointer; OdResult res = eOk; dimDep->upgradeOpen(); res = dimDep->detachFromObject(); res = action->setStatus(kErasedAssocStatus); return res; } OdResult getEdgeDirections(OdDbAssocEdgeActionParam* rotRefEdgeParam, OdGeVector3d& newDirection) { OdResult res = eNotApplicable; if (rotRefEdgeParam) { OdDbObjectIdArray dependencyIds; res = rotRefEdgeParam->getDependencies(true, false, dependencyIds); if (dependencyIds.size()) { OdDbAssocGeomDependencyPtr geomDep = dependencyIds.first().openObject(); if (geomDep.get()) { OdArray curves; res = geomDep->getEdgeSubentityGeometry(curves); if (curves.size()) { const OdGeCurve3d* newCurve = curves.first(); if (newCurve->isKindOf(OdGe::kLinearEnt3d)) newDirection = static_cast(newCurve)->direction(); for (auto curve : curves) delete curve; } } } ODA_VERIFY_ONCE(res == eOk); } return res; } OdResult rotateDimByEdge(OdDbAssocEdgeActionParam* edgeParam, OdDbRotatedDimension* rotDim, OdGeVector3d& newDir) { OdResult res = eOk; if (isEvaluationRequest(edgeParam->status(true))) { res = getEdgeDirections(edgeParam, newDir); OdGeVector3d dimNorm = rotDim->normal(); OdGeVector3d dimExtLineDir = OdGeVector3d::kYAxis; double dimRotation = rotDim->rotation(); dimExtLineDir.rotateBy(dimRotation, dimNorm); if (newDir.dotProduct(dimExtLineDir) < 0.0) newDir.negate(); double angle = dimExtLineDir.angleTo(newDir, dimNorm); rotDim->upgradeOpen(); rotDim->setRotation(angle + dimRotation); } return res; } bool checkAndUpdateRotation(OdDbAssocAction* action, OdDbAssocOsnapPointRefActionParamPtr osnapParams[2], OdDbRotatedDimension* rotDim) { if (!action || !rotDim) return false; if (action->paramAtName(L"RotRefEdge0").isNull() && action->paramAtName(L"RotRefEdge1").isNull()) return true; OdResult res = eOk; OdDbAssocEdgeActionParamPtr edgeParam1; if(osnapParams[0]) edgeParam1 = osnapParams[0]->paramAtIndex(0).openObject(); OdDbAssocEdgeActionParamPtr edgeParam2; if(osnapParams[1]) edgeParam2 = osnapParams[1]->paramAtIndex(0).openObject(); OdGeVector3d newDir1; OdGeVector3d newDir2; if (!edgeParam1.isNull() && edgeParam2.isNull()) { res = rotateDimByEdge(edgeParam1, rotDim, newDir1); } else if (edgeParam1.isNull() && !edgeParam2.isNull()) { res = rotateDimByEdge(edgeParam2, rotDim, newDir2); } else { bool bParam1Changed = isEvaluationRequest(edgeParam1->status(true)); res = getEdgeDirections(edgeParam1, newDir1); bool bParam2Changed = isEvaluationRequest(edgeParam2->status(true)); res = getEdgeDirections(edgeParam2, newDir2); if (bParam1Changed || bParam2Changed) { if (!newDir1.isParallelTo(newDir2)) return false; if (bParam1Changed && bParam2Changed) { res = rotateDimByEdge(edgeParam1, rotDim, newDir1); } } } ODA_VERIFY_ONCE(res == eOk); return true; } OdDbAssocDependencyPtr OdDbImpAssocAnnotationActionBody::lookUpVpDep(OdDbAssocAction* action) { OdDbObjectIdArray ids; action->getDependencies(true, false, ids); for (auto id : ids) { if(id.objectClass()->isDerivedFrom(OdDbAssocGeomDependency::desc())) continue; OdDbAssocDependencyPtr dep = id.openObject(); if (dep.get()) { if (dep->dependentOnObject().objectClass()->isDerivedFrom(OdDbViewport::desc())) return dep; } } return OdDbAssocDependencyPtr(); } void OdDbImpAssocRotatedDimActionBody::evaluateOverride(OdDbObjectId parentActionId) { OdDbAssocActionPtr action = OdDbAssocAction::cast(parentActionId.openObject(OdDb::kForWrite)); OdDbAssocDependencyPtr dimDep = m_annotationEntDepId.openObject(); for (;;) { if (dimDep.isNull()) { action->setStatus(kErasedAssocStatus); return; } OdDbRotatedDimensionPtr rotDim = dimDep->dependentOnObject().openObject(); OdDbAssocOsnapPointRefActionParamPtr osnapPointRefParams[2] = { m_xline1PointRefActionParamId.openObject(), m_xline2PointRefActionParamId.openObject() }; if (rotDim.isNull() || osnapPointRefParams[0].isNull() && osnapPointRefParams[1].isNull()) { action->setStatus(kErasedAssocStatus); return; } OdDbDimAssocPtr dimAssoc = (OdDbDimAssoc*)::odrxCreateObject(L"AcDbDimAssoc").get(); if (dimAssoc.isNull()) break; // FailedToEvaluate OdGePoint3d ptVals[2]; for (int pt = 0; pt < 2; ++pt) { if (osnapPointRefParams[pt].get()) { osnapPointRefParams[pt]->evaluatePointOverride(ptVals[pt]); OdDbOsnapPointRefPtr pRefPt = osnapPointRefParams[pt]->asOsnapPointRef(); //pRefPt->evalPoint(ptVals[pt]); dimAssoc->setPointRef(pt, pRefPt); } } if (isEvaluationRequest(dimDep->status())) { // dim modified, check associativity int nFlags = dimAssoc->assocFlag(); if (nFlags & OdDbDimAssoc::kFirstPointRef) { if (!rotDim->xLine1Point().isEqualTo(ptVals[OdDbDimAssoc::kXline1Point])) { dimAssoc->removePointRef(OdDbDimAssoc::kXline1Point); SETBIT_0(nFlags, OdDbDimAssoc::kFirstPointRef); } } if (nFlags & OdDbDimAssoc::kSecondPointRef) { if (!rotDim->xLine2Point().isEqualTo(ptVals[OdDbDimAssoc::kXline2Point])) { dimAssoc->removePointRef(OdDbDimAssoc::kXline2Point); SETBIT_0(nFlags, OdDbDimAssoc::kSecondPointRef); } } switch(nFlags) { case 0: breakAssociativity(action, dimDep); return; case 1: ::breakAssociativity(action, osnapPointRefParams[OdDbDimAssoc::kXline2Point], L"RotRefEdge1"); break; case 2: ::breakAssociativity(action, osnapPointRefParams[OdDbDimAssoc::kXline1Point], L"RotRefEdge0"); break; case 3: default: break; } } if (!::checkAndUpdateRotation(action, osnapPointRefParams, rotDim)) { breakAssociativity(action, dimDep); return; } OdDbAssocDependencyPtr vpDep = lookUpVpDep(action); bool vpChanged = vpDep.get() && isEvaluationRequest(vpDep->status()); if ( osnapPointRefParams[OdDbDimAssoc::kXline1Point].get() && !rotDim->xLine1Point().isEqualTo(ptVals[OdDbDimAssoc::kXline1Point]) || osnapPointRefParams[OdDbDimAssoc::kXline2Point].get() && !rotDim->xLine2Point().isEqualTo(ptVals[OdDbDimAssoc::kXline2Point]) || vpChanged) { rotDim->upgradeOpen(); if (vpChanged) { double newDimlFac = rotDim->dimlfac(); OdDbViewportPtr vViewPort = vpDep->dependentOnObject().openObject(); if (vViewPort.get()) { newDimlFac = 1 / vViewPort->customScale(); rotDim->setDimlfac(newDimlFac); } } OdSmartPtr watcher = (ExDimAssocWatcherPE*)OdDbEvalWatcherPE::cast(dimAssoc).get(); if (watcher.isNull()) break; // FailedToEvaluate dimAssoc->setDimObjId(rotDim->objectId()); watcher->updateDimension(dimAssoc, rotDim, ptVals); rotDim->downgradeOpen(); } action->evaluateDependencies(); action->setStatus(kIsUpToDateAssocStatus); return; } action->setStatus(kFailedToEvaluateAssocStatus); } OdResult OdDbImpAssocRotatedDimActionBody::createInstance( const OdDbFullSubentPathArray entPathArray, OdGePoint3dArray ptsSelected, OdDbObjectId& actionBodyId, OdString createAssocAlignedDim) { OdDbObjectIdArray sourceEntites; OdDbObjectId selectedEntId1; OdDbSmartCenterActionBodyPtr smartBody1, smartBody2; OdDbObjectIdArray pathArray = entPathArray[0].objectIds(); if (pathArray.length() < 1) return eInvalidInput; OdDbObjectId ownerBTRId = pathArray[0].openObject()->ownerId(); OdDbBlockTableRecordPtr pOwnerSpace = ownerBTRId.safeOpenObject(OdDb::kForWrite); OdDbObjectId networkId = OdDbAssocNetwork::getInstanceFromObject(pOwnerSpace->objectId(), true); OdDbViewportPtr viewportV; OdDbDatabase* pDb = nullptr; if (!pathArray.isEmpty()) { pDb = pathArray[0].database(); viewportV = OdDbViewport::cast(pathArray[0].openObject()); if (!viewportV.isNull()) { pathArray.removeFirst(); } selectedEntId1 = pathArray.first(); OdDbBlockReferencePtr pBody1 = OdDbBlockReference::cast(selectedEntId1.openObject(OdDb::kForRead)); if (!pBody1.isNull()) { for (OdUInt32 i = 1; i < pathArray.length(); i++) { OdDbObjectId bodyId1 = OdDbSmartCenterActionBody::getSmartCenterActionBody(pBody1); // CORE-16084 if (!bodyId1.isNull()) { smartBody1 = OdDbSmartCenterActionBody::cast(bodyId1.openObject()); break; } else pBody1 = OdDbBlockReference::cast(pathArray[i].openObject(OdDb::kForRead)); } } } OdDbObjectId sourceEntity1 = pathArray[pathArray.length() - 1];///TODO OdDbFullSubentPath pathDep0(pathArray, entPathArray[0].subentId()); pathArray = entPathArray[1].objectIds(); OdDbObjectId sourceEntity2 = pathArray[pathArray.length() - 1];///TODO OdDbObjectId selectedEntId2; if (!pathArray.isEmpty()) { viewportV = OdDbViewport::cast(pathArray[0].openObject()); if (!viewportV.isNull()) { pathArray.removeFirst(); } selectedEntId2 = pathArray.first(); OdDbBlockReferencePtr pBody2 = OdDbBlockReference::cast(selectedEntId2.openObject(OdDb::kForRead)); if (!pBody2.isNull()) { for (OdUInt32 i = 1; i < pathArray.length(); i++) { OdDbObjectId bodyId2 = OdDbSmartCenterActionBody::getSmartCenterActionBody(pBody2); if (!bodyId2.isNull()) { smartBody2 = OdDbSmartCenterActionBody::cast(bodyId2.openObject()); break; } else pBody2 = OdDbBlockReference::cast(pathArray[i].openObject(OdDb::kForRead)); } } } OdDbFullSubentPath pathDep1(pathArray, entPathArray[1].subentId()); const OdDbObjectId transferredID1 = smartBody1.isNull() ? selectedEntId1 : smartBody1->objectId(); const OdDbObjectId transferredID2 = smartBody2.isNull() ? selectedEntId2 : smartBody2->objectId(); sourceEntites.append(transferredID1); sourceEntites.append(transferredID2); /////////////////////////////////////////////////////////////////////// OdResult res = eOk; ODA_ASSERT(ptsSelected.length() > 2); OdGePoint3d dimLinePt = ptsSelected[2]; if (sourceEntites[0].isNull() && sourceEntites[1].isNull()) return eInvalidInput; //OdDbSmartCenterActionBodyPtr smartObj1, smartObj2; //if (!sourceEntites[0].isNull()) //{ // OdDbObjectPtr ptObj1 = sourceEntites[0].openObject(); //} //if (!sourceEntites[1].isNull()) //{ // OdDbObjectPtr ptObj2 = sourceEntites[1].openObject(); //} //if (smartObj1.isNull() && smartObj2.isNull()) TODO // return eInvalidInput; if (pDb == nullptr) pDb = sourceEntites[1].database(); //create action and action body //BEGIN OdString pClassName = OD_T("AcDbAssoc") + createAssocAlignedDim + OD_T("DimActionBody"); OdRxClass* pClass = (OdRxClass*)odrxClassDictionary()->getAt(pClassName).get(); OdDbObjectId actionId; if (eOk != createActionAndActionBodyAndPostToDatabase(pClass, networkId, actionId, actionBodyId)) { return eInvalidInput; } OdDbAssocAnnotationActionBodyPtr pActionBody = OdDbAssocActionBody::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("AcDb") + createAssocAlignedDim + OD_T("Dimension"); pClass = (OdRxClass*)odrxClassDictionary()->getAt(pClassName).get(); OdDbDimensionPtr pDimension = OdDbDimension::cast(pClass->create()); OdDbRotatedDimensionPtr pDimensionRot = OdDbRotatedDimension::cast(pDimension); OdDbAlignedDimensionPtr pDimensionAlig = OdDbAlignedDimension::cast(pDimension); pDimension->setDatabaseDefaults(pDb); pOwnerSpace->appendOdDbEntity(pDimension); OdDbDimStyleTablePtr pTable = pDb->getDimStyleTableId().safeOpenObject(OdDb::kForWrite); /**********************************************************************/ /* Add the DimStyle */ /**********************************************************************/ const OdDbObjectId odaDimStyleId = pDb->getDimStyleStandardId(); //transformPositionByViewPort(viewportV, ptsSelected[0]); //transformPositionByViewPort(viewportV, ptsSelected[1]); //transformPositionByViewPort(viewportV, dimLinePt); if (!pDimensionRot.isNull()) { pDimensionRot->setDimensionStyle(odaDimStyleId); pDimensionRot->setXLine1Point(ptsSelected[0]); pDimensionRot->setXLine2Point(ptsSelected[1]); pDimensionRot->setDimLinePoint(dimLinePt); pDimensionRot->setJogSymbolHeight(1.5); } if (!pDimensionAlig.isNull()) { pDimensionAlig->setDimensionStyle(odaDimStyleId); pDimensionAlig->setXLine1Point(ptsSelected[0]); pDimensionAlig->setXLine2Point(ptsSelected[1]); pDimensionAlig->setDimLinePoint(dimLinePt); pDimensionAlig->setJogSymbolHeight(1.5); } pDimension->useDefaultTextPosition(); pDimension->subClose(); OdDbObjectId anchorId; PointPositionOnBlockLine isStartPoint1 = kUndefined, isStartPoint2 = kUndefined; OdDbAssocGeomDependencyPtr pGeomDependency1, pGeomDependency2, pGeomDependency3, pGeomDependency4; if (!sourceEntites[0].isNull()) { CreateGeomDependencies(pathDep0, actionId, sourceEntites[0], pGeomDependency1, pGeomDependency2, isStartPoint1); } if (!sourceEntites[1].isNull()) { CreateGeomDependencies(pathDep1, actionId, sourceEntites[1], pGeomDependency3, pGeomDependency4, isStartPoint2); } 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 (!viewportV.isNull()) { pDependency = OdDbAssocDependency::createObject(); pDb->addOdDbObject(pDependency); pDependency->setIsReadDependency(true); pDependency->setIsWriteDependency(false); compoundObjectId.set(viewportV->objectId()); pDependency->attachToObject(compoundObjectId); pAction->addDependency(pDependency->objectId(), true); pActionBody->setAnnotationEntDepId(pDependency->objectId()); } if (!sourceEntites[0].isNull()) { const OdDbObjectId snapParamID1 = createOdDbAssocOSnapPointRefActionParam(actionId, sourceEntites[0], ptsSelected[0], pGeomDependency1, pGeomDependency2, anchorId, isStartPoint1, 0); if (pActionBody->isKindOf(OdDbAssocRotatedDimActionBody::desc())) OdDbAssocRotatedDimActionBody::cast(pActionBody)->setXline1PointRefActionParam(snapParamID1); if (pActionBody->isKindOf(OdDbAssocAlignedDimActionBody::desc())) OdDbAssocAlignedDimActionBody::cast(pActionBody)->setXline1PointRefActionParam(snapParamID1); //pActionBody->setXline1PointRefActionParam(snapParamID1); } if (!sourceEntites[1].isNull()) { const OdDbObjectId snapParamID2 = createOdDbAssocOSnapPointRefActionParam(actionId, sourceEntites[1], ptsSelected[1], pGeomDependency3, pGeomDependency4, anchorId, isStartPoint2, 1); if (pActionBody->isKindOf(OdDbAssocRotatedDimActionBody::desc())) OdDbAssocRotatedDimActionBody::cast(pActionBody)->setXline2PointRefActionParam(snapParamID2); if (pActionBody->isKindOf(OdDbAssocAlignedDimActionBody::desc())) OdDbAssocAlignedDimActionBody::cast(pActionBody)->setXline2PointRefActionParam(snapParamID2); //pActionBody->setXline2PointRefActionParam(snapParamID2); } return res; } OdResult OdDbImpAssocRotatedDimActionBody::createInstance( const OdDbFullSubentPathArray& entPathArray, const OdGePoint3dArray& ptsSelected, OdDbObjectId& actionBodyId, const OdArray& snapModeArr, OdString createAssocAlignedDim) { if (entPathArray.length() != 2 || snapModeArr.length() != 2) return eInvalidInput; OdDbObjectIdArray pathArray1 = entPathArray[0].objectIds(); OdDbObjectIdArray pathArray2 = entPathArray[1].objectIds(); OdDbObjectIdArray mainArray = pathArray1.isEmpty() ? pathArray2 : pathArray1; if (mainArray.isEmpty()) return eInvalidInput; OdDbObjectId ownerBTRId = mainArray[0].openObject()->ownerId(); OdDbBlockTableRecordPtr pOwnerSpace = ownerBTRId.safeOpenObject(OdDb::kForWrite); OdDbObjectId networkId = OdDbAssocNetwork::getInstanceFromObject(pOwnerSpace->objectId(), true); OdDbDatabase *pDb = mainArray[0].database(); OdDbViewportPtr viewportV; if (!pathArray1.isEmpty()) { viewportV = OdDbViewport::cast(pathArray1[0].openObject()); if (!viewportV.isNull()) pathArray1.removeFirst(); } if (!pathArray2.isEmpty()) { viewportV = OdDbViewport::cast(pathArray2[0].openObject()); if (!viewportV.isNull()) pathArray2.removeFirst(); } OdDbObjectId selectedEntId1 = pathArray1.isEmpty() ? OdDbObjectId::kNull : pathArray1.first(); OdDbObjectId selectedEntId2 = pathArray2.isEmpty() ? OdDbObjectId::kNull : pathArray2.first(); OdDbObjectIdArray sourceEntites; sourceEntites.append(selectedEntId1); sourceEntites.append(selectedEntId2); /////////////////////////////////////////////////////////////////////// OdResult res = eOk; ODA_ASSERT(ptsSelected.length() > 2); OdGePoint3d dimLinePt = ptsSelected[2]; if (sourceEntites[0].isNull() && sourceEntites[1].isNull()) return eInvalidInput; if (pDb == nullptr && !sourceEntites[1].isNull()) pDb = sourceEntites[1].database(); //create action and action body //BEGIN OdString pClassName = OD_T("AcDbAssoc") + createAssocAlignedDim + OD_T("DimActionBody"); OdRxClass * pClass = (OdRxClass*)odrxClassDictionary()->getAt(pClassName).get(); OdDbObjectId actionId; if (eOk != createActionAndActionBodyAndPostToDatabase(pClass, networkId, actionId, actionBodyId)) return eInvalidInput; OdDbAssocAnnotationActionBodyPtr pActionBody = OdDbAssocAnnotationActionBody::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("AcDb") + createAssocAlignedDim + OD_T("Dimension"); pClass = (OdRxClass*)odrxClassDictionary()->getAt(pClassName).get(); OdDbDimensionPtr pDimension = OdDbDimension::cast(pClass->create()); OdDbRotatedDimensionPtr pDimensionRot = OdDbRotatedDimension::cast(pDimension); OdDbAlignedDimensionPtr pDimensionAlig = OdDbAlignedDimension::cast(pDimension); pDimension->setDatabaseDefaults(pDb); pOwnerSpace->appendOdDbEntity(pDimension); OdDbDimStyleTablePtr pTable = pDb->getDimStyleTableId().safeOpenObject(OdDb::kForWrite); /**********************************************************************/ /* Add the DimStyle */ /**********************************************************************/ const OdDbObjectId odaDimStyleId = pDb->getDimStyleStandardId(); if (!pDimensionRot.isNull()) { pDimensionRot->setDimensionStyle(odaDimStyleId); pDimensionRot->setXLine1Point(ptsSelected[0]); pDimensionRot->setXLine2Point(ptsSelected[1]); pDimensionRot->setDimLinePoint(dimLinePt); pDimensionRot->setJogSymbolHeight(1.5); } if (!pDimensionAlig.isNull()) { pDimensionAlig->setDimensionStyle(odaDimStyleId); pDimensionAlig->setXLine1Point(ptsSelected[0]); pDimensionAlig->setXLine2Point(ptsSelected[1]); pDimensionAlig->setDimLinePoint(dimLinePt); pDimensionAlig->setJogSymbolHeight(1.5); } pDimension->useDefaultTextPosition(); pDimension->subClose(); if (!sourceEntites[0].isNull()) { OdDbObjectId snapParamID1; if (OdDbAssocOsnapPointRefActionParam:: createInstanceAndPostToDatabase(pActionBody->objectId(), snapModeArr[0], entPathArray[0], ptsSelected[0], snapParamID1) == eOk) { if (pActionBody->isKindOf(OdDbAssocRotatedDimActionBody::desc())) OdDbAssocRotatedDimActionBody::cast(pActionBody)->setXline1PointRefActionParam(snapParamID1); if (pActionBody->isKindOf(OdDbAssocAlignedDimActionBody::desc())) OdDbAssocAlignedDimActionBody::cast(pActionBody)->setXline1PointRefActionParam(snapParamID1); } } if (!sourceEntites[1].isNull()) { OdDbObjectId snapParamID2; if (OdDbAssocOsnapPointRefActionParam:: createInstanceAndPostToDatabase(pActionBody->objectId(), snapModeArr[1], entPathArray[1], ptsSelected[1], snapParamID2) == eOk) { if (pActionBody->isKindOf(OdDbAssocRotatedDimActionBody::desc())) OdDbAssocRotatedDimActionBody::cast(pActionBody)->setXline2PointRefActionParam(snapParamID2); if (pActionBody->isKindOf(OdDbAssocAlignedDimActionBody::desc())) OdDbAssocAlignedDimActionBody::cast(pActionBody)->setXline2PointRefActionParam(snapParamID2); } } 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 (!viewportV.isNull()) { pDependency = OdDbAssocDependency::createObject(); pDb->addOdDbObject(pDependency); pDependency->setIsReadDependency(true); pDependency->setIsWriteDependency(false); compoundObjectId.set(viewportV->objectId()); pDependency->attachToObject(compoundObjectId); pAction->addDependency(pDependency->objectId(), true); pActionBody->setAnnotationEntDepId(pDependency->objectId()); } return res; } OdStringArray OdDbImpAssocRotatedDimActionBody::compareWith(OdDbImpAssocActionBody *bodyIDToCompare, OdDb::DwgVersion /*filerVersion*/ /*OdDb::kDHL_CURRENT*/) const { OdStringArray retArr; OdDbImpAssocRotatedDimActionBody* comparedBody = static_cast(bodyIDToCompare); ODA_ASSERT(comparedBody != NULL); try { if (comparedBody != NULL) { //OdDbImpAssocRotatedDimActionBody start if (m_undefinedAnnotationActionBody != comparedBody->m_undefinedAnnotationActionBody) retArr.append(CS_UNDEFINED_ANNOTATION_ACTION_BODY); if (typeid(m_paramBasedActionBody) != typeid(comparedBody->m_paramBasedActionBody)) retArr.append(CS_PARAM_BASED_ACTION_BODY); //OdDbImpAssocRotatedDimActionBody end //DbImpAssocAnnotationActionBody OdDbObject* actionParamObject1 = m_xline1PointRefActionParamId.openObject().get(); OdDbObject* comparedActionParamObject1 = comparedBody->m_xline1PointRefActionParamId.openObject().get(); if (typeid(*actionParamObject1) != typeid(*comparedActionParamObject1)) retArr.append(CS_DIFFERENT_OBJECTS); OdDbObject* actionParamObject2 = m_xline2PointRefActionParamId.openObject().get(); OdDbObject* comparedActionParamObject2 = comparedBody->m_xline2PointRefActionParamId.openObject().get(); if (typeid(*actionParamObject2) != typeid(*comparedActionParamObject2)) retArr.append(CS_DIFFERENT_OBJECTS); OdDbObject* assocDependencyObject = m_annotationEntDepId.openObject().get(); OdDbObject* comparedAssocDependencyObject = comparedBody->m_annotationEntDepId.openObject().get(); if (typeid(*assocDependencyObject) != typeid(*comparedAssocDependencyObject)) retArr.append(CS_DIFFERENT_OBJECTS); if (m_undefined2 != comparedBody->m_undefined2) retArr.append(CS_UNDEFINED_PROPERTY); //OdDbImpAssocAnnotationActionBody } } catch (...) { retArr.append(CS_DIFFERENT_OBJECTS); } return retArr; }