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