Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchAPI / SketchAPI_Rotation.cpp
index 2dc0e87d9ff4b34fdbff37b586d7febedfe69eb4..a5b332adcff416c261a5b917022967a5ee4efe07 100644 (file)
@@ -1,11 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-// Name   : SketchAPI_Rotation.cpp
-// Purpose:
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// History:
-// 16/06/16 - Sergey POKHODENKO - Creation of the file
 
-//--------------------------------------------------------------------------------------
 #include "SketchAPI_Rotation.h"
 #include <SketchAPI_SketchEntity.h>
 //--------------------------------------------------------------------------------------
@@ -27,17 +38,18 @@ SketchAPI_Rotation::SketchAPI_Rotation(
     const ModelHighAPI_RefAttr & theCenter,
     const ModelHighAPI_Double & theAngle,
     const ModelHighAPI_Integer & theNumberOfObjects,
-    bool theFullValue)
+    bool theFullValue,
+    bool theReversed)
 : 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());
-    fillAttribute(theFullValue ? "FullAngle" : "SingleAngle", valueType());
 
-    execute(true);
+    setRotationList(theObjects);
   }
 }
 
@@ -46,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();
@@ -61,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
@@ -73,41 +112,80 @@ void SketchAPI_Rotation::dump(ModelHighAPI_Dumper& theDumper) const
   AttributeDoublePtr anAngle = angle();
   AttributeIntegerPtr aNbCopies = numberOfObjects();
   bool isFullValue = valueType()->value() != "SingleAngle";
+  bool isReversed = reversed()->value();
+
+  // Check all attributes are already dumped. If not, store the constraint as postponed.
+  size_t aFirstNotDumped = theDumper.indexOfFirstNotDumped(aRotObjects);
+  if (!theDumper.isDumped(aCenter) || aFirstNotDumped == 0) {
+    theDumper.postpone(aBase);
+    return;
+  }
+
+  // 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;
 
-  theDumper << aBase << " = " << aSketchName << ".addRotation("
-            << aRotObjects << ", " << aCenter << ", " << anAngle << ", " << aNbCopies;
-  if (isFullValue)
-    theDumper << ", " << isFullValue;
-  theDumper << ")" << std::endl;
+  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;
+  }
 
   // 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 << theDumper.name((*anIt)->feature(), false);
-  }
-  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);
   }
 }