Salome HOME
Merging with WPdev
[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 class SMESH_subMeshEventListener;
51 class SMESH_subMeshEventListenerData;
52
53 typedef SMESH_subMeshEventListener     EventListener;
54 typedef SMESH_subMeshEventListenerData EventListenerData;
55
56 class SMESH_EXPORT SMESH_subMesh
57 {
58  public:
59   SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
60                 const TopoDS_Shape & aSubShape);
61   virtual ~ SMESH_subMesh();
62
63   int GetId() const;
64
65   //   bool Contains(const TopoDS_Shape & aSubShape)
66   //     throw (SALOME_Exception);
67
68   SMESH_Mesh* GetFather() { return _father; }
69   
70   SMESHDS_SubMesh * GetSubMeshDS();
71
72   SMESHDS_SubMesh* CreateSubMeshDS();
73   // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
74
75   SMESH_subMesh *GetFirstToCompute();
76
77   const map < int, SMESH_subMesh * >&DependsOn();
78   //const map < int, SMESH_subMesh * >&Dependants();
79
80   const TopoDS_Shape & GetSubShape() const;
81
82   enum compute_state
83   {
84     NOT_READY, READY_TO_COMPUTE,
85     COMPUTE_OK, FAILED_TO_COMPUTE
86     };
87   enum algo_state
88   {
89     NO_ALGO, MISSING_HYP, HYP_OK
90     };
91   enum algo_event
92   {
93     ADD_HYP, ADD_ALGO,
94     REMOVE_HYP, REMOVE_ALGO,
95     ADD_FATHER_HYP, ADD_FATHER_ALGO,
96     REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO
97     };
98   enum compute_event
99   {
100     MODIF_HYP, MODIF_ALGO_STATE, COMPUTE,
101     CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
102     MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
103     };
104   enum event_type
105   {
106     ALGO_EVENT, COMPUTE_EVENT
107   };
108
109   // ==================================================================
110   // Members to track non hierarchical dependencies between submeshes 
111   // ==================================================================
112
113   /*!
114    * \brief Sets an event listener and its data to a submesh
115     * \param listener - the listener to store
116     * \param data - the listener data to store
117     * \param where - the submesh to store the listener and it's data
118     * \param deleteListener - if true then the listener will be deleted as
119     *        it is removed from where submesh
120    * 
121    * It remembers the submesh where it puts the listener in order to delete
122    * them when HYP_OK algo_state is lost
123    * After being set, event listener is notified on each event of where submesh.
124    */
125   void SetEventListener(EventListener*     listener,
126                         EventListenerData* data,
127                         SMESH_subMesh*     where);
128
129   /*!
130    * \brief Return an event listener data
131     * \param listener - the listener whose data is
132     * \retval EventListenerData* - found data, maybe NULL
133    */
134   EventListenerData* GetEventListenerData(EventListener* listener) const;
135
136   /*!
137    * \brief Unregister the listener and delete it and it's data
138     * \param listener - the event listener to delete
139    */
140   void DeleteEventListener(EventListener* listener);
141
142 protected:
143
144   //!< event listeners to notify
145   std::map< EventListener*, EventListenerData* >           myEventListeners;
146   //!< event listeners to delete when HYP_OK algo_state is lost
147   std::list< std::pair< SMESH_subMesh*, EventListener* > > myOwnListeners;
148
149   /*!
150    * \brief Sets an event listener and its data to a submesh
151     * \param listener - the listener to store
152     * \param data - the listener data to store
153    * 
154    * After being set, event listener is notified on each event of a submesh.
155    */
156   void SetEventListener(EventListener* listener, EventListenerData* data);
157
158   /*!
159    * \brief Notify stored event listeners on the occured event
160    * \param event - algo_event or compute_event itself
161    * \param eventType - algo_event or compute_event
162    * \param hyp - hypothesis, if eventType is algo_event
163    */
164   void NotifyListenersOnEvent( const int         event,
165                                const event_type  eventType,
166                                SMESH_Hypothesis* hyp = 0);
167
168   /*!
169    * \brief Delete event listeners depending on algo of this submesh
170    */
171   void DeleteOwnListeners();
172
173   // ==================================================================
174
175 public:
176
177   SMESH_Hypothesis::Hypothesis_Status
178     AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
179
180   SMESH_Hypothesis::Hypothesis_Status
181     SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
182
183   int GetAlgoState() const { return _algoState; }
184   int GetComputeState() const { return _computeState; };
185
186   void DumpAlgoState(bool isMain);
187
188   bool ComputeStateEngine(int event);
189
190   bool IsConform(const SMESH_Algo* theAlgo);
191   // check if a conform mesh will be produced by the Algo
192
193   bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
194   // return true if theHypothesis can be attached to me:
195   // its dimention is checked
196
197   static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
198                                     const TopAbs_ShapeEnum  theShapeType);
199
200   bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
201   { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
202   // return true if theHypothesis can be used to mesh me:
203   // its shape type is checked
204   
205   SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
206   // check if there are several applicable hypothesis on fathers
207
208   bool IsMeshComputed() const;
209   // check if _subMeshDS contains mesh elements
210
211 protected:
212   // ==================================================================
213   void InsertDependence(const TopoDS_Shape aSubShape);
214
215   bool SubMeshesComputed();
216
217   bool SubMeshesReady();
218
219   void RemoveSubMeshElementsAndNodes();
220   void UpdateDependantsState(const compute_event theEvent);
221   void UpdateSubMeshState(const compute_state theState);
222   void ComputeSubMeshStateEngine(int event);
223   void CleanDependants();
224   void CleanDependsOn();
225   void SetAlgoState(int state);
226
227   TopoDS_Shape GetCollection(SMESH_Gen * theGen, SMESH_Algo* theAlgo);
228   // return a shape containing all sub-shapes of the MainShape that can be
229   // meshed at once along with _subShape
230
231   bool ApplyToCollection (SMESH_Algo*         theAlgo,
232                           const TopoDS_Shape& theCollection);
233   // Apply theAlgo to all subshapes in theCollection
234
235   const SMESH_Hypothesis* GetSimilarAttached(const TopoDS_Shape&      theShape,
236                                              const SMESH_Hypothesis * theHyp,
237                                              const int                theHypType = 0);
238   // return a hypothesis attached to theShape.
239   // If theHyp is provided, similar but not same hypotheses
240   // is returned; else an applicable ones having theHypType
241   // is returned
242   
243   TopoDS_Shape _subShape;
244   SMESHDS_Mesh * _meshDS;
245   SMESHDS_SubMesh * _subMeshDS;
246   int _Id;
247   SMESH_Mesh *_father;
248   map < int, SMESH_subMesh * >_mapDepend;
249   bool _dependenceAnalysed;
250
251   int _algoState;
252   int _computeState;
253
254 };
255
256 #endif