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