Assembly: Replace "Activated" property by the core "Suppressed" mecha… (#22409)
* Assembly: Replace "Activated" property by the core "Suppressed" mechanism. * Fix inaccuracy * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * move the change to migrationScript5 function * Update JointObject.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -352,7 +352,7 @@ void AssemblyLink::synchronizeJoints()
|
||||
}
|
||||
|
||||
// Then we have to check the properties one by one.
|
||||
copyPropertyIfDifferent<App::PropertyBool>(joint, lJoint, "Activated");
|
||||
copyPropertyIfDifferent<App::PropertyBool>(joint, lJoint, "Suppressed");
|
||||
copyPropertyIfDifferent<App::PropertyFloat>(joint, lJoint, "Distance");
|
||||
copyPropertyIfDifferent<App::PropertyFloat>(joint, lJoint, "Distance2");
|
||||
copyPropertyIfDifferent<App::PropertyEnumeration>(joint, lJoint, "JointType");
|
||||
|
||||
@@ -651,8 +651,8 @@ AssemblyObject::getJoints(bool updateJCS, bool delBadJoints, bool subJoints)
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* prop = dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("Activated"));
|
||||
if (joint->isError() || !prop || !prop->getValue()) {
|
||||
auto* prop = dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("Suppressed"));
|
||||
if (joint->isError() || !prop || prop->getValue()) {
|
||||
// Filter grounded joints and deactivated joints.
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -404,8 +404,8 @@ void setJointActivated(const App::DocumentObject* joint, bool val)
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto propActivated = joint->getPropertyByName<App::PropertyBool>("Activated")) {
|
||||
propActivated->setValue(val);
|
||||
if (auto propSuppressed = joint->getPropertyByName<App::PropertyBool>("Suppressed")) {
|
||||
propSuppressed->setValue(!val);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,8 +415,8 @@ bool getJointActivated(const App::DocumentObject* joint)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (const auto propActivated = joint->getPropertyByName<App::PropertyBool>("Activated")) {
|
||||
return propActivated->getValue();
|
||||
if (const auto propActivated = joint->getPropertyByName<App::PropertyBool>("Suppressed")) {
|
||||
return !propActivated->getValue();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -65,8 +65,8 @@ std::vector<App::DocumentObject*> JointGroup::getJoints()
|
||||
continue;
|
||||
}
|
||||
|
||||
auto* prop = dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("Activated"));
|
||||
if (!prop || !prop->getValue()) {
|
||||
auto* prop = dynamic_cast<App::PropertyBool*>(joint->getPropertyByName("Suppressed"));
|
||||
if (!prop || prop->getValue()) {
|
||||
// Filter grounded joints and deactivated joints.
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -174,6 +174,8 @@ class Joint:
|
||||
def __init__(self, joint, type_index):
|
||||
joint.Proxy = self
|
||||
|
||||
joint.addExtension("App::SuppressibleExtensionPython")
|
||||
|
||||
joint.addProperty(
|
||||
"App::PropertyEnumeration",
|
||||
"JointType",
|
||||
@@ -196,6 +198,7 @@ class Joint:
|
||||
self.migrationScript2(joint)
|
||||
self.migrationScript3(joint)
|
||||
self.migrationScript4(joint)
|
||||
self.migrationScript5(joint)
|
||||
|
||||
# First Joint Connector
|
||||
if not hasattr(joint, "Reference1"):
|
||||
@@ -314,19 +317,6 @@ class Joint:
|
||||
locked=True,
|
||||
)
|
||||
|
||||
if not hasattr(joint, "Activated"):
|
||||
joint.addProperty(
|
||||
"App::PropertyBool",
|
||||
"Activated",
|
||||
"Joint",
|
||||
QT_TRANSLATE_NOOP(
|
||||
"App::Property",
|
||||
"This indicates if the joint is active.",
|
||||
),
|
||||
locked=True,
|
||||
)
|
||||
joint.Activated = True
|
||||
|
||||
if not hasattr(joint, "EnableLengthMin"):
|
||||
joint.addProperty(
|
||||
"App::PropertyBool",
|
||||
@@ -563,6 +553,23 @@ class Joint:
|
||||
processReference("Reference1")
|
||||
processReference("Reference2")
|
||||
|
||||
def migrationScript5(self, joint):
|
||||
if not joint.hasExtension("App::SuppressibleExtensionPython"):
|
||||
joint.addExtension("App::SuppressibleExtensionPython")
|
||||
|
||||
if App.GuiUp:
|
||||
if not joint.ViewObject.hasExtension("Gui::ViewProviderSuppressibleExtensionPython"):
|
||||
joint.ViewObject.addExtension("Gui::ViewProviderSuppressibleExtensionPython")
|
||||
|
||||
if hasattr(joint, "Activated"):
|
||||
activated = joint.Activated
|
||||
if not activated:
|
||||
print(
|
||||
"The 'Activated' property has been replaced by the 'Suppressed' property. Your file has a deactivated joint that is being migrated. If you open back this file in an older version, it will not be deactivated anymore."
|
||||
)
|
||||
joint.removeProperty("Activated")
|
||||
joint.Suppressed = not activated
|
||||
|
||||
def dumps(self):
|
||||
return None
|
||||
|
||||
@@ -747,10 +754,10 @@ class Joint:
|
||||
|
||||
isAssembly = assembly.Type == "Assembly"
|
||||
if isAssembly:
|
||||
joint.Activated = False
|
||||
joint.Suppressed = True
|
||||
part1Connected = assembly.isPartConnected(part1)
|
||||
part2Connected = assembly.isPartConnected(part2)
|
||||
joint.Activated = True
|
||||
joint.Suppressed = False
|
||||
else:
|
||||
part1Connected = True
|
||||
part2Connected = False
|
||||
@@ -853,6 +860,8 @@ class ViewProviderJoint:
|
||||
|
||||
vobj.Proxy = self
|
||||
|
||||
vobj.addExtension("Gui::ViewProviderSuppressibleExtensionPython")
|
||||
|
||||
def attach(self, vobj):
|
||||
"""Setup the scene sub-graph of the view provider, this method is mandatory"""
|
||||
self.app_obj = vobj.Object
|
||||
|
||||
Reference in New Issue
Block a user