1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Box.cpp
4 // Created: 10 Mar 2016
5 // Author: Clarisse Genrault (CEA)
7 #include <GeomAlgoAPI_Box.h>
9 #include <BRepPrimAPI_MakeBox.hxx>
10 #include <TopoDS_Shape.hxx>
12 //=================================================================================================
13 GeomAlgoAPI_Box::GeomAlgoAPI_Box()
17 //=================================================================================================
18 GeomAlgoAPI_Box::GeomAlgoAPI_Box(const double theDx, const double theDy, const double theDz)
23 myMethodType = MethodType::BOX_DIM;
26 //=================================================================================================
27 GeomAlgoAPI_Box::GeomAlgoAPI_Box(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
28 std::shared_ptr<GeomAPI_Pnt> theSecondPoint)
30 myFirstPoint = theFirstPoint;
31 mySecondPoint = theSecondPoint;
32 myMethodType = MethodType::BOX_POINTS;
35 //=================================================================================================
36 bool GeomAlgoAPI_Box::check()
38 if (myMethodType == MethodType::BOX_DIM) {
39 if (myDx < Precision::Confusion()) {
40 myError = "Box builder with dimensions :: Dx is null.";
42 } else if (myDy < Precision::Confusion()) {
43 myError = "Box builder with dimensions :: Dy is null.";
45 } else if (myDz < Precision::Confusion()) {
46 myError = "Box builder with dimensions :: Dz is null.";
49 } else if (myMethodType == MethodType::BOX_POINTS) {
50 if (!myFirstPoint.get()) {
51 myError = "Box builder with points :: the first point is not a correct";
54 if (!mySecondPoint.get()) {
55 myError = "Box builder with points :: the second point is not a correct";
58 if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) {
59 myError = "Box builder with points :: the distance between the two points is null.";
62 double aDiffX = myFirstPoint->x() - mySecondPoint->x();
63 double aDiffY = myFirstPoint->y() - mySecondPoint->y();
64 double aDiffZ = myFirstPoint->z() - mySecondPoint->z();
65 if (fabs(aDiffX) < Precision::Confusion() ||
66 fabs(aDiffY) < Precision::Confusion() ||
67 fabs(aDiffZ) < Precision::Confusion()) {
68 myError = "The points belong both to one of the OXY, OYZ or OZX planes";
72 myError = "Box builder :: Method not implemented.";
78 //=================================================================================================
79 void GeomAlgoAPI_Box::build()
81 if (myMethodType == MethodType::BOX_DIM) {
82 buildWithDimensions();
83 } else if (myMethodType == MethodType::BOX_POINTS) {
86 myError = "Box builder :: Method not implemented.";
91 //=================================================================================================
92 void GeomAlgoAPI_Box::buildWithDimensions()
94 myCreatedFaces.clear();
97 BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(myDx, myDy, myDz);
100 // Test the algorithm
101 if (!aBoxMaker->IsDone()) {
102 myError = "Box builder with dimensions :: algorithm failed.";
106 TopoDS_Shape aResult = aBoxMaker->Shape();
107 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
108 aShape->setImpl(new TopoDS_Shape(aResult));
111 // Test on the shapes
112 if (!aShape.get() || aShape->isNull()) {
113 myError = "Box builder with dimensions :: resulting shape is null.";
122 //=================================================================================================
123 void GeomAlgoAPI_Box::buildWithPoints()
125 myCreatedFaces.clear();
127 const gp_Pnt& aFirstPoint = myFirstPoint->impl<gp_Pnt>();
128 const gp_Pnt& aSecondPoint = mySecondPoint->impl<gp_Pnt>();
131 BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(aFirstPoint, aSecondPoint);
134 // Test the algorithm
135 if(!aBoxMaker->IsDone()) {
136 myError = "Box builder with two points :: algorithm failed.";
140 TopoDS_Shape aResult = aBoxMaker->Shape();
142 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
143 aShape->setImpl(new TopoDS_Shape(aResult));
146 // Tests on the shape
147 if (!aShape.get() || aShape->isNull()) {
148 myError = "Box builder with two points :: resulting shape is null.";
157 //=================================================================================================
158 void GeomAlgoAPI_Box::prepareNamingFaces()
160 BRepPrimAPI_MakeBox aBoxMaker = impl<BRepPrimAPI_MakeBox>();
161 std::shared_ptr<GeomAPI_Shape> aShapeFront(new GeomAPI_Shape);
162 aShapeFront->setImpl(new TopoDS_Shape(aBoxMaker.FrontFace()));
163 myCreatedFaces["Front"] = aShapeFront;
164 std::shared_ptr<GeomAPI_Shape> aShapeBack(new GeomAPI_Shape);
165 aShapeBack->setImpl(new TopoDS_Shape(aBoxMaker.BackFace()));
166 myCreatedFaces["Back"] = aShapeBack;
167 std::shared_ptr<GeomAPI_Shape> aShapeTop(new GeomAPI_Shape);
168 aShapeTop->setImpl(new TopoDS_Shape(aBoxMaker.TopFace()));
169 myCreatedFaces["Top"] = aShapeTop;
170 std::shared_ptr<GeomAPI_Shape> aShapeBottom(new GeomAPI_Shape);
171 aShapeBottom->setImpl(new TopoDS_Shape(aBoxMaker.BottomFace()));
172 myCreatedFaces["Bottom"] = aShapeBottom;
173 std::shared_ptr<GeomAPI_Shape> aShapeLeft(new GeomAPI_Shape);
174 aShapeLeft->setImpl(new TopoDS_Shape(aBoxMaker.LeftFace()));
175 myCreatedFaces["Left"] = aShapeLeft;
176 std::shared_ptr<GeomAPI_Shape> aShapeRight(new GeomAPI_Shape);
177 aShapeRight->setImpl(new TopoDS_Shape(aBoxMaker.RightFace()));
178 myCreatedFaces["Right"] = aShapeRight;