Salome HOME
SIP: HYDROData_ObstacleAltitude is included.
[modules/hydro.git] / src / HYDROData / HYDROData_ShapesTool.cxx
1
2 #include "HYDROData_ShapesTool.h"
3
4 #include <BRep_Tool.hxx>
5
6 #include <gp_Pnt.hxx>
7
8 #include <Precision.hxx>
9
10 #include <TopExp.hxx>
11
12 #include <TopoDS.hxx>
13 #include <TopoDS_Edge.hxx>
14 #include <TopoDS_Shape.hxx>
15 #include <TopoDS_Vertex.hxx>
16 #include <TopoDS_Wire.hxx>
17
18 #include <TopTools_SequenceOfShape.hxx>
19
20 #include <TopExp_Explorer.hxx>
21
22 void HYDROData_ShapesTool::ExploreShapeToShapes( const TopoDS_Shape&       theInShape,
23                                                  const TopAbs_ShapeEnum&   theExpType,
24                                                  TopTools_SequenceOfShape& theOutShapes )
25 {
26   theOutShapes.Clear();
27
28   if ( theInShape.IsNull() )
29     return;
30
31   TopExp_Explorer anExp( theInShape, theExpType );
32   for ( ; anExp.More(); anExp.Next() )
33   {
34     TopoDS_Shape anExpShape = anExp.Current();
35     theOutShapes.Append( anExpShape );
36   }
37 }
38
39 bool HYDROData_ShapesTool::Vertices( const TopoDS_Shape& theInShape,
40                                      TopoDS_Vertex&      theFirstVertex,
41                                      TopoDS_Vertex&      theLastVertex,
42                                      const bool          theIsCumOri  )
43 {
44   if ( theInShape.IsNull() )
45     return false;
46
47   if ( theInShape.ShapeType() == TopAbs_EDGE )
48   {
49     TopoDS_Edge anEdge = TopoDS::Edge( theInShape );
50     TopExp::Vertices( anEdge, theFirstVertex, theLastVertex, theIsCumOri );
51   }
52   else if ( theInShape.ShapeType() == TopAbs_WIRE )
53   {
54     TopoDS_Wire aWire = TopoDS::Wire( theInShape );
55     TopExp::Vertices( aWire, theFirstVertex, theLastVertex );
56   }
57   else
58   {
59     return false;
60   }
61
62   return true;
63 }
64
65 bool HYDROData_ShapesTool::IsVerticesEquals( const TopoDS_Vertex& theFirstVert,
66                                              const TopoDS_Vertex& theSecondVert,
67                                              const bool           theIs2D )
68 {
69   gp_Pnt aFirstPoint = BRep_Tool::Pnt( theFirstVert );
70   gp_Pnt aSecondPoint = BRep_Tool::Pnt( theSecondVert );
71
72   // Set the Z coord to zero for 2D equations
73   if ( theIs2D )
74   {
75     aFirstPoint.SetZ( 0.0 );
76     aSecondPoint.SetZ( 0.0 );
77   }
78
79   return aFirstPoint.IsEqual( aSecondPoint, Precision::Confusion() );
80 }
81
82 bool HYDROData_ShapesTool::IsEdgesEquals( const TopoDS_Edge& theFirstEdge,
83                                           const TopoDS_Edge& theSecondEdge,
84                                           const bool         theIs2D )
85 {
86   TopoDS_Vertex aFFirstVert, aFLastVert, aSFirstVert, aSLastVert;
87   TopExp::Vertices( theFirstEdge, aFFirstVert, aFLastVert );
88   TopExp::Vertices( theSecondEdge, aSFirstVert, aSLastVert );
89   return IsVerticesEquals( aFFirstVert, aSFirstVert, theIs2D ) &&
90          IsVerticesEquals( aFLastVert, aSLastVert, theIs2D );
91 }
92
93