public class SoEventCallback extends SoNode
SoEventCallback
will invoke application supplied callbacks during SoHandleEventAction
traversal. Methods allow the application to specify which Open Inventor events should trigger callbacks, and which path must be picked, if any, for the callback invocation to occur. The application callback is able to get information about the event and the pick detail, and may grab events, release events, and set whether the event was handled.
If you register more than one callback in an SoEventCallback
node, all the callbacks will be invoked when an event occurs, even if one of the callbacks handles the event. However, if the event is handled (i.e. setHandled is called) by any of the callbacks , no subsequent node in the scene graph will see the event. Generally SoEventCallback
nodes should be placed near the beginning of the scene graph, so the SoHandleEventAction
does not need to traverse the rest of the scene graph if the event is handled. Note that events may be handled by other nodes in the scene graph, for example draggers and manipulators. If the event is handled before the SoEventCallback
node is traversed, then none of the callbacks will be invoked.
Remember that when using the Open Inventor viewer classes, SoHandleEventAction
traversal is only done when the viewer is in "selection" mode (the arrow cursor is displayed). Also note that some methods may only be called from the callback .
When invoked, this SoEventCallback
node will be passed to the callback . Using this object, you can get the event being handled (getEvent()
) and query what geometry is under the cursor (getPickedPoint()
). These are convenient wrappers around the corresponding methods in the SoHandleEventAction
(which you can get using getAction()
).
Picking:
When getPickedPoint()
is called, the handle event action automatically applies an SoRayPickAction
to the scene graph using the cursor position in the event. The handle event action remembers the result in case another node needs pick information during the traversal. Often this is more convenient than creating and applying a pick action explicitly.
But note: The handle event action does not enable computation of normal vectors and texture coordinates in the pick action that it creates internally. If you need the normal vector at the point of intersection of the pick ray, then you must create your own pick action and apply it. In this case you can get the node to apply the pick action to by calling the handle event action's getPickRoot() method.
An event callback node that handles key and button events
Handler for key press eventsSoEventCallback eventNode = new SoEventCallback(); eventNode.addEventCallback( SoKeyboardEvent.class , new KeyEventHandler() ); eventNode.addEventCallback( SoMouseButtonEvent.class, new BtnEventHandler() );
Handler for mouse button eventsclass KeyEventHandler extends SoEventCallbackCB { @Override public void invoke( SoEventCallback node ) { // Get the event that triggered the callback SoKeyboardEvent evt = (SoKeyboardEvent)node.getEvent(); if (SoKeyboardEvent.isKeyPressEvent(evt, SoKeyboardEvent.Keys.UP_ARROW)) { // Do something, then tell action to stop traversal node.setHandled(); } else if (SoKeyboardEvent.isKeyPressEvent(evt, SoKeyboardEvent.Keys.DOWN_ARROW)) { // Do something, then tell action to stop traversal node.setHandled(); } } }
class BtnEventHandler extends SoEventCallbackCB { @Override public void invoke( SoEventCallback node ) { SoMouseButtonEvent evt = (SoMouseButtonEvent)node.getEvent(); // If button 1 was pressed if (SoMouseButtonEvent.isButtonPressEvent( evt, SoMouseButtonEvent.Buttons.BUTTON1 )) { // Check if any geometry is under the cursor SoHandleEventAction action = node.getAction(); SoPickedPoint pickedPt = action.getPickedPoint(); if (pickedPt != null) { SoPath pickedPath = pickedPt.getPath(); SoNode pickedNode = pickedPath.full.getTail(); } } } }
File format/default:
EventCallback {
See also:
SoInteraction, SoSelection
, SoHandleEventAction
, SoRayPickAction
, SoDragger
SoNode.RenderModes
Inventor.ConstructorCommand
VERBOSE_LEVEL, ZeroHandle
Constructor and Description |
---|
SoEventCallback()
Constructor creates an event callback node with no event interest and a NULL path.
|
Modifier and Type | Method and Description |
---|---|
void |
addEventCallback(java.lang.Class eventClass,
SoEventCallbackCB f)
Same as
addEventCallback (eventClass,f,null). |
void |
addEventCallback(java.lang.Class eventClass,
SoEventCallbackCB f,
java.lang.Object userData)
Same as
addEventCallback (eventClass.getName(),f,userData). |
void |
addEventCallback(java.lang.String eventClassName,
SoEventCallbackCB f,
java.lang.Object userData)
Specifies the callbacks to be invoked for different event types.
|
SoHandleEventAction |
getAction()
Returns the
SoHandleEventAction currently traversing this node, or NULL if traversal is not taking place. |
SoEvent |
getEvent()
Returns the event currently being handled, or NULL if traversal is not taking place.
|
SoPath |
getPath()
Gets the path which must be picked in order for the callbacks to be invoked.
|
SoPickedPoint |
getPickedPoint()
Returns pick information during
SoHandleEventAction traversal, or NULL if traversal is not taking place. |
void |
grabEvents()
Tells the event callback node to grab events.
|
boolean |
isHandled()
Returns whether the event has been handled.
|
void |
releaseEvents()
Tells the event callback node to release the grab of events.
|
void |
removeEventCallback(java.lang.Class eventClass,
SoEventCallbackCB f,
java.lang.Object userData)
|
void |
removeEventCallback(java.lang.String eventClassName,
SoEventCallbackCB f,
java.lang.Object userData)
Removes the callback function specified by
addEventCallback . |
void |
setHandled()
Tells the node the event was handled.
|
void |
setPath(SoPath path)
Sets the path which must be picked in order for the callbacks to be invoked.
|
affectsState, callback, copy, copy, distribute, doAction, getAlternateRep, getBoundingBox, getByName, getMatrix, getPrimitiveCount, getRenderEngineMode, getRenderUnitID, GLRender, GLRenderBelowPath, GLRenderInPath, GLRenderOffPath, grabEventsCleanup, grabEventsSetup, handleEvent, isBoundingBoxIgnoring, isOverride, pick, rayPick, search, setOverride, touch, write
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
getNativeResourceHandle
public SoEventCallback()
public void addEventCallback(java.lang.Class eventClass, SoEventCallbackCB f)
addEventCallback
(eventClass,f,null).eventClass
- one of the class in the package com.openinventor.inventor.events
public void addEventCallback(java.lang.Class eventClass, SoEventCallbackCB f, java.lang.Object userData)
addEventCallback
(eventClass.getName(),f,userData).eventClass
- one of the class in the package com.openinventor.inventor.events
public void addEventCallback(java.lang.String eventClassName, SoEventCallbackCB f, java.lang.Object userData)
eventClassName
- the name of one of the class in the package com.openinventor.inventor.events
public void removeEventCallback(java.lang.Class eventClass, SoEventCallbackCB f, java.lang.Object userData)
eventClass
- one of the class in the package com.openinventor.inventor.events
public void removeEventCallback(java.lang.String eventClassName, SoEventCallbackCB f, java.lang.Object userData)
addEventCallback
.eventClassName
- the name of one of the class in the package com.openinventor.inventor.events
public SoEvent getEvent()
public void setHandled()
SoEventCallback
node, all of them will be invoked, regardless of whether one has handled the event or not. This should be called only from callback .public SoPath getPath()
public SoPickedPoint getPickedPoint()
SoHandleEventAction
traversal, or NULL if traversal is not taking place.
This should be called only from callback .
When this method is called, an SoRayPickAction
is automatically applied to the scene graph that the SoHandleEventAction
is traversing, using the current event. However this is only done once for each SoHandleEventAction
traversal and the result is cached for subsequent queries during the current traversal.
Note: The handle event action does not enable computation of normal vectors and texture coordinates in the pick action that it creates internally. If you need the normal vector at the point of intersection of the pick ray, then you must create your own pick action and apply it. In this case you can get the node to apply the pick action to by calling the handle event action's getPickRoot() method.
public SoHandleEventAction getAction()
SoHandleEventAction
currently traversing this node, or NULL if traversal is not taking place.
This should be called only from callback .public boolean isHandled()
public void releaseEvents()
grabEvents()
.public void setPath(SoPath path)
setPath()
method makes its own copy of the passed path.public void grabEvents()
Generated on July 31, 2019, Copyright © Thermo Fisher Scientific. All rights reserved. http://www.openinventor.com