/////////////////////////////////////////////////////////////////////////////// // 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 "DgAutoplantDomeImpl.h" #include "DgAutoplantDome.h" #include "DgFiler.h" #include "Dg3DObject.h" #include "DgShape.h" #include "DgLine.h" #include "DgArc.h" //---------------------------------------------------------- // // OdDgAutoplantDomeImpl // //---------------------------------------------------------- OdDgAutoplantDomeImpl::OdDgAutoplantDomeImpl() { m_extraData = new OdDgAutoplantDomeExtraData(); m_dStartData = 0.0; m_ptOrigin = OdGePoint3d::kOrigin; m_vrDirection = OdGeVector3d::kZAxis; m_dRadius = 1.0; m_dHeight = 1.0; m_uFlags = 0x00010001; } //---------------------------------------------------------- OdDgAutoplantDomeImpl::~OdDgAutoplantDomeImpl() { m_pCacheElement = 0; delete m_extraData; m_extraData = NULL; } //---------------------------------------------------------- OdResult OdDgAutoplantDomeImpl::dgnInFields(OdDgFiler* pFiler) { m_dStartData = pFiler->rdDouble(); ODA_ASSERT_ONCE(OdZero(m_dStartData)); m_ptOrigin = pFiler->rdPoint3d(); m_vrDirection = pFiler->rdVector3d(); m_dRadius = pFiler->rdDouble(); m_dHeight = pFiler->rdDouble(); m_uFlags = pFiler->rdInt64(); m_extraData->m_pointValues[0] = pFiler->rdPoint3d(); m_extraData->m_pointValues[1] = pFiler->rdPoint3d(); m_extraData->m_pointValues[2] = pFiler->rdPoint3d(); m_extraData->m_pointValues[3] = pFiler->rdPoint3d(); m_extraData->m_vectorValues[0] = pFiler->rdVector3d(); m_extraData->m_vectorValues[1] = pFiler->rdVector3d(); m_extraData->m_doubleValues[0] = pFiler->rdDouble(); m_extraData->m_doubleValues[1] = pFiler->rdDouble(); m_pCacheElement = 0; return eOk; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::dgnOutFields(OdDgFiler* pFiler) const { pFiler->wrDouble(m_dStartData); pFiler->wrPoint3d(m_ptOrigin); pFiler->wrVector3d(m_vrDirection); pFiler->wrDouble(m_dRadius); pFiler->wrDouble(m_dHeight); pFiler->wrInt64(m_uFlags); pFiler->wrPoint3d(m_extraData->m_pointValues[0]); pFiler->wrPoint3d(m_extraData->m_pointValues[1]); pFiler->wrPoint3d(m_extraData->m_pointValues[2]); pFiler->wrPoint3d(m_extraData->m_pointValues[3]); pFiler->wrVector3d(m_extraData->m_vectorValues[0]); pFiler->wrVector3d(m_extraData->m_vectorValues[1]); pFiler->wrDouble(m_extraData->m_doubleValues[0]); pFiler->wrDouble(m_extraData->m_doubleValues[1]); } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::scaleData(double dScale) { m_ptOrigin *= dScale; m_dRadius *= dScale; m_dHeight *= dScale; m_extraData->m_doubleValues[0] *= dScale; m_extraData->m_doubleValues[1] *= dScale; m_extraData->m_pointValues[0] *= dScale; m_extraData->m_pointValues[1] *= dScale; m_extraData->m_pointValues[2] *= dScale; m_extraData->m_pointValues[3] *= dScale; if( !m_pCacheElement.isNull() ) m_pCacheElement->transformBy(OdGeMatrix3d::scaling(dScale)); } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::updateCachedElement(const OdDgAutoplantDome* pElm) { if (m_pCacheElement) m_pCacheElement = 0; OdDgSurfacePtr pHemiSphere = OdDgSurface::createObject(); pHemiSphere->setType(OdDgSurface::kSurfaceRevolution); OdDg3dObjectHelper helper(pHemiSphere); 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_dHeight); pBoundary1->setSecondaryAxis(m_dRadius); pBoundary1->setStartAngle(0); pBoundary1->setSweepAngle(OdaPI2); 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); OdGeMatrix3d matRule; matRule.setCoordSystem(OdGePoint3d::kOrigin, vrY, vrZ, vrX); matRule.transposeIt(); OdGeQuaternion quatRule; quatRule.set(matRule); OdDgArc3dPtr pVertRule1 = pBoundary1->clone(); pVertRule1->setOrigin(m_ptOrigin); pVertRule1->setPrimaryAxis(m_dRadius); pVertRule1->setSecondaryAxis(m_dRadius); pVertRule1->setStartAngle(0); pVertRule1->setSweepAngle(OdaPI2); pVertRule1->setRotation(quatRule); 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); pHemiSphere->setPropertiesFrom(pElm, true); pHemiSphere->setMaterial(pElm->getMaterial()); m_pCacheElement = pHemiSphere; } //---------------------------------------------------------- const OdDgGraphicsElement* OdDgAutoplantDomeImpl::getCachedElement(const OdDgAutoplantDome* pElm) const { if (m_pCacheElement.isNull()) { OdDgAutoplantDomeImpl* pThis = const_cast(this); pThis->updateCachedElement(pElm); } return m_pCacheElement.get(); } //---------------------------------------------------------- bool OdDgAutoplantDomeImpl::subWorldDraw(OdGiWorldDraw* pWd, const OdDgAutoplantDome* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if (pCache) return pCache->subWorldDraw(pWd); return true; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::subViewportDraw(OdGiViewportDraw *pVd, const OdDgAutoplantDome* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if(pCache) pCache->subViewportDraw(pVd); } //---------------------------------------------------------- OdResult OdDgAutoplantDomeImpl::subGetGeomExtents(OdGeExtents3d& extents, const OdDgAutoplantDome* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if(pCache) return pCache->subGetGeomExtents(extents); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantDomeImpl::subGetGeomExtents(const OdDgElementId& idView, OdGeExtents3d& extents, const OdDgAutoplantDome* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if (pCache) return pCache->subGetGeomExtents(idView, extents); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantDomeImpl::subExplode(OdRxObjectPtrArray& entitySet, const OdDgAutoplantDome* pElm) const { const OdDgGraphicsElement* pCache = getCachedElement(pElm); if(pCache) entitySet.append(pCache->clone()); return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantDomeImpl::transformBy(const OdGeMatrix3d& xfm) { OdGeVector3d vrDir = m_vrDirection; if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGePoint3d ptHeight = m_ptOrigin + vrDir * m_dHeight; OdGePoint3d ptRadius = m_ptOrigin + vrDir.perpVector() * m_dRadius; m_vrDirection.transformBy(xfm); m_ptOrigin.transformBy(xfm); ptHeight.transformBy(xfm); ptRadius.transformBy(xfm); m_dRadius = ptRadius.distanceTo(m_ptOrigin); m_dHeight = ptHeight.distanceTo(m_ptOrigin); m_pCacheElement = 0; return eOk; } //---------------------------------------------------------- OdUInt64 OdDgAutoplantDomeImpl::getFlags() const { return m_uFlags; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::setFlags(OdUInt64 uFlags) { m_uFlags = uFlags; } //---------------------------------------------------------- double OdDgAutoplantDomeImpl::getStartData() const { return m_dStartData; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::setStartData(double dStartData) { m_dStartData = dStartData; } //---------------------------------------------------------- OdGePoint3d OdDgAutoplantDomeImpl::getOrigin() const { return m_ptOrigin; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::setOrigin(const OdGePoint3d& ptOrigin) { m_ptOrigin = ptOrigin; m_pCacheElement = 0; } //---------------------------------------------------------- OdGeVector3d OdDgAutoplantDomeImpl::getDirection() const { return m_vrDirection; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::setDirection(const OdGeVector3d& vrDirection) { m_vrDirection = vrDirection; m_pCacheElement = 0; } //---------------------------------------------------------- double OdDgAutoplantDomeImpl::getRadius() const { return m_dRadius; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::setRadius(double dRadius) { m_dRadius = dRadius; m_pCacheElement = 0; } //---------------------------------------------------------- double OdDgAutoplantDomeImpl::getHeight() const { return m_dHeight; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::setHeight(double dHeight) { m_dHeight = dHeight; m_pCacheElement = 0; } //---------------------------------------------------------- OdDgAutoplantDomeExtraData OdDgAutoplantDomeImpl::getExtraData() const { return *m_extraData; } //---------------------------------------------------------- void OdDgAutoplantDomeImpl::setExtraData(const OdDgAutoplantDomeExtraData& extraData) { *m_extraData = extraData; } //----------------------------------------------------------