]> SALOME platform Git repositories - modules/shaper.git/blob - src/GeomAlgoAPI/GeomAlgoAPI_Scale.cpp
Salome HOME
Deleting the option of "Scale" feature from dimensions in X, in Y and in Z.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Scale.cpp
1 // Copyright (C) 2014-201x CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Scale.cpp
4 // Created:     23 Jan 2017
5 // Author:      Clarisse Genrault (CEA)
6
7 #include "GeomAlgoAPI_Scale.h"
8
9 #include <BRepBuilderAPI_Transform.hxx>
10 #include <Precision.hxx>
11
12 //=================================================================================================
13 GeomAlgoAPI_Scale::GeomAlgoAPI_Scale(std::shared_ptr<GeomAPI_Shape> theSourceShape,
14                                      std::shared_ptr<GeomAPI_Pnt>   theCenterPoint,
15                                      double theScaleFactor)
16 {
17   mySourceShape = theSourceShape;
18   myCenterPoint = theCenterPoint;
19   myScaleFactor = theScaleFactor;
20 }
21
22 //=================================================================================================
23 bool GeomAlgoAPI_Scale::check()
24 {
25   if (!mySourceShape) {
26     myError = "Scale builder :: source shape is invalid.";
27     return false;
28   }
29   if (!myCenterPoint) {
30     myError = "Scale builder :: center point is invalid.";
31     return false;
32   }
33   if (fabs(myScaleFactor) < Precision::Confusion()) {
34     myError = "Scale builder :: the scale factor is null.";
35     return false;
36   }
37   return true;
38 }
39
40 //=================================================================================================
41 void GeomAlgoAPI_Scale::build()
42 {
43   const gp_Pnt& aCenterPoint = myCenterPoint->impl<gp_Pnt>();
44   gp_Trsf* aTrsf = new gp_Trsf();
45   aTrsf->SetScale(aCenterPoint, myScaleFactor);
46
47   const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
48
49   if(aSourceShape.IsNull()) {
50     myError = "Scale builder :: source shape does not contain any actual shape.";
51     return;
52   }
53
54   // Transform the shape while copying it.
55   BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
56   if(!aBuilder) {
57     myError = "Scale builder :: transform initialization failed.";
58     return;
59   }
60
61   setImpl(aBuilder);
62   setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
63
64   if(!aBuilder->IsDone()) {
65     myError = "Scale builder :: algorithm failed.";
66     return;
67   }
68
69   TopoDS_Shape aResult = aBuilder->Shape();
70
71   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
72   aShape->setImpl(new TopoDS_Shape(aResult));
73   setShape(aShape);
74   setDone(true);
75 }