Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.renderer.common.nodes
Class BaseGroupingNode

java.lang.Object
  extended by org.web3d.vrml.renderer.common.nodes.AbstractNode
      extended by org.web3d.vrml.renderer.common.nodes.BaseGroupingNode
All Implemented Interfaces:
VRMLNode, FrameStateListener, VRMLBoundedNodeType, VRMLChildNodeType, VRMLGroupingNodeType, VRMLNodeType, VRMLWorldRootChildNodeType

public abstract class BaseGroupingNode
extends AbstractNode
implements VRMLGroupingNodeType, VRMLBoundedNodeType

Common basic implementation of any node that uses grouping functionality.

The basic (X3D) definition of X3DGroupingNode is:

  X3DGroupingNode : X3DChildNode, X3DBoundedObject {
    MFNode  [in]     addChildren
    MFNode  [in]     removeChildren
    MFNode  [in,out] children       []       [X3DChildNode]
    SFNode  [in,out] metadata       NULL     [X3DMetadataObject]
    SFVec3f []       bboxCenter     0 0 0    (-8,8)
    SFVec3f []       bboxSize       -1 -1 -1 [0,8) or -1 -1 -1
  }
 

Version:
$Revision: 1.28 $
Author:
Justin Couch

Field Summary
protected  int childCount
          The number of children nodes we added, not the total.
protected static int FIELD_ADDCHILDREN
          Index of the addChildren field
protected static int FIELD_BBOX_CENTER
          Index of the Bounding box center bboxCenter field
protected static int FIELD_BBOX_SIZE
          Index of the Bounding box size bboxSize field
protected static int FIELD_CHILDREN
          Index of the children field
protected static int FIELD_REMOVECHILDREN
          Index of the removeChildren field
protected  boolean hasBindables
          Flag indicating if this node contains bindable/activatable nodes
protected static int LAST_GROUP_INDEX
          The last field index used by this class
protected  int shareCount
          Counter for the number of sharing references this has
protected static java.lang.String USE_BIND_MSG
          Message when the USE is a bindable
protected  float[] vfBboxCenter
          SFVec3f bboxCenter NULL
protected  float[] vfBboxSize
          SFVec3f bboxSize NULL
protected  java.util.ArrayList vfChildren
          MFNode children NULL
 
Fields inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
BAD_NODE_MSG, errorReporter, FIELD_METADATA, fieldLocalData, hasChanged, INIT_ONLY_WRITE_MSG, inSetup, isDEF, isStatic, LAST_NODE_INDEX, layerIds, METADATA_NODE_MSG, METADATA_PROTO_MSG, nodeName, pMetadata, refCounts, removedLayerIds, stateManager, vfMetadata, vrmlMajorVersion, vrmlMinorVersion
 
Constructor Summary
protected BaseGroupingNode(java.lang.String name)
          Construct a default instance of the grouping node type.
 
Method Summary
 void addChild(VRMLNodeType newChild)
          Append a new child node to the existing collection.
protected  void addChildNode(VRMLNodeType node)
          Add a single child node to the list of available children.
protected  void clearChildren()
          Clear the child node list of all children in the VRML node.
 boolean containsBindableNodes()
          A check to see if this grouping node contains any bindable nodes.
protected  void copy(VRMLGroupingNodeType node)
          Set the fields of the grouping node that has the fields set based on the fields of the passed in node.
 float[] getBboxCenter()
          Accessor method to get current value of field bboxCenter default value is 0 0 0.
 float[] getBboxSize()
          Accessor method to get current value of field bboxSize default value is -1 -1 -1.
 VRMLNodeType[] getChildren()
          Get the children, provides a live reference not a copy
 int getChildrenSize()
          Returns the number of children
 VRMLFieldData getFieldValue(int index)
          Get the value of a field.
 int getPrimaryType()
          Get the primary type of this node.
 boolean isShared()
          Check to see if this node has been used more than once.
