Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
vtkMRMLNode.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 Program: 3D Slicer
9 Module: $RCSfile: vtkMRMLNode.h,v $
10 Date: $Date: 2006/03/19 17:12:29 $
11 Version: $Revision: 1.18 $
12
13=========================================================================auto=*/
14
15#ifndef __vtkMRMLNode_h
16#define __vtkMRMLNode_h
17
18// MRML includes
19#include "vtkMRML.h"
20#include "vtkObserverManager.h"
21#include "vtkIdTypeArray.h"
22#include "vtkIntArray.h"
23
24class vtkMRMLScene;
25class vtkStringArray;
26
27// VTK includes
28#include <vtkObject.h>
29#include <vtkSmartPointer.h>
30#include <vtkWeakPointer.h>
31class vtkCallbackCommand;
32
33// Slicer VTK add-on includes
34#include <vtkLoggingMacros.h>
35
36// Helper macros for simplifying reading, writing, copying, and printing node properties.
38
39// STD includes
40#include <map>
41#include <set>
42#include <string>
43#include <vector>
44
45#ifndef vtkSetMRMLObjectMacro
46#define vtkSetMRMLObjectMacro(node,value) {this->MRMLObserverManager->SetObject ( vtkObjectPointer( &(node)), (value) );};
47#endif
48
50#ifndef vtkSetAndObserveMRMLObjectMacro
51#define vtkSetAndObserveMRMLObjectMacro(node,value) {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value) );};
52#endif
53
54#ifndef vtkSetAndObserveMRMLObjectMacroNoWarning
55#define vtkSetAndObserveMRMLObjectMacroNoWarning(node,value) {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value), 0.0, false /* no warning */ );};
56#endif
57
58#ifndef vtkSetAndObserveMRMLObjectEventsMacro
59#define vtkSetAndObserveMRMLObjectEventsMacro(node,value,events) {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events));};
60#endif
61
62#ifndef vtkSetAndObserveMRMLObjectEventsMacroNoWarning
63#define vtkSetAndObserveMRMLObjectEventsMacroNoWarning(node,value,events) {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events), nullptr /* priorities */, false /* no warning */);};
64#endif
65
66#ifndef vtkObserveMRMLObjectMacro
67#define vtkObserveMRMLObjectMacro(node) {this->MRMLObserverManager->ObserveObject ( (node) );};
68#endif
69
70#ifndef vtkObserveMRMLObjectEventMacro
71#define vtkObserveMRMLObjectEventMacro(node, event) {this->MRMLObserverManager->AddObjectEvent ( (node), (event) );};
72#endif
73
74#ifndef vtkObserveMRMLObjectEventMacroNoWarning
75#define vtkObserveMRMLObjectEventMacroNoWarning(node, event) {this->MRMLObserverManager->AddObjectEvent ( (node), (event), 0.0, false );};
76#endif
77
78#ifndef vtkObserveMRMLObjectEventsMacro
79#define vtkObserveMRMLObjectEventsMacro(node, events) {this->MRMLObserverManager->AddObjectEvents ( (node), (events) );};
80#endif
81
82#ifndef vtkUnObserveMRMLObjectMacro
83#define vtkUnObserveMRMLObjectMacro(node) {this->MRMLObserverManager->RemoveObjectEvents ( (node) );};
84#endif
85
86#ifndef vtkSetReferenceStringBodyMacro
87#define vtkSetReferenceStringBodyMacro(name) \
88 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
89 if ( this->name == nullptr && _arg == nullptr) { return;} \
90 if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
91 std::string oldValue; \
92 if (this->name) { oldValue = this->name; delete [] this->name; } \
93 if (_arg) \
94 { \
95 size_t n = strlen(_arg) + 1; \
96 char *cp1 = new char[n]; \
97 const char *cp2 = (_arg); \
98 this->name = cp1; \
99 do { *cp1++ = *cp2++; } while ( --n ); \
100 } \
101 else \
102 { \
103 this->name = nullptr; \
104 } \
105 this->Modified(); \
106 if (this->Scene && this->name) \
107 { \
108 if (oldValue.size() > 0) \
109 { \
110 this->Scene->RemoveReferencedNodeID(oldValue.c_str(), this); \
111 } \
112 this->Scene->AddReferencedNodeID(this->name, this); \
113 }
114#endif
115
116#ifndef vtkSetReferenceStringMacro
117#define vtkSetReferenceStringMacro(name) \
118virtual void Set##name (const char* _arg) \
119{ \
120 vtkSetReferenceStringBodyMacro(name)\
121}
122#endif
123
124#ifndef vtkCxxSetReferenceStringMacro
125#define vtkCxxSetReferenceStringMacro(class,name) \
126void class::Set##name (const char* _arg) \
127{ \
128 vtkSetReferenceStringBodyMacro(name); \
129}
130#endif
131
132#ifndef vtkMRMLNodeNewMacro
133#define vtkMRMLNodeNewMacro(newClass) \
134 vtkStandardNewMacro(newClass); \
135 vtkMRMLNode* newClass::CreateNodeInstance() \
136 { \
137 return newClass::New(); \
138 }
139#endif
140
141// Use this macro to declare that this node supports
142// CopyContent.It also declares CopyContent and
143// HasCopyContent methods.
144//
145// The use of HasCopyContent() may be needed to determine if
146// a specific node class has implemented CopyContent (if only
147// a parent class implemented it that may not be enough).
148//
149#ifndef vtkMRMLCopyContentMacro
150#define vtkMRMLCopyContentMacro(thisClassName) \
151 void CopyContent(vtkMRMLNode* node, bool deepCopy=true) override; \
152 bool HasCopyContent() const override \
153 { \
154 return strcmp(#thisClassName, this->GetClassNameInternal()) == 0; \
155 }
156#endif
157
158// Use this macro to declare that this node supports
159// CopyContent by only declaring HasCopyContent without
160// implementing CopyContent method
161// (this is the case when parent classes copy all content).
162#ifndef vtkMRMLCopyContentDefaultMacro
163#define vtkMRMLCopyContentDefaultMacro(thisClassName) \
164 bool HasCopyContent() const override \
165 { \
166 return strcmp(#thisClassName, this->GetClassNameInternal()) == 0; \
167 }
168#endif
169
175class VTK_MRML_EXPORT vtkMRMLNode : public vtkObject
176{
179 friend class vtkMRMLScene;
181
182public:
183 vtkTypeMacro(vtkMRMLNode,vtkObject);
184 void PrintSelf(ostream& os, vtkIndent indent) override;
185
194
199
201 virtual bool HasCopyContent() const;
202
208 virtual void ReadXMLAttributes(const char** atts);
209
214 virtual void UpdateReferences();
215
218 virtual void ProcessChildNode(vtkMRMLNode *){};
219
223 virtual void UpdateScene(vtkMRMLScene *)
224 {
225 this->UpdateNodeReferences();
226 };
227
230 virtual void OnNodeAddedToScene()
231 {
232 this->UpdateNodeReferences();
233 };
234
241 virtual void WriteXML(ostream& of, int indent);
242
244 virtual void WriteNodeBodyXML(ostream& of, int indent);
245
252 virtual void Copy(vtkMRMLNode *node);
253
263 virtual void CopyContent(vtkMRMLNode* node, bool deepCopy=true);
264
269 virtual void CopyReferences(vtkMRMLNode* node);
270
286
307 virtual void Reset(vtkMRMLNode* defaultNode);
308
315 virtual int StartModify()
316 {
317 int disabledModify = this->GetDisableModifiedEvent();
319 return disabledModify;
320 };
321
329 virtual int EndModify(int previousDisableModifiedEventState)
330 {
331 this->SetDisableModifiedEvent(previousDisableModifiedEventState);
332 if (!previousDisableModifiedEventState)
333 {
334 return this->InvokePendingModifiedEvent();
335 }
336 return this->ModifiedEventPending;
337 };
338
339
343 virtual const char* GetNodeTagName() = 0;
344
348 virtual const char* GetTypeDisplayName()
349 {
350 return this->GetNodeTagName();
351 }
352
364 void SetAttribute(const char* name, const char* value);
365
367 void RemoveAttribute(const char* name);
368
372 const char* GetAttribute(const char* name);
373
375 std::vector< std::string > GetAttributeNames();
376
378 void GetAttributeNames(vtkStringArray* attributeNames);
379
381 vtkGetMacro(HideFromEditors, int);
382 vtkSetMacro(HideFromEditors, int);
383 vtkBooleanMacro(HideFromEditors, int);
384
386 vtkGetMacro(Selectable, int);
387 vtkSetMacro(Selectable, int);
388 vtkBooleanMacro(Selectable, int);
389
399 vtkGetMacro(UndoEnabled, bool);
400 vtkSetMacro(UndoEnabled, bool);
401 vtkBooleanMacro(UndoEnabled, bool);
402
404 virtual void ProcessMRMLEvents ( vtkObject *caller, unsigned long event, void *callData );
405
410 vtkGetMacro(InMRMLCallbackFlag, int);
411 void SetInMRMLCallbackFlag (int flag) {
412 this->InMRMLCallbackFlag = flag;
413 }
414
416 vtkSetStringMacro(Description);
417 vtkGetStringMacro(Description);
418
420 vtkSetStringMacro(Name);
421 vtkGetStringMacro(Name);
422
424 //vtkSetStringMacro(ID);
425 vtkGetStringMacro(ID);
426
453 vtkSetStringMacro(SingletonTag);
454 vtkGetStringMacro(SingletonTag);
456 {
457 this->SetSingletonTag("Singleton");
458 }
460 {
461 this->SetSingletonTag(nullptr);
462 }
464 {
465 return (this->GetSingletonTag() != nullptr);
466 }
467
469 vtkGetMacro(SaveWithScene, int);
470 vtkSetMacro(SaveWithScene, int);
471 vtkBooleanMacro(SaveWithScene, int);
472
474 vtkGetMacro(AddToScene, int);
475 vtkSetMacro(AddToScene, int);
476 vtkBooleanMacro(AddToScene, int);
477 void SetAddToSceneNoModify(int value);
478
480 vtkGetMacro(DisableModifiedEvent, int);
482 {
483 this->DisableModifiedEvent = onOff;
484 }
486 {
488 }
490 {
492 }
493
499 vtkGetMacro(ModifiedEventPending, int);
500
507 {
508 std::map< int, int >::iterator it = this->CustomModifiedEventPending.find(eventId);
509 if (it == this->CustomModifiedEventPending.end())
510 {
511 return 0;
512 }
513 else
514 {
515 return it->second;
516 }
517 }
518
532 void Modified() override
533 {
534 if (!this->GetDisableModifiedEvent())
535 {
536 Superclass::Modified();
537 }
538 else
539 {
540 ++this->ModifiedEventPending;
541 }
542 }
543
552 {
553 int oldModifiedEventPending = 0;
554 // Invoke pending standard Modified event
555 if ( this->ModifiedEventPending )
556 {
557 oldModifiedEventPending += this->ModifiedEventPending;
558 this->ModifiedEventPending = 0;
559 Superclass::Modified();
560 }
561 // Invoke pending custom modified events
562 if (!this->CustomModifiedEventPending.empty())
563 {
564 // Need to make a copy of the event IDs stored in this->CustomModifiedEventPending,
565 // because event invocation may add more events to this->CustomModifiedEventPending,
566 // which would then make the iterator invalid.
567 std::vector<int> customEventsToInvoke;
568 for (std::map< int, int >::iterator it=this->CustomModifiedEventPending.begin(); it!=this->CustomModifiedEventPending.end(); ++it)
569 {
570 oldModifiedEventPending += it->second;
571 customEventsToInvoke.push_back(it->first);
572 }
573 this->CustomModifiedEventPending.clear();
574 for (std::vector<int>::iterator it=customEventsToInvoke.begin(); it!=customEventsToInvoke.end(); ++it)
575 {
576 this->InvokeEvent(*it);
577 }
578 }
579 return oldModifiedEventPending;
580 }
581
594 virtual void InvokeCustomModifiedEvent(int eventId, void *callData=nullptr)
595 {
596 if (!this->GetDisableModifiedEvent())
597 {
598 // DisableModify is inactive, we immediately invoke the event
599 this->InvokeEvent(eventId, callData);
600 }
601 else
602 {
603 // just remember the custom modified event and invoke it once,
604 // when DisableModify is deactivated
605 ++this->CustomModifiedEventPending[eventId];
606 }
607 }
608
611
617 virtual void SetScene(vtkMRMLScene* scene);
618
623 virtual void SetSceneReferences();
624
626 virtual void UpdateReferenceID(const char *oldID, const char *newID);
627
632 vtkGetObjectMacro(ContentModifiedEvents, vtkIntArray);
633
640 const char *URLEncodeString(const char *inString);
641
648 const char *URLDecodeString(const char *inString);
649
653 std::string XMLAttributeEncodeString(const std::string& inString);
654
662 std::string XMLAttributeDecodeString(const std::string& inString);
663
665 vtkGetMacro(Selected, int);
666 vtkSetMacro(Selected, int);
667 vtkBooleanMacro(Selected, int);
668
689 void AddNodeReferenceRole(const char *referenceRole, const char *mrmlAttributeName=nullptr,
690 vtkIntArray *events=nullptr, bool observeContentModifiedEvents=false);
691
693 vtkMRMLNode* SetNodeReferenceID(const char* referenceRole, const char* referencedNodeID);
694
696 vtkMRMLNode* AddNodeReferenceID(const char* referenceRole , const char* referencedNodeID);
697
700 vtkMRMLNode* SetNthNodeReferenceID(const char* referenceRole, int n, const char* referencedNodeID);
701
711 vtkMRMLNode* SetAndObserveNodeReferenceID(const char* referenceRole , const char* referencedNodeID,
712 vtkIntArray *events=nullptr, ContentModifiedObserveType observeContentModifiedEvents=ContentModifiedObserveUndefined);
713
723 vtkMRMLNode* AddAndObserveNodeReferenceID(const char* referenceRole , const char* referencedNodeID,
724 vtkIntArray *events=nullptr, ContentModifiedObserveType observeContentModifiedEvents=ContentModifiedObserveUndefined);
725
747 vtkMRMLNode* SetAndObserveNthNodeReferenceID(const char* referenceRole, int n, const char *referencedNodeID,
748 vtkIntArray *events=nullptr, ContentModifiedObserveType observeContentModifiedEvents=ContentModifiedObserveUndefined);
749
751 void RemoveNthNodeReferenceID(const char* referenceRole, int n);
752
756 void RemoveNodeReferenceIDs(const char* referenceRole);
757
762 bool HasNodeReferenceID(const char* referenceRole, const char* referencedNodeID);
763
766 int GetNumberOfNodeReferences(const char* referenceRole);
767
774 const char *GetNthNodeReferenceID(const char* referenceRole, int n);
775
780 const char *GetNodeReferenceID(const char* referenceRole);
781
792 vtkMRMLNode* GetNthNodeReference(const char* referenceRole, int n);
793
796 vtkMRMLNode* GetNodeReference(const char* referenceRole);
797
805 void GetNodeReferences(const char* referenceRole, std::vector<vtkMRMLNode*> &nodes);
806
812 void GetNodeReferenceIDs(const char* referenceRole,
813 std::vector<const char*> &referencedNodeIDs);
814
817 void GetNodeReferenceRoles(std::vector<std::string> &roles);
818
822
825 const char* GetNthNodeReferenceRole(int n);
826
829 enum
830 {
837 };
838
840
854 typedef std::map<std::string, std::string> ReferencePropertiesType;
855 const ReferencePropertiesType* GetNthNodeReferenceProperties(const char* referenceRole, int n);
856 const ReferencePropertiesType* GetNodeReferenceProperties(const char* referenceRole);
858
860
862 void SetNodeReferenceProperty(const std::string& referenceRole, const std::string& propertyName, const std::string& value);
863 void SetNthNodeReferenceProperty(const std::string& referenceRole, int n, const std::string& propertyName, const std::string& value);
865
867
869 std::string GetNodeReferenceProperty(const std::string& referenceRole, const std::string& propertyName);
870 std::string GetNthNodeReferenceProperty(const std::string& referenceRole, int n, const std::string& propertyName);
872
874
876 void RemoveNodeReferenceProperty(const std::string& referenceRole, const std::string& propertyName);
877 void RemoveNthNodeReferenceProperty(const std::string& referenceRole, int n, const std::string& propertyName);
879
881
883 int GetNumberOfNodeReferenceProperties(const std::string& referenceRole);
884 int GetNumberOfNthNodeReferenceProperties(const std::string& referenceRole, int n);
886
888
890 std::string GetNodeReferencePropertyName(const std::string& referenceRole, int propertyIndex);
891 std::string GetNthNodeReferencePropertyName(const std::string& referenceRole, int referenceIndex, int propertyIndex);
893
895
897 std::vector<std::string> GetNodeReferencePropertyNames(const std::string& referenceRole);
898 std::vector<std::string> GetNthNodeReferencePropertyNames(const std::string& referenceRole, int n);
900
902
904 void ClearNodeReferenceProperties(const std::string& referenceRole);
905 void ClearNthNodeReferenceProperties(const std::string& referenceRole, int n);
907
908protected:
909
911 class VTK_MRML_EXPORT vtkMRMLNodeReference : public vtkObject
912 {
913 public:
914 vtkTypeMacro(vtkMRMLNodeReference,vtkObject);
916 void PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) override {};
917
918 public:
919 vtkSetStringMacro(ReferenceRole);
920 vtkGetStringMacro(ReferenceRole);
921
922 vtkSetStringMacro(ReferencedNodeID);
923 vtkGetStringMacro(ReferencedNodeID);
924
930 void SetStaticEvents(vtkIntArray* events);
931 vtkIntArray* GetStaticEvents() const;
932
936
939
942
944 bool SetProperty(const std::string& key, const std::string& value);
945
947 std::string GetProperty(const std::string& key) const;
948
950 bool RemoveProperty(const std::string& key);
951
954
955 const ReferencePropertiesType* GetProperties() const { return &this->Properties; }
956 void SetProperties(const ReferencePropertiesType& properties) { this->Properties = properties; }
957
958 protected:
961
964
967
969 vtkWeakPointer<vtkMRMLNode> ReferencingNode;
971 vtkSmartPointer<vtkMRMLNode> ReferencedNode;
972
977 vtkSmartPointer<vtkIntArray> StaticEvents;
982
984 };
985
988 ~vtkMRMLNode() override;
990 void operator=(const vtkMRMLNode&);
991
994 static void MRMLCallback( vtkObject *caller,
995 unsigned long eid, void *clientData, void *callData );
996
999 vtkSetStringMacro( TempURLString );
1000 vtkGetStringMacro( TempURLString );
1001
1009 virtual const char* GetReferenceRoleFromMRMLAttributeName(const char* attName);
1010
1018 virtual const char* GetMRMLAttributeNameFromReferenceRole(const char* refRole);
1019
1023 virtual bool IsReferenceRoleGeneric(const char* refRole);
1024
1028 virtual void UpdateNodeReferences(const char* referenceRole = nullptr);
1029
1033 void RemoveInvalidReferences(const std::set<std::string>& validNodeIDs);
1034
1039 virtual void UpdateNthNodeReference(const char* referenceRole, int n);
1040
1045 vtkIntArray *newEvents, bool newObserveContentModifiedEvents, vtkMRMLNodeReference* referenceToIgnore);
1046
1052 void GetUpdatedReferencedNodeEventList(int& oldReferencedNodeUseCount, int& newReferencedNodeUseCount,
1053 vtkIntArray* oldConsolidatedEventList, vtkIntArray* newConsolidatedEventList,
1054 vtkMRMLNode* oldReferencedNode, vtkMRMLNode* newReferencedNode,
1055 vtkMRMLNodeReference* referenceToIgnore, vtkIntArray* newEvents, bool newObserveContentModifiedEvents);
1056
1060
1065 {
1066 this->InvokeEvent(vtkMRMLNode::ReferenceAddedEvent, reference);
1067 }
1068
1071 {
1072 this->InvokeEvent(vtkMRMLNode::ReferenceModifiedEvent, reference);
1073 }
1074
1077 {
1078 this->InvokeEvent(vtkMRMLNode::ReferenceRemovedEvent, reference);
1079 }
1080
1083 void ParseReferencesAttribute(const char *attValue, std::set<std::string> &references);
1084
1086 std::string NodeReferencePropertyEncodeString(const std::string& inString);
1087
1089 std::string NodeReferencePropertyDecodeString(const std::string& inString);
1090
1092 vtkCallbackCommand *MRMLCallbackCommand;
1093
1094 char *ID{nullptr};
1095 char *Name{nullptr};
1096 char *Description{nullptr};
1099 int Selected{0};
1101 bool UndoEnabled{false};
1102
1103 int SaveWithScene{true};
1104
1108
1109 // We don't increase the reference count of Scene when store its pointer
1110 // therefore we must use a weak pointer to prevent pointer dangling when
1111 // the scene is deleted.
1112 vtkWeakPointer<vtkMRMLScene> Scene;
1113
1114 typedef std::map< std::string, std::string > AttributesType;
1116
1118
1120
1123 typedef std::vector< vtkSmartPointer<vtkMRMLNodeReference> > NodeReferenceListType;
1124 typedef std::map< std::string, NodeReferenceListType > NodeReferencesType;
1126
1127 std::map< std::string, std::string> NodeReferenceMRMLAttributeNames;
1128
1134 typedef std::map< std::string, NodeReferenceEventList> NodeReferenceEventsType;
1135 NodeReferenceEventsType NodeReferenceEvents; // for each role it specifies which referenced node emitted events this node should observe
1136
1137private:
1138
1141 void SetID(const char* newID);
1142
1144 char *TempURLString{nullptr};
1145
1146 char *SingletonTag{nullptr};
1147
1148 int DisableModifiedEvent{0};
1149 int ModifiedEventPending{0};
1150 std::map<int, int> CustomModifiedEventPending; // event id, pending value (number of events grouped together)
1151};
1152
1161class VTK_MRML_EXPORT MRMLNodeModifyBlocker
1162{
1163public:
1164 vtkWeakPointer<vtkMRMLNode> Node;
1167 {
1168 this->Node = node;
1169 if (this->Node)
1170 {
1171 this->WasModifying = this->Node->StartModify();
1172 }
1173 };
1175 {
1176 if (this->Node)
1177 {
1178 this->Node->EndModify(this->WasModifying);
1179 }
1180 }
1181};
1182
1183#endif
MRMLNodeModifyBlocker(vtkMRMLNode *node)
vtkWeakPointer< vtkMRMLNode > Node
Class to hold information about a node reference.
void SetReferencingNode(vtkMRMLNode *node)
vtkIntArray * GetStaticEvents() const
bool SetProperty(const std::string &key, const std::string &value)
Set the properties of the reference.
void PrintSelf(ostream &vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) override
vtkMRMLNodeReference(const vtkMRMLNodeReference &)
ContentModifiedObserveType ObserveContentModifiedEvents
vtkWeakPointer< vtkMRMLNode > ReferencingNode
Points to this MRML node (that added the reference)
void SetProperties(const ReferencePropertiesType &properties)
vtkSmartPointer< vtkIntArray > StaticEvents
Events that should be observed.
void SetReferencedNode(vtkMRMLNode *node)
static vtkMRMLNodeReference * New()
ReferencePropertiesType Properties
vtkMRMLNode * GetReferencingNode() const
char * ReferenceRole
Name of the reference role.
vtkMRMLNode * GetReferencedNode() const
bool RemoveProperty(const std::string &key)
Remove a property from the reference.
bool ClearProperties()
Remove all properties from the reference.
std::string GetProperty(const std::string &key) const
Get the properties of the reference.
void SetStaticEvents(vtkIntArray *events)
Set the events that will be observed when the referenced node will be available.
vtkSmartPointer< vtkMRMLNode > ReferencedNode
The referenced node that is actually observed now.
void operator=(const vtkMRMLNodeReference &)
const ReferencePropertiesType * GetProperties() const
Abstract Superclass for all specific types of MRML nodes.
virtual void UpdateReferences()
The method should remove all pointers and observations to all nodes that are not in the scene anymore...
void DisableModifiedEventOn()
std::vector< vtkSmartPointer< vtkMRMLNodeReference > > NodeReferenceListType
virtual void SetScene(vtkMRMLScene *scene)
This method is for internal use only. Use AddNode method of vtkMRMLScene to add a node to the scene.
virtual int StartModify()
Start modifying the node. Disable Modify events.
vtkMRMLNode * GetNodeReference(const char *referenceRole)
vtkMRMLNode * AddAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=nullptr, ContentModifiedObserveType observeContentModifiedEvents=ContentModifiedObserveUndefined)
Add and observe a reference node from this node for a specific referenceRole.
void DisableModifiedEventOff()
virtual void OnNodeReferenceRemoved(vtkMRMLNodeReference *reference)
Called when a referenced node pointer is removed (set to nullptr).
void ParseReferencesAttribute(const char *attValue, std::set< std::string > &references)
virtual void UpdateNodeReferences(const char *referenceRole=nullptr)
virtual void UpdateNthNodeReference(const char *referenceRole, int n)
int GetNumberOfNodeReferenceRoles()
virtual void OnNodeReferenceModified(vtkMRMLNodeReference *reference)
Called when a referenced node pointer is modified.
virtual const char * GetMRMLAttributeNameFromReferenceRole(const char *refRole)
Return the mrml attribute name (if found) associated with a reference role. Return 0 otherwise.
virtual void WriteNodeBodyXML(ostream &of, int indent)
Write this node's body to a MRML file in XML format.
NodeReferenceEventsType NodeReferenceEvents
vtkMRMLNode * AddNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Convenience method that adds a referencedNodeID at the end of the list.
vtkMRMLNode * UpdateNodeReferenceEventObserver(vtkMRMLNode *oldReferencedNode, vtkMRMLNode *newReferencedNode, vtkIntArray *newEvents, bool newObserveContentModifiedEvents, vtkMRMLNodeReference *referenceToIgnore)
void GetAttributeNames(vtkStringArray *attributeNames)
Get all attribute names. Python-wrappable version.
void ClearNodeReferenceProperties(const std::string &referenceRole)
Remove all node reference properties for a specific referenceRole.
void GetNodeReferenceRoles(std::vector< std::string > &roles)
std::map< std::string, std::string > ReferencePropertiesType
Get the node reference properties for a specific referenceRole.
void SetAddToSceneNoModify(int value)
void RemoveNthNodeReferenceID(const char *referenceRole, int n)
Convenience method that removes the Nth node ID from the list.
std::string GetNthNodeReferenceProperty(const std::string &referenceRole, int n, const std::string &propertyName)
virtual int InvokePendingModifiedEvent()
Invokes any modified events that are pending.
std::map< std::string, NodeReferenceListType > NodeReferencesType
virtual void CopyReferences(vtkMRMLNode *node)
Copy the references of the node into this.
std::string NodeReferencePropertyEncodeString(const std::string &inString)
Encode a node reference property string (replaces special characters by code sequences)
friend class vtkMRMLSceneViewNode
virtual void InvalidateNodeReferences()
virtual void Reset(vtkMRMLNode *defaultNode)
Reset node attributes to the initial state as defined in the constructor or the passed default node.
vtkIntArray * ContentModifiedEvents
std::string XMLAttributeEncodeString(const std::string &inString)
Encode an XML attribute string (replaces special characters by code sequences)
virtual int GetDisableModifiedEvent()
Turn on/off generating InvokeEvent for set macros.
AttributesType Attributes
void RemoveNodeReferenceProperty(const std::string &referenceRole, const std::string &propertyName)
Remove a node reference property for a specific referenceRole.
NodeReferencesType NodeReferences
virtual char * GetSingletonTag()
void SetNodeReferenceProperty(const std::string &referenceRole, const std::string &propertyName, const std::string &value)
Set the node reference property for a specific referenceRole.
@ ContentModifiedObserveDisabled
Do not observe content modified events (default)
@ ContentModifiedObserveUndefined
Observe content modified events if it is enabled in the node reference role.
@ ContentModifiedObserveEnabled
Observe content modified events.
virtual vtkMRMLNode * CreateNodeInstance()=0
Create instance of the default node. Like New only virtual.
int GetNumberOfNodeReferenceProperties(const std::string &referenceRole)
Get the number of node reference properties for a specific referenceRole.
void GetNodeReferences(const char *referenceRole, std::vector< vtkMRMLNode * > &nodes)
Return a list of the referenced nodes.
@ HierarchyModifiedEvent
@ ReferenceModifiedEvent
@ ReferencedNodeModifiedEvent
@ ReferenceRemovedEvent
virtual const char * GetNodeTagName()=0
std::map< std::string, std::string > NodeReferenceMRMLAttributeNames
void RemoveNodeReferenceIDs(const char *referenceRole)
Remove all node IDs and associated nodes for a specific referenceRole.
void RemoveInvalidReferences(const std::set< std::string > &validNodeIDs)
bool HasNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Return true if referencedNodeID is in the node ID list for a specific referenceRole.
virtual const char * GetTypeDisplayName()
virtual void ReadXMLAttributes(const char **atts)
void GetUpdatedReferencedNodeEventList(int &oldReferencedNodeUseCount, int &newReferencedNodeUseCount, vtkIntArray *oldConsolidatedEventList, vtkIntArray *newConsolidatedEventList, vtkMRMLNode *oldReferencedNode, vtkMRMLNode *newReferencedNode, vtkMRMLNodeReference *referenceToIgnore, vtkIntArray *newEvents, bool newObserveContentModifiedEvents)
virtual void OnNodeAddedToScene()
virtual bool HasCopyContent() const
Returns true if the class supports deep and shallow copying node content.
virtual void SetSceneReferences()
Update the references of the node to the scene.
const char * GetNodeReferenceID(const char *referenceRole)
Utility function that returns the first node id for a specific referenceRole.
virtual void OnNodeReferenceAdded(vtkMRMLNodeReference *reference)
std::map< std::string, NodeReferenceEventList > NodeReferenceEventsType
virtual bool IsReferenceRoleGeneric(const char *refRole)
Return true if the reference role is generic (ends with '/') or false otherwise.
std::string GetNodeReferencePropertyName(const std::string &referenceRole, int propertyIndex)
Get the name of the Nth node reference property for a specific referenceRole.
void SetAttribute(const char *name, const char *value)
Set a name value pair attribute.
const char * GetNthNodeReferenceRole(int n)
void RemoveAttribute(const char *name)
Remove attribute with the specified name.
std::string NodeReferencePropertyDecodeString(const std::string &inString)
Decode a node reference property string.
virtual void CopyContent(vtkMRMLNode *node, bool deepCopy=true)
Copy node contents from another node of the same type. Does not copy node ID, Scene,...
const char * URLEncodeString(const char *inString)
Encode a URL string.
const char * GetNthNodeReferenceID(const char *referenceRole, int n)
Return the string of the Nth node ID for a specific reference role.
virtual int EndModify(int previousDisableModifiedEventState)
End modifying the node.
void CopyWithScene(vtkMRMLNode *node)
Copy everything (including Scene and ID) from another node of the same type.
void GetNodeReferenceIDs(const char *referenceRole, std::vector< const char * > &referencedNodeIDs)
Return a list of the referenced node IDs.
void PrintSelf(ostream &os, vtkIndent indent) override
int GetNumberOfNodeReferences(const char *referenceRole)
Return the number of node IDs for a specific reference role (and nodes as they always have the same s...
char * Description
vtkMRMLNode * SetAndObserveNthNodeReferenceID(const char *referenceRole, int n, const char *referencedNodeID, vtkIntArray *events=nullptr, ContentModifiedObserveType observeContentModifiedEvents=ContentModifiedObserveUndefined)
Set and observe the Nth node ID for a specific reference role.
const ReferencePropertiesType * GetNodeReferenceProperties(const char *referenceRole)
virtual vtkMRMLScene * GetScene()
Get the scene this node has been added to.
const char * URLDecodeString(const char *inString)
Decode a URL string.
vtkMRMLNode * SetNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Set a reference to a node with specified nodeID from this node for a specific referenceRole.
vtkObserverManager * MRMLObserverManager
virtual void SetSingletonTag(const char *)
Tag that make this node a singleton in the scene.
virtual void WriteXML(ostream &of, int indent)
void SetSingletonOff()
vtkCallbackCommand * MRMLCallbackCommand
Holders for MRML callbacks.
int GetNumberOfNthNodeReferenceProperties(const std::string &referenceRole, int n)
vtkWeakPointer< vtkMRMLScene > Scene
bool IsSingleton()
vtkMRMLNode * SetAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=nullptr, ContentModifiedObserveType observeContentModifiedEvents=ContentModifiedObserveUndefined)
Set and observe a reference node from this node for a specific referenceRole.
std::vector< std::string > GetAttributeNames()
Get all attribute names.
const ReferencePropertiesType * GetNthNodeReferenceProperties(const char *referenceRole, int n)
virtual void UpdateReferenceID(const char *oldID, const char *newID)
Update the stored reference to another node in the scene.
void SetDisableModifiedEvent(int onOff)
const char * GetAttribute(const char *name)
Get value of a name value pair attribute.
virtual const char * GetReferenceRoleFromMRMLAttributeName(const char *attName)
Return the reference role (if found) associated with the attribute name found in a MRML scene file....
void Modified() override
Customized version of Modified() allowing to compress vtkCommand::ModifiedEvent.
void AddNodeReferenceRole(const char *referenceRole, const char *mrmlAttributeName=nullptr, vtkIntArray *events=nullptr, bool observeContentModifiedEvents=false)
Add a referenceRole.
friend class vtkMRMLScene
std::string GetNthNodeReferencePropertyName(const std::string &referenceRole, int referenceIndex, int propertyIndex)
void SetNthNodeReferenceProperty(const std::string &referenceRole, int n, const std::string &propertyName, const std::string &value)
int GetCustomModifiedEventPending(int eventId)
virtual void ProcessChildNode(vtkMRMLNode *)
Set dependencies between this node and a child node when parsing XML file.
int InMRMLCallbackFlag
Flag to avoid event loops.
std::vector< std::string > GetNthNodeReferencePropertyNames(const std::string &referenceRole, int n)
void RemoveNthNodeReferenceProperty(const std::string &referenceRole, int n, const std::string &propertyName)
void operator=(const vtkMRMLNode &)
void ClearNthNodeReferenceProperties(const std::string &referenceRole, int n)
void SetInMRMLCallbackFlag(int flag)
virtual void InvokeCustomModifiedEvent(int eventId, void *callData=nullptr)
This method allows the node to compress events.
std::vector< std::string > GetNodeReferencePropertyNames(const std::string &referenceRole)
Get the names of all node reference properties for a specific referenceRole.
std::map< std::string, std::string > AttributesType
virtual void Copy(vtkMRMLNode *node)
Copy node contents from another node of the same type. Does not copy node ID and Scene....
std::string GetNodeReferenceProperty(const std::string &referenceRole, const std::string &propertyName)
Get the node reference property for a specific referenceRole.
std::string XMLAttributeDecodeString(const std::string &inString)
Decode an XML attribute string.
vtkMRMLNode * GetNthNodeReference(const char *referenceRole, int n)
Get referenced MRML node for a specific referenceRole.
vtkMRMLNode * SetNthNodeReferenceID(const char *referenceRole, int n, const char *referencedNodeID)
Set a N-th reference from this node with specified referencedNodeID for a specific referenceRole.
void SetSingletonOn()
virtual void UpdateScene(vtkMRMLScene *)
~vtkMRMLNode() override
critical to have a virtual destructor!
vtkMRMLNode(const vtkMRMLNode &)
virtual void ProcessMRMLEvents(vtkObject *caller, unsigned long event, void *callData)
Propagate events generated in mrml.
static void MRMLCallback(vtkObject *caller, unsigned long eid, void *clientData, void *callData)
A set of MRML Nodes that supports serialization and undo/redo.
Manages adding and deleting of observers with events.
vtkSmartPointer< vtkIntArray > StaticEvents
ContentModifiedObserveType ObserveContentModifiedEvents