From: azv Date: Tue, 1 Sep 2015 08:20:47 +0000 (+0300) Subject: Send messages if the sketch is failed to solve or solved correctly X-Git-Tag: V_1.4.0_beta4~176 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7150ba67eb25e5b24052c70eb689702f84620e19;p=modules%2Fshaper.git Send messages if the sketch is failed to solve or solved correctly --- diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index eb64dc19e..545a34768 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -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 { diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 08f594fe7..8d8b81735 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -67,6 +67,14 @@ private: Slvs_hGroup GroupIndexer::myGroupIndex = 0; +static void sendMessage(const char* theMessageName) +{ + std::shared_ptr aMessage = std::shared_ptr( + 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 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; } diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 79f5f9fe0..13f614c75 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -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