Hierarchical assemblies.

When displaying a complex or animated scene, it is necessary to work with a large number of connected interactive objects that move relative to each other according to certain laws.

To facilitate this behavior, zencad provides the zencad.assemble library and its main tool zencad.assemble.unit.


Assembly unit (zencad.assemble.unit).

An assembly unit is an object that has its own local coordinate system, relative to which interactive objects and other units associated with this unit are positioned. Units can create a tree structure by counting their position relative to the position of the parent unit (unit.parent). If the unit does not have an ancestor, its position is measured from the global coordinate system.

The unit contains two coordinate transformation objects - location and global_location.


Adding an object.

Creates and links to the unit an interactive object based on the passed geometry object obj.

If an interactive object is passed as a parameter, the unit takes control of it. (Note: the unit controls the location of the interactive object).

Signature:

u.add(obj, color=zencad.default_color)

Example:

m = box(10)
i = interactive_object(box(10).right(20))
u.add(m)
u.add(i)

Adding a child unit.

Sets the u object to be the ancestor of the child object. Now the position of objects in the unit child (and its descendants) will be calculated taking into account the position of the object u.

Signature:

u.link(child)

Example:

***

Update global position.

Update the global position of the object according to its current position and the global position of the ancestor object. view - if the object is displayed, redraw it based on the new position. deep - apply recursively all descendants of an object.

Signature:

u.location_update(deep=True, view=True)

Update local position.

Change current position to location object and apply location_update procedure with deep, view options.

Signature:

u.relocate(location, deep=True, view=True)

Display on stage.

Signature:

u.bind_scene(scene, color=zencad.default_color, deep=True):

Add unit to scene scene. All objects whose colors are not set will be colored in default_color. If deep, recursively add all dependent units to the scene.