1 // Copyright (C) 2014-2019 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 (fabs(theScaleFactor) < Precision::Confusion()) {
32 myError = "Scale builder :: the scale factor is null.";
36 GeomTrsfPtr aTrsf(new GeomAPI_Trsf);
37 aTrsf->setScale(theCenterPoint, theScaleFactor);
39 build(theSourceShape, aTrsf);
42 //=================================================================================================
43 GeomAlgoAPI_Scale::GeomAlgoAPI_Scale(std::shared_ptr<GeomAPI_Shape> theSourceShape,
44 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
45 double theScaleFactorX,
46 double theScaleFactorY,
47 double theScaleFactorZ)
49 if (fabs(theScaleFactorX) < Precision::Confusion()) {
50 myError = "Scale builder :: the scale factor in X is null.";
53 if (fabs(theScaleFactorY) < Precision::Confusion()) {
54 myError = "Scale builder :: the scale factor in Y is null.";
57 if (fabs(theScaleFactorZ) < Precision::Confusion()) {
58 myError = "Scale builder :: the scale factor in Z is null.";
62 buildByDimensions(theSourceShape, theCenterPoint,
63 theScaleFactorX, theScaleFactorY, theScaleFactorZ);
66 //=================================================================================================
67 void GeomAlgoAPI_Scale::buildByDimensions(std::shared_ptr<GeomAPI_Shape> theSourceShape,
68 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
69 double theScaleFactorX,
70 double theScaleFactorY,
71 double theScaleFactorZ)
73 const gp_Pnt& aCenterPoint = theCenterPoint->impl<gp_Pnt>();
75 // Perform the rotation matrix
76 gp_Mat aMatRot(theScaleFactorX, 0., 0.,
77 0., theScaleFactorY, 0.,
78 0., 0., theScaleFactorZ);
80 // Perform the tranformation
84 aGTrsfP0.SetTranslationPart(gp::Origin().XYZ() - aCenterPoint.XYZ());
85 aGTrsf0P.SetTranslationPart(aCenterPoint.XYZ());
86 aGTrsf.SetVectorialPart(aMatRot);
87 aGTrsf = aGTrsf0P.Multiplied(aGTrsf);
88 aGTrsf = aGTrsf.Multiplied(aGTrsfP0);
90 const TopoDS_Shape& aSourceShape = theSourceShape->impl<TopoDS_Shape>();
92 if(aSourceShape.IsNull()) {
93 myError = "Scale builder :: source shape does not contain any actual shape.";
97 // Transform the shape while copying it.
98 BRepBuilderAPI_GTransform* aBuilder = new BRepBuilderAPI_GTransform(aSourceShape, aGTrsf, true);
100 myError = "Scale builder :: transform initialization failed.";
105 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
107 if(!aBuilder->IsDone()) {
108 myError = "Scale builder :: algorithm failed.";
112 TopoDS_Shape aResult = aBuilder->Shape();
114 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
115 aShape->setImpl(new TopoDS_Shape(aResult));