vtkSlicerLogic.h

Go to the documentation of this file.
00001 /*=auto=========================================================================
00002 
00003   Portions (c) Copyright 2005 Brigham and Women's Hospital (BWH) All Rights Reserved.
00004 
00005   See Doc/copyright/copyright.txt
00006   or http://www.slicer.org/copyright/copyright.txt for details.
00007 
00008   Program:   3D Slicer
00009   Module:    $RCSfile: vtkSlicerLogic.h,v $
00010   Date:      $Date: 2010-02-15 16:35:35 -0500 (Mon, 15 Feb 2010) $
00011   Version:   $Revision: 12142 $
00012 
00013 =========================================================================auto=*/
00020 
00021 #ifndef __vtkSlicerLogic_h
00022 #define __vtkSlicerLogic_h
00023 
00024 #include "vtkCommand.h"
00025 
00026 #include "vtkSlicerBaseLogic.h"
00027 #include "vtkObject.h"
00028 #include "vtkObjectFactory.h"
00029 #include "vtkIntArray.h"
00030 #include "vtkUnsignedLongArray.h"
00031 
00032 #include "vtkMRMLScene.h"
00033 #include "vtkObserverManager.h"
00034 
00035 //BTX
00036 
00037 #ifndef vtkSetMRMLNodeMacro
00038 #define vtkSetMRMLNodeMacro(node,value)  { \
00039   vtkObject *oldNode = (node); \
00040   this->MRMLObserverManager->SetObject ( vtkObjectPointer( &(node)), (value) ); \
00041   if ( oldNode != (node) ) \
00042     { \
00043     this->InvokeEvent (vtkCommand::ModifiedEvent); \
00044     } \
00045 };
00046 #endif
00047 
00048 #ifndef vtkSetAndObserveMRMLNodeMacro
00049 #define vtkSetAndObserveMRMLNodeMacro(node,value)  { \
00050   vtkObject *oldNode = (node); \
00051   this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node) ), (value) ); \
00052   if ( oldNode != (node) ) \
00053     { \
00054     this->InvokeEvent (vtkCommand::ModifiedEvent); \
00055     } \
00056 };
00057 #endif
00058 
00059 #ifndef vtkSetAndObserveNoModifyMRMLNodeMacro
00060 #define vtkSetAndObserveNoModifyMRMLNodeMacro(node,value)  { \
00061   this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node) ), (value) ); \
00062 };
00063 #endif
00064 
00065 #ifndef vtkSetAndObserveMRMLNodeEventsMacro
00066 #define vtkSetAndObserveMRMLNodeEventsMacro(node,value,events)  { \
00067   vtkObject *oldNode = (node); \
00068   this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events)); \
00069   if ( oldNode != (node) ) \
00070     { \
00071     this->InvokeEvent (vtkCommand::ModifiedEvent); \
00072     } \
00073 };
00074 #endif
00075 
00076 //ETX
00077 
00078 class VTK_SLICER_BASE_LOGIC_EXPORT vtkSlicerLogic : public vtkObject 
00079 {
00080   public:
00081 
00084   //BTX
00085   typedef void (vtkSlicerLogic::*TaskFunctionPointer)(void *clientdata);
00086   //ETX
00087   
00089   static vtkSlicerLogic *New();
00090   vtkTypeRevisionMacro(vtkSlicerLogic,vtkObject);
00091   void PrintSelf(ostream& os, vtkIndent indent);
00092 
00095   vtkGetObjectMacro (MRMLScene, vtkMRMLScene);
00096 
00099   void SetMRMLScene ( vtkMRMLScene *mrml )
00100     {
00101     vtkObject *oldValue = this->MRMLScene;
00102     this->MRMLObserverManager->SetObject ( vtkObjectPointer( &this->MRMLScene), mrml );
00103     this->RegisterNodes();
00104     if ( oldValue != this->MRMLScene )
00105       {
00106       this->InvokeEvent (vtkCommand::ModifiedEvent);
00107       }
00108     }
00109 
00110   void SetAndObserveMRMLScene ( vtkMRMLScene *mrml )
00111     {
00112     vtkObject *oldValue = this->MRMLScene;
00113     this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &this->MRMLScene), mrml );
00114     this->RegisterNodes();
00115     if ( oldValue != this->MRMLScene )
00116       {
00117       this->InvokeEvent (vtkCommand::ModifiedEvent);
00118       }
00119     }
00120 
00121   void SetAndObserveMRMLSceneEvents ( vtkMRMLScene *mrml, vtkIntArray *events )
00122     {
00123     vtkObject *oldValue = this->MRMLScene;
00124     this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &this->MRMLScene), mrml, events );
00125     this->RegisterNodes();
00126     if ( oldValue != this->MRMLScene )
00127       {
00128       this->InvokeEvent (vtkCommand::ModifiedEvent);
00129       }
00130     }
00131 
00132   virtual void ProcessMRMLEvents ( vtkObject * /*caller*/, 
00133       unsigned long /*event*/, void * /*callData*/ ) { };
00134 
00135   virtual void ProcessLogicEvents( vtkObject * /*caller*/, 
00136       unsigned long /*event*/, void * /*callData*/ ) { };
00137 
00138   virtual void ProcessLogicEvents() {};
00139 
00142   vtkSetStringMacro(Name);
00143   vtkGetStringMacro(Name);
00144   
00148   void SetInLogicCallbackFlag (int flag) {
00149     this->InLogicCallbackFlag = flag;
00150   }
00151   vtkGetMacro(InLogicCallbackFlag, int);
00152   void SetInMRMLCallbackFlag (int flag) {
00153     this->InMRMLCallbackFlag = flag;
00154   }
00155   vtkGetMacro(InMRMLCallbackFlag, int);
00156 
00158 
00161   virtual vtkIntArray* NewObservableEvents() { return vtkIntArray::New(); };
00162 
00163 protected:
00164   vtkSlicerLogic();
00165   virtual ~vtkSlicerLogic();
00166   vtkSlicerLogic(const vtkSlicerLogic&);
00167   void operator=(const vtkSlicerLogic&);
00168 
00171   virtual void RegisterNodes();
00172 
00173   vtkMRMLScene *MRMLScene;
00174 
00175   char *Name;
00176 
00177   //BTX
00181   static void MRMLCallback(vtkObject *caller, 
00182                 unsigned long eid, void *clientData, void *callData);
00183   static void LogicCallback(vtkObject *caller, 
00184                 unsigned long eid, void *clientData, void *callData);
00185 
00186   //ETX
00187 
00190   vtkCallbackCommand *LogicCallbackCommand;
00191 
00194   int InLogicCallbackFlag;
00195   int InMRMLCallbackFlag;
00196 
00197 
00198   vtkObserverManager *MRMLObserverManager;
00199 
00200 };
00201 
00202 #endif
00203 

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1