artisynth.core.modelbase
Class ComponentUtils

java.lang.Object
  extended by artisynth.core.modelbase.ComponentUtils

public class ComponentUtils
extends java.lang.Object


Field Summary
static char componentPropertySeparator
           
 
Constructor Summary
ComponentUtils()
           
 
Method Summary
static void addComponents(java.util.List<? extends ModelComponent> list, int[] indices, java.util.List<MutableCompositeComponent<?>> parents)
           
static void addComponents(java.util.List<? extends ModelComponent> list, int[] indices, java.util.List<MutableCompositeComponent<?>> parents, boolean reverse)
           
static void addComponents(java.util.List<? extends ModelComponent> list, int[] indices, MutableCompositeComponent<?> parent)
           
static void addComponentsInReverse(java.util.List<? extends ModelComponent> list, int[] indices, java.util.List<MutableCompositeComponent<?>> parents)
           
static boolean addCopyComponents(java.util.List<ModelComponent> list, ModelComponent comp)
           
static boolean addCopyReferences(java.util.List<ModelComponent> list, ModelComponent comp, ModelComponent ancestor)
           
static java.util.HashMap<ModelComponent,artisynth.core.modelbase.ComponentUtils.Dependencies> buildDependencyMap(CompositeComponent comp)
           
static CompositeComponent castRefToAncestor(java.lang.Object ref)
           
static void checkReferenceContainment(ModelComponent comp)
           
static ModelComponent findCommonAncestor(java.util.List<? extends ModelComponent> comps)
          Returns the common ancestor, if any, for a list of model components.
static ModelComponent findCommonAncestor(ModelComponent comp1, ModelComponent comp2)
          Returns the common ancestor, if any, for two model components.
static ModelComponent findComponent(ModelComponent comp, java.lang.String path)
           
static java.lang.Object findComponentOrProperty(ModelComponent comp, java.lang.String path)
           
static java.util.LinkedList<ModelComponent> findCopyComponents(java.util.List<ModelComponent> comps)
           
static java.util.LinkedList<ModelComponent> findDependentComponents(java.util.List<ModelComponent> update, java.util.List<? extends ModelComponent> comps)
           
static java.util.LinkedList<ModelComponent> findDependentComponentsOld(java.util.List<ModelComponent> update, java.util.List<? extends ModelComponent> comps)
           
static Property findProperty(ModelComponent comp, java.lang.String path)
           
static int getDepth(ModelComponent comp)
          Returns the depth of a component within the component hierarchy.
static java.lang.String getDiagnosticName(ModelComponent comp)
          Returns name information for a model comonent suitable for diagnistic printing.
static CompositeComponent getGrandParent(ModelComponent comp)
           
static java.lang.String getPathName(ModelComponent comp)
           
static java.lang.String getPathName(ModelComponent ancestor, ModelComponent comp)
           
static java.lang.String getPathName(ModelComponent reference, ModelComponent target, boolean compact)
          Returns a path name from a reference component to a target component.
static ModelComponent getPropertyComponent(Property prop)
          Returns the ModelComponent, if any, associated with a given property.
static java.lang.String getPropertyPathName(Property prop)
           
static java.lang.String getPropertyPathName(Property prop, ModelComponent topAncestor, boolean excludeLeaf)
           
static java.lang.String getWritePathName(CompositeComponent ancestor, ModelComponent comp)
           
static java.lang.String getWritePropertyPathName(Property prop, ModelComponent topAncestor)
           
static boolean haveCommonAncestor(ModelComponent comp1, ModelComponent comp2)
          Returns true if two components have a common ancestor.
static boolean isAncestorOf(ModelComponent comp0, ModelComponent comp1)
          Returns true if comp0 is an ancestor of comp1.
static boolean isAncestorSelected(ModelComponent comp)
           
static boolean isConnected(ModelComponent comp1, ModelComponent comp2)
          Returns true if comp2 is connected to the same component hierarchy as comp1.
static ModelComponent loadComponent(java.io.File file, CompositeComponent ancestor, java.lang.Class<?> expectedType)
           
static ModelComponent maybeCopy(int flags, java.util.Map<ModelComponent,ModelComponent> copyMap, CopyableComponent c)
           
static ModelComponent maybeGetCopy(int flags, java.util.Map<ModelComponent,ModelComponent> copyMap, CopyableComponent c)
           
static CompositeComponent nearestEncapsulatingAncestor(ModelComponent c)
          Returns the closest ancestor of a component (or the component itself) for which hierarchyContainsDependencies() returns true.
static java.util.ArrayList<Property> parseProperties(java.util.Deque<ScanToken> tokens, CompositeComponent ancestor)
           
static Property parseProperty(java.lang.Object obj, CompositeComponent ancestor)
           
static void recursivelyBuildDependencyMap(java.util.HashMap<ModelComponent,artisynth.core.modelbase.ComponentUtils.Dependencies> map, ModelComponent c)
           
