Sketcher: PropertyConstraintList input data validation

======================================================

PropertyConstraintList is provided with the ability to check its constraints indices against
a minimum and a maximum, and set an invalidindex status.

In this status, the getValues returns an emptylist, as in the case with invalid geometry types.
This commit is contained in:
Abdullah Tahiri
2020-06-28 19:09:29 +02:00
committed by abdullahtahiriyo
parent 7055b5ef0f
commit ee21985e25
2 changed files with 41 additions and 2 deletions

View File

@@ -61,6 +61,7 @@ PropertyConstraintList::PropertyConstraintList()
: validGeometryKeys(0)
, invalidGeometry(true)
, restoreFromTransaction(false)
, invalidIndices(false)
{
}
@@ -400,6 +401,41 @@ bool PropertyConstraintList::checkGeometry(const std::vector<Part::Geometry *> &
return invalidGeometry;
}
bool PropertyConstraintList::checkConstraintIndices(int geomax, int geomin)
{
int mininternalgeoid = std::numeric_limits<int>::max();
int maxinternalgeoid = Constraint::GeoUndef;
auto cmin = [] (int previousmin, int cindex) {
if( cindex == Constraint::GeoUndef )
return previousmin;
return ( cindex < previousmin )? cindex : previousmin;
};
auto cmax = [] (int previousmax, int cindex) {
return ( cindex > previousmax )? cindex : previousmax;
};
for (const auto &v : _lValueList) {
mininternalgeoid = cmin(mininternalgeoid, v->First);
mininternalgeoid = cmin(mininternalgeoid, v->Second);
mininternalgeoid = cmin(mininternalgeoid, v->Third);
maxinternalgeoid = cmax(maxinternalgeoid, v->First);
maxinternalgeoid = cmax(maxinternalgeoid, v->Second);
maxinternalgeoid = cmax(maxinternalgeoid, v->Third);
}
if(maxinternalgeoid > geomax || mininternalgeoid < geomin)
invalidIndices = true;
else
invalidIndices = false;
return invalidIndices;
}
/*!
* \brief PropertyConstraintList::scanGeometry tests if the supplied geometry
* is the same (all elements are of the same type as they used to be).

View File

@@ -99,11 +99,11 @@ public:
returns null. This must be checked by the caller.
*/
const Constraint *operator[] (const int idx) const {
return invalidGeometry ? 0 : _lValueList[idx];
return (invalidGeometry || invalidIndices) ? 0 : _lValueList[idx];
}
const std::vector<Constraint*> &getValues(void) const {
return invalidGeometry ? _emptyValueList : _lValueList;
return (invalidGeometry || invalidIndices) ? _emptyValueList : _lValueList;
}
const std::vector<Constraint*> &getValuesForce(void) const {//to suppress check for invalid geometry, to be used for sketch repairing.
return _lValueList;
@@ -124,6 +124,8 @@ public:
bool checkGeometry(const std::vector<Part::Geometry *> &GeoList);
bool scanGeometry(const std::vector<Part::Geometry *> &GeoList) const;
bool checkConstraintIndices(int geomax, int geomin);
/// Return status of geometry for better error reporting
bool hasInvalidGeometry() const { return invalidGeometry; }
@@ -162,6 +164,7 @@ private:
std::vector<unsigned int> validGeometryKeys;
bool invalidGeometry;
bool restoreFromTransaction;
bool invalidIndices;
void applyValues(std::vector<Constraint*>&&);
void applyValidGeometryKeys(const std::vector<unsigned int> &keys);