Salome HOME
Using test for testing number of sub-shapes.
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMulti.cpp
index 952fecafde345747888747c954693afe9a395e08..a86ab8b5fbd51731f26d30fdade40e31a67a402d 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 #include <SketchSolver_ConstraintMulti.h>
 #include <SketchSolver_Error.h>
 #include <SketchSolver_Manager.h>
@@ -35,7 +37,8 @@ void SketchSolver_ConstraintMulti::getEntities(std::list<EntityWrapperPtr>& theE
   FeaturePtr aFeature;
   std::list<ObjectPtr> anObjectList = aRefList->list();
   std::list<ObjectPtr>::iterator anObjIt = anObjectList.begin();
-  if ((myNumberOfCopies + 1) * myNumberOfObjects != aRefList->size()) // execute for the feature is not called yet
+  // execute for the feature is not called yet
+  if ((myNumberOfCopies + 1) * myNumberOfObjects != aRefList->size())
     myNumberOfCopies = aRefList->size() / myNumberOfObjects - 1;
 
   while (anObjIt != anObjectList.end()) {
@@ -43,7 +46,9 @@ void SketchSolver_ConstraintMulti::getEntities(std::list<EntityWrapperPtr>& theE
     if (!aFeature)
       continue;
 
-    myStorage->update(aFeature);
+    // the entity is not created, so it is a copy in "multi" constraint, force its creation
+    if (!myStorage->update(aFeature))
+      myStorage->update(aFeature, myGroupID, true);
     theEntities.push_back(myStorage->entity(aFeature));
     myFeatures.insert(aFeature);
     for (int i = 0; i < myNumberOfCopies && anObjIt != anObjectList.end(); ++i, ++anObjIt) {
@@ -72,7 +77,10 @@ void SketchSolver_ConstraintMulti::update(bool isForce)
   AttributeRefListPtr anInitialRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
   AttributeIntegerPtr aNbObjects = myBaseConstraint->integer(nameNbObjects());
-  bool isUpdated= anInitialRefList->size() != myNumberOfObjects || aNbObjects->value()-1 != myNumberOfCopies;
+  if (!anInitialRefList || !aNbObjects)
+    return; // the "Multi" constraint is in queue to remove
+  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>(
@@ -131,9 +139,16 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
     for (; aSIt != aSubs.end(); ++aSIt) {
       if ((*aSIt)->type() != ENTITY_POINT)
         continue;
-      std::list<ParameterWrapperPtr> aParameters = (*aSIt)->parameters();
-      aXCoord = aParameters.front()->value();
-      aYCoord = aParameters.back()->value();
+      AttributePoint2DPtr aPoint =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>((*aSIt)->baseAttribute());
+      if (aPoint) {
+        aXCoord = aPoint->x();
+        aYCoord = aPoint->y();
+      } else {
+        std::list<ParameterWrapperPtr> aParameters = (*aSIt)->parameters();
+        aXCoord = aParameters.front()->value();
+        aYCoord = aParameters.back()->value();
+      }
       getRelative(aXCoord, aYCoord, aXCoord, aYCoord);
       aX.push_back(aXCoord);
       aY.push_back(aYCoord);
@@ -146,8 +161,9 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
         continue;
       anEntity = myStorage->entity(aFeature);
 
+      bool aWasBlocked = false;
       if (!anEntity || !myStorage->isEventsBlocked())
-        aFeature->data()->blockSendAttributeUpdated(true);
+        aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true);
 
       std::list<AttributePtr> aPoints;
       if (aFeature->getKind() == SketchPlugin_Arc::ID()) {
@@ -188,7 +204,7 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
       }
 
       if (!anEntity || !myStorage->isEventsBlocked())
-        aFeature->data()->blockSendAttributeUpdated(false);
+        aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
     }
   }