protected  void removeChildNode(VRMLNodeType node)
          Remove the given node from this grouping node.
 void sendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex)
          Send a routed value from this node to the given destination node.
 void setChildren(VRMLNodeType newChild)
          Accessor method to set the children field Creates an array containing only newChild If passed null this method will act like removeChildren
 void setChildren(VRMLNodeType[] newChildren)
          Accesor method to set the children field If passed null this method will act like removeChildren
 void setDEF()
          Notify this node that is has been DEFd.
 void setShared(boolean used)
          Adjust the sharing count up or down one increment depending on the flag.
 void setupFinished()
          Notification that the construction phase of this node has finished.
 void setValue(int index, float[] value, int numValid)
          Set the value of the field at the given index as an array of floats.
 void setValue(int index, VRMLNodeType child)
          Set the value of the field at the given index as an array of nodes.
 void setValue(int index, VRMLNodeType[] children, int numValid)
          Set the value of the field at the given index as an array of nodes.
 void updateRefCount(int layer, boolean add)
          Change the reference count up or down by one for a given layer ID.
 
Methods inherited from class org.web3d.vrml.renderer.common.nodes.AbstractNode
addNodeListener, allEventsComplete, checkNodeType, checkSecondaryType, checkSecondaryType, clearRemovedLayerIds, fireFieldChanged, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, getSecondaryType, getUserData, getVRMLNodeName, hasFieldChanged, isDEF, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setErrorReporter, setFrameStateManager, setMetadataObject, setUserData, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setVersion, updateRefs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.web3d.vrml.nodes.VRMLNodeType
addNodeListener, clearRemovedLayerIds, getLayerIds, getMetadataObject, getRefCount, getRemovedLayerIds, hasFieldChanged, isSetupFinished, notifyExternProtoLoaded, removeNodeListener, setFrameStateManager, setMetadataObject, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue, setValue
 
Methods inherited from interface org.web3d.vrml.lang.VRMLNode
getFieldDeclaration, getFieldIndex, getNodeFieldIndices, getNumFields, getSecondaryType, getUserData, getVRMLNodeName, isDEF, setErrorReporter, setUserData, setVersion
 
Methods inherited from interface org.web3d.vrml.nodes.FrameStateListener
allEventsComplete
 

Field Detail

FIELD_CHILDREN

protected static final int FIELD_CHILDREN
Index of the children field

See Also:
Constant Field Values

FIELD_ADDCHILDREN

protected static final int FIELD_ADDCHILDREN
Index of the addChildren field

See Also:
Constant Field Values

FIELD_REMOVECHILDREN

protected static final int FIELD_REMOVECHILDREN
Index of the removeChildren field

See Also:
Constant Field Values

FIELD_BBOX_CENTER

protected static final int FIELD_BBOX_CENTER
Index of the Bounding box center bboxCenter field

See Also:
Constant Field Values

FIELD_BBOX_SIZE

protected static final int FIELD_BBOX_SIZE
Index of the Bounding box size bboxSize field

See Also:
Constant Field Values

LAST_GROUP_INDEX

protected static final int LAST_GROUP_INDEX
The last field index used by this class

See Also:
Constant Field Values

USE_BIND_MSG

protected static final java.lang.String USE_BIND_MSG
Message when the USE is a bindable

See Also:
Constant Field Values

vfChildren

protected java.util.ArrayList vfChildren
MFNode children NULL


vfBboxCenter

protected float[] vfBboxCenter
SFVec3f bboxCenter NULL


vfBboxSize

protected float[] vfBboxSize
SFVec3f bboxSize NULL


childCount

protected int childCount
The number of children nodes we added, not the total. We don't Add nodes to NR that have no scenegraph object (such as interpolators and timesensors). This count is so that we don't have to enable the ALLOW_CHILDREN_READ on the group (an optimisation step)


hasBindables

protected boolean hasBindables
Flag indicating if this node contains bindable/activatable nodes


