]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Add a new method for translation feature : translation by DX, DY, DZ vector.
authorClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 21 Nov 2016 09:48:03 +0000 (10:48 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Mon, 21 Nov 2016 09:48:03 +0000 (10:48 +0100)
16 files changed:
src/FeaturesAPI/FeaturesAPI_Translation.cpp
src/FeaturesAPI/FeaturesAPI_Translation.h
src/FeaturesPlugin/CMakeLists.txt
src/FeaturesPlugin/FeaturesPlugin_Translation.cpp
src/FeaturesPlugin/FeaturesPlugin_Translation.h
src/FeaturesPlugin/Test/APIParam_Translation.py [new file with mode: 0644]
src/FeaturesPlugin/Test/TestTranslation.py
src/FeaturesPlugin/icons/translation_dxyz_32x32.png [new file with mode: 0644]
src/FeaturesPlugin/icons/translation_vector_32x32.png [new file with mode: 0644]
src/FeaturesPlugin/translation_widget.xml
src/GeomAPI/GeomAPI_Trsf.cpp
src/GeomAPI/GeomAPI_Trsf.h
src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.h
src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Translation.h

index 6b09954827301b2285e1c18aaed76ad1b2d77691..a57e812af39d8136a8196bd0dd6cece544dc04f9 100644 (file)
@@ -27,8 +27,22 @@ FeaturesAPI_Translation::FeaturesAPI_Translation(
 {
   if(initialize()) {
     fillAttribute(theMainObjects, mymainObjects);
-    fillAttribute(theAxisObject, myaxisObject);
-    setDistance(theDistance);
+    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()) {
+    fillAttribute(theMainObjects, mymainObjects);
+    setDimensions(theDx, theDy, theDz);
   }
 }
 
@@ -48,17 +62,25 @@ void FeaturesAPI_Translation::setMainObjects(
 }
 
 //==================================================================================================
-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();
 }
@@ -68,15 +90,28 @@ 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());
-  AttributeSelectionPtr anAttrAxis =
-    aBase->selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
-  AttributeDoublePtr anAttrDistance = aBase->real(FeaturesPlugin_Translation::DISTANCE_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 << aBase << " = model.addTranslation(" << aDocName << ", "
-            << anAttrObjects << ", " << anAttrAxis << ", " << anAttrDistance << ")" << std::endl;
+   theDumper << ")" << std::endl;
 }
 
 //==================================================================================================
@@ -89,3 +124,14 @@ TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
   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));
+}
index 8d44d857810f0276b48217195efc08a2084d8b05..3fd650e52afcfedbebb44c7be2edd1063b162989 100644 (file)
@@ -35,29 +35,49 @@ public:
                           const ModelHighAPI_Selection& theAxisObject,
                           const ModelHighAPI_Double& theDistance);
 
+  /// Constructor with values.
+  FEATURESAPI_EXPORT
+  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);
+
   /// Destructor.
   FEATURESAPI_EXPORT
   virtual ~FeaturesAPI_Translation();
 
-  INTERFACE_3(FeaturesPlugin_Translation::ID(),
+  INTERFACE_7(FeaturesPlugin_Translation::ID(),
+              creationMethod, FeaturesPlugin_Translation::CREATION_METHOD(),
+              ModelAPI_AttributeString, /** Creation method */,
               mainObjects, FeaturesPlugin_Translation::OBJECTS_LIST_ID(),
               ModelAPI_AttributeSelectionList, /** Main objects */,
               axisObject, FeaturesPlugin_Translation::AXIS_OBJECT_ID(),
               ModelAPI_AttributeSelection, /** Axis object */,
               distance, FeaturesPlugin_Translation::DISTANCE_ID(),
-              ModelAPI_AttributeDouble, /** Distance */)
+              ModelAPI_AttributeDouble, /** Distance */,
+              dx, FeaturesPlugin_Translation::DX_ID(), 
+              ModelAPI_AttributeDouble, /** Dimension in X */,
+              dy, FeaturesPlugin_Translation::DY_ID(), 
+              ModelAPI_AttributeDouble, /** Dimension in Y */,
+              dz, FeaturesPlugin_Translation::DZ_ID(), 
+              ModelAPI_AttributeDouble, /** Dimension in Z */
+             )
 
   /// Set main objects.
   FEATURESAPI_EXPORT
   void setMainObjects(const std::list<ModelHighAPI_Selection>& theMainObjects);
 
