artisynth.core.modelbase
Class ModelComponentBase

java.lang.Object
  extended by artisynth.core.modelbase.ModelComponentBase
All Implemented Interfaces:
ModelComponent, java.lang.Cloneable, HasProperties, HierarchyNode, Scannable
Direct Known Subclasses:
Collidable.DefaultCollidable, CollisionComponent, ComponentList, CompositeComponentBase, ControlPanel, DynamicAttachment, FrameExciter, ModelAgentBase, MuscleExciter, PointExciter, PointForce, ReferenceComponent, RenderableComponentBase, Spring

public abstract class ModelComponentBase
extends java.lang.Object
implements ModelComponent, java.lang.Cloneable

Base class providing some default implementations of the ModelComponent interface.


Nested Class Summary
 
Nested classes/interfaces inherited from interface artisynth.core.modelbase.ModelComponent
ModelComponent.NavpanelVisibility
 
Field Summary
static boolean enforceUniqueCompositeNames
           
static boolean enforceUniqueNames
           
 int myNumber
           
static PropertyList myProps
           
static java.lang.Object NULL_OBJ
           
static boolean useCompactPathNames
           
 
Constructor Summary
ModelComponentBase()
           
ModelComponentBase(java.lang.String name)
           
 
Method Summary
 boolean checkFlag(int mask)
           
static java.lang.String checkName(java.lang.String name, ModelComponent comp)
          Check to see if a String represents a valid name for a model component.
static void checkNameUniqueness(ModelComponent comp, CompositeComponent parent)
          Check name uniqueness restrictions of a component with respect to a specific parent, and throw an exception if these are violated.
 void clearFlag(int mask)
           
 java.lang.Object clone()
           
 void connectToHierarchy()
          Called by the system after this component is added to the component hierarchy (i.e., when it is added as a child of another CompositeComponent).
 ModelComponent copy(int flags, java.util.Map<ModelComponent,ModelComponent> copyMap)
           
static int createTempFlag()
           
 void disconnectFromHierarchy()
          Called by the system after this component is removed from the component hierarchy (i.e., when it is removed as a child of its parent).
 PropertyList getAllPropertyInfo()
          Returns a list giving static information about all properties exported by this object.
 java.util.Iterator<? extends HierarchyNode> getChildren()
           
 CompositeComponent getGrandParent()
           
 void getHardReferences(java.util.List<ModelComponent> refs)
          Appends all hard references for this component to a list.
 java.lang.String getName()
          Gets the name of this component.
 Range getNameRange()
           
 ModelComponent.NavpanelVisibility getNavpanelVisibility()
           
static ModelComponent.NavpanelVisibility getNavpanelVisibility(int flags)
           
 int getNumber()
          Gets the number of this component.
 CompositeComponent getParent()
          Returns the current parent of this ModelComponent, if any.
 Property getProperty(java.lang.String path)
          Returns a property associated with a specified path name.
 void getSoftReferences(java.util.List<ModelComponent> refs)
          Appends all soft references for this component to a list.
 boolean hasChildren()
           
 boolean hasState()
          Returns true if this component has state.
 boolean isFixed()
          Returns true if this model component is fixed.
 boolean isMarked()
          Returns true if this model component is marked.
 boolean isSelected()
          Returns true if this model component is selected.
 boolean isWritable()
          Returns true if this component should in fact be written to secondary storage.
static java.lang.String makeValidName(java.lang.String name)
          Makes a valid component name from the string provided.
static java.lang.String makeValidName(java.lang.String name, ModelComponent comp, CompositeComponent parent)
          Makes a valid component name from the string provided.
 void notifyParentOfChange(ComponentChangeEvent e)
          Notifies the parent of this component (if any) of changes within in its descendants.
 void postscan(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor)
          Performs any required post-scanning for this component.
 void printReferences()
          Diagnostic method that prints the references associated with this component.
static boolean recursivelyContained(ModelComponent comp, CompositeComponent ancestor, java.util.Collection<? extends ModelComponent> collection)
           
static boolean recursivelyContains(CompositeComponent ancestor, ModelComponent comp)
          Returns true if a component is a descendant of a specified ancestor.
static void removeTempFlag(int mask)
           
 void scan(ReaderTokenizer rtok, java.lang.Object ref)
          Scans this element from a ReaderTokenizer.
 void setFixed(boolean fixed)
          Fixes or unfixes this component.
 void setFlag(int mask)
           
 void setMarked(boolean marked)
          Marks or unmarks this component.
 void setName(java.lang.String name)
          Sets the name of this component.
 void setNavpanelVisibility(ModelComponent.NavpanelVisibility visibility)
           
