Salome HOME
Wait cursor for solver operation
[modules/shaper.git] / src / SketchSolver / SketchSolver_Solver.cpp
index f9ed8c37204c788a6de8c685faac995fe3b30af9..b91d267f61b4625b1402b314787a0253a0850d66 100644 (file)
@@ -3,6 +3,7 @@
 // Author:  Artem ZHIDKOV
 
 #include "SketchSolver_Solver.h"
+#include <Events_LongOp.h>
 
 SketchSolver_Solver::SketchSolver_Solver()
 {
@@ -16,6 +17,11 @@ SketchSolver_Solver::SketchSolver_Solver()
   myEquationsSystem.failed = 0;
   myEquationsSystem.faileds = 0;
 
+  myEquationsSystem.dragged[0] = 0;
+  myEquationsSystem.dragged[1] = 0;
+  myEquationsSystem.dragged[2] = 0;
+  myEquationsSystem.dragged[3] = 0;
+
   // If the set of constraints is inconsistent,
   // the failed field will contain wrong constraints
   myEquationsSystem.calculateFaileds = 1;
@@ -49,6 +55,20 @@ void SketchSolver_Solver::setParameters(const std::vector<Slvs_Param>& theParame
     myEquationsSystem.param[i] = *aParamIter;
 }
 
+void SketchSolver_Solver::setDraggedParameters(const std::vector<Slvs_hParam>& theDragged)
+{
+  if (theDragged.size() == 0)
+  {
+    myEquationsSystem.dragged[0] = 0;
+    myEquationsSystem.dragged[1] = 0;
+    myEquationsSystem.dragged[2] = 0;
+    myEquationsSystem.dragged[3] = 0;
+    return;
+  }
+  for (unsigned int i = 0; i < theDragged.size(); i++)
+    myEquationsSystem.dragged[i] = theDragged[i];
+}
+
 void SketchSolver_Solver::setEntities(const std::vector<Slvs_Entity>& theEntities)
 {
   if (theEntities.size() != myEquationsSystem.entities) // number of entities was changed => reallocate the memory
@@ -73,6 +93,12 @@ void SketchSolver_Solver::setConstraints(const std::vector<Slvs_Constraint>& the
       delete [] myEquationsSystem.constraint;
     myEquationsSystem.constraints = theConstraints.size();
     myEquationsSystem.constraint = new Slvs_Constraint[theConstraints.size()];
+
+    // Assign the memory for the failed constraints
+    if (myEquationsSystem.failed)
+      delete [] myEquationsSystem.failed;
+    myEquationsSystem.failed = new Slvs_hConstraint[theConstraints.size()];
+    myEquationsSystem.faileds = theConstraints.size();
   }
 
   // Copy data
@@ -86,7 +112,9 @@ int SketchSolver_Solver::solve()
   if (myEquationsSystem.constraints <= 0)
     return SLVS_RESULT_EMPTY_SET;
 
+  Events_LongOp::start(this);
   Slvs_Solve(&myEquationsSystem, myGroupID);
+  Events_LongOp::end(this);
 
   return myEquationsSystem.result;
 }