Salome HOME
PR: merged from V5_1_4rc1
[modules/smesh.git] / src / SMESH / SMESH_subMeshEventListener.hxx
1 //  Copyright (C) 2007-2010  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.
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 //  SMESH SMESH : implementaion of SMESH idl descriptions
24 // File      : SMESH_subMeshEventListener.hxx
25 // Created   : Mon Nov 13 10:45:49 2006
26 // Author    : Edward AGAPOV (eap)
27 //
28 #ifndef SMESH_subMeshEventListener_HeaderFile
29 #define SMESH_subMeshEventListener_HeaderFile
30
31 #include "SMESH_SMESH.hxx"
32
33 #include <list>
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   bool myIsDeletable; //!< if true, it will be deleted by SMESH_subMesh
47 public:
48   SMESH_subMeshEventListener(bool isDeletable):myIsDeletable(isDeletable) {}
49   bool IsDeletable() const { return myIsDeletable; }
50   /*!
51    * \brief Do something on a certain event
52    * \param event - algo_event or compute_event itself (of SMESH_subMesh)
53    * \param eventType - ALGO_EVENT or COMPUTE_EVENT (of SMESH_subMesh)
54    * \param subMesh - the submesh where the event occures
55    * \param data - listener data stored in the subMesh
56    * \param hyp - hypothesis, if eventType is algo_event
57    * 
58    * The base implementation translates CLEAN event to the subMesh stored
59    * in the listener data. Also it sends SUBMESH_COMPUTED event in case of
60    * successful COMPUTE event.
61    */
62   virtual void ProcessEvent(const int          event,
63                             const int          eventType,
64                             SMESH_subMesh*     subMesh,
65                             SMESH_subMeshEventListenerData* data,
66                             const SMESH_Hypothesis*         hyp = 0);
67 };
68
69 // ------------------------------------------------------------------
70 /*!
71  * \brief Data specific for EventListener and to be stored in a submesh
72  */
73 // ------------------------------------------------------------------
74
75 struct SMESH_subMeshEventListenerData
76 {
77   bool myIsDeletable; //!< if true, it will be deleted by SMESH_subMesh
78   int myType;         //!< to recognize data type
79   std::list<SMESH_subMesh*> mySubMeshes; //!< generally: submeshes depending
80                                          // on the one storing this data
81 public:
82   SMESH_subMeshEventListenerData(bool isDeletable):myIsDeletable(isDeletable) {}
83   bool IsDeletable() const { return myIsDeletable; }
84
85   /*!
86    * \brief Create a default listener data.
87    * \param dependentSM - subMesh to store
88    * \param type - data type
89    * \retval SMESH_subMeshEventListenerData* - a new listener data
90    *
91    * See SMESH_subMeshEventListener::ProcessEvent() to know how the default
92    * listener uses it (implementation is in SMESH_subMesh.cxx)
93    */
94   static SMESH_subMeshEventListenerData* MakeData(SMESH_subMesh* dependentSM,
95                                                   const int      type = 0)
96   {
97     SMESH_subMeshEventListenerData* data = new SMESH_subMeshEventListenerData(true);
98     data->mySubMeshes.push_back( dependentSM );
99     data->myType = type;
100     return data;
101   }
102 };
103
104
105 #endif