Salome HOME
Revert "Revert "Add a new method for translation : translation by two points.""
authorClarisse Genrault <clarisse.genrault@cea.fr>
Wed, 23 Nov 2016 14:34:21 +0000 (15:34 +0100)
committerClarisse Genrault <clarisse.genrault@cea.fr>
Wed, 23 Nov 2016 14:34:21 +0000 (15:34 +0100)
This reverts commit 596cc06a3cdc89783d15e893e7da4b6b882fb442.

15 files changed:
src/FeaturesAPI/FeaturesAPI_Translation.cpp
src/FeaturesAPI/FeaturesAPI_Translation.h
src/FeaturesAPI/Test/APIParam_Translation.py
src/FeaturesPlugin/FeaturesPlugin_Translation.cpp
src/FeaturesPlugin/FeaturesPlugin_Translation.h
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/icons/translation_2pt_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
src/GeomAlgoAPI/Test/TestAPI_Translation.py

index bfcd5bdfc61524bbfc848111331f032ea5d00413..ec05c3cefb2951bc2e311bb1eb53fcec334166d6 100644 (file)
@@ -46,6 +46,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 +99,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
 {
@@ -109,6 +134,12 @@ 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;
@@ -135,3 +166,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));
+}
index 91f3e7e1444fb3fd31794e6554ff40a8431a9b51..11a7ddf8cb3d9350288f84049158e1b949d8313c 100644 (file)
@@ -39,15 +39,22 @@ public:
   FEATURESAPI_EXPORT
   explicit 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);
+                                   const ModelHighAPI_Double& theDx,
+                                   const ModelHighAPI_Double& theDy,
+                                   const ModelHighAPI_Double& theDz);
+
+  /// Constructor with values.
+  FEATURESAPI_EXPORT
+  explicit FeaturesAPI_Translation(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                   const std::list<ModelHighAPI_Selection>& theMainObjects,
+                                   const ModelHighAPI_Selection& theStartPoint,
+                                   const ModelHighAPI_Selection& theEndPoint);
 
   /// Destructor.
   FEATURESAPI_EXPORT
   virtual ~FeaturesAPI_Translation();
 
-  INTERFACE_7(FeaturesPlugin_Translation::ID(),
+  INTERFACE_9(FeaturesPlugin_Translation::ID(),
               creationMethod, FeaturesPlugin_Translation::CREATION_METHOD(),
               ModelAPI_AttributeString, /** Creation method */,
               mainObjects, FeaturesPlugin_Translation::OBJECTS_LIST_ID(),
@@ -61,7 +68,11 @@ public:
               dy, FeaturesPlugin_Translation::DY_ID(),
               ModelAPI_AttributeDouble, /** Dimension in Y */,
               dz, FeaturesPlugin_Translation::DZ_ID(),
-              ModelAPI_AttributeDouble, /** Dimension in Z */
+              ModelAPI_AttributeDouble, /** Dimension in Z */,
+              startPoint, FeaturesPlugin_Translation::START_POINT_ID(),
+              ModelAPI_AttributeSelection, /** Start point object */,
+              endPoint, FeaturesPlugin_Translation::END_POINT_ID(),
+              ModelAPI_AttributeSelection, /** End point object */
              )
 
   /// Set main objects.
@@ -79,6 +90,11 @@ public:
                      const ModelHighAPI_Double& theDy,
                      const ModelHighAPI_Double& theDz);
 
+  /// Modify CreationMethod, start_point, end_point attributes of the feature.
+  FEATURESAPI_EXPORT
+  void setPoints(const ModelHighAPI_Selection& theStartPoint,
+                 const ModelHighAPI_Selection& theEndPoint);
+
   /// Dump wrapped feature
   FEATURESAPI_EXPORT
   virtual void dump(ModelHighAPI_Dumper& theDumper) const;
@@ -104,4 +120,12 @@ TranslationPtr addTranslation(const std::shared_ptr<ModelAPI_Document>& thePart,
                               const ModelHighAPI_Double& theDy,
                               const ModelHighAPI_Double& theDz);
 
+/// \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_Selection& theStartPoint,
+                              const ModelHighAPI_Selection& theEndPoint);
+
 #endif // FeaturesAPI_Translation_H_
index 53b1767811eeb964d8368fb62090e1c9eec13eb5..6795c25b8499f078336ddf93a04292448fe27922 100644 (file)
@@ -32,4 +32,12 @@ assert (aTranslation1 is not None)
 aSession.startOperation()
 aTranslation2 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], 10, 10, 10).result()
 aSession.finishOperation()
+assert (aTranslation2 is not None)
+
+# Perform a translation by two points
+aSession.startOperation()
+aPoint1 = model.addPoint(aDocument, 0, 0, 0).result()
+aPoint2 = model.addPoint(aDocument, 10, 10, 0).result()
+aTranslation3 = model.addTranslation(aDocument, [model.selection("SOLID", "Box_1_1")], aPoint1, aPoint2).result()
+aSession.finishOperation()
 assert (aTranslation2 is not None)
\ No newline at end of file
index 26b70c33b9c32b20976c444d538b3baa5803e2af..4bd8aea03d2a0fb63918e6b35dd69329c907796e 100644 (file)
@@ -19,6 +19,8 @@
 #include <GeomAPI_Edge.h>
 #include <GeomAPI_Lin.h>
 
+#include <GeomAlgoAPI_PointBuilder.h>
+
 #include <FeaturesPlugin_Tools.h>
 
 //=================================================================================================
@@ -46,6 +48,11 @@ void FeaturesPlugin_Translation::initAttributes()
                        ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(FeaturesPlugin_Translation::DZ_ID(),
                        ModelAPI_AttributeDouble::typeId());
+
+  data()->addAttribute(FeaturesPlugin_Translation::START_POINT_ID(),
+                       ModelAPI_AttributeSelection::typeId());
+  data()->addAttribute(FeaturesPlugin_Translation::END_POINT_ID(),
+                       ModelAPI_AttributeSelection::typeId());
 }
 
 //=================================================================================================
@@ -61,6 +68,10 @@ void FeaturesPlugin_Translation::execute()
   if (aMethodType == CREATION_METHOD_BY_DIMENSIONS()) {
     performTranslationByDimensions();
   }
+
+  if (aMethodType == CREATION_METHOD_BY_TWO_POINTS()) {
+    performTranslationByTwoPoints();
+  }
 }
 
 //=================================================================================================
@@ -241,6 +252,101 @@ void FeaturesPlugin_Translation::performTranslationByDimensions()
   removeResults(aResultIndex);
 }
 
+//=================================================================================================
+void FeaturesPlugin_Translation::performTranslationByTwoPoints()
+{
+  // 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 the start point and the end point
+  AttributeSelectionPtr aRef1 = data()->selection(FeaturesPlugin_Translation::START_POINT_ID());
+  AttributeSelectionPtr aRef2 = data()->selection(FeaturesPlugin_Translation::END_POINT_ID());
+  std::shared_ptr<GeomAPI_Pnt> aFirstPoint;
+  std::shared_ptr<GeomAPI_Pnt> aSecondPoint;
+  if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
+    GeomShapePtr aShape1 = aRef1->value();
+    if (!aShape1.get()) //If we can't get the points directly, try getting them from the context
+      aShape1 = aRef1->context()->shape();
+    GeomShapePtr aShape2 = aRef2->value();
+    if (!aShape2.get())
+      aShape2 = aRef2->context()->shape();
+    if (aShape1 && aShape2) {
+      aFirstPoint = GeomAlgoAPI_PointBuilder::point(aShape1);
+      aSecondPoint = GeomAlgoAPI_PointBuilder::point(aShape2);
+    }
+  }
+
+  // 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(aFirstPoint, aSecondPoint);
+      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, aFirstPoint, aSecondPoint);
+
+      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::loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
                                               std::shared_ptr<ModelAPI_ResultBody> theResultBody,
index 2e3cf314b0c0e2201a3ee469d0c8aa7edcc92909..899a8e0f2af622d3ce8c13e5dbc9f10d5b74ff8d 100644 (file)
@@ -49,6 +49,13 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature
     return MY_CREATION_METHOD_ID;
   }
 
+  /// Attribute name for creation method "ByTwoPoints".
+  inline static const std::string& CREATION_METHOD_BY_TWO_POINTS()
+  {
+    static const std::string MY_CREATION_METHOD_ID("ByTwoPoints");
+    return MY_CREATION_METHOD_ID;
+  }
+
   /// Attribute name of referenced objects.
   inline static const std::string& OBJECTS_LIST_ID()
   {
@@ -91,6 +98,20 @@ class FeaturesPlugin_Translation : public ModelAPI_Feature
     return MY_DZ_ID;
   }
 
+  /// Attribute name of start point.
+  inline static const std::string& START_POINT_ID()
+  {
+    static const std::string MY_START_POINT_ID("start_point");
+    return MY_START_POINT_ID;
+  }
+
+  /// Attribute name of end point.
+  inline static const std::string& END_POINT_ID()
+  {
+    static const std::string MY_END_POINT_ID("end_point");
+    return MY_END_POINT_ID;
+  }
+
   /// \return the kind of a feature.
   FEATURESPLUGIN_EXPORT virtual const std::string& getKind()
   {
@@ -114,6 +135,9 @@ private:
   ///Perform the translation using three dimensions X, Y and Z
   void performTranslationByDimensions();
 
+  ///Perform the translation usind two points
+  void performTranslationByTwoPoints();
+
   void loadNamingDS(GeomAlgoAPI_Translation& theTranslationAlgo,
                     std::shared_ptr<ModelAPI_ResultBody> theResultBody,
                     std::shared_ptr<GeomAPI_Shape> theBaseShape);
index 25a388dffb92d64cedcd05360f487b82eb82a568..dcb41eb2dc1b497fc421346979d05594885eb9cc 100644 (file)
                    shape_types="vertices edges wires faces shells solids compsolids compounds">
     <validator id="FeaturesPlugin_ValidatorCompositeLauncher" parameters="base,Sketch"/>
   </sketch_launcher>
-  <multi_selector id="base"
-                  label="Base objects:"
-                  tooltip="Select a base objects"
-                  type_choice="vertices edges wires faces shells compounds"
-                  concealment="true">
-    <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
-  </multi_selector>
-  <shape_selector id="direction_object"
-                  icon="icons/Features/axis.png"
-                  label="Direction"
-                  tooltip="Select an edge for direction"
-                  shape_types="edge"
-                  default="&lt;base normal&gt;">
-    <validator id="GeomValidators_ShapeType" parameters="empty,line"/>
-  </shape_selector>
   <toolbox id="CreationMethod">
     <box id="BySizes"
          title="By sizes"
       </groupbox>
     </box>
   </toolbox>
+  <multi_selector id="base"
+                  label="Base objects:"
+                  tooltip="Select a base objects"
+                  type_choice="vertices edges wires faces shells compounds"
+                  concealment="true">
+    <validator id="FeaturesPlugin_ValidatorBaseForGeneration" parameters="vertex,edge,wire,face,shell,compound"/>
+  </multi_selector>
+  <shape_selector id="direction_object"
+                  icon="icons/Features/axis.png"
+                  label="Direction"
+                  tooltip="Select an edge for direction"
+                  shape_types="edge"
+                  default="&lt;base normal&gt;">
+    <validator id="GeomValidators_ShapeType" parameters="empty,line"/>
+  </shape_selector>
   <validator id="GeomValidators_ZeroOffset" parameters="CreationMethod,BySizes,base,to_size,from_size,to_object,to_offset,from_object,from_offset"/>
   <validator id="FeaturesPlugin_ValidatorExtrusionDir" parameters="base,direction_object"/>
 </source>
diff --git a/src/FeaturesPlugin/icons/translation_2pt_32x32.png b/src/FeaturesPlugin/icons/translation_2pt_32x32.png
new file mode 100644 (file)
index 0000000..5e68607
Binary files /dev/null and b/src/FeaturesPlugin/icons/translation_2pt_32x32.png differ
index 1e5556a93b19affe85b2712f6121335c7f2b8597..a5b247dc6e89f6d6ea1e86864d1d4ab96eccdc8e 100644 (file)
                    tooltip="Dimension in Z">
       </doublevalue>
     </box>
+    <box id="ByTwoPoints"
+         title="By two points"
+         icon="icons/Features/translation_2pt_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="start_point"
+                      icon=""
+                      label="Start point"
+                      tooltip="Select the start point to define the axis"
+                      shape_types="vertex"
+                      default="">
+        <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+        <validator id="GeomValidators_ConstructionComposite"/>
+      </shape_selector>
+      <shape_selector id="end_point"
+                      icon=""
+                      label="End point"
+                      tooltip="Select the end point to define the axis"
+                      shape_types="vertex"
+                      default="">
+        <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+        <validator id="GeomValidators_ConstructionComposite"/>
+        <validator id="GeomValidators_DifferentShapes"/>
+      </shape_selector>
+    </box>
  </toolbox>
 </source>
\ No newline at end of file
index 7983c91e606ba41c10c9ed5bc33e951c77de6b84..322c14b9061bcd06cb446382ce298918a0cd9efb 100644 (file)
@@ -40,6 +40,13 @@ void GeomAPI_Trsf::setTranslation(const double theDx, const double theDy, const
   MY_TRSF->SetTranslation(gp_Vec(theDx, theDy, theDz));
 }
 
+//=================================================================================================
+void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
+                                  const std::shared_ptr<GeomAPI_Pnt> theEndPoint)
+{
+  MY_TRSF->SetTranslation(theStartPoint->impl<gp_Pnt>(), theEndPoint->impl<gp_Pnt>());
+}
+
 //=================================================================================================
 void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
                                const double theAngle)
index 630c36fddfa6c17c7924a526671db2d1f3e1eef1..ed97f4bebe32880bb307ba33e64cb9d87d86169d 100644 (file)
@@ -13,6 +13,7 @@
 #include <memory>
 
 class GeomAPI_Ax1;
+class GeomAPI_Pnt;
 
 /**\class GeomAPI_Trsf
  * \ingroup DataModel
@@ -43,6 +44,13 @@ class GeomAPI_Trsf : public GeomAPI_Interface
                                      const double theDy,
                                      const double theDz);
 
+  /** \brief Sets a translation transformation using two points.
+   *  \param[in] theStartPoint  Start point of the translation vector.
+   *  \param[in] theEndPoint    End point of the translation vector.
+   */
+  GEOMAPI_EXPORT void setTranslation(const std::shared_ptr<GeomAPI_Pnt> theStartPoint,
+                                     const std::shared_ptr<GeomAPI_Pnt> theEndPoint);
+
   /** \brief Sets a rotation transformation.
    *  \param[in] theAxis  rotation axis.
    *  \param[in] theAngle rotation angle(in degree).
index bd5f6015b6eac47d0b5e6adfc9a189eca27978eb..37ecc1296c4bebf7dcaafa8a500ec9eb11a6ac7e 100644 (file)
@@ -106,4 +106,27 @@ namespace GeomAlgoAPI_ShapeAPI
     }
     return aTranslationAlgo.shape();
   }
+
+  //=========================================================================================================
+  std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeAPI::makeTranslation(
+    std::shared_ptr<GeomAPI_Shape> theSourceShape,
+    std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
+    std::shared_ptr<GeomAPI_Pnt>   theEndPoint) throw (GeomAlgoAPI_Exception)
+  {
+    GeomAlgoAPI_Translation aTranslationAlgo(theSourceShape, theStartPoint, theEndPoint);
+
+    if (!aTranslationAlgo.check()) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+
+    aTranslationAlgo.build();
+
+    if(!aTranslationAlgo.isDone()) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    if (!aTranslationAlgo.checkValid("Translation builder with two points")) {
+      throw GeomAlgoAPI_Exception(aTranslationAlgo.getError());
+    }
+    return aTranslationAlgo.shape();
+  }
 }
index f5769a35e2bff8d91480b91b6b1584af38f6c20e..5e0ef0ba9e7cc24ba745753a849666b485b6c21d 100644 (file)
@@ -59,6 +59,16 @@ public:
                      const double theDx,
                      const double theDy,
                      const double theDz) throw (GeomAlgoAPI_Exception);
+
+  /// Performs a translation from two points.
+  /// \param theSourceShape Shape to be moved.
+  /// \param theStartPoint Movement start point.
+  /// \param theEndPoint Movement end point.
+  /// \return a shape
+  static std::shared_ptr<GeomAPI_Shape> makeTranslation(
+                     std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                     std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
+                     std::shared_ptr<GeomAPI_Pnt>   theEndPoint) throw (GeomAlgoAPI_Exception);
 };
 }
 #endif
index 9fee16ebf9495f790b2979f999034f28c10473f1..574b63d23b74c208f94451a019ee337f19eb3648 100644 (file)
@@ -36,6 +36,17 @@ GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape>
   myDz = theDz;
 }
 
+//=================================================================================================
+GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                                                 std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
+                                                 std::shared_ptr<GeomAPI_Pnt>   theEndPoint)
+{
+  myMethodType = BY_POINTS;
+  mySourceShape = theSourceShape;
+  myStartPoint = theStartPoint;
+  myEndPoint = theEndPoint;
+}
+
 //=================================================================================================
 bool GeomAlgoAPI_Translation::check()
 {
@@ -58,6 +69,21 @@ bool GeomAlgoAPI_Translation::check()
       }
       return true;
     }
+    case BY_POINTS: {
+      if (!myStartPoint) {
+        myError = "Translation builder :: start point is invalid.";
+        return false;
+      }
+      if (!myEndPoint) {
+        myError = "Translation builder :: start point is invalid.";
+        return false;
+      }
+      if (!mySourceShape) {
+        myError = "Translation builder :: source shape is invalid.";
+        return false;
+      }
+      return true;
+    }
     default: {
       myError = "Translation builder :: method not implemented.";
       return false;
@@ -80,6 +106,12 @@ void GeomAlgoAPI_Translation::build()
       aTrsf->SetTranslation(gp_Vec(myDx, myDy, myDz));
       break;
     }
+    case BY_POINTS: {
+      const gp_Pnt& aStartPoint = myStartPoint->impl<gp_Pnt>();
+      const gp_Pnt& aEndPoint = myEndPoint->impl<gp_Pnt>();
+      aTrsf->SetTranslation(aStartPoint, aEndPoint);
+      break;
+    }
     default: {
       myError = "Translation builder :: method not supported";
       return;
index 91fc03c8fd08a9428137dafb0e622d21f7031ec6..62252139b79ec75ab762dac9b371050737c57372 100644 (file)
@@ -47,6 +47,15 @@ public:
                                              double                         theDy,
                                              double                         theDz);
 
+  /// \brief Creates an object which is obtained from current object by moving it along a vector
+  ///        defined by two points.
+  /// \param[in] theSourceShape  the shape to be moved.
+  /// \param[in] theStartPoint   the movement start point.
+  /// \param[in] theEndPoint     the movement end point.
+  GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                                             std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
+                                             std::shared_ptr<GeomAPI_Pnt>   theEndPoint);
+
   /// Checks if data for the translation execution is OK.
   GEOMALGOAPI_EXPORT bool check();
 
@@ -61,6 +70,8 @@ private:
   double myDx; /// Movement dimension on X.
   double myDy; /// Movement dimension on Y.
   double myDz; /// Movement dimension on Z.
+  std::shared_ptr<GeomAPI_Pnt> myStartPoint; /// Movement start point.
+  std::shared_ptr<GeomAPI_Pnt> myEndPoint; /// Movement end point.
 };
 
 #endif
index 0d405fbaf3bb995d63d3fafb98d56e96fe81bfe0..b3933912e5d4529c5040ea924d84f9b412b9c4cb 100644 (file)
@@ -33,3 +33,12 @@ try :
  
 except myExcept, ec:
   print ec.what()
+
+# Perfom a translation with two points.
+try :
+  pnt1 = pnt(10.,0.,0.)
+  pnt2 = pnt(10.,15.,0.)
+  translation3 = shaperpy.makeTranslation(box,pnt1,pnt2)
+except myExcept, ec:
+  print ec.what()