Salome HOME
Managing of several groups with conflicting constraints on the same sketch plane
authorazv <azv@opencascade.com>
Tue, 16 Feb 2016 13:46:14 +0000 (16:46 +0300)
committerdbv <dbv@opencascade.com>
Wed, 17 Feb 2016 11:29:47 +0000 (14:29 +0300)
src/SketchSolver/SketchSolver_Group.h
src/SketchSolver/SketchSolver_Manager.cpp
src/SketchSolver/SketchSolver_Manager.h

index 1586f6818924a2710ddd7ef7aba0e658bc474a74..f814dda84a19e87a8586fd46197b8c8a0a46070b 100644 (file)
@@ -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
index eb30c034f34601cd1d9c646578e43ff279086bd3..453fbf5fc15b4eb6e5d29bed13a888fcf3666a35 100644 (file)
@@ -5,6 +5,7 @@
 // Author:  Artem ZHIDKOV
 
 #include "SketchSolver_Manager.h"
+#include "SketchSolver_Error.h"
 
 #include <Events_Loop.h>
 #include <ModelAPI_AttributeDouble.h>
@@ -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<Events_Message>& 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<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
index 8a6851ef376f924567c26de99154729394f6c9b1..42ec9df676b4c8a07b80ae83f1566571a739430b 100644 (file)
@@ -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<Events_Message>& theMessage);
+
 private:
   static SketchSolver_Manager*     mySelf;    ///< Self pointer to implement singleton functionality
   std::list<SketchSolver_Group*>   myGroups;  ///< Groups of constraints