PartDesignGui: move feature with its dependencies
This commit is contained in:
parent
1944d43f28
commit
85015ef494
|
@ -587,6 +587,11 @@ void CmdPartDesignMoveFeature::activated(int iMsg)
|
|||
std::vector<App::DocumentObject*> features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId());
|
||||
if (features.empty()) return;
|
||||
|
||||
// Collect dependenies of the selected features
|
||||
std::vector<App::DocumentObject*> 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<App::DocumentObject*> 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
|
||||
|
|
|
@ -42,11 +42,16 @@
|
|||
|
||||
#include <Mod/PartDesign/App/Feature.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include <Mod/PartDesign/App/FeaturePrimitive.h>
|
||||
#include <Mod/PartDesign/App/FeatureSketchBased.h>
|
||||
#include <Mod/PartDesign/App/FeatureBoolean.h>
|
||||
#include <Mod/PartDesign/App/DatumCS.h>
|
||||
|
||||
#include "ReferenceSelection.h"
|
||||
#include "Utils.h"
|
||||
#include "WorkflowManager.h"
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// Helper for Body
|
||||
//===========================================================================
|
||||
|
@ -341,4 +346,75 @@ void relinkToBody (PartDesign::Feature *feature) {
|
|||
}
|
||||
}
|
||||
|
||||
} /* PartDesignGui */
|
||||
std::vector<App::DocumentObject*> collectDependencies(std::vector<App::DocumentObject*>& features)
|
||||
{
|
||||
std::set<App::DocumentObject*> 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<Sketcher::SketchObject*>(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<PartDesign::FeaturePrimitive*>(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<PartDesign::ProfileBased*>(feat);
|
||||
Part::Part2DObject* sk = prim->getVerifiedSketch(true);
|
||||
if (sk) {
|
||||
unique_objs.insert(static_cast<App::DocumentObject*>(sk));
|
||||
}
|
||||
if (auto prop = static_cast<App::PropertyLinkList*>(prim->getPropertyByName("Sections"))) {
|
||||
for (App::DocumentObject* obj : prop->getValues()) {
|
||||
unique_objs.insert(obj);
|
||||
}
|
||||
}
|
||||
if (auto prop = static_cast<App::PropertyLinkSub*>(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<App::PropertyLinkSub*>(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<App::PropertyLinkSub*>(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<PartDesign::Boolean*>(feat);
|
||||
for (App::DocumentObject* obj : boolobj->Bodies.getValues()) {
|
||||
unique_objs.insert(boolobj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<App::DocumentObject*> result;
|
||||
result.reserve(unique_objs.size());
|
||||
for (std::set<App::DocumentObject*>::iterator it = unique_objs.begin(); it != unique_objs.end(); ++it)
|
||||
result.push_back(*it);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
} /* PartDesignGui */
|
|
@ -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<App::DocumentObject*> collectDependencies(std::vector<App::DocumentObject*>& features);
|
||||
|
||||
} /* PartDesignGui */
|
||||
|
||||
#endif /* end of include guard: UTILS_H_CS5LK2ZQ */
|
||||
|
|
Loading…
Reference in New Issue
Block a user