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());
76 myStatistics.AddModif("Face reversed");
79 else if (myInitShape.ShapeType() == TopAbs_FACE)
81 myResultShape = myInitShape.EmptyCopied();
82 TopoDS_Iterator itr (myInitShape);
84 B.Add(myResultShape,itr.Value());
86 myStatistics.AddModif("Wire reversed");
88 myResultShape.Reverse();
90 else if ( myInitShape.ShapeType() == TopAbs_WIRE || myInitShape.ShapeType() == TopAbs_EDGE)
92 TopTools_ListOfShape reversedEdges;
93 for ( TopExp_Explorer edgeIt( myInitShape, TopAbs_EDGE ); edgeIt.More(); edgeIt.Next() )
95 const TopoDS_Edge& edge = TopoDS::Edge( edgeIt.Current() );
98 Handle(Geom_Curve) curve = BRep_Tool::Curve( edge, f,l );
99 Handle(Geom_TrimmedCurve) tc = Handle(Geom_TrimmedCurve)::DownCast(curve);
100 if ( !tc.IsNull() ) curve = tc->BasisCurve();
102 f = curve->ReversedParameter( f );
103 l = curve->ReversedParameter( l );
104 curve = curve->Reversed();
105 reversedEdges.Prepend( BRepBuilderAPI_MakeEdge( curve, Min( f, l ), Max( f, l )));
107 if ( myInitShape.ShapeType() == TopAbs_EDGE )
109 myResultShape = reversedEdges.First();
110 myStatistics.AddModif("Edge reversed");
114 BRepBuilderAPI_MakeWire wire;
115 wire.Add( reversedEdges );
116 myResultShape = wire;
117 myStatistics.AddModif("Wire reversed");
119 // myResultShape = myInitShape.EmptyCopied();
120 // TopoDS_Iterator itr (myInitShape);
121 // while (itr.More()) {
122 // B.Add(myResultShape,itr.Value());
125 // myResultShape.Reverse();
129 BRepBuilderAPI_Copy Copy (myInitShape);
130 if (!Copy.IsDone()) return false;
132 myResultShape = Copy.Shape();
133 if (myResultShape.IsNull()) return false;
135 if (myResultShape.Orientation() == TopAbs_FORWARD)
136 myResultShape.Orientation(TopAbs_REVERSED);
138 myResultShape.Orientation(TopAbs_FORWARD);
140 switch( myResultShape.ShapeType() ) {
141 case TopAbs_SOLID : myStatistics.AddModif("Solid reversed"); break;
142 case TopAbs_COMPSOLID: myStatistics.AddModif("Compsolid reversed"); break;
143 case TopAbs_COMPOUND : myStatistics.AddModif("Compound reversed"); break;