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