From 3112785d49cbff9374fe01fb172ae30d2b4d63c1 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 8 Oct 2019 15:23:50 +0300 Subject: [PATCH] Task 2.5 Show where the remaining degrees of freedom are (issue #2997) Implement the possibility to collect underconstrained features in SketchSolver plugin. --- .../PlaneGCSSolver/PlaneGCSSolver_Solver.cpp | 5 ++++ .../PlaneGCSSolver/PlaneGCSSolver_Solver.h | 3 +++ .../PlaneGCSSolver/PlaneGCSSolver_Storage.cpp | 24 +++++++++++++++++++ .../PlaneGCSSolver/PlaneGCSSolver_Storage.h | 3 +++ src/SketchSolver/SketchSolver_Group.cpp | 5 ++++ src/SketchSolver/SketchSolver_Group.h | 3 +++ src/SketchSolver/SketchSolver_Manager.cpp | 13 ++++++++++ src/SketchSolver/SketchSolver_Storage.h | 3 +++ 8 files changed, 59 insertions(+) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index 416b338b0..9716ae68c 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -243,6 +243,11 @@ void PlaneGCSSolver_Solver::diagnose(const GCS::Algorithm& theAlgo) myDiagnoseBeforeSolve = false; } +void PlaneGCSSolver_Solver::getFreeParameters(GCS::VEC_pD& theFreeParams) const +{ + myEquationSystem->getDependentParams(theFreeParams); +} + void PlaneGCSSolver_Solver::addFictiveConstraintIfNecessary() { bool hasOnlyMovement = true; diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index 4fb2abce9..e6c1b4ba5 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -79,6 +79,9 @@ public: /// \brief Check conflicting/redundant constraints and DoF void diagnose(const GCS::Algorithm& theAlgo = GCS::DogLeg); + /// \brief Return the list of modifiable parameters + void getFreeParameters(GCS::VEC_pD& theFreeParams) const; + /// \brief Degrees of freedom int dof(); diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index 4f546aacc..6404c4636 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -654,3 +654,27 @@ PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Storage::checkDegeneratedGeome } return PlaneGCSSolver_Solver::STATUS_OK; } + + +void PlaneGCSSolver_Storage::getUnderconstrainedGeometry(std::set& theFeatures) const +{ + std::vector aFreeParams; + mySketchSolver->getFreeParameters(aFreeParams); + if (aFreeParams.empty()) + return; + + std::map aParamOfFeatures; + for (std::map::const_iterator aFIt = myFeatureMap.begin(); + aFIt != myFeatureMap.end(); ++aFIt) { + GCS::SET_pD aParams = PlaneGCSSolver_Tools::parameters(aFIt->second); + for (GCS::SET_pD::iterator aPIt = aParams.begin(); aPIt != aParams.end(); ++aPIt) + aParamOfFeatures[*aPIt] = aFIt->first; + } + + for (std::vector::iterator anIt = aFreeParams.begin(); + anIt != aFreeParams.end(); ++anIt) { + std::map::iterator aFound = aParamOfFeatures.find(*anIt); + if (aFound != aParamOfFeatures.end()) + theFeatures.insert(aFound->second); + } +} diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h index eafa686c4..3c350e90d 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h @@ -95,6 +95,9 @@ public: /// Reversed arcs should have the last parameter lesser than the first parameter. virtual void adjustParametrizationOfArcs(); + /// \brief Return list of features which are not fully constrained + virtual void getUnderconstrainedGeometry(std::set& theFeatures) const; + private: /// \brief Convert feature using specified builder. EntityWrapperPtr createFeature(const FeaturePtr& theFeature, diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index ab9b38fc2..2662f564d 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -496,3 +496,8 @@ bool SketchSolver_Group::areConstraintsValid() const return false; return true; } + +void SketchSolver_Group::underconstrainedFeatures(std::set& theFeatures) const +{ + myStorage->getUnderconstrainedGeometry(theFeatures); +} diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index ed938f5d0..e76edf2d2 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -115,6 +115,9 @@ class SketchSolver_Group */ bool resolveConstraints(); + /// \brief Find the list of features, which are not fully constrained. + void underconstrainedFeatures(std::set& theFeatures) const; + /// \brief Block or unblock events sent by features in this group void blockEvents(bool isBlocked); diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index 00be4b13e..04fc59148 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -223,6 +223,19 @@ void SketchSolver_Manager::processEvent( } myIsComputed = false; } +//// else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURES_OF_FREEDOM)) { +//// FeaturePtr aComposite = theMessage->sketch(); +//// std::shared_ptr aSketch = +//// std::dynamic_pointer_cast(aComposite); +//// if (aSketch) { +//// SketchGroupPtr aGroup = findGroup(aSketch); +//// +//// std::set aFreeFeatures; +//// aGroup->underconstrainedFeatures(aFreeFeatures); +//// +//// // TODO: send features to GUI +//// } +//// } // resolve constraints if needed bool needToUpdate = needToResolve && resolveConstraints(); diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 0757abfb7..0f518b2fa 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -128,6 +128,9 @@ public: /// \brief Return list of conflicting constraints std::set getConflictingConstraints(SolverPtr theSolver) const; + /// \brief Return list of features which are not fully constrained + virtual void getUnderconstrainedGeometry(std::set& theFeatures) const = 0; + /// \brief Verify, the sketch contains degenerated geometry /// after resolving the set of constraints /// \return STATUS_OK if the geometry is valid, STATUS_DEGENERATED otherwise. -- 2.39.2