From 37e97ce820e95060b6a448b1fcc29df3ebccea87 Mon Sep 17 00:00:00 2001 From: azv Date: Tue, 16 Feb 2016 16:46:14 +0300 Subject: [PATCH] Managing of several groups with conflicting constraints on the same sketch plane --- src/SketchSolver/SketchSolver_Group.h | 6 ++++ src/SketchSolver/SketchSolver_Manager.cpp | 40 +++++++++++++++++++++++ src/SketchSolver/SketchSolver_Manager.h | 4 +++ 3 files changed, 50 insertions(+) diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 1586f6818..f814dda84 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -61,6 +61,12 @@ class SketchSolver_Group return mySketch->data() && mySketch->data()->isValid(); } + /// \brief Check the group has conflicting constraints + inline bool isFailed() const + { + return !myConflictingConstraints.empty(); + } + /** \brief Adds or updates a constraint in the group * \param[in] theConstraint constraint to be changed * \return \c true if the constraint added or updated successfully diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index eb30c034f..453fbf5fc 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -5,6 +5,7 @@ // Author: Artem ZHIDKOV #include "SketchSolver_Manager.h" +#include "SketchSolver_Error.h" #include #include @@ -58,6 +59,9 @@ SketchSolver_Manager::SketchSolver_Manager() Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_MOVED)); + + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED)); + Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_REPAIRED)); } SketchSolver_Manager::~SketchSolver_Manager() @@ -82,6 +86,7 @@ BuilderPtr SketchSolver_Manager::builder() void SketchSolver_Manager::processEvent( const std::shared_ptr& theMessage) { + checkConflictingConstraints(theMessage); if (myIsComputed) return; myIsComputed = true; @@ -182,6 +187,41 @@ void SketchSolver_Manager::processEvent( myIsComputed = false; } +void SketchSolver_Manager::checkConflictingConstraints(const std::shared_ptr& theMessage) +{ + if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_SOLVER_REPAIRED)) { + std::shared_ptr aMessage = + std::dynamic_pointer_cast(theMessage); + std::set aSentObjs = aMessage->objects(); + if (!aSentObjs.empty()) { + // Obtain sketch where the constraints are placed. + // It is enough to check only one constraint. + CompositeFeaturePtr aSketch; + FeaturePtr aConstraint = ModelAPI_Feature::feature(*aSentObjs.begin()); + std::list::const_iterator aGrIt = myGroups.begin(); + for (; aGrIt != myGroups.end(); ++aGrIt) + if ((*aGrIt)->isInteract(aConstraint)) { + aSketch = (*aGrIt)->getWorkplane(); + break; + } + + // Search failed groups built on the same sketch + if (aSketch) { + for (aGrIt = myGroups.begin(); aGrIt != myGroups.end(); ++aGrIt) { + SketchSolver_Group* aGroup = *aGrIt; + if (aGroup->isBaseWorkplane(aSketch) && aGroup->isFailed() && + !aGroup->isInteract(aConstraint)) { + // reset error message on the sketch + aGroup->getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue( + SketchSolver_Error::CONSTRAINTS()); + break; + } + } + } + } + } +} + // ============================================================================ // Function: changeWorkplane // Purpose: update workplane by given parameters of the sketch diff --git a/src/SketchSolver/SketchSolver_Manager.h b/src/SketchSolver/SketchSolver_Manager.h index 8a6851ef3..42ec9df67 100644 --- a/src/SketchSolver/SketchSolver_Manager.h +++ b/src/SketchSolver/SketchSolver_Manager.h @@ -109,6 +109,10 @@ private: /// \brief Allow to send the Update event void allowSendUpdate() const; + /// \brief If the message shows that any group is repaired after conflicting, + /// find other groups on the same sketch, which have conflicts. + void checkConflictingConstraints(const std::shared_ptr& theMessage); + private: static SketchSolver_Manager* mySelf; ///< Self pointer to implement singleton functionality std::list myGroups; ///< Groups of constraints -- 2.39.2