[OpendTect_Developers] How to add your own element in 2D Viewer's tree

Umesh Sinha umesh.sinha at dgbes.com
Thu Feb 3 11:37:48 CET 2011


Dear All,

As we all know dTector community is growing with the buzzword 'Its a 
great tool for 3D Visualization'. It is indeed. But at the same time, we 
at dGB are equally committed to facilitate you with a powerful and 
robust 2D viewer. Keeping this goal in mind we can proudly say that with 
our latest release, 4.2.0 Beta, we have taken quite a big and profound 
stride.

We are trying to make 2D Viewer independent of our 3D Viewer. If you 
have already downloaded our latest version 4.2.0 Beta and happen to come 
across 2D Viewer, you will quickly notice  the *tree with some elements* 
on the left side of window. This tree is quite similar to what we have 
in our 3D viewer, so theoretically you should be able to do all the 
stuff you have been doing with the 3D tree and that's what we aspire to 
achieve in long run.

So, today I'm going to let you know how to add your own element in 2D 
Viewer's tree.

Working principle behind tree structure in 2D Viewer system is, on top 
of every thing there should be a 'top tree' item, top tree item should 
have mother(parent) items as child and finally these mother(parent) 
items should be capable of generating their offspring(child) items.

'uiTreeFactorySet' is the class which helps in generating 'top tree' 
item. Since 2D viewer either displays 2 dimensional type objects or 3 
dimensional type objects, we have decided to have two 'uiTreeFactorySet' 
corresponding to each type. So you can access each set as in:

uiTreeFactorySet* tfs2d = ODMainWin()->viewer2DMgr().treeItemFactorySet2D();
uiTreeFactorySet* tfs3d = ODMainWin()->viewer2DMgr().treeItemFactorySet3D();

This 'uiTreeFactorySet' is also responsible for holding bunch of 
factories. These factories helps in generating 'parent' item and 
attaching them to 'top tree'.

Before going into how 'Factory' should look like we need to have an 
understanding of parent item. Every parent tree item must be a subclass 
of 'uiODVw2DTreeItem' and some of the important functions for parent 
tree item are:

_showSubMenu()_: when you right click on your parent tree item this 
function get called, here you generate your pop-up menu and call 
handleSubMenu(int). For a working example of what should be the content 
of this function see below.

uiPopupMenu mnu( getUiParent(), "Action" );
mnu.insertItem( new uiMenuItem("&New"), 0 );
mnu.insertItem( new uiMenuItem("&Load ..."), 1 );
return handleSubMenu( mnu.exec() );

_handleSubMenu(int)_: this is largely responsible for generating 
offspring(child).

Now comes question of 'Factory' class. Here  subclass of 
'uiTreeItemFactory' comes handy. If you say your parent class is 
'myItemParentTreeItem' then your factory tree item should be like

class myItemFactory : public uiTreeItemFactory
{
public:
    const char*         name() const            { return 
typeid(*this).name(); }
    uiTreeItem*         create() const
                        { _return new myItemParentTreeItem();_ }
};

This is a pretty straight forward class; underlined part shows how 
parent item get created.

Now you need to add this 'myItemFactory' to 'uiTreeFactorySet'. You can 
do this by calling 'uiTreeFactorySet::addFactory' function as shown below.

tfs(2d/3d)->addFactory( new myItemFactory, orderidx );

here second parameter of the function 'addFactory' should be an integer, 
it helps in determining order of your parent item in tree. The moment 
you call 'addfactory' function corresponding 'parent' tree item get 
created and get attached to 'top tree' item as child.

And finally comes the child, tree item of our interest. This is again a 
subclass of 'uiODVw2DTreeItem' and represents the 2d visual object. Some 
of the important functions corresponding to child tree are:

_init()_: The moment your child object get created this function get 
called. Here you do all your plumbing stuff, along with important step 
of creation of your 2d visual object.
_showSubMenu()_: Its functionality is same as of parent tree item.
_isSelectable()_: if you want your tree item to remain selected even 
after releasing the mouse click, you should implement this and make sure 
this function return 'true'.
_select()_: when you select your tree item in tree this function get called.

How to deal with 2d visual object in your tree item, I'll explain in my 
next post. Till then happy coding!

With Regards,
Umesh

-- 
Umesh Sinha
Geoscientific Software Engineer
dGB Earth Science
304, Gateway Plaza, Hiranandani Garden, Powai, Mumbai 400076, India
Phone: +91 22 25704984 , Fax: +91 22 25704977, Mobile: +91 9930126183
umesh.sinha at dgbes.com, http://www.dgbes.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20110203/e4946d60/attachment.html>


More information about the Developers mailing list