Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Box.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_Box.cpp
4 // Created:     10 Mar 2016
5 // Author:      Clarisse Genrault (CEA)
6
7 #include <GeomAlgoAPI_Box.h>
8
9 #include <BRepPrimAPI_MakeBox.hxx>
10 #include <TopoDS_Shape.hxx>
11
12 //=================================================================================================
13 GeomAlgoAPI_Box::GeomAlgoAPI_Box()
14 {
15 }
16
17 //=================================================================================================
18 GeomAlgoAPI_Box::GeomAlgoAPI_Box(const double theDx, const double theDy, const double theDz)
19 {
20   myDx = theDx;
21   myDy = theDy;
22   myDz = theDz;
23 }
24
25 //=================================================================================================
26 bool GeomAlgoAPI_Box::check()
27 {
28   if (myDx < Precision::Confusion()) {
29     myError = "Box builder with dimensions  :: Dx is null.";
30     return false;
31   } else if (myDy < Precision::Confusion()) {
32     myError = "Box builder with dimensions  :: Dy is null.";
33     return false;
34   } else if (myDz < Precision::Confusion()) {
35     myError = "Box builder with dimensions  :: Dz is null.";
36     return false;
37   }
38   return true;
39 }
40
41 //=================================================================================================
42 void GeomAlgoAPI_Box::build()
43 {
44   myCreatedFaces.clear();
45
46   // Construct the box
47   BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(myDx, myDy, myDz);
48   aBoxMaker->Build();
49
50   // Test the algorithm
51   if (!aBoxMaker->IsDone()) {
52     myError = "Box builder with dimensions  :: algorithm failed.";
53     return;
54   }
55
56   TopoDS_Shape aResult = aBoxMaker->Shape();
57   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
58   aShape->setImpl(new TopoDS_Shape(aResult));
59   setShape(aShape);
60
61   // Test on the shapes
62   if (!aShape.get() || aShape->isNull()) {
63     myError = "Box builder with dimensions  :: resulting shape is null.";
64     return;
65   }
66
67   setImpl(aBoxMaker);
68
69   setDone(true);
70 }
71
72 //=================================================================================================
73 void GeomAlgoAPI_Box::prepareNamingFaces()
74 {
75   BRepPrimAPI_MakeBox aBoxMaker = impl<BRepPrimAPI_MakeBox>();
76   std::shared_ptr<GeomAPI_Shape> aShapeFront(new GeomAPI_Shape);
77   aShapeFront->setImpl(new TopoDS_Shape(aBoxMaker.FrontFace()));
78   myCreatedFaces["Front"] = aShapeFront;
79   std::shared_ptr<GeomAPI_Shape> aShapeBack(new GeomAPI_Shape);
80   aShapeBack->setImpl(new TopoDS_Shape(aBoxMaker.BackFace()));
81   myCreatedFaces["Back"] = aShapeBack;
82   std::shared_ptr<GeomAPI_Shape> aShapeTop(new GeomAPI_Shape);
83   aShapeTop->setImpl(new TopoDS_Shape(aBoxMaker.TopFace()));
84   myCreatedFaces["Top"] = aShapeTop;
85   std::shared_ptr<GeomAPI_Shape> aShapeBottom(new GeomAPI_Shape);
86   aShapeBottom->setImpl(new TopoDS_Shape(aBoxMaker.BottomFace()));
87   myCreatedFaces["Bottom"] = aShapeBottom;
88   std::shared_ptr<GeomAPI_Shape> aShapeLeft(new GeomAPI_Shape);
89   aShapeLeft->setImpl(new TopoDS_Shape(aBoxMaker.LeftFace()));
90   myCreatedFaces["Left"] = aShapeLeft;
91   std::shared_ptr<GeomAPI_Shape> aShapeRight(new GeomAPI_Shape);
92   aShapeRight->setImpl(new TopoDS_Shape(aBoxMaker.RightFace()));
93   myCreatedFaces["Right"] = aShapeRight;
94 }