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