1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GeomAlgoAPI_Symmetry.h"
22 #include <BRepBuilderAPI_Transform.hxx>
24 //=================================================================================================
25 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
26 std::shared_ptr<GeomAPI_Pnt> thePoint)
28 myMethodType = BY_POINT;
29 mySourceShape = theSourceShape;
33 //=================================================================================================
34 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
35 std::shared_ptr<GeomAPI_Ax1> theAxis)
37 myMethodType = BY_AXIS;
38 mySourceShape = theSourceShape;
42 //=================================================================================================
43 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
44 std::shared_ptr<GeomAPI_Ax2> thePlane)
46 myMethodType = BY_PLANE;
47 mySourceShape = theSourceShape;
51 //=================================================================================================
52 bool GeomAlgoAPI_Symmetry::check()
54 switch (myMethodType) {
57 myError = "Symmetry builder :: point is not valid.";
61 myError = "Symmetry builder :: source shape is not valid.";
68 myError = "Symmetry builder :: axis is not valid.";
72 myError = "Symmetry builder :: source shape is not valid.";
79 myError = "Symmetry builder :: plane is not valid.";
83 myError = "Symmetry builder :: source shape is not valid.";
89 myError = "Symmetry builder :: method not implemented.";
95 //=================================================================================================
96 void GeomAlgoAPI_Symmetry::build()
98 gp_Trsf* aTrsf = new gp_Trsf();
100 switch (myMethodType) {
102 const gp_Pnt& aPoint = myPoint->impl<gp_Pnt>();
103 aTrsf->SetMirror(aPoint);
107 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
108 aTrsf->SetMirror(anAxis);
112 const gp_Ax2& aPlane = myPlane->impl<gp_Ax2>();
113 aTrsf->SetMirror(aPlane);
117 myError = "Symmetry builder :: method not supported";
122 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
124 if(aSourceShape.IsNull()) {
125 myError = "Symmetry builder :: source shape does not contain any actual shape.";
129 // Transform the shape while copying it.
130 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
132 myError = "Symmetry builder :: transform initialization failed.";
137 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
139 if(!aBuilder->IsDone()) {
140 myError = "Symmetry builder :: algorithm failed.";
144 TopoDS_Shape aResult = aBuilder->Shape();
146 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
147 aShape->setImpl(new TopoDS_Shape(aResult));