SketchSolver_Group::SketchSolver_Group(
std::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
: myID(GroupIndexer::NEW_GROUP()),
- myPrevSolved(true)
+ myPrevResult(STATUS_UNKNOWN)
{
// Initialize workplane
myWorkplaneID = EID_UNKNOWN;
return true;
}
-
-void SketchSolver_Group::updateConstraints()
-{
- std::set<SolverConstraintPtr> aPostponed; // postponed constraints Multi-Rotation and Multi-Translation
-
- ConstraintConstraintMap::iterator anIt = myConstraints.begin();
- for (; anIt != myConstraints.end(); ++anIt) {
- if (myChangedConstraints.find(anIt->first) == myChangedConstraints.end())
- continue;
- if (anIt->first->getKind() == SketchPlugin_MultiRotation::ID() ||
- anIt->first->getKind() == SketchPlugin_MultiTranslation::ID())
- aPostponed.insert(anIt->second);
- else
- anIt->second->update();
- }
-
- // Update postponed constraints
- std::set<SolverConstraintPtr>::iterator aSCIter = aPostponed.begin();
- for (; aSCIter != aPostponed.end(); ++aSCIter)
- (*aSCIter)->update();
-
- myChangedConstraints.clear();
-}
-
static void updateMultiConstraints(ConstraintConstraintMap& theConstraints, FeaturePtr theFeature)
{
ConstraintConstraintMap::iterator aCIt = theConstraints.begin();
if (!checkFeatureValidity(theFeature))
return false;
- myStorage->blockEvents(true);
+ bool isBlocked = myStorage->isEventsBlocked();
+ if (!isBlocked)
+ myStorage->blockEvents(true);
+
myStorage->refresh(true);
bool isUpdated = myStorage->update(theFeature);
updateMultiConstraints(myConstraints, theFeature);
+
+ // events were not blocked before, the feature has not been updated,
+ // so it is necessary to revert blocking
+ if (!isUpdated && !isBlocked)
+ myStorage->blockEvents(false);
return isUpdated;
}
// ============================================================================
bool SketchSolver_Group::resolveConstraints()
{
- if (!myChangedConstraints.empty())
- updateConstraints();
-
bool aResolved = false;
bool isGroupEmpty = isEmpty();
if (myStorage->isNeedToResolve() && !isGroupEmpty) {
} catch (...) {
// Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::SOLVESPACE_CRASH());
- if (myPrevSolved) {
+ if (myPrevResult == STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
// the error message should be changed before sending the message
sendMessage(EVENT_SOLVER_FAILED);
- myPrevSolved = false;
+ myPrevResult = STATUS_FAILED;
}
mySketchSolver->undo();
return false;
}
if (aResult == STATUS_OK || aResult == STATUS_EMPTYSET) { // solution succeeded, store results into correspondent attributes
myStorage->refresh();
- if (!myPrevSolved) {
+ if (myPrevResult != STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue("");
// the error message should be changed before sending the message
sendMessage(EVENT_SOLVER_REPAIRED);
- myPrevSolved = true;
+ myPrevResult = STATUS_OK;
}
} else {
mySketchSolver->undo();
if (!myConstraints.empty()) {
// Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue(SketchSolver_Error::CONSTRAINTS());
- if (myPrevSolved) {
+ if (myPrevResult != aResult || myPrevResult == STATUS_UNKNOWN) {
// the error message should be changed before sending the message
sendMessage(EVENT_SOLVER_FAILED);
- myPrevSolved = false;
+ myPrevResult = aResult;
}
}
}
// ============================================================================
void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint)
{
- bool isFullyRemoved = true;
ConstraintConstraintMap::iterator aCIter = myConstraints.begin();
for (; aCIter != myConstraints.end(); aCIter++)
if (aCIter->first == theConstraint) {
myConstraints.erase(aCIter);
}
-// ============================================================================
-// Function: isComplexConstraint
-// Class: SketchSolver_Group
-// Purpose: verifies the constraint is complex, i.e. it needs another constraints to be created before
-// ============================================================================
-bool SketchSolver_Group::isComplexConstraint(FeaturePtr theConstraint)
-{
- return theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID() ||
- theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID() ||
- theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID();
-}
-
// ============================================================================
// Function: setTemporary
// Class: SketchSolver_Group