App: add convenience methods to get minimum, maximum and step size of property constraints

This commit is contained in:
wmayer
2021-03-03 08:12:03 +01:00
parent 20024707a9
commit 30e9ba9609
4 changed files with 77 additions and 0 deletions

View File

@@ -623,6 +623,29 @@ const PropertyIntegerConstraint::Constraints* PropertyIntegerConstraint::getCon
return _ConstStruct;
}
long PropertyIntegerConstraint::getMinimum() const
{
if (_ConstStruct)
return _ConstStruct->LowerBound;
// return the min of int, not long
return std::numeric_limits<int>::min();
}
long PropertyIntegerConstraint::getMaximum() const
{
if (_ConstStruct)
return _ConstStruct->UpperBound;
// return the max of int, not long
return std::numeric_limits<int>::max();
}
long PropertyIntegerConstraint::getStepSize() const
{
if (_ConstStruct)
return _ConstStruct->StepSize;
return 1;
}
void PropertyIntegerConstraint::setPyObject(PyObject *value)
{
#if PY_MAJOR_VERSION < 3
@@ -1102,6 +1125,27 @@ const PropertyFloatConstraint::Constraints* PropertyFloatConstraint::getConstra
return _ConstStruct;
}
double PropertyFloatConstraint::getMinimum() const
{
if (_ConstStruct)
return _ConstStruct->LowerBound;
return std::numeric_limits<double>::min();
}
double PropertyFloatConstraint::getMaximum() const
{
if (_ConstStruct)
return _ConstStruct->UpperBound;
return std::numeric_limits<double>::max();
}
double PropertyFloatConstraint::getStepSize() const
{
if (_ConstStruct)
return _ConstStruct->StepSize;
return 1.0;
}
void PropertyFloatConstraint::setPyObject(PyObject *value)
{
if (PyFloat_Check(value)) {

View File

@@ -281,6 +281,10 @@ public:
const Constraints* getConstraints(void) const;
//@}
long getMinimum() const;
long getMaximum() const;
long getStepSize() const;
virtual const char* getEditorName(void) const { return "Gui::PropertyEditor::PropertyIntegerConstraintItem"; }
virtual void setPyObject(PyObject *);
@@ -561,6 +565,10 @@ public:
const Constraints* getConstraints(void) const;
//@}
double getMinimum() const;
double getMaximum() const;
double getStepSize() const;
virtual const char* getEditorName(void) const
{ return "Gui::PropertyEditor::PropertyFloatConstraintItem"; }

View File

@@ -181,6 +181,27 @@ const PropertyQuantityConstraint::Constraints* PropertyQuantityConstraint::getC
return _ConstStruct;
}
double PropertyQuantityConstraint::getMinimum() const
{
if (_ConstStruct)
return _ConstStruct->LowerBound;
return std::numeric_limits<double>::min();
}
double PropertyQuantityConstraint::getMaximum() const
{
if (_ConstStruct)
return _ConstStruct->UpperBound;
return std::numeric_limits<double>::max();
}
double PropertyQuantityConstraint::getStepSize() const
{
if (_ConstStruct)
return _ConstStruct->StepSize;
return 1.0;
}
void PropertyQuantityConstraint::setPyObject(PyObject *value)
{
Base::Quantity quant= createQuantityFromPy(value);

View File

@@ -106,6 +106,10 @@ public:
const Constraints* getConstraints(void) const;
//@}
double getMinimum() const;
double getMaximum() const;
double getStepSize() const;
virtual const char* getEditorName(void) const;
virtual void setPyObject(PyObject *);