Slicer 5.13
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLLayerDMObjectEventObserver.h
Go to the documentation of this file.
1/*==============================================================================
2
3 Program: 3D Slicer
4
5 Copyright (c) Kitware SAS
6
7 See COPYRIGHT.txt
8 or http://www.slicer.org/copyright/copyright.txt for details.
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15
16 This file was originally developed by Thibault Pelletier, Kitware SAS,
17 and was partially funded by ANR grants ANR-22-CE45-0034 and ANR-18-RHUS-005.
18
19==============================================================================*/
20
21#ifndef __vtkMRMLLayerDMObjectEventObserver_h
22#define __vtkMRMLLayerDMObjectEventObserver_h
23
24// LayerDM includes
25#include "vtkSlicerLayerDMModuleMRMLExport.h"
26
27// VTK includes
28#include <vtkCommand.h>
29#include <vtkObject.h>
30#include <vtkSmartPointer.h>
31#include <vtkWeakPointer.h>
32
33// STL includes
34#include <functional>
35#include <map>
36#include <set>
37#include <variant>
38#include <vector>
39
40class vtkCallbackCommand;
41
46class VTK_SLICER_LAYERDM_MODULE_MRML_EXPORT vtkMRMLLayerDMObjectEventObserver : public vtkObject
47{
48public:
49 struct UpdateGuard;
51 vtkTypeMacro(vtkMRMLLayerDMObjectEventObserver, vtkObject);
52 void PrintSelf(ostream& os, vtkIndent indent) override;
53
60 bool UpdateObservation(vtkObject* prevObj, vtkObject* obj, unsigned long event = vtkCommand::ModifiedEvent);
61 bool UpdateObservation(vtkObject* prevObj, vtkObject* obj, const std::vector<unsigned long>& events);
63
66 void RemoveObservations(vtkObject* obj);
67
70 void SetUpdateCallback(const std::function<void(vtkObject* node)>& callback);
71 void SetUpdateCallback(const std::function<void(vtkObject* node, unsigned long eventId)>& callback);
72 void SetUpdateCallback(const std::function<void(vtkObject* node, unsigned long eventId, void* callData)>& callback);
74
77
80 bool SetBlocked(bool isBlocked);
81 bool IsBlocked() const;
82
86 {
89
90 private:
92 bool WasBlocked{};
93 };
94
95protected:
98
99private:
100 void AddObservation(vtkObject* obj, unsigned long event);
101
103 void InvokeCallback(vtkObject* obj, unsigned long eventId, void* callData);
104
107 void OnObjectDeleted(vtkObject* obj);
108
109 vtkSmartPointer<vtkCallbackCommand> UpdateCommand;
110 std::map<vtkObject*, std::map<unsigned long, unsigned long>> ObservedEventsMap;
111 std::set<vtkObject*> DeleteEventObservers;
112 std::variant<std::function<void(vtkObject* node)>,
113 std::function<void(vtkObject* node, unsigned long eventId)>,
114 std::function<void(vtkObject* node, unsigned long eventId, void* callData)>>
115 Callback;
116 bool Blocked;
117};
118
119#endif
bool UpdateObservation(vtkObject *prevObj, vtkObject *obj, const std::vector< unsigned long > &events)
void RemoveObservations(vtkObject *obj)
void PrintSelf(ostream &os, vtkIndent indent) override
void ClearCallback()
Forget the update callback.
bool SetBlocked(bool isBlocked)
void SetUpdateCallback(const std::function< void(vtkObject *node, unsigned long eventId, void *callData)> &callback)
void SetUpdateCallback(const std::function< void(vtkObject *node, unsigned long eventId)> &callback)
bool UpdateObservation(vtkObject *prevObj, vtkObject *obj, unsigned long event=vtkCommand::ModifiedEvent)
static vtkMRMLLayerDMObjectEventObserver * New()
void SetUpdateCallback(const std::function< void(vtkObject *node)> &callback)
UpdateGuard(vtkMRMLLayerDMObjectEventObserver *obs)