Assembly: Use canDragObjectToTarget in viewProviderAssembly
This commit is contained in:
committed by
Yorik van Havre
parent
3e2bc7ad3d
commit
6088fdaa96
@@ -2118,6 +2118,10 @@ bool TreeWidget::dropInDocument(QDropEvent* event, TargetItemInfo& targetInfo,
|
||||
infos.reserve(items.size());
|
||||
bool syncPlacement = TreeParams::getSyncPlacement();
|
||||
|
||||
App::AutoTransaction committer(
|
||||
da == Qt::LinkAction ? "Link object" :
|
||||
da == Qt::CopyAction ? "Copy object" : "Move object");
|
||||
|
||||
// check if items can be dragged
|
||||
for (auto& v : items) {
|
||||
auto item = v.first;
|
||||
@@ -2127,15 +2131,17 @@ bool TreeWidget::dropInDocument(QDropEvent* event, TargetItemInfo& targetInfo,
|
||||
auto vpp = parentItem->object();
|
||||
// We querry all the parents recursively.
|
||||
bool allParentsOK = true;
|
||||
while (parentItem) {
|
||||
if (!parentItem->object()->canDragObjectToTarget(obj, nullptr)) {
|
||||
auto parentItemRecursive = parentItem;
|
||||
while (parentItemRecursive) {
|
||||
if (!parentItemRecursive->object()->canDragObjectToTarget(obj, nullptr)) {
|
||||
allParentsOK = false;
|
||||
break;
|
||||
}
|
||||
parentItem = parentItem->getParentItem();
|
||||
parentItemRecursive = parentItemRecursive->getParentItem();
|
||||
}
|
||||
|
||||
if (!allParentsOK || !parentItem->object()->canDragObjects() || !parentItem->object()->canDragObject(obj)) {
|
||||
committer.close(true);
|
||||
TREE_ERR("'" << obj->getFullName() << "' cannot be dragged out of '" << parentItem->object()->getObject()->getFullName() << "'");
|
||||
return false;
|
||||
}
|
||||
@@ -2174,9 +2180,6 @@ bool TreeWidget::dropInDocument(QDropEvent* event, TargetItemInfo& targetInfo,
|
||||
|
||||
// Open command
|
||||
auto manager = Application::Instance->macroManager();
|
||||
App::AutoTransaction committer(
|
||||
da == Qt::LinkAction ? "Link object" :
|
||||
da == Qt::CopyAction ? "Copy object" : "Move object");
|
||||
try {
|
||||
std::vector<App::DocumentObject*> droppedObjs;
|
||||
for (auto& info : infos) {
|
||||
|
||||
@@ -138,16 +138,27 @@ bool ViewProviderAssembly::canDragObject(App::DocumentObject* obj) const
|
||||
return false;
|
||||
}
|
||||
|
||||
// else if a solid is removed, remove associated joints if any.
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ViewProviderAssembly::canDragObjectToTarget(App::DocumentObject* obj,
|
||||
App::DocumentObject* target) const
|
||||
{
|
||||
// If a solid is removed from the assembly, its joints need to be removed.
|
||||
bool prompted = false;
|
||||
auto* assemblyPart = static_cast<AssemblyObject*>(getObject());
|
||||
|
||||
// If target is null then it's being dropped on a doc.
|
||||
if (target && assemblyPart->hasObject(target)) {
|
||||
// If the obj stays in assembly then its ok.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Combine the joints and groundedJoints vectors into one for simplicity.
|
||||
std::vector<App::DocumentObject*> allJoints = assemblyPart->getJoints();
|
||||
std::vector<App::DocumentObject*> groundedJoints = assemblyPart->getGroundedJoints();
|
||||
allJoints.insert(allJoints.end(), groundedJoints.begin(), groundedJoints.end());
|
||||
|
||||
Gui::Command::openCommand(tr("Delete associated joints").toStdString().c_str());
|
||||
for (auto joint : allJoints) {
|
||||
// getLinkObjFromProp returns nullptr if the property doesn't exist.
|
||||
App::DocumentObject* obj1 = AssemblyObject::getObjFromProp(joint, "Object1");
|
||||
@@ -175,7 +186,6 @@ bool ViewProviderAssembly::canDragObject(App::DocumentObject* obj) const
|
||||
joint->getNameInDocument());
|
||||
}
|
||||
}
|
||||
Gui::Command::commitCommand();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ public:
|
||||
}
|
||||
|
||||
bool canDragObject(App::DocumentObject*) const override;
|
||||
bool canDragObjectToTarget(App::DocumentObject* obj,
|
||||
App::DocumentObject* target) const override;
|
||||
|
||||
App::DocumentObject* getActivePart() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user