Class SoSearchPathAction


  • public class SoSearchPathAction
    extends SoSearchAction
    Searches for a node in a scene graph using a sequence of search criteria. This class extends SoSearchAction to search for a sequence of items defined in a string, e.g., "Wheel1/Hub/Bearing". Each item can be a

    • Node name, or
    • Node type (type name in angle brackets, e.g., "<Cone>").

    When the action finds a node that satisfies the current search item, it effectively restarts the search from that node, using the next search item. This means that the search for each item (after the first) is confined to the subgraph under the node that satisfied the previous search item. In most cases each item (except possibly the last one) will be a grouping node, but this is not enforced by the action.

    Finding nodes by name is a useful technique for modifying a scene graph, but using SoNode.getByName or SoSearchAction requires assigning a unique name to every (interesting) node. Often the same subgraph will be used multiple times and it would be convenient to assign each instance of the subgraph a unique name, but reuse the same names for the nodes inside the subgraph. SoSearchPathAction allows this kind of hierarchical naming.

    Given a scene graph with hierarchical names, for example:

      DEF Wheel1 Separator {
          DEF Hub Separator {
              DEF Bolt Separator {
                  Cylinder { height 3 }
              }
          }
      }
      DEF Wheel2 Separator {
          DEF Hub Separator {
              DEF Bolt Separator {
                  Cylinder { height 13 }
              }
          }
      }

    "Wheel1/Hub/Bolt" would find "Bolt" in the first wheel. Intermediate names may be omitted if the search string is still unambiguous. For example "Wheel1/Bolt" would find the same node in this simple case. "Wheel2/Hub/Bolt/<Cylinder>" would return a path including the leaf SoCylinder node in the second wheel.

    Most of the methods inherited from SoSearchAction are ignored and do not return useful information (set/getNode, set/getName, etc.). Relevant inherited methods are set/isSearchingAll, getPath, and reset.

    Note that by default nodekits do not search their children when a search action is applied. The reference page for SoBaseKit discusses the methods SoBaseKit.isSearchingChildren() and SoBaseKit.setSearchingChildren(), which allow you to query and control this behavior.

    See Also:
    SoPath, SoSearchAction, SoSearchStepAction, SoBaseKit
    • Constructor Detail

      • SoSearchPathAction

        public SoSearchPathAction()
        Constructor. The default action searches for first node of or derived from given type, using regular traversal rules.
    • Method Detail

      • setSearchString

        public void setSearchString​(java.lang.String searchString)
        Sets the search path string.
      • getNumItemsFound

        public int getNumItemsFound()
        Get the number of search items that were successfully found. If the complete search succeeded and a path was returned, then this will be the total number of search items (not in general the same as the number of nodes in the returned path!). If the search failed, this indicates which search item was the problem.
      • getSearchString

        public java.lang.String getSearchString()
        Gets the search path string.
      • getDerivedIsOK

        public boolean getDerivedIsOK()
        Gets flag to allow search on a type to match derived types.
      • enableElement

        public static void enableElement​(java.lang.Class<? extends Inventor> t,
                                         int stkIndex)
      • setSeparatorChar

        public void setSeparatorChar​(byte sepChar)
        Sets separator char for search string. The default is '/'.
      • getSeparatorChar

        public byte getSeparatorChar()
        Gets separator char for search string.
      • setDerivedIsOK

        public void setDerivedIsOK​(boolean derivedIsOK)
        Sets flag to allow search on a type to match derived types.