/////////////////////////////////////////////////////////////////////////////// // 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 "DgAutoplantSphereImpl.h" #include "DgAutoplantSphere.h" #include "DgFiler.h" #include "Dg3DObject.h" #include "DgShape.h" #include "DgLine.h" #include "DgArc.h" //---------------------------------------------------------- // // DgAutoplantSphereImpl // //---------------------------------------------------------- OdDgAutoplantSphereImpl::OdDgAutoplantSphereImpl() { m_ptOrigin = OdGePoint3d::kOrigin; m_vrDirection = OdGeVector3d::kZAxis; m_dRadius = 1.0; m_dStartData = 0.0; m_uFlags = 0; } //---------------------------------------------------------- OdDgAutoplantSphereImpl::~OdDgAutoplantSphereImpl() { m_pCacheElement = 0; } //---------------------------------------------------------- OdResult OdDgAutoplantSphereImpl::dgnInFields(OdDgFiler* pFiler) { m_dStartData = pFiler->rdDouble(); m_ptOrigin = pFiler->rdPoint3d(); m_vrDirection = pFiler->rdVector3d(); m_dRadius = pFiler->rdDouble(); ODA_ASSERT_ONCE(OdZero(m_dStartData)); m_uFlags = pFiler->rdInt64(); m_pCacheElement = 0; return eOk; } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::dgnOutFields(OdDgFiler* pFiler) const { pFiler->wrDouble(m_dStartData); pFiler->wrPoint3d(m_ptOrigin); pFiler->wrVector3d(m_vrDirection); pFiler->wrDouble(m_dRadius); pFiler->wrInt64(m_uFlags); } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::scaleData(double dScale) { m_ptOrigin *= dScale; m_dRadius *= dScale; if( !m_pCacheElement.isNull() ) m_pCacheElement->transformBy(OdGeMatrix3d::scaling(dScale)); } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::updateCachedElement(const OdDgAutoplantSphere* pElm) { if (m_pCacheElement) m_pCacheElement = 0; OdDgSurfacePtr pSphere = OdDgSurface::createObject(); pSphere->setType(OdDgSurface::kSurfaceRevolution); OdDg3dObjectHelper helper(pSphere); OdGeMatrix3d matPrimary; OdGeVector3d vrX = m_vrDirection; if (vrX.isZeroLength()) vrX = OdGeVector3d::kZAxis; else vrX.normalize(); OdGeVector3d vrY = vrX.perpVector(); OdGeVector3d vrZ = vrX.crossProduct(vrY); matPrimary.setCoordSystem(OdGePoint3d::kOrigin, vrX, vrY, vrZ); matPrimary.transposeIt(); OdGeQuaternion quatPrimary; quatPrimary.set(matPrimary); OdDgArc3dPtr pBoundary1 = OdDgArc3d::createObject(); pBoundary1->setOrigin(m_ptOrigin); pBoundary1->setPrimaryAxis(m_dRadius); pBoundary1->setSecondaryAxis(m_dRadius); pBoundary1->setStartAngle(0); pBoundary1->setSweepAngle(OdaPI); pBoundary1->setRotation(quatPrimary); pBoundary1->setClass(pElm->getClass()); helper.addToBoundary(pBoundary1); OdDgArc3dPtr pBoundary2 = pBoundary1->clone(); pBoundary2->transformBy(OdGeMatrix3d::rotation(OdaPI2, vrX, m_ptOrigin)); helper.addToBoundary(pBoundary2); OdDgArc3dPtr pVertRule1 = pBoundary1->clone(); pVertRule1->transformBy(OdGeMatrix3d::rotation(-OdaPI2, vrY, m_ptOrigin)); pVertRule1->setStartAngle(0); pVertRule1->setSweepAngle(OdaPI2); pVertRule1->setClass(pElm->getClass() == OdDgGraphicsElement::kClassPrimary ? OdDgGraphicsElement::kClassPrimaryRule : OdDgGraphicsElement::kClassConstructionRule); helper.addToRule(pVertRule1); OdDgArc3dPtr pBoundary3 = pBoundary2->clone(); pBoundary3->transformBy(OdGeMatrix3d::rotation(OdaPI2, vrX, m_ptOrigin)); helper.addToBoundary(pBoundary3); OdDgArc3dPtr pVertRule2 = pVertRule1->clone(); pVertRule2->transformBy(OdGeMatrix3d::rotation(OdaPI2, vrX, m_ptOrigin)); helper.addToRule(pVertRule2); OdDgArc3dPtr pBoundary4 = pBoundary3->clone(); pBoundary4->transformBy(OdGeMatrix3d::rotation(OdaPI2, vrX, m_ptOrigin)); helper.addToBoundary(pBoundary4); OdDgArc3dPtr pVertRule3 = pVertRule2->clone(); pVertRule3->transformBy(OdGeMatrix3d::rotation(OdaPI2, vrX, m_ptOrigin)); helper.addToRule(pVertRule3); OdDgArc3dPtr pBoundary5 = pBoundary1->clone(); helper.addToBoundary(pBoundary5); OdDgArc3dPtr pVertRule4 = pVertRule3->clone(); pVertRule4->transformBy(OdGeMatrix3d::rotation(OdaPI2, vrX, m_ptOrigin)); helper.addToRule(pVertRule4); pSphere->setPropertiesFrom(pElm, true); pSphere->setMaterial(pElm->getMaterial()); m_pCacheElement = pSphere; } //---------------------------------------------------------- const OdDgGraphicsElement* OdDgAutoplantSphereImpl::getCachedElement(const OdDgAutoplantSphere* pElm) const { if (m_pCacheElement.isNull()) { OdDgAutoplantSphereImpl* pThis = const_cast(this); pThis->updateCachedElement(pElm); } return m_pCacheElement.get(); } //---------------------------------------------------------- bool OdDgAutoplantSphereImpl::subWorldDraw(OdGiWorldDraw* pWd, const OdDgAutoplantSphere* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if (pCache) return pCache->subWorldDraw(pWd); return true; } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::subViewportDraw(OdGiViewportDraw *pVd, const OdDgAutoplantSphere* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if(pCache) pCache->subViewportDraw(pVd); } //---------------------------------------------------------- OdResult OdDgAutoplantSphereImpl::subGetGeomExtents(OdGeExtents3d& extents, const OdDgAutoplantSphere* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if(pCache) return pCache->subGetGeomExtents(extents); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantSphereImpl::subGetGeomExtents(const OdDgElementId& idView, OdGeExtents3d& extents, const OdDgAutoplantSphere* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if (pCache) return pCache->subGetGeomExtents(idView, extents); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantSphereImpl::subExplode(OdRxObjectPtrArray& entitySet, const OdDgAutoplantSphere* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if(pCache) entitySet.append(pCache->clone()); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantSphereImpl::transformBy(const OdGeMatrix3d& xfm) { OdGeVector3d vrDir = m_vrDirection; if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGePoint3d ptRadius = m_ptOrigin + vrDir * m_dRadius; m_vrDirection.transformBy(xfm); m_ptOrigin.transformBy(xfm); ptRadius.transformBy(xfm); m_dRadius = ptRadius.distanceTo(m_ptOrigin); m_pCacheElement = 0; return eOk; } //---------------------------------------------------------- OdUInt64 OdDgAutoplantSphereImpl::getFlags() const { return m_uFlags; } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::setFlags(OdUInt64 uFlags) { m_uFlags = uFlags; } //---------------------------------------------------------- double OdDgAutoplantSphereImpl::getStartData() const { return m_dStartData; } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::setStartData(double dStartData) { m_dStartData = dStartData; } //---------------------------------------------------------- OdGePoint3d OdDgAutoplantSphereImpl::getOrigin() const { return m_ptOrigin; } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::setOrigin(const OdGePoint3d& ptOrigin) { m_ptOrigin = ptOrigin; m_pCacheElement = 0; } //---------------------------------------------------------- OdGeVector3d OdDgAutoplantSphereImpl::getDirection() const { return m_vrDirection; } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::setDirection(const OdGeVector3d& vrDirection) { m_vrDirection = vrDirection; m_pCacheElement = 0; } //---------------------------------------------------------- double OdDgAutoplantSphereImpl::getRadius() const { return m_dRadius; } //---------------------------------------------------------- void OdDgAutoplantSphereImpl::setRadius(double dRadius) { m_dRadius = dRadius; m_pCacheElement = 0; } //----------------------------------------------------------