/////////////////////////////////////////////////////////////////////////////// // 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 "DgTextNodeGripPoints.h" #include "DgTextNode.h" #include "RxObjectImpl.h" #include "Ge/GeLine2d.h" #include "Ge/GeLine3d.h" #include "Ge/GePlane.h" #include "Ge/GeInterval.h" //----------------------------------------------------------------------------------------------------- OdResult OdDgTextNodeGripPointsPE::getGripPoints(const OdDgElement* pEnt, OdGePoint3dArray& gripPoints)const { if (pEnt->isKindOf(OdDgTextNode2d::desc())) { OdDgTextNode2dPtr pTextNode2d = pEnt; OdGePoint2dArray arrBoundingPts; pTextNode2d->getBoundingPoints(arrBoundingPts); OdGeVector2d vrXAxis2d = arrBoundingPts[3] - arrBoundingPts[0]; OdGeVector2d vrYAxis2d = arrBoundingPts[1] - arrBoundingPts[0]; OdGeVector3d vrXAxis(vrXAxis2d.x, vrXAxis2d.y, 0.0); OdGeVector3d vrYAxis(vrYAxis2d.x, vrYAxis2d.y, 0.0); OdGePoint3d ptBase(arrBoundingPts[0].x, arrBoundingPts[0].y, 0.0); gripPoints.push_back(ptBase); gripPoints.push_back(ptBase + vrYAxis * 0.5); gripPoints.push_back(ptBase + vrYAxis); gripPoints.push_back(ptBase + vrYAxis + vrXAxis * 0.5); gripPoints.push_back(ptBase + vrYAxis + vrXAxis); gripPoints.push_back(ptBase + vrYAxis*0.5 + vrXAxis); gripPoints.push_back(ptBase + vrXAxis); gripPoints.push_back(ptBase + vrXAxis*0.5); } else { OdDgTextNode3dPtr pTextNode3d = pEnt; OdGePoint3dArray arrBoundingPts; pTextNode3d->getBoundingPoints(arrBoundingPts); pTextNode3d->getBoundingPoints(arrBoundingPts); OdGeVector3d vrXAxis = arrBoundingPts[3] - arrBoundingPts[0]; OdGeVector3d vrYAxis = arrBoundingPts[1] - arrBoundingPts[0]; OdGePoint3d ptBase = arrBoundingPts[0]; gripPoints.push_back(ptBase); gripPoints.push_back(ptBase + vrYAxis * 0.5); gripPoints.push_back(ptBase + vrYAxis); gripPoints.push_back(ptBase + vrYAxis + vrXAxis * 0.5); gripPoints.push_back(ptBase + vrYAxis + vrXAxis); gripPoints.push_back(ptBase + vrYAxis * 0.5 + vrXAxis); gripPoints.push_back(ptBase + vrXAxis); gripPoints.push_back(ptBase + vrXAxis * 0.5); } return eOk; } //----------------------------------------------------------------------------------------------------- OdResult OdDgTextNodeGripPointsPE::moveGripPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { unsigned size = indices.size(); if (size == 0) return eOk; OdGePoint3dArray arrGripPts; getGripPoints(pEnt, arrGripPts); OdUInt32 uBestIndex = 0;; for (OdUInt32 i = 0; i < indices.size(); i++) { if (indices[i] % 2 != 0) { uBestIndex = indices[i]; break; } } if( uBestIndex != 0 && (uBestIndex < 8) ) { OdGePoint3d ptStart; OdGePoint3d ptEnd; switch( uBestIndex ) { case 1: { ptStart = arrGripPts[5]; ptEnd = arrGripPts[1]; } break; case 3: { ptStart = arrGripPts[7]; ptEnd = arrGripPts[3]; } break; case 5: { ptStart = arrGripPts[1]; ptEnd = arrGripPts[5]; } break; case 7: { ptStart = arrGripPts[3]; ptEnd = arrGripPts[7]; } break; } OdGeLine3d line3d(ptStart, ptEnd); OdGePoint3d ptNewEnd = ptEnd + offset; ptNewEnd = line3d.closestPointTo(ptNewEnd); double dOldLength = ptStart.distanceTo(ptEnd); double dNewLength = ptStart.distanceTo(ptNewEnd); double dScale = dNewLength / dOldLength; if (!OdEqual(dScale, 1.0)) { OdGeMatrix3d matTransform = OdGeMatrix3d::scaling(dScale, ptStart); pEnt->transformBy(matTransform); } } return eOk; } OdResult OdDgTextNodeGripPointsPE::getStretchPoints(const OdDgElement* pEnt, OdGePoint3dArray& stretchPoints) const { OdResult res = getGripPoints(pEnt, stretchPoints); if (res == eOk) { stretchPoints.resize(stretchPoints.size() - 1); } return res; } OdResult OdDgTextNodeGripPointsPE::moveStretchPointsAt(OdDgElement* pEnt, const OdIntArray& indices, const OdGeVector3d& offset) { return moveGripPointsAt(pEnt, indices, offset); } OdResult OdDgTextNodeGripPointsPE::getOsnapPoints(const OdDgElement* pEnt, OdDgElement::OsnapMode osnapMode, OdGsMarker gsSelectionMark, const OdGePoint3d& pickPoint, const OdGePoint3d& lastPoint, const OdGeMatrix3d& xWorldToEye, OdGePoint3dArray& snapPoints) const { OdGePoint3dArray gripPoints; OdResult res = getGripPoints(pEnt, gripPoints); if (res != eOk || gripPoints.size() < 3) return res; switch (osnapMode) { case OdDgElement::kOsModeEnd: { snapPoints.append(gripPoints[0]); //origin } break; case OdDgElement::kOsModeStart: { snapPoints.append(gripPoints[1]); //origin } break; default: break; } return eOk; }