/////////////////////////////////////////////////////////////////////////////// // 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 "DgAutoplantConeImpl.h" #include "DgAutoplantCone.h" #include "DgXAttribute.h" #include "DgAutoplantEntityProperties.h" #include "Ge/GePlane.h" //============================================================================================== // // OdDgAutoplantCone // //============================================================================================== ODRX_CONS_DEFINE_MEMBERS(OdDgAutoplantCone, OdDgProxyGraphicsElement, DGELEMENT_CONSTR) //============================================================================================== OdDgAutoplantCone::OdDgAutoplantCone() { set3dFormatFlag(true); setElementType(OdDgElement::kTypeExtraGraphicsElement); } //============================================================================================== OdUInt32 OdDgAutoplantCone::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 OdDgAutoplantCone::scaleDataAfterWorkingUnitsChange(double dScale) { return m_impl.scaleData(dScale); } //============================================================================================== bool OdDgAutoplantCone::subWorldDraw(OdGiWorldDraw* pWd) const { return m_impl.subWorldDraw(pWd, this); } //============================================================================================== void OdDgAutoplantCone::subViewportDraw(OdGiViewportDraw *pVd) const { return m_impl.subViewportDraw(pVd, this); } //============================================================================================== OdResult OdDgAutoplantCone::subGetGeomExtents(OdGeExtents3d& extents) const { return m_impl.subGetGeomExtents(extents, this); } //============================================================================================== OdResult OdDgAutoplantCone::subGetGeomExtents(const OdDgElementId& idView, OdGeExtents3d& extents) const { return m_impl.subGetGeomExtents(idView, extents, this); } //============================================================================================== OdResult OdDgAutoplantCone::subExplode(OdRxObjectPtrArray& entitySet) const { return m_impl.subExplode(entitySet, this); } //============================================================================================== OdResult OdDgAutoplantCone::transformBy(const OdGeMatrix3d& xfm) { assertWriteEnabled(); return m_impl.transformBy(xfm); } //============================================================================================== bool OdDgAutoplantCone::allowToConvertFromElement(OdDgElement* pBaseElement) const { if (pBaseElement && (pBaseElement->getElementType() == OdDgElement::kTypeExtraGraphicsElement) && (OdDgElement::getElementExtendedType(pBaseElement) == (OdUInt64)(OdDgAutoplantCone::kType)) ) { return true; } return false; } //============================================================================================== void OdDgAutoplantCone::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 OdDgAutoplantCone::dgnInFields(OdDgFiler* pFiler) { return m_impl.dgnInFields(pFiler); } //============================================================================================== void OdDgAutoplantCone::dgnOutFields(OdDgFiler* pFiler) const { m_impl.dgnOutFields(pFiler); } //============================================================================================== OdGePoint3d OdDgAutoplantCone::getCenter1() const { return m_impl.getCenter1(); } //============================================================================================== void OdDgAutoplantCone::setCenter1(const OdGePoint3d& ptCenter) { assertWriteEnabled(); m_impl.setCenter1( ptCenter); } //============================================================================================== OdGePoint3d OdDgAutoplantCone::getCenter2() const { return m_impl.getCenter2(); } //============================================================================================== void OdDgAutoplantCone::setCenter2(const OdGePoint3d& ptCenter) { assertWriteEnabled(); m_impl.setCenter2(ptCenter); } //============================================================================================== OdGeVector3d OdDgAutoplantCone::getCenter2Offset() const { return m_impl.getCenter2Offset(); } //============================================================================================== void OdDgAutoplantCone::setCenter2Offset(const OdGeVector3d& vrDirection) { assertWriteEnabled(); m_impl.setCenter2Offset(vrDirection); } //============================================================================================== double OdDgAutoplantCone::getRadius1() const { return m_impl.getRadius1(); } //============================================================================================== void OdDgAutoplantCone::setRadius1(double dRadius) { assertWriteEnabled(); m_impl.setRadius1(dRadius); } //============================================================================================== double OdDgAutoplantCone::getRadius2() const { return m_impl.getRadius2(); } //============================================================================================== void OdDgAutoplantCone::setRadius2(double dRadius) { assertWriteEnabled(); m_impl.setRadius2(dRadius); } //============================================================================================== bool OdDgAutoplantCone::getDrawStartCapFlag() const { return m_impl.getDrawStartCapFlag(); } //============================================================================================== void OdDgAutoplantCone::setDrawStartCapFlag(bool bSet) { assertWriteEnabled(); m_impl.setDrawStartCapFlag(bSet); } //============================================================================================== bool OdDgAutoplantCone::getDrawEndCapFlag() const { return m_impl.getDrawEndCapFlag(); } //============================================================================================== void OdDgAutoplantCone::setDrawEndCapFlag(bool bSet) { assertWriteEnabled(); m_impl.setDrawEndCapFlag(bSet); } //============================================================================================== OdUInt64 OdDgAutoplantCone::getFlags() const { return m_impl.getFlags(); } //============================================================================================== void OdDgAutoplantCone::setFlags(OdUInt64 uFlags) { assertWriteEnabled(); m_impl.setFlags(uFlags); } //============================================================================================== // CDA Properties for OdDgAutoplantCone //============================================================================================== //----------------------------------------------------------------------------------------------------------------------- // property: Center1 //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeCenter1Property::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getCenter1(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeCenter1Property::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setCenter1(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Center2 //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeCenter2Property::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getCenter2(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeCenter2Property::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setCenter2(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Center2Offset //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeCenter2OffsetProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getCenter2Offset(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeCenter2OffsetProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setCenter2Offset(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Radius1 //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeRadius1Property::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getRadius1(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeRadius1Property::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setRadius1(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Radius2 //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeRadius2Property::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getRadius2(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeRadius2Property::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setRadius2(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Draw Start Cap Flag //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeDrawStartCapFlagProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getDrawStartCapFlag(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeDrawStartCapFlagProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setDrawStartCapFlag(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Draw End Cap Flag //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeDrawEndCapFlagProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getDrawEndCapFlag(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeDrawEndCapFlagProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setDrawEndCapFlag(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Flags //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeFlagsProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getFlags(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantConeFlagsProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantConePtr pObj = OdDgAutoplantCone::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setFlags(*rxvalue_cast(&value)); return eOk; } //============================================================================================== // Grip and snap points for OdDgAutoplantCone //============================================================================================== OdResult OdDgAutoplantConeGripPointsPE::getGripPoints(const OdDgElement* pEnt, OdGePoint3dArray& gripPoints)const { unsigned int size = gripPoints.size(); gripPoints.resize(size + 4); OdDgAutoplantConePtr pCone = pEnt; OdGeVector3d vrDir = pCone->getCenter2() - pCone->getCenter1(); if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGeVector3d vrXRef = vrDir.perpVector(); gripPoints[size] = pCone->getCenter1(); gripPoints[size + 1] = pCone->getCenter2() + pCone->getCenter2Offset(); gripPoints[size + 2] = pCone->getCenter1() + vrXRef * pCone->getRadius1(); gripPoints[size + 3] = pCone->getCenter2() + pCone->getCenter2Offset() + vrXRef * pCone->getRadius2(); return eOk; } //============================================================================================== OdResult OdDgAutoplantConeGripPointsPE::moveGripPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { unsigned size = indices.size(); if (size == 0) return eOk; OdDgAutoplantConePtr pCone = pEnt; if (size > 1 || indices[0] == 4) { pCone->transformBy(OdGeMatrix3d::translation(offset)); } else if (indices[0] == 0) { pCone->setCenter1(pCone->getCenter1() + offset); } else if (indices[0] == 1) { pCone->setCenter2(pCone->getCenter2() + offset); } else if (indices[0] == 2) { OdGeVector3d vrDir = pCone->getCenter2() - pCone->getCenter1(); if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGeVector3d vrXRef = vrDir.perpVector(); OdGePoint3d ptRadius = pCone->getCenter1() + vrXRef * pCone->getRadius1(); OdGePlane planeBase(ptRadius, vrDir); OdGePoint3d ptNewRadius = ptRadius + offset; ptNewRadius = ptNewRadius.project(planeBase, vrDir); pCone->setRadius1(ptNewRadius.distanceTo(pCone->getCenter1())); } else { OdGeVector3d vrDir = pCone->getCenter2() - pCone->getCenter1(); if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGeVector3d vrXRef = vrDir.perpVector(); OdGePoint3d ptRadius = pCone->getCenter2() + pCone->getCenter2Offset() + vrXRef * pCone->getRadius2(); OdGePlane planeBase(ptRadius, vrDir); OdGePoint3d ptNewRadius = ptRadius + offset; ptNewRadius = ptNewRadius.project(planeBase, vrDir); pCone->setRadius2(ptNewRadius.distanceTo(pCone->getCenter2() + pCone->getCenter2Offset())); } return eOk; } //============================================================================================== OdResult OdDgAutoplantConeGripPointsPE::getStretchPoints(const OdDgElement* pEnt, OdGePoint3dArray& stretchPoints) const { OdResult res = getGripPoints(pEnt, stretchPoints); if (res == eOk) { stretchPoints.resize(stretchPoints.size() - 1); } return res; } //============================================================================================== OdResult OdDgAutoplantConeGripPointsPE::moveStretchPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { return moveGripPointsAt(pEnt, indices, offset); } //============================================================================================== OdResult OdDgAutoplantConeGripPointsPE::getOsnapPoints(const OdDgElement* pEnt, OdDgElement::OsnapMode osnapMode, OdGsMarker gsSelectionMark, const OdGePoint3d& pickPoint, const OdGePoint3d& lastPoint, const OdGeMatrix3d& xWorldToEye, OdGePoint3dArray& snapPoints) const { OdDgAutoplantConePtr pCone = pEnt; OdArray arrBottom; OdArray arrTop; OdGePoint3d ptBottom = pCone->getCenter1(); OdGePoint3d ptTop = pCone->getCenter2(); OdGeVector3d vrDir = ptTop - ptBottom; if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGeVector3d vrXRefBase = vrDir.perpVector() * pCone->getRadius1(); OdGeVector3d vrXRefTop = vrDir.perpVector() * pCone->getRadius2(); ptTop += pCone->getCenter2Offset(); switch (osnapMode) { case OdDgElement::kOsModeCen: { snapPoints.append(ptBottom); snapPoints.append(ptTop); } break; case OdDgElement::kOsModeEnd: { for( OdUInt32 i = 0; i < 8; i++ ) { snapPoints.append(ptBottom + vrXRefBase); snapPoints.append(ptTop + pCone->getCenter2Offset() + vrXRefTop); vrXRefBase.rotateBy(OdaPI4, vrDir); vrXRefTop.rotateBy(OdaPI4, vrDir); } } break; case OdDgElement::kOsModeMid: { for (OdUInt32 i = 0; i < 8; i++) { OdGePoint3d ptSegStart = ptBottom + vrXRefBase; OdGePoint3d ptSegEnd = ptTop + vrXRefTop; OdGeVector3d vrDirLine = ptTop - ptBottom; snapPoints.append(ptBottom + vrDirLine / 2.0); vrXRefBase.rotateBy(OdaPI4, vrDir); vrXRefTop.rotateBy(OdaPI4, vrDir); } } break; default: { } break; } return eOk; } //==============================================================================================