/////////////////////////////////////////////////////////////////////////////// // 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 "StdAfx.h" #include "RxObjectImpl.h" #include "DgAutoplantSphereImpl.h" #include "DgAutoplantSphere.h" #include "DgXAttribute.h" #include "DgAutoplantEntityProperties.h" #include "Ge/GePlane.h" #include "Ge/GeLine3d.h" //============================================================================================== // // OdDgAutoplantSphere // //============================================================================================== ODRX_CONS_DEFINE_MEMBERS(OdDgAutoplantSphere, OdDgProxyGraphicsElement, DGELEMENT_CONSTR) //============================================================================================== OdDgAutoplantSphere::OdDgAutoplantSphere() { set3dFormatFlag(true); setElementType(OdDgElement::kTypeExtraGraphicsElement); } //============================================================================================== OdUInt32 OdDgAutoplantSphere::subSetAttributes(OdGiDrawableTraits* pTraits) const { OdUInt32 uRet = OdDgGraphicsElement::subSetAttributes(pTraits); OdGiSubEntityTraitsPtr pSubEntityTraits = OdGiSubEntityTraits::cast(pTraits); if (!pSubEntityTraits.isNull()) { pSubEntityTraits->setLineType(0); pSubEntityTraits->setLineWeight(OdDb::kLnWt000); } return uRet; } //============================================================================================== void OdDgAutoplantSphere::scaleDataAfterWorkingUnitsChange(double dScale) { return m_impl.scaleData(dScale); } //============================================================================================== bool OdDgAutoplantSphere::subWorldDraw(OdGiWorldDraw* pWd) const { return m_impl.subWorldDraw(pWd, this); } //============================================================================================== void OdDgAutoplantSphere::subViewportDraw(OdGiViewportDraw *pVd) const { return m_impl.subViewportDraw(pVd, this); } //============================================================================================== OdResult OdDgAutoplantSphere::subGetGeomExtents(OdGeExtents3d& extents) const { return m_impl.subGetGeomExtents(extents, this); } //============================================================================================== OdResult OdDgAutoplantSphere::subGetGeomExtents(const OdDgElementId& idView, OdGeExtents3d& extents) const { return m_impl.subGetGeomExtents(idView, extents, this); } //============================================================================================== OdResult OdDgAutoplantSphere::subExplode(OdRxObjectPtrArray& entitySet) const { return m_impl.subExplode(entitySet, this); } //============================================================================================== OdResult OdDgAutoplantSphere::transformBy(const OdGeMatrix3d& xfm) { assertWriteEnabled(); return m_impl.transformBy(xfm); } //============================================================================================== bool OdDgAutoplantSphere::allowToConvertFromElement(OdDgElement* pBaseElement) const { if (pBaseElement && (pBaseElement->getElementType() == OdDgElement::kTypeExtraGraphicsElement) && (OdDgElement::getElementExtendedType(pBaseElement) == (OdUInt64)(OdDgAutoplantSphere::kType)) ) { return true; } return false; } //============================================================================================== void OdDgAutoplantSphere::decomposeForSave() { OdRxObjectPtrArray arrXAttrs; getXAttributes(OdDgExtendedElementTypeXAttribute::kType, arrXAttrs); bool bAddXAttr = true; if( !arrXAttrs.isEmpty() ) { OdDgExtendedElementTypeXAttributePtr pXAttr = arrXAttrs[0]; if( !pXAttr.isNull() ) { bAddXAttr = pXAttr->getElementType() != (OdDgExtendedElementTypeXAttribute::OdDgExtendedElementType)(kType); if (bAddXAttr) removeXAttributes(OdDgExtendedElementTypeXAttribute::kType); } } if (bAddXAttr) { OdDgExtendedElementTypeXAttributePtr pXAttr = OdDgExtendedElementTypeXAttribute::createObject(); pXAttr->setElementType((OdDgExtendedElementTypeXAttribute::OdDgExtendedElementType)(kType)); pXAttr->setFlags(0); pXAttr->setXAttrId(1); addXAttribute(OdDgExtendedElementTypeXAttribute::kType, pXAttr); } } //============================================================================================== OdResult OdDgAutoplantSphere::dgnInFields(OdDgFiler* pFiler) { return m_impl.dgnInFields(pFiler); } //============================================================================================== void OdDgAutoplantSphere::dgnOutFields(OdDgFiler* pFiler) const { m_impl.dgnOutFields(pFiler); } //============================================================================================== OdUInt64 OdDgAutoplantSphere::getFlags() const { return m_impl.getFlags(); } //============================================================================================== void OdDgAutoplantSphere::setFlags(OdUInt64 uFlags) { assertWriteEnabled(); m_impl.setFlags(uFlags); } //============================================================================================== OdGePoint3d OdDgAutoplantSphere::getOrigin() const { return m_impl.getOrigin(); } //============================================================================================== void OdDgAutoplantSphere::setOrigin(const OdGePoint3d& ptOrigin) { assertWriteEnabled(); m_impl.setOrigin(ptOrigin); } //============================================================================================== OdGeVector3d OdDgAutoplantSphere::getDirection() const { return m_impl.getDirection(); } //============================================================================================== void OdDgAutoplantSphere::setDirection(const OdGeVector3d& vrDirection) { assertWriteEnabled(); m_impl.setDirection(vrDirection); } //============================================================================================== double OdDgAutoplantSphere::getRadius() const { return m_impl.getRadius(); } //============================================================================================== void OdDgAutoplantSphere::setRadius(double dRadius) { assertWriteEnabled(); m_impl.setRadius(dRadius); } //============================================================================================== // CDA Properties for OdDgAutoplantSphere //============================================================================================== //----------------------------------------------------------------------------------------------------------------------- // property: Origin //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereOriginProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getOrigin(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereOriginProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setOrigin(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Direction //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereDirectionProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getDirection(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereDirectionProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setDirection(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Radius //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereRadiusProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getRadius(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereRadiusProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setRadius(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Flags //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereFlagsProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getFlags(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantSphereFlagsProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantSpherePtr pObj = OdDgAutoplantSphere::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setFlags(*rxvalue_cast(&value)); return eOk; } //============================================================================================== // Grip and snap points for OdDgAutoplantSphere //============================================================================================== OdResult OdDgAutoplantSphereGripPointsPE::getGripPoints(const OdDgElement* pEnt, OdGePoint3dArray& gripPoints)const { unsigned int size = gripPoints.size(); gripPoints.resize(size + 2); OdDgAutoplantSpherePtr pSphere = pEnt; OdGeVector3d vrZDir = pSphere->getDirection(); if (vrZDir.isZeroLength()) vrZDir = OdGeVector3d::kZAxis; else vrZDir.normalize(); gripPoints[size] = pSphere->getOrigin(); gripPoints[size + 1] = pSphere->getOrigin() + vrZDir * pSphere->getRadius(); return eOk; } //============================================================================================== OdResult OdDgAutoplantSphereGripPointsPE::moveGripPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { unsigned size = indices.size(); if (size == 0) return eOk; OdDgAutoplantSpherePtr pSphere = pEnt; if (size > 1 || indices[0] == 2) { pSphere->transformBy(OdGeMatrix3d::translation(offset)); } else if (indices[0] == 0) { pSphere->setOrigin(pSphere->getOrigin() + offset); } else { OdGeVector3d vrZDir = pSphere->getDirection(); if (vrZDir.isZeroLength()) vrZDir = OdGeVector3d::kZAxis; else vrZDir.normalize(); OdGePoint3d ptRadius = pSphere->getOrigin() + vrZDir * pSphere->getRadius() + offset; pSphere->setDirection(ptRadius - pSphere->getOrigin()); pSphere->setRadius(pSphere->getOrigin().distanceTo(ptRadius)); } return eOk; } //============================================================================================== OdResult OdDgAutoplantSphereGripPointsPE::getStretchPoints(const OdDgElement* pEnt, OdGePoint3dArray& stretchPoints) const { OdResult res = getGripPoints(pEnt, stretchPoints); if (res == eOk) { stretchPoints.resize(stretchPoints.size() - 1); } return res; } //============================================================================================== OdResult OdDgAutoplantSphereGripPointsPE::moveStretchPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { return moveGripPointsAt(pEnt, indices, offset); } //============================================================================================== OdResult OdDgAutoplantSphereGripPointsPE::getOsnapPoints(const OdDgElement* pEnt, OdDgElement::OsnapMode osnapMode, OdGsMarker gsSelectionMark, const OdGePoint3d& pickPoint, const OdGePoint3d& lastPoint, const OdGeMatrix3d& xWorldToEye, OdGePoint3dArray& snapPoints) const { OdDgAutoplantSpherePtr pSphere = pEnt; switch (osnapMode) { case OdDgElement::kOsModeCen: { snapPoints.append(pSphere->getOrigin()); } break; case OdDgElement::kOsModeEnd: { snapPoints.append(pSphere->getOrigin()); } break; default: { } break; } return eOk; } //==============================================================================================