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