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