Salome HOME
[SALOME platform 0013410]: SubMesh not taken into account with Netgen 1D-2D et 1D...
[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 "SMESH_ComputeError.hxx"
38
39 #include "Utils_SALOME_Exception.hxx"
40
41 #include <TopoDS_Shape.hxx>
42
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 class SMESH_subMesh;
53
54 typedef SMESH_subMeshEventListener     EventListener;
55 typedef SMESH_subMeshEventListenerData EventListenerData;
56
57 typedef boost::shared_ptr< SMDS_Iterator<SMESH_subMesh*> > SMESH_subMeshIteratorPtr;
58
59
60 class SMESH_EXPORT SMESH_subMesh
61 {
62  public:
63   SMESH_subMesh(int Id, SMESH_Mesh * father, SMESHDS_Mesh * meshDS,
64                 const TopoDS_Shape & aSubShape);
65   virtual ~ SMESH_subMesh();
66
67   int GetId() const;
68
69   SMESH_Mesh* GetFather() { return _father; }
70   
71   SMESHDS_SubMesh * GetSubMeshDS();
72
73   SMESHDS_SubMesh* CreateSubMeshDS();
74   // Explicit SMESHDS_SubMesh creation method, required for persistence mechanism
75
76   SMESH_subMesh *GetFirstToCompute();
77
78   const std::map < int, SMESH_subMesh * >& DependsOn();
79   //const map < int, SMESH_subMesh * >&Dependants();
80   /*!
81    * \brief Return iterator on the submeshes this one depends on
82    */
83   SMESH_subMeshIteratorPtr getDependsOnIterator(const bool includeSelf,
84                                                 const bool complexShapeFirst);
85
86   const TopoDS_Shape & GetSubShape() const;
87
88   enum compute_state
89   {
90     NOT_READY, READY_TO_COMPUTE,
91     COMPUTE_OK, FAILED_TO_COMPUTE
92     };
93   enum algo_state
94   {
95     NO_ALGO, MISSING_HYP, HYP_OK
96     };
97   enum algo_event
98   {
99     ADD_HYP          , ADD_ALGO,
100     REMOVE_HYP       , REMOVE_ALGO,
101     ADD_FATHER_HYP   , ADD_FATHER_ALGO,
102     REMOVE_FATHER_HYP, REMOVE_FATHER_ALGO,
103     MODIF_HYP
104     };
105   enum compute_event
106   {
107     MODIF_ALGO_STATE, COMPUTE,
108     CLEAN, SUBMESH_COMPUTED, SUBMESH_RESTORED,
109     MESH_ENTITY_REMOVED, CHECK_COMPUTE_STATE
110     };
111   enum event_type
112   {
113     ALGO_EVENT, COMPUTE_EVENT
114   };
115
116   // ==================================================================
117   // Members to track non hierarchical dependencies between submeshes 
118   // ==================================================================
119
120   /*!
121    * \brief Sets an event listener and its data to a submesh
122     * \param listener - the listener to store
123     * \param data - the listener data to store
124     * \param where - the submesh to store the listener and it's data
125    * 
126    * The method remembers the submesh \awhere it puts the listener in order to delete
127    * them when HYP_OK algo_state is lost
128    * After being set, event listener is notified on each event of \awhere submesh.
129    */
130   void SetEventListener(EventListener*     listener,
131                         EventListenerData* data,
132                         SMESH_subMesh*     where);
133
134   /*!
135    * \brief Return an event listener data
136     * \param listener - the listener whose data is
137     * \retval EventListenerData* - found data, maybe NULL
138    */
139   EventListenerData* GetEventListenerData(EventListener* listener) const;
140
141   /*!
142    * \brief Unregister the listener and delete it and it's data
143     * \param listener - the event listener to delete
144    */
145   void DeleteEventListener(EventListener* listener);
146
147 protected:
148
149   //!< event listeners to notify
150   std::map< EventListener*, EventListenerData* >           myEventListeners;
151   //!< event listeners to delete when HYP_OK algo_state is lost
152   std::list< std::pair< SMESH_subMesh*, EventListener* > > myOwnListeners;
153
154   /*!
155    * \brief Sets an event listener and its data to a submesh
156     * \param listener - the listener to store
157     * \param data - the listener data to store
158    * 
159    * After being set, event listener is notified on each event of a submesh.
160    */
161   void SetEventListener(EventListener* listener, EventListenerData* data);
162
163   /*!
164    * \brief Notify stored event listeners on the occured event
165    * \param event - algo_event or compute_event itself
166    * \param eventType - algo_event or compute_event
167    * \param hyp - hypothesis, if eventType is algo_event
168    */
169   void NotifyListenersOnEvent( const int         event,
170                                const event_type  eventType,
171                                SMESH_Hypothesis* hyp = 0);
172
173   /*!
174    * \brief Delete event listeners depending on algo of this submesh
175    */
176   void DeleteOwnListeners();
177
178   // ==================================================================
179
180 public:
181
182   SMESH_Hypothesis::Hypothesis_Status
183     AlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
184
185   SMESH_Hypothesis::Hypothesis_Status
186     SubMeshesAlgoStateEngine(int event, SMESH_Hypothesis * anHyp);
187
188   int GetAlgoState() const { return _algoState; }
189   int GetComputeState() const { return _computeState; };
190   SMESH_ComputeErrorPtr& GetComputeError() { return _computeError; }
191
192   void DumpAlgoState(bool isMain);
193
194   bool ComputeStateEngine(int event);
195
196   bool IsConform(const SMESH_Algo* theAlgo);
197   // check if a conform mesh will be produced by the Algo
198
199   bool CanAddHypothesis(const SMESH_Hypothesis* theHypothesis) const;
200   // return true if theHypothesis can be attached to me:
201   // its dimention is checked
202
203   static bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis,
204                                     const TopAbs_ShapeEnum  theShapeType);
205
206   bool IsApplicableHypotesis(const SMESH_Hypothesis* theHypothesis) const
207   { return IsApplicableHypotesis( theHypothesis, _subShape.ShapeType() ); }
208   // return true if theHypothesis can be used to mesh me:
209   // its shape type is checked
210   
211   SMESH_Hypothesis::Hypothesis_Status CheckConcurentHypothesis (const int theHypType);
212   // check if there are several applicable hypothesis on fathers
213
214   /*!
215    * \brief Return true if no mesh entities is bound to the submesh
216    */
217   bool IsEmpty() const;
218
219   bool IsMeshComputed() const;
220   // check if _subMeshDS contains mesh elements
221
222   /*!
223    * \brief Allow algo->Compute() if a subshape of lower dim is meshed but
224    *        none mesh entity is bound to it
225    */
226   void SetIsAlwaysComputed(bool isAlCo);
227
228
229 protected:
230   // ==================================================================
231   void InsertDependence(const TopoDS_Shape aSubShape);
232
233   bool SubMeshesComputed();
234
235   bool SubMeshesReady();
236
237   void RemoveSubMeshElementsAndNodes();
238   void UpdateDependantsState(const compute_event theEvent);
239   void UpdateSubMeshState(const compute_state theState);
240   void ComputeSubMeshStateEngine(int event);
241   void CleanDependants();
242   void CleanDependsOn();
243   void SetAlgoState(int state);
244
245   /*!
246    * \brief Return a shape containing all sub-shapes of the MainShape that can be
247    * meshed at once along with _subShape
248    */
249   TopoDS_Shape GetCollection(SMESH_Gen * theGen,
250                              SMESH_Algo* theAlgo,
251                              bool &      theSubComputed);
252
253   /*!
254    * \brief Apply theAlgo to all subshapes in theCollection
255    */
256   bool ApplyToCollection (SMESH_Algo*         theAlgo,
257                           const TopoDS_Shape& theCollection);
258
259   /*!
260    * \brief Update compute_state by _computeError
261     * \retval bool - false if there are errors
262    */
263   bool CheckComputeError(SMESH_Algo* theAlgo, const TopoDS_Shape& theShape=TopoDS_Shape());
264
265   /*!
266    * \brief Return a hypothesis attached to theShape.
267    * 
268    * If theHyp is provided, similar but not same hypotheses
269    * is returned; else an applicable ones having theHypType
270    * is returned
271    */
272   const SMESH_Hypothesis* GetSimilarAttached(const TopoDS_Shape&      theShape,
273                                              const SMESH_Hypothesis * theHyp,
274                                              const int                theHypType = 0);
275   // 
276
277 protected:
278
279   TopoDS_Shape          _subShape;
280   SMESHDS_SubMesh *     _subMeshDS;
281   SMESH_Mesh *          _father;
282   int                   _Id;
283
284   std::map < int, SMESH_subMesh * >_mapDepend;
285   bool                  _dependenceAnalysed;
286
287   int                   _algoState;
288   int                   _computeState;
289   SMESH_ComputeErrorPtr _computeError;
290
291   // allow algo->Compute() if a subshape of lower dim is meshed but
292   // none mesh entity is bound to it. Eg StdMeshers_CompositeSegment_1D can
293   // mesh several edges as a whole and leave some of them  without mesh entities
294   bool                  _alwaysComputed;
295
296 };
297
298 #endif