Adding an instance to a data tree

P

pgarrone

Hi,
I have a data tree. A node in the tree "assembles" itself when called
upon to do so by the level-of-detail algorithm.
It creates and adds its children to itself using a base class method
called "add". However in the pseudo-constructor called "setup", the
child node needs to be already linked into the tree in order to obtain
configuration information. So the "add" method creates the child,
optionally positions it within the parents frame of reference, then
invokes the child's setup method which has variable length arguments.
Here is an example of code in an assemble method.

self.add("Reservoir", (Reservoir, r, r +
self.inner_tank_thickness))
self.add("End_tank", (End_tank, r,
self.outer_tank_radius),
0.5*self.payload_length +
0.5*self.outer_tank_thickness)
self.add("Inner_end_tank", (End_tank, r,
self.outer_tank_radius),
-0.5*self.payload_length
-0.5*self.outer_tank_thickness)
self.add("Zero_G_port", Zero_G_port,
0.5*self.payload_length
-0.5*self.zg_length)
self.add("Hangar-floor", Hangar)
self.add("herc", Hercules_shuttle,
(0.5*self.payload_length - 25,
R3d(180.0,V3d(0,1,0))))
self.add("herc1", Hercules_shuttle,

(V3d(0,-12.5,0.5*self.payload_length - 25), R3d(180.0,V3d(0,1,0))))

The add method takes the parameters "name", child-information, and
optional location-information.
The child information is either a class, or a tuple whose first member
is a class. The remaining members of the tuple are parameters to the
class setup method.

The problem is this: Sometimes the setup method parameters are quite
numerous, leading to problems when the order is misjudged. If invoked
directly, then naming parameters minimises the problems with missed
parameters. However the indirect creation via the "add" method means
the parameters are passed in a tuple, so the parameters cannot be
named.

How can I "pre-construct" the children with parent id and optional
location information, and also implement the advantages of named
function parameters?
Looking for all suggestions.
 
P

pgarrone

And of course the solution occurs to me about 30 minutes after posting,
to have the add method return an instance which then invokes setup.
self.add(name, child_type, other_info).setup(child-setup-parameters)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top