Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
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#include "vtkMRMLI18N.h"
24
25class vtkMRMLScene;
26class vtkStringArray;
27
28// VTK includes
29#include <vtkObject.h>
30#include <vtkSmartPointer.h>
31#include <vtkWeakPointer.h>
32class vtkCallbackCommand;
33
34// Slicer VTK add-on includes
35#include <vtkLoggingMacros.h>
36
37// Helper macros for simplifying reading, writing, copying, and printing node properties.
39
40// STD includes
41#include <map>
42#include <set>
43#include <string>
44#include <vector>
45
46#ifndef vtkSetMRMLObjectMacro
47# define vtkSetMRMLObjectMacro(node, value) \
48 { \
49 this->MRMLObserverManager->SetObject(vtkObjectPointer(&(node)), (value)); \
50 };
51#endif
52
54#ifndef vtkSetAndObserveMRMLObjectMacro
55# define vtkSetAndObserveMRMLObjectMacro(node, value) \
56 { \
57 this->MRMLObserverManager->SetAndObserveObject(vtkObjectPointer(&(node)), (value)); \
58 };
59#endif
60
61#ifndef vtkSetAndObserveMRMLObjectMacroNoWarning
62# define vtkSetAndObserveMRMLObjectMacroNoWarning(node, value) \
63 { \
64 this->MRMLObserverManager->SetAndObserveObject(vtkObjectPointer(&(node)), (value), 0.0, false /* no warning */); \
65 };
66#endif
67
68#ifndef vtkSetAndObserveMRMLObjectEventsMacro
69# define vtkSetAndObserveMRMLObjectEventsMacro(node, value, events) \
70 { \
71 this->MRMLObserverManager->SetAndObserveObjectEvents(vtkObjectPointer(&(node)), (value), (events)); \
72 };
73#endif
74
75#ifndef vtkSetAndObserveMRMLObjectEventsMacroNoWarning
76# define vtkSetAndObserveMRMLObjectEventsMacroNoWarning(node, value, events) \
77 { \
78 this->MRMLObserverManager->SetAndObserveObjectEvents(vtkObjectPointer(&(node)), (value), (events), nullptr /* priorities */, false /* no warning */); \
79 };
80#endif
81
82#ifndef vtkObserveMRMLObjectMacro
83# define vtkObserveMRMLObjectMacro(node) \
84 { \
85 this->MRMLObserverManager->ObserveObject((node)); \
86 };
87#endif
88
89#ifndef vtkObserveMRMLObjectEventMacro
90# define vtkObserveMRMLObjectEventMacro(node, event) \
91 { \
92 this->MRMLObserverManager->AddObjectEvent((node), (event)); \
93 };
94#endif
95
96#ifndef vtkObserveMRMLObjectEventMacroNoWarning
97# define vtkObserveMRMLObjectEventMacroNoWarning(node, event) \
98 { \
99 this->MRMLObserverManager->AddObjectEvent((node), (event), 0.0, false); \
100 };
101#endif
102
103#ifndef vtkObserveMRMLObjectEventsMacro
104# define vtkObserveMRMLObjectEventsMacro(node, events) \
105 { \
106 this->MRMLObserverManager->AddObjectEvents((node), (events)); \
107 };
108#endif
109
110#ifndef vtkUnObserveMRMLObjectMacro
111# define vtkUnObserveMRMLObjectMacro(node) \
112 { \
113 this->MRMLObserverManager->RemoveObjectEvents((node)); \
114 };
115#endif
116
117#ifndef vtkSetReferenceStringBodyMacro
118# define vtkSetReferenceStringBodyMacro(name) \
119 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg ? _arg : "(null)")); \
120 if (this->name == nullptr && _arg == nullptr) \
121 { \
122 return; \
123 } \
124 if (this->name && _arg && (!strcmp(this->name, _arg))) \
125 { \
126 return; \
127 } \
128 std::string oldValue; \
129 if (this->name) \
130 { \
131 oldValue = this->name; \
132 delete[] this->name; \
133 } \
134 if (_arg) \
135 { \
136 size_t n = strlen(_arg) + 1; \
137 char* cp1 = new char[n]; \
138 const char* cp2 = (_arg); \
139 this->name = cp1; \
140 do \
141 { \
142 *cp1++ = *cp2++; \
143 } while (--n); \
144 } \
145 else \
146 { \
147 this->name = nullptr; \
148 } \
149 this->Modified(); \
150 if (this->Scene && this->name) \
151 { \
152 if (oldValue.size() > 0) \
153 { \
154 this->Scene->RemoveReferencedNodeID(oldValue.c_str(), this); \
155 } \
156 this->Scene->AddReferencedNodeID(this->name, this); \
157 }
158#endif
159
160#ifndef vtkSetReferenceStringMacro
161# define vtkSetReferenceStringMacro(name) \
162 virtual void Set##name(const char* _arg) \
163 { \
164 vtkSetReferenceStringBodyMacro(name) \
165 }
166#endif
167
168#ifndef vtkCxxSetReferenceStringMacro
169# define vtkCxxSetReferenceStringMacro(class, name) \
170 void class ::Set##name(const char* _arg) \
171 { \
172 vtkSetReferenceStringBodyMacro(name); \
173 }
174#endif
175
176#ifndef vtkMRMLNodeNewMacro
177# define vtkMRMLNodeNewMacro(newClass) \
178 vtkStandardNewMacro(newClass); \
179 vtkMRMLNode* newClass::CreateNodeInstance() \
180 { \
181 return newClass::New(); \
182 }
183#endif
184
185// Use this macro to declare that this node supports
186// CopyContent.It also declares CopyContent and
187// HasCopyContent methods.
188//
189// The use of HasCopyContent() may be needed to determine if
190// a specific node class has implemented CopyContent (if only
191// a parent class implemented it that may not be enough).
192//
193#ifndef vtkMRMLCopyContentMacro
194# define vtkMRMLCopyContentMacro(thisClassName) \
195 void CopyContent(vtkMRMLNode* node, bool deepCopy = true) override; \
196 bool HasCopyContent() const override \
197 { \
198 return strcmp(#thisClassName, this->GetClassNameInternal()) == 0; \
199 }
200#endif
201
202// Use this macro to declare that this node supports
203// CopyContent by only declaring HasCopyContent without
204// implementing CopyContent method
205// (this is the case when parent classes copy all content).
206#ifndef vtkMRMLCopyContentDefaultMacro
207# define vtkMRMLCopyContentDefaultMacro(thisClassName) \
208 bool HasCopyContent() const override \
209 { \
210 return strcmp(#thisClassName, this->GetClassNameInternal()) == 0; \
211 }
212#endif
213
214// This can be used for writing code that is backward-compatible with older Slicer versions
215// where GetDefaultNodeNamePrefix() returned const char* (instead of std::string).
216#define DEFAULT_NODE_NAME_PREFIX_IS_STD_STRING 1
217
223class VTK_MRML_EXPORT vtkMRMLNode : public vtkObject
224{
227 friend class vtkMRMLScene;
229
230public:
231 vtkTypeMacro(vtkMRMLNode, vtkObject);
232 void PrintSelf(ostream& os, vtkIndent indent) override;
233
242
247
249 virtual bool HasCopyContent() const;
250
256 virtual void ReadXMLAttributes(const char** atts);
257
262 virtual void UpdateReferences();
263
266 virtual void ProcessChildNode(vtkMRMLNode*) {};
267
271 virtual void UpdateScene(vtkMRMLScene*) { this->UpdateNodeReferences(); };
272
275 virtual void OnNodeAddedToScene() { this->UpdateNodeReferences(); };
276
283 virtual void WriteXML(ostream& of, int indent);
284
286 virtual void WriteNodeBodyXML(ostream& of, int indent);
287
294 virtual void Copy(vtkMRMLNode* node);
295
305 virtual void CopyContent(vtkMRMLNode* node, bool deepCopy = true);
306
311 virtual void CopyReferences(vtkMRMLNode* node);
312
328
349 virtual void Reset(vtkMRMLNode* defaultNode);
350
357 virtual int StartModify()
358 {
359 int disabledModify = this->GetDisableModifiedEvent();
361 return disabledModify;
362 };
363
371 virtual int EndModify(int previousDisableModifiedEventState)
372 {
373 this->SetDisableModifiedEvent(previousDisableModifiedEventState);
374 if (!previousDisableModifiedEventState)
375 {
376 return this->InvokePendingModifiedEvent();
377 }
378 return this->ModifiedEventPending;
379 };
380
384 virtual const char* GetNodeTagName() = 0;
385
389 virtual std::string GetTypeDisplayName();
390
396 virtual void SetTypeDisplayName(const std::string& name);
397
401 virtual std::string GetDefaultNodeNamePrefix();
402
408 virtual void SetDefaultNodeNamePrefix(const std::string& prefix);
409
421 void SetAttribute(const char* name, const char* value);
422
424 void RemoveAttribute(const char* name);
425
429 const char* GetAttribute(const char* name);
430
432 std::vector<std::string> GetAttributeNames();
433
435 void GetAttributeNames(vtkStringArray* attributeNames);
436
438 vtkGetMacro(HideFromEditors, int);
439 vtkSetMacro(HideFromEditors, int);
440 vtkBooleanMacro(HideFromEditors, int);
441
443 vtkGetMacro(Selectable, int);
444 vtkSetMacro(Selectable, int);
445 vtkBooleanMacro(Selectable, int);
446
456 vtkGetMacro(UndoEnabled, bool);
457 vtkSetMacro(UndoEnabled, bool);
458 vtkBooleanMacro(UndoEnabled, bool);
459
461 virtual void ProcessMRMLEvents(vtkObject* caller, unsigned long event, void* callData);
462
467 vtkGetMacro(InMRMLCallbackFlag, int);
468 void SetInMRMLCallbackFlag(int flag) { this->InMRMLCallbackFlag = flag; }
469
471 vtkSetStringMacro(Description);
472 vtkGetStringMacro(Description);
473
475 vtkSetStringMacro(Name);
476 vtkGetStringMacro(Name);
477
479 // vtkSetStringMacro(ID);
480 vtkGetStringMacro(ID);
481
508 vtkSetStringMacro(SingletonTag);
509 vtkGetStringMacro(SingletonTag);
510 void SetSingletonOn() { this->SetSingletonTag("Singleton"); }
511 void SetSingletonOff() { this->SetSingletonTag(nullptr); }
512 bool IsSingleton() { return (this->GetSingletonTag() != nullptr); }
513
515 vtkGetMacro(SaveWithScene, int);
516 vtkSetMacro(SaveWithScene, int);
517 vtkBooleanMacro(SaveWithScene, int);
518
520 vtkGetMacro(AddToScene, int);
521 vtkSetMacro(AddToScene, int);
522 vtkBooleanMacro(AddToScene, int);
523 void SetAddToSceneNoModify(int value);
524
526 vtkGetMacro(DisableModifiedEvent, int);
527 void SetDisableModifiedEvent(int onOff) { this->DisableModifiedEvent = onOff; }
530
536 vtkGetMacro(ModifiedEventPending, int);
537
544 {
545 std::map<int, int>::iterator it = this->CustomModifiedEventPending.find(eventId);
546 if (it == this->CustomModifiedEventPending.end())
547 {
548 return 0;
549 }
550 else
551 {
552 return it->second;
553 }
554 }
555
569 void Modified() override
570 {
571 if (!this->GetDisableModifiedEvent())
572 {
573 Superclass::Modified();
574 }
575 else
576 {
577 ++this->ModifiedEventPending;
578 }
579 }
580
589 {
590 int oldModifiedEventPending = 0;
591 // Invoke pending standard Modified event
592 if (this->ModifiedEventPending)
593 {
594 oldModifiedEventPending += this->ModifiedEventPending;
595 this->ModifiedEventPending = 0;
596 Superclass::Modified();
597 }
598 // Invoke pending custom modified events
599 if (!this->CustomModifiedEventPending.empty())
600 {
601 // Need to make a copy of the event IDs stored in this->CustomModifiedEventPending,
602 // because event invocation may add more events to this->CustomModifiedEventPending,
603 // which would then make the iterator invalid.
604 std::vector<int> customEventsToInvoke;
605 for (std::map<int, int>::iterator it = this->CustomModifiedEventPending.begin(); it != this->CustomModifiedEventPending.end(); ++it)
606 {
607 oldModifiedEventPending += it->second;
608 customEventsToInvoke.push_back(it->first);
609 }
610 this->CustomModifiedEventPending.clear();
611 for (std::vector<int>::iterator it = customEventsToInvoke.begin(); it != customEventsToInvoke.end(); ++it)
612 {
613 this->InvokeEvent(*it);
614 }
615 }
616 return oldModifiedEventPending;
617 }
618
631 virtual void InvokeCustomModifiedEvent(int eventId, void* callData = nullptr)
632 {
633 if (!this->GetDisableModifiedEvent())
634 {
635 // DisableModify is inactive, we immediately invoke the event
636 this->InvokeEvent(eventId, callData);
637 }
638 else
639 {
640 // just remember the custom modified event and invoke it once,
641 // when DisableModify is deactivated
642 ++this->CustomModifiedEventPending[eventId];
643 }
644 }
645
648
654 virtual void SetScene(vtkMRMLScene* scene);
655
660 virtual void SetSceneReferences();
661
663 virtual void UpdateReferenceID(const char* oldID, const char* newID);
664
669 vtkGetObjectMacro(ContentModifiedEvents, vtkIntArray);
670
677 const char* URLEncodeString(const char* inString);
678
685 const char* URLDecodeString(const char* inString);
686
690 std::string XMLAttributeEncodeString(const std::string& inString);
691
699 std::string XMLAttributeDecodeString(const std::string& inString);
700
702 vtkGetMacro(Selected, int);
703 vtkSetMacro(Selected, int);
704 vtkBooleanMacro(Selected, int);
705
726 void AddNodeReferenceRole(const char* referenceRole, const char* mrmlAttributeName = nullptr, vtkIntArray* events = nullptr, bool observeContentModifiedEvents = false);
727
729 vtkMRMLNode* SetNodeReferenceID(const char* referenceRole, const char* referencedNodeID);
730
732 vtkMRMLNode* AddNodeReferenceID(const char* referenceRole, const char* referencedNodeID);
733
736 vtkMRMLNode* SetNthNodeReferenceID(const char* referenceRole, int n, const char* referencedNodeID);
737
747 vtkMRMLNode* SetAndObserveNodeReferenceID(const char* referenceRole,
748 const char* referencedNodeID,
749 vtkIntArray* events = nullptr,
750 ContentModifiedObserveType observeContentModifiedEvents = ContentModifiedObserveUndefined);
751
761 vtkMRMLNode* AddAndObserveNodeReferenceID(const char* referenceRole,
762 const char* referencedNodeID,
763 vtkIntArray* events = nullptr,
764 ContentModifiedObserveType observeContentModifiedEvents = ContentModifiedObserveUndefined);
765
788 int n,
789 const char* referencedNodeID,
790 vtkIntArray* events = nullptr,
791 ContentModifiedObserveType observeContentModifiedEvents = ContentModifiedObserveUndefined);
792
794 void RemoveNthNodeReferenceID(const char* referenceRole, int n);
795
799 void RemoveNodeReferenceIDs(const char* referenceRole);
800
805 bool HasNodeReferenceID(const char* referenceRole, const char* referencedNodeID);
806
809 int GetNumberOfNodeReferences(const char* referenceRole);
810
817 const char* GetNthNodeReferenceID(const char* referenceRole, int n);
818
823 const char* GetNodeReferenceID(const char* referenceRole);
824
835 vtkMRMLNode* GetNthNodeReference(const char* referenceRole, int n);
836
839 vtkMRMLNode* GetNodeReference(const char* referenceRole);
840
848 void GetNodeReferences(const char* referenceRole, std::vector<vtkMRMLNode*>& nodes);
849
855 void GetNodeReferenceIDs(const char* referenceRole, std::vector<const char*>& referencedNodeIDs);
856
859 void GetNodeReferenceRoles(std::vector<std::string>& roles);
860
864
867 const char* GetNthNodeReferenceRole(int n);
868
871 enum
872 {
879 };
880
882
896 typedef std::map<std::string, std::string> ReferencePropertiesType;
897 const ReferencePropertiesType* GetNthNodeReferenceProperties(const char* referenceRole, int n);
898 const ReferencePropertiesType* GetNodeReferenceProperties(const char* referenceRole);
900
902
904 void SetNodeReferenceProperty(const std::string& referenceRole, const std::string& propertyName, const std::string& value);
905 void SetNthNodeReferenceProperty(const std::string& referenceRole, int n, const std::string& propertyName, const std::string& value);
907
909
911 std::string GetNodeReferenceProperty(const std::string& referenceRole, const std::string& propertyName);
912 std::string GetNthNodeReferenceProperty(const std::string& referenceRole, int n, const std::string& propertyName);
914
916
918 void RemoveNodeReferenceProperty(const std::string& referenceRole, const std::string& propertyName);
919 void RemoveNthNodeReferenceProperty(const std::string& referenceRole, int n, const std::string& propertyName);
921
923
925 int GetNumberOfNodeReferenceProperties(const std::string& referenceRole);
926 int GetNumberOfNthNodeReferenceProperties(const std::string& referenceRole, int n);
928
930
932 std::string GetNodeReferencePropertyName(const std::string& referenceRole, int propertyIndex);
933 std::string GetNthNodeReferencePropertyName(const std::string& referenceRole, int referenceIndex, int propertyIndex);
935
937
939 std::vector<std::string> GetNodeReferencePropertyNames(const std::string& referenceRole);
940 std::vector<std::string> GetNthNodeReferencePropertyNames(const std::string& referenceRole, int n);
942
944
946 void ClearNodeReferenceProperties(const std::string& referenceRole);
947 void ClearNthNodeReferenceProperties(const std::string& referenceRole, int n);
949
950protected:
952 class VTK_MRML_EXPORT vtkMRMLNodeReference : public vtkObject
953 {
954 public:
955 vtkTypeMacro(vtkMRMLNodeReference, vtkObject);
957 void PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) override {};
958
959 public:
960 vtkSetStringMacro(ReferenceRole);
961 vtkGetStringMacro(ReferenceRole);
962
963 vtkSetStringMacro(ReferencedNodeID);
964 vtkGetStringMacro(ReferencedNodeID);
965
971 void SetStaticEvents(vtkIntArray* events);
972 vtkIntArray* GetStaticEvents() const;
973
977
980
983
985 bool SetProperty(const std::string& key, const std::string& value);
986
988 std::string GetProperty(const std::string& key) const;
989
991 bool RemoveProperty(const std::string& key);
992
995
996 const ReferencePropertiesType* GetProperties() const { return &this->Properties; }
997 void SetProperties(const ReferencePropertiesType& properties) { this->Properties = properties; }
998
999 protected:
1002
1005
1008
1010 vtkWeakPointer<vtkMRMLNode> ReferencingNode;
1012 vtkSmartPointer<vtkMRMLNode> ReferencedNode;
1013
1018 vtkSmartPointer<vtkIntArray> StaticEvents;
1023
1025 };
1026
1029 ~vtkMRMLNode() override;
1032
1035 static void MRMLCallback(vtkObject* caller, unsigned long eid, void* clientData, void* callData);
1036
1039 vtkSetStringMacro(TempURLString);
1040 vtkGetStringMacro(TempURLString);
1041
1049 virtual const char* GetReferenceRoleFromMRMLAttributeName(const char* attName);
1050
1058 virtual const char* GetMRMLAttributeNameFromReferenceRole(const char* refRole);
1059
1063 virtual bool IsReferenceRoleGeneric(const char* refRole);
1064
1068 virtual void UpdateNodeReferences(const char* referenceRole = nullptr);
1069
1073 void RemoveInvalidReferences(const std::set<std::string>& validNodeIDs);
1074
1079 virtual void UpdateNthNodeReference(const char* referenceRole, int n);
1080
1085 vtkMRMLNode* newReferencedNode,
1086 vtkIntArray* newEvents,
1087 bool newObserveContentModifiedEvents,
1088 vtkMRMLNodeReference* referenceToIgnore);
1089
1095 void GetUpdatedReferencedNodeEventList(int& oldReferencedNodeUseCount,
1096 int& newReferencedNodeUseCount,
1097 vtkIntArray* oldConsolidatedEventList,
1098 vtkIntArray* newConsolidatedEventList,
1099 vtkMRMLNode* oldReferencedNode,
1100 vtkMRMLNode* newReferencedNode,
1101 vtkMRMLNodeReference* referenceToIgnore,
1102 vtkIntArray* newEvents,
1103 bool newObserveContentModifiedEvents);
1104
1108
1112 virtual void OnNodeReferenceAdded(vtkMRMLNodeReference* reference) { this->InvokeEvent(vtkMRMLNode::ReferenceAddedEvent, reference); }
1113
1115 virtual void OnNodeReferenceModified(vtkMRMLNodeReference* reference) { this->InvokeEvent(vtkMRMLNode::ReferenceModifiedEvent, reference); }
1116
1118 virtual void OnNodeReferenceRemoved(vtkMRMLNodeReference* reference) { this->InvokeEvent(vtkMRMLNode::ReferenceRemovedEvent, reference); }
1119
1122 void ParseReferencesAttribute(const char* attValue, std::set<std::string>& references);
1123
1125 std::string NodeReferencePropertyEncodeString(const std::string& inString);
1126
1128 std::string NodeReferencePropertyDecodeString(const std::string& inString);
1129
1131 vtkCallbackCommand* MRMLCallbackCommand;
1132
1133 char* ID{ nullptr };
1134 char* Name{ nullptr };
1135 char* Description{ nullptr };
1137 int Selectable{ 1 };
1138 int Selected{ 0 };
1139 int AddToScene{ 1 };
1140 bool UndoEnabled{ false };
1141
1142 std::string TypeDisplayName;
1144
1145 int SaveWithScene{ true };
1146
1150
1151 // We don't increase the reference count of Scene when store its pointer
1152 // therefore we must use a weak pointer to prevent pointer dangling when
1153 // the scene is deleted.
1154 vtkWeakPointer<vtkMRMLScene> Scene;
1155
1156 typedef std::map<std::string, std::string> AttributesType;
1158
1160
1162
1165 typedef std::vector<vtkSmartPointer<vtkMRMLNodeReference>> NodeReferenceListType;
1166 typedef std::map<std::string, NodeReferenceListType> NodeReferencesType;
1168
1169 std::map<std::string, std::string> NodeReferenceMRMLAttributeNames;
1170
1176 typedef std::map<std::string, NodeReferenceEventList> NodeReferenceEventsType;
1177 NodeReferenceEventsType NodeReferenceEvents; // for each role it specifies which referenced node emitted events this node should observe
1178
1179private:
1182 void SetID(const char* newID);
1183
1185 char* TempURLString{ nullptr };
1186
1187 char* SingletonTag{ nullptr };
1188
1189 int DisableModifiedEvent{ 0 };
1190 int ModifiedEventPending{ 0 };
1191 std::map<int, int> CustomModifiedEventPending; // event id, pending value (number of events grouped together)
1192};
1193
1202class VTK_MRML_EXPORT MRMLNodeModifyBlocker
1203{
1204public:
1205 vtkWeakPointer<vtkMRMLNode> Node;
1208 {
1209 this->Node = node;
1210 if (this->Node)
1211 {
1212 this->WasModifying = this->Node->StartModify();
1213 }
1214 };
1216 {
1217 if (this->Node)
1218 {
1219 this->Node->EndModify(this->WasModifying);
1220 }
1221 }
1222};
1223
1224#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()
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.
std::vector< vtkSmartPointer< vtkMRMLNodeReference > > NodeReferenceListType
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)
virtual std::string GetDefaultNodeNamePrefix()
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.
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()
std::map< std::string, NodeReferenceListType > NodeReferencesType
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
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 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)
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.
virtual void SetDefaultNodeNamePrefix(const std::string &prefix)
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.
std::map< std::string, std::string > AttributesType
void GetNodeReferenceIDs(const char *referenceRole, std::vector< const char * > &referencedNodeIDs)
Return a list of the referenced node IDs.
virtual void SetTypeDisplayName(const std::string &name)
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.
std::map< std::string, std::string > NodeReferenceMRMLAttributeNames
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
std::map< std::string, NodeReferenceEventList > NodeReferenceEventsType
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.
virtual std::string GetTypeDisplayName()
int InMRMLCallbackFlag
Flag to avoid event loops.
std::vector< std::string > GetNthNodeReferencePropertyNames(const std::string &referenceRole, int n)
std::string DefaultNodeNamePrefix
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.
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 &)
std::string TypeDisplayName
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