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)
31 myFirstPoint = theFirstPoint;
32 mySecondPoint = theSecondPoint;
33 myMethodType = MethodType::BOX_POINTS;
36 //=================================================================================================
37 bool GeomAlgoAPI_Box::check()
39 if (myMethodType == MethodType::BOX_DIM) {
40 if (myDx < Precision::Confusion()) {
41 myError = "Box builder with dimensions :: Dx is null.";
43 } else if (myDy < Precision::Confusion()) {
44 myError = "Box builder with dimensions :: Dy is null.";
46 } else if (myDz < Precision::Confusion()) {
47 myError = "Box builder with dimensions :: Dz is null.";
50 } else if (myMethodType == MethodType::BOX_POINTS) {
51 if (!myFirstPoint.get()) {
52 myError = "Box builder with points :: the first point is not a correct";
55 if (!mySecondPoint.get()) {
56 myError = "Box builder with points :: the second point is not a correct";
59 if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) {
60 myError = "Box builder with points :: the distance between the two points is null.";
63 double aDiffX = myFirstPoint->x() - mySecondPoint->x();
64 double aDiffY = myFirstPoint->y() - mySecondPoint->y();
65 double aDiffZ = myFirstPoint->z() - mySecondPoint->z();
66 if (fabs(aDiffX) < Precision::Confusion() ||
67 fabs(aDiffY) < Precision::Confusion() ||
68 fabs(aDiffZ) < Precision::Confusion()) {
69 myError = "The points belong both to one of the OXY, OYZ or OZX planes";
73 myError = "Box builder :: Method not implemented.";
79 //=================================================================================================
80 void GeomAlgoAPI_Box::build()
82 if (myMethodType == MethodType::BOX_DIM) {
83 buildWithDimensions();
84 } else if (myMethodType == MethodType::BOX_POINTS) {
87 myError = "Box builder :: Method not implemented.";
92 //=================================================================================================
93 void GeomAlgoAPI_Box::buildWithDimensions()
95 myCreatedFaces.clear();
98 BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(myDx, myDy, myDz);
101 // Test the algorithm
102 if (!aBoxMaker->IsDone()) {
103 myError = "Box builder with dimensions :: algorithm failed.";
107 TopoDS_Shape aResult = aBoxMaker->Shape();
108 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
109 aShape->setImpl(new TopoDS_Shape(aResult));
112 // Test on the shapes
113 if (!aShape.get() || aShape->isNull()) {
114 myError = "Box builder with dimensions :: resulting shape is null.";
124 //=================================================================================================
125 void GeomAlgoAPI_Box::buildWithPoints()
127 myCreatedFaces.clear();
129 const gp_Pnt& aFirstPoint = myFirstPoint->impl<gp_Pnt>();
130 const gp_Pnt& aSecondPoint = mySecondPoint->impl<gp_Pnt>();
133 BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(aFirstPoint, aSecondPoint);
136 // Test the algorithm
137 if(!aBoxMaker->IsDone()) {
138 myError = "Box builder with two points :: algorithm failed.";
142 TopoDS_Shape aResult = aBoxMaker->Shape();
144 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
145 aShape->setImpl(new TopoDS_Shape(aResult));
148 // Tests on the shape
149 if (!aShape.get() || aShape->isNull()) {
150 myError = "Box builder with two points :: resulting shape is null.";
159 //=================================================================================================
160 void GeomAlgoAPI_Box::prepareNamingFaces()
162 BRepPrimAPI_MakeBox aBoxMaker = impl<BRepPrimAPI_MakeBox>();
163 std::shared_ptr<GeomAPI_Shape> aShapeFront(new GeomAPI_Shape);
164 aShapeFront->setImpl(new TopoDS_Shape(aBoxMaker.FrontFace()));
165 myCreatedFaces["Front"] = aShapeFront;
166 std::shared_ptr<GeomAPI_Shape> aShapeBack(new GeomAPI_Shape);
167 aShapeBack->setImpl(new TopoDS_Shape(aBoxMaker.BackFace()));
168 myCreatedFaces["Back"] = aShapeBack;
169 std::shared_ptr<GeomAPI_Shape> aShapeTop(new GeomAPI_Shape);
170 aShapeTop->setImpl(new TopoDS_Shape(aBoxMaker.TopFace()));
171 myCreatedFaces["Top"] = aShapeTop;
172 std::shared_ptr<GeomAPI_Shape> aShapeBottom(new GeomAPI_Shape);
173 aShapeBottom->setImpl(new TopoDS_Shape(aBoxMaker.BottomFace()));
174 myCreatedFaces["Bottom"] = aShapeBottom;
175 std::shared_ptr<GeomAPI_Shape> aShapeLeft(new GeomAPI_Shape);
176 aShapeLeft->setImpl(new TopoDS_Shape(aBoxMaker.LeftFace()));
177 myCreatedFaces["Left"] = aShapeLeft;
178 std::shared_ptr<GeomAPI_Shape> aShapeRight(new GeomAPI_Shape);
179 aShapeRight->setImpl(new TopoDS_Shape(aBoxMaker.RightFace()));
180 myCreatedFaces["Right"] = aShapeRight;