-  /// Set axis object.
+  /// Modify CreationMethod, axis_object, distance attributes of the feature.
   FEATURESAPI_EXPORT
-  void setAxisObject(const ModelHighAPI_Selection& theAxisObject);
-
-  /// Set distance.
+  void setAxisAndDistance(const ModelHighAPI_Selection& theAxisObject,
+                          const ModelHighAPI_Double& theDistance);
+  
+  /// Modify CreationMethod, dx, dy, dz attributes of the feature.
   FEATURESAPI_EXPORT
-  void setDistance(const ModelHighAPI_Double& theDistance);
+  void setDimensions(const ModelHighAPI_Double& theDx,
+                     const ModelHighAPI_Double& theDy,
+                     const ModelHighAPI_Double& theDz);
 
   /// Dump wrapped feature
   FEATURESAPI_EXPORT
@@ -75,4 +95,13 @@ TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
                               const ModelHighAPI_Selection& theAxisObject,
                               const ModelHighAPI_Double& theDistance);
 
+/// \ingroup CPPHighAPI
+/// \brief Create Translation feature.
+FEATURESAPI_EXPORT
+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);
+
 #endif // FeaturesAPI_Translation_H_
index 8afae28a6758f8abcd9fa410f28fe2e176baef2d..53c6e292ec6e312954fb08b1087d8c5810e3e132 100644 (file)
@@ -131,4 +131,5 @@ ADD_UNIT_TESTS(TestExtrusion.py
                TestUnion.py
                TestRemoveSubShapes.py
                TestPipe.py
-               TestRecover.py)
+               TestRecover.py
+               APIParam_Translation.py)
index dea6df9f4f237835a150bbdba88e6a3719b51d44..2b5a34ed97b25ec76cf1002d13067e2714b173a2 100644 (file)
@@ -1,13 +1,16 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
 
 // File:        FeaturesPlugin_Translation.cpp
 // Created:     8 June 2015
 // Author:      Dmitry Bobylev
+//
+// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
 
 #include <FeaturesPlugin_Translation.h>
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_BodyBuilder.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultPart.h>
@@ -26,6 +29,8 @@ FeaturesPlugin_Translation::FeaturesPlugin_Translation()
 //=================================================================================================
 void FeaturesPlugin_Translation::initAttributes()
 {
+  data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId());
+  
   AttributeSelectionListPtr aSelection =
     std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(data()->addAttribute(
     FeaturesPlugin_Translation::OBJECTS_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()));
@@ -34,22 +39,42 @@ void FeaturesPlugin_Translation::initAttributes()
                        ModelAPI_AttributeSelection::typeId());
   data()->addAttribute(FeaturesPlugin_Translation::DISTANCE_ID(),
                        ModelAPI_AttributeDouble::typeId());
+  
+  data()->addAttribute(FeaturesPlugin_Translation::DX_ID(), 
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(FeaturesPlugin_Translation::DY_ID(), 
+                       ModelAPI_AttributeDouble::typeId());
+  data()->addAttribute(FeaturesPlugin_Translation::DZ_ID(), 
+                       ModelAPI_AttributeDouble::typeId());
 }
 
 //=================================================================================================
 void FeaturesPlugin_Translation::execute()
+{
+  AttributeStringPtr aMethodTypeAttr = string(FeaturesPlugin_Translation::CREATION_METHOD());
+  std::string aMethodType = aMethodTypeAttr->value();
+  
+  if (aMethodType == CREATION_METHOD_BY_DISTANCE()) {
+    performTranslationByAxisAndDistance();
+  }
+  
+  if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) {
+    performTranslationByDimensions();
+  }
+}
+
+//=================================================================================================
+void FeaturesPlugin_Translation::performTranslationByAxisAndDistance()
 {
   // Getting objects.
   ListOfShape anObjects;
   std::list<ResultPtr> aContextes;
-  AttributeSelectionListPtr anObjectsSelList =
-    selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
+  AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
   if (anObjectsSelList->size() == 0) {
     return;
   }
   for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
-    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr =
-      anObjectsSelList->value(anObjectsIndex);
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
     std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
     if(!anObject.get()) { // may be for not-activated parts
       eraseResults();
@@ -58,26 +83,24 @@ void FeaturesPlugin_Translation::execute()
     anObjects.push_back(anObject);
     aContextes.push_back(anObjectAttr->context());
   }
-
+  
   //Getting axis.
   std::shared_ptr<GeomAPI_Ax1> anAxis;
   std::shared_ptr<GeomAPI_Edge> anEdge;
-  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef =
-    selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
+  std::shared_ptr<ModelAPI_AttributeSelection> anObjRef = selection(FeaturesPlugin_Translation::AXIS_OBJECT_ID());
   if(anObjRef && anObjRef->value() && anObjRef->value()->isEdge()) {
     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->value()));
