Salome HOME
Merge branch 'V9_11_BR'
[modules/smesh.git] / src / SMESH / SMESH_Gen.hxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 //  SMESH SMESH : implementation of SMESH idl descriptions
24 //  File   : SMESH_Gen.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //
28 #ifndef _SMESH_GEN_HXX_
29 #define _SMESH_GEN_HXX_
30
31 #include "SMESH_SMESH.hxx"
32
33 #include "Utils_SALOME_Exception.hxx"
34
35 #include "SMESH_Algo.hxx"
36 #include "SMESH_ComputeError.hxx"
37 #include "SMESH_subMesh.hxx"
38
39 #include <map>
40 #include <list>
41 #include <set>
42 #include <vector>
43 #include <string>
44
45
46 #include <TopoDS_Shape.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
48
49 class SMESHDS_Document;
50 class SMESH_Algo;
51 class SMESH_Mesh;
52 class TopoDS_Shape;
53
54
55 typedef SMESH_Hypothesis::Hypothesis_Status TAlgoStateErrorName;
56
57 typedef struct studyContextStruct
58 {
59   std::map < int, SMESH_Hypothesis * >mapHypothesis;
60   std::map < int, SMESH_Mesh * >mapMesh;
61   SMESHDS_Document * myDocument;
62 } StudyContextStruct;
63
64 typedef std::set<int> TSetOfInt;
65
66 class SMESH_EXPORT SMESH_Gen
67 {
68 public:
69   SMESH_Gen();
70   ~SMESH_Gen();
71
72   SMESH_Mesh* CreateMesh(bool theIsEmbeddedMode);
73   SMESH_Mesh* CreateParallelMesh(bool theIsEmbeddedMode);
74
75   enum ComputeFlags
76   {
77     SHAPE_ONLY        = 1, // to ignore algo->OnlyUnaryInput() feature and to compute a given shape only.
78     UPWARD            = 2, // to compute from vertices up to more complex shape (internal usage)
79     COMPACT_MESH      = 4, // to compact the mesh at the end
80     SHAPE_ONLY_UPWARD = 3  // SHAPE_ONLY | UPWARD
81   };
82   /*!
83    * \brief Computes aMesh on aShape
84    *  \param aMesh - the mesh.
85    *  \param aShape - the shape.
86    *  \param aFlags - ComputeFlags. By default compute the whole mesh and compact at the end.
87    *  \param aDim - upper level dimension of the mesh computation (for preview)
88    *  \param aShapesId - list of shapes with computed mesh entities (elements or nodes)
89    *  \param anAllowedSubShapes - shapes to mesh only. Mesh all if empty or nullptr
90    *  \retval bool - true if none sub-mesh failed to compute
91    */
92   bool Compute(::SMESH_Mesh &              aMesh,
93                const TopoDS_Shape &        aShape,
94                const int                   aFlags = COMPACT_MESH,
95                const ::MeshDimension       aDim=::MeshDim_3D,
96                TSetOfInt*                  aShapesId=0,
97                TopTools_IndexedMapOfShape* anAllowedSubShapes=0);
98
99   void PrepareCompute(::SMESH_Mesh &        aMesh,
100                       const TopoDS_Shape &  aShape);
101   void CancelCompute(::SMESH_Mesh &        aMesh,
102                      const TopoDS_Shape &  aShape);
103
104   const SMESH_subMesh* GetCurrentSubMesh() const;
105
106   /*!
107    * \brief evaluates size of prospective mesh on a shape
108    * \param aMesh - the mesh
109    * \param aShape - the shape
110    * \param aResMap - map for prospective numbers of elements
111    * \retval bool - is a success
112    */
113   bool Evaluate(::SMESH_Mesh &        aMesh,
114                 const TopoDS_Shape &  aShape,
115                 MapShapeNbElems&      aResMap,
116                 const bool            anUpward=false,
117                 TSetOfInt*            aShapesId=0);
118
119   bool CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
120   // notify on bad state of attached algos, return false
121   // if Compute() would fail because of some algo bad state
122
123   /*!
124    * \brief Sets number of segments per diagonal of boundary box of geometry by which
125    *        default segment length of appropriate 1D hypotheses is defined
126    */
127   void SetBoundaryBoxSegmentation( int theNbSegments ) { _segmentation = theNbSegments; }
128   int  GetBoundaryBoxSegmentation() const { return _segmentation; }
129   /*!
130    * \brief Sets default number of segments per edge
131    */
132   void SetDefaultNbSegments(int nb) { _nbSegments = nb; }
133   int GetDefaultNbSegments() const { return _nbSegments; }
134
135   struct TAlgoStateError
136   {
137     TAlgoStateErrorName _name;
138     const SMESH_Algo*   _algo;
139     int                 _algoDim;
140     bool                _isGlobalAlgo;
141
142     TAlgoStateError(): _name(SMESH_Hypothesis::HYP_OK), _algo(0), _algoDim(0) {}
143     void Set(TAlgoStateErrorName name, const SMESH_Algo* algo, bool isGlobal)
144     { _name = name; _algo = algo; _algoDim = algo->GetDim(); _isGlobalAlgo = isGlobal; }
145     void Set(TAlgoStateErrorName name, const int algoDim,      bool isGlobal)
146     { _name = name; _algo = 0;    _algoDim = algoDim;        _isGlobalAlgo = isGlobal; }
147   };
148
149   bool GetAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
150                     std::list< SMESH_Gen::TAlgoStateError > & theErrors);
151   // notify on bad state of attached algos, return false
152   // if Compute() would fail because of some algo bad state
153   // theErrors list contains problems description
154
155   StudyContextStruct *GetStudyContext();
156
157   static int GetShapeDim(const TopAbs_ShapeEnum & aShapeType);
158   static int GetShapeDim(const TopoDS_Shape &     aShape)
159   { return GetShapeDim( aShape.ShapeType() ); }
160   static int GetFlatShapeDim(const TopoDS_Shape &aShape);
161
162   SMESH_Algo* GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape, TopoDS_Shape* assignedTo=0);
163   SMESH_Algo* GetAlgo(SMESH_subMesh * aSubMesh, TopoDS_Shape* assignedTo=0);
164
165   static bool IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh);
166
167   static std::vector< std::string > GetPluginXMLPaths();
168
169   int GetANewId();
170
171 public:
172   bool parallelComputeSubMeshes(
173           SMESH_Mesh & aMesh,
174           const TopoDS_Shape & aShape,
175           const ::MeshDimension       aDim,
176           TSetOfInt*                  aShapesId,
177           TopTools_IndexedMapOfShape* allowedSubShapes,
178           SMESH_subMesh::compute_event &computeEvent,
179           const bool includeSelf,
180           const bool complexShapeFirst,
181           const bool   aShapeOnly);
182
183   bool sequentialComputeSubMeshes(
184           SMESH_Mesh & aMesh,
185           const TopoDS_Shape & aShape,
186           const ::MeshDimension       aDim,
187           TSetOfInt*                  aShapesId /*=0*/,
188           TopTools_IndexedMapOfShape* allowedSubShapes,
189           SMESH_subMesh::compute_event &computeEvent,
190           const bool includeSelf,
191           const bool complexShapeFirst,
192           const bool aShapeOnly);
193
194 private:
195
196
197
198   int _localId;                         // unique Id of created objects, within SMESH_Gen entity
199   StudyContextStruct* _studyContext;
200
201   // hypotheses managing
202   int _hypId;
203
204   // number of segments per diagonal of boundary box of geometry by which
205   // default segment length of appropriate 1D hypotheses is defined
206   int _segmentation;
207   // default number of segments
208   int _nbSegments;
209
210   void setCurrentSubMesh(SMESH_subMesh* sm);
211   void resetCurrentSubMesh();
212
213   volatile bool               _compute_canceled;
214   std::list< SMESH_subMesh* > _sm_current;
215 };
216
217 #endif