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"
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
37 #include <GeomAbs_Shape.hxx>
46 class SMESH_HypoFilter;
53 class SMESH_MesherHelper;
55 class SMESH_Algo:public SMESH_Hypothesis
59 * \brief Creates algorithm
60 * \param hypId - algorithm ID
61 * \param studyId - study ID
62 * \param gen - SMESH_Gen
64 SMESH_Algo(int hypId, int studyId, SMESH_Gen * gen);
69 virtual ~ SMESH_Algo();
72 * \brief Saves nothing in a stream
73 * \param save - the stream
74 * \retval virtual std::ostream & - the stream
76 virtual std::ostream & SaveTo(std::ostream & save);
79 * \brief Loads nothing from a stream
80 * \param load - the stream
81 * \retval virtual std::ostream & - the stream
83 virtual std::istream & LoadFrom(std::istream & load);
86 * \brief Returns all types of compatible hypotheses
88 const std::vector < std::string > & GetCompatibleHypothesis();
91 * \brief Check hypothesis definition to mesh a shape
92 * \param aMesh - the mesh
93 * \param aShape - the shape
94 * \param aStatus - check result
95 * \retval bool - true if hypothesis is well defined
97 virtual bool CheckHypothesis(SMESH_Mesh& aMesh,
98 const TopoDS_Shape& aShape,
99 SMESH_Hypothesis::Hypothesis_Status& aStatus) = 0;
101 * \brief Computes mesh on a shape
102 * \param aMesh - the mesh
103 * \param aShape - the shape
104 * \retval bool - is a success
106 virtual bool Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape) = 0;
109 * \brief Computes mesh without geometry
110 * \param aMesh - the mesh
111 * \param aHelper - helper that must be used for adding elements to \aaMesh
112 * \retval bool - is a success
114 * The method is called if ( !aMesh->HasShapeToMesh() )
116 virtual bool Compute(SMESH_Mesh & aMesh, SMESH_MesherHelper* aHelper);
119 * \brief Returns a list of compatible hypotheses used to mesh a shape
120 * \param aMesh - the mesh
121 * \param aShape - the shape
122 * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
123 * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
125 * List the hypothesis used by the algorithm associated to the shape.
126 * Hypothesis associated to father shape -are- taken into account (see
127 * GetAppliedHypothesis). Relevant hypothesis have a name (type) listed in
128 * the algorithm. This method could be surcharged by specific algorithms, in
129 * case of several hypothesis simultaneously applicable.
131 virtual const std::list <const SMESHDS_Hypothesis *> &
132 GetUsedHypothesis(SMESH_Mesh & aMesh,
133 const TopoDS_Shape & aShape,
134 const bool ignoreAuxiliary=true);
136 * \brief Returns a list of compatible hypotheses assigned to a shape in a mesh
137 * \param aMesh - the mesh
138 * \param aShape - the shape
139 * \param ignoreAuxiliary - do not include auxiliary hypotheses in the list
140 * \retval const std::list <const SMESHDS_Hypothesis*> - hypotheses list
142 * List the relevant hypothesis associated to the shape. Relevant hypothesis
143 * have a name (type) listed in the algorithm. Hypothesis associated to
144 * father shape -are not- taken into account (see GetUsedHypothesis)
146 const list <const SMESHDS_Hypothesis *> &
147 GetAppliedHypothesis(SMESH_Mesh & aMesh,
148 const TopoDS_Shape & aShape,
149 const bool ignoreAuxiliary=true);
151 * \brief Make the filter recognize only compatible hypotheses
152 * \param theFilter - the filter to initialize
153 * \param ignoreAuxiliary - make filter ignore compatible auxiliary hypotheses
154 * \retval bool - true if the algo has compatible hypotheses
156 bool InitCompatibleHypoFilter( SMESH_HypoFilter & theFilter,
157 const bool ignoreAuxiliary) const;
159 * \brief Initialize my parameter values by the mesh built on the geometry
160 * \param theMesh - the built mesh
161 * \param theShape - the geometry of interest
162 * \retval bool - true if parameter values have been successfully defined
164 * Just return false as the algorithm does not hold parameters values
166 virtual bool SetParametersByMesh(const SMESH_Mesh* theMesh,
167 const TopoDS_Shape& theShape);
171 // ==================================================================
172 // Algo features influencing how Compute() is called:
173 // in what turn and with what input shape
174 // ==================================================================
176 // SMESH_Hypothesis::GetDim();
177 // 1 - dimention of target mesh
179 bool OnlyUnaryInput() const { return _onlyUnaryInput; }
180 // 2 - is collection of tesselatable shapes inacceptable as input;
181 // "collection" means a shape containing shapes of dim equal
183 // Algo which can process a collection shape should expect
184 // an input temporary shape that is neither MainShape nor
187 bool NeedDescretBoundary() const { return _requireDescretBoundary; }
188 // 3 - is a Dim-1 mesh prerequisite
190 bool NeedShape() const { return _requireShape; }
191 // 4 - is shape existance required
194 // ==================================================================
195 // Methods to track non hierarchical dependencies between submeshes
196 // ==================================================================
199 * \brief Sets event listener to submeshes if necessary
200 * \param subMesh - submesh where algo is set
202 * This method is called when a submesh gets HYP_OK algo_state.
203 * After being set, event listener is notified on each event of a submesh.
204 * By default non listener is set
206 virtual void SetEventListener(SMESH_subMesh* subMesh);
209 * \brief Allow algo to do something after persistent restoration
210 * \param subMesh - restored submesh
212 * This method is called only if a submesh has HYP_OK algo_state.
214 virtual void SubmeshRestored(SMESH_subMesh* subMesh);
217 // ==================================================================
218 // Common algo utilities
219 // ==================================================================
221 * \brief Fill vector of node parameters on geometrical edge, including vertex nodes
222 * \param theMesh - The mesh containing nodes
223 * \param theEdge - The geometrical edge of interest
224 * \param theParams - The resulting vector of sorted node parameters
225 * \retval bool - false if not all parameters are OK
227 static bool GetNodeParamOnEdge(const SMESHDS_Mesh* theMesh,
228 const TopoDS_Edge& theEdge,
229 std::vector< double > & theParams);
231 * \brief Find out elements orientation on a geometrical face
232 * \param theFace - The face correctly oriented in the shape being meshed
233 * \param theMeshDS - The mesh data structure
234 * \retval bool - true if the face normal and the normal of first element
235 * in the correspoding submesh point in different directions
237 static bool IsReversedSubMesh (const TopoDS_Face& theFace,
238 SMESHDS_Mesh* theMeshDS);
240 * \brief Compute length of an edge
241 * \param E - the edge
242 * \retval double - the length
244 static double EdgeLength(const TopoDS_Edge & E);
247 * \brief Return continuity of two edges
248 * \param E1 - the 1st edge
249 * \param E2 - the 2nd edge
250 * \retval GeomAbs_Shape - regularity at the junction between E1 and E2
252 static GeomAbs_Shape Continuity(const TopoDS_Edge & E1,
253 const TopoDS_Edge & E2);
256 * \brief Return the node built on a vertex
257 * \param V - the vertex
258 * \param meshDS - mesh
259 * \retval const SMDS_MeshNode* - found node or NULL
261 static const SMDS_MeshNode* VertexNode(const TopoDS_Vertex& V,
262 SMESHDS_Mesh* meshDS);
265 std::vector<std::string> _compatibleHypothesis;
266 std::list<const SMESHDS_Hypothesis *> _appliedHypList;
267 std::list<const SMESHDS_Hypothesis *> _usedHypList;
269 bool _onlyUnaryInput;
270 bool _requireDescretBoundary;
273 // quadratic mesh creation required