From e1b61137bd30e9e7cb076775540b27c51ee42855 Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 3 Sep 2015 11:22:33 +0300 Subject: [PATCH] Do not recalculate constraints if there are invalid features (issue #874) --- src/SketchSolver/SketchSolver_Group.cpp | 24 ++++++++++++++++++++++++ src/SketchSolver/SketchSolver_Group.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 8d8b81735..9325a6e1e 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include @@ -191,6 +193,9 @@ bool SketchSolver_Group::changeConstraint( if (!theConstraint) return false; + if (!checkFeatureValidity(theConstraint)) + return false; + bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end(); if (isNewConstraint) { // Add constraint to the current group @@ -280,6 +285,9 @@ bool SketchSolver_Group::changeConstraint( bool SketchSolver_Group::updateFeature(std::shared_ptr theFeature) { + if (!checkFeatureValidity(theFeature)) + return false; + std::set aConstraints = myFeatureStorage->getConstraints(std::dynamic_pointer_cast(theFeature)); if (aConstraints.empty()) @@ -698,3 +706,19 @@ void SketchSolver_Group::setTemporary(SolverConstraintPtr theConstraint) myTempConstraints.insert(theConstraint); } + +// ============================================================================ +// Function: checkFeatureValidity +// Class: SketchSolver_Group +// Purpose: verifies is the feature valid +// ============================================================================ +bool SketchSolver_Group::checkFeatureValidity(FeaturePtr theFeature) +{ + if (!theFeature || !theFeature->data()->isValid()) + return true; + + SessionPtr aMgr = ModelAPI_Session::get(); + ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + return aFactory->validate(theFeature); +} + diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 13f614c75..e75accd08 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -157,6 +157,9 @@ private: /// \brief Append given constraint to th group of temporary constraints void setTemporary(SolverConstraintPtr theConstraint); + /// \brief Verifies is the feature valid + bool checkFeatureValidity(FeaturePtr theFeature); + private: Slvs_hGroup myID; ///< Index of the group Slvs_hEntity myWorkplaneID; ///< Index of workplane, the group is based on -- 2.39.2