Salome HOME
Renaming the direct API high level.
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_BoxPoints.cpp
1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
2
3 // File:        GeomAlgoAPI_BoxPoints.cpp
4 // Created:     17 Mar 2016
5 // Author:      Clarisse Genrault (CEA)
6
7 #include <GeomAlgoAPI_BoxPoints.h>
8
9 #include <BRepPrimAPI_MakeBox.hxx>
10 #include <TopoDS_Shape.hxx>
11
12 #include <iostream>
13
14 //=================================================================================================
15 GeomAlgoAPI_BoxPoints::GeomAlgoAPI_BoxPoints(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
16                                              std::shared_ptr<GeomAPI_Pnt> theSecondPoint)
17 :GeomAlgoAPI_Box()
18 {
19   myFirstPoint = theFirstPoint;
20   mySecondPoint = theSecondPoint;
21 }
22
23 //=================================================================================================
24 bool GeomAlgoAPI_BoxPoints::check()
25 {
26   // The distance between myFirstPoint and mySecondPoint must not be null.
27   if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion())
28     return false;
29   return true;
30 }
31
32 //=================================================================================================
33 void GeomAlgoAPI_BoxPoints::build()
34 {
35   myCreatedFaces.clear();
36   
37   const gp_Pnt& aFirstPoint = myFirstPoint->impl<gp_Pnt>();
38   const gp_Pnt& aSecondPoint = mySecondPoint->impl<gp_Pnt>();
39
40   // Construct the box
41   BRepPrimAPI_MakeBox *aBoxMaker = new  BRepPrimAPI_MakeBox(aFirstPoint, aSecondPoint);
42   aBoxMaker->Build();
43   
44   // Test the algorithm
45   if(!aBoxMaker->IsDone()) {
46     myError = "Box builder with two points  :: algorithm failed.";
47     return;
48   }
49     
50   TopoDS_Shape aResult = aBoxMaker->Shape();
51   
52   std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
53   aShape->setImpl(new TopoDS_Shape(aResult));
54   setShape(aShape);
55   
56   // Tests on the shape
57   if (!aShape.get() || aShape->isNull()) {
58     myError = "Box builder with two points  :: resulting shape is null.";
59     return;
60   }
61   
62   setImpl(aBoxMaker);
63   
64   setDone(true);
65 }