]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Removing of coincidence constraints was changed. The crash when abort drawing line...
authorazv <azv@opencascade.com>
Thu, 29 May 2014 07:02:46 +0000 (11:02 +0400)
committerazv <azv@opencascade.com>
Thu, 29 May 2014 07:02:46 +0000 (11:02 +0400)
src/SketchSolver/SketchSolver_ConstraintGroup.cpp
src/SketchSolver/SketchSolver_ConstraintGroup.h
src/SketchSolver/SketchSolver_Solver.cpp

index df5111e6d81cdf8701e12d63fadd89074f72e620..3b8a08211c51475eed4cd5c70dfb7049566c2069 100644 (file)
@@ -194,8 +194,11 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
           aCoPtIter->find(aConstrEnt[0]) != aCoPtIter->end(),
           aCoPtIter->find(aConstrEnt[1]) != aCoPtIter->end(),
         };
-        if (isFound[0] && isFound[1]) // points are already connected by coincidence constraints => no need to additional one
+        if (isFound[0] && isFound[1]) // points are already connected by coincidence constraints => no need additional one
+        {
+          myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes
           return false;
+        }
         if ((isFound[0] && !isFound[1]) || (!isFound[0] && isFound[1]))
         {
           if (aFirstFound != myCoincidentPoints.end())
@@ -637,7 +640,7 @@ void SketchSolver_ConstraintGroup::splitGroup(std::vector<SketchSolver_Constrain
         break;
       }
     }
-    // Add new group is no one is found
+    // Add new group if no one is found
     if (aGrEntIter == aGroupsEntities.end())
     {
       std::set<Slvs_hEntity> aNewGrEnt;
@@ -706,12 +709,35 @@ bool SketchSolver_ConstraintGroup::updateGroup()
   std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::reverse_iterator
     aConstrIter = myConstraintMap.rbegin();
   bool isAllValid = true;
-  for ( ; isAllValid && aConstrIter != myConstraintMap.rend(); aConstrIter++)
+  bool isCCRemoved = false; // indicates that at least one of coincidence constraints was removed
+  while (isAllValid && aConstrIter != myConstraintMap.rend())
+  {
     if (!aConstrIter->first->data()->isValid())
     {
-      removeConstraint(aConstrIter->first);
+      if (aConstrIter->first->getKind().compare("SketchConstraintCoincidence") == 0)
+        isCCRemoved = true;
+      std::map<boost::shared_ptr<SketchPlugin_Constraint>, Slvs_hConstraint>::reverse_iterator
+        aCopyIter = aConstrIter++;
+      removeConstraint(aCopyIter->first);
       isAllValid = false;
     }
+    else aConstrIter++;
+  }
+
+  // Probably, need to update coincidence constraints
+  if (isCCRemoved && !myExtraCoincidence.empty())
+  {
+    // Make a copy, because the new list of unused constrtaints will be generated
+    std::set< boost::shared_ptr<SketchPlugin_Constraint> > anExtraCopy = myExtraCoincidence;
+    myExtraCoincidence.clear();
+
+    std::set< boost::shared_ptr<SketchPlugin_Constraint> >::iterator
+      aCIter = anExtraCopy.begin();
+    for ( ; aCIter != anExtraCopy.end(); aCIter++)
+      if ((*aCIter)->data()->isValid())
+        changeConstraint(*aCIter);
+  }
+
   return !isAllValid;
 }
 
@@ -962,6 +988,8 @@ void SketchSolver_ConstraintGroup::removeConstraint(boost::shared_ptr<SketchPlug
     for ( ; aCoPtIter != myCoincidentPoints.end(); aCoPtIter++)
       aCoPtIter->erase(*aRemIter);
   }
+  if (myCoincidentPoints.size() == 1 && myCoincidentPoints.front().empty())
+    myCoincidentPoints.clear();
 }
 
 
index c24268f30d8353e99910df5a357f5daf08763810..fe629046b16ef4ed3b8f9bcd7dce62cfe2b74ae8 100644 (file)
@@ -175,10 +175,6 @@ private:
   std::vector<Slvs_hParam>     myTempPointWhereDragged; ///< Parameters of one of the points which is moved by user
   Slvs_hEntity                 myTempPointWDrgdID;      ///< Identifier of such point
   std::list<Slvs_hConstraint>  myTempConstraints;       ///< The list of identifiers of temporary constraints (SLVS_C_WHERE_DRAGGED) applied for all other points moved by user
-                                                        //   NOTE: First ID in the list corresponds to myTempPointWhereDragged parameters and does not added to myConstraints list
-
-  std::vector< std::set<Slvs_hEntity> >
-                               myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints)
 
   // SketchPlugin entities
   boost::shared_ptr<SketchPlugin_Feature>
@@ -187,6 +183,13 @@ private:
                                myConstraintMap; ///< The map between SketchPlugin and SolveSpace constraints
   std::map<boost::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>
                                myEntityMap;     ///< The map between parameters of constraints and their equivalent SolveSpace entities
+
+  // Conincident items
+  std::vector< std::set<Slvs_hEntity> >
+                               myCoincidentPoints; ///< Stores the lists of identifiers of coincident points (to avoid unnecessary coincidence constraints)
+  std::set< boost::shared_ptr<SketchPlugin_Constraint> >
+                               myExtraCoincidence; ///< Additional coincidence constraints which are not necessary (coincidence between points already done
+                                                   ///< by other constraints) but created by GUI tools. Useful when some coincidence constraints were removed
 };
 
 #endif
index be307be93dda2682dca7c54e645e03b9ea3f4285..40c76d1a772b5a863d13af4c711a1fe65ee8f6a3 100644 (file)
@@ -97,7 +97,7 @@ void SketchSolver_Solver::setConstraints(const std::vector<Slvs_Constraint>& the
     if (myEquationsSystem.failed)
       delete [] myEquationsSystem.failed;
     myEquationsSystem.failed = new Slvs_hConstraint[theConstraints.size()];
-    myEquationsSystem.faileds = 0;
+    myEquationsSystem.faileds = theConstraints.size();
   }
 
   // Copy data