1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAlgoAPI_Symmetry.h"
23 #include <BRepBuilderAPI_Transform.hxx>
25 //=================================================================================================
26 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
27 std::shared_ptr<GeomAPI_Pnt> thePoint)
29 myMethodType = BY_POINT;
30 mySourceShape = theSourceShape;
34 //=================================================================================================
35 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
36 std::shared_ptr<GeomAPI_Ax1> theAxis)
38 myMethodType = BY_AXIS;
39 mySourceShape = theSourceShape;
43 //=================================================================================================
44 GeomAlgoAPI_Symmetry::GeomAlgoAPI_Symmetry(std::shared_ptr<GeomAPI_Shape> theSourceShape,
45 std::shared_ptr<GeomAPI_Ax2> thePlane)
47 myMethodType = BY_PLANE;
48 mySourceShape = theSourceShape;
52 //=================================================================================================
53 bool GeomAlgoAPI_Symmetry::check()
55 switch (myMethodType) {
58 myError = "Symmetry builder :: point is not valid.";
62 myError = "Symmetry builder :: source shape is not valid.";
69 myError = "Symmetry builder :: axis is not valid.";
73 myError = "Symmetry builder :: source shape is not valid.";
80 myError = "Symmetry builder :: plane is not valid.";
84 myError = "Symmetry builder :: source shape is not valid.";
90 myError = "Symmetry builder :: method not implemented.";
96 //=================================================================================================
97 void GeomAlgoAPI_Symmetry::build()
99 gp_Trsf* aTrsf = new gp_Trsf();
101 switch (myMethodType) {
103 const gp_Pnt& aPoint = myPoint->impl<gp_Pnt>();
104 aTrsf->SetMirror(aPoint);
108 const gp_Ax1& anAxis = myAxis->impl<gp_Ax1>();
109 aTrsf->SetMirror(anAxis);
113 const gp_Ax2& aPlane = myPlane->impl<gp_Ax2>();
114 aTrsf->SetMirror(aPlane);
118 myError = "Symmetry builder :: method not supported";
123 const TopoDS_Shape& aSourceShape = mySourceShape->impl<TopoDS_Shape>();
125 if(aSourceShape.IsNull()) {
126 myError = "Symmetry builder :: source shape does not contain any actual shape.";
130 // Transform the shape while copying it.
131 BRepBuilderAPI_Transform* aBuilder = new BRepBuilderAPI_Transform(aSourceShape, *aTrsf, true);
133 myError = "Symmetry builder :: transform initialization failed.";
138 setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
140 if(!aBuilder->IsDone()) {
141 myError = "Symmetry builder :: algorithm failed.";
145 TopoDS_Shape aResult = aBuilder->Shape();
147 std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape());
148 aShape->setImpl(new TopoDS_Shape(aResult));