From f49ddaea453fffcc5769961cd989a0dcee0bb746 Mon Sep 17 00:00:00 2001 From: Sergo Date: Sun, 21 Aug 2016 00:45:16 -0400 Subject: [PATCH] PD MoveFeature:Check if feature has dependencies in source body --- src/Mod/PartDesign/Gui/CommandBody.cpp | 14 +++- src/Mod/PartDesign/Gui/Utils.cpp | 100 +++++++++++++++++++------ src/Mod/PartDesign/Gui/Utils.h | 8 +- 3 files changed, 98 insertions(+), 24 deletions(-) diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index eed7634abc46..bdb3c9545cbe 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -587,8 +587,17 @@ void CmdPartDesignMoveFeature::activated(int iMsg) std::vector features = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()); if (features.empty()) return; + // Check if all features are valid to move + if (std::any_of(std::begin(features), std::end(features), [](App::DocumentObject* obj){return !PartDesignGui::isFeatureMovable(obj); })) + { + //show messagebox and cancel + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"), + QObject::tr("Some of the selected features has dependencies in the source body")); + return; + } + // Collect dependenies of the selected features - std::vector dependencies = PartDesignGui::collectDependencies(features); + std::vector dependencies = PartDesignGui::collectMovableDependencies(features); if (!dependencies.empty()) features.insert(std::end(features), std::begin(dependencies), std::end(dependencies)); @@ -665,6 +674,9 @@ void CmdPartDesignMoveFeature::activated(int iMsg) arg( QString::fromLatin1( sketch->Label.getValue () ) ) ); } } + + //relink origin for sketches and datums (coordinates) + PartDesignGui::relinkToOrigin(feat, target); } updateActive(); diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index ebc4aed7148d..5707b5b8d742 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -346,21 +346,71 @@ void relinkToBody (PartDesign::Feature *feature) { } } -std::vector collectDependencies(std::vector& features) +bool isFeatureMovable(App::DocumentObject* const feat) +{ + if (feat->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId())) { + auto prim = static_cast(feat); + App::DocumentObject* bf = prim->BaseFeature.getValue(); + if (bf) + return false; + } + + if (feat->getTypeId().isDerivedFrom(PartDesign::FeaturePrimitive::getClassTypeId())) { + auto prim = static_cast(feat); + + if (!isFeatureMovable(prim->CoordinateSystem.getValue())) + return false; + } + + if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { + auto prim = static_cast(feat); + auto sk = prim->getVerifiedSketch(true); + + if (!isFeatureMovable(static_cast(sk))) + return false; + + if (auto prop = static_cast(prim->getPropertyByName("Sections"))) { + if (std::any_of(prop->getValues().begin(), prop->getValues().end(), [](App::DocumentObject* obj){return !isFeatureMovable(obj); })) + return false; + } + + if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { + App::DocumentObject* axis = prop->getValue(); + if (!isFeatureMovable(static_cast(axis))) + return false; + } + + if (auto prop = static_cast(prim->getPropertyByName("Spine"))) { + App::DocumentObject* axis = prop->getValue(); + if (!isFeatureMovable(static_cast(axis))) + return false; + } + + if (auto prop = static_cast(prim->getPropertyByName("AuxillerySpine"))) { + App::DocumentObject* axis = prop->getValue(); + if (!isFeatureMovable(static_cast(axis))) + return false; + } + + } + + if (feat->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) || + feat->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { + auto attachable = static_cast(feat); + App::DocumentObject* support = attachable->Support.getValue(); + if (!support || !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) + return false; + } + + return true; +} + +std::vector collectMovableDependencies(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); @@ -369,7 +419,7 @@ std::vector collectDependencies(std::vectorgetTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { auto prim = static_cast(feat); Part::Part2DObject* sk = prim->getVerifiedSketch(true); @@ -395,26 +445,34 @@ std::vector collectDependencies(std::vector(prim->getPropertyByName("AuxillerySpine"))) { App::DocumentObject* axis = prop->getValue(); - if (axis && !PartDesign::Feature::isDatum(axis)){ + if (axis && !axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ 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); + result.insert(result.begin(), unique_objs.begin(), unique_objs.end()); + return result; } +void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody) +{ + if (feat->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) || + feat->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { + auto attachable = static_cast(feat); + App::DocumentObject* support = attachable->Support.getValue(); + if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) { + auto originfeat = static_cast(support); + App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue()); + if (targetOriginFeature) { + attachable->Support.setValue(static_cast(targetOriginFeature), ""); + } + } + } +} } /* PartDesignGui */ \ No newline at end of file diff --git a/src/Mod/PartDesign/Gui/Utils.h b/src/Mod/PartDesign/Gui/Utils.h index c13f510229bc..79b4ae03544c 100644 --- a/src/Mod/PartDesign/Gui/Utils.h +++ b/src/Mod/PartDesign/Gui/Utils.h @@ -64,8 +64,12 @@ 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); +/// Check if feature is dependent on anything except movable sketches and datums +bool isFeatureMovable(App::DocumentObject* feature); +/// Collect dependencies of the features during the move. Dependecies should only be dependent on origin +std::vector collectMovableDependencies(std::vector& features); +/// Relink sketches and datums to target body's origin +void relinkToOrigin(App::DocumentObject* feature, PartDesign::Body* body); } /* PartDesignGui */