mitk::DataStorage::Pointer storage = GetDefaultDataStorage(); storage->AddNodeEvent.AddListener( mitk::MessageDelegate1<YOURPLUGIN, const mitk::DataNode*>( this, &YOURPLUGIN::YOURPLUGINFUNCTION ));
First get a pointer to the default data storage. It's member variable AddNodeEvent, itself a typedef, offers the AddListener function. Use a mitk::MessageDelegate1 as parameter. MessageDelegate1 takes the type of your plug-in and a return value, in this case a mitk::DataNode pointer to effectivly create a delegate. Delegates are not part of C++, so this object is effectivly a delegate implementation taking a this pointer (google can help you if you don't know what this means). At last give the constructor of the delegate a this pointer and a function pointer to your listerner function.
That's it. If a node is added to the data storage the given listener function is called with a pointer to the added node. Further steps can be taken from here.
There are additional listener functions like DeleteNodeEvent, RemoveNodeEvent and ChangeNodeEvent. Implement them all for fame and glory.
Keine Kommentare:
Kommentar veröffentlichen