Skip to content

Commit

Permalink
Sketcher: bugfix: disallow opening when geometry types changed
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepSOIC authored and wwmayer committed Mar 28, 2015
1 parent 3e6eb43 commit 89d0a7a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
31 changes: 24 additions & 7 deletions src/Mod/Sketcher/App/PropertyConstraintList.cpp
Expand Up @@ -232,24 +232,41 @@ void PropertyConstraintList::applyValidGeometryKeys(const std::vector<unsigned i

void PropertyConstraintList::checkGeometry(const std::vector<Part::Geometry *> &GeoList)
{
if (validGeometryKeys.size() != GeoList.size()) {
if (!scanGeometry(GeoList)) {
invalidGeometry = true;
return;
}

//if we made it here, geometry is OK
if (invalidGeometry) {
//geometry was bad, but now it became OK.
invalidGeometry = false;
touch();
}
}

/*!
* \brief PropertyConstraintList::scanGeometry tests if the supplied geometry
* is the same (all elements are of the same type as they used to be).
* \param GeoList - new geometry list to be checked
* \return false, if the types have changed.
*/
bool PropertyConstraintList::scanGeometry(const std::vector<Part::Geometry *> &GeoList) const
{
if (validGeometryKeys.size() != GeoList.size()) {
return false;
}

unsigned int i=0;
for (std::vector< Part::Geometry * >::const_iterator it=GeoList.begin();
it != GeoList.end(); ++it, i++) {
if (validGeometryKeys[i] != (*it)->getTypeId().getKey()) {
invalidGeometry = true;
return;
return false;
}
}

if (invalidGeometry) {
invalidGeometry = false;
touch();
}
return true;
}


std::vector<Constraint *> PropertyConstraintList::_emptyValueList(0);
5 changes: 5 additions & 0 deletions src/Mod/Sketcher/App/PropertyConstraintList.h
Expand Up @@ -79,6 +79,9 @@ class SketcherExport PropertyConstraintList : public App::PropertyLists
const std::vector<Constraint*> &getValues(void) const {
return invalidGeometry ? _emptyValueList : _lValueList;
}
const std::vector<Constraint*> &getValuesForce(void) const {//to suppress check for invalid geometry, to be used for sketch repairing.
return _lValueList;
}

virtual PyObject *getPyObject(void);
virtual void setPyObject(PyObject *);
Expand All @@ -93,6 +96,8 @@ class SketcherExport PropertyConstraintList : public App::PropertyLists

void acceptGeometry(const std::vector<Part::Geometry *> &GeoList);
void checkGeometry(const std::vector<Part::Geometry *> &GeoList);
bool scanGeometry(const std::vector<Part::Geometry *> &GeoList) const;
bool isGeometryInvalid(){return invalidGeometry;}

private:
std::vector<Constraint *> _lValueList;
Expand Down
8 changes: 6 additions & 2 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -1756,7 +1756,7 @@ int SketchObject::delExternal(int ExtGeoId)

int SketchObject::delConstraintsToExternal()
{
const std::vector< Constraint * > &constraints = Constraints.getValues();
const std::vector< Constraint * > &constraints = Constraints.getValuesForce();
std::vector< Constraint * > newConstraints(0);
int GeoId = -3, NullId = -2000;
for (std::vector<Constraint *>::const_iterator it = constraints.begin();
Expand Down Expand Up @@ -2270,7 +2270,7 @@ bool SketchObject::evaluateConstraints() const
int extGeoCount = getExternalGeometryCount();

std::vector<Part::Geometry *> geometry = getCompleteGeometry();
const std::vector<Sketcher::Constraint *>& constraints = Constraints.getValues();
const std::vector<Sketcher::Constraint *>& constraints = Constraints.getValuesForce();
if (static_cast<int>(geometry.size()) != extGeoCount + intGeoCount)
return false;
if (geometry.size() < 2)
Expand All @@ -2282,6 +2282,10 @@ bool SketchObject::evaluateConstraints() const
return false;
}

if(constraints.size()>0){
if (!Constraints.scanGeometry(geometry)) return false;
}

return true;
}

Expand Down

0 comments on commit 89d0a7a

Please sign in to comment.