Salome HOME
Meet the coding style (line length <= 100)
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Scale.cpp
index d402713bc1e5729f84132de2da9a2e11cbeb0e25..e80f3b4cfaf84fc1afd49207f8cdfbc9b27f5ec7 100644 (file)
@@ -30,6 +30,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 +68,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 +99,23 @@ 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;
+  }
 
   theDumper << ")" << std::endl;
 }
@@ -85,4 +128,17 @@ ScalePtr addScale(const std::shared_ptr<ModelAPI_Document>& thePart,
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
   return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint, theScaleFactor));
+}
+
+//==================================================================================================
+ScalePtr addScale(const std::shared_ptr<ModelAPI_Document>& thePart,
+                  const std::list<ModelHighAPI_Selection>& theMainObjects,
+                  const ModelHighAPI_Selection& theCenterPoint,
+                  const ModelHighAPI_Double& theScaleFactorX,
+                  const ModelHighAPI_Double& theScaleFactorY,
+                  const ModelHighAPI_Double& theScaleFactorZ)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Scale::ID());
+  return ScalePtr(new FeaturesAPI_Scale(aFeature, theMainObjects, theCenterPoint,
+                  theScaleFactorX, theScaleFactorY, theScaleFactorZ));
 }
\ No newline at end of file