[OpendTect_Developers] Creation notification

Bert Bril bert at opendtect.org
Tue Sep 20 16:12:09 CEST 2011


Hi all,


I've just added a couple of macros to callback.h, for something that 
will become more and more pervasive in OpendTect. Expect them in next 
(patch) releases.

The issue is: you want to add your own stuff to an existing OpendTect 
window. That means you should get the opportunity, every time that an 
instance of that window is created, to do something - like add a button.

 From the perspective of the creator of the Window, this means not only 
'opening up' the interface (i.e. giving access to some of the internals 
of the window), but also making a notifier available that triggers every 
time a window is created.

<background>

In OpendTect, callback notification is done via the CallBack's. If 
classes want to notify a certain event, they add a Notifier to the 
public interface, like:

     Notifier<uiFoo>		barOccurred;

When foo actually occurs, the class programmer simply puts in the code:

     barOccurred.trigger();

The receiving end of the notification will ask for notification with 
something like:

     my_uifoo.notify( mCB(this,MyClass,handleFooEv) );

</background>


That is all boilerplate stuff. The novel usage is to notify something 
that you cannot tie to an instance, as it notifies the creation of 
something (the something cannot exist at the time you ask for the 
notification). And that calls for a static Notifier member.

The implementation is rather easy, and has some details that are not 
very interesting. Therefore, just the usage here:

1) In the public interface, add:
     mDeclInstanceCreatedNotifierAccess(uiFoo);
2) In the .cc file, add:
     mDefineInstanceCreatedNotifierAccess(uiFoo)
3) At the end of the constructor, add:
     mTriggerInstanceCreatedNotifier();

The users of the class need to do:
     uiFoo::instanceCreated().notify( mCB(this,MyClass,handleNewFoo) );


That's it.

The first thing we've done in this respect is supporting it for some of 
the most common 'Manage' windows. See next 4.3.x release.


- Bert

-- 
-- Bert Bril / OpendTect developer at dGB
-- mailto:Bert.Bril at opendtect.org , http://opendtect.org





More information about the Developers mailing list