From 85015ef494fe9f67af8f7aee3bf443a4a5ae24a6 Mon Sep 17 00:00:00 2001 From: Sergo Date: Tue, 9 Aug 2016 23:16:37 -0400 Subject: [PATCH] PartDesignGui: move feature with its dependencies --- src/Mod/PartDesign/Gui/CommandBody.cpp | 8 ++- src/Mod/PartDesign/Gui/Utils.cpp | 78 +++++++++++++++++++++++++- src/Mod/PartDesign/Gui/Utils.h | 3 + 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index 16b58ca32..eed7634ab 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -587,6 +587,11 @@ void CmdPartDesignMoveFeature::activated(int iMsg) std::vector features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (features.empty()) return; + // Collect dependenies of the selected features + std::vector dependencies = PartDesignGui::collectDependencies(features); + if (!dependencies.empty()) + features.insert(std::end(features), std::begin(dependencies), std::end(dependencies)); + // Create a list of all bodies in this part std::vector bodies = getDocument()->getObjectsOfType(Part::BodyBase::getClassTypeId()); @@ -634,7 +639,8 @@ void CmdPartDesignMoveFeature::activated(int iMsg) // If we removed the tip of the source body, make the new tip visible if ( featureWasTip ) { App::DocumentObject * sourceNewTip = source->Tip.getValue(); - doCommand(Gui,"Gui.activeDocument().show(\"%s\")", sourceNewTip->getNameInDocument()); + if (sourceNewTip) + doCommand(Gui,"Gui.activeDocument().show(\"%s\")", sourceNewTip->getNameInDocument()); } // Hide old tip and show new tip (the moved feature) of the target body diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 8b7e21f25..ebc4aed71 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -42,11 +42,16 @@ #include #include +#include +#include +#include +#include #include "ReferenceSelection.h" #include "Utils.h" #include "WorkflowManager.h" + //=========================================================================== // Helper for Body //=========================================================================== @@ -341,4 +346,75 @@ void relinkToBody (PartDesign::Feature *feature) { } } -} /* PartDesignGui */ +std::vector collectDependencies(std::vector& features) +{ + std::set unique_objs; + + for (auto const &feat : features) + { + // Get support of the sketch + if (feat->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId())) { + //not sure if support feature should be moved + //Sketcher::SketchObject *sketch = static_cast(feat); + //App::DocumentObject* support = sketch->Support.getValue(); + //if (support) + // temp.push_back(support); + } + + // Get coordinate system object + if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) { + auto prim = static_cast(feat); + App::DocumentObject* cs = prim->CoordinateSystem.getValue(); + if (cs && cs->getTypeId() == PartDesign::CoordinateSystem::getClassTypeId()) + unique_objs.insert(cs); + } + + // Get parts from profile based features + if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { + auto prim = static_cast(feat); + Part::Part2DObject* sk = prim->getVerifiedSketch(true); + if (sk) { + unique_objs.insert(static_cast(sk)); + } + if (auto prop = static_cast(prim->getPropertyByName("Sections"))) { + for (App::DocumentObject* obj : prop->getValues()) { + unique_objs.insert(obj); + } + } + if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ + unique_objs.insert(axis); + } + } + if (auto prop = static_cast(prim->getPropertyByName("Spine"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ + unique_objs.insert(axis); + } + } + if (auto prop = static_cast(prim->getPropertyByName("AuxillerySpine"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && !PartDesign::Feature::isDatum(axis)){ + unique_objs.insert(axis); + } + } + } + + if (feat->getTypeId().isDerivedFrom(PartDesign::Boolean::getClassTypeId())) { + auto boolobj = static_cast(feat); + for (App::DocumentObject* obj : boolobj->Bodies.getValues()) { + unique_objs.insert(boolobj); + } + } + } + + std::vector result; + result.reserve(unique_objs.size()); + for (std::set::iterator it = unique_objs.begin(); it != unique_objs.end(); ++it) + result.push_back(*it); + return result; +} + + +} /* PartDesignGui */ \ No newline at end of file diff --git a/src/Mod/PartDesign/Gui/Utils.h b/src/Mod/PartDesign/Gui/Utils.h index 5666192cc..c13f51022 100644 --- a/src/Mod/PartDesign/Gui/Utils.h +++ b/src/Mod/PartDesign/Gui/Utils.h @@ -64,6 +64,9 @@ bool isAnyNonPartDesignLinksTo ( PartDesign::Feature *feature, bool respectGroup /// Relink all nonPartDesign features to the body instead of the given partDesign Feature void relinkToBody ( PartDesign::Feature *feature ); +/// Collect all needed dependencies of the features during the move from one body to another +std::vector collectDependencies(std::vector& features); + } /* PartDesignGui */ #endif /* end of include guard: UTILS_H_CS5LK2ZQ */