Salome HOME
Hang up on constraining already fixed object
[modules/shaper.git] / src / SketchSolver / SketchSolver_Constraint.cpp
index efd447ab793487449238d027536ebb96ab5a681f..6a7ecdb09d03347693177ef95fd4bc733c8cc691 100644 (file)
@@ -118,6 +118,17 @@ void SketchSolver_Constraint::process()
 
 bool SketchSolver_Constraint::checkAttributesChanged(ConstraintPtr theConstraint)
 {
+  std::set<Slvs_hEntity> aCurAttrs; // list of currently used attributes
+  std::vector<Slvs_hConstraint>::const_iterator aConstrIter = mySlvsConstraints.begin();
+  for (; aConstrIter != mySlvsConstraints.end(); aConstrIter++) {
+    Slvs_Constraint aConstr = myStorage->getConstraint(*aConstrIter);
+    if (aConstr.ptA != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.ptA);
+    if (aConstr.ptB != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.ptB);
+    if (aConstr.entityA != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityA);
+    if (aConstr.entityB != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityB);
+    if (aConstr.entityC != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityC);
+    if (aConstr.entityD != SLVS_E_UNKNOWN) aCurAttrs.insert(aConstr.entityD);
+  }
   // Check the attrbutes of constraint are changed
   ConstraintPtr aConstraint = theConstraint ? theConstraint : myBaseConstraint;
   std::list<AttributePtr> anAttrList = aConstraint->data()->attributes(std::string());
@@ -128,11 +139,14 @@ bool SketchSolver_Constraint::checkAttributesChanged(ConstraintPtr theConstraint
     if (aRefAttr) {
       if (aRefAttr->isObject()) {
         FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object());
-        if (aFeature && myFeatureMap.find(aFeature) == myFeatureMap.end())
+        std::map<FeaturePtr, Slvs_hEntity>::iterator aFIt = myFeatureMap.find(aFeature);
+        if (aFeature && (aFIt == myFeatureMap.end() || aCurAttrs.find(aFIt->second) == aCurAttrs.end()))
+          return true;
+      } else if (aRefAttr->attr()) {
+        std::map<AttributePtr, Slvs_hEntity>::iterator anAIt = myAttributeMap.find(aRefAttr->attr());
+        if (anAIt == myAttributeMap.end() || aCurAttrs.find(anAIt->second) == aCurAttrs.end())
           return true;
-      } else if (aRefAttr->attr() &&
-                 myAttributeMap.find(aRefAttr->attr()) == myAttributeMap.end())
-        return true;
+      }
     }
     AttributeRefListPtr aRefList =
         std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anAttrIter);
@@ -263,6 +277,11 @@ void SketchSolver_Constraint::cleanRemovedEntities()
     std::map<AttributePtr, Slvs_hParam>::iterator aTmpIter = aValIt++;
     myValueMap.erase(aTmpIter);
   }
+  for (size_t i = 0; i < mySlvsConstraints.size(); i++)
+    if (aRemovedConstraints.find(mySlvsConstraints[i]) != aRemovedConstraints.end()) {
+      mySlvsConstraints.erase(mySlvsConstraints.begin() + i);
+      i--;
+    }
 }
 
 void SketchSolver_Constraint::getAttributes(
@@ -336,8 +355,10 @@ Slvs_hEntity SketchSolver_Constraint::changeEntity(AttributeRefAttrPtr theAttrib
 Slvs_hEntity SketchSolver_Constraint::changeEntity(AttributePtr theEntity, int& theType)
 {
   Slvs_hEntity aResult = SLVS_E_UNKNOWN;
-  if (!theEntity || !isInitialized(theEntity))
+  if (!theEntity || !isInitialized(theEntity)) {
+    myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
     return SLVS_E_UNKNOWN;
+  }
 
   // If the entity is already in the group, try to find it
   std::map<std::shared_ptr<ModelAPI_Attribute>, Slvs_hEntity>::const_iterator anEntIter =