Salome HOME
Merging with WPdev
[modules/smesh.git] / src / StdMeshers / StdMeshers_ProjectionUtils.hxx
1 //  SMESH SMESH : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 // File      : StdMeshers_ProjectionUtils.hxx
25 // Created   : Thu Oct 26 15:37:24 2006
26 // Author    : Edward AGAPOV (eap)
27
28
29 #ifndef StdMeshers_ProjectionUtils_HeaderFile
30 #define StdMeshers_ProjectionUtils_HeaderFile
31
32 #include "SMESH_StdMeshers.hxx"
33
34 #include <TopTools_DataMapOfShapeShape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Vertex.hxx>
37 #include <TopoDS_Face.hxx>
38
39 #include <list>
40 #include <map>
41
42 class TopoDS_Shape;
43 class SMDS_MeshNode;
44 class SMESH_Mesh;
45 class SMESH_Hypothesis;
46 class SMESH_subMesh;
47
48 /*!
49  * \brief Class encapsulating methods common to Projection algorithms
50  */
51 class STDMESHERS_EXPORT StdMeshers_ProjectionUtils
52 {
53  public:
54
55   typedef TopTools_DataMapOfShapeShape                         TShapeShapeMap;
56   typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
57
58   /*!
59    * \brief Looks for association of all subshapes of two shapes
60     * \param theShape1 - shape 1
61     * \param theMesh1 - mesh built on shape 1
62     * \param theShape2 - shape 2
63     * \param theMesh2 - mesh built on shape 2
64     * \param theAssociation - association map to be filled that may
65     *                         contain association of one or two pairs of vertices
66     * \retval bool - true if association found
67    */
68   static bool FindSubShapeAssociation(const TopoDS_Shape& theShape1,
69                                       SMESH_Mesh*         theMesh1,
70                                       const TopoDS_Shape& theShape2,
71                                       SMESH_Mesh*         theMesh2,
72                                       TShapeShapeMap &    theAssociationMap);
73
74   /*!
75    * \brief Find association of edges of faces
76     * \param face1 - face 1
77     * \param VV1 - vertices of face 1
78     * \param face2 - face 2
79     * \param VV2 - vertices of face 2 associated with oned of face 1
80     * \param edges1 - out list of edges of face 1
81     * \param edges2 - out list of edges of face 2
82     * \retval int - nb of edges in an outer wire in a success case, else zero
83    */
84   static int FindFaceAssociation(const TopoDS_Face&    face1,
85                                  TopoDS_Vertex         VV1[2],
86                                  const TopoDS_Face&    face2,
87                                  TopoDS_Vertex         VV2[2],
88                                  list< TopoDS_Edge > & edges1,
89                                  list< TopoDS_Edge > & edges2);
90
91   /*!
92    * \brief Insert vertex association defined by a hypothesis into a map
93     * \param theHyp - hypothesis
94     * \param theAssociationMap - association map
95    */
96   static void InitVertexAssociation( const SMESH_Hypothesis* theHyp,
97                                      TShapeShapeMap &        theAssociationMap);
98
99   /*!
100    * \brief Inserts association theShape1 <-> theShape2 to TShapeShapeMap
101     * \param theShape1 - shape 1
102     * \param theShape2 - shape 2
103     * \param theAssociationMap - association map 
104     * \param theBidirectional - if false, inserts theShape1 -> theShape2 association
105     * \retval bool - true if there was no association for these shapes before
106    */
107   static bool InsertAssociation( const TopoDS_Shape& theShape1,
108                                  const TopoDS_Shape& theShape2,
109                                  TShapeShapeMap &    theAssociationMap,
110                                  const bool          theBidirectional=true);
111
112   static bool IsSubShape( const TopoDS_Shape& shape, SMESH_Mesh* aMesh );
113
114   static bool IsSubShape( const TopoDS_Shape& shape, const TopoDS_Shape& mainShape );
115
116   /*!
117    * \brief Finds an edge by its vertices in a main shape of the mesh
118     * \param aMesh - the mesh
119     * \param V1 - vertex 1
120     * \param V2 - vertex 2
121     * \retval TopoDS_Edge - found edge
122    */
123   static TopoDS_Edge GetEdgeByVertices( SMESH_Mesh*          aMesh,
124                                         const TopoDS_Vertex& V1,
125                                         const TopoDS_Vertex& V2);
126                                         
127   /*!
128    * \brief Return another face sharing an edge
129     * \param aMesh - mesh
130     * \param edge - edge
131     * \param face - face
132     * \retval TopoDS_Face - found face
133    */
134   static TopoDS_Face GetNextFace( SMESH_Mesh*        aMesh,
135                                   const TopoDS_Edge& edge,
136                                   const TopoDS_Face& face);
137
138   /*!
139    * \brief Return an oriented propagation edge
140     * \param aMesh - mesh
141     * \param fromEdge - start edge for propagation
142     * \retval TopoDS_Edge - found edge
143    */
144   static TopoDS_Edge GetPropagationEdge( SMESH_Mesh*        aMesh,
145                                          const TopoDS_Edge& anEdge,
146                                          const TopoDS_Edge& fromEdge);
147
148   /*!
149    * \brief Find corresponding nodes on two faces
150     * \param face1 - the first face
151     * \param mesh1 - mesh containing elements on the first face
152     * \param face2 - the second face
153     * \param mesh2 - mesh containing elements on the second face
154     * \param assocMap - map associating subshapes of the faces
155     * \param nodeIn2OutMap - map containing found matching nodes
156     * \retval bool - is a success
157    */
158   static bool FindMatchingNodesOnFaces( const TopoDS_Face&     face1,
159                                         SMESH_Mesh*            mesh1,
160                                         const TopoDS_Face&     face2,
161                                         SMESH_Mesh*            mesh2,
162                                         const TShapeShapeMap & assocMap,
163                                         TNodeNodeMap &         nodeIn2OutMap);
164   /*!
165    * \brief Check if the first and last vertices of an edge are the same
166     * \param anEdge - the edge to check
167     * \retval bool - true if same
168    */
169   static bool IsClosedEdge( const TopoDS_Edge& anEdge );
170
171   /*!
172    * \brief Return any subshape of a face belonging to the outer wire
173     * \param face - the face
174     * \param type - type of subshape to return
175     * \retval TopoDS_Shape - the found subshape
176    */
177   static TopoDS_Shape OuterShape( const TopoDS_Face& face,
178                                   TopAbs_ShapeEnum   type);
179
180   /*!
181    * \brief Check that submeshis is computed and try to compute it if is not
182     * \param sm - submesh to compute
183     * \param iterationNb - int used to stop infinite recursive call
184     * \retval bool - true if computed
185    */
186   static bool MakeComputed(SMESH_subMesh * sm, const int iterationNb = 0);
187
188   /*!
189    * \brief Count nb of subshapes
190     * \param shape - the shape
191     * \param type - the type of subshapes to count
192     * \param ignoreSame - if true, use map not to count same shapes, esle use explorer
193     * \retval int - the calculated number
194    */
195   static int Count(const TopoDS_Shape&    shape,
196                    const TopAbs_ShapeEnum type,
197                    const bool             ignoreSame);
198 };
199
200 #endif