// Author: Artem ZHIDKOV
#include "SketchSolver_Manager.h"
+#include "SketchSolver_Error.h"
#include <Events_Loop.h>
#include <ModelAPI_AttributeDouble.h>
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()
void SketchSolver_Manager::processEvent(
const std::shared_ptr<Events_Message>& theMessage)
{
+ checkConflictingConstraints(theMessage);
if (myIsComputed)
return;
myIsComputed = true;
myIsComputed = false;
}
+void SketchSolver_Manager::checkConflictingConstraints(const std::shared_ptr<Events_Message>& theMessage)
+{
+ if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_SOLVER_REPAIRED)) {
+ std::shared_ptr<ModelAPI_SolverFailedMessage> aMessage =
+ std::dynamic_pointer_cast<ModelAPI_SolverFailedMessage>(theMessage);
+ std::set<ObjectPtr> 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<SketchSolver_Group*>::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
/// \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<Events_Message>& theMessage);
+
private:
static SketchSolver_Manager* mySelf; ///< Self pointer to implement singleton functionality
std::list<SketchSolver_Group*> myGroups; ///< Groups of constraints