From a0c28aba754e943c80d8df26c0019f4d85b5bbbf Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Tue, 14 Oct 2025 11:40:10 +0200 Subject: [PATCH] Assembly: Fix lengths cannot be negative (#24625) * Assembly: Fix lengths cannot be negative * Update PropertyUnits.cpp * Update PropertyUnits.h * Update JointObject.py --- src/App/PropertyContainerPyImp.cpp | 9 +++++++++ src/App/PropertyUnits.cpp | 8 +++++++- src/App/PropertyUnits.h | 3 +++ src/Mod/Assembly/JointObject.py | 5 +++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/App/PropertyContainerPyImp.cpp b/src/App/PropertyContainerPyImp.cpp index cba8d8285e..a630f7fe2b 100644 --- a/src/App/PropertyContainerPyImp.cpp +++ b/src/App/PropertyContainerPyImp.cpp @@ -30,6 +30,8 @@ #include #include +#include "PropertyUnits.h" + // inclusion of the generated files (generated out of PropertyContainerPy.xml) #include "PropertyContainerPy.h" #include "PropertyContainerPy.cpp" @@ -272,6 +274,12 @@ PyObject* PropertyContainerPy::setPropertyStatus(PyObject* args) continue; } + auto lengthProp = freecad_cast(prop); + if (lengthProp && v == "AllowNegativeValues") { + lengthProp->enableNegative(value); + continue; + } + PyErr_Format(PyExc_ValueError, "Unknown property status '%s'", v.c_str()); return nullptr; } @@ -721,3 +729,4 @@ PyObject* PropertyContainerPy::renameProperty(PyObject* args) const } PY_CATCH } + diff --git a/src/App/PropertyUnits.cpp b/src/App/PropertyUnits.cpp index ecb0a68397..42d63d3c10 100644 --- a/src/App/PropertyUnits.cpp +++ b/src/App/PropertyUnits.cpp @@ -518,7 +518,12 @@ TYPESYSTEM_SOURCE(App::PropertyLength, App::PropertyQuantityConstraint) PropertyLength::PropertyLength() { setUnit(Base::Unit::Length); - setConstraints(&LengthStandard); + enableNegative(false); +} + +void PropertyLength::enableNegative(bool on) +{ + setConstraints(on ? nullptr : &LengthStandard); } //************************************************************************** @@ -863,3 +868,4 @@ PropertyYoungsModulus::PropertyYoungsModulus() { setUnit(Base::Unit::YoungsModulus); } + diff --git a/src/App/PropertyUnits.h b/src/App/PropertyUnits.h index 2e2cca365c..6e3a44c5d1 100644 --- a/src/App/PropertyUnits.h +++ b/src/App/PropertyUnits.h @@ -515,6 +515,8 @@ class AppExport PropertyLength: public PropertyQuantityConstraint public: PropertyLength(); ~PropertyLength() override = default; + + void enableNegative(bool on); }; /** LuminousIntensity property @@ -923,3 +925,4 @@ public: } // namespace App #endif // APP_PROPERTYUNITS_H + diff --git a/src/Mod/Assembly/JointObject.py b/src/Mod/Assembly/JointObject.py index 7d14f08d2e..d4a1a3964f 100644 --- a/src/Mod/Assembly/JointObject.py +++ b/src/Mod/Assembly/JointObject.py @@ -370,6 +370,11 @@ class Joint: if not hasattr(joint, "AngleMax"): self.addAngleMaxProperty(joint) + joint.setPropertyStatus("Distance", "AllowNegativeValues") + joint.setPropertyStatus("Distance2", "AllowNegativeValues") + joint.setPropertyStatus("LengthMin", "AllowNegativeValues") + joint.setPropertyStatus("LengthMax", "AllowNegativeValues") + def addAngleProperty(self, joint): joint.addProperty( "App::PropertyAngle",