kanzure/python-brlcad — pull request #18 by ncsaba (2014-02-08 08:36:00+00:00)
Title: Wdb wrapper

Hi Bryan,

I added some code for reading the contents of a brlcad DB file. This is still WIP, but I want to share as early as possible to allow you to comment and critique :-)

What makes me really like python is this:

>>> from brlcad.wdb import *
>>> db = WDB("test_wdb.g")
>>> [x.d_namep for x in db]
['hyperboloid.s', 'rcc.s', 'epa.s', 'rhc.s', 'tgc.s', 'all.r', 'rpc.s', 'trc.s', 'eto.s', 'ehy.s', 'arb4.s', 'arb5.s', 'arb6.s', 'arb7.s', 'arb8.s', 'sph1.s', 'box1.s', 'cone.s', 'arbn.s', 'pipe.s', '_GLOBAL', 'torus.s', 'wedge1.s', 'trc_top.s', 'particle.s', 'ellipsoid.s']

I also added an "ls" method, which simply filters out the objects marked as hidden (here _GLOBAL is the only one):

>>> db.ls()
['hyperboloid.s', 'rcc.s', 'epa.s', 'rhc.s', 'tgc.s', 'all.r', 'rpc.s', 'trc.s', 'eto.s', 'ehy.s', 'arb4.s', 'arb5.s', 'arb6.s', 'arb7.s', 'arb8.s', 'sph1.s', 'box1.s', 'cone.s', 'arbn.s', 'pipe.s', 'torus.s', 'wedge1.s', 'trc_top.s', 'particle.s', 'ellipsoid.s']

I will likely add some more parameters to the ls, to filter by glob/regex, but it's just for convenience as you can always just filter the db iterator as you want in a list comprehension.

For now I only implemented the ARB8 and Combination primitives, the rest is still read and only wrapped in the generic Primitive class which does nothing for the moment.

Next I will work on:

* implementing ^, +, *, - operators over the primitives -> to yield the corresponding combination trees;

* wrap all primitives with convenience python code;

* test pip packaging and install;

As usual I'm happy for all and any feedback !

Cheers,
Csaba