From 28def3059257aa32b78f98c676b8a7e9a75d228c Mon Sep 17 00:00:00 2001 From: edi271 Date: Wed, 5 Apr 2023 13:16:43 +0200 Subject: [PATCH] Move getTrianglePoint to DrawUtil --- src/Mod/TechDraw/App/DrawUtil.cpp | 15 ++++++++++ src/Mod/TechDraw/App/DrawUtil.h | 1 + src/Mod/TechDraw/Gui/CommandExtensionDims.cpp | 29 +++++-------------- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 4f0f34730e..c1ed48d271 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -1050,6 +1050,21 @@ bool DrawUtil::circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C) } } +Base::Vector3d DrawUtil::getTrianglePoint(Base::Vector3d p1, Base::Vector3d dir, Base::Vector3d p2) +{ + // get third point of a perpendicular triangle + // p1, p2 ...vertexes of hypothenusis, dir ...direction of one kathete, p3 ...3rd vertex + float a = -dir.y; + float b = dir.x; + float c1 = p1.x * a + p1.y * b; + float c2 = -p2.x * b + p2.y * a; + float ab = a * a + b * b; + float x = (c1 * a - c2 * b) / ab; + float y = (c2 * a + c1 * b) / ab; + Base::Vector3d p3(x,y,0.0); + return p3; +} + int DrawUtil::countSubShapes(TopoDS_Shape shape, TopAbs_ShapeEnum subShape) { int count = 0; diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index f7a4121e0f..d10cf10b0c 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -202,6 +202,7 @@ public: static bool isCrazy(TopoDS_Edge e); static Base::Vector3d getFaceCenter(TopoDS_Face f); static bool circulation(Base::Vector3d A, Base::Vector3d B, Base::Vector3d C); + static Base::Vector3d getTrianglePoint(Base::Vector3d p1, Base::Vector3d d, Base::Vector3d p2); static int countSubShapes(TopoDS_Shape shape, TopAbs_ShapeEnum subShape); static void encodeXmlSpecialChars(std::string& inoutText); static std::list sort_Edges(double tol3d, std::list& edges); diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index b6a6a4fa76..8bbcf5955f 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -75,7 +75,6 @@ namespace TechDrawGui { //internal helper functions void _selectDimensionAttributes(Gui::Command* cmd); std::vector_getDimensions(std::vector selection, std::string needDimType); - Base::Vector3d _getTrianglePoint(Base::Vector3d p1, Base::Vector3d d, Base::Vector3d p2); std::vector _getVertexInfo(TechDraw::DrawViewPart* objFeat, std::vector subNames); TechDraw::DrawViewDimension* _createLinDimension(Gui::Command* cmd, @@ -698,7 +697,7 @@ void execPosObliqueChainDimension(Gui::Command* cmd) { float xDim = dim->X.getValue(); float yDim = dim->Y.getValue(); Base::Vector3d pDim(xDim, yDim, 0.0); - Base::Vector3d p3 = _getTrianglePoint(pMaster, dirMaster, pDim); + Base::Vector3d p3 = DrawUtil::getTrianglePoint(pMaster, dirMaster, pDim); dim->X.setValue(p3.x); dim->Y.setValue(p3.y); } @@ -1014,7 +1013,7 @@ void execCascadeObliqueDimension(Gui::Command* cmd) { Base::Vector3d dirMaster = pp.second() - pp.first(); dirMaster.y = -dirMaster.y; Base::Vector3d origin(0.0, 0.0, 0.0); - Base::Vector3d ipDelta = _getTrianglePoint(pMaster, dirMaster, origin); + Base::Vector3d ipDelta = DrawUtil::getTrianglePoint(pMaster, dirMaster, origin); float dimDistance = activeDimAttributes.getCascadeSpacing(); Base::Vector3d delta = ipDelta.Normalize() * dimDistance; int i = 0; @@ -1022,7 +1021,7 @@ void execCascadeObliqueDimension(Gui::Command* cmd) { float xDim = dim->X.getValue(); float yDim = dim->Y.getValue(); Base::Vector3d pDim(xDim, yDim, 0.0); - Base::Vector3d p3 = _getTrianglePoint(pMaster, dirMaster, pDim); + Base::Vector3d p3 = DrawUtil::getTrianglePoint(pMaster, dirMaster, pDim); p3 = p3 + delta * i; dim->X.setValue(p3.x); dim->Y.setValue(p3.y); @@ -1331,12 +1330,12 @@ void execCreateObliqueChainDimension(Gui::Command* cmd) { Base::Vector3d pMaster = allVertexes[0].point; Base::Vector3d dirMaster = pMaster - allVertexes[1].point; Base::Vector3d origin(0.0, 0.0, 0.0); - Base::Vector3d delta = _getTrianglePoint(pMaster, dirMaster, origin); + Base::Vector3d delta = DrawUtil::getTrianglePoint(pMaster, dirMaster, origin); float dimDistance = activeDimAttributes.getCascadeSpacing(); delta = delta.Normalize() * dimDistance; double scale = objFeat->getScale(); for (dimVertex oldVertex : allVertexes) { - Base::Vector3d nextPoint = _getTrianglePoint(pMaster, dirMaster, oldVertex.point); + Base::Vector3d nextPoint = DrawUtil::getTrianglePoint(pMaster, dirMaster, oldVertex.point); nextPoint.y = -nextPoint.y; oldVertex.point.y = -oldVertex.point.y; if ((oldVertex.point - nextPoint).Length() > 0.01) { @@ -1680,12 +1679,12 @@ void execCreateObliqueCoordDimension(Gui::Command* cmd) { Base::Vector3d pMaster = allVertexes[0].point; Base::Vector3d dirMaster = pMaster - allVertexes[1].point; Base::Vector3d origin(0.0, 0.0, 0.0); - Base::Vector3d delta = _getTrianglePoint(pMaster, dirMaster, origin); + Base::Vector3d delta = DrawUtil::getTrianglePoint(pMaster, dirMaster, origin); float dimDistance = activeDimAttributes.getCascadeSpacing(); delta = delta.Normalize() * dimDistance; double scale = objFeat->getScale(); for (dimVertex oldVertex : allVertexes) { - Base::Vector3d nextPoint = _getTrianglePoint(pMaster, dirMaster, oldVertex.point); + Base::Vector3d nextPoint = DrawUtil::getTrianglePoint(pMaster, dirMaster, oldVertex.point); nextPoint.y = -nextPoint.y; oldVertex.point.y = -oldVertex.point.y; if ((oldVertex.point - nextPoint).Length() > 0.01) { @@ -2319,20 +2318,6 @@ namespace TechDrawGui { return vertexes; } - Base::Vector3d _getTrianglePoint(Base::Vector3d p1, Base::Vector3d dir, Base::Vector3d p2) { - // get third point of a perpendicular triangle - // p1, p2 ...vertexes of hypothenusis, dir ...direction of one kathete, p3 ...3rd vertex - float a = -dir.y; - float b = dir.x; - float c1 = p1.x * a + p1.y * b; - float c2 = -p2.x * b + p2.y * a; - float ab = a * a + b * b; - float x = (c1 * a - c2 * b) / ab; - float y = (c2 * a + c1 * b) / ab; - Base::Vector3d p3(x, y, 0.0); - return p3; - } - std::vector_getDimensions(std::vector selection, std::string needDimType) { // get all selected dimensions of type needDimType std::vector validDimension;