public class SoDataSensor extends SoDelayQueueSensor
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.
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
Modifier and Type | Class and Description |
---|---|
static class |
SoDataSensor.ChangeTypes
Change type.
|
Inventor.ConstructorCommand
VERBOSE_LEVEL, ZeroHandle
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
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.
|
boolean |
getTriggerFastEditInfoFlag()
Queries the flag that indicates whether the trigger path fastEdit info (see
getTriggerFastEditInfo() ) is available to callbacks . |
SoField |
getTriggerField()
If this is a priority 0 data sensor, returns the field that was modified that caused this sensor to trigger.
|
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. |
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. |
SoNode |
getTriggerNode()
If this is a priority 0 data sensor, returns the node that was modified that caused this sensor to trigger.
|
SoPath |
getTriggerPath()
If this is a priority 0 data sensor, returns a path to the node that caused this sensor to trigger.
|
boolean |
getTriggerPathFlag()
Queries the flag that indicates whether the trigger path (see
getTriggerPath() ) is available to callbacks . |
SoDataSensor.ChangeTypes |
getTriggerType()
If this is a priority 0 data sensor, returns the type of change that occurred.
|
void |
setFinalTask(java.lang.Runnable task)
Deprecated.
As of Open Inventor 10.1, useless method: use ReferenceQueue
Java API instead.
|
void |
setTriggerFastEditInfoFlag(boolean flag)
Sets the flag that indicates whether the trigger path fastEdit info (see
getTriggerFastEditInfo() ) is available to callback methods. |
void |
setTriggerPathFlag(boolean flag)
Sets the flag that indicates whether the trigger path (see
getTriggerPath() ) is available to callback methods. |
getDefaultPriority, getPriority, isIdleOnly, setPriority
isScheduled, schedule, setTask, unschedule
dispose, getNativeResourceHandle
@Deprecated public void setFinalTask(java.lang.Runnable task)
public int getTriggerFastEditInfo()
public SoField getTriggerField()
public SoNode getTriggerNode()
public SoPath getTriggerPath()
public SoNode getTriggerChild()
public boolean getTriggerPathFlag()
getTriggerPath()
) is available to callbacks .public SoDataSensor.ChangeTypes getTriggerType()
public boolean getTriggerFastEditInfoFlag()
getTriggerFastEditInfo()
) is available to callbacks .
public int getTriggerChildIndex()
public void setTriggerPathFlag(boolean flag)
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.public int getTriggerMFieldNumValues()
SoMFVec3f
) caused this sensor to be triggered, returns the size of the range of the potentially changed values.
Otherwise, returns -1public void setTriggerFastEditInfoFlag(boolean flag)
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.
public int getTriggerMFieldStartIndex()
SoMFVec3f
) caused this sensor to be triggered, returns the first index of the range of the potentially changed values.
Otherwise, returns -1Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com