]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchSolver/SketchSolver_Solver.cpp
Salome HOME
Add tools
[modules/shaper.git] / src / SketchSolver / SketchSolver_Solver.cpp
index 650e11c2d79b12c9a261e355c45500c1358acd5d..36979d7474e67dceab857105e0fdd64155b1a5c4 100644 (file)
@@ -9,6 +9,7 @@
 
 SketchSolver_Solver::SketchSolver_Solver()
 {
+  myGroupID = 0;
   // Nullify all elements of the set of equations
   myEquationsSystem.param = 0;
   myEquationsSystem.params = 0;
@@ -26,13 +27,17 @@ SketchSolver_Solver::SketchSolver_Solver()
 
   // If the set of constraints is inconsistent,
   // the failed field will contain wrong constraints
-  myEquationsSystem.calculateFaileds = 1;
+  myEquationsSystem.calculateFaileds = 0;
 }
 
 SketchSolver_Solver::~SketchSolver_Solver()
 {
+  if (myEquationsSystem.constraint)
+    delete[] myEquationsSystem.constraint;
+  myEquationsSystem.constraint = 0;
   if (myEquationsSystem.failed)
     delete[] myEquationsSystem.failed;
+  myEquationsSystem.failed = 0;
 }
 
 void SketchSolver_Solver::setParameters(Slvs_Param* theParameters, int theSize)
@@ -56,8 +61,23 @@ void SketchSolver_Solver::setEntities(Slvs_Entity* theEntities, int theSize)
 
 void SketchSolver_Solver::setConstraints(Slvs_Constraint* theConstraints, int theSize)
 {
-  myEquationsSystem.constraint = theConstraints;
-  myEquationsSystem.constraints = theSize;
+  if (!myEquationsSystem.constraint) {
+    myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+    myEquationsSystem.constraints = theSize;
+    myEquationsSystem.failed = new Slvs_hConstraint[theSize];
+  }
+  else if (myEquationsSystem.constraints != theSize) {
+    if (theSize > myEquationsSystem.constraints) {
+      delete[] myEquationsSystem.constraint;
+      myEquationsSystem.constraint = new Slvs_Constraint[theSize];
+      if (myEquationsSystem.failed)
+        delete[] myEquationsSystem.failed;
+      myEquationsSystem.failed = new Slvs_hConstraint[theSize];
+    }
+    myEquationsSystem.constraints = theSize;
+  }
+  memcpy(myEquationsSystem.constraint, theConstraints, theSize * sizeof(Slvs_Constraint));
+  memset(myEquationsSystem.failed, SLVS_C_UNKNOWN, theSize * sizeof(Slvs_hConstraint));
 }