static
<E extends ModelComponent>
void
recursivelyFindComponents(java.lang.Class<E> clazz, CompositeComponent comp, java.util.List<E> out)
           
static boolean referencesContained(CompositeComponent ancestor, ModelComponent comp)
          Returns true if all references associated with a component are recursively contained beneath a specified ancestor.
static java.util.LinkedList<MutableCompositeComponent<?>> removeComponents(java.util.List<? extends ModelComponent> list, int[] indices)
           
static void saveComponent(java.io.File file, ModelComponent comp, NumberFormat fmt, ModelComponent ancestor)
           
static void testPaths(CompositeComponent comp)
          Used for debugging.
static
<C extends ModelComponent>
void
updateReferences(ModelComponent c, java.util.List<C> refs, boolean undo, java.util.Deque<java.lang.Object> undoInfo)
           
static boolean withinHierarchy(ModelComponent comp, ModelComponent ancestor)
          Returns true if a component is equal to, or is a descendant of a particular ancestor component.
static boolean withinHierarchy(ModelComponent comp, TransformableGeometry topObject)
          Returns true if a component is equal to, or is a descendant of a particular object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

componentPropertySeparator

public static final char componentPropertySeparator
See Also:
Constant Field Values
Constructor Detail

ComponentUtils

public ComponentUtils()
Method Detail

findDependentComponents

public static java.util.LinkedList<ModelComponent> findDependentComponents(java.util.List<ModelComponent> update,
                                                                           java.util.List<? extends ModelComponent> comps)

findDependentComponentsOld

public static java.util.LinkedList<ModelComponent> findDependentComponentsOld(java.util.List<ModelComponent> update,
                                                                              java.util.List<? extends ModelComponent> comps)

removeComponents

public static java.util.LinkedList<MutableCompositeComponent<?>> removeComponents(java.util.List<? extends ModelComponent> list,
                                                                                  int[] indices)

isAncestorSelected

public static boolean isAncestorSelected(ModelComponent comp)

addComponents

public static void addComponents(java.util.List<? extends ModelComponent> list,
                                 int[] indices,
                                 java.util.List<MutableCompositeComponent<?>> parents)

addComponentsInReverse

public static void addComponentsInReverse(java.util.List<? extends ModelComponent> list,
                                          int[] indices,
                                          java.util.List<MutableCompositeComponent<?>> parents)

addComponents

public static void addComponents(java.util.List<? extends ModelComponent> list,
                                 int[] indices,
                                 MutableCompositeComponent<?> parent)

addComponents

public static void addComponents(java.util.List<? extends ModelComponent> list,
                                 int[] indices,
                                 java.util.List<MutableCompositeComponent<?>> parents,
                                 boolean reverse)

withinHierarchy

public static boolean withinHierarchy(ModelComponent comp,
                                      ModelComponent ancestor)
Returns true if a component is equal to, or is a descendant of a particular ancestor component.

Parameters:
comp - component to check
ancestor - ancestor component
Returns:
true if comp is contained within the hierarchy rooted at ancestor

withinHierarchy

public static boolean withinHierarchy(ModelComponent comp,
                                      TransformableGeometry topObject)
Returns true if a component is equal to, or is a descendant of a particular object. If the object is not a ModelComponent, this method returns false.

Parameters:
comp - component to check
topObject - candidate ancestor component
Returns:
true if topObject is a ModelComponent and contains comp within its hierarchy

addCopyComponents

public static boolean addCopyComponents(java.util.List<ModelComponent> list,
                                        ModelComponent comp)

findCopyComponents

public static java.util.LinkedList<ModelComponent> findCopyComponents(java.util.List<ModelComponent> comps)

addCopyReferences

public static boolean addCopyReferences(java.util.List<ModelComponent> list,
                                        ModelComponent comp,
                                        ModelComponent ancestor)

getDepth

public static int getDepth(ModelComponent comp)
Returns the depth of a component within the component hierarchy. This equals the number of ancestor components, so a component with no parent would have a depth of 0, a component whose parent is the root would have a depth of 1, etc.


haveCommonAncestor

public static boolean haveCommonAncestor(ModelComponent comp1,
                                         ModelComponent comp2)
Returns true if two components have a common ancestor.


isConnected

public static boolean isConnected(ModelComponent comp1,
                                  ModelComponent comp2)
Returns true if comp2 is connected to the same component hierarchy as comp1.


findCommonAncestor

public static ModelComponent findCommonAncestor(ModelComponent comp1,
                                                ModelComponent comp2)
Returns the common ancestor, if any, for two model components. If there is no common ancestor, returns null. If the components are the same, then the (first) component is returned. If one component is an ancestor of the other, then that component is returned.


findCommonAncestor

public static ModelComponent findCommonAncestor(java.util.List<? extends ModelComponent> comps)
Returns the common ancestor, if any, for a list of model components. If there is no common ancestor, returns null.


isAncestorOf

public static boolean isAncestorOf(ModelComponent comp0,
                                   ModelComponent comp1)
