Salome HOME
PAL14921 (memory limitation and Salome freeze)
[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_Hypothesis.hxx"
33 #include "SMESH_ComputeError.hxx"
34 #include "SMESH_Comment.hxx"
35
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <GeomAbs_Shape.hxx>
39
40 #include <string>
41 #include <vector>
42 #include <list>
43
44 class SMESH_Gen;
45 class SMESH_Mesh;
46 class SMESH_HypoFilter;
47 class TopoDS_Vertex;
48 class TopoDS_Face;
49 class TopoDS_Shape;
50 class SMESHDS_Mesh;
51 class SMDS_MeshNode;
52 class SMESH_subMesh;
53 class SMESH_MesherHelper;
54
55
56 class SMESH_Algo:public SMESH_Hypothesis
57 {
58 public:
59   /*!
60    * \brief Creates algorithm
61     * \param hypId - algorithm ID
62     * \param studyId - study ID
63     * \param gen - SMESH_Gen
64    */
65   SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
66
67   /*!
68    * \brief Destructor
69    */
70   virtual ~ SMESH_Algo();
71
72   /*!
73    * \brief Saves nothing in a stream
74     * \param save - the stream
75     * \retval virtual std::ostream & - the stream
76    */
77   virtual std::ostream & SaveTo(std::ostream & save);
78
79   /*!
80    * \brief Loads nothing from a stream
81     * \param load - the stream
82     * \retval virtual std::ostream & - the stream
83    */
84   virtual std::istream & LoadFrom(std::istream & load);
85
86   /*!
87    * \brief Returns all types of compatible hypotheses
88    */
89   const std::vector < std::string > & GetCompatibleHypothesis();
90
91   /*!
92    * \brief Check hypothesis definition to mesh a shape
93     * \param aMesh - the mesh
94     * \param aShape - the shape
95     * \param aStatus - check result
96     * \retval bool - true if hypothesis is well defined
97    */
98   virtual bool CheckHypothesis(SMESH_Mesh&                          aMesh,
99                                const TopoDS_Shape&                  aShape,
100                                SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
101   /*!
102    * \brief Computes mesh on a shape
103     * \param aMesh - the mesh
104     * \param aShape - the shape
105     * \retval bool - is a success
106     *
107     * Algorithms that !NeedDescretBoundary() || !OnlyUnaryInput() are
108     * to set SMESH_ComputeError returned by SMESH_submesh::GetComputeError()
109     * to report problematic subshapes
110    */
111   virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
112
113   /*!
114    * \brief Computes mesh without geometry
115     * \param aMesh - the mesh
116     * \param aHelper - helper that must be used for adding elements to \aaMesh
117     * \retval bool - is a success
118     *
119     * The method is called if ( !aMesh->HasShapeToMesh() )
120    */
121   virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
122
123   /*!
124    * \brief Returns a list of compatible hypotheses used to mesh a shape
125     * \param aMesh - the mesh 
126     * \param aShape - the shape
127     * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
128     * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
129    * 
130    *  List the hypothesis used by the algorithm associated to the shape.
131    *  Hypothesis associated to father shape -are- taken into account (see
132    *  GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
133    *  the algorithm. This method could be surcharged by specific algorithms, in 
134    *  case of several hypothesis simultaneously applicable.
135    */
136   virtual const std::list <const SMESHDS_Hypothesis *> &
137   GetUsedHypothesis(SMESH_Mesh &         aMesh,
138                     const TopoDS_Shape & aShape,
139                     const bool           ignoreAuxiliary=true);
140   /*!
141    * \brief Returns a list of compatible hypotheses assigned to a shape in a mesh
142     * \param aMesh - the mesh 
143     * \param aShape - the shape
144     * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
145     * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
146    * 
147    *  List the relevant hypothesis associated to the shape. Relevant hypothesis
148    *  have a name (type) listed in the algorithm. Hypothesis associated to
149    *  father shape -are not- taken into account (see GetUsedHypothesis)
150    */
151   const list <const SMESHDS_Hypothesis *> &
152   GetAppliedHypothesis(SMESH_Mesh &         aMesh,
153                        const TopoDS_Shape & aShape,
154                        const bool           ignoreAuxiliary=true);
155   /*!
156    * \brief Make the filter recognize only compatible hypotheses
157    * \param theFilter - the filter to initialize
158    * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
159    * \retval bool - true if the algo has compatible hypotheses
160    */
161   bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
162                                  const bool         ignoreAuxiliary) const;
163   /*!
164    * \brief Initialize my parameter values by the mesh built on the geometry
165    *
166    * Just return false as the algorithm does not hold parameters values
167    */
168   virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh,
169                                    const TopoDS_Shape& theShape);
170   /*!
171    * \brief return compute error
172    */
173   SMESH_ComputeErrorPtr GetComputeError() const;
174   /*!
175    * \brief initialize compute error
176    */
177   void InitComputeError();
178
179 public:
180   // ==================================================================
181   // Algo features influencing how Compute() is called:
182   // in what turn and with what input shape
183   // ==================================================================
184
185   // SMESH_Hypothesis::GetDim();
186   // 1 - dimention of target mesh
187
188   bool OnlyUnaryInput() const { return _onlyUnaryInput; }
189   // 2 - is collection of tesselatable shapes inacceptable as input;
190   // "collection" means a shape containing shapes of dim equal
191   // to GetDim().
192   // Algo which can process a collection shape should expect
193   // an input temporary shape that is neither MainShape nor
194   // its child.
195
196   bool NeedDescretBoundary() const { return _requireDescretBoundary; }
197   // 3 - is a Dim-1 mesh prerequisite
198
199   bool NeedShape() const { return _requireShape; }
200   // 4 - is shape existance required
201
202 public:
203   // ==================================================================
204   // Methods to track non hierarchical dependencies between submeshes 
205   // ==================================================================
206
207   /*!
208    * \brief Sets event listener to submeshes if necessary
209     * \param subMesh - submesh where algo is set
210    *
211    * This method is called when a submesh gets HYP_OK algo_state.
212    * After being set, event listener is notified on each event of a submesh.
213    * By default non listener is set
214    */
215   virtual void SetEventListener(SMESH_subMesh* subMesh);
216   
217   /*!
218    * \brief Allow algo to do something after persistent restoration
219     * \param subMesh - restored submesh
220    *
221    * This method is called only if a submesh has HYP_OK algo_state.
222    */
223   virtual void SubmeshRestored(SMESH_subMesh* subMesh);
224   
225 public:
226   // ==================================================================
227   // Common algo utilities
228   // ==================================================================
229   /*!
230    * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
231    * \param theMesh - The mesh containing nodes
232    * \param theEdge - The geometrical edge of interest
233    * \param theParams - The resulting vector of sorted node parameters
234    * \retval bool - false if not all parameters are OK
235    */
236   static bool GetNodeParamOnEdge(const SMESHDS_Mesh*     theMesh,
237                                  const TopoDS_Edge&      theEdge,
238                                  std::vector< double > & theParams);
239   /*!
240    * \brief Find out elements orientation on a geometrical face
241    * \param theFace - The face correctly oriented in the shape being meshed
242    * \param theMeshDS - The mesh data structure
243    * \retval bool - true if the face normal and the normal of first element
244    *                in the correspoding submesh point in different directions
245    */
246   static bool IsReversedSubMesh (const TopoDS_Face&  theFace,
247                                  SMESHDS_Mesh*       theMeshDS);
248   /*!
249    * \brief Compute length of an edge
250     * \param E - the edge
251     * \retval double - the length
252    */
253   static double EdgeLength(const TopoDS_Edge & E);
254
255   /*!
256    * \brief Return continuity of two edges
257     * \param E1 - the 1st edge
258     * \param E2 - the 2nd edge
259     * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
260    */
261   static GeomAbs_Shape Continuity(const TopoDS_Edge & E1,
262                                   const TopoDS_Edge & E2);
263
264   /*!
265    * \brief Return the node built on a vertex
266     * \param V - the vertex
267     * \param meshDS - mesh
268     * \retval const SMDS_MeshNode* - found node or NULL
269    */
270   static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
271                                          SMESHDS_Mesh*        meshDS);
272
273 protected:
274
275   /*!
276    * \brief store error and comment and then return ( error == COMPERR_OK )
277    */
278   bool error(int error, const SMESH_Comment& comment = "");
279   /*!
280    * \brief store COMPERR_ALGO_FAILED error and comment and then return false
281    */
282   bool error(const SMESH_Comment& comment = "")
283   { return error(COMPERR_ALGO_FAILED, comment); }
284   /*!
285    * \brief store error and return error->IsOK()
286    */
287   bool error(SMESH_ComputeErrorPtr error);
288
289 protected:
290
291   std::vector<std::string>              _compatibleHypothesis;
292   std::list<const SMESHDS_Hypothesis *> _appliedHypList;
293   std::list<const SMESHDS_Hypothesis *> _usedHypList;
294
295   bool _onlyUnaryInput;
296   bool _requireDescretBoundary;
297   bool _requireShape;
298
299   // quadratic mesh creation required,
300   // is usually set trough SMESH_MesherHelper::IsQuadraticSubMesh()
301   bool _quadraticMesh;
302
303   int         _error;    //!< SMESH_ComputeErrorName or anything algo specific
304   std::string _comment;  //!< any text explaining what is wrong in Compute()
305 };
306
307 #endif