From 5e079d331be191901e2a79c158179b8cd0f472ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Tr=C3=B6ger?= Date: Mon, 18 Sep 2017 20:08:34 +0200 Subject: [PATCH] Improve GeoFeatureGroup claim children algorithm and remove special Body impelmentation --- .../ViewProviderGeoFeatureGroupExtension.cpp | 49 ++++++------ src/Mod/PartDesign/Gui/ViewProviderBody.cpp | 74 ------------------- src/Mod/PartDesign/Gui/ViewProviderBody.h | 4 - 3 files changed, 23 insertions(+), 104 deletions(-) diff --git a/src/Gui/ViewProviderGeoFeatureGroupExtension.cpp b/src/Gui/ViewProviderGeoFeatureGroupExtension.cpp index ceba53d326..952dee857f 100644 --- a/src/Gui/ViewProviderGeoFeatureGroupExtension.cpp +++ b/src/Gui/ViewProviderGeoFeatureGroupExtension.cpp @@ -67,35 +67,32 @@ std::vector ViewProviderGeoFeatureGroupExtension::extensio std::vector ViewProviderGeoFeatureGroupExtension::extensionClaimChildren(void) const { - //we must be careful which objects to claim, as there might be stacked relations inside the coordinate system, - //like pad/sketch - auto* ext = getExtendedViewProvider()->getObject()->getExtensionByType(); - if(ext) { - //filter out all objects with more than one inlink, as they are most likely hold by another - //object in the tree - std::vector claim; - auto objs = ext->Group.getValues(); + auto* group = getExtendedViewProvider()->getObject()->getExtensionByType(); + const std::vector &model = group->Group.getValues (); + std::set outSet; //< set of objects not to claim (childrens of childrens) - for(auto obj : objs) { + // search for objects handled (claimed) by the features + for( auto obj: model){ + //stuff in annother geofeaturegroup is not in the model anyway + if (!obj || obj->hasExtension(App::GeoFeatureGroupExtension::getExtensionClassTypeId())) { continue; } + + Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj ); + if (!vp || vp == getExtendedViewProvider()) { continue; } - auto vin = obj->getInList(); - - //we don't want to count objects that are deleted or part of other geo feature groups. - //Second criteria is actually not possible in normal operation, but only in some error - //condition. But then it is needed to understand the problem for the user - auto grp = getExtendedViewProvider()->getObject(); - vin.erase(std::remove_if(vin.begin(), vin.end(), [&](App::DocumentObject* obj)->bool { - return obj->isRemoving() || - obj == grp || - App::GeoFeatureGroupExtension::getGroupOfObject(obj)!=grp; - }), vin.end()); - - if(vin.empty()) - claim.push_back(obj); - } - return claim; + auto children = vp->claimChildren(); + std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr); } - return std::vector(); + + // remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct + std::vector Result; + + // claim for rest content not claimed by any other features + std::remove_copy_if (model.begin(), model.end(), std::back_inserter (Result), + [outSet] (App::DocumentObject* obj) { + return outSet.find (obj) != outSet.end(); + } ); + + return Result; } void ViewProviderGeoFeatureGroupExtension::extensionAttach(App::DocumentObject* pcObject) diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp index 591318fd9d..b201a8c03e 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.cpp @@ -178,80 +178,6 @@ bool ViewProviderBody::doubleClicked(void) return true; } -std::vector ViewProviderBody::claimChildren(void)const -{ - PartDesign::Body* body= static_cast ( getObject () ); - const std::vector &model = body->Group.getValues (); - std::set outSet; //< set of objects not to claim (childrens of childrens) - - // search for objects handled (claimed) by the features - for( auto obj: model){ - if (!obj) { continue; } - Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider ( obj ); - if (!vp) { continue; } - - auto children = vp->claimChildren(); - std::remove_copy ( children.begin (), children.end (), std::inserter (outSet, outSet.begin () ), nullptr); - } - - // remove the otherwise handled objects, preserving their order so the order in the TreeWidget is correct - std::vector Result; - - if (body->Origin.getValue()) { // Clame for the Origin - Result.push_back (body->Origin.getValue()); - } - - // claim for rest content not claimed by any other features - std::remove_copy_if (model.begin(), model.end(), std::back_inserter (Result), - [outSet] (App::DocumentObject* obj) { - return outSet.find (obj) != outSet.end(); - } ); - - return Result; -} - - -std::vector ViewProviderBody::claimChildren3D(void)const - -{ - - PartDesign::Body* body = static_cast(getObject()); - - - - const std::vector & features = body->Group.getValues(); - - - - std::vector rv; - - - - if ( body->Origin.getValue() ) { // Add origin - - rv.push_back (body->Origin.getValue()); - - } - - if ( body->BaseFeature.getValue() ) { // Add Base Feature - - rv.push_back (body->BaseFeature.getValue()); - - } - - - - // Add all other stuff - - std::copy (features.begin(), features.end(), std::back_inserter (rv) ); - - - - return rv; - -} - - // TODO To be deleted (2015-09-08, Fat-Zer) //void ViewProviderBody::updateTree() diff --git a/src/Mod/PartDesign/Gui/ViewProviderBody.h b/src/Mod/PartDesign/Gui/ViewProviderBody.h index ef28a9dccf..29804b1a51 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderBody.h +++ b/src/Mod/PartDesign/Gui/ViewProviderBody.h @@ -57,10 +57,6 @@ public: virtual bool doubleClicked(void); virtual void setupContextMenu(QMenu* menu, QObject* receiver, const char* member); - virtual std::vector claimChildren(void)const; - - // returns the root node where the children gets collected(3D) - virtual std::vector claimChildren3D(void)const; virtual std::vector< std::string > getDisplayModes(void) const; virtual void setDisplayMode(const char* ModeName);