]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1177: improve removing coincidence of the fixed points
authorazv <azv@opencascade.com>
Fri, 25 Dec 2015 05:28:30 +0000 (08:28 +0300)
committerazv <azv@opencascade.com>
Fri, 25 Dec 2015 05:28:30 +0000 (08:28 +0300)
src/SketchSolver/SketchSolver_ConstraintFixed.cpp
src/SketchSolver/SketchSolver_Storage.cpp
src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp

index 5ce8df01451b11df3fb24310dccea6d5b1a68dce..012a45423c05873fa2e3a10425f3a4cf0b80a82a 100644 (file)
@@ -55,6 +55,9 @@ void SketchSolver_ConstraintFixed::fixFeature(EntityWrapperPtr theFeature)
     myStorage->update(theFeature->baseAttribute(), GID_OUTOFGROUP);
   else if (theFeature->baseFeature())
     myStorage->update(theFeature->baseFeature(), GID_OUTOFGROUP);
+
+  if (myBaseConstraint)
+    myStorage->addConstraint(myBaseConstraint, std::list<ConstraintWrapperPtr>());
 }
 
 void SketchSolver_ConstraintFixed::getAttributes(
index b8773d92d4f007f1598995fd4fadda70ec7c1ad1..e54aec7e42ca3233a6de81668ae6a370872d2de7 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModelAPI_AttributeRefList.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
+#include <SketchPlugin_ConstraintRigid.h>
 
 
 /// \brief Verify two vectors of constraints are equal.
@@ -295,6 +296,22 @@ static bool isUsed(EntityWrapperPtr theFeature, AttributePtr theSubEntity)
   return false;
 }
 
+static bool isUsed(ConstraintPtr theConstraint, AttributePtr theAttribute)
+{
+  if (!theConstraint || !theAttribute)
+    return false;
+  std::list<AttributePtr> anAttrList = theConstraint->data()->attributes(std::string());
+  std::list<AttributePtr>::const_iterator anIt = anAttrList.begin();
+  for (; anIt != anAttrList.end(); ++anIt) {
+    if (*anIt == theAttribute)
+      return true;
+    AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
+    if (aRefAttr && !aRefAttr->isObject() && aRefAttr->attr() == theAttribute)
+      return true;
+  }
+  return false;
+}
+
 bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const
 {
   if (myFeatureMap.find(theFeature) != myFeatureMap.end())
@@ -333,10 +350,15 @@ bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const
   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
       aCIt = myConstraintMap.begin();
   std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
-  for (; aCIt != myConstraintMap.end(); ++aCIt)
+  for (; aCIt != myConstraintMap.end(); ++aCIt) {
     for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
       if (::isUsed(*aCWIt, anAttribute))
         return true;
+    // Additional check for the Fixed constraints, which have no wrapper associated.
+    if (aCIt->first->getKind() == SketchPlugin_ConstraintRigid::ID() &&
+        ::isUsed(aCIt->first, anAttribute))
+      return true;
+  }
   // check in features
   std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
   for (; aFIt != myFeatureMap.end(); ++aFIt)
index e2cd45ad5ab6af9bcb55fc9e395df8f0d6ac2f6a..681c96c57428634a2ee2d23270bdbf73e494bc32 100644 (file)
@@ -1119,12 +1119,12 @@ bool SolveSpaceSolver_Storage::remove(ConstraintWrapperPtr theConstraint)
     return true;
 
   bool isFullyRemoved = removeConstraint((Slvs_hConstraint)aConstraint->id());
+  isFullyRemoved = SketchSolver_Storage::remove(theConstraint) && isFullyRemoved;
 
   // remove point-point coincidence
   if (aConstraint->type() == CONSTRAINT_PT_PT_COINCIDENT)
-    isFullyRemoved = removeCoincidence(theConstraint);
-
-  return SketchSolver_Storage::remove(theConstraint) && isFullyRemoved;
+    isFullyRemoved = removeCoincidence(theConstraint) && isFullyRemoved;
+  return isFullyRemoved;
 }
 
 bool SolveSpaceSolver_Storage::remove(EntityWrapperPtr theEntity)
@@ -1132,9 +1132,32 @@ bool SolveSpaceSolver_Storage::remove(EntityWrapperPtr theEntity)
   if (!theEntity)
     return false;
 
+  // Additional check for entity to be used in point-point coincidence
+  bool isCoincide = false;
+  if (theEntity->type() == ENTITY_POINT) {
+    CoincidentPointsMap::const_iterator anIt = myCoincidentPoints.begin();
+    std::set<EntityWrapperPtr>::const_iterator aCIt;
+    for (; anIt != myCoincidentPoints.end(); ++anIt) {
+      if (anIt->first == theEntity)
+        break;
+      for (aCIt = anIt->second.begin(); aCIt != anIt->second.end(); ++aCIt)
+        if (*aCIt == theEntity)
+          break;
+      if (aCIt != anIt->second.end())
+        break;
+    }
+    if (anIt != myCoincidentPoints.end()) {
+      if (anIt->first != theEntity && isUsed(anIt->first->baseAttribute()))
+        isCoincide = true;
+      for (aCIt = anIt->second.begin(); !isCoincide && aCIt != anIt->second.end(); ++aCIt)
+        if (*aCIt != theEntity && isUsed((*aCIt)->baseAttribute()))
+          isCoincide = true;
+    }
+  }
+
   std::shared_ptr<SolveSpaceSolver_EntityWrapper> anEntity = 
         std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theEntity);
-  bool isFullyRemoved = removeEntity((Slvs_hEntity)anEntity->id());
+  bool isFullyRemoved = isCoincide ? true : removeEntity((Slvs_hEntity)anEntity->id());
   return SketchSolver_Storage::remove(theEntity) && isFullyRemoved;
 }