-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+// 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
+//
-// File: GeomAlgoAPI_Translation.cpp
-// Created: 8 June 2015
-// Author: Dmitry Bobylev
+#include <GeomAlgoAPI_Translation.h>
-#include "GeomAlgoAPI_Translation.h"
+#include <GeomAPI_Ax1.h>
+#include <GeomAPI_Shape.h>
-#include <BRepBuilderAPI_Transform.hxx>
-#include <gp_Ax1.hxx>
+#include <Precision.hxx>
//=================================================================================================
GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
std::shared_ptr<GeomAPI_Ax1> theAxis,
double theDistance)
{
- build(theSourceShape, theAxis, theDistance);
+ if (!theAxis) {
+ myError = "Translation builder :: axis is not valid.";
+ return;
+ }
+
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setTranslation(theAxis, theDistance);
+
+ build(theSourceShape, aTrsf);
}
//=================================================================================================
-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;
- }
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setTranslation(theDx, theDy, theDz);
- const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
- const gp_Ax1& anAxis = theAxis->impl<gp_Ax1>();
+ build(theSourceShape, aTrsf);
+}
- if(aSourceShape.IsNull()) {
+//=================================================================================================
+GeomAlgoAPI_Translation::GeomAlgoAPI_Translation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
+ std::shared_ptr<GeomAPI_Pnt> theStartPoint,
+ std::shared_ptr<GeomAPI_Pnt> theEndPoint)
+{
+ if (!theStartPoint) {
+ myError = "Translation builder :: start point is not valid.";
return;
}
-
- gp_Trsf* aTrsf = new gp_Trsf();
- aTrsf->SetTranslation(gp_Vec(anAxis.Direction()) * theDistance);
-
- // Transform the shape with copying it.
- BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
- if(!aBuilder) {
+ if (!theEndPoint) {
+ myError = "Translation builder :: end point is not valid.";
return;
}
- this->setImpl(aBuilder);
- this->setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
-
- if(aBuilder->IsDone() != Standard_True) {
+ if (theStartPoint->distance(theEndPoint) < Precision::Confusion()) {
+ myError = "Translation builder :: start point and end point coincide.";
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);
+ GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
+ aTrsf->setTranslation(theStartPoint, theEndPoint);
+
+ build(theSourceShape, aTrsf);
}