[Developers] Scoping your data

Bert Bril Bert.Bril at opendtect.org
Mon Jun 4 16:49:40 CEST 2007


Hi all,

To avoid data lying all around on the user's disks, most data should
simply go in the current survey directory. But some data is simply not
tied to any survey. I will not handle 'DTECT_DATA' level data here, I
figure that is too uncommon. Mostly, we are talking about installation-
and user-specific settings. It's important to use the right tool for the
right scope.


* Installation-wide setup data is typically in files that are delivered
with your plugin package. System administrators can then later change
these files. You cannot make edit utilities for these files inside
Opendtect itself due to permission issues: the installation itself is
normally not writable for users.

There is already a sketch of a system administrator's utility program in
uiTools (uiodsysadmmain.cc), but it just outlines the idea and only
implements copying color bars made by a user to the installation
directory.  We are planning to extend this idea in the coming year, and
so make a standard tool for management of setup files, installations,
utilities for data management, licensing stuff, and so forth.


* User-specific setup data should go in the user settings, see
Basic/settings.h. The Settings object is simply an IOPar. There is a
global 'common()' setting tied to HOME/.od/setttings which could be used
as follows:

 int iconsz = 32;
 Settings::common().get( "dTect.Icons.size", iconsz ).
 if ( iconsz > 64 )
 {
   iconsz = 64;
   Settings::common().set( "dTect.Icons.size", iconsz );
   Settings::common().write();
 }

If the settings are specific to your plugin only, you can ask for your
own settings:

Settings& setts = Settings::fetch( "MyOwnPlugin" );
setts.set( "Foo size", foo.size() );
setts.write();

These statements will read (and write) a settings_MyOwnPlugin file in
the .od directory in the user's 'home' directory. You can therefore use
your own settings just like the common settings and use them as if they
had always existed. This mecahnism is already use for color table,
shortcuts, FlatViewer etc. setup parameters (settings_coltabs,
settings_flatview, ...).


* Survey-specific data can be one of two:
 - Just another cube, horizon or well etc.
 - Something else
In the 'something else' case, you can choose to add your object to the
standard directories. For example, if you want to store a new weird kind
of surface, the 'Surfaces' directory would be a good candidate.

But chances are that you have very specific stuff that is of no use to
anyone else. In that case, you can use the mechanism as described in a
previous post (Oct 17, 2006) to create your own data directory. An
example plugin that uses this mechanism is:
ftp://ftp.opendtect.org/pub/devel/uiowniodir.tar.gz

I'll summarize here:
- Choose your selection key:

    static const char* sSelKey = "789987"; // unique and > 100000

- Create a translator group and a translator with two simple macros

mDeclEmptyTranslatorBundle(FooObj,FooFmt,"Foo bar")
mDefSimpleTranslatorsWithSelKey(FooObj,"FOO Object",FooFmt,None,sSelKey)

- Add the directory in the plugin's init by asking the IOM():

    IOMan::CustomDirData cdd( sSelKey, "FooishData", "Foo-ish data" );
    MultiID id = IOMan::addCustomDataDir( cdd );
    if ( id != sSelKey )
        return "Can't create the 'FooishData' storage directory";



That's it. Three ways to handle 3 very different data scopes.


/Bert

-- 
-- Bert Bril / OpendTect developer at dGB
-- Nijverheidstraat 11-2, 7511 JM Enschede, The Netherlands
-- mailto:Bert.Bril at opendtect.org , http://opendtect.org
-- Tel: +31 534315155 , Fax: +31 534315104




More information about the Developers mailing list