1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: ShHealOper_ChangeOrientation.cxx
24 // Created: 11.07.06 11:46:45
25 // Author: Sergey KUUL
27 #include <ShHealOper_ChangeOrientation.hxx>
29 #include <BRepBuilderAPI_Copy.hxx>
30 #include <BRepBuilderAPI_MakeEdge.hxx>
31 #include <BRepBuilderAPI_MakeWire.hxx>
32 #include <BRep_Builder.hxx>
33 #include <Geom_Curve.hxx>
34 #include <TopExp_Explorer.hxx>
35 #include <TopTools_ListOfShape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Iterator.hxx>
39 #include <Geom_TrimmedCurve.hxx>
41 //=======================================================================
42 //function : ShHealOper_ChangeOrientation()
43 //purpose : Constructor
44 //=======================================================================
46 ShHealOper_ChangeOrientation::ShHealOper_ChangeOrientation ( const TopoDS_Shape& theShape )
51 //=======================================================================
54 //=======================================================================
56 void ShHealOper_ChangeOrientation::Init(const TopoDS_Shape& theShape)
58 ShHealOper_Tool::Init(theShape);
61 //=======================================================================
64 //=======================================================================
66 Standard_Boolean ShHealOper_ChangeOrientation::Perform()
69 if (myInitShape.ShapeType() == TopAbs_SHELL)
71 myResultShape = myInitShape.EmptyCopied();
72 TopoDS_Iterator itr (myInitShape);
74 B.Add(myResultShape,itr.Value().Reversed());
78 else if (myInitShape.ShapeType() == TopAbs_FACE)
80 myResultShape = myInitShape.EmptyCopied();
81 TopoDS_Iterator itr (myInitShape);
83 B.Add(myResultShape,itr.Value());
86 myResultShape.Reverse();
88 else if ( myInitShape.ShapeType() == TopAbs_WIRE || myInitShape.ShapeType() == TopAbs_EDGE)
90 TopTools_ListOfShape reversedEdges;
91 for ( TopExp_Explorer edgeIt( myInitShape, TopAbs_EDGE ); edgeIt.More(); edgeIt.Next() )
93 const TopoDS_Edge& edge = TopoDS::Edge( edgeIt.Current() );
96 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f,l );
97 Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(curve);
98 if ( !tc.IsNull() ) curve = tc->BasisCurve();
100 f = curve->ReversedParameter( f );
101 l = curve->ReversedParameter( l );
102 curve = curve->Reversed();
103 reversedEdges.Prepend( BRepBuilderAPI_MakeEdge( curve, Min( f, l ), Max( f, l )));
105 if ( myInitShape.ShapeType() == TopAbs_EDGE )
107 myResultShape = reversedEdges.First();
111 BRepBuilderAPI_MakeWire wire;
112 wire.Add( reversedEdges );
113 myResultShape = wire;
115 // myResultShape = myInitShape.EmptyCopied();
116 // TopoDS_Iterator itr (myInitShape);
117 // while (itr.More()) {
118 // B.Add(myResultShape,itr.Value());
121 // myResultShape.Reverse();
125 BRepBuilderAPI_Copy Copy (myInitShape);
126 if (!Copy.IsDone()) return false;
128 myResultShape = Copy.Shape();
129 if (myResultShape.IsNull()) return false;
131 if (myResultShape.Orientation() == TopAbs_FORWARD)
132 myResultShape.Orientation(TopAbs_REVERSED);
134 myResultShape.Orientation(TopAbs_FORWARD);