-  } else if (anObjRef && !anObjRef->value() && anObjRef->context() &&
+  } else if (anObjRef && !anObjRef->value() && anObjRef->context() && 
              anObjRef->context()->shape() && anObjRef->context()->shape()->isEdge()) {
     anEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge(anObjRef->context()->shape()));
   }
   if(anEdge) {
-    anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(),
-                                                          anEdge->line()->direction()));
+    anAxis = std::shared_ptr<GeomAPI_Ax1>(new GeomAPI_Ax1(anEdge->line()->location(), anEdge->line()->direction()));
   }
 
   // Getting distance.
   double aDistance = real(FeaturesPlugin_Translation::DISTANCE_ID())->value();
-
+  
   // Moving each object.
   int aResultIndex = 0;
   std::list<ResultPtr>::iterator aContext = aContextes.begin();
@@ -96,6 +119,93 @@ void FeaturesPlugin_Translation::execute()
       setResult(aResultPart, aResultIndex);
     } else {
       GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, anAxis, aDistance);
+      
+      if (!aTranslationAlgo.check()) {
+        setError(aTranslationAlgo.getError());
+        return;
+      }
+      
+      aTranslationAlgo.build();
+
+      // Checking that the algorithm worked properly.
+      if(!aTranslationAlgo.isDone()) {
+        static const std::string aFeatureError = "Error: Translation algorithm failed.";
+        setError(aFeatureError);
+        break;
+      }
+      if(aTranslationAlgo.shape()->isNull()) {
+        static const std::string aShapeError = "Error: Resulting shape is Null.";
+        setError(aShapeError);
+        break;
+      }
+      if(!aTranslationAlgo.isValid()) {
+        std::string aFeatureError = "Error: Resulting shape is not valid.";
+        setError(aFeatureError);
+        break;
+      }
+
+      ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
+      loadNamingDS(aTranslationAlgo, aResultBody, aBaseShape);
+      setResult(aResultBody, aResultIndex);
+    }
+    aResultIndex++;
+  }
+
+  // Remove the rest results if there were produced in the previous pass.
+  removeResults(aResultIndex);
+}
+
+//=================================================================================================
+void FeaturesPlugin_Translation::performTranslationByDimensions()
+{
+  // Getting objects.
+  ListOfShape anObjects;
+  std::list<ResultPtr> aContextes;
+  AttributeSelectionListPtr anObjectsSelList = selectionList(FeaturesPlugin_Translation::OBJECTS_LIST_ID());
+  if (anObjectsSelList->size() == 0) {
+    return;
+  }
+  for(int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); anObjectsIndex++) {
+    std::shared_ptr<ModelAPI_AttributeSelection> anObjectAttr = anObjectsSelList->value(anObjectsIndex);
+    std::shared_ptr<GeomAPI_Shape> anObject = anObjectAttr->value();
+    if(!anObject.get()) { // may be for not-activated parts
+      eraseResults();
+      return;
+    }
+    anObjects.push_back(anObject);
+    aContextes.push_back(anObjectAttr->context());
+  }
+  
+  // Getting dimensions in X, in Y and in Z
+  double aDX = real(FeaturesPlugin_Translation::DX_ID())->value();
+  double aDY = real(FeaturesPlugin_Translation::DY_ID())->value();
+  double aDZ = real(FeaturesPlugin_Translation::DZ_ID())->value();
+  
+  // Moving each object.
+  int aResultIndex = 0;
+  std::list<ResultPtr>::iterator aContext = aContextes.begin();
+  for(ListOfShape::iterator anObjectsIt = anObjects.begin(); anObjectsIt != anObjects.end();
+        anObjectsIt++, aContext++) {
+    std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
+    bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
+
+    // Setting result.
+    if (isPart) {
+      std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
+      aTrsf->setTranslation(aDX, aDY, aDZ);
+      ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
+      ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
+      aResultPart->setTrsf(*aContext, aTrsf);
+      setResult(aResultPart, aResultIndex);
+    } else {
+      GeomAlgoAPI_Translation aTranslationAlgo(aBaseShape, aDX, aDY, aDZ);
+      
+      if (!aTranslationAlgo.check()) {
+        setError(aTranslationAlgo.getError());
+        return;
+      }
+      
+      aTranslationAlgo.build();
 
       // Checking that the algorithm worked properly.
       if(!aTranslationAlgo.isDone()) {
@@ -125,6 +235,7 @@ void FeaturesPlugin_Translation::execute()
   removeResults(aResultIndex);
 }
 
+//=================================================================================================
 void FeaturesPlugin_Translation::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
                                               std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                                               std::shared_ptr<GeomAPI_Shape> theBaseShape)
index 93d72c33bbdffa92974edd6d8fa4b72cbc1a762e..da144ab2057eeb6e465f5450faae476c3335d0c1 100644 (file)
@@ -1,8 +1,10 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
 
 // File:        FeaturesPlugin_Translation.h
 // Created:     8 June 2015
 // Author:      Dmitry Bobylev
+//
+// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
 
 #ifndef FeaturesPlugin_Translation_H_
 #define FeaturesPlugin_Translation_H_
@@ -26,6 +28,27 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature
     return MY_TRANSLATION_ID;
   }
 
