From c90da8e5fbba937833aaee046519b159074ddf01 Mon Sep 17 00:00:00 2001 From: Sergo Date: Wed, 24 Aug 2016 00:41:52 -0400 Subject: [PATCH] fix relinkToOrigin, remove source body from list, etc --- src/Mod/PartDesign/Gui/CommandBody.cpp | 28 ++++++++++++++++++++++---- src/Mod/PartDesign/Gui/Utils.cpp | 21 ++++++++++++++----- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/Mod/PartDesign/Gui/CommandBody.cpp b/src/Mod/PartDesign/Gui/CommandBody.cpp index c61a69f30a7f..ed86fb7f8999 100644 --- a/src/Mod/PartDesign/Gui/CommandBody.cpp +++ b/src/Mod/PartDesign/Gui/CommandBody.cpp @@ -603,12 +603,32 @@ void CmdPartDesignMoveFeature::activated(int iMsg) // Create a list of all bodies in this part std::vector bodies = getDocument()->getObjectsOfType(Part::BodyBase::getClassTypeId()); + + std::set source_bodies; + for (auto feat : features) { + PartDesign::Body* source = PartDesign::Body::findBodyOf(feat); + source_bodies.insert(static_cast(source)); + } + + std::vector target_bodies; + for (auto body : bodies) { + if (!source_bodies.count(body)) + target_bodies.push_back(body); + } - // Ask user to select the target body + if (target_bodies.empty()) + { + QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Features cannot be moved"), + QObject::tr("There are no other bodies to move to")); + return; + } + + // Ask user to select the target body (remove source bodies from list) bool ok; QStringList items; - for (std::vector::iterator it = bodies.begin(); it != bodies.end(); ++it) - items.push_back(QString::fromUtf8((*it)->Label.getValue())); + for (auto body : target_bodies) { + items.push_back(QString::fromUtf8(body->Label.getValue())); + } QString text = QInputDialog::getItem(Gui::getMainWindow(), qApp->translate("PartDesign_MoveFeature", "Select body"), qApp->translate("PartDesign_MoveFeature", "Select a body from the list"), @@ -617,7 +637,7 @@ void CmdPartDesignMoveFeature::activated(int iMsg) int index = items.indexOf(text); if (index < 0) return; - PartDesign::Body* target = static_cast(bodies[index]); + PartDesign::Body* target = static_cast(target_bodies[index]); openCommand("Move an object"); diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 5707b5b8d742..ddb234a3b3d3 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -394,11 +394,10 @@ bool isFeatureMovable(App::DocumentObject* const feat) } - if (feat->getTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) || - feat->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { + if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { auto attachable = static_cast(feat); App::DocumentObject* support = attachable->Support.getValue(); - if (!support || !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) + if (support && !support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) return false; } @@ -461,8 +460,7 @@ std::vector collectMovableDependencies(std::vectorgetTypeId().isDerivedFrom(Sketcher::SketchObject::getClassTypeId()) || - feat->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) { + if (feat->getTypeId().isDerivedFrom(Part::AttachableObject::getClassTypeId())) { auto attachable = static_cast(feat); App::DocumentObject* support = attachable->Support.getValue(); if (support && support->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())) { @@ -473,6 +471,19 @@ void relinkToOrigin(App::DocumentObject* feat, PartDesign::Body* targetbody) } } } + else if (feat->getTypeId().isDerivedFrom(PartDesign::ProfileBased::getClassTypeId())) { + auto prim = static_cast(feat); + if (auto prop = static_cast(prim->getPropertyByName("ReferenceAxis"))) { + App::DocumentObject* axis = prop->getValue(); + if (axis && axis->getTypeId().isDerivedFrom(App::OriginFeature::getClassTypeId())){ + auto originfeat = static_cast(axis); + App::OriginFeature* targetOriginFeature = targetbody->getOrigin()->getOriginFeature(originfeat->Role.getValue()); + if (targetOriginFeature) { + prop->setValue(static_cast(targetOriginFeature), std::vector(0)); + } + } + } + } } } /* PartDesignGui */ \ No newline at end of file