Class SoSelection
- java.lang.Object
-
- All Implemented Interfaces:
SafeDisposable
- Direct Known Subclasses:
SoExtSelection
public class SoSelection extends SoSeparator
Manages a list of selected objects.SoSelection
defines a node which can be inserted into a scene graph and will generate and manage a selection list from picks on any node in the subgraph below it. Nodes are selected based on a current selection policy. Callbacks report back to the application when a path has been selected or deselected. The selection list can also be managed programmatically.SoSelection
is convenient when the application just needs to know the path (SoPath
) to the objects that were selected (or deselected).SoSelection
automatically does picking (applies anSoRayPickAction
), but it does not provide information about the picked point or pick details. For that seeSoRayPickAction
,SoEventCallback
andSoDetail
.SoSelection
does picking based on a single coordinate (the cursor position). TheSoExtSelection
node can do selection based on a lasso or rectangle drawn on the screen.The selection callbacks are invoked every time an object is selected, whether from user interaction or from a method call. The callbacks are invoked after the object has been added to the selection list.
When handling events, by default
SoSelection
makes sure that the mouse release event was over the same object as the mouse press event before changing the list of selected objects. This allows users to mouse down on an object, change their mind and move the cursor off the object, then release the mouse button without altering the selection. See thesetPickMatching
method.The selection can be highlighted automatically by replacing the render area's render action with one of the specialized highlighting render actions, for example
SoHaloHighlightRenderAction
. See the code example below. The application can also create a custom highlight action. See the chapter "Creating a Selection Highlight Style" in the Inventor Toolmaker Volume 1.It is possible to use multiple
SoSelection
nodes in a scene graph, but there are a few things to keep in mind:- If two selection nodes could potentially select the same geometry, the geometry will be selected by the selection node lowest in the scene graph (the closest ancestor of the geometry).
- The automatic viewer redraw on selection change (renderArea's redrawOnSelectionChange method) feature currently only works for a single selection node. You can work around this by calling renderArea's scheduleRedraw() method in a selection callback .
- The box and line highlighting render actions currently search for the first selection node in the scene graph and only highlight geometry selected by that selection node. You can work around this by creating a custom highlight action.
Instancing:
When instance nodes of aSoMultipleInstance
or aSoMultipleCopy
group are selected, the application can get the instance identifier using theSoPath
method getInstanceIndex().Hidden references:
SoSelection
creates anSoPath
when an object is added to the selection list. TheSoPath
references each node in the path, including theSoSelection
node. This reference will prevent those nodes, including theSoSelection
, from being reclaimed for as long as theSoPath
exists. TheSoPath
exists until the object is deselected or the selection list is cleared. In general, thedeselectAll()
method should be called when theSoSelection
is no longer needed.EXAMPLE Create an
SoSelection
node, set a selection callback and add children.SoSelection selectionNode = new SoSelection(); selectionNode.addSelectionCallback ( new SelectionCB() ); selectionNode.addDeselectionCallback( new DeselectionCB() ); selectionNode.addChild(scene); Enable automatic highlighting.
selectionNode.addChangeCallback(new SoSelectionClassCB() { public void invoke(SoSelection s) { area.scheduleRedraw(); } }); viewer.setSceneGraph( selectionNode ); viewer.getRenderArea().setGLRenderAction( new SoHaloHighlightRenderAction() ); Implement the selection and deselection callbacks.
static class SelectionCB extends SoSelectionPathCB { @Override public void invoke( SoPath path ) { SoNode node = path.regular.getTail(); System.out.printf( "Selected %s\n", node.getClass().getName() ); } } static class DeselectionCB extends SoSelectionPathCB { @Override public void invoke( SoPath path ) { SoNode node = path.regular.getTail(); System.out.printf( "De-selected %s\n", node.getClass().getName() ); } } File format/default:
Selection {
boundingBoxCaching AUTO renderCulling AUTO pickCulling AUTO policy SHIFT fastEditing DISABLE
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SoSelection.Policies
-
Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoSeparator
SoSeparator.Cachings, SoSeparator.FastEditings, SoSeparator.RenderUnitIds
-
Nested classes/interfaces inherited from class com.openinventor.inventor.nodes.SoNode
SoNode.RenderModes
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
Fields Modifier and Type Field Description SoSFEnum<SoSelection.Policies>
policy
Selection policy that is followed in response to user interaction.-
Fields inherited from class com.openinventor.inventor.nodes.SoSeparator
boundingBoxCaching, fastEditing, pickCulling, renderCaching, renderCulling, renderUnitId
-
Fields inherited from class com.openinventor.inventor.nodes.SoGroup
boundingBoxIgnoring
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SoSelection()
Creates a selection node with the default settings.SoSelection(int nChildren)
Constructor that specifies the approximate number of children.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeCallback(SoSelectionClassCB f)
void
addChangeCallback(SoSelectionClassCB f, java.lang.Object userData)
void
addDeselectionCallback(SoSelectionPathCB f)
equivalent to addDeselectionCallback(f,null)void
addDeselectionCallback(SoSelectionPathCB f, java.lang.Object userData)
The deselection callbacks are invoked every time an object is deselected, whether it be from user interaction or from method call.void
addFinishCallback(SoSelectionClassCB f)
equivalent to addFinishCallback(f,null)void
addFinishCallback(SoSelectionClassCB f, java.lang.Object userData)
The finish callbacks are invoked when the user has finished interactively changing the selection list (by picking objects).void
addSelectionCallback(SoSelectionPathCB f)
equivalent to addSelectionCallback(f,null)void
addSelectionCallback(SoSelectionPathCB f, java.lang.Object userData)
The selection callbacks are invoked every time an object is selected, whether it be from user interaction or from method call.void
addStartCallback(SoSelectionClassCB f)
equivalent to addStartCallback(f,null)void
addStartCallback(SoSelectionClassCB f, java.lang.Object userData)
The start callbacks are invoked when the user has initiated an interactive change to the selection list (by picking objects).void
deselect(int which)
Deselects a path by removing it from the selection list.void
deselect(SoNode node)
Deselects the passed node by creating a path to it, and removing the node from the selection list by calling deselect(path) .void
deselect(SoPath path)
Deselects the passed path by removing it from the selection list.void
deselectAll()
Deselects all paths in the selection list, that is, clear the list.java.util.Vector<SoPath>
getList()
Returns the list of selected paths.int
getNumSelected()
Returns the number of paths in the selection list.SoPath
getPath(int index)
Returns the ith path in the selection list.float
getPickRadius()
Returns the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking.SoPath
getValueAt(int i)
boolean
isPickMatching()
Returns pick matching flag.boolean
isSelected(SoNode node)
Returns true if the passed node is selected by creating a path to it, then callingisSelected()
.boolean
isSelected(SoPath path)
Returns true if the passed path is selected, that is, if it is in the selection list.void
removeChangeCallback(SoSelectionClassCB f)
void
removeChangeCallback(SoSelectionClassCB f, java.lang.Object userData)
void
removeDeselectionCallback(SoSelectionPathCB f)
void
removeDeselectionCallback(SoSelectionPathCB f, java.lang.Object userData)
void
removeFinishCallback(SoSelectionClassCB f)
void
removeFinishCallback(SoSelectionClassCB f, java.lang.Object userData)
void
removeSelectionCallback(SoSelectionPathCB f)
void
removeSelectionCallback(SoSelectionPathCB f, java.lang.Object userData)
void
removeStartCallback(SoSelectionClassCB f)
void
removeStartCallback(SoSelectionClassCB f, java.lang.Object userData)
void
select(SoNode node)
Selects the passed node by creating a path to it, and adding the path to the selection list by calling select(path) .void
select(SoPath path)
Selects the passed path by adding it to the selection list.void
setPickFilterCallback(SoSelectionPickCB f)
equivalent to setPickFilterCallback(f,null,true)void
setPickFilterCallback(SoSelectionPickCB f, java.lang.Object userData)
equivalent to setPickFilterCallback(f,userData,true)void
setPickFilterCallback(SoSelectionPickCB f, java.lang.Object userData, boolean callOnlyIfSelectable)
The pick filter callback is invoked when a pick has occurred and the selection node is about to change the selection list.void
setPickMatching(boolean pickTwice)
SoSelection
will pick once on mouse down and once on mouse up, and make sure the picks match before changing the selection list.void
setPickRadius(float radiusInPixels)
Sets the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking.void
toggle(SoNode node)
Toggles the selection status of the passed node by creating a path to it, then calling toggle(path) .void
toggle(SoPath path)
Toggles the selection status of the passed path - if the path is in the selection list, it is removed; if not in the list, it is added.-
Methods inherited from class com.openinventor.inventor.nodes.SoGroup
addChild, findChild, getChild, getNumChildren, insertChild, removeAllChildren, removeChild, removeChild, replaceChild, replaceChild
-
Methods inherited from class com.openinventor.inventor.nodes.SoNode
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
-
Methods inherited from class com.openinventor.inventor.fields.SoFieldContainer
copyFieldValues, copyFieldValues, enableNotify, fieldsAreEqual, get, getAllFields, getEventIn, getEventOut, getField, getFieldName, hasDefaultValues, isNotifyEnabled, set, setToDefaults
-
Methods inherited from class com.openinventor.inventor.misc.SoBase
dispose, getName, isDisposable, isSynchronizable, setName, setSynchronizable
-
Methods inherited from class com.openinventor.inventor.Inventor
getNativeResourceHandle
-
-
-
-
Field Detail
-
policy
public final SoSFEnum<SoSelection.Policies> policy
Selection policy that is followed in response to user interaction. Use enumPolicy
. Default is SHIFT.
-
-
Method Detail
-
addChangeCallback
public void addChangeCallback(SoSelectionClassCB f)
-
addChangeCallback
public void addChangeCallback(SoSelectionClassCB f, java.lang.Object userData)
-
removeChangeCallback
public void removeChangeCallback(SoSelectionClassCB f)
-
removeChangeCallback
public void removeChangeCallback(SoSelectionClassCB f, java.lang.Object userData)
-
addSelectionCallback
public void addSelectionCallback(SoSelectionPathCB f)
equivalent to addSelectionCallback(f,null)
-
addSelectionCallback
public void addSelectionCallback(SoSelectionPathCB f, java.lang.Object userData)
The selection callbacks are invoked every time an object is selected, whether it be from user interaction or from method call. The callbacks are invoked after the object has been added to the selection list.
-
removeSelectionCallback
public void removeSelectionCallback(SoSelectionPathCB f)
-
removeSelectionCallback
public void removeSelectionCallback(SoSelectionPathCB f, java.lang.Object userData)
-
addDeselectionCallback
public void addDeselectionCallback(SoSelectionPathCB f)
equivalent to addDeselectionCallback(f,null)
-
addDeselectionCallback
public void addDeselectionCallback(SoSelectionPathCB f, java.lang.Object userData)
The deselection callbacks are invoked every time an object is deselected, whether it be from user interaction or from method call. This is invoked after the object has been removed from the selection list.
-
removeDeselectionCallback
public void removeDeselectionCallback(SoSelectionPathCB f)
-
removeDeselectionCallback
public void removeDeselectionCallback(SoSelectionPathCB f, java.lang.Object userData)
-
addStartCallback
public void addStartCallback(SoSelectionClassCB f)
equivalent to addStartCallback(f,null)
-
addStartCallback
public void addStartCallback(SoSelectionClassCB f, java.lang.Object userData)
The start callbacks are invoked when the user has initiated an interactive change to the selection list (by picking objects). This will be followed by invocations of the select and/or deselect callbacks, finally followed by each finish callback. A start callback can be used, for instance, to save the current selection for later restoration (e.g. undo/redo). The start callbacks are not called when the selection list is changed programmatically.
-
removeStartCallback
public void removeStartCallback(SoSelectionClassCB f)
-
removeStartCallback
public void removeStartCallback(SoSelectionClassCB f, java.lang.Object userData)
-
addFinishCallback
public void addFinishCallback(SoSelectionClassCB f)
equivalent to addFinishCallback(f,null)
-
addFinishCallback
public void addFinishCallback(SoSelectionClassCB f, java.lang.Object userData)
The finish callbacks are invoked when the user has finished interactively changing the selection list (by picking objects). This was preceded by an invocation of each start callback, and invocations of the select and/or deselect callbacks. The finish callbacks are not called when the selection list is changed programmatically.
-
removeFinishCallback
public void removeFinishCallback(SoSelectionClassCB f)
-
removeFinishCallback
public void removeFinishCallback(SoSelectionClassCB f, java.lang.Object userData)
-
setPickFilterCallback
public void setPickFilterCallback(SoSelectionPickCB f)
equivalent to setPickFilterCallback(f,null,true)
-
setPickFilterCallback
public void setPickFilterCallback(SoSelectionPickCB f, java.lang.Object userData)
equivalent to setPickFilterCallback(f,userData,true)
-
setPickFilterCallback
public void setPickFilterCallback(SoSelectionPickCB f, java.lang.Object userData, boolean callOnlyIfSelectable)
The pick filter callback is invoked when a pick has occurred and the selection node is about to change the selection list. The callback function returns the path that the selection node should use when selecting and deselecting. If no pick callback is registered (the default), the selection node will use the path returned bySoPickedPoint.getPath()
on the picked point associated with the event being processed.Note that a picked object may or may not be a child of the selection node. A selection node will only select paths that pass through it. Possible return values from the callback:
[a] null - selection behaves as if nothing was picked (i.e. for SINGLE and SHIFT policies, this clears the selection list). Handle event action traversal halts.
[b] Path - this path will be selected/deselected according to the selection policy (it must lie under the selection node). Handle event action traversal halts.
[c] Path containing only the selection node - apply the selection policy as if nothing was picked. Handle event action traversal continues.
[d] Path not passing through the selection node - selection ignores this pick event and no change is made to the selection list. Handle event action traversal continues.
A simple way to tell selection to ignore the pick is to return an
SoPath
with no nodes in it. (i.e. return new SoPath();) Selection will always ref the path returned by the callback, make a copy of the path, then unref the path.The callOnlyIfSelectable argument, when set to true, means the pick callback function will only be invoked on picks which pass through the selection node. When false, all picks will be passed to the callback whether they pass through the selection or not.
- See Also:
setPickMatching(boolean)
,isPickMatching()
-
toggle
public void toggle(SoPath path)
Toggles the selection status of the passed path - if the path is in the selection list, it is removed; if not in the list, it is added.
-
getNumSelected
public int getNumSelected()
Returns the number of paths in the selection list.
-
getList
public java.util.Vector<SoPath> getList()
Returns the list of selected paths.
-
getPath
public SoPath getPath(int index)
Returns the ith path in the selection list.
-
deselect
public void deselect(SoNode node)
Deselects the passed node by creating a path to it, and removing the node from the selection list by calling deselect(path) . If there is more than one instance of node beneath the selection node, the created path will be the first instance found.
-
isSelected
public boolean isSelected(SoNode node)
Returns true if the passed node is selected by creating a path to it, then callingisSelected()
. If there is more than one instance of node beneath the selection node, the created path will be the first instance found.
-
setPickMatching
public void setPickMatching(boolean pickTwice)
SoSelection
will pick once on mouse down and once on mouse up, and make sure the picks match before changing the selection list. This allows the user to pick down on an object, change their mind and drag off the object, release the mouse button and not affect the selection. Pass true to enable this behavior. Pass false to disable this, meaning whatever is picked on a mouse release is added to/removed from the selection list. Default is pick-matching on.
-
isSelected
public boolean isSelected(SoPath path)
Returns true if the passed path is selected, that is, if it is in the selection list.
-
toggle
public void toggle(SoNode node)
Toggles the selection status of the passed node by creating a path to it, then calling toggle(path) . If there is more than one instance of node beneath the selection node, the created path will be the first instance found.
-
deselectAll
public void deselectAll()
Deselects all paths in the selection list, that is, clear the list.
-
isPickMatching
public boolean isPickMatching()
Returns pick matching flag.
-
select
public void select(SoNode node)
Selects the passed node by creating a path to it, and adding the path to the selection list by calling select(path) . If there is more than one instance of node beneath the selection node, the created path will be the first instance found.
-
getPickRadius
public float getPickRadius()
Returns the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking.
-
select
public void select(SoPath path)
Selects the passed path by adding it to the selection list. The selection node must lie in the path. The path is copied and truncated such that the selection node is the head of the path. If the selection node does not lie in the path, the selection list remains unchanged. This method ignores the current selection policy.
-
getValueAt
public SoPath getValueAt(int i)
-
deselect
public void deselect(int which)
Deselects a path by removing it from the selection list. The argument which specifies which path in the list to be removed.
-
deselect
public void deselect(SoPath path)
Deselects the passed path by removing it from the selection list.
-
setPickRadius
public void setPickRadius(float radiusInPixels)
Sets the radius (in pixels) around the viewport-space point through which the ray passes when doing ray picking. Ray picking is performed when getPickedPoint() is called. The pick radius set here is only used when testing the ray against lines and points.
-
-