Salome HOME
Remove extra files
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMulti.cpp
index 6f05e9a53ad43150f4543638dc83e808fbf35264..bd0a82ad3206962483ae6a6bffa4b5d5fe5b5fa8 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>(
@@ -113,27 +121,34 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
     return;
   }
 
-  FeaturePtr aFeature;
+  FeaturePtr anOriginal, aFeature;
   std::list<ObjectPtr> anObjectList = aRefList->list();
   std::list<ObjectPtr>::iterator anObjIt = anObjectList.begin();
   while (anObjIt != anObjectList.end()) {
-    aFeature = ModelAPI_Feature::feature(*anObjIt++);
-    if (!aFeature)
+    anOriginal = ModelAPI_Feature::feature(*anObjIt++);
+    if (!anOriginal)
       continue;
 
     // Fill lists of coordinates of points composing a feature
     std::list<double> aX, aY;
     std::list<double>::iterator aXIt, aYIt;
     double aXCoord, aYCoord;
-    EntityWrapperPtr anEntity = myStorage->entity(aFeature);
+    EntityWrapperPtr anEntity = myStorage->entity(anOriginal);
     std::list<EntityWrapperPtr> aSubs = anEntity->subEntities();
     std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
     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);
@@ -157,9 +172,12 @@ 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 if (aFeature->getKind() == SketchPlugin_Circle::ID())
+      } else if (aFeature->getKind() == SketchPlugin_Circle::ID()) {
         aPoints.push_back(aFeature->attribute(SketchPlugin_Circle::CENTER_ID()));
-      else if (aFeature->getKind() == SketchPlugin_Point::ID() ||
+        // update circle's radius
+        aFeature->real(SketchPlugin_Circle::RADIUS_ID())->setValue(
+            anOriginal->real(SketchPlugin_Circle::RADIUS_ID())->value());
+      } else if (aFeature->getKind() == SketchPlugin_Point::ID() ||
                aFeature->getKind() == SketchPlugin_IntersectionPoint::ID())
         aPoints.push_back(aFeature->attribute(SketchPlugin_Point::COORD_ID()));
 
@@ -176,6 +194,13 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
       // update feature in the storage if it is used by another constraints
       if (anEntity)
         myStorage->update(aFeature);
+      else { // update attributes, if they exist in the storage
+        for (aPtIt = aPoints.begin(); aPtIt != aPoints.end(); ++aPtIt) {
+          EntityWrapperPtr aPntEnt = myStorage->entity(*aPtIt);
+          if (aPntEnt)
+            myStorage->update(*aPtIt);
+        }
+      }
 
       if (!anEntity || !myStorage->isEventsBlocked())
         aFeature->data()->blockSendAttributeUpdated(false);
@@ -187,6 +212,24 @@ void SketchSolver_ConstraintMulti::adjustConstraint()
 
 bool SketchSolver_ConstraintMulti::isUsed(FeaturePtr theFeature) const
 {
-  return myFeatures.find(theFeature) != myFeatures.end() ||
-         SketchSolver_Constraint::isUsed(theFeature);
+  return theFeature && (myFeatures.find(theFeature) != myFeatures.end() ||
+         SketchSolver_Constraint::isUsed(theFeature));
+}
+
+bool SketchSolver_ConstraintMulti::isUsed(AttributePtr theAttribute) const
+{
+  AttributePtr anAttribute = theAttribute;
+  AttributeRefAttrPtr aRefAttr =
+      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
+  if (aRefAttr) {
+    if (aRefAttr->isObject())
+      return isUsed(ModelAPI_Feature::feature(aRefAttr->object()));
+    else
+      anAttribute = aRefAttr->attr();
+  }
+  if (!anAttribute)
+    return false;
+
+  FeaturePtr anOwner = ModelAPI_Feature::feature(anAttribute->owner());
+  return myFeatures.find(anOwner) != myFeatures.end();
 }