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;
44 #ifndef vtkSetMRMLObjectMacro 45 #define vtkSetMRMLObjectMacro(node,value) {this->MRMLObserverManager->SetObject ( vtkObjectPointer( &(node)), (value) );}; 49 #ifndef vtkSetAndObserveMRMLObjectMacro 50 #define vtkSetAndObserveMRMLObjectMacro(node,value) {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value) );}; 53 #ifndef vtkSetAndObserveMRMLObjectMacroNoWarning 54 #define vtkSetAndObserveMRMLObjectMacroNoWarning(node,value) {this->MRMLObserverManager->SetAndObserveObject ( vtkObjectPointer( &(node)), (value), 0.0, false );}; 57 #ifndef vtkSetAndObserveMRMLObjectEventsMacro 58 #define vtkSetAndObserveMRMLObjectEventsMacro(node,value,events) {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events));}; 61 #ifndef vtkSetAndObserveMRMLObjectEventsMacroNoWarning 62 #define vtkSetAndObserveMRMLObjectEventsMacroNoWarning(node,value,events) {this->MRMLObserverManager->SetAndObserveObjectEvents ( vtkObjectPointer( &(node)), (value), (events), NULL , false );}; 65 #ifndef vtkObserveMRMLObjectMacro 66 #define vtkObserveMRMLObjectMacro(node) {this->MRMLObserverManager->ObserveObject ( (node) );}; 69 #ifndef vtkObserveMRMLObjectEventsMacro 70 #define vtkObserveMRMLObjectEventsMacro(node, events) {this->MRMLObserverManager->AddObjectEvents ( (node), (events) );}; 73 #ifndef vtkUnObserveMRMLObjectMacro 74 #define vtkUnObserveMRMLObjectMacro(node) {this->MRMLObserverManager->RemoveObjectEvents ( (node) );}; 77 #ifndef vtkSetReferenceStringBodyMacro 78 #define vtkSetReferenceStringBodyMacro(name) \ 79 vtkDebugMacro(<< this->GetClassName() << " (" << this << "): setting " << #name " to " << (_arg?_arg:"(null)") ); \ 80 if ( this->name == NULL && _arg == NULL) { return;} \ 81 if ( this->name && _arg && (!strcmp(this->name,_arg))) { return;} \ 82 std::string oldValue; \ 83 if (this->name) { oldValue = this->name; delete [] this->name; } \ 86 size_t n = strlen(_arg) + 1; \ 87 char *cp1 = new char[n]; \ 88 const char *cp2 = (_arg); \ 90 do { *cp1++ = *cp2++; } while ( --n ); \ 97 if (this->Scene && this->name) \ 99 if (oldValue.size() > 0) \ 101 this->Scene->RemoveReferencedNodeID(oldValue.c_str(), this); \ 103 this->Scene->AddReferencedNodeID(this->name, this); \ 107 #ifndef vtkSetReferenceStringMacro 108 #define vtkSetReferenceStringMacro(name) \ 109 virtual void Set##name (const char* _arg) \ 111 vtkSetReferenceStringBodyMacro(name)\ 115 #ifndef vtkCxxSetReferenceStringMacro 116 #define vtkCxxSetReferenceStringMacro(class,name) \ 117 void class::Set##name (const char* _arg) \ 119 vtkSetReferenceStringBodyMacro(name); \ 123 #ifndef vtkMRMLNodeNewMacro 124 #define vtkMRMLNodeNewMacro(newClass) \ 125 vtkStandardNewMacro(newClass); \ 126 vtkMRMLNode* newClass::CreateNodeInstance() \ 128 return newClass::New(); \ 147 void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
192 virtual void WriteXML(ostream& of,
int indent);
259 return disabledModify;
269 virtual int EndModify(
int previousDisableModifiedEventState)
272 if (!previousDisableModifiedEventState)
276 return this->ModifiedEventPending;
324 virtual void ProcessMRMLEvents ( vtkObject *caller,
unsigned long event,
void *callData );
340 vtkSetStringMacro(
Name);
341 vtkGetStringMacro(
Name);
345 vtkGetStringMacro(
ID);
373 vtkSetStringMacro(SingletonTag);
374 vtkGetStringMacro(SingletonTag);
400 vtkGetMacro(DisableModifiedEvent,
int);
403 this->DisableModifiedEvent = onOff;
419 vtkGetMacro(ModifiedEventPending,
int);
442 ++this->ModifiedEventPending;
455 int oldModifiedEventPending = 0;
457 if ( this->ModifiedEventPending )
459 oldModifiedEventPending += this->ModifiedEventPending;
460 this->ModifiedEventPending = 0;
464 if (!this->CustomModifiedEventPending.empty())
469 std::vector<int> customEventsToInvoke;
470 for (std::map< int, int >::iterator it=this->CustomModifiedEventPending.begin(); it!=this->CustomModifiedEventPending.end(); ++it)
472 oldModifiedEventPending += it->second;
473 customEventsToInvoke.push_back(it->first);
475 this->CustomModifiedEventPending.clear();
476 for (std::vector<int>::iterator it=customEventsToInvoke.begin(); it!=customEventsToInvoke.end(); ++it)
478 this->InvokeEvent(*it);
481 return oldModifiedEventPending;
501 this->InvokeEvent(eventId, callData);
507 ++this->CustomModifiedEventPending[eventId];
607 void AddNodeReferenceRole(
const char *referenceRole,
const char *mrmlAttributeName=0, vtkIntArray *events=0);
711 std::vector<const char*> &referencedNodeIDs);
746 void PrintSelf(ostream& vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) VTK_OVERRIDE {};
749 vtkSetStringMacro(ReferenceRole);
750 vtkGetStringMacro(ReferenceRole);
752 vtkSetStringMacro(ReferencedNodeID);
753 vtkGetStringMacro(ReferencedNodeID);
760 void SetEvents(vtkIntArray* events);
761 vtkIntArray* GetEvents()
const;
800 static void MRMLCallback( vtkObject *caller,
801 unsigned long eid,
void *clientData,
void *callData );
805 vtkSetStringMacro( TempURLString );
806 vtkGetStringMacro( TempURLString );
815 virtual const char* GetReferenceRoleFromMRMLAttributeName(
const char* attName);
824 virtual const char* GetMRMLAttributeNameFromReferenceRole(
const char* refRole);
829 virtual bool IsReferenceRoleGeneric(
const char* refRole);
834 virtual void UpdateNodeReferences(
const char* referenceRole = NULL);
840 virtual void UpdateNthNodeReference(
const char* referenceRole,
int n);
853 void GetUpdatedReferencedNodeEventList(
int& oldReferencedNodeUseCount,
int& newReferencedNodeUseCount,
854 vtkIntArray* oldConsolidatedEventList, vtkIntArray* newConsolidatedEventList,
860 virtual void InvalidateNodeReferences();
884 void ParseReferencesAttribute(
const char *attValue, std::map<std::string, std::string> &references);
928 void SetID(
const char* newID);
935 int DisableModifiedEvent;
936 int ModifiedEventPending;
937 std::map<int, int> CustomModifiedEventPending;
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)
virtual void Copy(vtkMRMLNode *node) VTK_OVERRIDE
Copy the node's attributes to this object
void DisableModifiedEventOff()
std::vector< vtkSmartPointer< vtkMRMLNodeReference > > NodeReferenceListType
virtual int InvokePendingModifiedEvent()
Invokes any modified events that are pending.
void AddNodeReferenceRole(const char *referenceRole, const char *mrmlAttributeName=0, vtkIntArray *events=0)
Add a referenceRole.
vtkMRMLNode * SetAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=0)
Set and observe a reference node from this node for a specific referenceRole.
std::map< std::string, NodeReferenceListType > NodeReferencesType
std::vector< std::string > GetAttributeNames()
Get all attribute names.
virtual void WriteNodeBodyXML(ostream &of, int indent) VTK_OVERRIDE
Write this node's body to a MRML file in XML format.
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()
Only the scene can set itself to the node.
virtual void Reset(vtkMRMLNode *defaultNode)
Reset node attributes to the initial state as defined in the constructor or the passed default node...
Manages adding and deleting of obserevers with events.
void CopyWithSceneWithSingleModifiedEvent(vtkMRMLNode *node)
Copy everything (including Scene and ID) from another node of the same type.
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
virtual void OnNodeAddedToScene()
const char * GetNthNodeReferenceRole(int n)
virtual int StartModify()
Start modifying the node. Disable Modify events.
virtual void ProcessMRMLEvents(vtkObject *, unsigned long, void *) VTK_OVERRIDE
alternative method to propagate events generated in Storage nodes
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.
virtual char * GetSingletonTag()
NodeReferenceEventsType NodeReferenceEvents
void GetNodeReferenceIDs(const char *referenceRole, std::vector< const char *> &referencedNodeIDs)
Return a list of the referenced node IDs.
std::string XMLAttributeEncodeString(const std::string &inString)
Encode an XML attribute string (replaces special characters by code sequences)
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.
virtual const char * GetNodeTagName() VTK_OVERRIDE
Get node XML tag name (like Volume, Model)
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 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 NULL).
vtkMRMLNode * AddAndObserveNodeReferenceID(const char *referenceRole, const char *referencedNodeID, vtkIntArray *events=0)
Add and observe a reference node from this node for a specific referenceRole.
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)
void PrintSelf(ostream &vtkNotUsed(os), vtkIndent vtkNotUsed(indent)) VTK_OVERRIDE
const char * URLDecodeString(const char *inString)
Decode a URL string.
char * ReferenceRole
Name of the reference role.
AttributesType Attributes
vtkMRMLNode * SetAndObserveNthNodeReferenceID(const char *referenceRole, int n, const char *referencedNodeID, vtkIntArray *events=0)
Set and observe the Nth node ID for a specific reference role.
void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual void WriteXML(ostream &of, int indent) VTK_OVERRIDE
Write this node's information to a MRML file in XML format.
vtkMRMLNode * GetNthNodeReference(const char *referenceRole, int n)
Get referenced MRML node for a specific referenceRole.
std::map< std::string, std::string > AttributesType
void CopyWithSingleModifiedEvent(vtkMRMLNode *node)
void RemoveNodeReferenceIDs(const char *referenceRole)
Remove all node IDs and associated nodes for a specific referenceRole.
void CopyWithoutModifiedEvent(vtkMRMLNode *node)
vtkCallbackCommand * MRMLCallbackCommand
Holders for MRML callbacks.
vtkWeakPointer< vtkMRMLScene > Scene
virtual void InvokeCustomModifiedEvent(int eventId, void *callData=NULL)
This method allows the node to compress events.
virtual vtkMRMLNode * CreateNodeInstance() VTK_OVERRIDE
MRMLNode methods.
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)
virtual void UpdateNodeReferences(const char *referenceRole=NULL)
void GetNodeReferences(const char *referenceRole, std::vector< vtkMRMLNode *> &nodes)
Return a list of the referenced nodes.
void SetInMRMLCallbackFlag(int flag)
virtual void Modified() VTK_OVERRIDE
Customized version of Modified() allowing to compress vtkCommand::ModifiedEvent.
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()
virtual void UpdateScene(vtkMRMLScene *)
virtual void ReadXMLAttributes(const char **atts) VTK_OVERRIDE
Read node attributes from XML file