]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Minor updates in SketchSolver plugin
authorazv <azv@opencascade.com>
Mon, 21 Dec 2015 05:41:57 +0000 (08:41 +0300)
committerazv <azv@opencascade.com>
Mon, 21 Dec 2015 05:42:15 +0000 (08:42 +0300)
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_ConstraintMirror.cpp
src/SketchSolver/SketchSolver_ConstraintTangent.cpp
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Storage.cpp
src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp

index 1de16cfe79a18b71be201aab9d80cd577067c996..7dbde50c73130c4ffba06118fc35165b95b2fe7c 100644 (file)
@@ -122,7 +122,10 @@ void SketchSolver_Constraint::update()
   if (aValueAttr) {
     std::list<ConstraintWrapperPtr>::iterator aWIt = aWrapper.begin();
     for (; aWIt != aWrapper.end(); ++aWIt)
-      (*aWIt)->setValue(aValueAttr->value());
+      if (fabs((*aWIt)->value() - aValueAttr->value()) > tolerance) {
+        (*aWIt)->setValue(aValueAttr->value());
+        myStorage->setNeedToResolve(true);
+      }
   }
   myStorage->addConstraint(myBaseConstraint, aWrapper);
 
index c496b719d77b5862283b61a0838d5e8f4e13ed03..f271d1817f665dbe9cb4f2b23a0becf61266b3dc 100644 (file)
@@ -18,7 +18,7 @@ void SketchSolver_ConstraintMirror::getAttributes(
   }
 
   myType = TYPE(myBaseConstraint);
-  myStorage->update(aMirLineAttr, myGroupID);
+  myStorage->update(aMirLineAttr/*, myGroupID*/);
   theMirrorLine = myStorage->entity(aMirLineAttr);
 
   // Create SolveSpace entity for all features
@@ -45,7 +45,7 @@ void SketchSolver_ConstraintMirror::getAttributes(
       if (!aFeature)
         continue;
 
-      myStorage->update(aFeature, myGroupID);
+      myStorage->update(aFeature/*, myGroupID*/);
       aList->push_back(myStorage->entity(aFeature));
     }
   }
index bf551e43c27dc156663e6cbe472b9b7c0ecabc66..51d87e276de239089abf6586a30f22e6e3e3cee7 100644 (file)
@@ -21,8 +21,12 @@ static bool hasSingleCoincidence(EntityWrapperPtr theEntity1, EntityWrapperPtr t
   int aNbCoinc = 0;
   std::list<EntityWrapperPtr>::const_iterator anIt1, anIt2;
   for (anIt1 = aStartIt1; anIt1 != aPoints1.end(); ++anIt1) {
+    if ((*anIt1)->type() != ENTITY_POINT)
+      continue;
     std::shared_ptr<GeomAPI_Pnt2d> aPt1 = aBuilder->point(*anIt1);
     for (anIt2 = aStartIt2; anIt2 != aPoints2.end(); ++anIt2) {
+      if ((*anIt2)->type() != ENTITY_POINT)
+        continue;
       std::shared_ptr<GeomAPI_Pnt2d> aPt2 = aBuilder->point(*anIt2);
       if (aPt1->distance(aPt2) < tolerance)
         ++aNbCoinc;
index 0959722eeb56e68471b3524971f9b638d3517752..bf64e49db39700fb46251603998f795586826270 100644 (file)
@@ -196,6 +196,17 @@ void SketchSolver_Group::updateConstraints()
   myChangedConstraints.clear();
 }
 
+static void updateMultiConstraints(ConstraintConstraintMap& theConstraints, FeaturePtr theFeature)
+{
+  ConstraintConstraintMap::iterator aCIt = theConstraints.begin();
+  for (; aCIt != theConstraints.end(); ++aCIt) {
+    if ((aCIt->second->getType() == CONSTRAINT_MULTI_ROTATION ||
+         aCIt->second->getType() == CONSTRAINT_MULTI_TRANSLATION)
+        && aCIt->second->isUsed(theFeature))
+      std::dynamic_pointer_cast<SketchSolver_ConstraintMulti>(aCIt->second)->update(true);
+  }
+}
+
 bool SketchSolver_Group::updateFeature(FeaturePtr theFeature)
 {
   if (!checkFeatureValidity(theFeature))
@@ -203,7 +214,10 @@ bool SketchSolver_Group::updateFeature(FeaturePtr theFeature)
 
   myStorage->blockEvents(true);
   myStorage->refresh(true);
-  return myStorage->update(theFeature);
+  bool isUpdated = myStorage->update(theFeature);
+
+  updateMultiConstraints(myConstraints, theFeature);
+  return isUpdated;
 }
 
 void SketchSolver_Group::moveFeature(FeaturePtr theFeature)
@@ -214,22 +228,16 @@ void SketchSolver_Group::moveFeature(FeaturePtr theFeature)
   myStorage->blockEvents(true);
   myStorage->refresh(true);
 
-  // Secondly, search attributes of the feature in the list of the Multi constraints and update them
-  ConstraintConstraintMap::iterator aCIt = myConstraints.begin();
-  for (; aCIt != myConstraints.end(); ++aCIt) {
-    if ((aCIt->second->getType() == CONSTRAINT_MULTI_ROTATION ||
-         aCIt->second->getType() == CONSTRAINT_MULTI_TRANSLATION)
-        && aCIt->second->isUsed(theFeature))
-      std::dynamic_pointer_cast<SketchSolver_ConstraintMulti>(aCIt->second)->update(true);
-  }
-
-  // Then, create temporary rigid constraint
+  // Then, create temporary Fixed constraint
   SolverConstraintPtr aConstraint = aBuilder->createMovementConstraint(theFeature);
   if (!aConstraint)
     return;
   aConstraint->process(myStorage, getId(), getWorkplaneId());
   if (aConstraint->error().empty())
     setTemporary(aConstraint);
+
+  // Secondly, search attributes of the feature in the list of the Multi constraints and update them
+  updateMultiConstraints(myConstraints, theFeature);
 }
 
 // ============================================================================
index feae88f9c7bca42846caed0112e80f3b59492a93..2e283a90f6cde0897740b187b0570429134d9237 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
 
@@ -209,8 +210,10 @@ bool SketchSolver_Storage::removeConstraint(ConstraintPtr theConstraint)
       ++anIt;
     }
   }