static int setNavpanelVisibility(ModelComponent.NavpanelVisibility visibility, int flags)
           
 void setNumber(int num)
          Sets the number of this component.
 void setParent(CompositeComponent parent)
          Sets the parent for this component.
 void setSelected(boolean selected)
          Selects or deselects this component.
 void updateReferences(boolean undo, java.util.Deque<java.lang.Object> undoInfo)
          May be called by the system if any of the soft references for this component are removed from the the component hierarchy.
 void write(java.io.PrintWriter pw, NumberFormat fmt, java.lang.Object ref)
          Writes a text description of this element to a PrintWriter.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myNumber

public int myNumber

NULL_OBJ

public static final java.lang.Object NULL_OBJ

enforceUniqueNames

public static boolean enforceUniqueNames

enforceUniqueCompositeNames

public static boolean enforceUniqueCompositeNames

useCompactPathNames

public static boolean useCompactPathNames

myProps

public static PropertyList myProps
Constructor Detail

ModelComponentBase

public ModelComponentBase(java.lang.String name)

ModelComponentBase

public ModelComponentBase()
Method Detail

createTempFlag

public static int createTempFlag()

removeTempFlag

public static void removeTempFlag(int mask)

getAllPropertyInfo

public PropertyList getAllPropertyInfo()
Description copied from interface: HasProperties
Returns a list giving static information about all properties exported by this object.

Specified by:
getAllPropertyInfo in interface HasProperties
Returns:
static information for all exported properties

getProperty

public Property getProperty(java.lang.String path)
Returns a property associated with a specified path name. All properties exported by this object must have a name which is a valid Java identifier. Specifying one of these names causes the corresponding Property to be returned. Handles to sub-properties can also be obtained by delimiting the sub-property name(s) by '.' characters. A sub-property exists if the value of a property is itself an object which exports properties. It is only possible to obtain a sub-property handle if each of its ancestor properties exports their values by reference.

Specified by:
getProperty in interface HasProperties
Parameters:
path - name of the desired property or sub-property
Returns:
handle to the property

getName

public java.lang.String getName()
Gets the name of this component.

Specified by:
getName in interface ModelComponent
Returns:
name of this component

setName

public void setName(java.lang.String name)
Sets the name of this component. When the name is set, this method should call notifyParentOfChange with a NameChangeEvent so that it's parent can update the name map entry and other ancestors can adjust for the new name.

Component names can be specified as null. However, if not null, they should have non-zero length and should not begin with a digit or contain the characters '.' or '/'. Implementations can use ModelComponentBase.checkName() to determine if a proposed name is valid.

Specified by:
setName in interface ModelComponent
Parameters:
name - new component name

getNameRange

public Range getNameRange()

write

public void write(java.io.PrintWriter pw,
                  NumberFormat fmt,
                  java.lang.Object ref)
           throws java.io.IOException
Writes a text description of this element to a PrintWriter. The text description should be compatable with scan and complete enough to allow full reconstruction of the element.

Specified by:
write in interface Scannable
Parameters:
pw - stream for writing the element
fmt - numeric formating information
ref - optional reference object which can be used for producing references to other objects
Throws:
java.io.IOException - if an I/O error occured

isWritable

public boolean isWritable()
Returns true if this component should in fact be written to secondary storage. This gives subclasses control over whether or not they are actually written out.

Specified by:
isWritable in interface Scannable
Returns:
true if this component should be written to secondary storage.

scan

public void scan(ReaderTokenizer rtok,
                 java.lang.Object ref)
          throws java.io.IOException
Scans this element from a ReaderTokenizer. The expected text format is assumed to be compatible with that produced by write.

Specified by:
scan in interface ModelComponent
Specified by:
scan in interface Scannable
Parameters:
rtok - Tokenizer from which to scan the element
ref - optional reference object which can be used for resolving references to other objects
Throws:
java.io.IOException - if an I/O or formatting error occured

postscan

public void postscan(java.util.Deque<ScanToken> tokens,
                     CompositeComponent ancestor)
              throws java.io.IOException
