From d0995d76f7a7f1ff72981efc4ffb46a98e9585fb Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 10 Oct 2014 11:23:07 +0400 Subject: [PATCH] Regression on line movement. Sketch solver was changed to work precisely with temporary constraints --- .../SketchSolver_ConstraintGroup.cpp | 39 ++++++++++++++++++- .../SketchSolver_ConstraintGroup.h | 10 ++++- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index 53461bb5d..a675349b1 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -79,7 +79,10 @@ SketchSolver_ConstraintGroup::SketchSolver_ConstraintGroup( myEntities.clear(); myEntOfConstr.clear(); myConstraints.clear(); + myTempConstraints.clear(); + myTempPointWhereDragged.clear(); + myTempPointWDrgdID = 0; // Initialize workplane myWorkplane.h = SLVS_E_UNKNOWN; @@ -98,6 +101,7 @@ SketchSolver_ConstraintGroup::~SketchSolver_ConstraintGroup() myConstraints.clear(); myConstraintMap.clear(); myTempConstraints.clear(); + myTempPointWhereDragged.clear(); // If the group with maximal identifier is deleted, decrease the indexer if (myID == myGroupIndexer) @@ -410,7 +414,7 @@ Slvs_hEntity SketchSolver_ConstraintGroup::changeEntity( // If the attribute was changed by the user, we need to fix it before solving if (myNeedToSolve && theEntity->isImmutable()) - addTemporaryConstraintWhereDragged(theEntity); + addTemporaryConstraintWhereDragged(theEntity, false); return aResult; } @@ -647,6 +651,7 @@ bool SketchSolver_ConstraintGroup::resolveConstraints() myConstrSolver.setParameters(myParams); myConstrSolver.setEntities(myEntities); myConstrSolver.setConstraints(myConstraints); + myConstrSolver.setDraggedParameters(myTempPointWhereDragged); int aResult = myConstrSolver.solve(); if (aResult == SLVS_RESULT_OKAY) { // solution succeeded, store results into correspondent attributes @@ -698,6 +703,18 @@ void SketchSolver_ConstraintGroup::mergeGroups(const SketchSolver_ConstraintGrou myTempConstraints.push_back(aFind->second); } + if (myTempPointWhereDragged.empty()) + myTempPointWhereDragged = theGroup.myTempPointWhereDragged; + else if (!theGroup.myTempPointWhereDragged.empty()) { // Need to create additional transient constraint + std::map, Slvs_hEntity>::const_iterator aFeatureIter = + theGroup.myEntityAttrMap.begin(); + for (; aFeatureIter != theGroup.myEntityAttrMap.end(); aFeatureIter++) + if (aFeatureIter->second == myTempPointWDrgdID) { + addTemporaryConstraintWhereDragged(aFeatureIter->first); + break; + } + } + myNeedToSolve = myNeedToSolve || theGroup.myNeedToSolve; } @@ -993,7 +1010,8 @@ void SketchSolver_ConstraintGroup::updateEntityIfPossible( // which was moved by user // ============================================================================ void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged( - boost::shared_ptr theEntity) + boost::shared_ptr theEntity, + bool theAllowToFit) { // Find identifier of the entity std::map, Slvs_hEntity>::const_iterator anEntIter = @@ -1001,8 +1019,21 @@ void SketchSolver_ConstraintGroup::addTemporaryConstraintWhereDragged( if (anEntIter == myEntityAttrMap.end()) return; + // If this is a first dragged point, its parameters should be placed + // into Slvs_System::dragged field to avoid system inconsistense + if (myTempPointWhereDragged.empty() && theAllowToFit) { + int anEntPos = Search(anEntIter->second, myEntities); + Slvs_hParam* aDraggedParam = myEntities[anEntPos].param; + for (int i = 0; i < 4; i++, aDraggedParam++) + if (*aDraggedParam != 0) + myTempPointWhereDragged.push_back(*aDraggedParam); + myTempPointWDrgdID = myEntities[anEntPos].h; + return; + } + // Get identifiers of all dragged points std::set aDraggedPntID; + aDraggedPntID.insert(myTempPointWDrgdID); std::list::iterator aTmpCoIter = myTempConstraints.begin(); for (; aTmpCoIter != myTempConstraints.end(); aTmpCoIter++) { unsigned int aConstrPos = Search(*aTmpCoIter, myConstraints); @@ -1050,6 +1081,10 @@ void SketchSolver_ConstraintGroup::removeTemporaryConstraints() myConstrMaxID--; } myTempConstraints.clear(); + + // Clear basic dragged point + myTempPointWhereDragged.clear(); + myTempPointWDrgdID = SLVS_E_UNKNOWN; } // ============================================================================ diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index f6f450f26..f8258f90f 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -165,9 +165,13 @@ protected: const Slvs_hEntity& theEntityID); /** \brief Adds a constraint for a point which should not be changed during computations - * \param[in] theEntity the base for the constraint + * \param[in] theEntity the base for the constraint + * \param[in] theAllowToFit this flag shows that the entity may be placed into + * the 'dragged' field of SolveSpace solver, so this entity + * may be changed a little during solution */ - void addTemporaryConstraintWhereDragged(boost::shared_ptr theEntity); + void addTemporaryConstraintWhereDragged(boost::shared_ptr theEntity, + bool theAllowToFit = true); /** \brief Remove all temporary constraint after computation finished */ @@ -209,6 +213,8 @@ protected: SketchSolver_Solver myConstrSolver; ///< Solver for set of equations obtained by constraints + std::vector myTempPointWhereDragged; ///< Parameters of one of the points which is moved by user + Slvs_hEntity myTempPointWDrgdID; ///< Identifier of such point std::list myTempConstraints; ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user // SketchPlugin entities -- 2.39.2