/////////////////////////////////////////////////////////////////////////////// // 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 "DgAutoplantCylinderImpl.h" #include "DgAutoplantCylinder.h" #include "DgXAttribute.h" #include "DgAutoplantEntityProperties.h" #include "Ge/GePlane.h" //============================================================================================== // // OdDgAutoplantCylinder // //============================================================================================== ODRX_CONS_DEFINE_MEMBERS(OdDgAutoplantCylinder, OdDgProxyGraphicsElement, DGELEMENT_CONSTR) //============================================================================================== OdDgAutoplantCylinder::OdDgAutoplantCylinder() { set3dFormatFlag(true); setElementType(OdDgElement::kTypeExtraGraphicsElement); } //============================================================================================== OdUInt32 OdDgAutoplantCylinder::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 OdDgAutoplantCylinder::scaleDataAfterWorkingUnitsChange(double dScale) { return m_impl.scaleData(dScale); } //============================================================================================== bool OdDgAutoplantCylinder::subWorldDraw(OdGiWorldDraw* pWd) const { return m_impl.subWorldDraw(pWd, this); } //============================================================================================== void OdDgAutoplantCylinder::subViewportDraw(OdGiViewportDraw *pVd) const { return m_impl.subViewportDraw(pVd, this); } //============================================================================================== OdResult OdDgAutoplantCylinder::subGetGeomExtents(OdGeExtents3d& extents) const { return m_impl.subGetGeomExtents(extents, this); } //============================================================================================== OdResult OdDgAutoplantCylinder::subGetGeomExtents(const OdDgElementId& idView, OdGeExtents3d& extents) const { return m_impl.subGetGeomExtents(idView, extents, this); } //============================================================================================== OdResult OdDgAutoplantCylinder::subExplode(OdRxObjectPtrArray& entitySet) const { return m_impl.subExplode(entitySet, this); } //============================================================================================== OdResult OdDgAutoplantCylinder::transformBy(const OdGeMatrix3d& xfm) { assertWriteEnabled(); return m_impl.transformBy(xfm); } //============================================================================================== bool OdDgAutoplantCylinder::allowToConvertFromElement(OdDgElement* pBaseElement) const { if (pBaseElement && (pBaseElement->getElementType() == OdDgElement::kTypeExtraGraphicsElement) && (OdDgElement::getElementExtendedType(pBaseElement) == (OdUInt64)(OdDgAutoplantCylinder::kType)) ) { return true; } return false; } //============================================================================================== void OdDgAutoplantCylinder::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 OdDgAutoplantCylinder::dgnInFields(OdDgFiler* pFiler) { return m_impl.dgnInFields(pFiler); } //============================================================================================== void OdDgAutoplantCylinder::dgnOutFields(OdDgFiler* pFiler) const { m_impl.dgnOutFields(pFiler); } //============================================================================================== OdGePoint3d OdDgAutoplantCylinder::getCenter1() const { return m_impl.getCenter1(); } //============================================================================================== void OdDgAutoplantCylinder::setCenter1(const OdGePoint3d& ptCenter) { assertWriteEnabled(); m_impl.setCenter1( ptCenter); } //============================================================================================== OdGePoint3d OdDgAutoplantCylinder::getCenter2() const { return m_impl.getCenter2(); } //============================================================================================== void OdDgAutoplantCylinder::setCenter2(const OdGePoint3d& ptCenter) { assertWriteEnabled(); m_impl.setCenter2(ptCenter); } //============================================================================================== double OdDgAutoplantCylinder::getRadius() const { return m_impl.getRadius(); } //============================================================================================== void OdDgAutoplantCylinder::setRadius(double dRadius) { assertWriteEnabled(); m_impl.setRadius(dRadius); } //============================================================================================== bool OdDgAutoplantCylinder::getDrawStartCapFlag() const { return m_impl.getDrawStartCapFlag(); } //============================================================================================== void OdDgAutoplantCylinder::setDrawStartCapFlag(bool bSet) { assertWriteEnabled(); m_impl.setDrawStartCapFlag(bSet); } //============================================================================================== bool OdDgAutoplantCylinder::getDrawEndCapFlag() const { return m_impl.getDrawEndCapFlag(); } //============================================================================================== void OdDgAutoplantCylinder::setDrawEndCapFlag(bool bSet) { assertWriteEnabled(); m_impl.setDrawEndCapFlag(bSet); } //============================================================================================== OdUInt64 OdDgAutoplantCylinder::getFlags() const { return m_impl.getFlags(); } //============================================================================================== void OdDgAutoplantCylinder::setFlags(OdUInt64 uFlags) { assertWriteEnabled(); m_impl.setFlags(uFlags); } //============================================================================================== // CDA Properties for OdDgAutoplantCylinder //============================================================================================== //----------------------------------------------------------------------------------------------------------------------- // property: Center1 //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderCenter1Property::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getCenter1(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderCenter1Property::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setCenter1(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Center2 //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderCenter2Property::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getCenter2(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderCenter2Property::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setCenter2(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Radius //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderRadiusProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getRadius(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderRadiusProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setRadius(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Draw Start Cap Flag //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderDrawStartCapFlagProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getDrawStartCapFlag(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderDrawStartCapFlagProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setDrawStartCapFlag(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Draw End Cap Flag //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderDrawEndCapFlagProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getDrawEndCapFlag(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderDrawEndCapFlagProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setDrawEndCapFlag(*rxvalue_cast(&value)); return eOk; } //----------------------------------------------------------------------------------------------------------------------- // property: Flags //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderFlagsProperty::subGetValue(const OdRxObject* pO, OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; value = pObj->getFlags(); return eOk; } //----------------------------------------------------------------------------------------------------------------------- OdResult OdDgAutoplantCylinderFlagsProperty::subSetValue(OdRxObject* pO, const OdRxValue& value) const { OdDgAutoplantCylinderPtr pObj = OdDgAutoplantCylinder::cast(pO); if (pObj.isNull()) return eNotApplicable; pObj->setFlags(*rxvalue_cast(&value)); return eOk; } //============================================================================================== // Grip and snap points for OdDgAutoplantCylinder //============================================================================================== OdResult OdDgAutoplantCylinderGripPointsPE::getGripPoints(const OdDgElement* pEnt, OdGePoint3dArray& gripPoints)const { unsigned int size = gripPoints.size(); gripPoints.resize(size + 3); OdDgAutoplantCylinderPtr pCylinder = pEnt; OdGePoint3d ptCenter1 = pCylinder->getCenter1(); OdGePoint3d ptCenter2 = pCylinder->getCenter2(); OdGeVector3d vrDir = ptCenter2 - ptCenter1; if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGeVector3d vrXRef = vrDir.perpVector(); gripPoints[size] = ptCenter1; gripPoints[size + 1] = ptCenter2; gripPoints[size + 2] = ptCenter1 + vrXRef * pCylinder->getRadius(); return eOk; } //============================================================================================== OdResult OdDgAutoplantCylinderGripPointsPE::moveGripPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { unsigned size = indices.size(); if (size == 0) return eOk; OdDgAutoplantCylinderPtr pCylinder = pEnt; if (size > 1 || indices[0] == 3) { pCylinder->transformBy(OdGeMatrix3d::translation(offset)); } else if (indices[0] == 0) { pCylinder->setCenter1(pCylinder->getCenter1() + offset); } else if (indices[0] == 1) { pCylinder->setCenter1(pCylinder->getCenter2() + offset); } else { OdGePoint3d ptCenter1 = pCylinder->getCenter1(); OdGePoint3d ptCenter2 = pCylinder->getCenter2(); OdGeVector3d vrDir = ptCenter2 - ptCenter1; if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGeVector3d vrXRef = vrDir.perpVector(); OdGePoint3d ptRadius = ptCenter1 + vrXRef * pCylinder->getRadius(); OdGePlane planeBase(ptRadius, vrDir); OdGePoint3d ptNewRadius = ptRadius + offset; ptNewRadius = ptNewRadius.project(planeBase, vrDir); pCylinder->setRadius(ptNewRadius.distanceTo(ptCenter1)); } return eOk; } //============================================================================================== OdResult OdDgAutoplantCylinderGripPointsPE::getStretchPoints(const OdDgElement* pEnt, OdGePoint3dArray& stretchPoints) const { OdResult res = getGripPoints(pEnt, stretchPoints); if (res == eOk) { stretchPoints.resize(stretchPoints.size() - 1); } return res; } //============================================================================================== OdResult OdDgAutoplantCylinderGripPointsPE::moveStretchPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { return moveGripPointsAt(pEnt, indices, offset); } //============================================================================================== OdResult OdDgAutoplantCylinderGripPointsPE::getOsnapPoints(const OdDgElement* pEnt, OdDgElement::OsnapMode osnapMode, OdGsMarker gsSelectionMark, const OdGePoint3d& pickPoint, const OdGePoint3d& lastPoint, const OdGeMatrix3d& xWorldToEye, OdGePoint3dArray& snapPoints) const { OdDgAutoplantCylinderPtr pCylinder = pEnt; OdArray arrBottom; OdArray arrTop; OdGePoint3d ptBottom = pCylinder->getCenter1(); OdGePoint3d ptTop = pCylinder->getCenter2(); OdGeVector3d vrDir = ptTop - ptBottom; double dHeight = vrDir.length(); if (vrDir.isZeroLength()) vrDir = OdGeVector3d::kZAxis; else vrDir.normalize(); OdGeVector3d vrXRef = vrDir.perpVector() * pCylinder->getRadius(); 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 + vrXRef); snapPoints.append(ptTop + vrXRef); vrXRef.rotateBy(OdaPI4, vrDir); } } break; case OdDgElement::kOsModeMid: { OdGePoint3d ptCenter = ptBottom + vrDir * dHeight / 2.0; for (OdUInt32 i = 0; i < 8; i++) { snapPoints.append(ptCenter + vrXRef); vrXRef.rotateBy(OdaPI4, vrDir); } } break; default: { } break; } return eOk; } //==============================================================================================