Introduction
Starting with 12.0, it is possible to allow Snapper
s to exist 'on' other Snapper
s. Referred to as 'child' Snapper
s, these Snapper
s will function almost entirely the same as 'normal', but will not be present in the BSP or a Space
. This allows for complex product structures, while reducing the potential performance penalties accrued with traditional composition strategies. This also allows developers to leverage the full flexibility of the Snapper
class while organizing into 'sub'-objects.
Family Trees
Some Snapper
functionality is encapsulated in specific classes. For example, Model3DSnapper
adds additional support for working with 3D graphics, and BlockSnapper
adds support for working with block Spaces. The parent/child functionality, however, is built directly into Snapper
; there is no specific subclass that adds this functionality. This means that any Snapper
can become a parent or child. It is an 'opt-in' mechanism that any Snapper
can allow.
A Snapper
becomes a parent by accepting an adoption of another Snapper
. A Snapper
becomes a child by being adopted by another Snapper
. A child Snapper
can itself become a parent by accepting the adoption of another Snapper
. This allows for deep 'nesting' of Snapper
s, should such behavior be desired.
There are a handful of interfaces on Snapper
(explained below) that can retrieve parents and children once the adoption has taken place. There also exists an object on the parent, called a SnapperRelationship
, which specifies how the child should behave. This can be used to specify whether or not the child is selectable, movable, etc.
User Adoption Process
The process by which a user assigns Snapper
s to be adopted by a parent is very short/simple. What follows is an approximation of steps taken
- A
Snapper
is placed in the drawing by any means. Call thisSnapper
'A'. - The user begins the placement of another
Snapper
; either by dragging or inserting. Call thisSnapper
'B' - When
Snapper
'B' is placed in the proximity ofSnapper
'A', the Animation will invokeacceptAdoption()
onSnapper
'A'- If this method returns a value of
false
(the default returned value),Snapper
'B' will not be adopted, and bothSnapper
s will continue to behave as normal - If this method returns a value of
true
, the Animation will invoke the appropriate methods to form a parent/child relationship betweenSnapper
'A' (now the parent) andSnapper
'B' (now the child)
- If this method returns a value of
Manual Adoption
It is also possible to assign Snapper
s to a parent/child relationship manually (via code). The changeParent()
function can be called to either assign a parent to a child, or remove a parent (by specifying null
for the to
argument).
public bool changeParent(Snapper z, Snapper to, bool putInBsp=true, ChangeParentEnv env=null)
Interfaces
What follows is a description of the methods and classes available for working with parent/child Snapper
s
Snapper
public bool acceptAdoption(Snapper child)
This method indicates whether or not a certain Snapper
should be adopted as a child.
public void childAdded(Snapper child)
public void childRemoved(Snapper child)
These methods are invoked on a parent Snapper
when a child is added or removed. This is the best place to update any internal state relevant to children.
public void parentChanged(Snapper oldParent)
This method is invoked when a Snapper
's parentage changes (either added or removed).
public Snapper parent()
public Snapper rootParent()
parent()
returns a Snapper
's immediate parent (or null if not a child Snapper
). rootParent()
will return the outer-most parent, by recursively invoking parent()
until finding the Snapper
that has no parent. rootParent()
can return this
if this is already the root parent.
public bool isChildSnapper()
Returns 'true' if this Snapper
has a parent.
public bool childOf(Snapper parent)
public bool anyChildOf(Snapper parent)
childOf()
will return true
if this Snapper
is an immediate child of parent
. anyChildOf()
will return true
if this Snapper
is a child, grandchild, etc. of parent
.
public bool hasChildSnappers()
This method indicates that the Snapper
has at least one child snapper
public Snapper{} children(bool recursive=false)
children()
gathers the immediate children of this Snapper
, or all children recursively if recursive
is true
.
public void visitChildren(SnapperVisitor visitor)
This method allows for visiting all immediate children of this Snapper
, via the visitor pattern
public SnapperRelationship relationship(Snapper child)
public SnapperRelationship parentRelationship()
The relationship()
method is where a Snapper
provides the SnapperRelationship
that should be used when specifying behavior of the child snapper child
. parentRelationship()
will return the SnapperRelationship
of the Snapper
's parent (if any).
SnapperRelationship
public bool redirectSelectionToParent(Snapper parent, Snapper child)
Indicates whether or not the child Snapper
should be selectable. If this method returns true
, clicking on the child Snapper
will instead select its parent. Default: false
public bool allowUserMoveChild(Snapper parent, Snapper child, Animation anim=null)
Indicates whether or not the user should be able to move the child Snapper
(when single-selected). If false
, click-dragging on the child Snapper
will do nothing. Default: true
public bool redirectLeftDragToParent(Snapper parent, Snapper child)
Indicates whether the parent or the child should be dragged when the user click-drags on the child Snapper
. If this method returns true
, user click-drag on the child snapper will instead drag the parent Snapper
. Default: false
public bool allowUserReleaseChild(Snapper parent, Snapper child, Animation anim=null)
Indicates whether or not the child Snapper
can be removed from the parent Snapper
. Default: true
public bool allowUserDeleteChild(Snapper parent, Snapper child)
Indicates whether or not the child Snapper
can be deleted, either via the user selecting the child and pressing DELETE, or the remover tool. Default: true
public bool includeChildParts(Snapper parent, Snapper child)
Indicates whether or not parts should be collected from the child Snapper
. Default: true
public bool propagatePartTags(Snapper parent, Snapper child)
Indicates whether or not part tags should be applied to the child Snapper
when they are applied to the parent. Default: false
public bool propagateCategories(Snapper parent, Snapper child)
Indicates whether or not categories applied to the parent Snapper
(by the user) should also be applied to the child Snapper
. Default: false
public bool propagateSpaceVolumes(Snapper parent, Snapper child)
Indicates whether or not the child Snapper
should change space volumes when the parent changes space volumes. Default: false
Comments
0 comments
Please sign in to leave a comment.