Salome HOME
Send messages if the sketch is failed to solve or solved correctly
authorazv <azv@opencascade.com>
Tue, 1 Sep 2015 08:20:47 +0000 (11:20 +0300)
committerazv <azv@opencascade.com>
Tue, 1 Sep 2015 08:20:47 +0000 (11:20 +0300)
src/ModelAPI/ModelAPI_Events.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Group.h

index eb64dc19efbf29a8d77c763c3f9021b12ee17209..545a347681749a847f21dd3701ca8be05baee3a5 100644 (file)
@@ -48,6 +48,9 @@ static const char * EVENT_FEATURE_STATE_RESPONSE = "FeatureStateResponse";
 static const char * EVENT_UPDATE_VIEWER_BLOCKED = "UpdateViewerBlocked";
 static const char * EVENT_UPDATE_VIEWER_UNBLOCKED = "UpdateViewerUnblocked";
 
+static const char * EVENT_SOLVER_FAILED = "SolverFailed";
+static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired";
+
 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
 {
index 08f594fe7dc90af4776ea05c7e68de734c64815c..8d8b8173554d0a7531a46564ac48fb29471e93d9 100644 (file)
@@ -67,6 +67,14 @@ private:
 Slvs_hGroup GroupIndexer::myGroupIndex = 0;
 
 
+static void sendMessage(const char* theMessageName)
+{
+  std::shared_ptr<Events_Message> aMessage = std::shared_ptr<Events_Message>(
+      new Events_Message(Events_Loop::eventByName(theMessageName)));
+  Events_Loop::loop()->send(aMessage);
+}
+
+
 
 // ========================================================
 // =========  SketchSolver_Group  ===============
@@ -74,7 +82,8 @@ Slvs_hGroup GroupIndexer::myGroupIndex = 0;
 
 SketchSolver_Group::SketchSolver_Group(
     std::shared_ptr<ModelAPI_CompositeFeature> theWorkplane)
-    : myID(GroupIndexer::NEW_GROUP())
+    : myID(GroupIndexer::NEW_GROUP()),
+      myPrevSolved(true)
 {
   // Initialize workplane
   myWorkplaneID = SLVS_E_UNKNOWN;
@@ -466,6 +475,10 @@ bool SketchSolver_Group::resolveConstraints()
       }
     } catch (...) {
       Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
+      if (myPrevSolved) {
+        sendMessage(EVENT_SOLVER_FAILED);
+        myPrevSolved = false;
+      }
       return false;
     }
     if (aResult == SLVS_RESULT_OKAY) {  // solution succeeded, store results into correspondent attributes
@@ -474,8 +487,17 @@ bool SketchSolver_Group::resolveConstraints()
       for (; aConstrIter != myConstraints.end(); aConstrIter++)
         aConstrIter->second->refresh();
       myFeatureStorage->blockEvents(false);
-    } else if (!myConstraints.empty())
+      if (!myPrevSolved) {
+        sendMessage(EVENT_SOLVER_REPAIRED);
+        myPrevSolved = true;
+      }
+    } else if (!myConstraints.empty()) {
       Events_Error::send(SketchSolver_Error::CONSTRAINTS(), this);
+      if (myPrevSolved) {
+        sendMessage(EVENT_SOLVER_FAILED);
+        myPrevSolved = false;
+      }
+    }
 
     aResolved = true;
   }
index 79f5f9fe04350c2ec7f5f4c7d0bbe9f3ee4342aa..13f614c754cfc3fc8099e434f45b4a428e9c3592 100644 (file)
@@ -168,6 +168,8 @@ private:
   FeatureStoragePtr myFeatureStorage; ///< Container for the set of SketchPlugin features and their dependencies
 
   SketchSolver_Solver myConstrSolver;  ///< Solver for set of equations obtained by constraints
+
+  bool myPrevSolved; ///< Indicates that previous solving was done correctly
 };
 
 #endif