From 58c49c9bea03fb99e7d94fdbe2f95516b76e593a Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 14 Aug 2015 18:22:47 +0300 Subject: [PATCH] Changes to avoid "conflicting constraints" during rotation and translation --- .../SketchSolver_ConstraintMultiRotation.cpp | 20 +++++++++++++++---- .../SketchSolver_ConstraintMultiRotation.h | 1 + ...ketchSolver_ConstraintMultiTranslation.cpp | 19 ++++++++++++++---- .../SketchSolver_ConstraintMultiTranslation.h | 1 + 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index 53f7af568..d93983f72 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -138,13 +138,24 @@ void SketchSolver_ConstraintMultiRotation::process() mySlvsConstraints.push_back(aConstraint.h); } - // Set all objects unchanged (only initial object may be changed by user) + // Keep all objects unchanged (only initial object may be changed by user) myCircsAndCopies.clear(); std::vector >::const_iterator anEntIt = anEntitiesAndCopies.begin(); std::vector::const_iterator aCpIt; for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) { std::vector aCircs; - for (aCpIt = anEntIt->begin(); aCpIt != anEntIt->end(); ++aCpIt) { + aCpIt = anEntIt->begin(); + // Obtain initial points + Slvs_Entity anInitial = myStorage->getEntity(*aCpIt); + if (anInitial.type == SLVS_E_POINT_IN_2D || anInitial.type == SLVS_E_POINT_IN_3D) + myInitialPoints.insert(anInitial.h); + else { + for (int i = 0; i < 4 && anInitial.point[i] != SLVS_E_UNKNOWN; i++) + myInitialPoints.insert(anInitial.point[i]); + } + + // Fix the copies + for (++aCpIt; aCpIt != anEntIt->end(); ++aCpIt) { const Slvs_Entity& anEntity = myStorage->getEntity(*aCpIt); std::vector aNewConstr; if (anEntity.type == SLVS_E_CIRCLE) { @@ -222,6 +233,7 @@ bool SketchSolver_ConstraintMultiRotation::remove(ConstraintPtr theConstraint) // Clear list of rotated points myPointsAndCopies.clear(); + myInitialPoints.clear(); return true; } @@ -293,8 +305,8 @@ void SketchSolver_ConstraintMultiRotation::adjustConstraint() // we will update its position correspondingly Slvs_hConstraint aFixed; for (aCoIt = aCoincident.begin(); aCoIt != aCoincident.end(); ++aCoIt) { - if ((aCoIt->ptA == anInitial.h && myStorage->isPointFixed(aCoIt->ptB, aFixed, true)) || - (aCoIt->ptB == anInitial.h && myStorage->isPointFixed(aCoIt->ptA, aFixed, true))) { + if ((aCoIt->ptA == anInitial.h && myInitialPoints.find(aCoIt->ptB) != myInitialPoints.end()) || + (aCoIt->ptB == anInitial.h && myInitialPoints.find(aCoIt->ptA) != myInitialPoints.end())) { Slvs_hEntity anOtherId = aCoIt->ptA == anInitial.h ? aCoIt->ptB : aCoIt->ptA; if (!myStorage->isTemporary(aFixed) && myPointsJustUpdated.find(anOtherId) == myPointsJustUpdated.end()) diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h index f3a0f64fc..3294112dd 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h @@ -69,6 +69,7 @@ private: std::vector< std::vector > myCircsAndCopies; ///< list of circles and their copies (to change their radii together) std::set myPointsJustUpdated; ///< list of points touched by user + std::set myInitialPoints; ///< list of points containig initial objects }; #endif diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp index 5b7b27538..28da9cf9a 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp @@ -138,13 +138,24 @@ void SketchSolver_ConstraintMultiTranslation::process() } } - // Set all objects unchanged (only initial object may be changed by user) + // Keep all objects unchanged (only initial object may be changed by user) myCircsAndCopies.clear(); std::vector >::const_iterator anEntIt = anEntitiesAndCopies.begin(); std::vector::const_iterator aCpIt; for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) { std::vector aCircs; - for (aCpIt = anEntIt->begin(); aCpIt != anEntIt->end(); ++aCpIt) { + aCpIt = anEntIt->begin(); + // Obtain initial points + Slvs_Entity anInitial = myStorage->getEntity(*aCpIt); + if (anInitial.type == SLVS_E_POINT_IN_2D || anInitial.type == SLVS_E_POINT_IN_3D) + myInitialPoints.insert(anInitial.h); + else { + for (int i = 0; i < 4 && anInitial.point[i] != SLVS_E_UNKNOWN; i++) + myInitialPoints.insert(anInitial.point[i]); + } + + // Fix the copies + for (++aCpIt; aCpIt != anEntIt->end(); ++aCpIt) { const Slvs_Entity& anEntity = myStorage->getEntity(*aCpIt); std::vector aNewConstr; if (anEntity.type == SLVS_E_CIRCLE) { @@ -279,8 +290,8 @@ void SketchSolver_ConstraintMultiTranslation::adjustConstraint() // we will update its position correspondingly Slvs_hConstraint aFixed; for (aCoIt = aCoincident.begin(); aCoIt != aCoincident.end(); ++aCoIt) { - if ((aCoIt->ptA == anInitial.h && myStorage->isPointFixed(aCoIt->ptB, aFixed, true)) || - (aCoIt->ptB == anInitial.h && myStorage->isPointFixed(aCoIt->ptA, aFixed, true))) { + if ((aCoIt->ptA == anInitial.h && myInitialPoints.find(aCoIt->ptB) != myInitialPoints.end()) || + (aCoIt->ptB == anInitial.h && myInitialPoints.find(aCoIt->ptA) != myInitialPoints.end())) { Slvs_hEntity anOtherId = aCoIt->ptA == anInitial.h ? aCoIt->ptB : aCoIt->ptA; if (!myStorage->isTemporary(aFixed) && myPointsJustUpdated.find(anOtherId) == myPointsJustUpdated.end()) diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h index bed7df229..10d44dbf1 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h @@ -67,6 +67,7 @@ private: std::vector< std::vector > myCircsAndCopies; ///< list of circles and their copies (to change their radii together) std::set myPointsJustUpdated; ///< list of points touched by user + std::set myInitialPoints; ///< list of points containig initial objects }; #endif -- 2.39.2