Salome HOME
Regression of SALOME_TESTS/Grids/smesh/imps_09/K2
[modules/smesh.git] / src / StdMeshers / StdMeshers_ProjectionUtils.hxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 SMDS_MeshNode;
42 class SMESH_Algo;
43 class SMESH_Hypothesis;
44 class SMESH_Mesh;
45 class SMESH_subMesh;
46 class TopTools_IndexedDataMapOfShapeListOfShape;
47 class TopTools_IndexedMapOfShape;
48 class TopoDS_Shape;
49
50 /*!
51  * \brief Struct used instead of a sole TopTools_DataMapOfShapeShape to avoid
52  *        problems with bidirectional bindings
53  */
54 struct StdMeshers_ShapeShapeBiDirectionMap
55 {
56   TopTools_DataMapOfShapeShape _map1to2, _map2to1;
57
58   // convention: s1 - target, s2 - source
59   bool Bind( const TopoDS_Shape& s1, const TopoDS_Shape& s2 )
60   { _map1to2.Bind( s1, s2 ); return _map2to1.Bind( s2, s1 ); }
61   bool IsBound( const TopoDS_Shape& s, const bool isShape2=false ) const 
62   { return (isShape2 ? _map2to1 : _map1to2).IsBound( s ); }
63   bool IsEmpty() const { return _map1to2.IsEmpty(); }
64   int  Extent()  const { return _map1to2.Extent(); }
65   void Clear() { _map1to2.Clear(); _map2to1.Clear(); }
66   const TopoDS_Shape& operator()( const TopoDS_Shape& s, const bool isShape2=false ) const
67   { // if we get a Standard_NoSuchObject here, it means that the calling code
68     // passes incorrect isShape2
69     return (isShape2 ? _map2to1 : _map1to2)( s );
70   }
71 };
72
73 /*!
74  * \brief Methods common to Projection algorithms
75  */
76 namespace StdMeshers_ProjectionUtils
77 {
78   typedef StdMeshers_ShapeShapeBiDirectionMap                  TShapeShapeMap;
79   typedef TopTools_IndexedDataMapOfShapeListOfShape            TAncestorMap;
80   typedef std::map<const SMDS_MeshNode*, const SMDS_MeshNode*> TNodeNodeMap;
81
82   /*!
83    * \brief Looks for association of all sub-shapes of two shapes
84    * \param theShape1 - shape 1
85    * \param theMesh1 - mesh built on shape 1
86    * \param theShape2 - shape 2
87    * \param theMesh2 - mesh built on shape 2
88    * \param theAssociation - association map to be filled that may
89    *                         contain association of one or two pairs of vertices
90    * \retval bool - true if association found
91    */
92   bool FindSubShapeAssociation(const TopoDS_Shape& theShape1,
93                                SMESH_Mesh*         theMesh1,
94                                const TopoDS_Shape& theShape2,
95                                SMESH_Mesh*         theMesh2,
96                                TShapeShapeMap &    theAssociationMap);
97
98   /*!
99    * \brief Find association of edges of faces
100    * \param face1 - face 1
101    * \param VV1 - vertices of face 1
102    * \param face2 - face 2
103    * \param VV2 - vertices of face 2 associated with oned of face 1
104    * \param edges1 - out list of edges of face 1
105    * \param edges2 - out list of edges of face 2
106    * \retval int - nb of edges in an outer wire in a success case, else zero
107    */
108   int FindFaceAssociation(const TopoDS_Face&         face1,
109                           TopoDS_Vertex              VV1[2],
110                           const TopoDS_Face&         face2,
111                           TopoDS_Vertex              VV2[2],
112                           std::list< TopoDS_Edge > & edges1,
113                           std::list< TopoDS_Edge > & edges2);
114
115   /*!
116    * \brief Insert vertex association defined by a hypothesis into a map
117    * \param theHyp - hypothesis
118    * \param theAssociationMap - association map
119    * \param theTargetShape - the shape theHyp assigned to
120    */
121   void InitVertexAssociation( const SMESH_Hypothesis* theHyp,
122                               TShapeShapeMap &        theAssociationMap);
123
124   /*!
125    * \brief Inserts association theShape1 <-> theShape2 to TShapeShapeMap
126    * \param theShape1 - target shape
127    * \param theShape2 - source shape
128    * \param theAssociationMap - association map 
129    * \param theBidirectional - if false, inserts theShape1 -> theShape2 association
130    * \retval bool - true if there was no association for these shapes before
131    */
132   bool InsertAssociation( const TopoDS_Shape& theShape1, // target
133                           const TopoDS_Shape& theShape2, // source
134                           TShapeShapeMap &    theAssociationMap);
135
136   /*!
137    * \brief Finds an edge by its vertices in a main shape of the mesh
138    */
139   TopoDS_Edge GetEdgeByVertices( SMESH_Mesh*          aMesh,
140                                  const TopoDS_Vertex& V1,
141                                  const TopoDS_Vertex& V2);
142
143   /*!
144    * \brief Return another face sharing an edge
145    * \param edgeToFaces - data map of descendants to ancestors
146    */
147   TopoDS_Face GetNextFace( const TAncestorMap& edgeToFaces,
148                            const TopoDS_Edge&  edge,
149                            const TopoDS_Face&  face);
150   /*!
151    * \brief Return other vertex of an edge
152    */
153   TopoDS_Vertex GetNextVertex(const TopoDS_Edge&   edge,
154                               const TopoDS_Vertex& vertex);
155
156   /*!
157    * \brief Return an oriented propagation edge
158    * \param aMesh - mesh
159    * \param fromEdge - start edge for propagation
160    * \param chain - return, if provided, a propagation chain passed till
161    *        anEdge; if anEdge.IsNull() then a full propagation chain is returned
162    * \retval pair<int,TopoDS_Edge> - propagation step and found edge
163    */
164   std::pair<int,TopoDS_Edge> GetPropagationEdge( SMESH_Mesh*                 aMesh,
165                                                  const TopoDS_Edge&          anEdge,
166                                                  const TopoDS_Edge&          fromEdge,
167                                                  TopTools_IndexedMapOfShape* chain=0);
168
169   /*!
170    * \brief Find corresponding nodes on two faces
171    * \param face1 - the first face
172    * \param mesh1 - mesh containing elements on the first face
173    * \param face2 - the second face
174    * \param mesh2 - mesh containing elements on the second face
175    * \param assocMap - map associating sub-shapes of the faces
176    * \param nodeIn2OutMap - map containing found matching nodes
177    * \retval bool - is a success
178    */
179   bool FindMatchingNodesOnFaces( const TopoDS_Face&     face1,
180                                  SMESH_Mesh*            mesh1,
181                                  const TopoDS_Face&     face2,
182                                  SMESH_Mesh*            mesh2,
183                                  const TShapeShapeMap & assocMap,
184                                  TNodeNodeMap &         nodeIn2OutMap);
185   /*!
186    * \brief Return any sub-shape of a face belonging to the outer wire
187    * \param face - the face
188    * \param type - type of sub-shape to return
189    * \retval TopoDS_Shape - the found sub-shape
190    */
191   TopoDS_Shape OuterShape( const TopoDS_Face& face,
192                            TopAbs_ShapeEnum   type);
193
194   /*!
195    * \brief Check that submeshis is computed and try to compute it if is not
196    * \param sm - submesh to compute
197    * \param iterationNb - int used to stop infinite recursive call
198    * \retval bool - true if computed
199    */
200   bool MakeComputed(SMESH_subMesh * sm, const int iterationNb = 0);
201
202   /*!
203    * \brief Returns an error message to show in case if MakeComputed( sm ) fails.
204    */
205   std::string SourceNotComputedError( SMESH_subMesh * sm = 0,
206                                       SMESH_Algo*     projAlgo=0);
207
208   /*!
209    * \brief Set event listeners to submesh with projection algo
210    * \param subMesh - submesh with projection algo
211    * \param srcShape - source shape
212    * \param srcMesh - source mesh
213    */
214   void SetEventListener(SMESH_subMesh* subMesh,
215                         TopoDS_Shape   srcShape,
216                         SMESH_Mesh*    srcMesh);
217
218   /*!
219    * \brief Return a boundary EDGE (or all boundary EDGEs) of edgeContainer
220    */
221   TopoDS_Edge GetBoundaryEdge(const TopoDS_Shape&       edgeContainer,
222                               const SMESH_Mesh&         mesh,
223                               std::list< TopoDS_Edge >* allBndEdges = 0 );
224 };
225
226 #endif