Class SoDataSensor

  • Direct Known Subclasses:
    SoFieldSensor, SoNodeSensor, SoPathSensor

    public class SoDataSensor
    extends SoDelayQueueSensor
    Abstract base class for sensors attached to parts of a scene. Data sensors detect changes to scene graph objects (paths, nodes, or fields) and trigger their callback when the object changes. The Open Inventor viewer classes, for example, attach an SoNodeSensor to the root of the application's scene graph in order to know when any part of the scene graph has been modified and a redraw is needed.

    Data sensors provide methods that can be called in the callback to determine exactly which node or field caused the sensor to be triggered. However these methods only return valid information if the sensor priority was explicitly set to zero (default is 100). Depending on the type of attached object, there are multiple possible triggers and only some of the get trigger info methods will return useful information.

    Priority zero data sensors are triggered immediately after the change. Normal priority sensors are not triggered until the next time the "delay queue" is processed. Normally this happens when the viewer / renderArea is not rendering and there are no input events to be processed.

    A data sensor will be triggered if its schedule() method is called. But the trigger node, trigger field, etc. queries will return null. Generally this method is only useful for "at some future time" sensors like SoIdleSensor or SoAlarmSensor.

    Data sensors provide a "final" task that is called when the object the data sensor is attached to is finalized. This task should not attempt to modify the object in any way. (see setFinalTask(Runnable)) that is called just before the object the data sensor is attached to is destroyed. The callback should not attempt to modify the object in any way.

    EXAMPLE

    Create a node sensor to detect when the camera has been modified.

     SoCamera camera = viewer.getArea().getCamera();
     SoNodeSensor nodeSensor = new SoNodeSensor();
     nodeSensor.setTask(      new nodeChangedCB(nodeSensor) );
     nodeSensor.setFinalTask( new nodeDestroyedCB(nodeSensor) );
     nodeSensor.setPriority( 0 );
     nodeSensor.attach( camera );

    Method called when the object is modified.

     class nodeChangedCB implements Runnable {
         private SoNodeSensor m_nodeSensor = null;
         public nodeChangedCB( SoNodeSensor sensor ) {
             m_nodeSensor = sensor;
         }
         public void run() {
             SoNode node = m_nodeSensor.getAttachedNode();
             System.out.println( "Node changed: " + node.getClass().getSimpleName() );
             if (m_nodeSensor.getPriority() == 0) {
                 SoField field = m_nodeSensor.getTriggerField();
                 String fieldName = node.getFieldName( field );
                 System.out.println( "     Field: " + fieldName );
             }
         }
     }
     
     class nodeDestroyedCB implements Runnable {
         private SoNodeSensor m_nodeSensor = null;
         public nodeDestroyedCB( SoNodeSensor sensor ) {
             m_nodeSensor = sensor;
         }
         public void run() {
             if (m_nodeSensor != null) {
                 SoNode node = m_nodeSensor.getAttachedNode();
                 System.out.println( "Node destroyed: " + node.getClass().getSimpleName() );
             }
         }
     }

    See Also:
    SoNodeSensor, SoPathSensor, SoFieldSensor, SoDelayQueueSensor
    • Method Detail

      • setFinalTask

        @Deprecated(since="10.1")
        public void setFinalTask​(java.lang.Runnable task)
        Deprecated.
        As of Open Inventor 10.1, useless method: use ReferenceQueue Java API instead.
        Sets the task to be executed when the object the sensor is sensing is finalized. Execute the task means simply call its run method.
      • getTriggerFastEditInfo

        public int getTriggerFastEditInfo()
        Returns true if the triggered changes come from a field or node that was below a Separator with a fastEditPolicy field with a value different than OFF.

        Since:
        Open Inventor 9.2.3

      • getTriggerField

        public SoField getTriggerField()
        If this is a priority 0 data sensor, returns the field that was modified that caused this sensor to trigger. Returns NULL if the sensor was not triggered because a field changed (for example, if schedule() is called on the sensor) or if this sensor is not a priority 0 sensor. Note that because one change to the scene graph may cause multiple nodes or fields to be modified (because of field-to-field connections), the field returned may not be the only one that changed.
      • getTriggerNode

        public SoNode getTriggerNode()
        If this is a priority 0 data sensor, returns the node that was modified that caused this sensor to trigger. Returns NULL if the sensor was not triggered because a node changed (for example, if schedule() is called on the sensor) or if this sensor is not a priority 0 sensor. Note that because one change to the scene graph may cause multiple nodes or fields to be modified (because of field-to-field connections), the node returned may not be the only one that changed.
      • getTriggerPath

        public SoPath getTriggerPath()
        If this is a priority 0 data sensor, returns a path to the node that caused this sensor to trigger. Because recreating the path to the node that changed is relatively expensive, setTriggerPathFlag(true) must be called before the sensor is scheduled. If it is not called, or if the sensor wasn't triggered because a node changed, this returns NULL. NULL is also returned if this is not a priority 0 sensor.
      • getTriggerChild

        public SoNode getTriggerChild()
        If this is a priority 0 data sensor, and a change to a group node's children caused this sensor to be triggered (getTriggerType returns GROUP_ADD_CHILD, GROUP_INSERT_CHILD, or GROUP_REPLACE_CHILD), returns the node that was added to the group, and NULL in all other cases.
      • getTriggerPathFlag

        public boolean getTriggerPathFlag()
        Queries the flag that indicates whether the trigger path (see getTriggerPath()) is available to callbacks .
      • getTriggerType

        public SoDataSensor.ChangeTypes getTriggerType()
        If this is a priority 0 data sensor, returns the type of change that occurred. Returns UNSPECIFIED if the sensor was not triggered by a group children change or a multi-value field change or if this sensor is not a priority 0 sensor. A GROUP_* return value indicates that getTriggerChild and getTriggerChildIndex will return valid data. A FIELD_* return value indicates that the getTriggerMField* methods will return valid data.
      • getTriggerFastEditInfoFlag

        public boolean getTriggerFastEditInfoFlag()
        Queries the flag that indicates whether the trigger path fastEdit info (see getTriggerFastEditInfo()) is available to callbacks .

        Since:
        Open Inventor 9.2.3

      • getTriggerChildIndex

        public int getTriggerChildIndex()
        If this is a priority 0 data sensor, and a change to a group node's children caused this sensor to be triggered (getTriggerType returns GROUP_ADD_CHILD, GROUP_INSERT_CHILD, or GROUP_REPLACE_CHILD), returns the index of the node that was added or removed, and -1 in all other cases.
      • setTriggerPathFlag

        public void setTriggerPathFlag​(boolean flag)
        Sets the flag that indicates whether the trigger path (see getTriggerPath()) is available to callback methods. This is false by default. Note that setting this to true will add a little overhead when the sensor is notified.
      • getTriggerMFieldNumValues

        public int getTriggerMFieldNumValues()
        If this is a priority 0 data sensor, and a change in the data values of a multiple field (e.g., SoMFVec3f) caused this sensor to be triggered, returns the size of the range of the potentially changed values. Otherwise, returns -1
      • setTriggerFastEditInfoFlag

        public void setTriggerFastEditInfoFlag​(boolean flag)
        Sets the flag that indicates whether the trigger path fastEdit info (see getTriggerFastEditInfo()) is available to callback methods. This is false by default. Note that setting this to true will add a little overhead when the sensor is notified.

        Since:
        Open Inventor 9.2.3

      • getTriggerMFieldStartIndex

        public int getTriggerMFieldStartIndex()
        If this is a priority 0 data sensor, and a change in the data values of a multiple field (e.g., SoMFVec3f) caused this sensor to be triggered, returns the first index of the range of the potentially changed values. Otherwise, returns -1