Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
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>
18 class vtkMRMLNode;
19 class vtkMRMLScene;
20 
21 // VTK includes
22 #include <vtkCommand.h>
23 #include <vtkObject.h>
24 class vtkIntArray;
25 class 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
50 #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 
133 class VTK_MRML_LOGIC_EXPORT vtkMRMLAbstractLogic : public vtkObject
134 {
135 public:
138  typedef void (vtkMRMLAbstractLogic::*TaskFunctionPointer)(void *clientdata);
139 
140  static vtkMRMLAbstractLogic *New();
141  void PrintSelf(ostream& os, vtkIndent indent) override;
142  vtkTypeMacro(vtkMRMLAbstractLogic, vtkObject);
143 
145  virtual vtkMRMLApplicationLogic* GetMRMLApplicationLogic()const;
146  virtual void SetMRMLApplicationLogic(vtkMRMLApplicationLogic* logic);
147 
149  vtkMRMLScene * GetMRMLScene()const;
150 
152  void SetMRMLScene(vtkMRMLScene * newScene);
153 
162  void SetAndObserveMRMLScene(vtkMRMLScene * newScene);
163  void SetAndObserveMRMLSceneEvents(vtkMRMLScene * newScene, vtkIntArray * events, vtkFloatArray* priorities=nullptr);
165 
166 protected:
167 
169  ~vtkMRMLAbstractLogic() override;
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 
218  vtkObserverManager * GetMRMLSceneObserverManager()const;
219 
222  vtkObserverManager * GetMRMLNodesObserverManager()const;
223 
226  vtkObserverManager * GetMRMLLogicsObserverManager()const;
227 
229  int GetProcessingMRMLSceneEvent()const;
230 
236  virtual void UnobserveMRMLScene();
244  virtual void ObserveMRMLScene();
251  virtual void UpdateFromMRMLScene();
252 
264  virtual void OnMRMLSceneEndBatchProcess();
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 
341  void SetAndObserveMRMLSceneEventsInternal(vtkMRMLScene *newScene,
342  vtkIntArray *events,
343  vtkFloatArray *priorities=nullptr);
344 
347  virtual void RegisterNodes(){}
348 
353  void SetInMRMLSceneCallbackFlag(int flag);
354 
359  int GetInMRMLSceneCallbackFlag()const;
360 
363  virtual bool EnterMRMLSceneCallback()const;
364 
367  void SetProcessingMRMLSceneEvent(int event);
368 
373  void SetInMRMLNodesCallbackFlag(int flag);
374 
379  int GetInMRMLNodesCallbackFlag()const;
380 
384  virtual bool EnterMRMLNodesCallback()const;
385 
390  void SetInMRMLLogicsCallbackFlag(int flag);
391 
396  int GetInMRMLLogicsCallbackFlag()const;
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 
422  bool GetDisableModifiedEvent()const;
423  void SetDisableModifiedEvent(bool onOff);
424 
430  void Modified() override;
431 
434  int InvokePendingModifiedEvent();
435 
436  int GetPendingModifiedEventCount()const;
437 
438 private:
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 //---------------------------------------------------------------------------
457 int 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
virtual void OnMRMLSceneStartClose()
Superclass for MRML logic classes.
int InvokePendingModifiedEvent()
virtual void OnMRMLSceneEndImport()
virtual void OnMRMLSceneEndClose()
Manages adding and deleting of obserevers with events.
bool GetDisableModifiedEvent() const
virtual void OnMRMLSceneStartImport()
int EndModify(bool wasModifying)
virtual void OnMRMLSceneStartBatchProcess()
virtual void OnMRMLNodeModified(vtkMRMLNode *)
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:61
virtual void OnMRMLSceneNodeAdded(vtkMRMLNode *)
virtual void OnMRMLSceneNodeRemoved(vtkMRMLNode *)
int GetPendingModifiedEventCount() const
virtual void OnMRMLSceneEndRestore()
virtual void OnMRMLSceneStartRestore()
void SetDisableModifiedEvent(bool onOff)
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167