/////////////////////////////////////////////////////////////////////////////// // 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 "DgAutoplantCylinderImpl.h" #include "DgAutoplantCylinder.h" #include "DgFiler.h" //---------------------------------------------------------- // // OdDgAutoplantCylinderImpl // //---------------------------------------------------------- OdDgAutoplantCylinderImpl::OdDgAutoplantCylinderImpl() { m_ptCenter1 = OdGePoint3d::kOrigin; m_ptCenter2 = OdGePoint3d::kOrigin; m_dRadius = 1.0; m_dStartData = 0.0; m_uFlags = 0x0003; } //---------------------------------------------------------- OdDgAutoplantCylinderImpl::~OdDgAutoplantCylinderImpl() { m_pConeElement = 0; m_pCapElement = 0; } //---------------------------------------------------------- OdResult OdDgAutoplantCylinderImpl::dgnInFields(OdDgFiler* pFiler) { m_dStartData = pFiler->rdDouble(); ODA_ASSERT_ONCE(OdZero(m_dStartData)); m_ptCenter1 = pFiler->rdPoint3d(); m_ptCenter2 = pFiler->rdPoint3d(); m_dRadius = pFiler->rdDouble(); m_uFlags = pFiler->rdInt64(); m_pConeElement = 0; m_pCapElement = 0; return eOk; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::dgnOutFields(OdDgFiler* pFiler) const { pFiler->wrDouble(m_dStartData); pFiler->wrPoint3d(m_ptCenter1); pFiler->wrPoint3d(m_ptCenter2); pFiler->wrDouble(m_dRadius); pFiler->wrInt64(m_uFlags); } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::scaleData(double dScale) { m_ptCenter1 *= dScale; m_ptCenter2 *= dScale; m_dRadius *= dScale; if (!m_pConeElement.isNull()) m_pConeElement->transformBy(OdGeMatrix3d::scaling(dScale)); if (!m_pCapElement.isNull()) m_pCapElement->transformBy(OdGeMatrix3d::scaling(dScale)); } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::updateConeElement(const OdDgAutoplantCylinder* pElm) { if (m_pConeElement) { m_pConeElement = 0; m_pCapElement = 0; } m_pConeElement = OdDgCone::createObject(); m_pConeElement->setCenter1(m_ptCenter1); m_pConeElement->setCenter2(m_ptCenter2); m_pConeElement->setSolid(pElm->getDrawStartCapFlag() && pElm->getDrawEndCapFlag()); OdGeVector3d vrZ = m_ptCenter2 - m_ptCenter1; if (vrZ.isZeroLength()) vrZ = OdGeVector3d::kZAxis; else vrZ.normalize(); OdGeVector3d vrX = vrZ.perpVector(); OdGeVector3d vrY = vrZ.crossProduct(vrX); OdGeMatrix3d matRotation; matRotation.setCoordSystem(OdGePoint3d::kOrigin, vrX, vrY, vrZ); matRotation.transposeIt(); OdGeQuaternion quatRot; quatRot.set(matRotation); m_pConeElement->setRotation(quatRot); m_pConeElement->setRadius1(m_dRadius); m_pConeElement->setRadius2(m_dRadius); m_pConeElement->setPropertiesFrom(pElm); m_pConeElement->setMaterial(pElm->getMaterial()); if( !m_pConeElement->isSolid() ) { if( pElm->getDrawStartCapFlag() ) { m_pCapElement = OdDgEllipse3d::createObject(); m_pCapElement->setOrigin(m_ptCenter1); m_pCapElement->setRotation(quatRot); m_pCapElement->setPrimaryAxis(m_dRadius); m_pCapElement->setSecondaryAxis(m_dRadius); m_pCapElement->setPropertiesFrom(pElm); m_pCapElement->setMaterial(pElm->getMaterial()); } else if (pElm->getDrawEndCapFlag()) { m_pCapElement = OdDgEllipse3d::createObject(); m_pCapElement->setOrigin(m_ptCenter2); m_pCapElement->setRotation(quatRot); m_pCapElement->setPrimaryAxis(m_dRadius); m_pCapElement->setSecondaryAxis(m_dRadius); m_pCapElement->setPropertiesFrom(pElm); m_pCapElement->setMaterial(pElm->getMaterial()); } } } //---------------------------------------------------------- const OdDgCone* OdDgAutoplantCylinderImpl::getConeElement(const OdDgAutoplantCylinder* pElm) const { if (m_pConeElement.isNull()) { OdDgAutoplantCylinderImpl* pThis = const_cast(this); pThis->updateConeElement(pElm); } return m_pConeElement.get(); } //---------------------------------------------------------- bool OdDgAutoplantCylinderImpl::subWorldDraw(OdGiWorldDraw* pWd, const OdDgAutoplantCylinder* pElm) const { const OdDgCone* pCone = getConeElement(pElm); if (pCone) { if( !m_pCapElement.isNull() ) m_pCapElement->subWorldDraw(pWd); return pCone->subWorldDraw(pWd); } return true; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::subViewportDraw(OdGiViewportDraw *pVd, const OdDgAutoplantCylinder* pElm) const { const OdDgCone* pCone = getConeElement(pElm); if( pCone ) { if( !m_pCapElement.isNull() ) m_pCapElement->subViewportDraw(pVd); pCone->subViewportDraw(pVd); } } //---------------------------------------------------------- OdResult OdDgAutoplantCylinderImpl::subGetGeomExtents(OdGeExtents3d& extents, const OdDgAutoplantCylinder* pElm) const { const OdDgCone* pCone = getConeElement(pElm); if( pCone ) return pCone->subGetGeomExtents(extents); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantCylinderImpl::subGetGeomExtents(const OdDgElementId& idView, OdGeExtents3d& extents, const OdDgAutoplantCylinder* pElm) const { const OdDgCone* pCone = getConeElement(pElm); if (pCone) return pCone->subGetGeomExtents(idView, extents); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantCylinderImpl::subExplode(OdRxObjectPtrArray& entitySet, const OdDgAutoplantCylinder* pElm) const { const OdDgCone* pCone = getConeElement(pElm); if( pCone ) entitySet.append(pCone->clone()); if( !m_pCapElement.isNull() ) entitySet.append(m_pCapElement->clone()); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantCylinderImpl::transformBy(const OdGeMatrix3d& xfm) { OdGeVector3d vrZ = m_ptCenter2 - m_ptCenter1; if (vrZ.isZeroLength()) vrZ = OdGeVector3d::kZAxis; else vrZ.normalize(); OdGePoint3d ptRadius = m_ptCenter1 + vrZ.perpVector() * m_dRadius; m_ptCenter1.transformBy(xfm); m_ptCenter2.transformBy(xfm); ptRadius.transformBy(xfm); m_dRadius = ptRadius.distanceTo(m_ptCenter1); m_pConeElement = 0; m_pCapElement = 0; return eOk; } //---------------------------------------------------------- OdGePoint3d OdDgAutoplantCylinderImpl::getCenter1() const { return m_ptCenter1; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::setCenter1(const OdGePoint3d& ptCenter) { m_ptCenter1 = ptCenter; m_pConeElement = 0; m_pCapElement = 0; } //---------------------------------------------------------- OdGePoint3d OdDgAutoplantCylinderImpl::getCenter2() const { return m_ptCenter2; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::setCenter2(const OdGePoint3d& ptCenter) { m_ptCenter2 = ptCenter; m_pConeElement = 0; m_pCapElement = 0; } //---------------------------------------------------------- double OdDgAutoplantCylinderImpl::getRadius() const { return m_dRadius; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::setRadius(double dRadius) { m_dRadius = dRadius; m_pConeElement = 0; m_pCapElement = 0; } //---------------------------------------------------------- bool OdDgAutoplantCylinderImpl::getDrawStartCapFlag() const { return (m_uFlags & 0x1) ? true : false; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::setDrawStartCapFlag(bool bSet) { OdUInt64 uFlagMask = 0x1; if (!bSet) m_uFlags &= ~uFlagMask; else m_uFlags |= uFlagMask; m_pConeElement = 0; m_pCapElement = 0; } //---------------------------------------------------------- bool OdDgAutoplantCylinderImpl::getDrawEndCapFlag() const { return (m_uFlags & 0x2) ? true : false; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::setDrawEndCapFlag(bool bSet) { OdUInt64 uFlagMask = 0x2; if (!bSet) m_uFlags &= ~uFlagMask; else m_uFlags |= uFlagMask; m_pConeElement = 0; m_pCapElement = 0; } //---------------------------------------------------------- OdUInt64 OdDgAutoplantCylinderImpl::getFlags() const { return m_uFlags; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::setFlags(OdUInt64 uFlags) { m_uFlags = uFlags; } //---------------------------------------------------------- double OdDgAutoplantCylinderImpl::getStartData() const { return m_dStartData; } //---------------------------------------------------------- void OdDgAutoplantCylinderImpl::setStartData(double dStartData) { m_dStartData = dStartData; } //----------------------------------------------------------