1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_ShapesTool.h"
21 #include <BRep_Tool.hxx>
25 #include <Precision.hxx>
30 #include <TopoDS_Edge.hxx>
31 #include <TopoDS_Shape.hxx>
32 #include <TopoDS_Vertex.hxx>
33 #include <TopoDS_Wire.hxx>
35 #include <TopTools_SequenceOfShape.hxx>
36 #include <TopTools_ListOfShape.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
39 #include <TopExp_Explorer.hxx>
41 void HYDROData_ShapesTool::ExploreShapeToShapes( const TopoDS_Shape& theInShape,
42 const TopAbs_ShapeEnum& theExpType,
43 TopTools_SequenceOfShape& theOutShapes )
47 if ( theInShape.IsNull() )
50 TopExp_Explorer anExp( theInShape, theExpType );
51 for ( ; anExp.More(); anExp.Next() )
53 TopoDS_Shape anExpShape = anExp.Current();
54 theOutShapes.Append( anExpShape );
58 bool HYDROData_ShapesTool::Vertices( const TopoDS_Shape& theInShape,
59 TopoDS_Vertex& theFirstVertex,
60 TopoDS_Vertex& theLastVertex,
61 const bool theIsCumOri )
63 if ( theInShape.IsNull() )
66 if ( theInShape.ShapeType() == TopAbs_EDGE )
68 TopoDS_Edge anEdge = TopoDS::Edge( theInShape );
69 TopExp::Vertices( anEdge, theFirstVertex, theLastVertex, theIsCumOri );
71 else if ( theInShape.ShapeType() == TopAbs_WIRE )
73 TopoDS_Wire aWire = TopoDS::Wire( theInShape );
74 TopExp::Vertices( aWire, theFirstVertex, theLastVertex );
84 bool HYDROData_ShapesTool::IsVerticesEquals( const TopoDS_Vertex& theFirstVert,
85 const TopoDS_Vertex& theSecondVert,
88 gp_Pnt aFirstPoint = BRep_Tool::Pnt( theFirstVert );
89 gp_Pnt aSecondPoint = BRep_Tool::Pnt( theSecondVert );
91 // Set the Z coord to zero for 2D equations
94 aFirstPoint.SetZ( 0.0 );
95 aSecondPoint.SetZ( 0.0 );
98 return aFirstPoint.IsEqual( aSecondPoint, Precision::Confusion() )==Standard_True;
101 TopoDS_Shape HYDROData_ShapesTool::Translated( const TopoDS_Shape& theShape,
106 TopoDS_Shape aTranslatedShape;
107 if ( theShape.IsNull() )
108 return aTranslatedShape;
110 gp_Vec aVec( theDx, theDy, theDz );
113 aTrsf.SetTranslation( aVec );
115 TopLoc_Location aLocOrig = theShape.Location();
116 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
118 TopLoc_Location aLocRes( aTrsf * aTrsfOrig );
119 aTranslatedShape = theShape.Located( aLocRes );
121 return aTranslatedShape;
124 bool HYDROData_ShapesTool::IsEdgesEquals( const TopoDS_Edge& theFirstEdge,
125 const TopoDS_Edge& theSecondEdge,
128 TopoDS_Vertex aFFirstVert, aFLastVert, aSFirstVert, aSLastVert;
129 TopExp::Vertices( theFirstEdge, aFFirstVert, aFLastVert );
130 TopExp::Vertices( theSecondEdge, aSFirstVert, aSLastVert );
131 return IsVerticesEquals( aFFirstVert, aSFirstVert, theIs2D ) &&
132 IsVerticesEquals( aFLastVert, aSLastVert, theIs2D );
135 void HYDROData_ShapesTool::AddShapes( TopTools_SequenceOfShape& theShapes,
136 const TopTools_SequenceOfShape& theShapesToAdd )
138 for ( int i = 1, n = theShapesToAdd.Length(); i <= n; ++i )
140 const TopoDS_Shape& aShape = theShapesToAdd.Value( i );
141 theShapes.Append( aShape );
145 void HYDROData_ShapesTool::AddShapes( TopTools_SequenceOfShape& theShapes,
146 const TopTools_ListOfShape& theShapesToAdd )
148 TopTools_ListIteratorOfListOfShape anIter( theShapesToAdd );
149 for ( ; anIter.More(); anIter.Next() )
151 const TopoDS_Shape& aShape = anIter.Value();
152 theShapes.Append( aShape );
156 void HYDROData_ShapesTool::AddShapes( TopTools_ListOfShape& theShapes,
157 const TopTools_SequenceOfShape& theShapesToAdd )
159 for ( int i = 1, n = theShapesToAdd.Length(); i <= n; ++i )
161 const TopoDS_Shape& aShape = theShapesToAdd.Value( i );
162 theShapes.Append( aShape );
166 void HYDROData_ShapesTool::AddShapes( TopTools_ListOfShape& theShapes,
167 const TopTools_ListOfShape& theShapesToAdd )
169 TopTools_ListIteratorOfListOfShape anIter( theShapesToAdd );
170 for ( ; anIter.More(); anIter.Next() )
172 const TopoDS_Shape& aShape = anIter.Value();
173 theShapes.Append( aShape );
177 void HYDROData_ShapesTool::DumpShapeSubShapes( std::ostream& theStream,
178 const char* theTitle,
179 const TopoDS_Shape& theShape,
180 const TopAbs_ShapeEnum& theExpType )
182 TopTools_SequenceOfShape aShapeSubShapes;
183 ExploreShapeToShapes( theShape, theExpType, aShapeSubShapes );
185 theStream << theTitle << "\n";
186 DumpSequenceOfShapes( theStream, aShapeSubShapes );
189 void HYDROData_ShapesTool::DumpSequenceOfShapes( std::ostream& theStream,
190 const TopTools_SequenceOfShape& theShapes )
192 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
194 const TopoDS_Shape& aShape = theShapes.Value( i );
195 theStream << "Shape " << i << " : " << aShape.TShape() << "\n";