15#ifndef __vtkMRMLNode_h
16#define __vtkMRMLNode_h
21#include "vtkIdTypeArray.h"
22#include "vtkIntArray.h"
29#include <vtkSmartPointer.h>
30#include <vtkWeakPointer.h>
31class vtkCallbackCommand;
34#include <vtkLoggingMacros.h>
45#ifndef vtkSetMRMLObjectMacro
46#define vtkSetMRMLObjectMacro(node,value) {this->MRMLObserverManager->SetObject ( vtkObjectPointer( &(node)), (value) );};
50#ifndef vtkSetAndObserveMRMLObjectMacro
51#define vtkSetAndObserveMRMLObjectMacro(node,value) {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value) );};
54#ifndef vtkSetAndObserveMRMLObjectMacroNoWarning
55#define vtkSetAndObserveMRMLObjectMacroNoWarning(node,value) {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value), 0.0, false );};
58#ifndef vtkSetAndObserveMRMLObjectEventsMacro
59#define vtkSetAndObserveMRMLObjectEventsMacro(node,value,events) {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events));};
62#ifndef vtkSetAndObserveMRMLObjectEventsMacroNoWarning
63#define vtkSetAndObserveMRMLObjectEventsMacroNoWarning(node,value,events) {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events), nullptr , false );};
66#ifndef vtkObserveMRMLObjectMacro
67#define vtkObserveMRMLObjectMacro(node) {this->MRMLObserverManager->ObserveObject ( (node) );};
70#ifndef vtkObserveMRMLObjectEventsMacro
71#define vtkObserveMRMLObjectEventsMacro(node, events) {this->MRMLObserverManager->AddObjectEvents ( (node), (events) );};
74#ifndef vtkUnObserveMRMLObjectMacro
75#define vtkUnObserveMRMLObjectMacro(node) {this->MRMLObserverManager->RemoveObjectEvents ( (node) );};
78#ifndef vtkSetReferenceStringBodyMacro
79#define vtkSetReferenceStringBodyMacro(name) \
80 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \
81 if ( this->name == nullptr && _arg == nullptr) { return;} \
82 if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \
83 std::string oldValue; \
84 if (this->name) { oldValue = this->name; delete [] this->name; } \
87 size_t n = strlen(_arg) + 1; \
88 char *cp1 = new char[n]; \
89 const char *cp2 = (_arg); \
91 do { *cp1++ = *cp2++; } while ( --n ); \
95 this->name = nullptr; \
98 if (this->Scene && this->name) \
100 if (oldValue.size() > 0) \
102 this->Scene->RemoveReferencedNodeID(oldValue.c_str(), this); \
104 this->Scene->AddReferencedNodeID(this->name, this); \
108#ifndef vtkSetReferenceStringMacro
109#define vtkSetReferenceStringMacro(name) \
110virtual void Set##name (const char* _arg) \
112 vtkSetReferenceStringBodyMacro(name)\
116#ifndef vtkCxxSetReferenceStringMacro
117#define vtkCxxSetReferenceStringMacro(class,name) \
118void class::Set##name (const char* _arg) \
120 vtkSetReferenceStringBodyMacro(name); \
124#ifndef vtkMRMLNodeNewMacro
125#define vtkMRMLNodeNewMacro(newClass) \
126 vtkStandardNewMacro(newClass); \
127 vtkMRMLNode* newClass::CreateNodeInstance() \
129 return newClass::New(); \
141#ifndef vtkMRMLCopyContentMacro
142#define vtkMRMLCopyContentMacro(thisClassName) \
143 void CopyContent(vtkMRMLNode* node, bool deepCopy=true) override; \
144 bool HasCopyContent() const override \
146 return strcmp(#thisClassName, this->GetClassNameInternal()) == 0; \
154#ifndef vtkMRMLCopyContentDefaultMacro
155#define vtkMRMLCopyContentDefaultMacro(thisClassName) \
156 bool HasCopyContent() const override \
158 return strcmp(#thisClassName, this->GetClassNameInternal()) == 0; \
182 ContentModifiedObserveUndefined = -1,
183 ContentModifiedObserveDisabled = 0,
184 ContentModifiedObserveEnabled = 1
217 this->UpdateNodeReferences();
224 this->UpdateNodeReferences();
309 int disabledModify = this->GetDisableModifiedEvent();
310 this->DisableModifiedEventOn();
311 return disabledModify;
321 virtual int EndModify(
int previousDisableModifiedEventState)
323 this->SetDisableModifiedEvent(previousDisableModifiedEventState);
324 if (!previousDisableModifiedEventState)
326 return this->InvokePendingModifiedEvent();
328 return this->ModifiedEventPending;
342 return this->GetNodeTagName();
373 vtkGetMacro(HideFromEditors,
int);
374 vtkSetMacro(HideFromEditors,
int);
375 vtkBooleanMacro(HideFromEditors,
int);
378 vtkGetMacro(Selectable,
int);
379 vtkSetMacro(Selectable,
int);
380 vtkBooleanMacro(Selectable,
int);
391 vtkGetMacro(UndoEnabled,
bool);
392 vtkSetMacro(UndoEnabled,
bool);
393 vtkBooleanMacro(UndoEnabled,
bool);
402 vtkGetMacro(InMRMLCallbackFlag,
int);
404 this->InMRMLCallbackFlag = flag;
408 vtkSetStringMacro(Description);
409 vtkGetStringMacro(Description);
412 vtkSetStringMacro(Name);
413 vtkGetStringMacro(Name);
417 vtkGetStringMacro(ID);
445 vtkSetStringMacro(SingletonTag);
446 vtkGetStringMacro(SingletonTag);
449 this->SetSingletonTag(
"Singleton");
453 this->SetSingletonTag(
nullptr);
457 return (this->GetSingletonTag() !=
nullptr);
461 vtkGetMacro(SaveWithScene,
int);
462 vtkSetMacro(SaveWithScene,
int);
463 vtkBooleanMacro(SaveWithScene,
int);
466 vtkGetMacro(AddToScene,
int);
467 vtkSetMacro(AddToScene,
int);
468 vtkBooleanMacro(AddToScene,
int);
472 vtkGetMacro(DisableModifiedEvent,
int);
475 this->DisableModifiedEvent = onOff;
479 this->SetDisableModifiedEvent(1);
483 this->SetDisableModifiedEvent(0);
491 vtkGetMacro(ModifiedEventPending,
int);
500 std::map< int, int >::iterator it = this->CustomModifiedEventPending.find(eventId);
501 if (it == this->CustomModifiedEventPending.end())
526 if (!this->GetDisableModifiedEvent())
528 Superclass::Modified();
532 ++this->ModifiedEventPending;
545 int oldModifiedEventPending = 0;
547 if ( this->ModifiedEventPending )
549 oldModifiedEventPending += this->ModifiedEventPending;
550 this->ModifiedEventPending = 0;
551 Superclass::Modified();
554 if (!this->CustomModifiedEventPending.empty())
559 std::vector<int> customEventsToInvoke;
560 for (std::map< int, int >::iterator it=this->CustomModifiedEventPending.begin(); it!=this->CustomModifiedEventPending.end(); ++it)
562 oldModifiedEventPending += it->second;
563 customEventsToInvoke.push_back(it->first);
565 this->CustomModifiedEventPending.clear();
566 for (std::vector<int>::iterator it=customEventsToInvoke.begin(); it!=customEventsToInvoke.end(); ++it)
568 this->InvokeEvent(*it);
571 return oldModifiedEventPending;
588 if (!this->GetDisableModifiedEvent())
591 this->InvokeEvent(eventId, callData);
597 ++this->CustomModifiedEventPending[eventId];
624 vtkGetObjectMacro(ContentModifiedEvents, vtkIntArray);
657 vtkGetMacro(Selected,
int);
658 vtkSetMacro(Selected,
int);
659 vtkBooleanMacro(Selected,
int);
682 vtkIntArray *events=
nullptr,
bool observeContentModifiedEvents=
false);
805 std::vector<const char*> &referencedNodeIDs);
823 HierarchyModifiedEvent = 16000,
824 IDChangedEvent = 16001,
828 ReferencedNodeModifiedEvent
908 void PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent))
override {};
911 vtkSetStringMacro(ReferenceRole);
912 vtkGetStringMacro(ReferenceRole);
914 vtkSetStringMacro(ReferencedNodeID);
915 vtkGetStringMacro(ReferencedNodeID);
936 bool SetProperty(
const std::string& key,
const std::string& value);
987 unsigned long eid,
void *clientData,
void *callData );
991 vtkSetStringMacro( TempURLString );
992 vtkGetStringMacro( TempURLString );
1037 vtkIntArray *newEvents,
bool newObserveContentModifiedEvents,
vtkMRMLNodeReference* referenceToIgnore);
1045 vtkIntArray* oldConsolidatedEventList, vtkIntArray* newConsolidatedEventList,
1047 vtkMRMLNodeReference* referenceToIgnore, vtkIntArray* newEvents,
bool newObserveContentModifiedEvents);
1087 char *Name{
nullptr};
1088 char *Description{
nullptr};
1089 int HideFromEditors{0};
1093 bool UndoEnabled{
false};
1095 int SaveWithScene{
true};
1099 int InMRMLCallbackFlag{0};
1133 void SetID(
const char* newID);
1136 char *TempURLString{
nullptr};
1138 char *SingletonTag{
nullptr};
1140 int DisableModifiedEvent{0};
1141 int ModifiedEventPending{0};
1142 std::map<int, int> CustomModifiedEventPending;
1163 this->WasModifying = this->Node->StartModify();
1170 this->Node->EndModify(this->WasModifying);
Safe replacement of MRML node start/end modify.
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 &)
vtkWeakPointer< vtkMRMLNode > ReferencingNode
Points to this MRML node (that added the reference)
void SetProperties(const ReferencePropertiesType &properties)
~vtkMRMLNodeReference() override
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)
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)
AttributesType Attributes
void RemoveNodeReferenceProperty(const std::string &referenceRole, const std::string &propertyName)
Remove a node reference property for a specific referenceRole.
NodeReferencesType NodeReferences
void SetNodeReferenceProperty(const std::string &referenceRole, const std::string &propertyName, const std::string &value)
Set the node reference property for a specific referenceRole.
ContentModifiedObserveType
@ ContentModifiedObserveUndefined
Observe content modified events if it is enabled in the node reference role.
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.
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...
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 WriteXML(ostream &of, int indent)
vtkCallbackCommand * MRMLCallbackCommand
Holders for MRML callbacks.
int GetNumberOfNthNodeReferenceProperties(const std::string &referenceRole, int n)
vtkWeakPointer< vtkMRMLScene > Scene
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.
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.
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.
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