Base: Quantity: use isDimensionless whenever feasible

Quantity is often queried for Unit just to see if it has a dimension.
Ask Quantity directly using isDimensionless() method and modify that
method not to care about Quantity value validity; no user was ever
asking for value validity.
This commit is contained in:
Ladislav Michl
2025-04-10 17:43:41 +02:00
parent f486b7c84b
commit 913c30429c
10 changed files with 31 additions and 58 deletions

View File

@@ -105,13 +105,12 @@ void PropertyQuantity::setPyObject(PyObject* value)
else {
Base::Quantity quant = createQuantityFromPy(value);
Unit unit = quant.getUnit();
if (unit.isEmpty()) {
if (quant.isDimensionless()) {
PropertyFloat::setValue(quant.getValue());
return;
}
if (unit != _Unit) {
if (_Unit != quant.getUnit()) {
throw Base::UnitsMismatchError("Not matching Unit!");
}
@@ -123,7 +122,7 @@ void PropertyQuantity::setPathValue(const ObjectIdentifier& /*path*/, const boos
{
auto q = App::anyToQuantity(value);
aboutToSetValue();
if (!q.getUnit().isEmpty()) {
if (!q.isDimensionless()) {
_Unit = q.getUnit();
}
_dValue = q.getValue();
@@ -187,7 +186,6 @@ void PropertyQuantityConstraint::setPyObject(PyObject* value)
{
Base::Quantity quant = createQuantityFromPy(value);
Unit unit = quant.getUnit();
double temp = quant.getValue();
if (_ConstStruct) {
if (temp > _ConstStruct->UpperBound) {
@@ -199,12 +197,12 @@ void PropertyQuantityConstraint::setPyObject(PyObject* value)
}
quant.setValue(temp);
if (unit.isEmpty()) {
if (quant.isDimensionless()) {
PropertyFloat::setValue(quant.getValue()); // clazy:exclude=skipped-base-method
return;
}
if (unit != _Unit) {
if (_Unit != quant.getUnit()) {
throw Base::UnitsMismatchError("Not matching Unit!");
}