Salome HOME
58d03e6f5d0a7d5f603a895fbddb3e2751ef7b8f
[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 "Utils_SALOME_Exception.hxx"
33
34 #include "SMESH_Hypothesis.hxx"
35 #include "SMESH_Algo.hxx"
36 #include "SMESH_1D_Algo.hxx"
37 #include "SMESH_2D_Algo.hxx"
38 #include "SMESH_3D_Algo.hxx"
39 #include "SMESH_Mesh.hxx"
40
41 #include "SMESHDS_Document.hxx"
42
43 #include <TopoDS_Shape.hxx>
44
45 #include <map>
46
47
48 typedef struct studyContextStruct
49 {
50         std::map < int, SMESH_Hypothesis * >mapHypothesis;
51           std::map < int, SMESH_Mesh * >mapMesh;
52           SMESHDS_Document * myDocument;
53 } StudyContextStruct;
54
55 class SMESH_Gen
56 {
57  public:
58   SMESH_Gen();
59   ~SMESH_Gen();
60
61 //  SMESH_Hypothesis *CreateHypothesis(const char *anHyp, int studyId)
62 //    throw(SALOME_Exception);
63   SMESH_Mesh* CreateMesh(int theStudyId, bool theIsEmbeddedMode)
64     throw(SALOME_Exception);
65   bool Compute(::SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
66
67   bool CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
68   // notify on bad state of attached algos, return false
69   // if Compute() would fail because of some algo bad state
70
71   
72   enum TAlgoStateErrorName { NONE=0,
73                              MISSING_ALGO,
74                              MISSING_HYPO,
75                              NOT_CONFORM_MESH,
76                              BAD_PARAM_VALUE };
77   struct TAlgoStateError
78   {
79     TAlgoStateErrorName _name;
80     const SMESH_Algo*   _algo;
81     int                 _algoDim;
82     bool                _isGlobalAlgo;
83
84     TAlgoStateError(): _algoDim(0),_algo(0),_name(NONE) {}
85     void Set(TAlgoStateErrorName name, const SMESH_Algo* algo, bool isGlobal)
86     { _name = name; _algo = algo; _algoDim = algo->GetDim(); _isGlobalAlgo = isGlobal; }
87     void Set(TAlgoStateErrorName name, const int algoDim,      bool isGlobal)
88     { _name = name; _algo = 0;    _algoDim = algoDim;        _isGlobalAlgo = isGlobal; }
89   };
90
91   bool GetAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
92                     std::list< SMESH_Gen::TAlgoStateError > & theErrors);
93   // notify on bad state of attached algos, return false
94   // if Compute() would fail because of some algo bad state
95   // theErrors list contains problems description
96
97
98   StudyContextStruct *GetStudyContext(int studyId);
99
100   static int GetShapeDim(const TopAbs_ShapeEnum & aShapeType);
101   static int GetShapeDim(const TopoDS_Shape & aShape)
102   { return GetShapeDim( aShape.ShapeType() ); }
103   SMESH_Algo* GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape);
104   static bool IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh);
105
106   // inherited methods from SALOMEDS::Driver
107
108   void Save(int studyId, const char *aUrlOfFile);
109   void Load(int studyId, const char *aUrlOfFile);
110   void Close(int studyId);
111   const char *ComponentDataType();
112
113   const char *IORToLocalPersistentID(const char *IORString, bool & IsAFile);
114   const char *LocalPersistentIDToIOR(const char *aLocalPersistentID);
115
116   int GetANewId();
117
118   std::map < int, SMESH_Algo * >_mapAlgo;
119   std::map < int, SMESH_1D_Algo * >_map1D_Algo;
120   std::map < int, SMESH_2D_Algo * >_map2D_Algo;
121   std::map < int, SMESH_3D_Algo * >_map3D_Algo;
122
123  private:
124
125   int _localId;                         // unique Id of created objects, within SMESH_Gen entity
126   std::map < int, StudyContextStruct * >_mapStudyContext;
127
128   // hypotheses managing
129   int _hypId;
130 };
131
132 #endif