Assembly: deleting a component deletes its joints.

This commit is contained in:
PaddleStroke
2024-06-11 15:37:52 +02:00
committed by Chris Hennes
parent 99aebd8a33
commit 3052760541
3 changed files with 33 additions and 0 deletions

View File

@@ -908,6 +908,32 @@ bool ViewProviderAssembly::onDelete(const std::vector<std::string>& subNames)
return ViewProviderPart::onDelete(subNames);
}
bool ViewProviderAssembly::canDelete(App::DocumentObject* obj) const
{
bool res = ViewProviderPart::canDelete(obj);
if (res) {
// If a component is deleted, then we delete the joints as well.
for (auto parent : obj->getInList()) {
if (!parent) {
continue;
}
auto* prop =
dynamic_cast<App::PropertyBool*>(parent->getPropertyByName("EnableLimits"));
auto* prop2 =
dynamic_cast<App::PropertyLink*>(parent->getPropertyByName("ObjectToGround"));
if (prop || prop2) {
Gui::Command::doCommand(Gui::Command::Doc,
"App.getDocument(\"%s\").removeObject(\"%s\")",
parent->getDocument()->getName(),
parent->getNameInDocument());
}
}
}
return res;
}
void ViewProviderAssembly::setDraggerVisibility(bool val)
{
asmDraggerSwitch->whichChild = val ? SO_SWITCH_ALL : SO_SWITCH_NONE;

View File

@@ -72,6 +72,7 @@ public:
bool doubleClicked() override;
bool onDelete(const std::vector<std::string>& subNames) override;
bool canDelete(App::DocumentObject* obj) const override;
/** @name enter/exit edit mode */
//@{

View File

@@ -941,6 +941,9 @@ class ViewProviderJoint:
return True
def canDelete(self, _obj):
return True
################ Grounded Joint object #################
@@ -1143,6 +1146,9 @@ class ViewProviderGroundedJoint:
Since no data were serialized nothing needs to be done here."""
return None
def canDelete(self, _obj):
return True
class MakeJointSelGate:
def __init__(self, taskbox, assembly):