From 8b3047a8dbb6be4fca3a92ae3dfb4148438d6fde Mon Sep 17 00:00:00 2001 From: azv Date: Thu, 9 Apr 2015 11:53:55 +0300 Subject: [PATCH] Fit incorrect movement of a line which boundary coincident to a point from another sketch --- src/SketchSolver/SketchSolver_Constraint.cpp | 7 +++++++ src/SketchSolver/SketchSolver_Constraint.h | 3 +++ .../SketchSolver_ConstraintRigid.cpp | 13 +++++++------ src/SketchSolver/SketchSolver_Group.cpp | 18 +++++++++++++++--- src/SketchSolver/SketchSolver_Group.h | 3 +++ src/SketchSolver/SketchSolver_Storage.cpp | 18 +++++++++++++++++- src/SketchSolver/SketchSolver_Storage.h | 10 +++++++++- 7 files changed, 61 insertions(+), 11 deletions(-) diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 1d2abb354..36bde98f8 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -674,3 +674,10 @@ void SketchSolver_Constraint::calculateMiddlePoint( } } +void SketchSolver_Constraint::makeTemporary() const +{ + std::vector::const_iterator anIt = mySlvsConstraints.begin(); + for (; anIt != mySlvsConstraints.end(); anIt++) + myStorage->addTemporaryConstraint(*anIt); +} + diff --git a/src/SketchSolver/SketchSolver_Constraint.h b/src/SketchSolver/SketchSolver_Constraint.h index 6cfe355f8..134263412 100644 --- a/src/SketchSolver/SketchSolver_Constraint.h +++ b/src/SketchSolver/SketchSolver_Constraint.h @@ -51,6 +51,9 @@ public: /// \brief Returns the type of constraint virtual int getType() const = 0; + /// \brief The constraint is made temoparary + void makeTemporary() const; + /// \brief Checks the constraint is used by current object virtual bool hasConstraint(ConstraintPtr theConstraint) const { return theConstraint == myBaseConstraint; } diff --git a/src/SketchSolver/SketchSolver_ConstraintRigid.cpp b/src/SketchSolver/SketchSolver_ConstraintRigid.cpp index 6c1875ccb..39e6f93ee 100644 --- a/src/SketchSolver/SketchSolver_ConstraintRigid.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintRigid.cpp @@ -52,7 +52,8 @@ void SketchSolver_ConstraintRigid::process() if (*anEntIter == SLVS_E_UNKNOWN) continue; Slvs_hConstraint aConstrID = myStorage->isPointFixed(*anEntIter); - bool isForceUpdate = (aConstrID != SLVS_E_UNKNOWN && !myBaseConstraint); + bool isForceUpdate = (aConstrID != SLVS_E_UNKNOWN && !myBaseConstraint && + myStorage->isTemporary(aConstrID)); if (isEmpty && !isForceUpdate) { // create new constraint if (aConstrID != SLVS_E_UNKNOWN) continue; // the coincident point is already fixed @@ -61,7 +62,7 @@ void SketchSolver_ConstraintRigid::process() aConstraint.h = myStorage->addConstraint(aConstraint); mySlvsConstraints.push_back(aConstraint.h); if (!myBaseConstraint) - myStorage->addTemporaryConstraint(aConstraint.h); + myStorage->addConstraintWhereDragged(aConstraint.h); } else { // update already existent constraint if (aConstrID == SLVS_E_UNKNOWN || myBaseConstraint) aConstrID = *aConstrIter; @@ -69,7 +70,7 @@ void SketchSolver_ConstraintRigid::process() aConstraint.ptA = *anEntIter; myStorage->addConstraint(aConstraint); if (!myBaseConstraint) - myStorage->addTemporaryConstraint(aConstraint.h); + myStorage->addConstraintWhereDragged(aConstraint.h); if (!isEmpty) { aConstrIter++; isEmpty = aConstrIter == mySlvsConstraints.end(); @@ -86,7 +87,7 @@ void SketchSolver_ConstraintRigid::process() aConstraint.h = myStorage->addConstraint(aConstraint); mySlvsConstraints.push_back(aConstraint.h); if (!myBaseConstraint) - myStorage->addTemporaryConstraint(aConstraint.h); + myStorage->addConstraintWhereDragged(aConstraint.h); } } @@ -226,7 +227,7 @@ void SketchSolver_ConstraintRigid::fixArc(const Slvs_Entity& theArc) aConstraint.h = myStorage->addConstraint(aConstraint); mySlvsConstraints.push_back(aConstraint.h); if (!myBaseConstraint) - myStorage->addTemporaryConstraint(aConstraint.h); + myStorage->addConstraintWhereDragged(aConstraint.h); } // Fix radius of the arc @@ -242,7 +243,7 @@ void SketchSolver_ConstraintRigid::fixArc(const Slvs_Entity& theArc) aConstraint.h = myStorage->addConstraint(aConstraint); mySlvsConstraints.push_back(aConstraint.h); if (!myBaseConstraint) - myStorage->addTemporaryConstraint(aConstraint.h); + myStorage->addConstraintWhereDragged(aConstraint.h); } } diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index ca39f6e2d..7fdc32a4c 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -231,7 +231,7 @@ bool SketchSolver_Group::changeConstraint( continue; aConstraint->setGroup(this); aConstraint->setStorage(myStorage); - myTempConstraints.insert(aConstraint); + setTemporary(aConstraint); } } // Fix base features for mirror @@ -273,7 +273,7 @@ void SketchSolver_Group::moveFeature(std::shared_ptr theFe return; aConstraint->setGroup(this); aConstraint->setStorage(myStorage); - myTempConstraints.insert(aConstraint); + setTemporary(aConstraint); } // ============================================================================ @@ -295,7 +295,7 @@ void SketchSolver_Group::fixFeaturesList(AttributeRefListPtr theList) continue; aConstraint->setGroup(this); aConstraint->setStorage(myStorage); - myTempConstraints.insert(aConstraint); + setTemporary(aConstraint); } } @@ -523,6 +523,7 @@ bool SketchSolver_Group::isConsistent() void SketchSolver_Group::removeTemporaryConstraints() { myTempConstraints.clear(); + myStorage->removeTemporaryConstraints(); // Clean lists of removed entities in the storage std::set aRemPar; std::set aRemEnt; @@ -562,3 +563,14 @@ bool SketchSolver_Group::isComplexConstraint(FeaturePtr theConstraint) theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID(); } +// ============================================================================ +// Function: setTemporary +// Class: SketchSolver_Group +// Purpose: append given constraint to th group of temporary constraints +// ============================================================================ +void SketchSolver_Group::setTemporary(SolverConstraintPtr theConstraint) +{ + theConstraint->makeTemporary(); + myTempConstraints.insert(theConstraint); +} + diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 534d48051..79f5f9fe0 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -154,6 +154,9 @@ private: /// \brief Apply temporary rigid constraints for the list of features void fixFeaturesList(AttributeRefListPtr theList); + /// \brief Append given constraint to th group of temporary constraints + void setTemporary(SolverConstraintPtr theConstraint); + private: Slvs_hGroup myID; ///< Index of the group Slvs_hEntity myWorkplaneID; ///< Index of workplane, the group is based on diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index d4a517132..40d1d281f 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -318,7 +318,7 @@ std::list SketchSolver_Storage::getConstraintsByType(int theCon } -void SketchSolver_Storage::addTemporaryConstraint(const Slvs_hConstraint& theConstraintID) +void SketchSolver_Storage::addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID) { if (myFixed != SLVS_E_UNKNOWN) return; // the point is already fixed @@ -327,6 +327,22 @@ void SketchSolver_Storage::addTemporaryConstraint(const Slvs_hConstraint& theCon myFixed = theConstraintID; } +void SketchSolver_Storage::addTemporaryConstraint(const Slvs_hConstraint& theConstraintID) +{ + myTemporaryConstraints.insert(theConstraintID); +} + +void SketchSolver_Storage::removeTemporaryConstraints() +{ + myTemporaryConstraints.clear(); +} + +bool SketchSolver_Storage::isTemporary(const Slvs_hConstraint& theConstraintID) const +{ + return myTemporaryConstraints.find(theConstraintID) != myTemporaryConstraints.end(); +} + + void SketchSolver_Storage::getRemoved( std::set& theParameters, std::set& theEntities, diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index cf04f47ab..a95d83c72 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -87,8 +87,15 @@ public: /// \brief Returns list of constraints of specified type std::list getConstraintsByType(int theConstraintType) const; - /// \brief Attach temporary constraint to this storage. It need to make precise calculations + /// \brief Attach constraint SLVS_C_WHERE_DRAGGED to this storage. It need to make precise calculations + void addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID); + + /// \brief Add transient constraint void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID); + /// \brief Remove all transient constraints + void removeTemporaryConstraints(); + /// \brief Checks the constraint is temporary + bool isTemporary(const Slvs_hConstraint& theConstraintID) const; /// \brief Shows the sketch should be resolved bool isNeedToResolve() const @@ -129,6 +136,7 @@ private: bool myNeedToResolve; ///< parameters are changed and group needs to be resolved + std::set myTemporaryConstraints; ///< list of transient constraints std::set myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant) std::set myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant) std::set myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant) -- 2.39.2