]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task 2.6. Change color of fully constrained sketch
authorazv <azv@opencascade.com>
Tue, 28 Mar 2017 07:04:31 +0000 (10:04 +0300)
committerazv <azv@opencascade.com>
Tue, 28 Mar 2017 07:05:32 +0000 (10:05 +0300)
src/ModelAPI/ModelAPI_Events.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Group.h

index 92d20059956d31854c35df24c2eb6a7273cd75d3..bbe18f7b6dc92152045a4e247529dad41ae1df13 100644 (file)
@@ -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";
 
index 7e01d45f97902516bfaf9e99fb53f81e087c2524..709407ee5d79cb9594f433db8f3ab60a75102aea 100644 (file)
@@ -34,6 +34,20 @@ static void sendMessage(const char* theMessageName, const std::set<ObjectPtr>& t
   Events_Loop::loop()->send(aMessage);
 }
 
+static void sendMessage(const char* theMessageName, const CompositeFeaturePtr& theSketch, const int theDOF)
+{
+  std::shared_ptr<ModelAPI_SolverFailedMessage> aMessage =
+      std::shared_ptr<ModelAPI_SolverFailedMessage>(
+      new ModelAPI_SolverFailedMessage(Events_Loop::eventByName(theMessageName)));
+
+  std::set<ObjectPtr> 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<ObjectPtr>& 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;
 }
 
 // ============================================================================
index 7e8c9424f1f55e91119f53c2c8fb17d491aa95d6..a9d305a44a0ddcc9329f09f4e84f8e977a06eed6 100644 (file)
@@ -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<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
 
+  int  myDOF; ///< degrees of freedom of the current sketch
+
   bool myIsEventsBlocked; ///< shows the events are blocked for this group
 };