From: azv Date: Thu, 29 May 2014 07:02:46 +0000 (+0400) Subject: Removing of coincidence constraints was changed. The crash when abort drawing line... X-Git-Tag: V_0.4.4~339^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d7221651e77934d198d3bf9c32a9a345545ea680;p=modules%2Fshaper.git Removing of coincidence constraints was changed. The crash when abort drawing line was fixed --- diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp index df5111e6d..3b8a08211 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.cpp @@ -194,8 +194,11 @@ bool SketchSolver_ConstraintGroup::changeConstraint( aCoPtIter->find(aConstrEnt[0]) != aCoPtIter->end(), aCoPtIter->find(aConstrEnt[1]) != aCoPtIter->end(), }; - if (isFound[0] && isFound[1]) // points are already connected by coincidence constraints => no need to additional one + if (isFound[0] && isFound[1]) // points are already connected by coincidence constraints => no need additional one + { + myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes return false; + } if ((isFound[0] && !isFound[1]) || (!isFound[0] && isFound[1])) { if (aFirstFound != myCoincidentPoints.end()) @@ -637,7 +640,7 @@ void SketchSolver_ConstraintGroup::splitGroup(std::vector aNewGrEnt; @@ -706,12 +709,35 @@ bool SketchSolver_ConstraintGroup::updateGroup() std::map, Slvs_hConstraint>::reverse_iterator aConstrIter = myConstraintMap.rbegin(); bool isAllValid = true; - for ( ; isAllValid && aConstrIter != myConstraintMap.rend(); aConstrIter++) + bool isCCRemoved = false; // indicates that at least one of coincidence constraints was removed + while (isAllValid && aConstrIter != myConstraintMap.rend()) + { if (!aConstrIter->first->data()->isValid()) { - removeConstraint(aConstrIter->first); + if (aConstrIter->first->getKind().compare("SketchConstraintCoincidence") == 0) + isCCRemoved = true; + std::map, Slvs_hConstraint>::reverse_iterator + aCopyIter = aConstrIter++; + removeConstraint(aCopyIter->first); isAllValid = false; } + else aConstrIter++; + } + + // Probably, need to update coincidence constraints + if (isCCRemoved && !myExtraCoincidence.empty()) + { + // Make a copy, because the new list of unused constrtaints will be generated + std::set< boost::shared_ptr > anExtraCopy = myExtraCoincidence; + myExtraCoincidence.clear(); + + std::set< boost::shared_ptr >::iterator + aCIter = anExtraCopy.begin(); + for ( ; aCIter != anExtraCopy.end(); aCIter++) + if ((*aCIter)->data()->isValid()) + changeConstraint(*aCIter); + } + return !isAllValid; } @@ -962,6 +988,8 @@ void SketchSolver_ConstraintGroup::removeConstraint(boost::shared_ptrerase(*aRemIter); } + if (myCoincidentPoints.size() == 1 && myCoincidentPoints.front().empty()) + myCoincidentPoints.clear(); } diff --git a/src/SketchSolver/SketchSolver_ConstraintGroup.h b/src/SketchSolver/SketchSolver_ConstraintGroup.h index c24268f30..fe629046b 100644 --- a/src/SketchSolver/SketchSolver_ConstraintGroup.h +++ b/src/SketchSolver/SketchSolver_ConstraintGroup.h @@ -175,10 +175,6 @@ private: 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 - // NOTE: First ID in the list corresponds to myTempPointWhereDragged parameters and does not added to myConstraints list - - std::vector< std::set > - myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints) // SketchPlugin entities boost::shared_ptr @@ -187,6 +183,13 @@ private: myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints std::map, Slvs_hEntity> myEntityMap; ///< The map between parameters of constraints and their equivalent SolveSpace entities + + // Conincident items + std::vector< std::set > + myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints) + std::set< boost::shared_ptr > + myExtraCoincidence; ///< Additional coincidence constraints which are not necessary (coincidence between points already done + ///< by other constraints) but created by GUI tools. Useful when some coincidence constraints were removed }; #endif diff --git a/src/SketchSolver/SketchSolver_Solver.cpp b/src/SketchSolver/SketchSolver_Solver.cpp index be307be93..40c76d1a7 100644 --- a/src/SketchSolver/SketchSolver_Solver.cpp +++ b/src/SketchSolver/SketchSolver_Solver.cpp @@ -97,7 +97,7 @@ void SketchSolver_Solver::setConstraints(const std::vector& the if (myEquationsSystem.failed) delete [] myEquationsSystem.failed; myEquationsSystem.failed = new Slvs_hConstraint[theConstraints.size()]; - myEquationsSystem.faileds = 0; + myEquationsSystem.faileds = theConstraints.size(); } // Copy data