]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Translation and Rotation code clean up
authordbv <dbv@opencascade.com>
Tue, 8 Sep 2015 15:28:48 +0000 (18:28 +0300)
committerdbv <dbv@opencascade.com>
Tue, 8 Sep 2015 15:29:06 +0000 (18:29 +0300)
src/FeaturesPlugin/FeaturesPlugin_Rotation.cpp
src/FeaturesPlugin/FeaturesPlugin_Translation.cpp
src/GeomAPI/GeomAPI_Trsf.cpp
src/GeomAPI/GeomAPI_Trsf.h
src/GeomAlgoAPI/GeomAlgoAPI_Rotation.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Rotation.h
src/GeomAlgoAPI/GeomAlgoAPI_Translation.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Translation.h

index e71fabcfa311a734ce8b5f76d4a2d2758ccf2d43..422a4d3347c3648a1e55552c0b0ee9251f7aecc7 100755 (executable)
@@ -78,32 +78,35 @@ void FeaturesPlugin_Rotation::execute()
         anObjectsIt++, aContext++) {
     std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
     bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
-    GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, anAxis, anAngle, isPart);
-
-    // Checking that the algorithm worked properly.
-    if(!aRotationAlgo.isDone()) {
-      static const std::string aFeatureError = "Rotation algorithm failed";
-      setError(aFeatureError);
-      break;
-    }
-    if(aRotationAlgo.shape()->isNull()) {
-      static const std::string aShapeError = "Resulting shape is Null";
-      setError(aShapeError);
-      break;
-    }
-    if(!aRotationAlgo.isValid()) {
-      std::string aFeatureError = "Warning: resulting shape is not valid";
-      setError(aFeatureError);
-      break;
-    }
 
     // Setting result.
     if (isPart) {
+      std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
+      aTrsf->setRotation(anAxis, anAngle);
       ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
       ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
-      aResultPart->setTrsf(*aContext, aRotationAlgo.transformation());
+      aResultPart->setTrsf(*aContext, aTrsf);
       setResult(aResultPart);
     } else {
+      GeomAlgoAPI_Rotation aRotationAlgo(aBaseShape, anAxis, anAngle);
+
+      // Checking that the algorithm worked properly.
+      if(!aRotationAlgo.isDone()) {
+        static const std::string aFeatureError = "Rotation algorithm failed";
+        setError(aFeatureError);
+        break;
+      }
+      if(aRotationAlgo.shape()->isNull()) {
+        static const std::string aShapeError = "Resulting shape is Null";
+        setError(aShapeError);
+        break;
+      }
+      if(!aRotationAlgo.isValid()) {
+        std::string aFeatureError = "Warning: resulting shape is not valid";
+        setError(aFeatureError);
+        break;
+      }
+
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
       LoadNamingDS(aRotationAlgo, aResultBody, aBaseShape);
       setResult(aResultBody, aResultIndex);
index d1ff455a2406fb7ce9d614ec5dbf027b293c41c0..423ea9459aed423d9865c008c595aa6452a20e6d 100644 (file)
@@ -78,32 +78,35 @@ void FeaturesPlugin_Translation::execute()
         anObjectsIt++, aContext++) {
     std::shared_ptr<GeomAPI_Shape> aBaseShape = *anObjectsIt;
     bool isPart = (*aContext)->groupName() == ModelAPI_ResultPart::group();
-    GeomAlgoAPI_Translation aMovementAlgo(aBaseShape, anAxis, aDistance, isPart);
-
-    // Checking that the algorithm worked properly.
-    if(!aMovementAlgo.isDone()) {
-      static const std::string aFeatureError = "Movement algorithm failed";
-      setError(aFeatureError);
-      break;
-    }
-    if(aMovementAlgo.shape()->isNull()) {
-      static const std::string aShapeError = "Resulting shape is Null";
-      setError(aShapeError);
-      break;
-    }
-    if(!aMovementAlgo.isValid()) {
-      std::string aFeatureError = "Warning: resulting shape is not valid";
-      setError(aFeatureError);
-      break;
-    }
 
     // Setting result.
     if (isPart) {
+      std::shared_ptr<GeomAPI_Trsf> aTrsf(new GeomAPI_Trsf());
+      aTrsf->setTranslation(anAxis, aDistance);
       ResultPartPtr anOrigin = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aContext);
       ResultPartPtr aResultPart = document()->copyPart(anOrigin, data(), aResultIndex);
-      aResultPart->setTrsf(*aContext, aMovementAlgo.transformation());
+      aResultPart->setTrsf(*aContext, aTrsf);
       setResult(aResultPart);
     } else {
+      GeomAlgoAPI_Translation aMovementAlgo(aBaseShape, anAxis, aDistance);
+
+      // Checking that the algorithm worked properly.
+      if(!aMovementAlgo.isDone()) {
+        static const std::string aFeatureError = "Movement algorithm failed";
+        setError(aFeatureError);
+        break;
+      }
+      if(aMovementAlgo.shape()->isNull()) {
+        static const std::string aShapeError = "Resulting shape is Null";
+        setError(aShapeError);
+        break;
+      }
+      if(!aMovementAlgo.isValid()) {
+        std::string aFeatureError = "Warning: resulting shape is not valid";
+        setError(aFeatureError);
+        break;
+      }
+
       ResultBodyPtr aResultBody = document()->createBody(data(), aResultIndex);
       LoadNamingDS(aMovementAlgo, aResultBody, aBaseShape);
       setResult(aResultBody, aResultIndex);
index 7a3c8c17800cc50c88910b2e7feaa22d0f76706f..f0775141ceb40c9c22919d747ace9f04b977b31f 100644 (file)
@@ -6,14 +6,35 @@
 
 #include<GeomAPI_Trsf.h>
 
+#include <GeomAPI_Ax1.h>
+
+#include <gp_Ax1.hxx>
 #include<gp_Trsf.hxx>
 
+#define MY_TRSF implPtr<gp_Trsf>()
+
+//=================================================================================================
 GeomAPI_Trsf::GeomAPI_Trsf()
-    : GeomAPI_Interface()
+: GeomAPI_Interface(new gp_Trsf())
 {
 }
 
+//=================================================================================================
 GeomAPI_Trsf::GeomAPI_Trsf(void* theTrsf)
-    : GeomAPI_Interface(theTrsf)
+: GeomAPI_Interface(theTrsf)
+{
+}
+
+//=================================================================================================
+void GeomAPI_Trsf::setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+                                  const double theDistance)
+{
+  MY_TRSF->SetTranslation(gp_Vec(theAxis->impl<gp_Ax1>().Direction()) * theDistance);
+}
+
+//=================================================================================================
+void GeomAPI_Trsf::setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+                               const double theAngle)
 {
+  MY_TRSF->SetRotation(theAxis->impl<gp_Ax1>(), theAngle / 180.0 * M_PI);
 }
index ebb7871f9e55121a679c80da20e55b5dadfb194f..d5f3ffd5b4a4dcb07c43ea4036bd489ed32d7f40 100644 (file)
@@ -10,6 +10,8 @@
 #include <GeomAPI_Interface.h>
 #include <memory>
 
+class GeomAPI_Ax1;
+
 /**\class GeomAPI_Trsf
  * \ingroup DataModel
  * \brief Keep the transformation matrix coefficients
@@ -22,6 +24,20 @@ class GeomAPI_Trsf : public GeomAPI_Interface
   GEOMAPI_EXPORT GeomAPI_Trsf();
   /// Takes the pointer to existing transformation
   GEOMAPI_EXPORT GeomAPI_Trsf(void* theTrsf);
+
+  /** \brief Sets a translation transformation.
+   *  \param[in] theAxis     translation axis.
+   *  \param[in] theDistance translation distance.
+   */
+  GEOMAPI_EXPORT void setTranslation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+                                     const double theDistance);
+
+  /** \brief Sets a rotation transformation.
+   *  \param[in] theAxis  rotation axis.
+   *  \param[in] theAngle rotation angle(in degree).
+   */
+  GEOMAPI_EXPORT void setRotation(const std::shared_ptr<GeomAPI_Ax1> theAxis,
+                                  const double theAngle);
 };
 
 #endif
index 0ecd76ecc0c14b9c3172600eef44a8913540b805..62e687d98dc9e5aea6e277d23ddd2836930d52df 100644 (file)
 //=================================================================================================
 GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                            std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                           double                         theAngle,
-                                           bool theSimpleTransform)
+                                           double                         theAngle)
 : myDone(false)
 {
-  build(theSourceShape, theAxis, theAngle, theSimpleTransform);
+  build(theSourceShape, theAxis, theAngle);
 }
 
 //=================================================================================================
 void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                  std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                 double                         theAngle,
-                                 bool theSimpleTransform)
+                                 double                         theAngle)
 {
   if(!theSourceShape || !theAxis) {
     return;
@@ -40,38 +38,30 @@ void GeomAlgoAPI_Rotation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
     return;
   }
 
-  gp_Trsf aTrsf;
-  aTrsf.SetRotation(anAxis, theAngle / 180.0 * M_PI);
+  gp_Trsf* aTrsf = new gp_Trsf();
+  aTrsf->SetRotation(anAxis, theAngle / 180.0 * M_PI);
+  myTrsf.reset(new GeomAPI_Trsf(aTrsf));
 
-  TopoDS_Shape aResult;
   // Transform the shape with copying it.
-  if (theSimpleTransform) {
-    TopLoc_Location aDelta(aTrsf);
-    aResult = aSourceShape.Moved(aDelta);
-    //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
-    myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
-    myDone = true; // is OK for sure
-  } else {
-    BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
-    if(!aBuilder) {
-      return;
-    }
-    myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
-
-    myDone = aBuilder->IsDone() == Standard_True;
-
-    if(!myDone) {
-      return;
-    }
-
-    aResult = aBuilder->Shape();
-    // Fill data map to keep correct orientation of sub-shapes.
-    myMap.reset(new GeomAPI_DataMapOfShapeShape());
-    for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
-      std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
-      aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
-      myMap->bind(aCurrentShape, aCurrentShape);
-    }
+  BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
+  if(!aBuilder) {
+    return;
+  }
+  myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
+
+  myDone = aBuilder->IsDone() == Standard_True;
+
+  if(!myDone) {
+    return;
+  }
+
+  TopoDS_Shape aResult = aBuilder->Shape();
+  // Fill data map to keep correct orientation of sub-shapes.
+  myMap.reset(new GeomAPI_DataMapOfShapeShape());
+  for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
+    std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+    aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
+    myMap->bind(aCurrentShape, aCurrentShape);
   }
 
   myShape.reset(new GeomAPI_Shape());
index bf8e035796a9f271de2c297ab68523358db58417..ef56c33eafc67e79573d515ea50d601c27eb87d6 100644 (file)
@@ -25,12 +25,10 @@ public:
    *  \param[in] theSourceShape  a shape to be rotated.
    *  \param[in] theAxis         rotation axis.
    *  \param[in] theAngle        rotation angle(in degree).
-   *  \param[in] theSimpleTransform makes just transformation of shape without changing of topology or geometry
    */
   GEOMALGOAPI_EXPORT GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                           std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                          double                         theAngle,
-                                          bool theSimpleTransform = false);
+                                          double                         theAngle);
 
   /// \return true if algorithm succeed.
   GEOMALGOAPI_EXPORT const bool isDone() const
@@ -58,8 +56,7 @@ private:
   /// Builds resulting shape.
   void build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
              std::shared_ptr<GeomAPI_Ax1>   theAxis,
-             double                         theAngle,
-             bool theSimpleTransform);
+             double                         theAngle);
 
 private:
   /// Fields.
index b9cc3b690af73a93ab7cd162392a98684f574dc5..8f505072fcd30199867814a90207a4089014cff4 100644 (file)
 
 //=================================================================================================
 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
-                                           std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                           double                         theDistance,
-                                           bool theSimpleTransform)
+                                                 std::shared_ptr<GeomAPI_Ax1>   theAxis,
+                                                 double                         theDistance)
 : myDone(false)
 {
-  build(theSourceShape, theAxis, theDistance, theSimpleTransform);
+  build(theSourceShape, theAxis, theDistance);
 }
 
 //=================================================================================================
 void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
-                                 std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                 double                         theDistance,
-                                 bool theSimpleTransform)
+                                    std::shared_ptr<GeomAPI_Ax1>   theAxis,
+                                    double                         theDistance)
 {
   if(!theSourceShape || !theAxis) {
     return;
@@ -41,39 +39,30 @@ void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShap
     return;
   }
 
-  gp_Trsf aTrsf;
-  aTrsf.SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
+  gp_Trsf* aTrsf = new gp_Trsf();
+  aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
+  myTrsf.reset(new GeomAPI_Trsf(aTrsf));
 
-  TopoDS_Shape aResult;
   // Transform the shape with copying it.
-  if (theSimpleTransform) {
-    TopLoc_Location aDelta(aTrsf);
-    aResult = aSourceShape.Moved(aDelta);
-    // store the accumulated information about the result and this delta
-    //myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf * aSourceShape.Location().Transformation())));
-    myTrsf = std::shared_ptr<GeomAPI_Trsf>(new GeomAPI_Trsf(new gp_Trsf(aTrsf)));
-    myDone = true; // is OK for sure
-  } else {
-    BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, aTrsf, true);
-    if(!aBuilder) {
-      return;
-    }
-    myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
-
-    myDone = aBuilder->IsDone() == Standard_True;
-
-    if(!myDone) {
-      return;
-    }
-
-    aResult = aBuilder->Shape();
-    // Fill data map to keep correct orientation of sub-shapes.
-    myMap.reset(new GeomAPI_DataMapOfShapeShape());
-    for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
-      std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
-      aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
-      myMap->bind(aCurrentShape, aCurrentShape);
-    }
+  BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
+  if(!aBuilder) {
+    return;
+  }
+  myMkShape.reset(new GeomAlgoAPI_MakeShape(aBuilder));
+
+  myDone = aBuilder->IsDone() == Standard_True;
+
+  if(!myDone) {
+    return;
+  }
+
+  TopoDS_Shape aResult = aBuilder->Shape();
+  // Fill data map to keep correct orientation of sub-shapes.
+  myMap.reset(new GeomAPI_DataMapOfShapeShape());
+  for(TopExp_Explorer anExp(aResult, TopAbs_FACE); anExp.More(); anExp.Next()) {
+    std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
+    aCurrentShape->setImpl(new TopoDS_Shape(anExp.Current()));
+    myMap->bind(aCurrentShape, aCurrentShape);
   }
 
   myShape.reset(new GeomAPI_Shape());
index 95f9c55f7801e1a1767c4753fc828d9000bc55fb..e8f3d8147fc0149fadcf688494ae738381048387 100644 (file)
@@ -25,12 +25,10 @@ public:
    *  \param[in] theSourceShape  a shape to be moved.
    *  \param[in] theAxis         movement axis.
    *  \param[in] theDistance     movement distance.
-   *  \param[in] theSimpleTransform makes just transformation of shape without changing of topology or geometry
    */
   GEOMALGOAPI_EXPORT GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
-                                          std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                          double                         theDistance,
-                                          bool theSimpleTransform = false);
+                                             std::shared_ptr<GeomAPI_Ax1>   theAxis,
+                                             double                         theDistance);
 
   /// \return true if algorithm succeed.
   GEOMALGOAPI_EXPORT const bool isDone() const
@@ -58,8 +56,7 @@ private:
   /// Builds resulting shape.
   void build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
              std::shared_ptr<GeomAPI_Ax1>   theAxis,
-             double                         theDistance,
-             bool theSimpleTransform);
+             double                         theDistance);
 
 private:
   /// Fields.
@@ -67,7 +64,7 @@ private:
   std::shared_ptr<GeomAPI_Shape> myShape;
   std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
   std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
-  std::shared_ptr<GeomAPI_Trsf> myTrsf; ///< transformation of the shape in case theSimpleTransform
+  std::shared_ptr<GeomAPI_Trsf> myTrsf;
 };
 
 #endif