/////////////////////////////////////////////////////////////////////////////// // 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 "DbObject.h" #include "DbImpAssocGeomDependency.h" #include "DbFiler.h" #include "DbEntity.h" #include "DbPolyline.h" #include "DbExtrudedSurface.h" #include "OdDbAssocPersSubentIdPE.h" #include "DbAssoc2dConstraintGroup.h" #include "OdConstrainedGeometryImpl.h" #include "DbAssocPersSubentId.h" #include "OdDbAssocPolylinePersSubentIdPE.h" #include "DbAssocNetwork.h" #include "DbImpSmartCenterActionBody.h" #include "ShHistory/DbAssocPersSubentManager.h" #include "ShHistory/DbAssocPersSubentManagerCloner.h" OdDbImpAssocGeomDependency::OdDbImpAssocGeomDependency() : OdDbImpAssocDependency() ,m_bCachingGeometry(false) ,m_bPolylineGeometry(true) { m_pPersSubent = NULL; m_pSubentCurve = NULL; } OdDbImpAssocGeomDependency::~OdDbImpAssocGeomDependency() { m_pPersSubent.release(); delete m_pSubentCurve; } OdResult OdDbImpAssocGeomDependency::dwgInFields(OdDbDwgFiler* pFiler) { m_pPersSubent.release(); //m_pCachingSubentityGeometry.reset(); OdResult es = OdDbImpAssocDependency::dwgInFields(pFiler); if (es != eOk) return es; if (pFiler->rdInt16() != 0) // Version? { ODA_FAIL(); return eMakeMeProxy; } if (pFiler->rdBool()) es = OdDbAssocPersSubentId::createObjectAndDwgInFields(pFiler, m_pPersSubent); if (es != eOk) return es; bool /*m_*/bCachingGeometry = pFiler->rdBool(); if (bCachingGeometry) { ODA_FAIL(); // TODO return eMakeMeProxy; //m_pCachingSubentityGeometry.reset(new OdDbAssocSubentGeomCache()); //return m_pCachingSubentityGeometry->dwgInFields(pFiler); } return eOk; } void OdDbImpAssocGeomDependency::dwgOutFields(OdDbDwgFiler* pFiler) const { OdDbImpAssocDependency::dwgOutFields(pFiler); pFiler->wrInt16(0); // Version? pFiler->wrBool(!m_pPersSubent.isNull()); if (!m_pPersSubent.isNull()) { m_pPersSubent->dwgOutFields(pFiler); } ODA_ASSERT(!m_bCachingGeometry); pFiler->wrBool(false); // TODO: m_bCachingGeometry } OdResult OdDbImpAssocGeomDependency::dxfInFields(OdDbDxfFiler* pFiler) { m_pPersSubent.release(); //m_pCachingSubentityGeometry.reset(); OdResult es = OdDbImpAssocDependency::dxfInFields(pFiler); if (es != eOk) return es; // Check that we are at the correct subclass data if( !pFiler->atSubclassData( OdDbAssocGeomDependency::desc()->name() )) { return eBadDxfSequence; } NEXT_CODE(90) if( pFiler->rdInt32() != 0) // version return eMakeMeProxy; NEXT_CODE(290) if (pFiler->rdBool()) es = OdDbAssocPersSubentId::createObjectAndDxfInFields(pFiler, m_pPersSubent); if (es != eOk) return es; NEXT_CODE(290) bool /*m_*/bCachingGeometry = pFiler->rdBool(); if (bCachingGeometry) { ODA_FAIL(); return eMakeMeProxy; //m_pCachingSubentityGeometry.reset(new OdDbAssocSubentGeomCache()); //return m_pCachingSubentityGeometry->dwgInFields(pFiler); } return eOk; } void OdDbImpAssocGeomDependency::dxfOutFields(OdDbDxfFiler* pFiler) const { OdDbImpAssocDependency::dxfOutFields(pFiler); pFiler->wrSubclassMarker(OdDbAssocGeomDependency::desc()->name()); pFiler->wrInt32(90, 0); // Version pFiler->wrBool(290, !m_pPersSubent.isNull()); if(!m_pPersSubent.isNull()) { m_pPersSubent->dxfOutFields(pFiler); } ODA_ASSERT(!m_bCachingGeometry); pFiler->wrBool(290, false); // TODO: m_bCachingGeometry } OdDbAssocPersSubentIdPtr OdDbImpAssocGeomDependency::persistentSubentId() const { return m_pPersSubent; } OdResult OdDbImpAssocGeomDependency::getTransientSubentIds(OdArray& transientSubentIds) const { if (!m_pPersSubent.isNull()) { OdDbObjectId idDependentOn = geomObject(); if (!idDependentOn.isNull()) { OdDbEntityPtr pEnt = idDependentOn.openObject(); return m_pPersSubent->getTransientSubentIds(pEnt, transientSubentIds); } } return eNullObjectPointer; } OdResult OdDbImpAssocGeomDependency::setSubentity(const OdDbSubentId& transientSubentId) { if ( !isAttachedToObject() ) return eNullObjectPointer; OdDbObjectId objId = geomObject(); OdDbObjectPtr pObj = objId.openObject(); if ( pObj.isNull() ) return eNullObjectPointer; if ( !pObj->isKindOf(OdDbEntity::desc()) ) return eNullObjectPointer; OdSmartPtr pPE = pObj->isA()->getX(OdDbAssocPersSubentIdPE::desc()); if ( pPE.isNull() ) return eNullObjectPointer; //pPE->setAssocGeomDependency(this); // TODO ABT 09222017 OdDbEntityPtr pEntity = OdDbEntity::cast(pObj); pEntity->upgradeOpen(); m_pPersSubent = pPE->createNewPersSubent(pEntity, m_refPath, transientSubentId); if ( m_pPersSubent.isNull() ) return eNullObjectPointer; switch ( transientSubentId.type() ) { case OdDb::kVertexSubentType: { OdGePoint3d vertex; if ( pPE->getVertexSubentityGeometry(pEntity, transientSubentId, vertex) != eOk ) return eBadObjType; OdGePoint3dArray arrPt; arrPt.append(vertex); return setVertexSubentityGeometry(arrPt); } break; case OdDb::kEdgeSubentType: { OdGeCurve3d *pCurve; if ( pPE->getEdgeSubentityGeometry(pEntity, transientSubentId, pCurve) != eOk ) return eBadObjType; OdArray arrEdge; arrEdge.append(pCurve); OdResult res = setEdgeSubentityGeometry(arrEdge); delete pCurve; return res; } break; case OdDb::kAxisSubentType: { return eOk; } break; default: ODA_FAIL_ONCE(); } //pPE->setAssocGeomDependency(NULL);// TODO ABT 09222017 return eBadObjType; } OdDb::SubentType OdDbImpAssocGeomDependency::subentType() const { if (!m_pPersSubent.isNull()) { OdDbObjectId idDependentOn = geomObject(); if (!idDependentOn.isNull()) { OdDbEntityPtr pEnt = idDependentOn.openObject(); return m_pPersSubent->subentType(pEnt); } } return OdDb::kNullSubentType; } OdInt32 OdDbImpAssocGeomDependency::transientSubentCount() const { if (!m_pPersSubent.isNull()) { OdDbObjectId idDependentOn = geomObject(); if (!idDependentOn.isNull()) { OdDbEntityPtr pEnt = idDependentOn.openObject(); return m_pPersSubent->transientSubentCount(pEnt); } } return 0; } bool OdDbImpAssocGeomDependency::isCachingSubentityGeometry() const { return m_bCachingGeometry; } void OdDbImpAssocGeomDependency::setCachingSubentityGeometry(bool bCaching) { m_bCachingGeometry = bCaching; } OdResult OdDbImpAssocGeomDependency::getVertexSubentityGeometry(OdGePoint3dArray& vertexPositions) const { OdDb::SubentType type = subentType(); if (type != OdDb::kVertexSubentType) return eBadObjType; OdDbCompoundObjectId compoundObjectId; getDependentOnCompoundObject(compoundObjectId); if (compoundObjectId.leafId().isErased()) return eWasErased; OdDbEntityPtr pEnt = compoundObjectId.leafId().openObject(); if (pEnt.isNull()) { ODA_ASSERT(!L"CompoundObject not completed yet"); return eNullObjectId; } OdDbAssocPersSubentIdPEPtr pPE = pEnt->isA()->getX(OdDbAssocPersSubentIdPE::desc()); if (pPE.isNull()) { ODA_ASSERT(!L"OdDbAssocPersSubentIdPEPtr is Null"); return eNullObjectId; } OdArray arrIds; OdResult res = pPE->getTransientSubentIds(pEnt, persistentSubentId(), arrIds); if (res != eOk || 0 == arrIds.length()) return res; OdGePoint3d vertex; res = pPE->getVertexSubentityGeometry(pEnt, arrIds[0], vertex); if (res != eOk) return res; if (!compoundObjectId.isSimpleObjectId()) { OdGeMatrix3d mTrans; res = compoundObjectId.getTransform(mTrans); if (res != eOk) return res; vertex.transformBy(mTrans); } vertexPositions.append(vertex); return res; } OdResult OdDbImpAssocGeomDependency::getEdgeSubentityGeometry(OdArray& edgeCurves) const { OdDbCompoundObjectId compoundObjectId; getDependentOnCompoundObject(compoundObjectId); if (compoundObjectId.leafId().isErased()) return eWasErased; OdDb::SubentType type = subentType(); if ( type != OdDb::kEdgeSubentType ) return eBadObjType; OdDbEntityPtr pEnt = compoundObjectId.leafId().openObject(); if (pEnt.isNull()) { ODA_ASSERT(!L"CompoundObject not completed yet"); return eNullObjectId; } OdDbAssocPersSubentIdPEPtr pPE = pEnt->isA()->getX(OdDbAssocPersSubentIdPE::desc()); if (pPE.isNull()) { ODA_ASSERT(!L"OdDbAssocPersSubentIdPEPtr is Null"); return eNullObjectId; } OdArray arrIds; OdResult res = pPE->getTransientSubentIds(pEnt, persistentSubentId(), arrIds); if (res != eOk || 0 == arrIds.length()) return res; OdGeCurve3d* pCurve = NULL; res = pPE->getEdgeSubentityGeometry(pEnt, arrIds[0], pCurve); if (res != eOk) return res; if (!compoundObjectId.isSimpleObjectId()) { OdGeMatrix3d mTrans; res = compoundObjectId.getTransform(mTrans); if (res != eOk) return res; pCurve->transformBy(mTrans); } edgeCurves.append(pCurve); return res; } OdResult OdDbImpAssocGeomDependency::getFaceSubentityGeometry(OdArray& /*faceSurfaces*/) const { return eNotImplementedYet; } OdResult OdDbImpAssocGeomDependency::setVertexSubentityGeometry(const OdGePoint3dArray& newVertexPositions) { if ( subentType() != OdDb::kVertexSubentType ) return eBadObjType; if ( newVertexPositions.length() == 0 ) return eBadObjType; m_subentPt = newVertexPositions[0]; return eOk; } OdResult OdDbImpAssocGeomDependency::setEdgeSubentityGeometry(const OdArray& newEdgeCurves) { if ( subentType() != OdDb::kEdgeSubentType ) return eBadObjType; if ( newEdgeCurves.length() == 0 ) return eBadObjType; delete m_pSubentCurve; #if 0 // when copy will create for all gepm object remove this precompiled directive m_pSubentCurve = (OdGeCurve3d*)newEdgeCurves[0]->copy(); #else if ( newEdgeCurves[0]->isKindOf(OdGe::kCircArc3d) ) { OdGeCircArc3d *pCircArc = (OdGeCircArc3d*)newEdgeCurves[0]; m_pSubentCurve = new OdGeCircArc3d(pCircArc->center(), pCircArc->normal(), pCircArc->refVec(), pCircArc->radius(), pCircArc->startAng(), pCircArc->endAng()); } else if ( newEdgeCurves[0]->isKindOf(OdGe::kLineSeg3d) ) { OdGeLineSeg3d *pLineSeg = (OdGeLineSeg3d*)newEdgeCurves[0]; m_pSubentCurve = new OdGeLineSeg3d(pLineSeg->startPoint(), pLineSeg->endPoint()); } else if ( newEdgeCurves[0]->isKindOf(OdGe::kRay3d) ) { OdGeRay3d *pRay = (OdGeRay3d*)newEdgeCurves[0]; m_pSubentCurve = new OdGeRay3d(pRay->pointOnLine(), pRay->direction()); } else if ( newEdgeCurves[0]->isKindOf(OdGe::kLine3d) ) { OdGeLine3d *pLine = (OdGeLine3d*)newEdgeCurves[0]; m_pSubentCurve = new OdGeLine3d(pLine->pointOnLine(), pLine->direction()); } else if ( newEdgeCurves[0]->isKindOf(OdGe::kEllipArc3d) ) { OdGeEllipArc3d *pEllipArc = ( OdGeEllipArc3d*)newEdgeCurves[0]; m_pSubentCurve = new OdGeEllipArc3d(pEllipArc->center(), pEllipArc->majorAxis(), pEllipArc->minorAxis(), pEllipArc->majorRadius(), pEllipArc->minorRadius(), pEllipArc->startAng(), pEllipArc->endAng()); } else if ( newEdgeCurves[0]->isKindOf(OdGe::kNurbCurve3d) ) { OdGeNurbCurve3d *pNurb = (OdGeNurbCurve3d*)newEdgeCurves[0]; OdGeDoubleArray arrWeights; OdGePoint3dArray arrCtrlPt; OdInt32 i; for ( i = 0; i < pNurb->numWeights(); i++ ) arrWeights.append(pNurb->weightAt(i)); for ( i = 0; i < pNurb->numControlPoints(); i++ ) arrCtrlPt.append(pNurb->controlPointAt(i)); double period; m_pSubentCurve = new OdGeNurbCurve3d(pNurb->degree(), pNurb->knots(), arrCtrlPt, arrWeights, pNurb->isPeriodic(period)); } #endif return eOk; } OdResult OdDbImpAssocGeomDependency::setFaceSubentityGeometry(const OdArray& /*newFaceSurfaces*/) { return eNotImplementedYet; } OdResult OdDbImpAssocGeomDependency::dependentOnObjectMirrored() { if (!m_pPersSubent.isNull()) { OdDbObjectId idDependentOn = dependentOnObject(); if (!idDependentOn.isNull()) { OdDbEntityPtr pEnt = idDependentOn.openObject(); return m_pPersSubent->mirror(pEnt); } } return eNullObjectPointer; } OdResult OdDbImpAssocGeomDependency::setOwningAction(OdDbObjectId actionId, OdDbAssocDependency *pDep) { if ( m_pPersSubent.isNull() ) return eBadObjType; return OdDbImpAssocDependency::setOwningAction(actionId, pDep); } OdResult OdDbImpAssocGeomDependency::updateDependentOnObject(OdDbAssocDependency *) { return eOk; } OdStringArray OdDbImpAssocGeomDependency::compareWith(const OdDbImpAssocDependency *depIDToCompare, OdDb::DwgVersion filerVersion) const { OdStringArray retArray = OdDbImpAssocDependency::compareWith(depIDToCompare, filerVersion); //OdDbImpAssocGeomDependency* comparedDep = (OdDbImpAssocGeomDependency *)(depIDToCompare); return retArray; } OdDbObjectId OdDbImpAssocGeomDependency::geomObject() const { OdDbCompoundObjectId compId; getDependentOnCompoundObject(compId); return !compId.isEmpty() ? compId.leafId() : OdDbObjectId::kNull; }