]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix crashes caused by PlaneGCSSolver connector (issue #1538)
authorazv <azv@opencascade.com>
Thu, 2 Jun 2016 11:57:43 +0000 (14:57 +0300)
committerazv <azv@opencascade.com>
Thu, 2 Jun 2016 11:57:43 +0000 (14:57 +0300)
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ParameterWrapper.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp
src/SketchSolver/SketchSolver_Storage.cpp

index 0a271ffab432c73727f4aaa9f7ed3baf65fd5d2c..9c0dfde11b63ef903a5947aac3d442fb9a266b78 100644 (file)
@@ -16,7 +16,8 @@ PlaneGCSSolver_ParameterWrapper::PlaneGCSSolver_ParameterWrapper(double *const t
 
 PlaneGCSSolver_ParameterWrapper::~PlaneGCSSolver_ParameterWrapper()
 {
-  delete myValue;
+  if (!myProcessing)
+    delete myValue;
 }
 
 void PlaneGCSSolver_ParameterWrapper::setValue(double theValue)
index efd48c3618f8ebfe4583d49822f634e734591242..b7c7591af49253f8eab8625d2460f99bdc2c76b5 100644 (file)
@@ -15,9 +15,7 @@ PlaneGCSSolver_Solver::~PlaneGCSSolver_Solver()
 
 void PlaneGCSSolver_Solver::clear()
 {
-  std::set<GCS::Constraint*>::const_iterator anIt = myConstraints.begin();
-  for (; anIt != myConstraints.end(); ++anIt)
-    myEquationSystem.removeConstraint(*anIt);
+  myEquationSystem.clear();
   myConstraints.clear();
   myParameters.clear();
 }
@@ -80,8 +78,10 @@ SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve()
   if (aResult == GCS::Success) {
     myEquationSystem.applySolution();
     aStatus = STATUS_OK;
-  } else
+  } else {
+    undo();
     aStatus = STATUS_FAILED;
+  }
 
   return aStatus;
 }
index 0c00e30646dce550ea5eb2aabbf739e1499a12cf..84dc0c9726a9a8c945ef173b69f6a560a2789384 100644 (file)
@@ -239,6 +239,16 @@ bool PlaneGCSSolver_Storage::remove(ConstraintWrapperPtr theConstraint)
 bool PlaneGCSSolver_Storage::remove(EntityWrapperPtr theEntity)
 {
   bool isFullyRemoved = SketchSolver_Storage::remove(theEntity);
+  if (theEntity->type() == ENTITY_ARC) {
+    // remove arc additional constraints
+    std::map<EntityWrapperPtr, std::vector<GCSConstraintPtr> >::iterator
+        aFound = myArcConstraintMap.find(theEntity);
+    if (aFound != myArcConstraintMap.end()) {
+      myRemovedConstraints.insert(myRemovedConstraints.end(),
+          aFound->second.begin(), aFound->second.end());
+      myArcConstraintMap.erase(aFound);
+    }
+  }
   if (isFullyRemoved && theEntity->id() == myEntityLastID)
     --myEntityLastID;
   return isFullyRemoved;
@@ -257,6 +267,7 @@ bool PlaneGCSSolver_Storage::remove(ParameterWrapperPtr theParameter)
     if (anIt != myParameters.end()) {
       myParameters.erase(anIt);
       setNeedToResolve(true);
+      aParam->setProcessed(false);
     }
     else {
       for (anIt = myConst.begin(); anIt != myConst.end(); ++anIt)
@@ -265,10 +276,10 @@ bool PlaneGCSSolver_Storage::remove(ParameterWrapperPtr theParameter)
       if (anIt != myConst.end()) {
         myConst.erase(anIt);
         setNeedToResolve(true);
+        aParam->setProcessed(false);
       }
     }
   }
-  aParam->setProcessed(false);
   return true;
 }
 
@@ -531,6 +542,7 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver)
       std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(theSolver);
   if (!aSolver)
     return;
+  aSolver->clear();
 
   if (myExistArc)
     processArcs();
index 688f6b35a4f80a2f9019cc92e2df1ada06629ae9..a3b68b0872c4f846313ced95e31a8b17f0e1a190 100644 (file)
@@ -602,8 +602,13 @@ bool SketchSolver_Storage::remove(EntityWrapperPtr theEntity)
     FeaturePtr aBaseFeature = (*anEntIt)->baseFeature();
     if (aBaseFeature)
       isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseFeature) && isFullyRemoved;
-    else
-      isFullyRemoved = SketchSolver_Storage::removeEntity((*anEntIt)->baseAttribute()) && isFullyRemoved;
+    else {
+      AttributePtr aBaseAttr = (*anEntIt)->baseAttribute();
+      if (aBaseAttr)
+        isFullyRemoved = SketchSolver_Storage::removeEntity(aBaseAttr) && isFullyRemoved;
+      else
+        remove(*anEntIt);
+    }
   }
 
   std::list<ParameterWrapperPtr>::const_iterator aParIt = theEntity->parameters().begin();