Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/smesh.git] / src / SMESH / SMESH_subMesh.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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_subMesh.hxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #ifndef _SMESH_SUBMESH_HXX_
30 #define _SMESH_SUBMESH_HXX_
31
32 #include "SMESHDS_Mesh.hxx"
33 #include "SMESHDS_SubMesh.hxx"
34 #include "SMESH_Hypothesis.hxx"
35 #include "Utils_SALOME_Exception.hxx"
36 #include <TopoDS_Shape.hxx>
37 #include <TColStd_IndexedMapOfTransient.hxx>
38 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
39
40 #include <set>
41 #include <list>
42 #include <map>
43
44 class SMESH_Mesh;
45 class SMESH_Hypothesis;
46 class SMESH_Algo;
47 class SMESH_Gen;
48
49 class SMESH_subMesh
50 {
51  public:
52   SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
53                 const TopoDS_Shape & aSubShape);
54   virtual ~ SMESH_subMesh();
55
56   int GetId() const;
57
58   //   bool Contains(const TopoDS_Shape & aSubShape)
59   //     throw (SALOME_Exception);
60
61   SMESH_Mesh* GetFather() { return _father; }
62   
63   SMESHDS_SubMesh * GetSubMeshDS();
64
65   SMESHDS_SubMesh* CreateSubMeshDS();
66   // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
67
68   SMESH_subMesh *GetFirstToCompute();
69
70   const map < int, SMESH_subMesh * >&DependsOn();
71   //const map < int, SMESH_subMesh * >&Dependants();
72
73   const TopoDS_Shape & GetSubShape() const;
74
75 //  bool _vertexSet;                    // only for vertex subMesh, set to false for dim > 0
76
77   enum compute_state
78   {
79     NOT_READY, READY_TO_COMPUTE,
80     COMPUTE_OK, FAILED_TO_COMPUTE
81     };
82   enum algo_state
83   {
84     NO_ALGO, MISSING_HYP, HYP_OK
85     };
86   enum algo_event
87   {
88     ADD_HYP, ADD_ALGO,
89     REMOVE_HYP, REMOVE_ALGO,
90     ADD_FATHER_HYP, ADD_FATHER_ALGO,
91     REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO
92     };
93   enum compute_event
94   {
95     MODIF_HYP, MODIF_ALGO_STATE, COMPUTE,
96     CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
97     MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
98     };
99
100   SMESH_Hypothesis::Hypothesis_Status
101     AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
102
103   SMESH_Hypothesis::Hypothesis_Status
104     SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
105
106   int GetAlgoState() const { return _algoState; }
107   int GetComputeState() const { return _computeState; };
108
109   void DumpAlgoState(bool isMain);
110
111   bool ComputeStateEngine(int event);
112
113   bool IsConform(const SMESH_Algo* theAlgo);
114   // check if a conform mesh will be produced by the Algo
115
116   bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
117   // return true if theHypothesis can be attached to me:
118   // its dimention is checked
119
120   static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
121                                     const TopAbs_ShapeEnum  theShapeType);
122
123   bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
124   { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
125   // return true if theHypothesis can be used to mesh me:
126   // its shape type is checked
127   
128   SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
129   // check if there are several applicable hypothesis on fathers
130
131  protected:
132   void InsertDependence(const TopoDS_Shape aSubShape);
133
134   bool SubMeshesComputed();
135
136   bool SubMeshesReady();
137
138   void RemoveSubMeshElementsAndNodes();
139   void UpdateDependantsState(const compute_event theEvent);
140   void UpdateSubMeshState(const compute_state theState);
141   void ComputeSubMeshStateEngine(int event);
142   void CleanDependants();
143   void CleanDependsOn();
144   void SetAlgoState(int state);
145
146   bool IsMeshComputed() const;
147   // check if _subMeshDS contains mesh elements
148
149   TopoDS_Shape GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo);
150   // return a shape containing all sub-shapes of the MainShape that can be
151   // meshed at once along with _subShape
152
153   bool ApplyToCollection (SMESH_Algo*         theAlgo,
154                           const TopoDS_Shape& theCollection);
155   // Apply theAlgo to all subshapes in theCollection
156
157   const SMESH_Hypothesis* GetSimilarAttached(const TopoDS_Shape&      theShape,
158                                              const SMESH_Hypothesis * theHyp,
159                                              const int                theHypType = 0);
160   // return a hypothesis attached to theShape.
161   // If theHyp is provided, similar but not same hypotheses
162   // is returned; else an applicable ones having theHypType
163   // is returned
164   
165   TopoDS_Shape _subShape;
166   SMESHDS_Mesh * _meshDS;
167   SMESHDS_SubMesh * _subMeshDS;
168   int _Id;
169   SMESH_Mesh *_father;
170   map < int, SMESH_subMesh * >_mapDepend;
171   bool _dependenceAnalysed;
172
173   int _algoState;
174   int _computeState;
175
176 };
177
178 #endif