[Developers] Adding tree items

Nanne Hemstra nanne.hemstra at opendtect.org
Tue Jun 29 10:03:25 CEST 2004


Hi all,

Release 1.2 saw some major redesigns to make things even more 'Open'. 
The most notable issue was the design of the tree with display objects. 
We wanted to make it possible to add tree items from plugins. The new 
tree items should have the same status as the 'standard' tree items - 
for example the display objects must be (re-)storable to/from sessions.

To understand the mechanism, you have to remember that OpendTect 
supports multiple scenes. Therefore, we need to make an object that can 
create our tree item when this is necessary (i.e. when a new scene is 
created). Thus, the first thing we must do is program a 'creater' for 
the top level tree item. This class must a subclass of 
'uiODTreeItemCreater'. The create() function creates the parent tree 
item. The scene manager keeps the list of these creaters so we have to 
add our new creater to the scene manager's set:

int index = 3000; // determines order in the tree
uiTreeCreaterSet* tcs = ODMainWin()->sceneMgr().treeItemCreaterSet();
tcs->addCreater( new MyTreeItemCreater, index );


The treeitem itself consists of a parent treeitem and its children, each 
representing the visual objects. As the user likes to add objects to the 
scene and do various actions and manipulations to an object we have 
right-click submenus. So, the second thing we need to do is program the 
classes for the parent and the children with functions for menu creation 
and handling.

The parent is a subclass of 'uiTreeItem'. Most important function is the 
showSubMenu() function. Here you'll implement what menu should be shown 
when the user right-clicks on the parent item. For the top level, this 
is usually only an 'Add' menu.

A child is a subclass of 'uiODDisplayTreeItem'. I'll explain a few of 
its functions:

* init(): This function is called when the child item is created. The 
tree item is representing a visual object, so this is the place where 
you can create your visual object and add it to the scene.

* createMenuCB(): Create the right-click menu. Each item you add to this 
menu has a unique id. This id will be used in the handleMenuCB().

* handleMenuCB(): Handle the selected menuitem.


A good example of this all can be found in our new VolumeRender plugin 
(plugins/VolumeRender: volumerenderpi.cc and treeitem.cc/h).


Best regards,

Nanne Hemstra

-- 
/*
     dGB Earth Sciences B.V.
     Boulevard 1945 - 24, 7511 AE Enschede, the Netherlands
     Tel: +31 534315155   Fax: +31 534315104
     http://www.opendtect.org || http://www.dgb-group.com
*/



More information about the Developers mailing list