From e64813827d7b8ae320fac2fd5008db03d9817137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Mon, 18 Sep 2017 19:50:07 +0200 Subject: [PATCH] Expose global placement calculation to python API --- src/App/GeoFeatureGroupExtension.cpp | 3 +++ src/App/GeoFeaturePy.xml | 7 +++++++ src/App/GeoFeaturePyImp.cpp | 15 +++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/App/GeoFeatureGroupExtension.cpp b/src/App/GeoFeatureGroupExtension.cpp index 68d1ba2fa2..ec45732545 100644 --- a/src/App/GeoFeatureGroupExtension.cpp +++ b/src/App/GeoFeatureGroupExtension.cpp @@ -112,6 +112,9 @@ DocumentObject* GeoFeatureGroupExtension::getGroupOfObject(const DocumentObject* Base::Placement GeoFeatureGroupExtension::globalGroupPlacement() { + if(getExtendedObject()->isRecomputing()) + throw Base::Exception("Global placement cannot be calculated on recompute"); + return recursiveGroupPlacement(this); } diff --git a/src/App/GeoFeaturePy.xml b/src/App/GeoFeaturePy.xml index d2f165ce2a..5ded4b50b7 100644 --- a/src/App/GeoFeaturePy.xml +++ b/src/App/GeoFeaturePy.xml @@ -18,6 +18,13 @@ returns all possible paths to the root of the document + + + Returns the placement of the object in the global coordinate space, respecting all stacked relationships. + Note: This function is not available during recompute, as there the placements of parents can change + after the execution of this object, rendering the result wrong. + + Returns the property name of the actual geometry or None. diff --git a/src/App/GeoFeaturePyImp.cpp b/src/App/GeoFeaturePyImp.cpp index 9eee2ea815..d95ea35a90 100644 --- a/src/App/GeoFeaturePyImp.cpp +++ b/src/App/GeoFeaturePyImp.cpp @@ -28,6 +28,7 @@ // inclusion of the generated files (generated out of GeoFeaturePy.xml) #include "GeoFeaturePy.h" #include "GeoFeaturePy.cpp" +#include #include using namespace App; @@ -44,6 +45,20 @@ PyObject* GeoFeaturePy::getPaths(PyObject * /*args*/) return 0; } +PyObject* GeoFeaturePy::getGlobalPlacement(PyObject * args) { + + if (!PyArg_ParseTuple(args, "")) + return 0; + + try { + Base::Placement p = static_cast(getDocumentObjectPtr())->globalPlacement(); + 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, ""))