Salome HOME
Pipe validator fix
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMulti.cpp
index d2135179c35538fe52fe63c8f0c779218fafa86e..6f05e9a53ad43150f4543638dc83e808fbf35264 100644 (file)
@@ -7,7 +7,10 @@
 #include <ModelAPI_AttributeRefAttr.h>
 #include <ModelAPI_AttributeRefList.h>
 #include <SketchPlugin_Arc.h>
+#include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
+#include <SketchPlugin_IntersectionPoint.h>
 
 void SketchSolver_ConstraintMulti::getEntities(std::list<EntityWrapperPtr>& theEntities)
 {
@@ -42,24 +45,53 @@ void SketchSolver_ConstraintMulti::getEntities(std::list<EntityWrapperPtr>& theE
 
     myStorage->update(aFeature);
     theEntities.push_back(myStorage->entity(aFeature));
-    for (int i = 0; i < myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt)
-      ; // just skip copied features
+    myFeatures.insert(aFeature);
+    for (int i = 0; i < myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt) {
+      // just add copied features into the list of objects
+      aFeature = ModelAPI_Feature::feature(*anObjIt);
+      if (aFeature)
+        myFeatures.insert(aFeature);
+    }
   }
 }
 
+bool SketchSolver_ConstraintMulti::remove()
+{
+  myFeatures.clear();
+  return SketchSolver_Constraint::remove();
+}
+
 void SketchSolver_ConstraintMulti::update()
 {
   update(false);
 }
 
-
 void SketchSolver_ConstraintMulti::update(bool isForce)
 {
   cleanErrorMsg();
   AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
   AttributeIntegerPtr aNbObjects = myBaseConstraint->integer(nameNbObjects());
-  if (anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies) {
+  bool isUpdated= anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies;
+  if (!isUpdated) {
+    // additional check that the features and their copies are changed
+    AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+        myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
+    if (aRefList && aRefList->size() != 0) {
+      FeaturePtr aFeature;
+      std::list<ObjectPtr> anObjectList = aRefList->list();
+      std::list<ObjectPtr>::iterator anObjIt = anObjectList.begin();
+      for (; anObjIt != anObjectList.end(); ++anObjIt) {
+        aFeature = ModelAPI_Feature::feature(*anObjIt);
+        if (aFeature && myFeatures.find(aFeature) == myFeatures.end()) {
+          isUpdated = true;
+          break;
+        }
+      }
+    } else
+      isUpdated = true;
+  }
+  if (isUpdated) {
     remove();
     process();
     return;
@@ -69,8 +101,7 @@ void SketchSolver_ConstraintMulti::update(bool isForce)
   updateLocal();
   if (isForce)
     myAdjusted = false;
-  // update parent object
-  SketchSolver_Constraint::update();
+  adjustConstraint();
 }
 
 void SketchSolver_ConstraintMulti::adjustConstraint()
@@ -126,8 +157,11 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
       } else if (aFeature->getKind() == SketchPlugin_Line::ID()) {
         aPoints.push_back(aFeature->attribute(SketchPlugin_Line::START_ID()));
         aPoints.push_back(aFeature->attribute(SketchPlugin_Line::END_ID()));
-      } else
-        aPoints = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+      } else if (aFeature->getKind() == SketchPlugin_Circle::ID())
+        aPoints.push_back(aFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
+      else if (aFeature->getKind() == SketchPlugin_Point::ID() ||
+               aFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
+        aPoints.push_back(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
 
       std::list<AttributePtr>::iterator aPtIt = aPoints.begin();
       for (aXIt = aX.begin(), aYIt = aY.begin(); aPtIt != aPoints.end(); ++aXIt, ++aYIt, ++aPtIt) {
@@ -150,3 +184,9 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
 
   myAdjusted = true;
 }
+
+bool SketchSolver_ConstraintMulti::isUsed(FeaturePtr theFeature) const
+{
+  return myFeatures.find(theFeature) != myFeatures.end() ||
+         SketchSolver_Constraint::isUsed(theFeature);
+}