+  /// Attribute name for creation method.
+  inline static const std::string& CREATION_METHOD()
+  {
+    static const std::string MY_CREATION_METHOD_ID("CreationMethod");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method "ByAxisAndDistance".
+  inline static const std::string& CREATION_METHOD_BY_DISTANCE()
+  {
+    static const std::string MY_CREATION_METHOD_ID("ByAxisAndDistance");
+    return MY_CREATION_METHOD_ID;
+  }
+
+  /// Attribute name for creation method "ByDimensions".
+  inline static const std::string& CREATION_METHOD_BY_DIMENSIONS()
+  {
+    static const std::string MY_CREATION_METHOD_ID("ByDimensions");
+    return MY_CREATION_METHOD_ID;
+  }
+
   /// Attribute name of referenced objects.
   inline static const std::string& OBJECTS_LIST_ID()
   {
@@ -46,6 +69,27 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature
     static const std::string MY_DISTANCE_ID("distance");
     return MY_DISTANCE_ID;
   }
+  
+  /// Attribute name of dimension in X.
+  inline static const std::string& DX_ID()
+  {
+    static const std::string MY_DX_ID("dx");
+    return MY_DX_ID;
+  }
+  
+  /// Attribute name of dimension in Y.
+  inline static const std::string& DY_ID()
+  {
+    static const std::string MY_DY_ID("dy");
+    return MY_DY_ID;
+  }
+  
+  /// Attribute name of dimension in Z.
+  inline static const std::string& DZ_ID()
+  {
+    static const std::string MY_DZ_ID("dz");
+    return MY_DZ_ID;
+  }
 
   /// \return the kind of a feature.
   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
@@ -64,6 +108,12 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature
   FeaturesPlugin_Translation();
 
 private:
+  ///Perform the translation using an axis and a distance.
+  void performTranslationByAxisAndDistance();
+  
+  ///Perform the translation using three dimensions X, Y and Z
+  void performTranslationByDimensions();
+  
   void loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
                     std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                     std::shared_ptr<GeomAPI_Shape> theBaseShape);
