diff --git a/src/App/GeoFeature.cpp b/src/App/GeoFeature.cpp index 8142ec1ec1..8ce3c94718 100644 --- a/src/App/GeoFeature.cpp +++ b/src/App/GeoFeature.cpp @@ -27,6 +27,7 @@ #endif #include "GeoFeature.h" +#include "GeoFeatureGroupExtension.h" #include using namespace App; @@ -55,6 +56,16 @@ void GeoFeature::transformPlacement(const Base::Placement &transform) this->Placement.setValue(plm); } +Base::Placement GeoFeature::globalPlacement() +{ + auto* group = GeoFeatureGroupExtension::getGroupOfObject(this); + if(group) { + auto ext = group->getExtensionByType(); + return ext->globalGroupPlacement() * Placement.getValue(); + } + return Placement.getValue(); +} + const PropertyComplexGeoData* GeoFeature::getPropertyOfGeometry() const { return nullptr; diff --git a/src/App/GeoFeature.h b/src/App/GeoFeature.h index 292d63ca9d..b030c606c0 100644 --- a/src/App/GeoFeature.h +++ b/src/App/GeoFeature.h @@ -66,6 +66,20 @@ public: * @return the Python binding object */ virtual PyObject* getPyObject(void); + + /** + * @brief Calculates the placement in the global reference coordinate system + * + * 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 annother local coordinate system, the Placement + * property does only give the local transformation. This function can be used to calculate the + * placement of the object in the global reference coordinate system taking all stacked local + * system into account. + * + * @return Base::Placement The transformation from the global reference coordinate system + */ + Base::Placement globalPlacement(); }; } //namespace App diff --git a/src/App/GeoFeatureGroupExtension.cpp b/src/App/GeoFeatureGroupExtension.cpp index d10391559f..3b3b9a7e54 100644 --- a/src/App/GeoFeatureGroupExtension.cpp +++ b/src/App/GeoFeatureGroupExtension.cpp @@ -160,6 +160,25 @@ DocumentObject* GeoFeatureGroupExtension::getGroupOfObject(const DocumentObject* return 0; } +Base::Placement GeoFeatureGroupExtension::globalGroupPlacement() { + + return recursiveGroupPlacement(this); +} + + +Base::Placement GeoFeatureGroupExtension::recursiveGroupPlacement(GeoFeatureGroupExtension* group) { + + + auto inList = group->getExtendedObject()->getInList(); + for(auto* link : inList) { + if(link->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) + return recursiveGroupPlacement(link->getExtensionByType()) * group->placement().getValue(); + } + + return group->placement().getValue(); +} + + // Python feature --------------------------------------------------------- namespace App { diff --git a/src/App/GeoFeatureGroupExtension.h b/src/App/GeoFeatureGroupExtension.h index c6fe4a9f9f..ecb51cf66a 100644 --- a/src/App/GeoFeatureGroupExtension.h +++ b/src/App/GeoFeatureGroupExtension.h @@ -70,12 +70,27 @@ public: * default is true */ static DocumentObject* getGroupOfObject(const DocumentObject* obj, bool indirect=true); + + /** + * @brief Calculates the global placement of this group + * + * The returned placement describes the transformation from the global reference coordinate + * system to the local coordinate system of this geo feature group. If this group has a no parent + * GeoFeatureGroup the returned placement is the one of this group. For multiple stacked + * GeoFeatureGroups the returned Placement is the combination of all parent placements including + * ths one of this group. + * @return Base::Placement The transformation from global reference system to the groups local system + */ + Base::Placement globalGroupPlacement(); /// Returns true if the given DocumentObject is DocumentObjectGroup but not GeoFeatureGroup static bool isNonGeoGroup(const DocumentObject* obj) { return obj->hasExtension(GroupExtension::getExtensionClassTypeId()) && !obj->hasExtension(GeoFeatureGroupExtension::getExtensionClassTypeId()); } + +private: + Base::Placement recursiveGroupPlacement(GeoFeatureGroupExtension* group); }; typedef ExtensionPythonT> GeoFeatureGroupExtensionPython;