vtkMRMLNode.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: vtkMRMLNode.h,v $
00010   Date:      $Date: 2006/03/19 17:12:29 $
00011   Version:   $Revision: 1.18 $
00012 
00013 =========================================================================auto=*/
00019 
00020 #ifndef __vtkMRMLNode_h
00021 #define __vtkMRMLNode_h
00022 
00023 #include <string>
00024 #include <map>
00025 
00026 #include "vtkObject.h"
00027 
00028 #include "vtkMRML.h"
00029 #include "vtkObserverManager.h"
00030 #include "vtkEventBroker.h"
00031 
00032 #ifndef vtkSetMRMLObjectMacro
00033 #define vtkSetMRMLObjectMacro(node,value)  {this->MRMLObserverManager->SetObject ( vtkObjectPointer( &(node)), (value) );};
00034 #endif
00035 
00036 #ifndef vtkSetAndObserveMRMLObjectMacro
00037 #define vtkSetAndObserveMRMLObjectMacro(node,value)  {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value) );};
00038 #endif
00039 
00040 #ifndef vtkSetAndObserveMRMLObjectEventsMacro
00041 #define vtkSetAndObserveMRMLObjectEventsMacro(node,value,events)  {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events));};
00042 #endif
00043 
00044 //BTX
00045 #ifndef vtkSetReferenceStringMacro
00046 #define vtkSetReferenceStringMacro(name) \
00047 virtual void Set##name (const char* _arg) \
00048   { \
00049   vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
00050   if ( this->name == NULL && _arg == NULL) { return;} \
00051   if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
00052   std::string oldValue; \
00053   if (this->name) { oldValue = this->name; delete [] this->name;  } \
00054   if (_arg) \
00055     { \
00056     size_t n = strlen(_arg) + 1; \
00057     char *cp1 =  new char[n]; \
00058     const char *cp2 = (_arg); \
00059     this->name = cp1; \
00060     do { *cp1++ = *cp2++; } while ( --n ); \
00061     } \
00062    else \
00063     { \
00064     this->name = NULL; \
00065     } \
00066   this->Modified(); \
00067   if (this->Scene && this->name) \
00068     { \
00069     if (oldValue.size() > 0) \
00070       { \
00071       this->Scene->RemoveReferencedNodeID(oldValue.c_str(), this); \
00072       } \
00073     this->Scene->AddReferencedNodeID(this->name, this); \
00074     } \
00075   } 
00076 #endif
00077 //ETX
00078 
00079 class vtkMRMLScene;
00080 class vtkCallbackCommand;
00081 
00082 class VTK_MRML_EXPORT vtkMRMLNode : public vtkObject
00083 {
00084   //BTX
00088     friend class vtkMRMLScene;
00089   //ETX
00090 public:
00091   static vtkMRMLNode *New();
00092   vtkTypeMacro(vtkMRMLNode,vtkObject);
00093   void PrintSelf(ostream& os, vtkIndent indent);
00094   
00098   virtual vtkMRMLNode* CreateNodeInstance() = 0;
00099 
00104   virtual void ReadXMLAttributes(const char** atts);
00105 
00109   virtual void UpdateReferences() {};
00110 
00114   virtual void ProcessParentNode(vtkMRMLNode *){};
00115 
00119   virtual void ProcessChildNode(vtkMRMLNode *){};
00120   
00125   virtual void UpdateScene(vtkMRMLScene *) {};
00126 
00131   virtual void WriteXML(ostream& of, int indent);
00132 
00135   virtual void WriteNodeBodyXML(ostream& of, int indent);
00136   
00141   virtual void Copy(vtkMRMLNode *node);
00142 
00145   void CopyWithScene(vtkMRMLNode *node);
00146   
00152   virtual void Reset();
00153 
00158   virtual int StartModify() 
00159     {
00160     int disabledModify = this->GetDisableModifiedEvent();
00161     this->DisableModifiedEventOn();
00162     return disabledModify;
00163     };
00164 
00168   virtual void EndModify(int previousDisableModifiedEventState) 
00169     {
00170     this->SetDisableModifiedEvent(previousDisableModifiedEventState);
00171     if (!previousDisableModifiedEventState)
00172       {
00173       this->InvokePendingModifiedEvent();
00174       }
00175     };
00176 
00177 
00181   virtual const char* GetNodeTagName() = 0;
00182 
00185   void SetAttribute(const char* name, const char* value);
00186   void SetNthAttribute(int i, const char* value);
00187 
00191   const char* GetAttribute(const char* name);
00192   int GetNumberOfAttributes();
00193   const char* GetNthAttributeName(int i);
00194 
00197   vtkGetMacro(HideFromEditors, int);
00198   vtkSetMacro(HideFromEditors, int);
00199   vtkBooleanMacro(HideFromEditors, int);
00200 
00203   vtkGetMacro(Selectable, int);
00204   vtkSetMacro(Selectable, int);
00205   vtkBooleanMacro(Selectable, int);
00206 
00207   
00210   virtual void ProcessMRMLEvents ( vtkObject *caller, unsigned long event, void *callData );
00211 
00215   vtkGetMacro(InMRMLCallbackFlag, int);
00216   void SetInMRMLCallbackFlag (int flag) {
00217     this->InMRMLCallbackFlag = flag;
00218   }
00219 
00222   vtkSetStringMacro(Description);
00223   vtkGetStringMacro(Description);
00224 
00227   vtkSetStringMacro(SceneRootDir);
00228   vtkGetStringMacro(SceneRootDir);
00229   
00232   vtkSetStringMacro(Name);
00233   vtkGetStringMacro(Name);
00234   
00235   
00239   vtkGetMacro(Indent, int);
00240   
00243   //vtkSetStringMacro(ID);
00244   vtkGetStringMacro(ID);
00245 
00246   void UpdateID(const char *newID)
00247     {
00248     this->SetID(newID);
00249     };
00252   void CopyID(vtkMRMLNode *node);
00253 
00258   vtkSetStringMacro(SingletonTag);
00259   vtkGetStringMacro(SingletonTag);
00260 
00263   vtkGetMacro(ModifiedSinceRead, int);
00264   vtkSetMacro(ModifiedSinceRead, int);
00265   vtkBooleanMacro(ModifiedSinceRead, int);
00266 
00269   vtkGetMacro(SaveWithScene, int);
00270   vtkSetMacro(SaveWithScene, int);
00271   vtkBooleanMacro(SaveWithScene, int);
00272 
00275   vtkGetMacro(AddToScene, int);
00276   vtkSetMacro(AddToScene, int);
00277   vtkBooleanMacro(AddToScene, int);
00278   void SetAddToSceneNoModify(int value);
00279 
00282   vtkGetMacro(DisableModifiedEvent, int);
00283   void SetDisableModifiedEvent(int onOff)
00284     {
00285     this->DisableModifiedEvent = onOff;
00286     }
00287   void DisableModifiedEventOn()
00288     {
00289     this->SetDisableModifiedEvent(1);
00290     }
00291   void DisableModifiedEventOff()
00292     {
00293     this->SetDisableModifiedEvent(0);
00294     }
00295 
00302   virtual void Modified() 
00303     {
00304     if (!this->GetDisableModifiedEvent())
00305       {
00306       Superclass::Modified();
00307       }
00308     else
00309       {
00310       this->ModifiedEventPending = 1;
00311       }
00312     }
00313 
00317   void InvokePendingModifiedEvent ()
00318     {
00319     if ( this->ModifiedEventPending )
00320       {
00321       Superclass::Modified();
00322       }
00323     this->ModifiedEventPending = 0;
00324     }
00325 
00326   void CopyWithSingleModifiedEvent (vtkMRMLNode *node)
00327     {
00328     int oldMode = this->GetDisableModifiedEvent();
00329     this->DisableModifiedEventOn();
00330     this->Copy(node);
00331     this->InvokePendingModifiedEvent();
00332     this->SetDisableModifiedEvent(oldMode);
00333     }
00334     
00335   void CopyWithoutModifiedEvent (vtkMRMLNode *node)
00336     {
00337     int oldMode = this->GetDisableModifiedEvent();
00338     this->DisableModifiedEventOn();
00339     this->Copy(node);
00340     this->SetDisableModifiedEvent(oldMode);
00341     }
00342 
00343   void CopyWithSceneWithSingleModifiedEvent (vtkMRMLNode *node)
00344     {
00345     int oldMode = this->GetDisableModifiedEvent();
00346     this->DisableModifiedEventOn();
00347     this->CopyWithScene(node);
00348     this->InvokePendingModifiedEvent();
00349     this->SetDisableModifiedEvent(oldMode);
00350     }
00351 
00352   void CopyWithSceneWithoutModifiedEvent (vtkMRMLNode *node)
00353     {
00354     int oldMode = this->GetDisableModifiedEvent();
00355     this->DisableModifiedEventOn();
00356     this->CopyWithScene(node);
00357     this->SetDisableModifiedEvent(oldMode);
00358     }
00359   
00360   vtkMRMLScene* GetScene() {return this->Scene;};
00361   void SetScene(vtkMRMLScene* scene) {this->Scene = scene;};
00362 
00365   virtual void UpdateReferenceID(const char *oldID, const char *newID);
00366 
00371   const char *URLEncodeString(const char *inString);
00376   const char *URLDecodeString(const char *inString);
00377 
00379   vtkGetMacro(Selected, int);
00380   vtkSetMacro(Selected, int);
00381   vtkBooleanMacro(Selected, int);
00382 
00383 protected:
00384   
00385   vtkMRMLNode();
00387   virtual ~vtkMRMLNode();
00388   vtkMRMLNode(const vtkMRMLNode&);
00389   void operator=(const vtkMRMLNode&);
00390   
00391   vtkSetMacro(Indent, int);
00392 
00393   //BTX
00396   static void MRMLCallback( vtkObject *caller,
00397                             unsigned long eid, void *clientData, void *callData );
00398 
00401   vtkCallbackCommand *MRMLCallbackCommand;
00402 
00405   int InMRMLCallbackFlag;
00406 
00407   char *Description;
00408   char *SceneRootDir;
00409   char *Name;
00410   char *ID;
00411   int Indent;
00412   int HideFromEditors;
00413   int Selectable;
00414   int Selected;
00415   int AddToScene;
00416 
00417   int  ModifiedSinceRead;
00418   int  SaveWithScene;
00419 
00420   vtkMRMLScene *Scene;
00421 
00422   //BTX
00423   std::map< std::string, std::string > Attributes;
00424   //ETX
00425 
00426   vtkObserverManager *MRMLObserverManager;
00427 
00430   vtkSetStringMacro( TempURLString );
00431   vtkGetStringMacro( TempURLString );
00432   
00433 private:
00436   vtkSetStringMacro(ID);
00437  
00441   const char* ConstructID(const char * str, int index);
00442 
00445   void ConstructAndSetID(const char * str, int index);
00446 
00447   //BTX
00450   std::string TempID;
00451   //ETX
00452 
00455   char * TempURLString;
00456 
00457   char *SingletonTag;
00458 
00459   int DisableModifiedEvent;
00460   int ModifiedEventPending;
00461 };
00462 
00463 #endif
00464 
00465 
00466 

Generated on 6 Apr 2011 for Slicer3 by  doxygen 1.6.1