Salome HOME
e047be38f346dedefc356bd3517b84588a82eb57
[modules/smesh.git] / src / SMESH / SMESH_Gen.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, 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 : implementaion 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
38 #include <map>
39 #include <list>
40 #include <set>
41 #include <vector>
42 #include <string>
43
44 #include <TopoDS_Shape.hxx>
45
46 class SMESHDS_Document;
47 class SMESH_Algo;
48 class SMESH_Mesh;
49 class TopoDS_Shape;
50 class SMESH_subMesh;
51
52 typedef SMESH_Hypothesis::Hypothesis_Status TAlgoStateErrorName;
53
54 typedef struct studyContextStruct
55 {
56   std::map < int, SMESH_Hypothesis * >mapHypothesis;
57   std::map < int, SMESH_Mesh * >mapMesh;
58   SMESHDS_Document * myDocument;
59 } StudyContextStruct;
60
61 typedef std::set<int> TSetOfInt;
62
63 class SMESH_EXPORT  SMESH_Gen
64 {
65 public:
66   SMESH_Gen();
67   ~SMESH_Gen();
68
69   SMESH_Mesh* CreateMesh(int theStudyId, bool theIsEmbeddedMode)
70     throw(SALOME_Exception);
71
72   /*!
73    * \brief Computes aMesh on aShape 
74    *  \param aShapeOnly - if true, algo->OnlyUnaryInput() feature is ignored and
75    *                      only \a aShape is computed.
76    *  \param anUpward - compute from vertices up to more complex shape (internal usage)
77    *  \param aDim - upper level dimension of the mesh computation
78    *  \param aShapesId - list of shapes with computed mesh entities (elements or nodes)
79    *  \retval bool - true if none submesh failed to compute
80    */
81   bool Compute(::SMESH_Mesh &        aMesh,
82                const TopoDS_Shape &  aShape,
83                const bool            aShapeOnly=false,
84                const bool            anUpward=false,
85                const ::MeshDimension aDim=::MeshDim_3D,
86                TSetOfInt*            aShapesId=0);
87
88   void PrepareCompute(::SMESH_Mesh &        aMesh,
89                       const TopoDS_Shape &  aShape);
90   void CancelCompute(::SMESH_Mesh &        aMesh,
91                      const TopoDS_Shape &  aShape);
92
93   const SMESH_subMesh* GetCurrentSubMesh() const;
94
95   /*!
96    * \brief evaluates size of prospective mesh on a shape 
97    * \param aMesh - the mesh
98    * \param aShape - the shape
99    * \param aResMap - map for prospective numbers of elements
100    * \retval bool - is a success
101    */
102   bool Evaluate(::SMESH_Mesh &        aMesh,
103                 const TopoDS_Shape &  aShape,
104                 MapShapeNbElems&      aResMap,
105                 const bool            anUpward=false,
106                 TSetOfInt*            aShapesId=0);
107
108   bool CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
109   // notify on bad state of attached algos, return false
110   // if Compute() would fail because of some algo bad state
111
112   /*!
113    * \brief Sets number of segments per diagonal of boundary box of geometry by which
114    *        default segment length of appropriate 1D hypotheses is defined
115    */
116   void SetBoundaryBoxSegmentation( int theNbSegments ) { _segmentation = theNbSegments; }
117   int  GetBoundaryBoxSegmentation() const { return _segmentation; }
118   /*!
119    * \brief Sets default number of segments per edge
120    */
121   void SetDefaultNbSegments(int nb) { _nbSegments = nb; }
122   int GetDefaultNbSegments() const { return _nbSegments; }
123
124   struct TAlgoStateError
125   {
126     TAlgoStateErrorName _name;
127     const SMESH_Algo*   _algo;
128     int                 _algoDim;
129     bool                _isGlobalAlgo;
130
131     TAlgoStateError(): _name(SMESH_Hypothesis::HYP_OK), _algo(0), _algoDim(0) {}
132     void Set(TAlgoStateErrorName name, const SMESH_Algo* algo, bool isGlobal)
133     { _name = name; _algo = algo; _algoDim = algo->GetDim(); _isGlobalAlgo = isGlobal; }
134     void Set(TAlgoStateErrorName name, const int algoDim,      bool isGlobal)
135     { _name = name; _algo = 0;    _algoDim = algoDim;        _isGlobalAlgo = isGlobal; }
136   };
137
138   bool GetAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
139                     std::list< SMESH_Gen::TAlgoStateError > & theErrors);
140   // notify on bad state of attached algos, return false
141   // if Compute() would fail because of some algo bad state
142   // theErrors list contains problems description
143
144   StudyContextStruct *GetStudyContext(int studyId);
145
146   static int GetShapeDim(const TopAbs_ShapeEnum & aShapeType);
147   static int GetShapeDim(const TopoDS_Shape &     aShape)
148   { return GetShapeDim( aShape.ShapeType() ); }
149
150   SMESH_Algo* GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape, TopoDS_Shape* assignedTo=0);
151   SMESH_Algo* GetAlgo(SMESH_subMesh * aSubMesh, TopoDS_Shape* assignedTo=0);
152
153   static bool IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh);
154
155   static std::vector< std::string > GetPluginXMLPaths();
156
157   int GetANewId();
158
159 private:
160
161   int _localId;                         // unique Id of created objects, within SMESH_Gen entity
162   std::map < int, StudyContextStruct * >_mapStudyContext;
163
164   // hypotheses managing
165   int _hypId;
166
167   // number of segments per diagonal of boundary box of geometry by which
168   // default segment length of appropriate 1D hypotheses is defined
169   int _segmentation;
170   // default number of segments
171   int _nbSegments;
172
173   void setCurrentSubMesh(SMESH_subMesh* sm);
174   void resetCurrentSubMesh();
175
176   volatile bool               _compute_canceled;
177   std::list< SMESH_subMesh* > _sm_current;
178 };
179
180 #endif