Salome HOME
Imp 19925 - Mesh preview
[modules/smesh.git] / src / SMESH / SMESH_Gen.hxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  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 //
24 //  File   : SMESH_Gen.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef _SMESH_GEN_HXX_
30 #define _SMESH_GEN_HXX_
31
32 #include "SMESH_SMESH.hxx"
33
34 #include "Utils_SALOME_Exception.hxx"
35
36 #include "SMESH_Hypothesis.hxx"
37 #include "SMESH_ComputeError.hxx"
38 #include "SMESH_Algo.hxx"
39 #include "SMESH_0D_Algo.hxx"
40 #include "SMESH_1D_Algo.hxx"
41 #include "SMESH_2D_Algo.hxx"
42 #include "SMESH_3D_Algo.hxx"
43 #include "SMESH_Mesh.hxx"
44
45 #include <TopoDS_Shape.hxx>
46
47 #include <map>
48 #include <list>
49
50 class SMESHDS_Document;
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 anUpward - compute from vertices up to more complex shape (internal usage)
75    *  \param aDim - upper level dimension of the mesh computation
76    *  \param aShapesId - list of shapes with computed mesh entities (elements or nodes)
77    *  \retval bool - true if none submesh failed to compute
78    */
79   bool Compute(::SMESH_Mesh &        aMesh,
80                const TopoDS_Shape &  aShape,
81                const bool            anUpward=false,
82                const ::MeshDimension aDim=::MeshDim_3D,
83                TSetOfInt*            aShapesId=0);
84
85   bool CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
86   // notify on bad state of attached algos, return false
87   // if Compute() would fail because of some algo bad state
88
89   
90   struct TAlgoStateError
91   {
92     TAlgoStateErrorName _name;
93     const SMESH_Algo*   _algo;
94     int                 _algoDim;
95     bool                _isGlobalAlgo;
96
97     TAlgoStateError(): _algoDim(0),_algo(0),_name(SMESH_Hypothesis::HYP_OK) {}
98     void Set(TAlgoStateErrorName name, const SMESH_Algo* algo, bool isGlobal)
99     { _name = name; _algo = algo; _algoDim = algo->GetDim(); _isGlobalAlgo = isGlobal; }
100     void Set(TAlgoStateErrorName name, const int algoDim,      bool isGlobal)
101     { _name = name; _algo = 0;    _algoDim = algoDim;        _isGlobalAlgo = isGlobal; }
102   };
103
104   bool GetAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
105                     std::list< SMESH_Gen::TAlgoStateError > & theErrors);
106   // notify on bad state of attached algos, return false
107   // if Compute() would fail because of some algo bad state
108   // theErrors list contains problems description
109
110   StudyContextStruct *GetStudyContext(int studyId);
111
112   static int GetShapeDim(const TopAbs_ShapeEnum & aShapeType);
113   static int GetShapeDim(const TopoDS_Shape & aShape)
114   { return GetShapeDim( aShape.ShapeType() ); }
115   SMESH_Algo* GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape, TopoDS_Shape* assignedTo=0);
116   static bool IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh);
117
118   // inherited methods from SALOMEDS::Driver
119
120   void Save(int studyId, const char *aUrlOfFile);
121   void Load(int studyId, const char *aUrlOfFile);
122   void Close(int studyId);
123   const char *ComponentDataType();
124
125   const char *IORToLocalPersistentID(const char *IORString, bool & IsAFile);
126   const char *LocalPersistentIDToIOR(const char *aLocalPersistentID);
127
128   int GetANewId();
129
130   std::map < int, SMESH_Algo * >_mapAlgo;
131   std::map < int, SMESH_0D_Algo * >_map0D_Algo;
132   std::map < int, SMESH_1D_Algo * >_map1D_Algo;
133   std::map < int, SMESH_2D_Algo * >_map2D_Algo;
134   std::map < int, SMESH_3D_Algo * >_map3D_Algo;
135
136  private:
137
138   int _localId;                         // unique Id of created objects, within SMESH_Gen entity
139   std::map < int, StudyContextStruct * >_mapStudyContext;
140
141   // hypotheses managing
142   int _hypId;
143 };
144
145 #endif