1 // SMESH SMESH : implementaion of SMESH idl descriptions
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESH_Algo.hxx
25 // Author : Paul RASCLE, EDF
29 #ifndef _SMESH_ALGO_HXX_
30 #define _SMESH_ALGO_HXX_
32 #include "SMESH_Hypothesis.hxx"
33 #include "SMESH_ComputeError.hxx"
34 #include "SMESH_Comment.hxx"
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <GeomAbs_Shape.hxx>
46 class SMESH_HypoFilter;
53 class SMESH_MesherHelper;
56 class SMESH_Algo:public SMESH_Hypothesis
60 * \brief Creates algorithm
61 * \param hypId - algorithm ID
62 * \param studyId - study ID
63 * \param gen - SMESH_Gen
65 SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
70 virtual ~ SMESH_Algo();
73 * \brief Saves nothing in a stream
74 * \param save - the stream
75 * \retval virtual std::ostream & - the stream
77 virtual std::ostream & SaveTo(std::ostream & save);
80 * \brief Loads nothing from a stream
81 * \param load - the stream
82 * \retval virtual std::ostream & - the stream
84 virtual std::istream & LoadFrom(std::istream & load);
87 * \brief Returns all types of compatible hypotheses
89 const std::vector < std::string > & GetCompatibleHypothesis();
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
98 virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
99 const TopoDS_Shape& aShape,
100 SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
102 * \brief Computes mesh on a shape
103 * \param aMesh - the mesh
104 * \param aShape - the shape
105 * \retval bool - is a success
107 * Algorithms that !NeedDescretBoundary() || !OnlyUnaryInput() are
108 * to set SMESH_ComputeError returned by SMESH_submesh::GetComputeError()
109 * to report problematic subshapes
111 virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
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
119 * The method is called if ( !aMesh->HasShapeToMesh() )
121 virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
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
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.
136 virtual const std::list <const SMESHDS_Hypothesis *> &
137 GetUsedHypothesis(SMESH_Mesh & aMesh,
138 const TopoDS_Shape & aShape,
139 const bool ignoreAuxiliary=true);
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
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)
151 const list <const SMESHDS_Hypothesis *> &
152 GetAppliedHypothesis(SMESH_Mesh & aMesh,
153 const TopoDS_Shape & aShape,
154 const bool ignoreAuxiliary=true);
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
161 bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
162 const bool ignoreAuxiliary) const;
164 * \brief Initialize my parameter values by the mesh built on the geometry
166 * Just return false as the algorithm does not hold parameters values
168 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh,
169 const TopoDS_Shape& theShape);
171 * \brief return compute error
173 SMESH_ComputeErrorPtr GetComputeError() const;
175 * \brief initialize compute error
177 void InitComputeError();
180 // ==================================================================
181 // Algo features influencing how Compute() is called:
182 // in what turn and with what input shape
183 // ==================================================================
185 // SMESH_Hypothesis::GetDim();
186 // 1 - dimention of target mesh
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
192 // Algo which can process a collection shape should expect
193 // an input temporary shape that is neither MainShape nor
196 bool NeedDescretBoundary() const { return _requireDescretBoundary; }
197 // 3 - is a Dim-1 mesh prerequisite
199 bool NeedShape() const { return _requireShape; }
200 // 4 - is shape existance required
203 // ==================================================================
204 // Methods to track non hierarchical dependencies between submeshes
205 // ==================================================================
208 * \brief Sets event listener to submeshes if necessary
209 * \param subMesh - submesh where algo is set
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
215 virtual void SetEventListener(SMESH_subMesh* subMesh);
218 * \brief Allow algo to do something after persistent restoration
219 * \param subMesh - restored submesh
221 * This method is called only if a submesh has HYP_OK algo_state.
223 virtual void SubmeshRestored(SMESH_subMesh* subMesh);
226 // ==================================================================
227 // Common algo utilities
228 // ==================================================================
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
236 static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
237 const TopoDS_Edge& theEdge,
238 std::vector< double > & theParams);
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
246 static bool IsReversedSubMesh (const TopoDS_Face& theFace,
247 SMESHDS_Mesh* theMeshDS);
249 * \brief Compute length of an edge
250 * \param E - the edge
251 * \retval double - the length
253 static double EdgeLength(const TopoDS_Edge & E);
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
261 static GeomAbs_Shape Continuity(const TopoDS_Edge & E1,
262 const TopoDS_Edge & E2);
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
270 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
271 SMESHDS_Mesh* meshDS);
276 * \brief store error and comment and then return ( error == COMPERR_OK )
278 bool error(int error, const SMESH_Comment& comment = "");
280 * \brief To be used as error in previous method
282 SMESH_ComputeErrorName dfltErr() const { return COMPERR_ALGO_FAILED; }
284 * \brief store error and return error->IsOK()
286 bool error(SMESH_ComputeErrorPtr error);
290 std::vector<std::string> _compatibleHypothesis;
291 std::list<const SMESHDS_Hypothesis *> _appliedHypList;
292 std::list<const SMESHDS_Hypothesis *> _usedHypList;
294 bool _onlyUnaryInput;
295 bool _requireDescretBoundary;
298 // quadratic mesh creation required,
299 // is usually set trough SMESH_MesherHelper::IsQuadraticSubMesh()
302 int _error; //!< SMESH_ComputeErrorName or anything algo specific
303 std::string _comment; //!< any text explaining what is wrong in Compute()