Salome HOME
updated copyright message
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Scale.cpp
index d402713bc1e5729f84132de2da9a2e11cbeb0e25..27354643b6a59b3c683a15fa62fa01e305a21d03 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-201x CEA/DEN, EDF R&D -->
-
-// File:        FeaturesAPI_Scale.cpp
-// Created:     24 Jan 2017
-// Author:      Clarisse Genrault (CEA)
+// 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
+//
 
 #include "FeaturesAPI_Scale.h"
 
@@ -30,6 +43,22 @@ FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& th
   }
 }
 
+//==================================================================================================
+FeaturesAPI_Scale::FeaturesAPI_Scale(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                     const ModelHighAPI_Selection& theCenterPoint,
+                                     const ModelHighAPI_Double& theScaleFactorX,
+                                     const ModelHighAPI_Double& theScaleFactorY,
+                                     const ModelHighAPI_Double& theScaleFactorZ)
+: ModelHighAPI_Interface(theFeature)
+{
+  if (initialize()) {
+    fillAttribute(theMainObjects, mainObjects());
+    fillAttribute(theCenterPoint, centerPoint());
+    setDimensions(theScaleFactorX, theScaleFactorY, theScaleFactorZ);
+  }
+}
+
 //==================================================================================================
 FeaturesAPI_Scale::~FeaturesAPI_Scale()
 {
@@ -52,10 +81,23 @@ void FeaturesAPI_Scale::setCenterPoint(const ModelHighAPI_Selection& theCenterPo
 //==================================================================================================
 void FeaturesAPI_Scale::setScaleFactor(const ModelHighAPI_Double& theScaleFactor)
 {
+  fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR(), creationMethod());
   fillAttribute(theScaleFactor, scaleFactor());
   execute();
 }
 
+//==================================================================================================
+void FeaturesAPI_Scale::setDimensions(const ModelHighAPI_Double& theScaleFactorX,
+                                      const ModelHighAPI_Double& theScaleFactorY,
+                                      const ModelHighAPI_Double& theScaleFactorZ)
+{
+  fillAttribute(FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS(), creationMethod());
+  fillAttribute(theScaleFactorX, scaleFactorX());
+  fillAttribute(theScaleFactorY, scaleFactorY());
+  fillAttribute(theScaleFactorZ, scaleFactorZ());
+  execute();
+}
+
 //==================================================================================================
 void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
 {
@@ -70,9 +112,26 @@ void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
     aBase->selection(FeaturesPlugin_Scale::CENTER_POINT_ID());
   theDumper << " , " << anAttrPoint;
 
-  AttributeDoublePtr anAttrScaleFactor =
+  std::string aCreationMethod =
+    aBase->string(FeaturesPlugin_Scale::CREATION_METHOD())->value();
+
+  if (aCreationMethod == FeaturesPlugin_Scale::CREATION_METHOD_BY_FACTOR()) {
+    AttributeDoublePtr anAttrScaleFactor =
       aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_ID());
     theDumper << ", " << anAttrScaleFactor;
+  } else if (aCreationMethod == FeaturesPlugin_Scale::CREATION_METHOD_BY_DIMENSIONS()) {
+    AttributeDoublePtr anAttrScaleFactorX =
+      aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_X_ID());
+    AttributeDoublePtr anAttrScaleFactorY =
+      aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_Y_ID());
+    AttributeDoublePtr anAttrScaleFactorZ =
+      aBase->real(FeaturesPlugin_Scale::SCALE_FACTOR_Z_ID());
+    theDumper << ", " << anAttrScaleFactorX << " , " << anAttrScaleFactorY;
+    theDumper << ", " << anAttrScaleFactorZ;
+  }
+
+  if (!aBase->data()->version().empty())
+    theDumper << ", keepSubResults = True";
 
   theDumper << ")" << std::endl;
 }
@@ -81,8 +140,19 @@ void FeaturesAPI_Scale::dump(ModelHighAPI_Dumper& theDumper) const
 ScalePtr addScale(const std::shared_ptr<ModelAPI_Document>& thePart,
                   const std::list<ModelHighAPI_Selection>& theMainObjects,
                   const ModelHighAPI_Selection& theCenterPoint,
-                  const ModelHighAPI_Double& theScaleFactor)
+                  const ModelHighAPI_Double& theScaleFactorX,
+                  const ModelHighAPI_Double& theScaleFactorY,
+                  const ModelHighAPI_Double& theScaleFactorZ,
+                  const bool keepSubResults)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
-  return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactor));
+  if (!keepSubResults)
+    aFeature->data()->setVersion("");
+  ScalePtr aScale;
+  if (theScaleFactorY.value() == 0 && theScaleFactorZ.value() == 0)
+    aScale.reset(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactorX));
+  else
+    aScale.reset(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint,
+                 theScaleFactorX, theScaleFactorY, theScaleFactorZ));
+  return aScale;
 }
\ No newline at end of file