Salome HOME
Fix for the issue #2573: Wrong position of created part
[modules/shaper.git] / src / FeaturesAPI / FeaturesAPI_Translation.cpp
index bfcd5bdfc61524bbfc848111331f032ea5d00413..2a23db4f6242990edf0771f9ae8637b609f3c413 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        FeaturesAPI_Translation.cpp
-// Created:     07 June 2016
-// Author:      Dmitry Bobylev
+// Copyright (C) 2014-2017  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
+// 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<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "FeaturesAPI_Translation.h"
 
@@ -46,6 +60,20 @@ FeaturesAPI_Translation::FeaturesAPI_Translation(
   }
 }
 
+//==================================================================================================
+FeaturesAPI_Translation::FeaturesAPI_Translation(
+  const std::shared_ptr<ModelAPI_Feature>& theFeature,
+  const std::list<ModelHighAPI_Selection>& theMainObjects,
+  const ModelHighAPI_Selection& theStartPoint,
+  const ModelHighAPI_Selection& theEndPoint)
+: ModelHighAPI_Interface(theFeature)
+{
+  if(initialize()) {
+    fillAttribute(theMainObjects, mymainObjects);
+    setPoints(theStartPoint, theEndPoint);
+  }
+}
+
 //==================================================================================================
 FeaturesAPI_Translation::~FeaturesAPI_Translation()
 {
@@ -85,6 +113,17 @@ void FeaturesAPI_Translation::setDimensions(const ModelHighAPI_Double& theDx,
   execute();
 }
 
+//==================================================================================================
+void FeaturesAPI_Translation::setPoints(const ModelHighAPI_Selection& theStartPoint,
+                                        const ModelHighAPI_Selection& theEndPoint)
+{
+  fillAttribute(FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS(), mycreationMethod);
+  fillAttribute(theStartPoint, mystartPoint);
+  fillAttribute(theEndPoint, myendPoint);
+
+  execute();
+}
+
 //==================================================================================================
 void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
 {
@@ -98,7 +137,7 @@ void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
   std::string aCreationMethod =
     aBase->string(FeaturesPlugin_Translation::CREATION_METHOD())->value();
 
-  if(aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) {
+  if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_DISTANCE()) {
     AttributeSelectionPtr anAttrAxis =
       aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
     AttributeDoublePtr anAttrDistance =
@@ -109,9 +148,15 @@ void FeaturesAPI_Translation::dump(ModelHighAPI_Dumper& theDumper) const
     AttributeDoublePtr anAttrDy = aBase->real(FeaturesPlugin_Translation::DY_ID());
     AttributeDoublePtr anAttrDz = aBase->real(FeaturesPlugin_Translation::DZ_ID());
     theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz;
+  } else if (aCreationMethod == FeaturesPlugin_Translation::CREATION_METHOD_BY_TWO_POINTS()) {
+    AttributeSelectionPtr anAttrStartPoint =
+      aBase->selection(FeaturesPlugin_Translation::START_POINT_ID());
+    AttributeSelectionPtr anAttrEndPoint =
+      aBase->selection(FeaturesPlugin_Translation::END_POINT_ID());
+    theDumper << ", " << anAttrStartPoint << ", " << anAttrEndPoint;
   }
 
-   theDumper << ")" << std::endl;
+  theDumper << ")" << std::endl;
 }
 
 //==================================================================================================
@@ -135,3 +180,14 @@ TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
   return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects, theDx, theDy, theDz));
 }
+
+//==================================================================================================
+TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
+                              const std::list<ModelHighAPI_Selection>& theMainObjects,
+                              const ModelHighAPI_Selection& theStartPoint,
+                              const ModelHighAPI_Selection& theEndPoint)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(FeaturesAPI_Translation::ID());
+  return TranslationPtr(new FeaturesAPI_Translation(aFeature, theMainObjects,
+                                                    theStartPoint, theEndPoint));
+}