Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
vtkMRMLAbstractLogic.h
Go to the documentation of this file.
1/*=auto=========================================================================
2
3 Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
4
5 See COPYRIGHT.txt
6 or http://www.slicer.org/copyright/copyright.txt for details.
7
8=========================================================================auto=*/
9
10#ifndef __vtkMRMLAbstractLogic_h
11#define __vtkMRMLAbstractLogic_h
12
13// MRMLLogic includes
15
16// MRML includes
17#include <vtkObserverManager.h>
18class vtkMRMLNode;
19class vtkMRMLScene;
20
21// VTK includes
22#include <vtkCommand.h>
23#include <vtkObject.h>
24class vtkIntArray;
25class vtkFloatArray;
26
27#include "vtkMRMLLogicExport.h"
28
29//----------------------------------------------------------------------------
30// Convenient macros
31
32//----------------------------------------------------------------------------
33// It removes all the event observations associated with the old value.
34#ifndef vtkSetMRMLNodeMacro
35# define vtkSetMRMLNodeMacro(node, value) \
36 { \
37 vtkObject* _oldNode = (node); \
38 this->GetMRMLNodesObserverManager()->SetObject(vtkObjectPointer(&(node)), (value)); \
39 vtkObject* _newNode = (node); \
40 if (_oldNode != _newNode) \
41 { \
42 this->Modified(); \
43 } \
44 };
45#endif
46
47//----------------------------------------------------------------------------
48#ifndef vtkSetAndObserveMRMLNodeMacro
65# define vtkSetAndObserveMRMLNodeMacro(node, value) \
66 { \
67 vtkObject* _oldNode = (node); \
68 this->GetMRMLNodesObserverManager()->SetAndObserveObject(vtkObjectPointer(&(node)), (value)); \
69 vtkObject* _newNode = (node); \
70 if (_oldNode != _newNode) \
71 { \
72 this->Modified(); \
73 } \
74 };
75#endif
76
77//----------------------------------------------------------------------------
78#ifndef vtkSetAndObserveMRMLNodeEventsMacro
79# define vtkSetAndObserveMRMLNodeEventsMacro(node, value, events) \
80 { \
81 vtkObject* _oldNode = (node); \
82 this->GetMRMLNodesObserverManager()->SetAndObserveObjectEvents(vtkObjectPointer(&(node)), (value), (events)); \
83 vtkObject* _newNode = (node); \
84 if (_oldNode != _newNode) \
85 { \
86 this->Modified(); \
87 } \
88 };
89#endif
90
91#ifndef vtkObserveMRMLNodeMacro
92# define vtkObserveMRMLNodeMacro(node) \
93 { \
94 this->GetMRMLNodesObserverManager()->ObserveObject((node)); \
95 };
96#endif
97
98#ifndef vtkObserveMRMLNodeEventsMacro
99# define vtkObserveMRMLNodeEventsMacro(node, events) \
100 { \
101 this->GetMRMLNodesObserverManager()->AddObjectEvents((node), (events)); \
102 };
103#endif
104
105#ifndef vtkUnObserveMRMLNodeMacro
106# define vtkUnObserveMRMLNodeMacro(node) \
107 { \
108 this->GetMRMLNodesObserverManager()->RemoveObjectEvents((node)); \
109 };
110#endif
111
112#ifndef vtkIsObservedMRMLNodeEventMacro
113# define vtkIsObservedMRMLNodeEventMacro(node, event) (this->GetMRMLNodesObserverManager()->GetObservationsCount(node, event) != 0)
114#endif
115
128class VTK_MRML_LOGIC_EXPORT vtkMRMLAbstractLogic : public vtkObject
129{
130public:
133 typedef void (vtkMRMLAbstractLogic::*TaskFunctionPointer)(void* clientdata);
134
136 void PrintSelf(ostream& os, vtkIndent indent) override;
137 vtkTypeMacro(vtkMRMLAbstractLogic, vtkObject);
138
142
145
147 void SetMRMLScene(vtkMRMLScene* newScene);
148
157 void SetAndObserveMRMLScene(vtkMRMLScene* newScene);
158 void SetAndObserveMRMLSceneEvents(vtkMRMLScene* newScene, vtkIntArray* events, vtkFloatArray* priorities = nullptr);
160
161protected:
164
167 virtual void ProcessMRMLSceneEvents(vtkObject* caller, unsigned long event, void* callData);
168
178 virtual void ProcessMRMLNodesEvents(vtkObject* caller, unsigned long event, void* callData);
179
186 virtual void ProcessMRMLLogicsEvents(vtkObject* caller, unsigned long event, void* callData);
187
192 vtkCallbackCommand* GetMRMLSceneCallbackCommand();
193
198 vtkCallbackCommand* GetMRMLNodesCallbackCommand();
199
202 vtkCallbackCommand* GetMRMLLogicsCallbackCommand();
203
207
211
215
218
224 virtual void UnobserveMRMLScene();
232 virtual void ObserveMRMLScene();
239 virtual void UpdateFromMRMLScene();
240
257 virtual void OnMRMLSceneStartClose() {}
262 virtual void OnMRMLSceneEndClose() {}
267 virtual void OnMRMLSceneStartImport() {}
272 virtual void OnMRMLSceneEndImport() {}
277 virtual void OnMRMLSceneStartRestore() {}
282 virtual void OnMRMLSceneEndRestore() {}
287 virtual void OnMRMLSceneNew() {}
292 virtual void OnMRMLSceneNodeAdded(vtkMRMLNode* /*node*/) {}
297 virtual void OnMRMLSceneNodeRemoved(vtkMRMLNode* /*node*/) {}
298
301 virtual void OnMRMLNodeModified(vtkMRMLNode* /*node*/) {}
302
309 virtual void SetMRMLSceneInternal(vtkMRMLScene* newScene);
310
314 void SetAndObserveMRMLSceneInternal(vtkMRMLScene* newScene);
316
329 void SetAndObserveMRMLSceneEventsInternal(vtkMRMLScene* newScene, vtkIntArray* events, vtkFloatArray* priorities = nullptr);
330
333 virtual void RegisterNodes() {}
334
340
346
349 virtual bool EnterMRMLSceneCallback() const;
350
354
360
366
370 virtual bool EnterMRMLNodesCallback() const;
371
377
383
386 virtual bool EnterMRMLLogicsCallback() const;
387
390 static void MRMLSceneCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
391
393 static void MRMLNodesCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
394
396 static void MRMLLogicsCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
397
401 inline bool StartModify();
402
406 inline int EndModify(bool wasModifying);
407
409 void SetDisableModifiedEvent(bool onOff);
410
416 void Modified() override;
417
421
423
424private:
426 void operator=(const vtkMRMLAbstractLogic&) = delete;
427
428 class vtkInternal;
429 vtkInternal* Internal;
430};
431
432//---------------------------------------------------------------------------
434{
435 bool disabledModify = this->GetDisableModifiedEvent();
436 this->SetDisableModifiedEvent(true);
437 return disabledModify;
438}
439
440//---------------------------------------------------------------------------
441int vtkMRMLAbstractLogic::EndModify(bool previousDisableModifiedEventState)
442{
443 this->SetDisableModifiedEvent(previousDisableModifiedEventState);
444 if (!previousDisableModifiedEventState)
445 {
446 return this->InvokePendingModifiedEvent();
447 }
448 return this->GetPendingModifiedEventCount();
449}
450
451#endif
int GetProcessingMRMLSceneEvent() const
Return the event id currently processed or 0 if any.
virtual void OnMRMLSceneStartImport()
virtual void OnMRMLSceneStartClose()
virtual void OnMRMLNodeModified(vtkMRMLNode *)
vtkMRMLScene * GetMRMLScene() const
Return a reference to the current MRML scene.
vtkCallbackCommand * GetMRMLLogicsCallbackCommand()
int GetInMRMLSceneCallbackFlag() const
static vtkMRMLAbstractLogic * New()
void PrintSelf(ostream &os, vtkIndent indent) override
vtkCallbackCommand * GetMRMLNodesCallbackCommand()
void SetDisableModifiedEvent(bool onOff)
~vtkMRMLAbstractLogic() override
virtual void ProcessMRMLNodesEvents(vtkObject *caller, unsigned long event, void *callData)
virtual bool EnterMRMLLogicsCallback() const
void Modified() override
void SetInMRMLNodesCallbackFlag(int flag)
vtkCallbackCommand * GetMRMLSceneCallbackCommand()
virtual void UpdateFromMRMLScene()
void SetMRMLScene(vtkMRMLScene *newScene)
Set and observe the MRMLScene.
virtual void ProcessMRMLSceneEvents(vtkObject *caller, unsigned long event, void *callData)
virtual vtkMRMLApplicationLogic * GetMRMLApplicationLogic() const
Get access to overall application state.
virtual bool EnterMRMLSceneCallback() const
static void MRMLLogicsCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
MRMLLogicCallback is a static function to relay modified events from the logics.
static void MRMLNodesCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
MRMLNodesCallback is a static function to relay modified events from the nodes.
vtkObserverManager * GetMRMLLogicsObserverManager() const
bool GetDisableModifiedEvent() const
virtual void OnMRMLSceneEndClose()
vtkObserverManager * GetMRMLNodesObserverManager() const
virtual void SetMRMLSceneInternal(vtkMRMLScene *newScene)
virtual void OnMRMLSceneNodeRemoved(vtkMRMLNode *)
virtual void SetMRMLApplicationLogic(vtkMRMLApplicationLogic *logic)
virtual void UnobserveMRMLScene()
void(vtkMRMLAbstractLogic::* TaskFunctionPointer)(void *clientdata)
int EndModify(bool wasModifying)
int GetPendingModifiedEventCount() const
virtual void ObserveMRMLScene()
virtual void OnMRMLSceneNodeAdded(vtkMRMLNode *)
void SetAndObserveMRMLSceneEventsInternal(vtkMRMLScene *newScene, vtkIntArray *events, vtkFloatArray *priorities=nullptr)
virtual void OnMRMLSceneEndBatchProcess()
void SetInMRMLLogicsCallbackFlag(int flag)
void SetInMRMLSceneCallbackFlag(int flag)
int GetInMRMLNodesCallbackFlag() const
virtual void ProcessMRMLLogicsEvents(vtkObject *caller, unsigned long event, void *callData)
int InvokePendingModifiedEvent()
int GetInMRMLLogicsCallbackFlag() const
virtual void OnMRMLSceneEndImport()
virtual bool EnterMRMLNodesCallback() const
virtual void OnMRMLSceneStartRestore()
vtkObserverManager * GetMRMLSceneObserverManager() const
void SetProcessingMRMLSceneEvent(int event)
virtual void OnMRMLSceneEndRestore()
static void MRMLSceneCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
virtual void OnMRMLSceneStartBatchProcess()
Abstract Superclass for all specific types of MRML nodes.
A set of MRML Nodes that supports serialization and undo/redo.
Manages adding and deleting of observers with events.