[OpendTect_Developers] Creating custom objects

Ranojay Sen ranojay.sen at dgbes.com
Wed Jul 31 10:41:39 CEST 2013


  Hi Tim,

In a nut shell, you need the following things, one parent tree item, one 
child tree item, a visual object, and a tree item factory.  So to start 
with, you have to derive each of these classes from the OD classes, and 
implement your own functionality in them.

So first we need a parent tree item which will appear in the list of the 
main OpendTect tree list, which will respond to the right-click menu and 
add a child tree item to it. The child tree item should have a 
visBase/visSurvey  object which it can add to the scene via 
visPartServer. That means ...

class MyParentTreeItem : public uiTreeItem
{
public:
                                             MyParentTreeItem();
                                             ~MyParentTreeItem();

     int                                   sceneID() const;

protected:
     vistual bool                    init();
     vistual const char*        parentType() const;
      virtual bool                   showSubMenu();

     ChildTreeItem*             childitem_;
};

//// In the source file

MyParentTreeItem::MyParentTreeItem()
     : uiTreeItem("Parent")
     , childitem_(0)
{}


MyParentTreeItem::~MyParentTreeItem()
{}


bool MyParentTreeItem::showSubMenu()
{
     uiMenu mnu( getUiParent(), "Action" );
     mnu.insertItem( new uiAction("&Add ..."), 0 );
     mnu.insertItem( new uiAction("&Remove ..."), 1 );
     const int mnusel = mnu.exec();
     if ( mnusel == 0 )
     {
         childitem_ = new MyChildItem( "Child" );
         addChild ( childitem_, true );
     }
     else if ( mnusel == 1 )
     {
         removeChild( childitem_ );
     }

     return true;
}


int MyParentTreeItem::sceneID() const
{
     int sceneid;
     if ( !getProperty<int>(uiODTreeTop::sceneidkey(),sceneid) )
     return -1;
     return sceneid;
}


bool MyParentTreeItem::init()
{
     return uiTreeItem::init();
}


const char* MyParentTreeItem::parentType() const
{ return typeid(uiODTreeTop).name(); }

////////////////////////////////////////////////

Similarly for the child item we need the following

class ChildTreeItem: public uiODDisplayTreeItem
{
public:
                                             ChildTreeItem(const char* s);
                                             ~ChildTreeItem();
   protected:

     virtual const char*        parentType() const
                                             { return typeid 
(ParentTreeItem).name(); }
     virtual   bool                  init();

     /*vsiBase::yourVisObject*        visobject_;*/
};


///////////////////and the source file should be

ChildTreeItem::ChildTreeItem( const char *s )
     : visobject_(0)
{}


ChildTreeItem::~ChildTreeItem()
{
}


bool ChildTreeItem::init()
{
     uiVisPartServer* visserv = ODMainWin()->applMgr().visServer();
     visobject_ = visBase::YourVisObject::create();
     visserv->addObject( visobject_, sceneID(), false );
      return uiODDisplayTreeItem::init();
}


and you need a tree item factory to add to the list of global tree items 
of OpendTect.

class TreeItemFactory : public uiODTreeItemFactory
{
public:
     const char*                        name() const   { return getName(); }
     static const char*             getName()      { return 
typeid(TreeItemFactory).name();}
     uiTreeItem*                       create() const { return new 
MyParentTreeItem; }
     uiTreeItem*                       create(int,uiTreeItem*) const { 
return new MyParentTreeItem; }
};


At your programs entry point you have to create one instance of this 
class and add it to the factory list.

  TreeItemFactory*  mytreefactory = new TreeItemFactory;
  ODMainWin()->sceneMgr().treeItemFactorySet()->addFactory( mytreefactory );


So this was roughly the structure you need to start with a tree item and 
a visual object. You can have a look at the source code for the 
Annotations plugin, which is in the open source part of OpendTect.

For more on this, you can always come back to me.

Regards
Ranojay
> Dear Developers,
>
> I am trying to create my own visual objects in OD but I need help with 
> add the item to the tree and visualising it.
>
> Can you show me two quick examples?
>
> The example I found on the web is from 2004.
> Cheers
> Timi
>
>
> _____________________________________________________________
> OpendTect Developers mailing list Developers at opendtect.org
> http://lists.opendtect.org/mailman/listinfo/developers
>
> You receive this mail because you are listed on developers at opendtect.org To unsubscribe please go to http://lists.opendtect.org/mailman/options/developers . If you encounter any problems, please contact support at opendtect.org .


-- 
Ranojay Sen
Team leader Windows development
dGB Earth Sciences (India)
310, Gateway Plaza,
Hiranandani Gardens - Powai
Mumbai 400 076 - India -
Tel. +91 22 25704984 - Fax +91 22 25704977
www.dgbes.com www.opendtect.org

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


More information about the Developers mailing list