shareCount

protected int shareCount
Counter for the number of sharing references this has

Constructor Detail

BaseGroupingNode

protected BaseGroupingNode(java.lang.String name)
Construct a default instance of the grouping node type.

Parameters:
name - The name of the type of node
Method Detail

copy

protected void copy(VRMLGroupingNodeType node)
Set the fields of the grouping node that has the fields set based on the fields of the passed in node. This will not copy any children nodes, only the local fields.

Parameters:
node - The grouping node to copy info from

getBboxCenter

public float[] getBboxCenter()
Accessor method to get current value of field bboxCenter default value is 0 0 0.

Specified by:
getBboxCenter in interface VRMLBoundedNodeType
Returns:
Value of bboxCenter(SFVec3f)

getBboxSize

public float[] getBboxSize()
Accessor method to get current value of field bboxSize default value is -1 -1 -1.

Specified by:
getBboxSize in interface VRMLBoundedNodeType
Returns:
The size of the bounding box(SFVec3f)

getChildren

public VRMLNodeType[] getChildren()
Get the children, provides a live reference not a copy

Specified by:
getChildren in interface VRMLGroupingNodeType
Returns:
An array of VRMLNodeTypes

setChildren

public void setChildren(VRMLNodeType[] newChildren)
Accesor method to set the children field If passed null this method will act like removeChildren

Specified by:
setChildren in interface VRMLGroupingNodeType
Parameters:
newChildren - Array of new children

setChildren

public void setChildren(VRMLNodeType newChild)
Accessor method to set the children field Creates an array containing only newChild If passed null this method will act like removeChildren

Specified by:
setChildren in interface VRMLGroupingNodeType
Parameters:
newChild - The new child

addChild

public void addChild(VRMLNodeType newChild)
Append a new child node to the existing collection. Should be used sparingly. It is really only provided for Proto handling purposes.

Specified by:
addChild in interface VRMLGroupingNodeType
Parameters:
newChild - The new child

getChildrenSize

public int getChildrenSize()
Returns the number of children

Specified by:
getChildrenSize in interface VRMLGroupingNodeType
Returns:
The number of children

containsBindableNodes

public boolean containsBindableNodes()
A check to see if this grouping node contains any bindable nodes. This does a dynamic check of all the children now to see if any of them are bindable.

Specified by:
containsBindableNodes in interface VRMLGroupingNodeType
Returns:
true if this or any of its children contain bindable nodes

isShared

public boolean isShared()
Check to see if this node has been used more than once. If it has then return true.

Specified by:
isShared in interface VRMLGroupingNodeType
Returns:
true if this node is shared

setShared

public void setShared(boolean used)
Adjust the sharing count up or down one increment depending on the flag.

Specified by:
setShared in interface VRMLGroupingNodeType
Parameters:
used - true if this is about to have another reference added

updateRefCount

public void updateRefCount(int layer,
                           boolean add)
Change the reference count up or down by one for a given layer ID. If there is no reference to the given layer ID previously, add one now. A listing of the layer IDs that reference this node can be retrieved through AbstractNode.getLayerIds().

Specified by:
updateRefCount in interface VRMLNodeType
Overrides:
updateRefCount in class AbstractNode
Parameters:
layer - The id of the layer to modify the ref count on
add - true to increment the reference count, false to decrement

setDEF

public void setDEF()
Notify this node that is has been DEFd.

Specified by:
setDEF in interface VRMLNodeType
Overrides:
setDEF in class AbstractNode
Throws:
java.lang.IllegalStateException - The setup is finished.

setupFinished

public void setupFinished()
Notification that the construction phase of this node has finished. This will call setupFinished() on the child nodes. Derived classes that do not like this behaviour should override this method or ensure that the implGroup has a parent before this method is called.

Specified by:
setupFinished in interface VRMLNodeType
Overrides:
setupFinished in class AbstractNode

getPrimaryType