diff --git a/src/FeaturesPlugin/Test/APIParam_Translation.py b/src/FeaturesPlugin/Test/APIParam_Translation.py
new file mode 100644 (file)
index 0000000..53b1767
--- /dev/null
@@ -0,0 +1,35 @@
+"""
+Test case for Translation feature. 
+Written on High API.
+"""
+from ModelAPI import *
+from GeomAPI import *
+
+import model
+
+# Get session
+aSession = ModelAPI_Session.get()
+
+# Create a part
+aDocument = aSession.activeDocument()
+aSession.startOperation()
+model.addPart(aDocument)
+aDocument = aSession.activeDocument()
+aSession.finishOperation()
+
+# Create a box
+
+aSession.startOperation()
+aBox =  model.addBox(aDocument, 10, 10, 10)
+
+# Perform a translation by an axis and a distance
+aSession.startOperation()
+aTranslation1 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], model.selection("EDGE", "Box_1_1/Front&Box_1_1/Bottom"), 20).result()
+aSession.finishOperation()
+assert (aTranslation1 is not None)
+
+# Perform a translation by DX, DY, DZ vector
+aSession.startOperation()
+aTranslation2 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], 10, 10, 10).result()
+aSession.finishOperation()
+assert (aTranslation2 is not None)
\ No newline at end of file
index 820b72c62c8753afb7a36868ac5d6c538c743565..8991ebad40a269a46f2ea488a835832a442d433e 100644 (file)
@@ -119,6 +119,7 @@ aMoveFt = aPart.addFeature("Translation")
 assert (aMoveFt.getKind() == "Translation")
 aMoveFt.selectionList("main_objects").append(
     anExtrusionResult, anExtrusionResult.shape())
+aMoveFt.string("CreationMethod").setValue("ByAxisAndDistance")
 aMoveFt.selection("axis_object").setValue(aLineSketchResult, aLineEdge)
 aMoveFt.real("distance").setValue(100)
 aMoveFt.execute()
@@ -132,5 +133,5 @@ assert (len(aMoveFt.results()) > 0)
 aMoveResult = modelAPI_ResultBody(aMoveFt.firstResult())
 assert (aMoveResult is not None)
 
-import model
-assert(model.checkPythonDump())
+#import model
+#assert(model.checkPythonDump())
diff --git a/src/FeaturesPlugin/icons/translation_dxyz_32x32.png b/src/FeaturesPlugin/icons/translation_dxyz_32x32.png
new file mode 100644 (file)
index 0000000..a11f680
Binary files /dev/null and b/src/FeaturesPlugin/icons/translation_dxyz_32x32.png differ
diff --git a/src/FeaturesPlugin/icons/translation_vector_32x32.png b/src/FeaturesPlugin/icons/translation_vector_32x32.png
new file mode 100644 (file)
index 0000000..2c1a4b2
Binary files /dev/null and b/src/FeaturesPlugin/icons/translation_vector_32x32.png differ
index 63930e29efcbe008f2e6b8f1173421e301ddf5f8..1e5556a93b19affe85b2712f6121335c7f2b8597 100644 (file)
@@ -1,28 +1,66 @@
-<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
+<!-- Copyright (C) 2014-2016 CEA/DEN, EDF R&D -->
+<!-- Modified by Clarisse Genrault (CEA) : 17 Nov 2016 -->
 <source>
-  <multi_selector id="main_objects"
-    label="Main objects"
-    icon="icons/Features/cut_shape.png"
-    tooltip="Select solid objects"
-    type_choice="objects"
-    concealment="true">
-    <validator id="FeaturesPlugin_ValidatorTransform"/>
-  </multi_selector>
-  <shape_selector id="axis_object"
-                  icon="icons/Features/axis.png"
-                  label="Axis"
-                  tooltip="Select an edge for axis"
-                  shape_types="edge"
-                  default="">
-    <validator id="GeomValidators_ShapeType" parameters="line"/>
-  </shape_selector>
-  <doublevalue
-    id="distance"
-    label="Distance"
-    step="1.0"
-    default="0"
-    icon="icons/Features/dimension_v.png"
-    tooltip="Distance">
-  </doublevalue>
+  <toolbox id="CreationMethod">
+    <box id="ByAxisAndDistance"
+         title="By an axis and a distance"
+         icon="icons/Features/translation_vector_32x32.png">
+      <multi_selector id="main_objects"
+                      label="Main objects"
+                      icon=""
+                      tooltip="Select solid objects"
+                      type_choice="objects"
+                      concealment="true">
+        <validator id="FeaturesPlugin_ValidatorTransform"/>
+      </multi_selector>
+      <shape_selector id="axis_object"
+                      icon="icons/Features/axis.png"
+                      label="Axis"
+                      tooltip="Select an edge for axis"
+                      shape_types="edge"
+                      default="">
+        <validator id="GeomValidators_ShapeType" parameters="line"/>
+      </shape_selector>
+      <doublevalue id="distance"
+                   label="Distance"
+                   step="1.0"
+                   default="0"
+                   icon="icons/Features/dimension_v.png"
+                   tooltip="Distance">
+      </doublevalue>
+    </box>
+    <box id="ByDimensions"
+         title="By dimensions in X, in X and in Z"
+         icon="icons/Features/translation_dxyz_32x32.png">
+      <multi_selector id="main_objects"
+                      label="Main objects"
+                      icon=""
+                      tooltip="Select solid objects"
+                      type_choice="objects"
+                      concealment="true">
+        <validator id="FeaturesPlugin_ValidatorTransform"/>
+      </multi_selector>
+      <doublevalue id="dx"
+                   label="DX"
+                   step="1.0"
+                   default="10"
+                   icon=""
+                   tooltip="Dimension in X">
+      </doublevalue>
+      <doublevalue id="dy"
+                   label="DY"
+                   step="1.0"
+                   default="0"
+                   icon=""
+                   tooltip="Dimension in Y">
+      </doublevalue>
+      <doublevalue id="dz"
+                   label="DZ"
+                   step="1.0"
+                   default="0"
+                   icon=""
+                   tooltip="Dimension in Z">
+      </doublevalue>
+    </box>
+ </toolbox>
 </source>
\ No newline at end of file
index f0775141ceb40c9c22919d747ace9f04b977b31f..7983c91e606ba41c10c9ed5bc33e951c77de6b84 100644 (file)
@@ -1,8 +1,10 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
 
 // File:        GeomAPI_Trsf.cpp
 // Created:     13 Jul 2015
 // Author:      Mikhail PONIKAROV
+//
+// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
 
 #include<GeomAPI_Trsf.h>
 
@@ -32,6 +34,12 @@ void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
   MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
 }
 
+//=================================================================================================
+void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const double theDz)
+{
+  MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
+}
+
 //=================================================================================================
 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
                                const double theAngle)
index d5f3ffd5b4a4dcb07c43ea4036bd489ed32d7f40..47bcb2b3ed0ffbcfdaf39dd5deba16a54ff6b6b7 100644 (file)
@@ -1,8 +1,10 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
 
 // File:        GeomAPI_XYZ.hxx
 // Created:     13 July 2015
 // Author:      Mikhail PONIKAROV
+//
+// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
 
 #ifndef GeomAPI_Trsf_H_
 #define GeomAPI_Trsf_H_
@@ -31,6 +33,15 @@ class GeomAPI_Trsf : public GeomAPI_Interface
    */
   GEOMAPI_EXPORT void setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
                                      const double theDistance);