Returns true if comp0 is an ancestor of comp1. If comp0 is not an ancestor of comp1, or if it equals comp1, then the method returns false.


referencesContained

public static boolean referencesContained(CompositeComponent ancestor,
                                          ModelComponent comp)
Returns true if all references associated with a component are recursively contained beneath a specified ancestor.

Parameters:
ancestor - ancestor component beneath which reference should be contained
comp - component whose references should be checked
Returns:
true if all references are recursively contained below the specified ancestor

getDiagnosticName

public static java.lang.String getDiagnosticName(ModelComponent comp)
Returns name information for a model comonent suitable for diagnistic printing.


checkReferenceContainment

public static void checkReferenceContainment(ModelComponent comp)

nearestEncapsulatingAncestor

public static CompositeComponent nearestEncapsulatingAncestor(ModelComponent c)
Returns the closest ancestor of a component (or the component itself) for which hierarchyContainsDependencies() returns true. That means all inter-component references are contained within the ancestor's hierarchy. If no such ancestor is found, null is returned.

Returns:
closest encapsulated ancestor

saveComponent

public static void saveComponent(java.io.File file,
                                 ModelComponent comp,
                                 NumberFormat fmt,
                                 ModelComponent ancestor)
                          throws java.io.IOException
Throws:
java.io.IOException

loadComponent

public static ModelComponent loadComponent(java.io.File file,
                                           CompositeComponent ancestor,
                                           java.lang.Class<?> expectedType)
                                    throws java.io.IOException
Throws:
java.io.IOException

getPropertyComponent

public static ModelComponent getPropertyComponent(Property prop)
Returns the ModelComponent, if any, associated with a given property.

Parameters:
prop - property to be queried
Returns:
model component associated with the property

findComponent

public static ModelComponent findComponent(ModelComponent comp,
                                           java.lang.String path)

findProperty

public static Property findProperty(ModelComponent comp,
                                    java.lang.String path)

findComponentOrProperty

public static java.lang.Object findComponentOrProperty(ModelComponent comp,
                                                       java.lang.String path)

parseProperty

public static Property parseProperty(java.lang.Object obj,
                                     CompositeComponent ancestor)
                              throws java.io.IOException
Throws:
java.io.IOException

parseProperties

public static java.util.ArrayList<Property> parseProperties(java.util.Deque<ScanToken> tokens,
                                                            CompositeComponent ancestor)
                                                     throws java.io.IOException
Throws:
java.io.IOException

getPathName

public static java.lang.String getPathName(ModelComponent comp)

getPathName

public static java.lang.String getPathName(ModelComponent ancestor,
                                           ModelComponent comp)

getPathName

public static java.lang.String getPathName(ModelComponent reference,
                                           ModelComponent target,
                                           boolean compact)
Returns a path name from a reference component to a target component. The reference does not need to be an ancestor of the target.


getWritePropertyPathName

public static java.lang.String getWritePropertyPathName(Property prop,
                                                        ModelComponent topAncestor)

getPropertyPathName

public static java.lang.String getPropertyPathName(Property prop,
                                                   ModelComponent topAncestor,
                                                   boolean excludeLeaf)

getPropertyPathName

public static java.lang.String getPropertyPathName(Property prop)

getGrandParent

public static CompositeComponent getGrandParent(ModelComponent comp)

maybeGetCopy

public static ModelComponent maybeGetCopy(int flags,
                                          java.util.Map<ModelComponent,ModelComponent> copyMap,
                                          CopyableComponent c)

maybeCopy

public static ModelComponent maybeCopy(int flags,
                                       java.util.Map<ModelComponent,ModelComponent> copyMap,
                                       CopyableComponent c)

recursivelyFindComponents

public static <E extends ModelComponent> void recursivelyFindComponents(java.lang.Class<E> clazz,
                                                                        CompositeComponent comp,
                                                                        java.util.List<E> out)

getWritePathName

public static java.lang.String getWritePathName(CompositeComponent ancestor,
                                                ModelComponent comp)

testPaths

public static void testPaths(CompositeComponent comp)
Used for debugging. Recursively make sure that every descendent component of this CompositeComponent has a valid path name.


castRefToAncestor

public static CompositeComponent castRefToAncestor(java.lang.Object ref)
                                            throws java.io.IOException
Throws:
java.io.IOException

recursivelyBuildDependencyMap

public static void recursivelyBuildDependencyMap(java.util.HashMap<ModelComponent,artisynth.core.modelbase.ComponentUtils.Dependencies> map,
                                                 ModelComponent c)

buildDependencyMap

public static java.util.HashMap<ModelComponent,artisynth.core.modelbase.ComponentUtils.Dependencies> buildDependencyMap(CompositeComponent comp)

updateReferences

public static <C extends ModelComponent> void updateReferences(ModelComponent c,
                                                               java.util.List<C> refs,
                                                               boolean undo,
                                                               java.util.Deque<java.lang.Object> undoInfo)