1 // Copyright (C) 2014-2022 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_Scale.h>
22 #include <GeomAPI_Pnt.h>
24 #include <BRepBuilderAPI_GTransform.hxx>
26 //=================================================================================================
27 GeomAlgoAPI_Scale::GeomAlgoAPI_Scale(std::shared_ptr<GeomAPI_Shape> theSourceShape,
28 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
29 double theScaleFactor)
31 if (!theCenterPoint) {
32 myError = "Scale builder :: center point is not valid.";
35 if (fabs(theScaleFactor) < Precision::Confusion()) {
36 myError = "Scale builder :: the scale factor is null.";
40 GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
41 aTrsf->setScale(theCenterPoint, theScaleFactor);
43 build(theSourceShape, aTrsf);
46 //=================================================================================================
47 GeomAlgoAPI_Scale::GeomAlgoAPI_Scale(std::shared_ptr<GeomAPI_Shape> theSourceShape,
48 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
49 double theScaleFactorX,
50 double theScaleFactorY,
51 double theScaleFactorZ)
53 if (!theCenterPoint) {
54 myError = "Scale builder :: center point is not valid.";
57 if (fabs(theScaleFactorX) < Precision::Confusion()) {
58 myError = "Scale builder :: the scale factor in X is null.";
61 if (fabs(theScaleFactorY) < Precision::Confusion()) {
62 myError = "Scale builder :: the scale factor in Y is null.";
65 if (fabs(theScaleFactorZ) < Precision::Confusion()) {
66 myError = "Scale builder :: the scale factor in Z is null.";
70 buildByDimensions(theSourceShape, theCenterPoint,
71 theScaleFactorX, theScaleFactorY, theScaleFactorZ);
74 //=================================================================================================
75 void GeomAlgoAPI_Scale::buildByDimensions(std::shared_ptr<GeomAPI_Shape> theSourceShape,
76 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
77 double theScaleFactorX,
78 double theScaleFactorY,
79 double theScaleFactorZ)
81 if (!theSourceShape) {
82 myError = "Scale builder :: source shape is not valid.";
86 const gp_Pnt& aCenterPoint = theCenterPoint->impl<gp_Pnt>();
88 // Perform the rotation matrix
89 gp_Mat aMatRot(theScaleFactorX, 0., 0.,
90 0., theScaleFactorY, 0.,
91 0., 0., theScaleFactorZ);
93 // Perform the tranformation
97 aGTrsfP0.SetTranslationPart(gp::Origin().XYZ() - aCenterPoint.XYZ());
98 aGTrsf0P.SetTranslationPart(aCenterPoint.XYZ());
99 aGTrsf.SetVectorialPart(aMatRot);
100 aGTrsf = aGTrsf0P.Multiplied(aGTrsf);
101 aGTrsf = aGTrsf.Multiplied(aGTrsfP0);
103 const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
105 if(aSourceShape.IsNull()) {
106 myError = "Scale builder :: source shape does not contain any actual shape.";
110 // Transform the shape while copying it.
111 BRepBuilderAPI_GTransform* aBuilder = new BRepBuilderAPI_GTransform(aSourceShape, aGTrsf, true);
113 myError = "Scale builder :: transform initialization failed.";
118 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
120 if(!aBuilder->IsDone()) {
121 myError = "Scale builder :: algorithm failed.";
125 TopoDS_Shape aResult = aBuilder->Shape();
127 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
128 aShape->setImpl(new TopoDS_Shape(aResult));