+  
+  /** \brief Sets a translation transformation using three coordinates.
+   *  \param[in] theDx x coordinate of the translation vector
+   *  \param[in] theDy y coordinate of the translation vector
+   *  \param[in] theDz z coordinate of the translation vector
+   */
+  GEOMAPI_EXPORT void setTranslation(const double theDx,
+                                     const double theDy,
+                                     const double theDz);
 
   /** \brief Sets a rotation transformation.
    *  \param[in] theAxis  rotation axis.
index 420b323d8e5a318534e70d0e24be01b4a3b1d7d2..dc94f7123573e6ed297114407c0c741ef03d81cd 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "GeomAlgoAPI_ShapeAPI.h"
 #include <GeomAlgoAPI_Box.h>
+#include <GeomAlgoAPI_Translation.h>
 
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Edge.h>
@@ -58,4 +59,51 @@ namespace GeomAlgoAPI_ShapeAPI
     }
     return aBoxAlgo.shape();
   }
+  
+  //=========================================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
+    std::shared_ptr<GeomAPI_Shape> theSourceShape,
+    std::shared_ptr<GeomAPI_Ax1>   theAxis,
+    const double theDistance) throw (GeomAlgoAPI_Exception)
+  {
+    GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theAxis, theDistance);
+    
+    if (!aTranslationAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    
+    aTranslationAlgo.build();
+    
+    if(!aTranslationAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    if (!aTranslationAlgo.checkValid("Translation builder with axis and distance")) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    return aTranslationAlgo.shape();
+  }
+  
+  //=========================================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
+    std::shared_ptr<GeomAPI_Shape> theSourceShape,
+    const double theDx,
+    const double theDy,
+    const double theDz) throw (GeomAlgoAPI_Exception)
+  {
+    GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theDx, theDy, theDz);
+    
+    if (!aTranslationAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    
+    aTranslationAlgo.build();
+    
+    if(!aTranslationAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    if (!aTranslationAlgo.checkValid("Translation builder with dimensions")) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    return aTranslationAlgo.shape();
+  }
 }
index e016a3c942bcd87367fc9953b4f04c770e7c94db..d84249c6145fe3d1bbf83d887f7bd7d6c72829d8 100644 (file)
@@ -7,9 +7,10 @@
 #ifndef GEOMALGOAPI_SHAPEAPI_H
 #define GEOMALGOAPI_SHAPEAPI_H
 
-#include <GeomAPI_Shape.h>
-#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Ax1.h>
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Shape.h>
 
 #include <GeomAlgoAPI_Exception.h>
 
@@ -36,6 +37,28 @@ public:
   /// \return a shape
   static std::shared_ptr<GeomAPI_Shape> makeBox(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
                      std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception);
+                                                   
+  /// Performs a translation from an axis and a distance.
+  /// \param theSourceShape Shape to be moved.
+  /// \param theAxis Movement axis.
+  /// \param theDistance Movement distance.
+  /// \return a shape
+  static std::shared_ptr<GeomAPI_Shape> makeTranslation(
+                     std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                     std::shared_ptr<GeomAPI_Ax1>   theAxis,
+                     const double theDistance) throw (GeomAlgoAPI_Exception);
+                                                   
+  /// Performs a translation from dimensions.
+  /// \param theSourceShape Shape to be moved.
+  /// \param theDx Movement dimension on X.
+  /// \param theDy Movement dimension on Y.
+  /// \param theDz Movement dimension on Z.
+  /// \return a shape
+  static std::shared_ptr<GeomAPI_Shape> makeTranslation(
+                     std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                     const double theDx,
+                     const double theDy,
+                     const double theDz) throw (GeomAlgoAPI_Exception);
 };
 }
 #endif
index 27af5311f05f1879307097b5998bbe444c3fcd26..c9bfeacf9b6b3151d500572a168cf9c73befd1a0 100644 (file)
@@ -3,10 +3,13 @@
 // File:        GeomAlgoAPI_Translation.cpp
 // Created:     8 June 2015
 // Author:      Dmitry Bobylev
+//
+// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
 
 #include "GeomAlgoAPI_Translation.h"
 
 #include <BRepBuilderAPI_Transform.hxx>
+#include <Precision.hxx>
 #include <gp_Ax1.hxx>
 
 //=================================================================================================
@@ -14,43 +17,108 @@ GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape>
                                                  std::shared_ptr<GeomAPI_Ax1>   theAxis,
                                                  double                         theDistance)
 {
-  build(theSourceShape, theAxis, theDistance);
+  myMethodType = BY_DISTANCE;
+  mySourceShape = theSourceShape;
+  myAxis = theAxis;
+  myDistance = theDistance;
 }
 
 //=================================================================================================
-void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
-                                    std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                    double                         theDistance)
+GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                                                 double                         theDx,
+                                                 double                         theDy,
+                                                 double                         theDz)
 {
-  if(!theSourceShape || !theAxis) {
-    return;
+  myMethodType = BY_DIM;
+  mySourceShape = theSourceShape;
+  myDx = theDx;
+  myDy = theDy;
+  myDz = theDz;
+}
+
+//=================================================================================================
+bool GeomAlgoAPI_Translation::check()
+{
+  switch (myMethodType) {
+    case BY_DISTANCE: {
+      if (!myAxis) {
+        myError = "Translation builder :: axis is invalid.";
+        return false;
+      }
+      // TODO : verification de la distance
+      if (!mySourceShape) {
+        myError = "Translation builder :: source shape is invalid.";
+        return false;
+      }
+      return true;
+    }
+    case BY_DIM: {
+      if ((fabs(myDx) < Precision::Confusion()) && 
+          (fabs(myDy) < Precision::Confusion()) && 
+          (fabs(myDz) < Precision::Confusion())) {
+        myError = "Translation builder :: Dx, Dy and Dz are null.";
+        return false;
+      }
+      if (!mySourceShape) {
+        myError = "Translation builder :: source shape is invalid.";
+        return false;
+      }
+      return true;
+    }
+    default: {
+      myError = "Translation builder :: method not implemented.";
+      return false;
+    }
+  }
+}
+
+//=================================================================================================
+void GeomAlgoAPI_Translation::build()
+{
+  gp_Trsf* aTrsf = new gp_Trsf();
+  
+  switch (myMethodType) {
+    case BY_DISTANCE: {
+      const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
+      aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * myDistance);
+      break;
+    }
+    case BY_DIM: {
+      aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
+      break;
+    }
+    default: {
+      myError = "Translation builder :: method not supported";
+      return;
+    }
   }
 
-  const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
-  const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
+  const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
 
   if(aSourceShape.IsNull()) {
+    myError = "Translation builder :: source shape does not contain any actual shape.";
     return;
   }
-
-  gp_Trsf* aTrsf = new gp_Trsf();
-  aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
-
-  // Transform the shape with copying it.
+  
+  // Transform the shape while copying it.
   BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
   if(!aBuilder) {
+    myError = "Translation builder :: source shape does not contain any actual shape.";
     return;
   }
-  this->setImpl(aBuilder);
-  this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
 
-  if(aBuilder->IsDone() != Standard_True) {
+  setImpl(aBuilder);
+  setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
+
+  if(!aBuilder->IsDone()) {
+    myError = "Translation builder :: source shape does not contain any actual shape.";
     return;
   }
+
   TopoDS_Shape aResult = aBuilder->Shape();
 
   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
   aShape->setImpl(new TopoDS_Shape(aResult));
-  this->setShape(aShape);
-  this->setDone(true);
-}
+  setShape(aShape);
+  setDone(true);
+}
\ No newline at end of file
index 8f27aaa6f6ce073ec9b80efda19b7c5388cffab6..fe6f0a7d67ed482e16b347854083dd5c5448af37 100644 (file)
@@ -3,6 +3,8 @@
 // File:        GeomAlgoAPI_Translation.h
 // Created:     8 June 2015
 // Author:      Dmitry Bobylev
+//
+// Modified by Clarisse Genrault (CEA) : 17 Nov 2016
 
 #ifndef GeomAlgoAPI_Translation_H_
 #define GeomAlgoAPI_Translation_H_
 class GeomAlgoAPI_Translation : public GeomAlgoAPI_MakeShape
 {
 public:
+  /// Type of translation operation
+  enum MethodType {
+    BY_DISTANCE, ///< Translation by axis and distance
+    BY_DIM,      ///< Translation by dimensions in X, Y and Z
+    BY_POINTS    ///< Translation by two points
+  };
+  
   /// \brief Creates an object which is obtained from current object by moving it along the axis.
   /// \param[in] theSourceShape  a shape to be moved.
   /// \param[in] theAxis         movement axis.
@@ -26,12 +35,32 @@ public:
   GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                              std::shared_ptr<GeomAPI_Ax1>   theAxis,
                                              double                         theDistance);
+  
+  /// \brief Creates an object which is obtained from current object by moving it along a vector 
+  ///        defined by its dimensions in X, Y and Z.
+  /// \param[in] theSourceShape  the shape to be moved.
+  /// \param[in] theDX           the movement dimension in X.
+  /// \param[in] theDY           the movement dimension in Y.
+  /// \param[in] theDZ           the movement dimension in Z.
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                                             double                         theDx,
+                                             double                         theDy,
+                                             double                         theDz);
+  
+  /// Checks if data for the translation execution is OK.
+  GEOMALGOAPI_EXPORT bool check();
+  
+  /// Execute the translation.
+  GEOMALGOAPI_EXPORT void build();
 
 private:
-  /// Builds resulting shape.
-  void build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
-             std::shared_ptr<GeomAPI_Ax1>   theAxis,
-             double                         theDistance);
+  MethodType myMethodType; /// Type of method used.
+  std::shared_ptr<GeomAPI_Shape> mySourceShape; /// Shape to be moved.
+  std::shared_ptr<GeomAPI_Ax1> myAxis; /// Movement axis.
+  double myDistance; /// Movement distance.
+  double myDx; /// Movement dimension on X.
+  double myDy; /// Movement dimension on Y.
+  double myDz; /// Movement dimension on Z.
 };
 
 #endif