Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rotation.cpp
index 178b3d0a059571b9eb3dbcc0f1334200ad41e052..a5b332adcff416c261a5b917022967a5ee4efe07 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -43,14 +43,13 @@ SketchAPI_Rotation::SketchAPI_Rotation(
 : ModelHighAPI_Interface(theFeature)
 {
   if (initialize()) {
-    fillAttribute(theObjects, rotationList());
     fillAttribute(theCenter, center());
     fillAttribute(theFullValue ? "FullAngle" : "SingleAngle", valueType());
     fillAttribute(theAngle, angle());
     fillAttribute(theReversed, reversed());
     fillAttribute(theNumberOfObjects, numberOfObjects());
 
-    execute(true);
+    setRotationList(theObjects);
   }
 }
 
@@ -59,6 +58,13 @@ SketchAPI_Rotation::~SketchAPI_Rotation()
 
 }
 
+void SketchAPI_Rotation::setRotationList(
+    const std::list<std::shared_ptr<ModelAPI_Object> >& theObjects)
+{
+  fillAttribute(theObjects, rotationList());
+  execute(true);
+}
+
 std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rotation::rotated() const
 {
   std::list<ObjectPtr> aList = rotatedObjects()->list();
@@ -74,6 +80,26 @@ std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rotation::rotated(
   return SketchAPI_SketchEntity::wrap(anIntermediate);
 }
 
+std::list<std::shared_ptr<SketchAPI_SketchEntity> > SketchAPI_Rotation::rotatedList() const
+{
+  std::list<ObjectPtr> aList = rotationList()->list();
+  std::set<ObjectPtr> anOriginalObjects;
+  anOriginalObjects.insert(aList.begin(), aList.end());
+  // remove all initial features
+  std::list<FeaturePtr> anIntermediate;
+  aList = rotatedObjects()->list();
+  std::list<ObjectPtr>::const_iterator anIt = aList.begin();
+  for (; anIt != aList.end(); ++anIt) {
+    if (anOriginalObjects.find(*anIt) != anOriginalObjects.end())
+      continue; // skip initial object
+    FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+    AttributeBooleanPtr isCopy = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+    if (isCopy.get() && isCopy->value())
+      anIntermediate.push_back(aFeature);
+  }
+  return SketchAPI_SketchEntity::wrap(anIntermediate);
+}
+
 //--------------------------------------------------------------------------------------
 
 void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
@@ -89,49 +115,77 @@ void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
   bool isReversed = reversed()->value();
 
   // Check all attributes are already dumped. If not, store the constraint as postponed.
-  if (!theDumper.isDumped(aCenter) || !theDumper.isDumped(aRotObjects)) {
+  size_t aFirstNotDumped = theDumper.indexOfFirstNotDumped(aRotObjects);
+  if (!theDumper.isDumped(aCenter) || aFirstNotDumped == 0) {
     theDumper.postpone(aBase);
     return;
   }
 
-  theDumper << aBase << " = " << aSketchName << ".addRotation("
-            << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
-  if (isFullValue || isReversed)
-  {
-    theDumper << ", " << isFullValue;
-    if (isReversed)
-      theDumper << ", " << isReversed;
+  // the number of dumped aRotObjects is not changed, no need to dump anything
+  static std::map<FeaturePtr, size_t> aNbDumpedArguments;
+  std::map<FeaturePtr, size_t>::iterator aFound = aNbDumpedArguments.find(aBase);
+  if (aFound != aNbDumpedArguments.end() && aFound->second == aFirstNotDumped) {
+    theDumper.postpone(aBase);
+    return;
+  }
+  else
+    aNbDumpedArguments[aBase] = aFirstNotDumped;
+
+  if (theDumper.isDumped(aBase)) {
+    // the feature is already dumped, but it was postponed, because of some arguments
+    // were not dumped yet, thus, it is necessary to update the list of rotated objects
+    theDumper << "\n### Update " << aBase->getKind() << std::endl;
+    theDumper << aBase << ".setRotationList(" << aRotObjects << ")" << std::endl;
+  }
+  else {
+    // the feature is not dumped yet, make the full dump
+    theDumper << aBase << " = " << aSketchName << ".addRotation("
+              << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
+    if (isFullValue || isReversed)
+    {
+      theDumper << ", " << isFullValue;
+      if (isReversed)
+        theDumper << ", " << isReversed;
+    }
+    theDumper << ")" << std::endl;
   }
-  theDumper << ")" << std::endl;
 
   // Dump variables for a list of rotated features
   theDumper << "[";
-  std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = rotated();
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = rotatedList();
   std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
-  for (; anIt != aList.end(); ++anIt) {
-    if (anIt != aList.begin())
-      theDumper << ", ";
-    theDumper << (*anIt)->feature();
-  }
-  theDumper << "] = " << theDumper.name(aBase) << ".rotated()" << std::endl;
-
-  // Set necessary "auxiliary" flag for rotated features
-  // (flag is set if it differs to base entity)
-  std::list<ObjectPtr> aRotList = aRotObjects->list();
-  std::list<ObjectPtr>::const_iterator aRIt = aRotList.begin();
-  anIt = aList.begin();
-  for (; aRIt != aRotList.end(); ++aRIt) {
-    FeaturePtr aFeature = ModelAPI_Feature::feature(*aRIt);
-    if (!aFeature)
-      continue;
-    bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
-
-    for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) {
-      aFeature = (*anIt)->feature();
-      bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
-      if (aFeatAux != aBaseAux)
-        theDumper << theDumper.name((*anIt)->feature(), false)
-                  << ".setAuxiliary(" << aFeatAux << ")" <<std::endl;
+  for (size_t anIndex = 0; anIndex < aFirstNotDumped; ++anIndex)
+    for (int i = 1; i < aNbCopies->value() && anIt != aList.end(); ++i, ++anIt) {
+      if (anIt != aList.begin())
+        theDumper << ", ";
+      theDumper << (*anIt)->feature();
     }
+  theDumper << "] = " << theDumper.name(aBase) << ".rotatedList()" << std::endl;
+
+  if (theDumper.isDumped(aRotObjects)) {
+    aNbDumpedArguments.erase(aBase);
+    // Set necessary "auxiliary" flag for rotated features
+    // (flag is set if it differs to base entity)
+    std::list<ObjectPtr> aRotList = aRotObjects->list();
+    std::list<ObjectPtr>::const_iterator aRIt = aRotList.begin();
+    anIt = aList.begin();
+    for (; aRIt != aRotList.end(); ++aRIt) {
+      FeaturePtr aFeature = ModelAPI_Feature::feature(*aRIt);
+      if (!aFeature)
+        continue;
+      bool aBaseAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
+
+      for (int i = 1; i < aNbCopies->value(); ++i, ++anIt) {
+        aFeature = (*anIt)->feature();
+        bool aFeatAux = aFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
+        if (aFeatAux != aBaseAux)
+          theDumper << theDumper.name((*anIt)->feature(), false)
+                    << ".setAuxiliary(" << aFeatAux << ")" << std::endl;
+      }
+    }
+  }
+  else {
+    // If all refereced objects are not dumped yet, mark the feature as postponed.
+    theDumper.postpone(aBase);
   }
 }