1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Scale.cpp
4 // Created: 23 Jan 2017
5 // Author: Clarisse Genrault (CEA)
7 #include "GeomAlgoAPI_Scale.h"
9 #include <BRepBuilderAPI_Transform.hxx>
10 #include <Precision.hxx>
12 //=================================================================================================
13 GeomAlgoAPI_Scale::GeomAlgoAPI_Scale(std::shared_ptr<GeomAPI_Shape> theSourceShape,
14 std::shared_ptr<GeomAPI_Pnt> theCenterPoint,
15 double theScaleFactor)
17 mySourceShape = theSourceShape;
18 myCenterPoint = theCenterPoint;
19 myScaleFactor = theScaleFactor;
22 //=================================================================================================
23 bool GeomAlgoAPI_Scale::check()
26 myError = "Scale builder :: source shape is invalid.";
30 myError = "Scale builder :: center point is invalid.";
33 if (fabs(myScaleFactor) < Precision::Confusion()) {
34 myError = "Scale builder :: the scale factor is null.";
40 //=================================================================================================
41 void GeomAlgoAPI_Scale::build()
43 const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
44 gp_Trsf* aTrsf = new gp_Trsf();
45 aTrsf->SetScale(aCenterPoint, myScaleFactor);
47 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
49 if(aSourceShape.IsNull()) {
50 myError = "Scale builder :: source shape does not contain any actual shape.";
54 // Transform the shape while copying it.
55 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
57 myError = "Scale builder :: transform initialization failed.";
62 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
64 if(!aBuilder->IsDone()) {
65 myError = "Scale builder :: algorithm failed.";
69 TopoDS_Shape aResult = aBuilder->Shape();
71 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
72 aShape->setImpl(new TopoDS_Shape(aResult));