From 306183ce26c0693374639e2f6e7cdffa8a4e9f9f Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Mon, 30 Sep 2024 10:45:22 +0200 Subject: [PATCH] Core: GeoFeature: Add python binding to the new getGlobalPlacement() --- src/App/GeoFeature.h | 3 ++- src/App/GeoFeaturePy.xml | 17 +++++++++++++++++ src/App/GeoFeaturePyImp.cpp | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/App/GeoFeature.h b/src/App/GeoFeature.h index 216f741dcd..1f35ab1e79 100644 --- a/src/App/GeoFeature.h +++ b/src/App/GeoFeature.h @@ -108,8 +108,9 @@ public: const DocumentObject *filter=nullptr,const char **element=nullptr, GeoFeature **geo=nullptr); /** - * @brief Calculates the placement in the global reference coordinate system + * @brief Deprecated. Calculates the placement in the global reference coordinate system * + * Deprecated: This does not handle App::Links correctly. Use getGlobalPlacement() instead. * In FreeCAD the GeoFeature placement describes the local placement of the object in its parent * coordinate system. This is however not always the same as the global reference system. If the * object is in a GeoFeatureGroup, hence in another local coordinate system, the Placement diff --git a/src/App/GeoFeaturePy.xml b/src/App/GeoFeaturePy.xml index aeaefe7a4e..84afc5b76b 100644 --- a/src/App/GeoFeaturePy.xml +++ b/src/App/GeoFeaturePy.xml @@ -30,6 +30,7 @@ Note: Not implemented. getGlobalPlacement() -> Base.Placement +Deprecated: This function does not handle Links correctly. Use getGlobalPlacementOf instead. Returns the placement of the object in the global coordinate space, respecting all stacked relationships. @@ -37,6 +38,22 @@ Note: This function is not available during recompute, as there the placements o can change after the execution of this object, rendering the result wrong. + + + getGlobalPlacementOf(targetObj, rootObj, subname) -> Base.Placement +Selection example: obj = "part1" sub = "linkToPart2.LinkToBody.Pad.face1" + +Global placement of Pad in this context : +getGlobalPlacementOf(pad, part1, "linkToPart2.LinkToBody.Pad.face1") + +Global placement of linkToPart2 in this context : +getGlobalPlacementOf(linkToPart2, part1, "linkToPart2.LinkToBody.Pad.face1") + +Returns the placement of the object in the global coordinate space, respecting all stacked +relationships. + + + getPropertyNameOfGeometry() -> str or None diff --git a/src/App/GeoFeaturePyImp.cpp b/src/App/GeoFeaturePyImp.cpp index 26a08a9f2d..9ee3a2d93e 100644 --- a/src/App/GeoFeaturePyImp.cpp +++ b/src/App/GeoFeaturePyImp.cpp @@ -57,6 +57,27 @@ PyObject* GeoFeaturePy::getGlobalPlacement(PyObject * args) { } } +PyObject* GeoFeaturePy::getGlobalPlacementOf(PyObject * args) { + + PyObject* pyTargetObj; + PyObject* pyRootObj; + char* pname; + + if (!PyArg_ParseTuple(args, "OOs", &pyTargetObj, &pyRootObj, &pname)) { + return nullptr; + } + auto* targetObj = static_cast(pyTargetObj)->getDocumentObjectPtr(); + auto* rootObj = static_cast(pyRootObj)->getDocumentObjectPtr(); + + try { + Base::Placement p = GeoFeature::getGlobalPlacement(targetObj, rootObj, pname); + return new Base::PlacementPy(new Base::Placement(p)); + } + catch (const Base::Exception& e) { + throw Py::RuntimeError(e.what()); + } +} + PyObject* GeoFeaturePy::getPropertyNameOfGeometry(PyObject * args) { if (!PyArg_ParseTuple(args, ""))