2 #include "HYDROData_ShapesTool.h"
4 #include <BRep_Tool.hxx>
8 #include <Precision.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Vertex.hxx>
16 #include <TopoDS_Wire.hxx>
18 #include <TopTools_SequenceOfShape.hxx>
19 #include <TopTools_ListOfShape.hxx>
20 #include <TopTools_ListIteratorOfListOfShape.hxx>
22 #include <TopExp_Explorer.hxx>
24 void HYDROData_ShapesTool::ExploreShapeToShapes( const TopoDS_Shape& theInShape,
25 const TopAbs_ShapeEnum& theExpType,
26 TopTools_SequenceOfShape& theOutShapes )
30 if ( theInShape.IsNull() )
33 TopExp_Explorer anExp( theInShape, theExpType );
34 for ( ; anExp.More(); anExp.Next() )
36 TopoDS_Shape anExpShape = anExp.Current();
37 theOutShapes.Append( anExpShape );
41 bool HYDROData_ShapesTool::Vertices( const TopoDS_Shape& theInShape,
42 TopoDS_Vertex& theFirstVertex,
43 TopoDS_Vertex& theLastVertex,
44 const bool theIsCumOri )
46 if ( theInShape.IsNull() )
49 if ( theInShape.ShapeType() == TopAbs_EDGE )
51 TopoDS_Edge anEdge = TopoDS::Edge( theInShape );
52 TopExp::Vertices( anEdge, theFirstVertex, theLastVertex, theIsCumOri );
54 else if ( theInShape.ShapeType() == TopAbs_WIRE )
56 TopoDS_Wire aWire = TopoDS::Wire( theInShape );
57 TopExp::Vertices( aWire, theFirstVertex, theLastVertex );
67 bool HYDROData_ShapesTool::IsVerticesEquals( const TopoDS_Vertex& theFirstVert,
68 const TopoDS_Vertex& theSecondVert,
71 gp_Pnt aFirstPoint = BRep_Tool::Pnt( theFirstVert );
72 gp_Pnt aSecondPoint = BRep_Tool::Pnt( theSecondVert );
74 // Set the Z coord to zero for 2D equations
77 aFirstPoint.SetZ( 0.0 );
78 aSecondPoint.SetZ( 0.0 );
81 return aFirstPoint.IsEqual( aSecondPoint, Precision::Confusion() );
84 TopoDS_Shape HYDROData_ShapesTool::Translated( const TopoDS_Shape& theShape,
89 TopoDS_Shape aTranslatedShape;
90 if ( theShape.IsNull() )
91 return aTranslatedShape;
93 gp_Vec aVec( theDx, theDy, theDz );
96 aTrsf.SetTranslation( aVec );
98 TopLoc_Location aLocOrig = theShape.Location();
99 gp_Trsf aTrsfOrig = aLocOrig.Transformation();
101 TopLoc_Location aLocRes( aTrsf * aTrsfOrig );
102 aTranslatedShape = theShape.Located( aLocRes );
104 return aTranslatedShape;
107 bool HYDROData_ShapesTool::IsEdgesEquals( const TopoDS_Edge& theFirstEdge,
108 const TopoDS_Edge& theSecondEdge,
111 TopoDS_Vertex aFFirstVert, aFLastVert, aSFirstVert, aSLastVert;
112 TopExp::Vertices( theFirstEdge, aFFirstVert, aFLastVert );
113 TopExp::Vertices( theSecondEdge, aSFirstVert, aSLastVert );
114 return IsVerticesEquals( aFFirstVert, aSFirstVert, theIs2D ) &&
115 IsVerticesEquals( aFLastVert, aSLastVert, theIs2D );
118 void HYDROData_ShapesTool::AddShapes( TopTools_SequenceOfShape& theShapes,
119 const TopTools_SequenceOfShape& theShapesToAdd )
121 for ( int i = 1, n = theShapesToAdd.Length(); i <= n; ++i )
123 const TopoDS_Shape& aShape = theShapesToAdd.Value( i );
124 theShapes.Append( aShape );
128 void HYDROData_ShapesTool::AddShapes( TopTools_SequenceOfShape& theShapes,
129 const TopTools_ListOfShape& theShapesToAdd )
131 TopTools_ListIteratorOfListOfShape anIter( theShapesToAdd );
132 for ( ; anIter.More(); anIter.Next() )
134 const TopoDS_Shape& aShape = anIter.Value();
135 theShapes.Append( aShape );
139 void HYDROData_ShapesTool::AddShapes( TopTools_ListOfShape& 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_ListOfShape& 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::DumpShapeSubShapes( std::ostream& theStream,
161 const char* theTitle,
162 const TopoDS_Shape& theShape,
163 const TopAbs_ShapeEnum& theExpType )
165 TopTools_SequenceOfShape aShapeSubShapes;
166 ExploreShapeToShapes( theShape, theExpType, aShapeSubShapes );
168 theStream << theTitle << "\n";
169 DumpSequenceOfShapes( theStream, aShapeSubShapes );
172 void HYDROData_ShapesTool::DumpSequenceOfShapes( std::ostream& theStream,
173 const TopTools_SequenceOfShape& theShapes )
175 for ( int i = 1, n = theShapes.Length(); i <= n; ++i )
177 const TopoDS_Shape& aShape = theShapes.Value( i );
178 theStream << "Shape " << i << " : " << aShape.TShape() << "\n";