/////////////////////////////////////////////////////////////////////////////// // 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 "OdDbAssocTextPersSubentIdPE.h" #include "DbMText.h" #include "DbText.h" ODRX_NO_CONS_DEFINE_MEMBERS_ALTNAME(OdDbAssocTextPersSubentIdPE, OdDbAssocPointBasedPersSubentIdPE, L"AcDbAssocTextPersSubentIdPE"); ODRX_NO_CONS_DEFINE_MEMBERS_ALTNAME(OdDbAssocMTextPersSubentIdPE, OdDbAssocPointBasedPersSubentIdPE, L"AcDbAssocMTextPersSubentIdPE"); static OdDbSubentId textInsertionSubent() { return OdDbSubentId(OdDb::kVertexSubentType, -1); } static OdGePoint3d getPosition(const OdDbText& text) { return text.position(); } static OdGePoint3d getPosition(const OdDbMText& mtext) { return mtext.location(); } static void setPosition(OdDbText& text, const OdGePoint3d& position) { text.setPosition(position); } static void setPosition(OdDbMText& mtext, const OdGePoint3d& position) { mtext.setLocation(position); } static OdGeVector3d getDirection(const OdDbText& text) { return text.normal(); } static OdGeVector3d getDirection(const OdDbMText& mtext) { return mtext.direction(); } static void setDirection(OdDbText& text, const OdGeVector3d& direction) { text.setNormal(direction); } static void setDirection(OdDbMText& mtext, const OdGeVector3d& direction) { mtext.setDirection(direction); } template class OdDbImpAssocTextPersSubentIdPE { public: static bool isValid(const OdDbEntity* pEnt) { return pEnt && pEnt->isKindOf(T::desc()); } static OdDbAssocPersSubentIdPtr createNewPersSubent(OdDbEntity* pEntity, const OdDbCompoundObjectId&, const OdDbSubentId& subentId) { OdDbAssocSimplePersSubentIdPtr res; if (isValid(pEntity) && ( subentId == textInsertionSubent() || subentId.type() == OdDb::kAxisSubentType) ) { res = OdDbAssocSimplePersSubentId::createObject(); res->init(subentId); } return res; } static OdResult getAllSubentities(const OdDbEntity* pEntity, OdDb::SubentType subentType, OdArray& allSubentIds) { if (!isValid(pEntity)) return eBadObjType; if (subentType == OdDb::kVertexSubentType) { allSubentIds.push_back(textInsertionSubent()); return eOk; } else if (subentType == OdDb::kEdgeSubentType || subentType == OdDb::kFaceSubentType) return eOk; else if (subentType == OdDb::kAxisSubentType) { allSubentIds.append(OdDbSubentId(OdDb::kAxisSubentType, (OdGsMarker)kMajorAxis)); return eOk; } else return eBadObjType; } static OdResult getVertexSubentityGeometry(const OdDbEntity* pEntity, const OdDbSubentId& vertexSubentId, OdGePoint3d& vertexPosition) { OdResult res = eBadObjType; if (isValid(pEntity) && vertexSubentId == textInsertionSubent()) { vertexPosition = getPosition(static_cast(*pEntity)); res = eOk; } return res; } static OdResult setVertexSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& vertexSubentId, const OdGePoint3d& newVertexPosition) { if (isValid(pEntity) && vertexSubentId == textInsertionSubent()) { setPosition(static_cast(*pEntity), newVertexPosition); return eOk; } return eBadObjType; } static OdResult setSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& subentId, const OdDbEntity* pNewSubentityGeometry) { if (isValid(pEntity) && isValid(pNewSubentityGeometry) && subentId == textInsertionSubent()) { OdGePoint3d vert = getPosition(static_cast(*pNewSubentityGeometry)); setPosition(static_cast(*pEntity), vert); return eOk; } return eBadObjType; } /** \details Gets the axis of an entity corresponding to the associated subentity ID. \param pEntity [in] pointer to the entity. \param axisSubentId [in] identifier of axis subentity. \param axis [out] requested axis geometry. \return eOk on success, eBadObjType otherwise. */ static OdResult getAxisSubentityGeometry(const OdDbEntity* pEntity, const OdDbSubentId& axisSubentId, OdGeVector3d& axis) { if (!isValid(pEntity) || !(axisSubentId.type() == OdDb::kAxisSubentType && axisSubentId.index() == kMajorAxis)) return eBadObjType; axis = getDirection(static_cast(*pEntity)); return eOk; } /** \details Sets the geometry of an axis subentity corresponding to the associated subentity ID. \param pEntity [in] pointer to the entity. \param axisSubentId [in] identifier of axis subentity. \param axis [in] new value. \return eOk on success, eBadObjType otherwise. */ static OdResult setAxisSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& axisSubentId, const OdGeVector3d& newAxis) { if (!isValid(pEntity) || !(axisSubentId.type() == OdDb::kAxisSubentType && axisSubentId.index() == kMajorAxis)) return eBadObjType; setDirection(static_cast(*pEntity), newAxis); return eOk; } }; OdDbAssocPersSubentIdPtr OdDbAssocTextPersSubentIdPE::createNewPersSubent(OdDbEntity* pEntity, const OdDbCompoundObjectId& compId, const OdDbSubentId& subentId) { return OdDbImpAssocTextPersSubentIdPE::createNewPersSubent(pEntity, compId, subentId); } OdResult OdDbAssocTextPersSubentIdPE::getAllSubentities(const OdDbEntity* pEntity, OdDb::SubentType subentType, OdArray& allSubentIds) { return OdDbImpAssocTextPersSubentIdPE::getAllSubentities(pEntity, subentType, allSubentIds); } OdResult OdDbAssocTextPersSubentIdPE::getVertexSubentityGeometry(const OdDbEntity* pEntity, const OdDbSubentId& vertexSubentId, OdGePoint3d& vertexPosition) { return OdDbImpAssocTextPersSubentIdPE::getVertexSubentityGeometry(pEntity, vertexSubentId, vertexPosition); } OdResult OdDbAssocTextPersSubentIdPE::setVertexSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& vertexSubentId, const OdGePoint3d& newVertexPosition) { return OdDbImpAssocTextPersSubentIdPE::setVertexSubentityGeometry(pEntity, vertexSubentId, newVertexPosition); } OdResult OdDbAssocTextPersSubentIdPE::setSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& subentId, const OdDbEntity* pNewSubentityGeometry) { return OdDbImpAssocTextPersSubentIdPE::setSubentityGeometry(pEntity, subentId, pNewSubentityGeometry); } OdResult OdDbAssocTextPersSubentIdPE::getTransientSubentIds(const OdDbEntity* pEntity, const OdDbAssocPersSubentId* pPerSubentId, OdArray& subents) const { return OdDbAssocPointBasedPersSubentIdPE::getTransientSubentIds(pEntity, pPerSubentId, subents); } OdResult OdDbAssocTextPersSubentIdPE::getAxisSubentityGeometry(const OdDbEntity* pEntity, const OdDbSubentId& axisSubentId, OdGeVector3d& axis) { return OdDbImpAssocTextPersSubentIdPE::getAxisSubentityGeometry(pEntity, axisSubentId, axis); } OdResult OdDbAssocTextPersSubentIdPE::setAxisSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& axisSubentId, const OdGeVector3d& newAxis) { return OdDbImpAssocTextPersSubentIdPE::setAxisSubentityGeometry(pEntity, axisSubentId, newAxis); } OdDbAssocPersSubentIdPtr OdDbAssocMTextPersSubentIdPE::createNewPersSubent(OdDbEntity* pEntity, const OdDbCompoundObjectId& compId, const OdDbSubentId& subentId) { return OdDbImpAssocTextPersSubentIdPE::createNewPersSubent(pEntity, compId, subentId); } OdResult OdDbAssocMTextPersSubentIdPE::getAllSubentities(const OdDbEntity* pEntity, OdDb::SubentType subentType, OdArray& allSubentIds) { return OdDbImpAssocTextPersSubentIdPE::getAllSubentities(pEntity, subentType, allSubentIds); } OdResult OdDbAssocMTextPersSubentIdPE::getVertexSubentityGeometry(const OdDbEntity* pEntity, const OdDbSubentId& vertexSubentId, OdGePoint3d& vertexPosition) { return OdDbImpAssocTextPersSubentIdPE::getVertexSubentityGeometry(pEntity, vertexSubentId, vertexPosition); } OdResult OdDbAssocMTextPersSubentIdPE::setVertexSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& vertexSubentId, const OdGePoint3d& newVertexPosition) { return OdDbImpAssocTextPersSubentIdPE::setVertexSubentityGeometry(pEntity, vertexSubentId, newVertexPosition); } OdResult OdDbAssocMTextPersSubentIdPE::setSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& subentId, const OdDbEntity* pNewSubentityGeometry) { return OdDbImpAssocTextPersSubentIdPE::setSubentityGeometry(pEntity, subentId, pNewSubentityGeometry); } OdResult OdDbAssocMTextPersSubentIdPE::getTransientSubentIds(const OdDbEntity* pEntity, const OdDbAssocPersSubentId* pPerSubentId, OdArray& subents) const { return OdDbAssocPointBasedPersSubentIdPE::getTransientSubentIds(pEntity, pPerSubentId, subents); } OdResult OdDbAssocMTextPersSubentIdPE::getAxisSubentityGeometry(const OdDbEntity* pEntity, const OdDbSubentId& axisSubentId, OdGeVector3d& axis) { return OdDbImpAssocTextPersSubentIdPE::getAxisSubentityGeometry(pEntity, axisSubentId, axis); } OdResult OdDbAssocMTextPersSubentIdPE::setAxisSubentityGeometry(OdDbEntity* pEntity, const OdDbSubentId& axisSubentId, const OdGeVector3d& newAxis) { return OdDbImpAssocTextPersSubentIdPE::setAxisSubentityGeometry(pEntity, axisSubentId, newAxis); }