Salome HOME
Update copyright information
[modules/smesh.git] / src / SMESH / SMESH_Gen.hxx
1 //  Copyright (C) 2007-2008  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 //  SMESH SMESH : implementaion of SMESH idl descriptions
23 //  File   : SMESH_Gen.hxx
24 //  Author : Paul RASCLE, EDF
25 //  Module : SMESH
26 //  $Header$
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 <TopoDS_Shape.hxx>
45
46 #include <map>
47
48 class SMESHDS_Document;
49
50 typedef SMESH_Hypothesis::Hypothesis_Status TAlgoStateErrorName;
51
52 typedef struct studyContextStruct
53 {
54   std::map < int, SMESH_Hypothesis * >mapHypothesis;
55   std::map < int, SMESH_Mesh * >mapMesh;
56   SMESHDS_Document * myDocument;
57 } StudyContextStruct;
58
59 class SMESH_EXPORT  SMESH_Gen
60 {
61  public:
62   SMESH_Gen();
63   ~SMESH_Gen();
64
65   SMESH_Mesh* CreateMesh(int theStudyId, bool theIsEmbeddedMode)
66     throw(SALOME_Exception);
67
68   /*!
69    * \brief Computes aMesh on aShape 
70    *  \param anUpward - compute from vertices up to more complex shape (internal usage)
71    *  \retval bool - true if none submesh failed to compute
72    */
73   bool Compute(::SMESH_Mesh &       aMesh,
74                const TopoDS_Shape & aShape,
75                const bool           anUpward=false);
76
77   bool CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
78   // notify on bad state of attached algos, return false
79   // if Compute() would fail because of some algo bad state
80
81   
82   struct TAlgoStateError
83   {
84     TAlgoStateErrorName _name;
85     const SMESH_Algo*   _algo;
86     int                 _algoDim;
87     bool                _isGlobalAlgo;
88
89     TAlgoStateError(): _algoDim(0),_algo(0),_name(SMESH_Hypothesis::HYP_OK) {}
90     void Set(TAlgoStateErrorName name, const SMESH_Algo* algo, bool isGlobal)
91     { _name = name; _algo = algo; _algoDim = algo->GetDim(); _isGlobalAlgo = isGlobal; }
92     void Set(TAlgoStateErrorName name, const int algoDim,      bool isGlobal)
93     { _name = name; _algo = 0;    _algoDim = algoDim;        _isGlobalAlgo = isGlobal; }
94   };
95
96   bool GetAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
97                     std::list< SMESH_Gen::TAlgoStateError > & theErrors);
98   // notify on bad state of attached algos, return false
99   // if Compute() would fail because of some algo bad state
100   // theErrors list contains problems description
101
102   StudyContextStruct *GetStudyContext(int studyId);
103
104   static int GetShapeDim(const TopAbs_ShapeEnum & aShapeType);
105   static int GetShapeDim(const TopoDS_Shape & aShape)
106   { return GetShapeDim( aShape.ShapeType() ); }
107   SMESH_Algo* GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape, TopoDS_Shape* assignedTo=0);
108   static bool IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh);
109
110   // inherited methods from SALOMEDS::Driver
111
112   void Save(int studyId, const char *aUrlOfFile);
113   void Load(int studyId, const char *aUrlOfFile);
114   void Close(int studyId);
115   const char *ComponentDataType();
116
117   const char *IORToLocalPersistentID(const char *IORString, bool & IsAFile);
118   const char *LocalPersistentIDToIOR(const char *aLocalPersistentID);
119
120   int GetANewId();
121
122   std::map < int, SMESH_Algo * >_mapAlgo;
123   std::map < int, SMESH_0D_Algo * >_map0D_Algo;
124   std::map < int, SMESH_1D_Algo * >_map1D_Algo;
125   std::map < int, SMESH_2D_Algo * >_map2D_Algo;
126   std::map < int, SMESH_3D_Algo * >_map3D_Algo;
127
128  private:
129
130   int _localId;                         // unique Id of created objects, within SMESH_Gen entity
131   std::map < int, StudyContextStruct * >_mapStudyContext;
132
133   // hypotheses managing
134   int _hypId;
135 };
136
137 #endif