-  if (!isFullyRemoved)
-    myConstraintMap[theConstraint] = aConstrList;
+  if (!isFullyRemoved) {
+    // revert removed constraint
+    addConstraint(theConstraint, aConstrList);
+  }
   return isFullyRemoved;
 }
 
@@ -235,6 +238,9 @@ static bool isUsed(EntityWrapperPtr theFeature, AttributePtr theSubEntity)
 
 bool SketchSolver_Storage::isUsed(FeaturePtr theFeature) const
 {
+  if (myFeatureMap.find(theFeature) != myFeatureMap.end())
+    return true;
+  // check constraints
   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
       aCIt = myConstraintMap.begin();
   std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
@@ -262,6 +268,9 @@ bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const
       anAttribute = aRefAttr->attr();
   }
 
+  if (myAttributeMap.find(theAttribute) != myAttributeMap.end())
+    return true;
+  // check in constraints
   std::map<ConstraintPtr, std::list<ConstraintWrapperPtr> >::const_iterator
       aCIt = myConstraintMap.begin();
   std::list<ConstraintWrapperPtr>::const_iterator aCWIt;
@@ -269,6 +278,11 @@ bool SketchSolver_Storage::isUsed(AttributePtr theAttribute) const
     for (aCWIt = aCIt->second.begin(); aCWIt != aCIt->second.end(); ++aCWIt)
       if (::isUsed(*aCWIt, anAttribute))
         return true;
+  // check in features
+  std::map<FeaturePtr, EntityWrapperPtr>::const_iterator aFIt = myFeatureMap.begin();
+  for (; aFIt != myFeatureMap.end(); ++aFIt)
+    if (::isUsed(aFIt->second, anAttribute))
+      return true;
   return false;
 }
 
@@ -290,6 +304,7 @@ bool SketchSolver_Storage::removeEntity(FeaturePtr theFeature)
     return true;
   // feature is not removed, revert operation
   myFeatureMap[theFeature] = anEntity;
+  update(anEntity);
   return false;
 }
 
@@ -315,6 +330,7 @@ bool SketchSolver_Storage::removeEntity(AttributePtr theAttribute)
     return true;
   // attribute is not removed, revert operation
   myAttributeMap[theAttribute] = anEntity;
+  update(anEntity);
   return false;
 }
 
@@ -380,6 +396,19 @@ bool SketchSolver_Storage::isInteract(const AttributePtr& theAttribute) const
   if (!theAttribute)
     return false;
 
+  AttributeRefListPtr aRefList = 
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(theAttribute);
+  if (aRefList) {
+    std::list<ObjectPtr> anObjects = aRefList->list();
+    std::list<ObjectPtr>::iterator anObjIt = anObjects.begin();
+    for (; anObjIt != anObjects.end(); ++anObjIt) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(*anObjIt);
+      if (isInteract(aFeature))
+        return true;
+    }
+    return false;
+  }
+
   AttributeRefAttrPtr aRefAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
   if (!aRefAttr)
index 2c47352adbda2c366a0c4e4702c0573d42ba1a62..5e1b85015d27534de5c319239072282ecb0fbfba 100644 (file)
@@ -231,8 +231,7 @@ std::list<ConstraintWrapperPtr> SolveSpaceSolver_Builder::createMirror(
     std::list<EntityWrapperPtr>::const_iterator anIt1 = theEntity1->subEntities().begin();
     std::list<EntityWrapperPtr>::const_iterator anIt2 = theEntity2->subEntities().begin();
     if ((*anIt2)->group() == theGroupID) // mirrored point is not fixed
-      makeMirrorPoints(theEntity1->subEntities().front(),
-          theEntity2->subEntities().front(), theMirrorLine);
+      makeMirrorPoints(*anIt1, *anIt2, theMirrorLine);
 
     // Workaround to avoid problems in SolveSpace.
     // The symmetry of two arcs will be done using symmetry of three points on these arcs: