Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Translation.cpp
index 8f505072fcd30199867814a90207a4089014cff4..868b9213711f5ac3574f85429143bfbec3a18f8d 100644 (file)
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomAlgoAPI_Translation.cpp
-// Created:     8 June 2015
-// Author:      Dmitry Bobylev
+// Copyright (C) 2014-2023  CEA, EDF
+//
+// 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
+//
 
 #include <GeomAlgoAPI_Translation.h>
 
-#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Shape.h>
 
-#include <BRepBuilderAPI_Transform.hxx>
-#include <BRepCheck_Analyzer.hxx>
-#include <gp_Ax1.hxx>
 #include <Precision.hxx>
-#include <TopExp_Explorer.hxx>
 
 //=================================================================================================
 GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
                                                  std::shared_ptr<GeomAPI_Ax1>   theAxis,
                                                  double                         theDistance)
-: myDone(false)
-{
-  build(theSourceShape, theAxis, theDistance);
-}
-
-//=================================================================================================
-void GeomAlgoAPI_Translation::build(std::shared_ptr<GeomAPI_Shape> theSourceShape,
-                                    std::shared_ptr<GeomAPI_Ax1>   theAxis,
-                                    double                         theDistance)
 {
-  if(!theSourceShape || !theAxis) {
-    return;
-  }
-
-  const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
-  const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
-
-  if(aSourceShape.IsNull()) {
-    return;
-  }
-
-  gp_Trsf* aTrsf = new gp_Trsf();
-  aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
-  myTrsf.reset(new GeomAPI_Trsf(aTrsf));
-
-  // Transform the shape with copying it.
-  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) {
+  if (!theAxis) {
+    myError = "Translation builder :: axis is not valid.";
     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());
-  myShape->setImpl(new TopoDS_Shape(aResult));
-}
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setTranslation(theAxis, theDistance);
 
-//=================================================================================================
-const bool GeomAlgoAPI_Translation::isValid() const
-{
-  BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
-  return (aChecker.IsValid() == Standard_True);
+  build(theSourceShape, aTrsf);
 }
 
 //=================================================================================================
-const bool GeomAlgoAPI_Translation::hasVolume() const
+GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                                                 double                         theDx,
+                                                 double                         theDy,
+                                                 double                         theDz)
 {
-  bool hasVolume(false);
-  if(isValid() && (GeomAlgoAPI_ShapeTools::volume(myShape) > Precision::Confusion())) {
-    hasVolume = true;
-  }
-  return hasVolume;
-}
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setTranslation(theDx, theDy, theDz);
 
-//=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Translation::shape() const
-{
-  return myShape;
+  build(theSourceShape, aTrsf);
 }
 
 //=================================================================================================
-std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Translation::mapOfShapes() const
+GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+                                                 std::shared_ptr<GeomAPI_Pnt>   theStartPoint,
+                                                 std::shared_ptr<GeomAPI_Pnt>   theEndPoint)
 {
-  return myMap;
-}
+  if (!theStartPoint) {
+    myError = "Translation builder :: start point is not valid.";
+    return;
+  }
+  if (!theEndPoint) {
+    myError = "Translation builder :: end point is not valid.";
+    return;
+  }
+  if (theStartPoint->distance(theEndPoint) < Precision::Confusion()) {
+    myError = "Translation builder :: start point and end point coincide.";
+    return;
+  }
 
-//=================================================================================================
-std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Translation::makeShape() const
-{
-  return myMkShape;
-}
+  GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+  aTrsf->setTranslation(theStartPoint, theEndPoint);
 
-//=================================================================================================
-std::shared_ptr<GeomAPI_Trsf> GeomAlgoAPI_Translation::transformation() const
-{
-  return myTrsf;
+  build(theSourceShape, aTrsf);
 }