1 // Copyright (C) 2014-2016 CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_Symmetry.cpp
4 // Created: 30 Nov 2016
5 // Author: Clarisse Genrault (CEA)
7 #include "GeomAlgoAPI_Symmetry.h"
9 #include <BRepBuilderAPI_Transform.hxx>
11 //=================================================================================================
12 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
13 std::shared_ptr<GeomAPI_Pnt> thePoint)
15 myMethodType = BY_POINT;
16 mySourceShape = theSourceShape;
20 //=================================================================================================
21 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
22 std::shared_ptr<GeomAPI_Ax1> theAxis)
24 myMethodType = BY_AXIS;
25 mySourceShape = theSourceShape;
29 //=================================================================================================
30 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
31 std::shared_ptr<GeomAPI_Ax2> thePlane)
33 myMethodType = BY_PLANE;
34 mySourceShape = theSourceShape;
38 //=================================================================================================
39 bool GeomAlgoAPI_Symmetry::check()
41 switch (myMethodType) {
44 myError = "Symmetry builder :: point is not valid.";
48 myError = "Symmetry builder :: source shape is not valid.";
55 myError = "Symmetry builder :: axis is not valid.";
59 myError = "Symmetry builder :: source shape is not valid.";
66 myError = "Symmetry builder :: plane is not valid.";
70 myError = "Symmetry builder :: source shape is not valid.";
76 myError = "Symmetry builder :: method not implemented.";
82 //=================================================================================================
83 void GeomAlgoAPI_Symmetry::build()
85 gp_Trsf* aTrsf = new gp_Trsf();
87 switch (myMethodType) {
89 const gp_Pnt& aPoint = myPoint->impl<gp_Pnt>();
90 aTrsf->SetMirror(aPoint);
94 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
95 aTrsf->SetMirror(anAxis);
99 const gp_Ax2& aPlane = myPlane->impl<gp_Ax2>();
100 aTrsf->SetMirror(aPlane);
104 myError = "Symmetry builder :: method not supported";
109 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
111 if(aSourceShape.IsNull()) {
112 myError = "Symmetry builder :: source shape does not contain any actual shape.";
116 // Transform the shape while copying it.
117 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
119 myError = "Symmetry builder :: transform initialization failed.";
124 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
126 if(!aBuilder->IsDone()) {
127 myError = "Symmetry builder :: algorithm failed.";
131 TopoDS_Shape aResult = aBuilder->Shape();
133 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
134 aShape->setImpl(new TopoDS_Shape(aResult));