Salome HOME
5071209cd233f7cac8ba9798229a9c2a2cdbdae7
[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 <TopTools_DataMapOfShapeShape.hxx>
33 #include <TopoDS_Edge.hxx>
34 #include <TopoDS_Vertex.hxx>
35 #include <TopoDS_Face.hxx>
36
37 #include <list>
38 #include <map>
39
40 class TopoDS_Shape;
41 class SMDS_MeshNode;
42 class SMESH_Mesh;
43 class SMESH_Hypothesis;
44 class SMESH_subMesh;
45
46 /*!
47  * \brief Class encapsulating methods common to Projection algorithms
48  */
49 class StdMeshers_ProjectionUtils
50 {
51  public:
52
53   typedef TopTools_DataMapOfShapeShape                         TShapeShapeMap;
54   typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
55
56   /*!
57    * \brief Looks for association of all subshapes of two shapes
58     * \param theShape1 - shape 1
59     * \param theMesh1 - mesh built on shape 1
60     * \param theShape2 - shape 2
61     * \param theMesh2 - mesh built on shape 2
62     * \param theAssociation - association map to be filled that may
63     *                         contain association of one or two pairs of vertices
64     * \retval bool - true if association found
65    */
66   static bool FindSubShapeAssociation(const TopoDS_Shape& theShape1,
67                                       SMESH_Mesh*         theMesh1,
68                                       const TopoDS_Shape& theShape2,
69                                       SMESH_Mesh*         theMesh2,
70                                       TShapeShapeMap &    theAssociationMap);
71
72   /*!
73    * \brief Find association of edges of faces
74     * \param face1 - face 1
75     * \param VV1 - vertices of face 1
76     * \param face2 - face 2
77     * \param VV2 - vertices of face 2 associated with oned of face 1
78     * \param edges1 - out list of edges of face 1
79     * \param edges2 - out list of edges of face 2
80     * \retval int - nb of edges in an outer wire in a success case, else zero
81    */
82   static int FindFaceAssociation(const TopoDS_Face&    face1,
83                                  TopoDS_Vertex         VV1[2],
84                                  const TopoDS_Face&    face2,
85                                  TopoDS_Vertex         VV2[2],
86                                  list< TopoDS_Edge > & edges1,
87                                  list< TopoDS_Edge > & edges2);
88
89   /*!
90    * \brief Insert vertex association defined by a hypothesis into a map
91     * \param theHyp - hypothesis
92     * \param theAssociationMap - association map
93    */
94   static void InitVertexAssociation( const SMESH_Hypothesis* theHyp,
95                                      TShapeShapeMap &        theAssociationMap);
96
97   /*!
98    * \brief Inserts association theShape1 <-> theShape2 to TShapeShapeMap
99     * \param theShape1 - shape 1
100     * \param theShape2 - shape 2
101     * \param theAssociationMap - association map 
102     * \param theBidirectional - if false, inserts theShape1 -> theShape2 association
103     * \retval bool - true if there was no association for these shapes before
104    */
105   static bool InsertAssociation( const TopoDS_Shape& theShape1,
106                                  const TopoDS_Shape& theShape2,
107                                  TShapeShapeMap &    theAssociationMap,
108                                  const bool          theBidirectional=true);
109
110   static bool IsSubShape( const TopoDS_Shape& shape, SMESH_Mesh* aMesh );
111
112   static bool IsSubShape( const TopoDS_Shape& shape, const TopoDS_Shape& mainShape );
113
114   /*!
115    * \brief Finds an edge by its vertices in a main shape of the mesh
116     * \param aMesh - the mesh
117     * \param V1 - vertex 1
118     * \param V2 - vertex 2
119     * \retval TopoDS_Edge - found edge
120    */
121   static TopoDS_Edge GetEdgeByVertices( SMESH_Mesh*          aMesh,
122                                         const TopoDS_Vertex& V1,
123                                         const TopoDS_Vertex& V2);
124                                         
125   /*!
126    * \brief Return another face sharing an edge
127     * \param aMesh - mesh
128     * \param edge - edge
129     * \param face - face
130     * \retval TopoDS_Face - found face
131    */
132   static TopoDS_Face GetNextFace( SMESH_Mesh*        aMesh,
133                                   const TopoDS_Edge& edge,
134                                   const TopoDS_Face& face);
135
136   /*!
137    * \brief Return an oriented propagation edge
138     * \param aMesh - mesh
139     * \param fromEdge - start edge for propagation
140     * \retval TopoDS_Edge - found edge
141    */
142   static TopoDS_Edge GetPropagationEdge( SMESH_Mesh*        aMesh,
143                                          const TopoDS_Edge& anEdge,
144                                          const TopoDS_Edge& fromEdge);
145
146   /*!
147    * \brief Find corresponding nodes on two faces
148     * \param face1 - the first face
149     * \param mesh1 - mesh containing elements on the first face
150     * \param face2 - the second face
151     * \param mesh2 - mesh containing elements on the second face
152     * \param assocMap - map associating subshapes of the faces
153     * \param nodeIn2OutMap - map containing found matching nodes
154     * \retval bool - is a success
155    */
156   static bool FindMatchingNodesOnFaces( const TopoDS_Face&     face1,
157                                         SMESH_Mesh*            mesh1,
158                                         const TopoDS_Face&     face2,
159                                         SMESH_Mesh*            mesh2,
160                                         const TShapeShapeMap & assocMap,
161                                         TNodeNodeMap &         nodeIn2OutMap);
162   /*!
163    * \brief Check if the first and last vertices of an edge are the same
164     * \param anEdge - the edge to check
165     * \retval bool - true if same
166    */
167   static bool IsClosedEdge( const TopoDS_Edge& anEdge );
168
169   /*!
170    * \brief Return any subshape of a face belonging to the outer wire
171     * \param face - the face
172     * \param type - type of subshape to return
173     * \retval TopoDS_Shape - the found subshape
174    */
175   static TopoDS_Shape OuterShape( const TopoDS_Face& face,
176                                   TopAbs_ShapeEnum   type);
177
178   /*!
179    * \brief Check that submeshis is computed and try to compute it if is not
180     * \param sm - submesh to compute
181     * \param iterationNb - int used to stop infinite recursive call
182     * \retval bool - true if computed
183    */
184   static bool MakeComputed(SMESH_subMesh * sm, const int iterationNb = 0);
185
186   /*!
187    * \brief Count nb of subshapes
188     * \param shape - the shape
189     * \param type - the type of subshapes to count
190     * \param ignoreSame - if true, use map not to count same shapes, esle use explorer
191     * \retval int - the calculated number
192    */
193   static int Count(const TopoDS_Shape&    shape,
194                    const TopAbs_ShapeEnum type,
195                    const bool             ignoreSame);
196
197   /*!
198    * \brief Set event listeners to submesh with projection algo
199     * \param subMesh - submesh with projection algo
200     * \param srcShape - source shape
201     * \param srcMesh - source mesh
202    */
203   static void SetEventListener(SMESH_subMesh* subMesh,
204                                TopoDS_Shape   srcShape,
205                                SMESH_Mesh*    srcMesh);
206 };
207
208 #endif