Salome HOME
Revert "Add a new method for translation : translation by two points."
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Translation.cpp
index e4c61d95458f096f6fd55c726784f1b5f304078c..bfcd5bdfc61524bbfc848111331f032ea5d00413 100644 (file)
@@ -6,26 +6,43 @@
 
 #include "FeaturesAPI_Translation.h"
 
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
 
 //==================================================================================================
-FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+FeaturesAPI_Translation::FeaturesAPI_Translation(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature)
 : ModelHighAPI_Interface(theFeature)
 {
   initialize();
 }
 
 //==================================================================================================
-FeaturesAPI_Translation::FeaturesAPI_Translation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                                                 const std::list<ModelHighAPI_Selection>& theMainObjects,
-                                                 const ModelHighAPI_Selection& theAxisObject,
-                                                 const ModelHighAPI_Double& theDistance)
+FeaturesAPI_Translation::FeaturesAPI_Translation(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<ModelHighAPI_Selection>& theMainObjects,
+  const ModelHighAPI_Selection& theAxisObject,
+  const ModelHighAPI_Double& theDistance)
+: ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    fillAttribute(theMainObjects, mymainObjects);
+    setAxisAndDistance(theAxisObject, theDistance);
+  }
+}
+
+//==================================================================================================
+FeaturesAPI_Translation::FeaturesAPI_Translation(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<ModelHighAPI_Selection>& theMainObjects,
+  const ModelHighAPI_Double& theDx,
+  const ModelHighAPI_Double& theDy,
+  const ModelHighAPI_Double& theDz)
 : ModelHighAPI_Interface(theFeature)
 {
   if(initialize()) {
-    setMainObjects(theMainObjects);
-    setAxisObject(theAxisObject);
-    setDistance(theDistance);
+    fillAttribute(theMainObjects, mymainObjects);
+    setDimensions(theDx, theDy, theDz);
   }
 }
 
@@ -36,7 +53,8 @@ FeaturesAPI_Translation::~FeaturesAPI_Translation()
 }
 
 //==================================================================================================
-void FeaturesAPI_Translation::setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects)
+void FeaturesAPI_Translation::setMainObjects(
+  const std::list<ModelHighAPI_Selection>& theMainObjects)
 {
   fillAttribute(theMainObjects, mymainObjects);
 
@@ -44,22 +62,58 @@ void FeaturesAPI_Translation::setMainObjects(const std::list<ModelHighAPI_Select
 }
 
 //==================================================================================================
-void FeaturesAPI_Translation::setAxisObject(const ModelHighAPI_Selection& theAxisObject)
+void FeaturesAPI_Translation::setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
+                                                 const ModelHighAPI_Double& theDistance)
 {
+  fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE(), mycreationMethod);
   fillAttribute(theAxisObject, myaxisObject);
+  fillAttribute(theDistance, mydistance);
 
   execute();
 }
 
 //==================================================================================================
-void FeaturesAPI_Translation::setDistance(const ModelHighAPI_Double& theDistance)
+void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
+                                            const ModelHighAPI_Double& theDy,
+                                            const ModelHighAPI_Double& theDz)
 {
-  fillAttribute(theDistance, mydistance);
+  fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS(), mycreationMethod);
+  fillAttribute(theDx, mydx);
+  fillAttribute(theDy, mydy);
+  fillAttribute(theDz, mydz);
 
   execute();
 }
 
-// TODO(spo): make add* as static functions of the class
+//==================================================================================================
+void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aDocName = theDumper.name(aBase->document());
+
+  AttributeSelectionListPtr anAttrObjects =
+    aBase->selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
+  theDumper << aBase << " = model.addTranslation(" << aDocName << ", " << anAttrObjects;
+
+  std::string aCreationMethod =
+    aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
+
+  if(aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) {
+    AttributeSelectionPtr anAttrAxis =
+      aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
+    AttributeDoublePtr anAttrDistance =
+      aBase->real(FeaturesPlugin_Translation::DISTANCE_ID());
+    theDumper << ", " << anAttrAxis << ", " << anAttrDistance;
+  } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DIMENSIONS()) {
+    AttributeDoublePtr anAttrDx = aBase->real(FeaturesPlugin_Translation::DX_ID());
+    AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID());
+    AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID());
+    theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
+  }
+
+   theDumper << ")" << std::endl;
+}
+
 //==================================================================================================
 TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
                               const std::list<ModelHighAPI_Selection>& theMainObjects,
@@ -67,5 +121,17 @@ TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
                               const ModelHighAPI_Double& theDistance)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
-  return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theAxisObject, theDistance));
+  return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
+                                                    theAxisObject, theDistance));
+}
+
+//==================================================================================================
+TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                              const std::list<ModelHighAPI_Selection>& theMainObjects,
+                              const ModelHighAPI_Double& theDx,
+                              const ModelHighAPI_Double& theDy,
+                              const ModelHighAPI_Double& theDz)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
+  return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
 }