Description copied from interface: ModelComponent
Performs any required post-scanning for this component. This involves handling any information whose processing was deferred during the scan() method and stored in the token queue. The most common use of this method is to resolve the paths of component references, which may not have been created at the time of the initial scan() call.

Specified by:
postscan in interface ModelComponent
Parameters:
tokens - token information that was stored during scan().
ancestor - ancestor component with respect to which reference component paths are defined.
Throws:
java.io.IOException

connectToHierarchy

public void connectToHierarchy()
Called by the system after this component is added to the component hierarchy (i.e., when it is added as a child of another CompositeComponent). This method is responsible for doing any required hierarchy-dependent initialization.

When this method is called, ModelComponent.getParent() will return the new parent component; the system will have set this beforehand.

Specified by:
connectToHierarchy in interface ModelComponent

disconnectFromHierarchy

public void disconnectFromHierarchy()
Called by the system after this component is removed from the component hierarchy (i.e., when it is removed as a child of its parent). This method is responsible for any required hierarchy-dependent deinitialization.

When this method is called, ModelComponent.getParent() will still return this original parent component; the system will set this to null after.

Specified by:
disconnectFromHierarchy in interface ModelComponent

getParent

public CompositeComponent getParent()
Returns the current parent of this ModelComponent, if any.

Specified by:
getParent in interface ModelComponent
Specified by:
getParent in interface HierarchyNode
Returns:
parent of this ModelComponent

setParent

public void setParent(CompositeComponent parent)
Sets the parent for this component. A value of null is specified when the component is being removed from the hierarchy.

This method is intended for internal use by the system only.

Specified by:
setParent in interface ModelComponent
Parameters:
parent - new parent component, or null.

getGrandParent

public CompositeComponent getGrandParent()

isSelected

public boolean isSelected()
Returns true if this model component is selected.

Specified by:
isSelected in interface ModelComponent
Returns:
true if this component is selected

setSelected

public void setSelected(boolean selected)
Selects or deselects this component. This method should only be used by the selection manager, since object selection must be coordinated with other system components.

Specified by:
setSelected in interface ModelComponent
Parameters:
selected - if true, this component is selected

isMarked

public boolean isMarked()
Returns true if this model component is marked. Marking is used temporarily for applications such as determining which components which are referenced by a set of components.

Specified by:
isMarked in interface ModelComponent
Returns:
true if this component is marked

setMarked

public void setMarked(boolean marked)
Marks or unmarks this component.

Specified by:
setMarked in interface ModelComponent
Parameters:
marked - if true, this component is marked

isFixed

public boolean isFixed()
Returns true if this model component is fixed. Fixed is used to indicate that the component should not be removed from its parent.

Specified by:
isFixed in interface ModelComponent
Returns:
true if this component is fixed

setFixed

public void setFixed(boolean fixed)
Fixes or unfixes this component. This method should be used with care, and only be component designers.

Specified by:
setFixed in interface ModelComponent
Parameters:
fixed - if true, this component will be fixed to its parent.

setNavpanelVisibility

public static int setNavpanelVisibility(ModelComponent.NavpanelVisibility visibility,
                                        int flags)

getNavpanelVisibility

public static ModelComponent.NavpanelVisibility getNavpanelVisibility(int flags)

getNavpanelVisibility

public ModelComponent.NavpanelVisibility getNavpanelVisibility()
Specified by:
getNavpanelVisibility in interface ModelComponent

setNavpanelVisibility

public void setNavpanelVisibility(ModelComponent.NavpanelVisibility visibility)

checkFlag

public boolean checkFlag(int mask)

setFlag

public void setFlag(int mask)

clearFlag

public void clearFlag(int mask)

getHardReferences

public void getHardReferences(java.util.List<ModelComponent> refs)
Appends all hard references for this component to a list. References are other components, outside of this component's immediate ancestry, on which this component depends. For example, an AxialSpring refers to two Point components as for it's end points. A hard reference is one which the referring component must have, and which if deleted, implies that the referring component should be deleted too.

Specified by:
getHardReferences in interface ModelComponent
Parameters:
refs - list to which hard references are appended

getSoftReferences

public void getSoftReferences(java.util.List<ModelComponent> refs)
Appends all soft references for this component to a list. References are other components, outside of this component's immediate ancestry, on which this component depends. For example, an ExcitationComponent may refer to one or more other ExcitationComponents to act as excitation sources. A soft reference is one which can be removed from the referring component. In particular, if any soft references for a component are deleted, then that component's updateReferences() method will be called to update its internal reference information.

Specified by:
getSoftReferences in interface ModelComponent
Parameters:
refs - list to which soft references are appended

recursivelyContains

public static boolean recursivelyContains(CompositeComponent ancestor,
                                          ModelComponent comp)
Returns true if a component is a descendant of a specified ancestor. If the component is not a descendant of the ancestor, or if the component and the ancestor are equal, the method returns false.

Parameters:
ancestor - ancestor component to check
comp - component to check for descendence from ancestor

recursivelyContained

public static boolean recursivelyContained(ModelComponent comp,
                                           CompositeComponent ancestor,
                                           java.util.Collection<? extends ModelComponent> collection)

getNumber

public int getNumber()
Gets the number of this component. A unique component number is assigned whenever a component is made a child of a parent component, and this number will be persistent as long as the component remains a child that parent. In particular, cmponent numbers are not indices, and will not change as other components are added or removed from the parent. The purpose of the component number is to provide a alternate name for a component in case the string name is not set.

Specified by:
getNumber in interface ModelComponent
Returns:
number of this component

setNumber

public void setNumber(int num)
Sets the number of this component. This method should only be called by parent components when they add or remove this component as a child.

Specified by:
setNumber in interface ModelComponent
Parameters:
num - new component number

notifyParentOfChange

public void notifyParentOfChange(ComponentChangeEvent e)
Notifies the parent of this component (if any) of changes within in its descendants. This is done by calling the parent's componentChanged method.

Specified by:
notifyParentOfChange in interface ModelComponent
Parameters:
e - optional argument giving specific information about the change

getChildren

public java.util.Iterator<? extends HierarchyNode> getChildren()
Specified by:
getChildren in interface HierarchyNode

hasChildren

public boolean hasChildren()
Specified by:
hasChildren in interface HierarchyNode

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

copy

public ModelComponent copy(int flags,
                           java.util.Map<ModelComponent,ModelComponent> copyMap)

printReferences

public void printReferences()
Diagnostic method that prints the references associated with this component.


makeValidName

public static java.lang.String makeValidName(java.lang.String name,
                                             ModelComponent comp,
                                             CompositeComponent parent)
Makes a valid component name from the string provided. If comp (and possibly parent) is also specified, then the method will also ensure that the name is unique to the component's parent.

Parameters:
name - name to validate
comp - Component for which the name is intended. If null, name uniqueness will not be checked.
parent - Parent of the component. May be null, in which case the component's current parent will be used.

makeValidName

public static java.lang.String makeValidName(java.lang.String name)
Makes a valid component name from the string provided. Does not check uniqueness with respect to the component's parent.

Parameters:
name - name to modify

checkNameUniqueness

public static void checkNameUniqueness(ModelComponent comp,
                                       CompositeComponent parent)
Check name uniqueness restrictions of a component with respect to a specific parent, and throw an exception if these are violated. These restrictions will depend on static settings in ModelComponentBase.

Parameters:
comp - component whose name should be checked
parent - parent component in which name may have to be unique.

checkName

public static java.lang.String checkName(java.lang.String name,
                                         ModelComponent comp)
Check to see if a String represents a valid name for a model component. Returns null if it is, and an error message otherwise.

Parameters:
name - name to be validated
comp - Component for which the name is intended. May be null, in which case duplicate sibling names will not be checked.
Returns:
null, or error message if the name is not valid.

hasState

public boolean hasState()
Description copied from interface: ModelComponent
Returns true if this component has state. Structure change events involving components that have state will cause the current state history of of the system to be cleared.

Specified by:
hasState in interface ModelComponent

updateReferences

public void updateReferences(boolean undo,
                             java.util.Deque<java.lang.Object> undoInfo)
May be called by the system if any of the soft references for this component are removed from the the component hierarchy. If called with undo equal to false, this component should then examine its soft references and use ComponentUtils.isConnected() to determine which of them have been disconnected from the hierarchy. Disconnected references should be removed, and sufficient information should be appended to undoInfo to allow this update to be undone if this method is called later with undo equal to true. When undoing an update, the undo information should be removed from the front of undoInfo.

Specified by:
updateReferences in interface ModelComponent
Parameters:
undo - if true, indicates that the most recent reference update should be undone, using the supplied undo information.
undoInfo - if undo is false, should be used to store information allowing the reference update to be undone. Otherwise, if undo is true, then this supplied information to undo the most recent update.