From 7e738aefbfe841ed93b104a56fd492aee68b3fd0 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 21 Mar 2017 10:02:28 +0300 Subject: [PATCH] Improve movement of single point of a constrained feature. This change caused by incorrect "conflicting constraints" message while moving the feature under Horizontal constraint. The problem is the fixing of the whole feature even in case of single point is moved. There has been implemented searching of the changed attribute and fixing it only. --- .../PlaneGCSSolver_PointWrapper.h | 2 + .../SketchSolver_ConstraintFixed.cpp | 54 ++++++++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_PointWrapper.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_PointWrapper.h index 4e536d7a0..8acd7df4b 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_PointWrapper.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_PointWrapper.h @@ -33,4 +33,6 @@ private: GCSPointPtr myPoint; }; +typedef std::shared_ptr PointWrapperPtr; + #endif diff --git a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp index 68200eb2e..41ba5d46b 100644 --- a/src/SketchSolver/SketchSolver_ConstraintFixed.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintFixed.cpp @@ -7,17 +7,19 @@ #include #include +#include + +#include + +// Find parameters of the feature that have been updated during the movement +static EntityWrapperPtr getChangedEntity(const FeaturePtr& theFeature, + const StoragePtr& theStorage); + SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(ConstraintPtr theConstraint) : SketchSolver_Constraint(theConstraint) { myType = CONSTRAINT_FIXED; -//// AttributeRefAttrPtr anAttribute = -//// theConstraint->refattr(SketchPlugin_ConstraintRigid::ENTITY_A()); -//// if (anAttribute->isObject()) -//// myFixedFeature = ModelAPI_Feature::feature(anAttribute->object()); -//// else -//// myFixedAttribute = anAttribute->attr(); } SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature) @@ -25,7 +27,6 @@ SketchSolver_ConstraintFixed::SketchSolver_ConstraintFixed(FeaturePtr theFeature myBaseFeature(theFeature) { myType = CONSTRAINT_FIXED; -//// process(); } void SketchSolver_ConstraintFixed::blockEvents(bool isBlocked) @@ -125,8 +126,8 @@ void SketchSolver_ConstraintFixed::getAttributes( { if (myBaseFeature) { // The feature is fixed. + EntityWrapperPtr aSolverEntity = getChangedEntity(myBaseFeature, myStorage); myStorage->update(myBaseFeature); - EntityWrapperPtr aSolverEntity = myStorage->entity(myBaseFeature); if (aSolverEntity) theAttributes.push_back(aSolverEntity); } else if (myBaseConstraint) { @@ -141,3 +142,40 @@ void SketchSolver_ConstraintFixed::getAttributes( } else myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); } + + + + +// ==================== Auxiliary functions =============================== +static bool isSameCoordinates(const AttributePoint2DPtr& thePointAttr, + const PointWrapperPtr& thePointWrapper) +{ + GCSPointPtr aGCSPoint = thePointWrapper->point(); + return fabs(*aGCSPoint->x - thePointAttr->x()) < tolerance && + fabs(*aGCSPoint->y - thePointAttr->y()) < tolerance; +} + +EntityWrapperPtr getChangedEntity(const FeaturePtr& theFeature, + const StoragePtr& theStorage) +{ + std::list aPoints = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list aChangedPoints; + + std::list::const_iterator aPIt = aPoints.begin(); + for (; aPIt != aPoints.end(); ++aPIt) { + AttributePoint2DPtr aPnt = std::dynamic_pointer_cast(*aPIt); + EntityWrapperPtr anEnt = theStorage->entity(*aPIt); + if (!anEnt) + continue; + PointWrapperPtr aPW = std::dynamic_pointer_cast(anEnt); + if (!isSameCoordinates(aPnt, aPW)) + aChangedPoints.push_back(anEnt); + } + + EntityWrapperPtr aChanged; + if (aChangedPoints.size() == 1) + aChanged = aChangedPoints.front(); + else if (!aChangedPoints.empty()) // update whole feature + aChanged = theStorage->entity(theFeature); + return aChanged; +} -- 2.39.2