1 // Copyright (C) 2014-2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <GeomAlgoAPI_Rotation.h>
22 #include <GeomAPI_Ax1.h>
23 #include <GeomAPI_Pnt.h>
24 #include <GeomAPI_XYZ.h>
26 #include <Precision.hxx>
28 // Verify points are applicable to build the rotation transformation
29 static bool checkPoints(GeomPointPtr theCenterPoint,
30 GeomPointPtr theStartPoint,
31 GeomPointPtr theEndPoint,
32 std::string& theError);
34 //=================================================================================================
35 GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
36 std::shared_ptr<GeomAPI_Ax1> theAxis,
40 myError = "Rotation builder :: axis is not valid.";
44 GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
45 aTrsf->setRotation(theAxis, theAngle);
47 build(theSourceShape, aTrsf);
51 //=================================================================================================
52 GeomAlgoAPI_Rotation::GeomAlgoAPI_Rotation(std::shared_ptr<GeomAPI_Shape> theSourceShape,
53 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
54 std::shared_ptr<GeomAPI_Pnt> theStartPoint,
55 std::shared_ptr<GeomAPI_Pnt> theEndPoint)
57 if (!checkPoints(theCenterPoint, theStartPoint, theEndPoint, myError))
60 GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
61 aTrsf->setRotation(theCenterPoint, theStartPoint, theEndPoint);
63 build(theSourceShape, aTrsf);
66 //=================================================================================================
67 bool checkPoints(GeomPointPtr theCenterPoint,
68 GeomPointPtr theStartPoint,
69 GeomPointPtr theEndPoint,
70 std::string& theError)
72 if (!theCenterPoint) {
73 theError = "Rotation builder :: center point is not valid.";
77 theError = "Rotation builder :: start point is not valid.";
81 theError = "Rotation builder :: end point is not valid.";
84 if (theCenterPoint->distance(theStartPoint) < Precision::Confusion()) {
85 theError = "Rotation builder :: center point and start point coincide.";
88 if (theCenterPoint->distance(theEndPoint) < Precision::Confusion()) {
89 theError = "Rotation builder :: center point and end point coincide.";
92 if (theStartPoint->distance(theEndPoint) < Precision::Confusion()) {
93 theError = "Rotation builder :: start point and end point coincide.";
96 std::shared_ptr<GeomAPI_XYZ> aCenterPointXYZ = theCenterPoint->xyz();
97 std::shared_ptr<GeomAPI_XYZ> aStartPointXYZ = theStartPoint->xyz();
98 std::shared_ptr<GeomAPI_XYZ> aEndPointXYZ = theEndPoint->xyz();
99 std::shared_ptr<GeomAPI_XYZ> vectCenterPointStartPoint =
100 aStartPointXYZ->decreased(aCenterPointXYZ);
101 std::shared_ptr<GeomAPI_XYZ> vectCenterPointEndPoint =
102 aEndPointXYZ->decreased(aCenterPointXYZ);
103 std::shared_ptr<GeomAPI_XYZ> crossProduct =
104 vectCenterPointStartPoint->cross(vectCenterPointEndPoint);
106 if (crossProduct->squareModulus() < Precision::SquareConfusion()) {
107 theError = "Rotation builder :: center point, start point and end point are on a line.";