public int getPrimaryType()
Get the primary type of this node. Replaces the instanceof mechanism for use in switch statements.

Specified by:
getPrimaryType in interface VRMLNode
Returns:
The primary type

getFieldValue

public VRMLFieldData getFieldValue(int index)
                            throws InvalidFieldException
Get the value of a field. If the field is a primitive type, it will return a class representing the value. For arrays or nodes it will return the instance directly.

Specified by:
getFieldValue in interface VRMLNodeType
Overrides:
getFieldValue in class AbstractNode
Parameters:
index - The index of the field to change.
Returns:
The class representing the field value
Throws:
InvalidFieldException - The field index is not known

sendRoute

public void sendRoute(double time,
                      int srcIndex,
                      VRMLNodeType destNode,
                      int destIndex)
Send a routed value from this node to the given destination node. The route should use the appropriate setValue() method of the destination node. It should not attempt to cast the node up to a higher level. Routing should also follow the standard rules for the loop breaking and other appropriate rules for the specification.

Specified by:
sendRoute in interface VRMLNodeType
Overrides:
sendRoute in class AbstractNode
Parameters:
time - The time that this route occurred (not necessarily epoch time. Should be treated as a relative value only)
srcIndex - The index of the field in this node that the value should be sent from
destNode - The node reference that we will be sending the value to
destIndex - The index of the field in the destination node that the value should be sent to.

setValue

public void setValue(int index,
                     float[] value,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException,
                     InvalidFieldAccessException
Set the value of the field at the given index as an array of floats. This would be used to set MFFloat, SFVec2f, SFVec3f and SFRotation field types.

Specified by:
setValue in interface VRMLNodeType
Overrides:
setValue in class AbstractNode
Parameters:
index - The index of destination field to set
value - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The field index is not known
InvalidFieldValueException - The value provided is out of range for the field type.
InvalidFieldAccessException - The call is attempting to write to a field that does not permit writing now

setValue

public void setValue(int index,
                     VRMLNodeType child)
              throws InvalidFieldException,
                     InvalidFieldValueException,
                     InvalidFieldAccessException
Set the value of the field at the given index as an array of nodes. This would be used to set MFNode field types.

Specified by:
setValue in interface VRMLNodeType
Overrides:
setValue in class AbstractNode
Parameters:
index - The index of destination field to set
child - The new value to use for the node
Throws:
InvalidFieldException - The field index is not known
InvalidFieldValueException - The value provided is out of range for the field type.
InvalidFieldAccessException - The call is attempting to write to a field that does not permit writing now

setValue

public void setValue(int index,
                     VRMLNodeType[] children,
                     int numValid)
              throws InvalidFieldException,
                     InvalidFieldValueException,
                     InvalidFieldAccessException
Set the value of the field at the given index as an array of nodes. This would be used to set MFNode field types.

Specified by:
setValue in interface VRMLNodeType
Overrides:
setValue in class AbstractNode
Parameters:
index - The index of destination field to set
children - The new value to use for the node
numValid - The number of valid values to copy from the array
Throws:
InvalidFieldException - The field index is not known
InvalidFieldValueException - The value provided is out of range for the field type.
InvalidFieldAccessException - The call is attempting to write to a field that does not permit writing now

clearChildren

protected void clearChildren()
Clear the child node list of all children in the VRML node. Override to provide.renderer-specific behaviour, but remember to also call this implementation too.


addChildNode

protected void addChildNode(VRMLNodeType node)
                     throws InvalidFieldValueException
Add a single child node to the list of available children. Override to provide.renderer-specific behaviour, but remember to also call this implementation too.

Parameters:
node - The node to add
Throws:
InvalidFieldValueException - This is a bindable node shared

removeChildNode

protected void removeChildNode(VRMLNodeType node)
Remove the given node from this grouping node. If the node is not a child of this node, the request is silently ignored.

Parameters:
node - The node to remove

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium