Salome HOME
added test for bos#34658
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_MultiRotation.cpp
index 8e59da5f22c912ffd96c0f85c3c4e8cf402cf0fa..cb00985a23620e4142c30a54c52517615a5d2a8c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2017-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2017-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -23,6 +23,7 @@
 
 #include <FeaturesAPI_MultiRotation.h>
 
+#include <ModelHighAPI_Double.h>
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 
@@ -132,19 +133,10 @@ void FeaturesAPI_MultiRotation::dump(ModelHighAPI_Dumper& theDumper) const
     aBase->integer(FeaturesPlugin_MultiRotation::NB_COPIES_ANGULAR_ID());
   theDumper << ", " << anAttrNumberAngular;
 
-  theDumper << ")" << std::endl;
-}
+  if (!aBase->data()->version().empty())
+    theDumper << ", keepSubResults = True";
 
-//==================================================================================================
-MultiRotationPtr addMultiRotation(const std::shared_ptr<ModelAPI_Document>& thePart,
-                                  const std::list<ModelHighAPI_Selection>& theMainObjects,
-                                  const ModelHighAPI_Selection& theAxis,
-                                  const ModelHighAPI_Integer& theNumber)
-{
-  std::shared_ptr<ModelAPI_Feature> aFeature =
-    thePart->addFeature(FeaturesAPI_MultiRotation::ID());
-  return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
-                                                        theAxis, theNumber));
+  theDumper << ")" << std::endl;
 }
 
 //==================================================================================================
@@ -152,10 +144,30 @@ MultiRotationPtr addMultiRotation(const std::shared_ptr<ModelAPI_Document>& theP
                                   const std::list<ModelHighAPI_Selection>& theMainObjects,
                                   const ModelHighAPI_Selection& theAxis,
                                   const ModelHighAPI_Double& theStep,
-                                  const ModelHighAPI_Integer& theNumber)
+                                  const ModelHighAPI_Integer& theNumber,
+                                  const bool keepSubResults)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     thePart->addFeature(FeaturesAPI_MultiRotation::ID());
-  return MultiRotationPtr(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
-                                                        theAxis, theStep, theNumber));
+  if (!keepSubResults)
+    aFeature->data()->setVersion("");
+
+  MultiRotationPtr aResult;
+  if (theNumber.string().empty()) {
+    // rotate for the whole circle
+    double aStepVal = theStep.value();
+    std::wstring aStepStr = theStep.string();
+    std::wostringstream aStepValAsStr;
+    aStepValAsStr << aStepVal;
+
+    ModelHighAPI_Integer aNumber = aStepStr == aStepValAsStr.str()
+                                 ? ModelHighAPI_Integer((int)aStepVal)
+                                 : ModelHighAPI_Integer(aStepStr);
+    aResult.reset(new FeaturesAPI_MultiRotation(aFeature, theMainObjects, theAxis, aNumber));
+  }
+  else {
+    aResult.reset(new FeaturesAPI_MultiRotation(aFeature, theMainObjects,
+                                                theAxis, theStep, theNumber));
+  }
+  return aResult;
 }