From: azv Date: Tue, 28 Mar 2017 07:04:31 +0000 (+0300) Subject: Task 2.6. Change color of fully constrained sketch X-Git-Tag: V_2.7.0~170 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6d20474c626b44f4a66089dbe799fd250c208eb5;p=modules%2Fshaper.git Task 2.6. Change color of fully constrained sketch --- diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 92d200599..bbe18f7b6 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -70,6 +70,13 @@ static const char * EVENT_SOLVER_FAILED = "SolverFailed"; /// Event ID that the problem in solver disappeared static const char * EVENT_SOLVER_REPAIRED = "SolverRepaired"; +/// Event Id that sketch has DoF = 0 +static const char * EVENT_SKETCH_FULLY_CONSTRAINED = "SketchFullyConstrainted"; +/// Event Id that sketch has DoF > 0 +static const char * EVENT_SKETCH_UNDER_CONSTRAINED = "SketchUnderConstrainted"; +/// Event Id that sketch has DoF < 0 +static const char * EVENT_SKETCH_OVER_CONSTRAINED = "SketchOverConstrainted"; + /// Event ID that informs that some object has changed the stability static const char * EVENT_STABILITY_CHANGED = "StabilityChanged"; diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index 7e01d45f9..709407ee5 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -34,6 +34,20 @@ static void sendMessage(const char* theMessageName, const std::set& t Events_Loop::loop()->send(aMessage); } +static void sendMessage(const char* theMessageName, const CompositeFeaturePtr& theSketch, const int theDOF) +{ + std::shared_ptr aMessage = + std::shared_ptr( + new ModelAPI_SolverFailedMessage(Events_Loop::eventByName(theMessageName))); + + std::set anObjects; + anObjects.insert(theSketch); + aMessage->setObjects(anObjects); + aMessage->dof(theDOF); + + Events_Loop::loop()->send(aMessage); +} + // ======================================================== @@ -43,6 +57,7 @@ static void sendMessage(const char* theMessageName, const std::set& t SketchSolver_Group::SketchSolver_Group(const CompositeFeaturePtr& theWorkplane) : mySketch(theWorkplane), myPrevResult(PlaneGCSSolver_Solver::STATUS_UNKNOWN), + myDOF(0), myIsEventsBlocked(false) { mySketchSolver = SolverPtr(new PlaneGCSSolver_Solver); @@ -93,6 +108,12 @@ bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) bool SketchSolver_Group::moveFeature(FeaturePtr theFeature) { + if (myDOF == 0) { + // avoid moving elements of fully constrained sketch + myStorage->refresh(); + return true; + } + // Create temporary Fixed constraint SolverConstraintPtr aConstraint = PlaneGCSSolver_Tools::createMovementConstraint(theFeature); if (!aConstraint) @@ -210,15 +231,24 @@ bool SketchSolver_Group::resolveConstraints() // Class: SketchSolver_Group // Purpose: compute DoF of the sketch and set corresponding field // ============================================================================ -void SketchSolver_Group::computeDoF() const +void SketchSolver_Group::computeDoF() { std::ostringstream aDoFMsg; - int aDoF = /*isEmpty() ? myStorage->numberOfParameters() :*/ mySketchSolver->dof(); + int aDoF = mySketchSolver->dof(); if (aDoF == 0) aDoFMsg << "Sketch is fully fixed (DoF = 0)"; else aDoFMsg << "DoF (degrees of freedom) = " << aDoF; mySketch->string(SketchPlugin_Sketch::SOLVER_DOF())->setValue(aDoFMsg.str()); + + if (aDoF > 0 && myDOF == 0) + sendMessage(EVENT_SKETCH_UNDER_CONSTRAINED, mySketch, aDoF); + else if (aDoF == 0 && myDOF > 0) + sendMessage(EVENT_SKETCH_FULLY_CONSTRAINED, mySketch, aDoF); + else if (aDoF < 0) + sendMessage(EVENT_SKETCH_OVER_CONSTRAINED, mySketch, aDoF); + + myDOF = aDoF; } // ============================================================================ diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index 7e8c9424f..a9d305a44 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -96,7 +96,7 @@ private: void setTemporary(SolverConstraintPtr theConstraint); /// \brief Compute DoF of the sketch and set corresponding field - void computeDoF() const; + void computeDoF(); private: CompositeFeaturePtr mySketch; ///< Sketch for this group @@ -110,6 +110,8 @@ private: PlaneGCSSolver_Solver::SolveStatus myPrevResult; std::set myConflictingConstraints; ///< List of conflicting constraints + int myDOF; ///< degrees of freedom of the current sketch + bool myIsEventsBlocked; ///< shows the events are blocked for this group };