/////////////////////////////////////////////////////////////////////////////// // 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 "DgAutoplantBoltImpl.h" #include "DgAutoplantBolt.h" #include "DgFiler.h" #include "Gi/GiViewport.h" #include "Gi/GiWorldDraw.h" #include "Gi/GiViewportDraw.h" #include "DgView.h" //---------------------------------------------------------- // // OdDgAutoplantBoltImpl // //---------------------------------------------------------- OdDgAutoplantBoltImpl::OdDgAutoplantBoltImpl() { m_dStartData = 0.0; m_ptOrigin = OdGePoint3d::kOrigin; m_vrDirection = OdGeVector3d::kZAxis; m_dStemLength = 1.0; m_dRadius = 1.0; m_uFlags = 0; } //---------------------------------------------------------- OdDgAutoplantBoltImpl::~OdDgAutoplantBoltImpl() { } //---------------------------------------------------------- OdResult OdDgAutoplantBoltImpl::dgnInFields(OdDgFiler* pFiler) { m_dStartData = pFiler->rdDouble(); m_dStemLength = pFiler->rdDouble(); m_dRadius = pFiler->rdDouble(); m_vrDirection = pFiler->rdVector3d(); m_ptOrigin = pFiler->rdPoint3d(); ODA_ASSERT_ONCE(OdZero(m_dStartData)); m_uFlags = pFiler->rdInt64(); return eOk; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::dgnOutFields(OdDgFiler* pFiler) const { pFiler->wrDouble(m_dStartData); pFiler->wrDouble(m_dStemLength); pFiler->wrDouble(m_dRadius); pFiler->wrVector3d(m_vrDirection); pFiler->wrPoint3d(m_ptOrigin); pFiler->wrInt64(m_uFlags); } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::scaleData(double dScale) { m_dStemLength *= dScale; m_dRadius *= dScale; m_ptOrigin *= dScale; } //---------------------------------------------------------- bool OdDgAutoplantBoltImpl::subWorldDraw(OdGiWorldDraw* pWd) const { // Doen't draw entity in shaded mode. if (pWd && ((pWd->regenType() == kOdGiHideOrShadeCommand) || (pWd->regenType() == kOdGiRenderCommand))) { if( m_uFlags & 0x7 ) return true; } return false; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::subViewportDraw(OdGiViewportDraw *pVd) const { const OdGiViewport& viewport = pVd->viewport(); OdGeMatrix3d matTransform = viewport.getEyeToWorldTransform(); OdGeMatrix3d matTransformBack = matTransform; matTransformBack = matTransformBack.invert(); OdGeVector3d vrDir = m_vrDirection; OdGeVector3d vrZAxis = OdGeVector3d::kZAxis; OdGePoint3d ptLineStart = m_ptOrigin; OdGePoint3d ptLineEnd = m_ptOrigin + vrDir * m_dStemLength; ptLineStart.transformBy(matTransformBack); ptLineEnd.transformBy(matTransformBack); vrZAxis.transformBy(matTransform); ptLineStart.z = 0; ptLineEnd.z = 0; ptLineStart.transformBy(matTransform); ptLineEnd.transformBy(matTransform); vrDir = ptLineEnd - ptLineStart; if (vrDir.isZeroLength()) vrDir = m_vrDirection; else vrDir.normalize(); vrDir = vrZAxis.crossProduct(vrDir); OdGePoint3d linePts[2]; linePts[0] = m_ptOrigin; linePts[1] = m_ptOrigin + vrDir * m_dStemLength; OdGiSubEntityTraits& traits = pVd->subEntityTraits(); OdGiFillType oldFill = traits.fillType(); if( (pVd->regenType() == kOdGiHideOrShadeCommand) || (pVd->regenType() == kOdGiRenderCommand) ) traits.setFillType(kOdGiFillAlways); pVd->geometry().polyline(2, linePts); pVd->geometry().circle(linePts[1] + vrDir * m_dRadius, m_dRadius, vrZAxis); traits.setFillType(oldFill); } //---------------------------------------------------------- OdResult OdDgAutoplantBoltImpl::subGetGeomExtents(OdGeExtents3d& extents) const { OdGeVector3d vrDir = m_vrDirection; if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kXAxis; else vrDir.normalize(); OdGeVector3d vrZAxis = OdGeVector3d::kZAxis; if (vrDir.isParallelTo(vrZAxis)) vrZAxis = OdGeVector3d::kXAxis; vrDir = vrZAxis.crossProduct(vrDir); OdGePoint3d linePts[2]; linePts[0] = m_ptOrigin; linePts[1] = m_ptOrigin + vrDir * m_dStemLength; extents.addPoint(linePts[0]); extents.addPoint(linePts[1]); OdGePoint3d ptCircleCenter = linePts[1] + vrDir * m_dRadius; OdGeVector3d vrCircleRef = vrZAxis.perpVector(); for (OdUInt32 i = 0; i < 16; i++) { extents.addPoint(ptCircleCenter + vrCircleRef * m_dRadius); vrCircleRef.rotateBy(OdaPI / 8, vrZAxis); } return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantBoltImpl::subGetGeomExtents(const OdDgElementId& idView, OdGeExtents3d& extents) const { OdDgViewPtr pView; if( !idView.isNull() ) pView = idView.openObject(OdDg::kForRead); OdGeMatrix3d rotation; if (!pView.isNull()) { if (pView->getUseCameraFlag()) { pView->getCameraRotation(rotation); rotation.transposeIt(); } else { pView->getOrthographyRotation(rotation); rotation.transposeIt(); } } OdGeMatrix3d matTransformBack = rotation; matTransformBack = matTransformBack.invert(); OdGeVector3d vrDir = m_vrDirection; OdGeVector3d vrZAxis = OdGeVector3d::kZAxis; OdGePoint3d ptLineStart = m_ptOrigin; OdGePoint3d ptLineEnd = m_ptOrigin + vrDir * m_dStemLength; ptLineStart.transformBy(matTransformBack); ptLineEnd.transformBy(matTransformBack); vrZAxis.transformBy(rotation); ptLineStart.z = 0; ptLineEnd.z = 0; ptLineStart.transformBy(rotation); ptLineEnd.transformBy(rotation); vrDir = ptLineEnd - ptLineStart; if (vrDir.isZeroLength()) vrDir = m_vrDirection; else vrDir.normalize(); vrDir = vrZAxis.crossProduct(vrDir); OdGePoint3d linePts[2]; linePts[0] = m_ptOrigin; linePts[1] = m_ptOrigin + vrDir * m_dStemLength; extents.addPoint(linePts[0]); extents.addPoint(linePts[1]); OdGePoint3d ptCircleCenter = linePts[1] + vrDir * m_dRadius; OdGeVector3d vrCircleRef = vrZAxis.perpVector(); for( OdUInt32 i = 0; i < 16; i++ ) { extents.addPoint(ptCircleCenter + vrCircleRef * m_dRadius); vrCircleRef.rotateBy(OdaPI / 8, vrZAxis); } return eOk; } //---------------------------------------------------------- OdResult OdDgAutoplantBoltImpl::subExplode(OdRxObjectPtrArray& entitySet, const OdDgAutoplantBolt* pEnt) const { return pEnt->explodeGeometry(entitySet); } //---------------------------------------------------------- OdResult OdDgAutoplantBoltImpl::transformBy(const OdGeMatrix3d& xfm) { m_ptOrigin.transformBy(xfm); m_vrDirection.transformBy(xfm); m_vrDirection.normalize(); m_dRadius *= xfm.scale(); m_dStemLength *= xfm.scale(); return eOk; } //---------------------------------------------------------- OdUInt64 OdDgAutoplantBoltImpl::getFlags() const { return m_uFlags; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::setFlags(OdUInt64 uFlags) { m_uFlags = uFlags; } //---------------------------------------------------------- double OdDgAutoplantBoltImpl::getStartData() const { return m_dStartData; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::setStartData(double dStartData) { m_dStartData = dStartData; } //---------------------------------------------------------- OdGePoint3d OdDgAutoplantBoltImpl::getOrigin() const { return m_ptOrigin; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::setOrigin(const OdGePoint3d& ptOrigin) { m_ptOrigin = ptOrigin; } //---------------------------------------------------------- OdGeVector3d OdDgAutoplantBoltImpl::getDirection() const { return m_vrDirection; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::setDirection(const OdGeVector3d& vrDirection) { m_vrDirection = vrDirection; } //---------------------------------------------------------- double OdDgAutoplantBoltImpl::getRadius() const { return m_dRadius; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::setRadius(double dRadius) { m_dRadius = dRadius; } //---------------------------------------------------------- double OdDgAutoplantBoltImpl::getStemLength() const { return m_dStemLength; } //---------------------------------------------------------- void OdDgAutoplantBoltImpl::setStemLength(double dLength) { m_dStemLength = dLength; } //----------------------------------------------------------