From b3a1fd967681c8f1120c4356c8bd87edf3326af9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 23 Dec 2024 23:39:16 +0100 Subject: [PATCH] App: Add methods to get base and direction of datum element Add the methods DatumElement::getBasePoint() and DatumElement::getDirection() to hide implementation details and guarantee consistent behaviour. Using the methods fixes several regressions in: * Constraint::getDirection * PolarPattern::getTransformations --- src/App/Datums.cpp | 15 +++++++++++++++ src/App/Datums.h | 2 ++ src/Mod/Fem/App/FemConstraint.cpp | 6 ++---- src/Mod/PartDesign/App/FeatureLinearPattern.cpp | 4 +--- src/Mod/PartDesign/App/FeatureMirrored.cpp | 6 ++---- src/Mod/PartDesign/App/FeaturePolarPattern.cpp | 4 +--- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 5 ++--- 7 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/App/Datums.cpp b/src/App/Datums.cpp index a551381c45..4f16c1ebff 100644 --- a/src/App/Datums.cpp +++ b/src/App/Datums.cpp @@ -87,6 +87,21 @@ bool DatumElement::isOriginFeature() return lcs ? lcs->isOrigin() : false; } +Base::Vector3d DatumElement::getBasePoint() const +{ + Base::Placement plc = Placement.getValue(); + return plc.getPosition(); +} + +Base::Vector3d DatumElement::getDirection() const +{ + Base::Vector3d dir(0.0, 0.0, 1.0); + Base::Placement plc = Placement.getValue(); + Base::Rotation rot = plc.getRotation(); + rot.multVec(dir, dir); + return dir; +} + // ---------------------------------------------------------------------------- LocalCoordinateSystem::LocalCoordinateSystem() diff --git a/src/App/Datums.h b/src/App/Datums.h index b199ffebd8..a99682f0c6 100644 --- a/src/App/Datums.h +++ b/src/App/Datums.h @@ -51,6 +51,8 @@ public: /// Finds the origin object this plane belongs to App::LocalCoordinateSystem* getLCS(); + Base::Vector3d getBasePoint() const; + Base::Vector3d getDirection() const; bool getCameraAlignmentDirection(Base::Vector3d& direction, const char* subname) const override; diff --git a/src/Mod/Fem/App/FemConstraint.cpp b/src/Mod/Fem/App/FemConstraint.cpp index e52c5b5ff3..91ae981391 100644 --- a/src/Mod/Fem/App/FemConstraint.cpp +++ b/src/Mod/Fem/App/FemConstraint.cpp @@ -516,14 +516,12 @@ const Base::Vector3d Constraint::getDirection(const App::PropertyLinkSub& direct } if (obj->isDerivedFrom()) { - Base::Vector3d vec(1.0, 0.0, 0.0); - static_cast(obj)->Placement.getValue().multVec(vec, vec); + Base::Vector3d vec = static_cast(obj)->getDirection(); return vec; } if (obj->isDerivedFrom()) { - Base::Vector3d vec(0.0, 0.0, 1.0); - static_cast(obj)->Placement.getValue().multVec(vec, vec); + Base::Vector3d vec = static_cast(obj)->getDirection(); return vec; } diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp index 1a0265850f..58455b4624 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp @@ -161,9 +161,7 @@ const std::list LinearPattern::getTransformations(const std::vectorisDerivedFrom()) { App::Line* line = static_cast(refObject); - Base::Rotation rot = line->Placement.getValue().getRotation(); - Base::Vector3d d(1,0,0); - rot.multVec(d, d); + Base::Vector3d d = line->getDirection(); dir = gp_Dir(d.x, d.y, d.z); } else if (refObject->isDerivedFrom()) { if (subStrings[0].empty()) diff --git a/src/Mod/PartDesign/App/FeatureMirrored.cpp b/src/Mod/PartDesign/App/FeatureMirrored.cpp index 15af22543b..f9c530bf98 100644 --- a/src/Mod/PartDesign/App/FeatureMirrored.cpp +++ b/src/Mod/PartDesign/App/FeatureMirrored.cpp @@ -116,11 +116,9 @@ const std::list Mirrored::getTransformations(const std::vector(refObject)) { - Base::Vector3d base = plane->Placement.getValue().getPosition(); + Base::Vector3d base = plane->getBasePoint(); axbase = gp_Pnt(base.x, base.y, base.z); - Base::Rotation rot = plane->Placement.getValue().getRotation(); - Base::Vector3d dir(0,0,1); - rot.multVec(dir, dir); + Base::Vector3d dir = plane->getDirection(); axdir = gp_Dir(dir.x, dir.y, dir.z); return true; } diff --git a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp index 9f337c571d..f2c4802f2b 100644 --- a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp +++ b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp @@ -129,9 +129,7 @@ const std::list PolarPattern::getTransformations(const std::vectorisDerivedFrom()) { App::Line* line = static_cast(refObject); - Base::Rotation rot = line->Placement.getValue().getRotation(); - Base::Vector3d d(1,0,0); - rot.multVec(d, d); + Base::Vector3d d = line->getDirection(); axdir = gp_Dir(d.x, d.y, d.z); } else if (refObject->isDerivedFrom()) { if (subStrings[0].empty()) diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 92f22da99a..d04833e39b 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -1358,9 +1358,8 @@ void ProfileBased::getAxis(const App::DocumentObject * pcReferenceAxis, const st if (pcReferenceAxis->isDerivedFrom()) { auto* line = static_cast(pcReferenceAxis); - Base::Placement plc = line->Placement.getValue(); - base = plc.getPosition(); - plc.getRotation().multVec(Base::Vector3d(0, 0, 1), dir); + base = line->getBasePoint(); + dir = line->getDirection(); verifyAxisFunc(checkAxis, sketchplane, gp_Dir(dir.x, dir.y, dir.z)); return;