From fac0a1740fabed4de52eab757ddf6165f35f08c4 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Mon, 6 Mar 2023 19:59:57 +0800 Subject: [PATCH] PartDesign: do not include transform for sub-object in Feature --- src/Mod/PartDesign/App/Feature.cpp | 38 ++++++++++++++++++++++++++++++ src/Mod/PartDesign/App/Feature.h | 5 ++++ 2 files changed, 43 insertions(+) diff --git a/src/Mod/PartDesign/App/Feature.cpp b/src/Mod/PartDesign/App/Feature.cpp index 257ef40234..fee65f0313 100644 --- a/src/Mod/PartDesign/App/Feature.cpp +++ b/src/Mod/PartDesign/App/Feature.cpp @@ -234,6 +234,44 @@ Body* Feature::getFeatureBody() const { return nullptr; } +App::DocumentObject *Feature::getSubObject(const char *subname, + PyObject **pyObj, Base::Matrix4D *pmat, bool transform, int depth) const +{ + if (subname && subname != Data::ComplexGeoData::findElementName(subname)) { + const char * dot = strchr(subname,'.'); + if (dot) { + auto body = PartDesign::Body::findBodyOf(this); + if (body) { + auto feat = body->Group.find(std::string(subname, dot)); + if (feat) { + Base::Matrix4D _mat; + if (!transform) { + // Normally the parent object is supposed to transform + // the sub-object using its own placement. So, if no + // transform is requested, (i.e. no parent + // transformation), we just need to NOT apply the + // transformation. + // + // But PartDesign features (including sketch) are + // supposed to be contained inside a body. It makes + // little sense to transform its sub-object. So if 'no + // transform' is requested, we need to actively apply + // an inverse trasnform. + _mat = Placement.getValue().inverse().toMatrix(); + if (pmat) + *pmat *= _mat; + else + pmat = &_mat; + } + return feat->getSubObject(dot+1, pyObj, pmat, true, depth+1); + } + } + } + } + return Part::Feature::getSubObject(subname, pyObj, pmat, transform, depth); +} + + }//namespace PartDesign namespace App { diff --git a/src/Mod/PartDesign/App/Feature.h b/src/Mod/PartDesign/App/Feature.h index 347cf4c884..7e671a8142 100644 --- a/src/Mod/PartDesign/App/Feature.h +++ b/src/Mod/PartDesign/App/Feature.h @@ -81,6 +81,11 @@ public: return "PartDesignGui::ViewProvider"; } + + App::DocumentObject *getSubObject(const char *subname, + PyObject **pyObj, Base::Matrix4D *pmat, bool transform, int depth) const override; + + protected: /**