Slicer 5.4
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//----------------------------------------------------------------------------
31// Convenient macros
32
33//----------------------------------------------------------------------------
34// It removes all the event observations associated with the old value.
35#ifndef vtkSetMRMLNodeMacro
36#define vtkSetMRMLNodeMacro(node,value) { \
37 vtkObject *_oldNode = (node); \
38 this->GetMRMLNodesObserverManager()->SetObject( \
39 vtkObjectPointer(&(node)), (value)); \
40 vtkObject *_newNode = (node); \
41 if (_oldNode != _newNode) \
42 { \
43 this->Modified(); \
44 } \
45};
46#endif
47
48//----------------------------------------------------------------------------
49#ifndef vtkSetAndObserveMRMLNodeMacro
66#define vtkSetAndObserveMRMLNodeMacro(node,value) { \
67 vtkObject *_oldNode = (node); \
68 this->GetMRMLNodesObserverManager()->SetAndObserveObject( \
69 vtkObjectPointer(&(node)), (value)); \
70 vtkObject *_newNode = (node); \
71 if (_oldNode != _newNode) \
72 { \
73 this->Modified(); \
74 } \
75};
76#endif
77
78//----------------------------------------------------------------------------
79#ifndef vtkSetAndObserveMRMLNodeEventsMacro
80#define vtkSetAndObserveMRMLNodeEventsMacro(node,value,events) { \
81 vtkObject *_oldNode = (node); \
82 this->GetMRMLNodesObserverManager()->SetAndObserveObjectEvents( \
83 vtkObjectPointer(&(node)), (value), (events)); \
84 vtkObject *_newNode = (node); \
85 if (_oldNode != _newNode) \
86 { \
87 this->Modified(); \
88 } \
89};
90#endif
91
92#ifndef vtkObserveMRMLNodeMacro
93#define vtkObserveMRMLNodeMacro(node) \
94{ \
95 this->GetMRMLNodesObserverManager()->ObserveObject( (node) ); \
96};
97#endif
98
99
100#ifndef vtkObserveMRMLNodeEventsMacro
101#define vtkObserveMRMLNodeEventsMacro(node, events) \
102{ \
103 this->GetMRMLNodesObserverManager()->AddObjectEvents ( (node), (events) ); \
104};
105#endif
106
107#ifndef vtkUnObserveMRMLNodeMacro
108#define vtkUnObserveMRMLNodeMacro(node) \
109{ \
110 this->GetMRMLNodesObserverManager()->RemoveObjectEvents ( (node) ); \
111};
112#endif
113
114#ifndef vtkIsObservedMRMLNodeEventMacro
115#define vtkIsObservedMRMLNodeEventMacro(node, event) \
116 ( \
117 this->GetMRMLNodesObserverManager()->GetObservationsCount(node, event) != 0 \
118 )
119#endif
120
133class VTK_MRML_LOGIC_EXPORT vtkMRMLAbstractLogic : public vtkObject
134{
135public:
138 typedef void (vtkMRMLAbstractLogic::*TaskFunctionPointer)(void *clientdata);
139
141 void PrintSelf(ostream& os, vtkIndent indent) override;
142 vtkTypeMacro(vtkMRMLAbstractLogic, vtkObject);
143
147
150
152 void SetMRMLScene(vtkMRMLScene * newScene);
153
162 void SetAndObserveMRMLScene(vtkMRMLScene * newScene);
163 void SetAndObserveMRMLSceneEvents(vtkMRMLScene * newScene, vtkIntArray * events, vtkFloatArray* priorities=nullptr);
165
166protected:
167
170
173 virtual void ProcessMRMLSceneEvents(vtkObject* caller,
174 unsigned long event,
175 void * callData);
176
186 virtual void ProcessMRMLNodesEvents(vtkObject* caller,
187 unsigned long event,
188 void * callData);
189
196 virtual void ProcessMRMLLogicsEvents(vtkObject* caller,
197 unsigned long event,
198 void * callData);
199
204 vtkCallbackCommand * GetMRMLSceneCallbackCommand();
205
210 vtkCallbackCommand * GetMRMLNodesCallbackCommand();
211
214 vtkCallbackCommand * GetMRMLLogicsCallbackCommand();
215
219
223
227
230
236 virtual void UnobserveMRMLScene();
244 virtual void ObserveMRMLScene();
251 virtual void UpdateFromMRMLScene();
252
269 virtual void OnMRMLSceneStartClose(){}
274 virtual void OnMRMLSceneEndClose(){}
279 virtual void OnMRMLSceneStartImport(){}
284 virtual void OnMRMLSceneEndImport(){}
289 virtual void OnMRMLSceneStartRestore(){}
294 virtual void OnMRMLSceneEndRestore(){}
299 virtual void OnMRMLSceneNew(){}
304 virtual void OnMRMLSceneNodeAdded(vtkMRMLNode* /*node*/){}
309 virtual void OnMRMLSceneNodeRemoved(vtkMRMLNode* /*node*/){}
310
313 virtual void OnMRMLNodeModified(vtkMRMLNode* /*node*/){}
314
321 virtual void SetMRMLSceneInternal(vtkMRMLScene* newScene);
322
326 void SetAndObserveMRMLSceneInternal(vtkMRMLScene *newScene);
328
342 vtkIntArray *events,
343 vtkFloatArray *priorities=nullptr);
344
347 virtual void RegisterNodes(){}
348
354
360
363 virtual bool EnterMRMLSceneCallback()const;
364
368
374
380
384 virtual bool EnterMRMLNodesCallback()const;
385
391
397
400 virtual bool EnterMRMLLogicsCallback()const;
401
404 static void MRMLSceneCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData);
405
407 static void MRMLNodesCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData);
408
410 static void MRMLLogicsCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData);
411
415 inline bool StartModify() ;
416
420 inline int EndModify(bool wasModifying);
421
423 void SetDisableModifiedEvent(bool onOff);
424
430 void Modified() override;
431
435
437
438private:
439
441 void operator=(const vtkMRMLAbstractLogic&) = delete;
442
443 class vtkInternal;
444 vtkInternal * Internal;
445
446};
447
448//---------------------------------------------------------------------------
450{
451 bool disabledModify = this->GetDisableModifiedEvent();
452 this->SetDisableModifiedEvent(true);
453 return disabledModify;
454}
455
456//---------------------------------------------------------------------------
457int vtkMRMLAbstractLogic::EndModify(bool previousDisableModifiedEventState)
458{
459 this->SetDisableModifiedEvent(previousDisableModifiedEventState);
460 if (!previousDisableModifiedEventState)
461 {
462 return this->InvokePendingModifiedEvent();
463 }
464 return this->GetPendingModifiedEventCount();
465}
466
467#endif
Superclass for MRML logic classes.
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()
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.