Assembly: Fix lengths cannot be negative (#24625)

* Assembly: Fix lengths cannot be negative

* Update PropertyUnits.cpp

* Update PropertyUnits.h

* Update JointObject.py
This commit is contained in:
PaddleStroke
2025-10-14 11:40:10 +02:00
committed by GitHub
parent d0c7b427ff
commit 6e090a2dad
4 changed files with 24 additions and 1 deletions

View File

@@ -30,6 +30,8 @@
#include <boost/iostreams/device/array.hpp>
#include <boost/iostreams/stream.hpp>
#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<App::PropertyLength*>(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
}

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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",