Salome HOME
0021672: [CEA 565] Dump Study from script
[modules/geom.git] / src / ShHealOper / ShHealOper_ChangeOrientation.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // File:      ShHealOper_ChangeOrientation.cxx
24 // Created:   11.07.06 11:46:45
25 // Author:    Sergey KUUL
26
27 #include <ShHealOper_ChangeOrientation.hxx>
28
29 #include <BRep_Builder.hxx>
30 #include <BRepBuilderAPI_Copy.hxx>
31
32 #include <TopoDS_Iterator.hxx>
33
34 //=======================================================================
35 //function : ShHealOper_ChangeOrientation()
36 //purpose  : Constructor
37 //=======================================================================
38
39 ShHealOper_ChangeOrientation::ShHealOper_ChangeOrientation ( const TopoDS_Shape& theShape )
40 {
41   Init(theShape);
42 }
43
44 //=======================================================================
45 //function : Init
46 //purpose  : 
47 //=======================================================================
48
49 void ShHealOper_ChangeOrientation::Init(const TopoDS_Shape& theShape)
50 {
51   ShHealOper_Tool::Init(theShape);
52 }
53
54 //=======================================================================
55 //function : Perform
56 //purpose  : 
57 //=======================================================================
58
59 Standard_Boolean ShHealOper_ChangeOrientation::Perform()
60 {
61   BRep_Builder B;
62   if (myInitShape.ShapeType() == TopAbs_SHELL) {
63     myResultShape = myInitShape.EmptyCopied();
64     TopoDS_Iterator itr (myInitShape);
65     while (itr.More()) {
66       B.Add(myResultShape,itr.Value().Reversed());
67       itr.Next();
68     }
69   }
70   else if (myInitShape.ShapeType() == TopAbs_FACE) {
71     myResultShape = myInitShape.EmptyCopied();
72     TopoDS_Iterator itr (myInitShape);
73     while (itr.More()) {
74       B.Add(myResultShape,itr.Value());
75       itr.Next();
76     }
77     myResultShape.Reverse();
78   }
79   else if ( myInitShape.ShapeType() == TopAbs_WIRE || myInitShape.ShapeType() == TopAbs_EDGE) {
80     myResultShape = myInitShape.EmptyCopied();
81     TopoDS_Iterator itr (myInitShape);
82     while (itr.More()) {
83       B.Add(myResultShape,itr.Value());
84       itr.Next();
85     }
86     myResultShape.Reverse();
87   }
88   else {
89     BRepBuilderAPI_Copy Copy (myInitShape);
90     if (!Copy.IsDone()) return false;
91
92     myResultShape = Copy.Shape();
93     if (myResultShape.IsNull()) return false;
94
95     if (myResultShape.Orientation() == TopAbs_FORWARD)
96       myResultShape.Orientation(TopAbs_REVERSED);
97     else
98       myResultShape.Orientation(TopAbs_FORWARD);
99   }
100
101   return true;
102 }