15 #ifndef __vtkMRMLNode_h 16 #define __vtkMRMLNode_h 21 #include "vtkIdTypeArray.h" 22 #include "vtkIntArray.h" 28 #include <vtkObject.h> 29 #include <vtkSmartPointer.h> 30 #include <vtkWeakPointer.h> 31 class 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) \ 110 virtual void Set##name (const char* _arg) \ 112 vtkSetReferenceStringBodyMacro(name)\ 116 #ifndef vtkCxxSetReferenceStringMacro 117 #define vtkCxxSetReferenceStringMacro(class,name) \ 118 void 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; \ 176 void PrintSelf(ostream& os, vtkIndent indent)
override;
224 virtual void WriteXML(ostream& of,
int indent);
302 return disabledModify;
312 virtual int EndModify(
int previousDisableModifiedEventState)
315 if (!previousDisableModifiedEventState)
319 return this->ModifiedEventPending;
379 virtual void ProcessMRMLEvents ( vtkObject *caller,
unsigned long event,
void *callData );
395 vtkSetStringMacro(
Name);
396 vtkGetStringMacro(
Name);
400 vtkGetStringMacro(
ID);
428 vtkSetStringMacro(SingletonTag);
429 vtkGetStringMacro(SingletonTag);
455 vtkGetMacro(DisableModifiedEvent,
int);
458 this->DisableModifiedEvent = onOff;
474 vtkGetMacro(ModifiedEventPending,
int);
497 ++this->ModifiedEventPending;
510 int oldModifiedEventPending = 0;
512 if ( this->ModifiedEventPending )
514 oldModifiedEventPending += this->ModifiedEventPending;
515 this->ModifiedEventPending = 0;
519 if (!this->CustomModifiedEventPending.empty())
524 std::vector<int> customEventsToInvoke;
525 for (std::map< int, int >::iterator it=this->CustomModifiedEventPending.begin(); it!=this->CustomModifiedEventPending.end(); ++it)
527 oldModifiedEventPending += it->second;
528 customEventsToInvoke.push_back(it->first);
530 this->CustomModifiedEventPending.clear();
531 for (std::vector<int>::iterator it=customEventsToInvoke.begin(); it!=customEventsToInvoke.end(); ++it)
533 this->InvokeEvent(*it);
536 return oldModifiedEventPending;
556 this->InvokeEvent(eventId, callData);
562 ++this->CustomModifiedEventPending[eventId];
641 void AddNodeReferenceRole(
const char *referenceRole,
const char *mrmlAttributeName=
nullptr, vtkIntArray *events=
nullptr);
745 std::vector<const char*> &referencedNodeIDs);
780 void PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent))
override {};
783 vtkSetStringMacro(ReferenceRole);
784 vtkGetStringMacro(ReferenceRole);
786 vtkSetStringMacro(ReferencedNodeID);
787 vtkGetStringMacro(ReferencedNodeID);
794 void SetEvents(vtkIntArray* events);
795 vtkIntArray* GetEvents()
const;
834 static void MRMLCallback( vtkObject *caller,
835 unsigned long eid,
void *clientData,
void *callData );
839 vtkSetStringMacro( TempURLString );
840 vtkGetStringMacro( TempURLString );
849 virtual const char* GetReferenceRoleFromMRMLAttributeName(
const char* attName);
858 virtual const char* GetMRMLAttributeNameFromReferenceRole(
const char* refRole);
863 virtual bool IsReferenceRoleGeneric(
const char* refRole);
868 virtual void UpdateNodeReferences(
const char* referenceRole =
nullptr);
874 virtual void UpdateNthNodeReference(
const char* referenceRole,
int n);
887 void GetUpdatedReferencedNodeEventList(
int& oldReferencedNodeUseCount,
int& newReferencedNodeUseCount,
888 vtkIntArray* oldConsolidatedEventList, vtkIntArray* newConsolidatedEventList,
894 virtual void InvalidateNodeReferences();
918 void ParseReferencesAttribute(
const char *attValue, std::set<std::string> &references);
925 char *Description{
nullptr};
926 int HideFromEditors{0};
930 bool UndoEnabled{
false};
932 int SaveWithScene{
true};
936 int InMRMLCallbackFlag{0};
965 void SetID(
const char* newID);
968 char *TempURLString{
nullptr};
970 char *SingletonTag{
nullptr};
972 int DisableModifiedEvent{0};
973 int ModifiedEventPending{0};
974 std::map<int, int> CustomModifiedEventPending;
988 vtkWeakPointer<vtkMRMLNode>
Node;
1002 this->Node->EndModify(this->WasModifying);
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...
const char * GetNthNodeReferenceID(const char *referenceRole, int n)
Return the string of the Nth node ID for a specific reference role.
vtkMRMLNode * GetNodeReference(const char *referenceRole)
const char * GetNodeTagName() override
Get node XML tag name (like Volume, Model)
void DisableModifiedEventOff()
void PrintSelf(ostream &os, vtkIndent indent) override
virtual void CopyContent(vtkMRMLNode *node, bool deepCopy=true)
Copy node contents from another node of the same type. Does not copy node ID, Scene, Name, SingletonTag, HideFromEditors, AddToScene, UndoEnabled, and node references. If deepCopy is set to false then a shallow copy of bulk data (such as image or mesh data) could be made; copying may be faster but the node may share some data with the source node instead of creating an independent copy.
std::vector< vtkSmartPointer< vtkMRMLNodeReference > > NodeReferenceListType
virtual int InvokePendingModifiedEvent()
Invokes any modified events that are pending.
vtkMRMLNode * SetAndObserveNthNodeReferenceID(const char *referenceRole, int n, const char *referencedNodeID, vtkIntArray *events=nullptr)
Set and observe the Nth node ID for a specific reference role.
std::map< std::string, NodeReferenceListType > NodeReferencesType
std::vector< std::string > GetAttributeNames()
Get all attribute names.
vtkWeakPointer< vtkMRMLNode > ReferencingNode
Points to this MRML node (that added the reference)
std::string XMLAttributeDecodeString(const std::string &inString)
Decode an XML attribute string.
virtual vtkMRMLScene * GetScene()
Get the scene this node has been added to.
virtual void Reset(vtkMRMLNode *defaultNode)
Reset node attributes to the initial state as defined in the constructor or the passed default node...
vtkMRMLNode * CreateNodeInstance() override
MRMLNode methods.
Manages adding and deleting of obserevers with events.
const char * GetNodeReferenceID(const char *referenceRole)
Utility function that returns the first node id for a specific referenceRole.
void GetNodeReferenceRoles(std::vector< std::string > &roles)
void SetAttribute(const char *name, const char *value)
Set a name value pair attribute.
int InMRMLCallbackFlag
Flag to avoid event loops
vtkObserverManager * MRMLObserverManager
vtkMRMLNode * SetAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=nullptr)
Set and observe a reference node from this node for a specific referenceRole.
virtual void InvokeCustomModifiedEvent(int eventId, void *callData=nullptr)
This method allows the node to compress events.
virtual void OnNodeAddedToScene()
const char * GetNthNodeReferenceRole(int n)
void ReadXMLAttributes(const char **atts) override
Read node attributes from XML file
virtual bool HasCopyContent() const
Returns true if the class supports deep and shallow copying node content.
virtual int StartModify()
Start modifying the node. Disable Modify events.
void PrintSelf(ostream &vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) override
virtual void UpdateReferences()
The method should remove all pointers and observations to all nodes that are not in the scene anymore...
virtual void CopyReferences(vtkMRMLNode *node)
Copy the references of the node into this.
std::map< std::string, vtkSmartPointer< vtkIntArray > > NodeReferenceEventsType
void SetDisableModifiedEvent(int onOff)
virtual int GetDisableModifiedEvent()
Turn on/off generating InvokeEvent for set macros.
virtual void UpdateReferenceID(const char *oldID, const char *newID)
Update the stored reference to another node in the scene.
std::map< std::string, std::string > NodeReferenceMRMLAttributeNames
const char * GetAttribute(const char *name)
Get value of a name value pair attribute.
bool HasNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Return true if referencedNodeID is in the node ID list for a specific referenceRole.
virtual void OnNodeReferenceModified(vtkMRMLNodeReference *reference)
Called when a referenced node pointer is modified.
vtkMRMLNode * AddAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=nullptr)
Add and observe a reference node from this node for a specific referenceRole.
virtual char * GetSingletonTag()
NodeReferenceEventsType NodeReferenceEvents
void GetNodeReferenceIDs(const char *referenceRole, std::vector< const char *> &referencedNodeIDs)
Return a list of the referenced node IDs.
virtual void UpdateNodeReferences(const char *referenceRole=nullptr)
std::string XMLAttributeEncodeString(const std::string &inString)
Encode an XML attribute string (replaces special characters by code sequences)
void WriteNodeBodyXML(ostream &of, int indent) override
Write this node's body to a MRML file in XML format.
vtkSmartPointer< vtkMRMLNode > ReferencedNode
The referenced node that is actually observed now.
void SetAddToSceneNoModify(int value)
virtual void SetSceneReferences()
Update the references of the node to the scene.
void RemoveAttribute(const char *name)
Remove attribute with the specified name.
A set of MRML Nodes that supports serialization and undo/redo.
vtkIntArray * ContentModifiedEvents
Safe replacement of MRML node start/end modify.
vtkSmartPointer< vtkIntArray > Events
vtkMRMLNode * AddNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Convenience method that adds a referencedNodeID at the end of the list.
virtual int EndModify(int previousDisableModifiedEventState)
End modifying the node.
void AddNodeReferenceRole(const char *referenceRole, const char *mrmlAttributeName=nullptr, vtkIntArray *events=nullptr)
Add a referenceRole.
void RemoveNthNodeReferenceID(const char *referenceRole, int n)
Convenience method that removes the Nth node ID from the list.
virtual void OnNodeReferenceRemoved(vtkMRMLNodeReference *reference)
Called when a referenced node pointer is removed (set to nullptr).
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...
virtual void ProcessChildNode(vtkMRMLNode *)
Set dependencies between this node and a child node when parsing XML file.
virtual void SetScene(vtkMRMLScene *scene)
This method is for internal use only. Use AddNode method of vtkMRMLScene to add a node to the scene...
const char * URLDecodeString(const char *inString)
Decode a URL string.
char * ReferenceRole
Name of the reference role.
AttributesType Attributes
vtkMRMLNode * GetNthNodeReference(const char *referenceRole, int n)
Get referenced MRML node for a specific referenceRole.
std::map< std::string, std::string > AttributesType
void ProcessMRMLEvents(vtkObject *, unsigned long, void *) override
alternative method to propagate events generated in Storage nodes
void RemoveNodeReferenceIDs(const char *referenceRole)
Remove all node IDs and associated nodes for a specific referenceRole.
void Copy(vtkMRMLNode *node) override
Copy the node's attributes to this object
vtkCallbackCommand * MRMLCallbackCommand
Holders for MRML callbacks.
vtkWeakPointer< vtkMRMLScene > Scene
MRMLNodeModifyBlocker(vtkMRMLNode *node)
void WriteXML(ostream &of, int indent) override
Write this node's information to a MRML file in XML format.
vtkMRMLNode * SetNodeReferenceID(const char *referenceRole, const char *referencedNodeID)
Set a reference to a node with specified nodeID from this node for a specific referenceRole.
virtual void OnNodeReferenceAdded(vtkMRMLNodeReference *reference)
void Modified() override
Customized version of Modified() allowing to compress vtkCommand::ModifiedEvent.
void GetNodeReferences(const char *referenceRole, std::vector< vtkMRMLNode *> &nodes)
Return a list of the referenced nodes.
void SetInMRMLCallbackFlag(int flag)
void CopyWithScene(vtkMRMLNode *node)
Copy everything (including Scene and ID) from another node of the same type.
Abstract Superclass for all specific types of MRML nodes.
Class to hold information about a node reference.
const char * URLEncodeString(const char *inString)
Encode a URL string.
NodeReferencesType NodeReferences
virtual void SetSingletonTag(const char *)
Tag that make this node a singleton in the scene.
void DisableModifiedEventOn()
int GetNumberOfNodeReferenceRoles()
vtkWeakPointer< vtkMRMLNode > Node
virtual void UpdateScene(vtkMRMLScene *)