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 or negative.";
42 } else if (myDy < Precision::Confusion()) {
43 myError = "Box builder with dimensions :: Dy is null or negative.";
45 } else if (myDz < Precision::Confusion()) {
46 myError = "Box builder with dimensions :: Dz is null or negative.";
49 } else if (myMethodType == MethodType::BOX_POINTS) {
50 if (!myFirstPoint.get()) {
51 myError = "Box builder with points :: the first point is not valid.";
54 if (!mySecondPoint.get()) {
55 myError = "Box builder with points :: the second point is not valid.";
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()) {
69 "Box builder with points :: 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.";
123 //=================================================================================================
124 void GeomAlgoAPI_Box::buildWithPoints()
126 myCreatedFaces.clear();
128 const gp_Pnt& aFirstPoint = myFirstPoint->impl<gp_Pnt>();
129 const gp_Pnt& aSecondPoint = mySecondPoint->impl<gp_Pnt>();
132 BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(aFirstPoint, aSecondPoint);
135 // Test the algorithm
136 if(!aBoxMaker->IsDone()) {
137 myError = "Box builder with two points :: algorithm failed.";
141 TopoDS_Shape aResult = aBoxMaker->Shape();
143 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
144 aShape->setImpl(new TopoDS_Shape(aResult));
147 // Tests on the shape
148 if (!aShape.get() || aShape->isNull()) {
149 myError = "Box builder with two points :: resulting shape is null.";
158 //=================================================================================================
159 void GeomAlgoAPI_Box::prepareNamingFaces()
161 BRepPrimAPI_MakeBox aBoxMaker = impl<BRepPrimAPI_MakeBox>();
162 std::shared_ptr<GeomAPI_Shape> aShapeFront(new GeomAPI_Shape);
163 aShapeFront->setImpl(new TopoDS_Shape(aBoxMaker.FrontFace()));
164 myCreatedFaces["Front"] = aShapeFront;
165 std::shared_ptr<GeomAPI_Shape> aShapeBack(new GeomAPI_Shape);
166 aShapeBack->setImpl(new TopoDS_Shape(aBoxMaker.BackFace()));
167 myCreatedFaces["Back"] = aShapeBack;
168 std::shared_ptr<GeomAPI_Shape> aShapeTop(new GeomAPI_Shape);
169 aShapeTop->setImpl(new TopoDS_Shape(aBoxMaker.TopFace()));
170 myCreatedFaces["Top"] = aShapeTop;
171 std::shared_ptr<GeomAPI_Shape> aShapeBottom(new GeomAPI_Shape);
172 aShapeBottom->setImpl(new TopoDS_Shape(aBoxMaker.BottomFace()));
173 myCreatedFaces["Bottom"] = aShapeBottom;
174 std::shared_ptr<GeomAPI_Shape> aShapeLeft(new GeomAPI_Shape);
175 aShapeLeft->setImpl(new TopoDS_Shape(aBoxMaker.LeftFace()));
176 myCreatedFaces["Left"] = aShapeLeft;
177 std::shared_ptr<GeomAPI_Shape> aShapeRight(new GeomAPI_Shape);
178 aShapeRight->setImpl(new TopoDS_Shape(aBoxMaker.RightFace()));
179 myCreatedFaces["Right"] = aShapeRight;