Salome HOME
23514: EDF 16031 - SMESH freezes
[modules/smesh.git] / src / SMESH / SMESH_subMeshEventListener.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 // File    : SMESH_subMeshEventListener.hxx
24 // Created : Mon Nov 13 10:45:49 2006
25 // Author  : Edward AGAPOV (eap)
26 //
27 #ifndef SMESH_subMeshEventListener_HeaderFile
28 #define SMESH_subMeshEventListener_HeaderFile
29
30 #include "SMESH_SMESH.hxx"
31
32 #include <list>
33 #include <set>
34
35 class  SMESH_subMesh;
36 class  SMESH_Hypothesis;
37 struct SMESH_subMeshEventListenerData;
38
39 // ------------------------------------------------------------------
40 /*!
41  * \brief A base for objects reacting on submesh events
42  */
43 // ------------------------------------------------------------------
44
45 class SMESH_EXPORT SMESH_subMeshEventListener
46 {
47   bool myIsDeletable; //!< if true, it will be deleted by SMESH_subMesh
48   mutable std::set<SMESH_subMesh*> myBusySM; //!< to avoid infinite recursion via events
49   const char*                      myName;   //!< identifier
50   friend class SMESH_subMesh;
51
52  public:
53   SMESH_subMeshEventListener(bool isDeletable, const char* name)
54     :myIsDeletable(isDeletable), myName(name) {}
55   virtual      ~SMESH_subMeshEventListener() {}
56   bool         IsDeletable() const { return myIsDeletable; }
57   const char*  GetName()     const { return myName; }
58   virtual void BeforeDelete(SMESH_subMesh*                  subMesh,
59                             SMESH_subMeshEventListenerData* data)
60   {}
61   /*!
62    * \brief Do something on a certain event
63    * \param event - algo_event or compute_event itself (of SMESH_subMesh)
64    * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
65    * \param subMesh - the submesh where the event occurs
66    * \param data - listener data stored in the subMesh
67    * \param hyp - hypothesis, if eventType is algo_event
68    * 
69    * The base implementation (see SMESH_subMesh.cxx) translates CLEAN event
70    * to the subMeshes stored in the listener data. Also it sends SUBMESH_COMPUTED
71    * event in case of successful COMPUTE event.
72    */
73   virtual void ProcessEvent(const int          event,
74                             const int          eventType,
75                             SMESH_subMesh*     subMesh,
76                             SMESH_subMeshEventListenerData* data,
77                             const SMESH_Hypothesis*         hyp = 0);
78 };
79
80 // ------------------------------------------------------------------
81 /*!
82  * \brief Data specific for EventListener and to be stored in a submesh
83  */
84 // ------------------------------------------------------------------
85
86 struct SMESH_subMeshEventListenerData
87 {
88   bool myIsDeletable; //!< if true, it will be deleted by SMESH_subMesh
89   int myType;         //!< to recognize data type
90   std::list<SMESH_subMesh*> mySubMeshes; /* generally: submeshes depending
91                                             on the one storing this data;
92                                             !! they are used to track intermesh
93                                             dependencies at mesh loading as well !! */
94 public:
95   SMESH_subMeshEventListenerData(bool isDeletable):myIsDeletable(isDeletable) {}
96   virtual ~SMESH_subMeshEventListenerData() {}
97   bool IsDeletable() const { return myIsDeletable; }
98
99   /*!
100    * \brief Create a default listener data.
101    * \param dependentSM - subMesh to store
102    * \param type - data type
103    * \retval SMESH_subMeshEventListenerData* - a new listener data
104    *
105    * See SMESH_subMeshEventListener::ProcessEvent() to know how the default
106    * listener uses it (implementation is in SMESH_subMesh.cxx)
107    */
108   static SMESH_subMeshEventListenerData* MakeData(SMESH_subMesh* dependentSM,
109                                                   const int      type = 0)
110   {
111     SMESH_subMeshEventListenerData* data = new SMESH_subMeshEventListenerData(true);
112     data->mySubMeshes.push_back( dependentSM );
113     data->myType = type;
114     return data;
115   }
116 };
117
118
119 #endif