Salome HOME
Merging with WPdev
[modules/smesh.git] / src / SMESH / SMESH_Algo.hxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
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   : SMESH_Algo.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef _SMESH_ALGO_HXX_
30 #define _SMESH_ALGO_HXX_
31
32 #include "SMESH_SMESH.hxx"
33
34 #include "SMESH_Hypothesis.hxx"
35
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <gp_XY.hxx>
39
40 #include <string>
41 #include <vector>
42 #include <list>
43 #include <map>
44
45 class SMESH_Gen;
46 class SMESH_Mesh;
47 class SMESH_HypoFilter;
48 class TopoDS_Face;
49 class TopoDS_Shape;
50 class SMESHDS_Mesh;
51 class SMDS_MeshNode;
52 class SMESH_subMesh;
53
54 class SMESH_EXPORT SMESH_Algo:public SMESH_Hypothesis
55 {
56 public:
57   /*!
58    * \brief Creates algorithm
59     * \param hypId - algorithm ID
60     * \param studyId - study ID
61     * \param gen - SMESH_Gen
62    */
63   SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
64
65   /*!
66    * \brief Destructor
67    */
68   virtual ~ SMESH_Algo();
69
70   /*!
71    * \brief Saves nothing in a stream
72     * \param save - the stream
73     * \retval virtual std::ostream & - the stream
74    */
75   virtual std::ostream & SaveTo(std::ostream & save);
76
77   /*!
78    * \brief Loads nothing from a stream
79     * \param load - the stream
80     * \retval virtual std::ostream & - the stream
81    */
82   virtual std::istream & LoadFrom(std::istream & load);
83
84   /*!
85    * \brief Returns all types of compatible hypotheses
86    */
87   const std::vector < std::string > & GetCompatibleHypothesis();
88
89   /*!
90    * \brief Check hypothesis definition to mesh a shape
91     * \param aMesh - the mesh
92     * \param aShape - the shape
93     * \param aStatus - check result
94     * \retval bool - true if hypothesis is well defined
95    */
96   virtual bool CheckHypothesis(SMESH_Mesh&                          aMesh,
97                                const TopoDS_Shape&                  aShape,
98                                SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
99   /*!
100    * \brief Computes mesh on a shape
101     * \param aMesh - the mesh
102     * \param aShape - the shape
103     * \retval bool - is a success
104    */
105   virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
106
107   /*!
108    * \brief Returns a list of compatible hypotheses used to mesh a shape
109     * \param aMesh - the mesh 
110     * \param aShape - the shape
111     * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
112     * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
113    * 
114    *  List the hypothesis used by the algorithm associated to the shape.
115    *  Hypothesis associated to father shape -are- taken into account (see
116    *  GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
117    *  the algorithm. This method could be surcharged by specific algorithms, in 
118    *  case of several hypothesis simultaneously applicable.
119    */
120   virtual const std::list <const SMESHDS_Hypothesis *> &
121   GetUsedHypothesis(SMESH_Mesh &         aMesh,
122                     const TopoDS_Shape & aShape,
123                     const bool           ignoreAuxiliary=true);
124   /*!
125    * \brief Returns a list of compatible hypotheses assigned to a shape in a mesh
126     * \param aMesh - the mesh 
127     * \param aShape - the shape
128     * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
129     * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
130    * 
131    *  List the relevant hypothesis associated to the shape. Relevant hypothesis
132    *  have a name (type) listed in the algorithm. Hypothesis associated to
133    *  father shape -are not- taken into account (see GetUsedHypothesis)
134    */
135   const list <const SMESHDS_Hypothesis *> &
136   GetAppliedHypothesis(SMESH_Mesh &         aMesh,
137                        const TopoDS_Shape & aShape,
138                        const bool           ignoreAuxiliary=true);
139   /*!
140    * \brief Make the filter recognize only compatible hypotheses
141    * \param theFilter - the filter to initialize
142    * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
143    * \retval bool - true if the algo has compatible hypotheses
144    */
145   bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
146                                  const bool         ignoreAuxiliary) const;
147   /*!
148    * \brief Initialize my parameter values by the mesh built on the geometry
149    * \param theMesh - the built mesh
150    * \param theShape - the geometry of interest
151    * \retval bool - true if parameter values have been successfully defined
152    *
153    * Just return false as the algorithm does not hold parameters values
154    */
155   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh,
156                                    const TopoDS_Shape& theShape);
157
158
159 public:
160   // ==================================================================
161   // Algo features influencing how Compute() is called:
162   // in what turn and with what input shape
163   // ==================================================================
164
165   // SMESH_Hypothesis::GetDim();
166   // 1 - dimention of target mesh
167
168   bool OnlyUnaryInput() const { return _onlyUnaryInput; }
169   // 2 - is collection of tesselatable shapes inacceptable as input;
170   // "collection" means a shape containing shapes of dim equal
171   // to GetDim().
172   // Algo which can process a collection shape should expect
173   // an input temporary shape that is neither MainShape nor
174   // its child.
175
176   bool NeedDescretBoundary() const { return _requireDescretBoundary; }
177   // 3 - is a Dim-1 mesh prerequisite
178
179 public:
180   // ==================================================================
181   // Methods to track non hierarchical dependencies between submeshes 
182   // ==================================================================
183
184   /*!
185    * \brief Sets event listener to submeshes if necessary
186     * \param subMesh - submesh where algo is set
187    *
188    * This method is called when a submesh gets HYP_OK algo_state.
189    * After being set, event listener is notified on each event of a submesh.
190    * By default non listener is set
191    */
192   virtual void SetEventListener(SMESH_subMesh* subMesh);
193   
194 public:
195   // ==================================================================
196   // Common algo utilities
197   // ==================================================================
198   /*!
199    * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
200    * \param theMesh - The mesh containing nodes
201    * \param theEdge - The geometrical edge of interest
202    * \param theParams - The resulting vector of sorted node parameters
203    * \retval bool - false if not all parameters are OK
204    */
205   static bool GetNodeParamOnEdge(const SMESHDS_Mesh*     theMesh,
206                                  const TopoDS_Edge&      theEdge,
207                                  std::vector< double > & theParams);
208   /*!
209    * \brief Find out elements orientation on a geometrical face
210    * \param theFace - The face correctly oriented in the shape being meshed
211    * \param theMeshDS - The mesh data structure
212    * \retval bool - true if the face normal and the normal of first element
213    *                in the correspoding submesh point in different directions
214    */
215   static bool IsReversedSubMesh (const TopoDS_Face&  theFace,
216                                  SMESHDS_Mesh*       theMeshDS);
217   /*!
218    * \brief Compute length of an edge
219     * \param E - the edge
220     * \retval double - the length
221    */
222   static double EdgeLength(const TopoDS_Edge & E);
223
224
225 protected:
226   bool _onlyUnaryInput;
227   bool _requireDescretBoundary;
228   std::vector<std::string> _compatibleHypothesis;
229   std::list<const SMESHDS_Hypothesis *> _appliedHypList;
230   std::list<const SMESHDS_Hypothesis *> _usedHypList;
231
232   // quadratic mesh creation required
233   bool _quadraticMesh;
234 };
235
236 #endif