1 // Copyright (C) 2007-2015 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 #include "HYDROData_ShapesTool.h"
25 #include <BRep_Tool.hxx>
29 #include <Precision.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Wire.hxx>
39 #include <TopTools_SequenceOfShape.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
43 #include <TopExp_Explorer.hxx>
45 void HYDROData_ShapesTool::ExploreShapeToShapes( const TopoDS_Shape& theInShape,
46 const TopAbs_ShapeEnum& theExpType,
47 TopTools_SequenceOfShape& theOutShapes )
51 if ( theInShape.IsNull() )
54 TopExp_Explorer anExp( theInShape, theExpType );
55 for ( ; anExp.More(); anExp.Next() )
57 TopoDS_Shape anExpShape = anExp.Current();
58 theOutShapes.Append( anExpShape );
62 bool HYDROData_ShapesTool::Vertices( const TopoDS_Shape& theInShape,
63 TopoDS_Vertex& theFirstVertex,
64 TopoDS_Vertex& theLastVertex,
65 const bool theIsCumOri )
67 if ( theInShape.IsNull() )
70 if ( theInShape.ShapeType() == TopAbs_EDGE )
72 TopoDS_Edge anEdge = TopoDS::Edge( theInShape );
73 TopExp::Vertices( anEdge, theFirstVertex, theLastVertex, theIsCumOri );
75 else if ( theInShape.ShapeType() == TopAbs_WIRE )
77 TopoDS_Wire aWire = TopoDS::Wire( theInShape );
78 TopExp::Vertices( aWire, theFirstVertex, theLastVertex );
88 bool HYDROData_ShapesTool::IsVerticesEquals( const TopoDS_Vertex& theFirstVert,
89 const TopoDS_Vertex& theSecondVert,
92 gp_Pnt aFirstPoint = BRep_Tool::Pnt( theFirstVert );
93 gp_Pnt aSecondPoint = BRep_Tool::Pnt( theSecondVert );
95 // Set the Z coord to zero for 2D equations
98 aFirstPoint.SetZ( 0.0 );
99 aSecondPoint.SetZ( 0.0 );
102 return aFirstPoint.IsEqual( aSecondPoint, Precision::Confusion() );
105 TopoDS_Shape HYDROData_ShapesTool::Translated( const TopoDS_Shape& theShape,
110 TopoDS_Shape aTranslatedShape;
111 if ( theShape.IsNull() )
112 return aTranslatedShape;
114 gp_Vec aVec( theDx, theDy, theDz );
117 aTrsf.SetTranslation( aVec );
119 TopLoc_Location aLocOrig = theShape.Location();
120 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
122 TopLoc_Location aLocRes( aTrsf * aTrsfOrig );
123 aTranslatedShape = theShape.Located( aLocRes );
125 return aTranslatedShape;
128 bool HYDROData_ShapesTool::IsEdgesEquals( const TopoDS_Edge& theFirstEdge,
129 const TopoDS_Edge& theSecondEdge,
132 TopoDS_Vertex aFFirstVert, aFLastVert, aSFirstVert, aSLastVert;
133 TopExp::Vertices( theFirstEdge, aFFirstVert, aFLastVert );
134 TopExp::Vertices( theSecondEdge, aSFirstVert, aSLastVert );
135 return IsVerticesEquals( aFFirstVert, aSFirstVert, theIs2D ) &&
136 IsVerticesEquals( aFLastVert, aSLastVert, theIs2D );
139 void HYDROData_ShapesTool::AddShapes( TopTools_SequenceOfShape& theShapes,
140 const TopTools_SequenceOfShape& theShapesToAdd )
142 for ( int i = 1, n = theShapesToAdd.Length(); i <= n; ++i )
144 const TopoDS_Shape& aShape = theShapesToAdd.Value( i );
145 theShapes.Append( aShape );
149 void HYDROData_ShapesTool::AddShapes( TopTools_SequenceOfShape& theShapes,
150 const TopTools_ListOfShape& theShapesToAdd )
152 TopTools_ListIteratorOfListOfShape anIter( theShapesToAdd );
153 for ( ; anIter.More(); anIter.Next() )
155 const TopoDS_Shape& aShape = anIter.Value();
156 theShapes.Append( aShape );
160 void HYDROData_ShapesTool::AddShapes( TopTools_ListOfShape& theShapes,
161 const TopTools_SequenceOfShape& theShapesToAdd )
163 for ( int i = 1, n = theShapesToAdd.Length(); i <= n; ++i )
165 const TopoDS_Shape& aShape = theShapesToAdd.Value( i );
166 theShapes.Append( aShape );
170 void HYDROData_ShapesTool::AddShapes( TopTools_ListOfShape& theShapes,
171 const TopTools_ListOfShape& theShapesToAdd )
173 TopTools_ListIteratorOfListOfShape anIter( theShapesToAdd );
174 for ( ; anIter.More(); anIter.Next() )
176 const TopoDS_Shape& aShape = anIter.Value();
177 theShapes.Append( aShape );
181 void HYDROData_ShapesTool::DumpShapeSubShapes( std::ostream& theStream,
182 const char* theTitle,
183 const TopoDS_Shape& theShape,
184 const TopAbs_ShapeEnum& theExpType )
186 TopTools_SequenceOfShape aShapeSubShapes;
187 ExploreShapeToShapes( theShape, theExpType, aShapeSubShapes );
189 theStream << theTitle << "\n";
190 DumpSequenceOfShapes( theStream, aShapeSubShapes );
193 void HYDROData_ShapesTool::DumpSequenceOfShapes( std::ostream& theStream,
194 const TopTools_SequenceOfShape& theShapes )
196 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
198 const TopoDS_Shape& aShape = theShapes.Value( i );
199 theStream << "Shape " << i << " : " << aShape.TShape() << "\n";