Class SoCallbackAction
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.actions.SoAction
-
- com.openinventor.inventor.actions.SoCallbackAction
-
- Direct Known Subclasses:
SoSTLWriteAction
,SoToU3DAction
public class SoCallbackAction extends SoAction
Performs a generic traversal of a scene graph or path. Performs a generic traversal of a scene graph or path. In many cases a "custom" action can be implemented usingSoCallbackAction
with much less complexity than deriving a completely new action class.The application can specify callback methods that will be called when the action traverses a node of the specified class or a derived class. For example a callback for the
SoCone
class will only be called forSoCone
nodes, but a callback for theSoShape
class will be called for any type of shape node.This makes
SoCallbackAction
flexible and very convenient for "visiting" a set of nodes, especially when you only need the node itself and not a path to the node. For example, to count all the shapes in the scene graph. It is possible to get the path to the node being visited (seegetCurPath()
), butSoSearchAction
may be more convenient for getting a path to one or a small number of nodes.In addition, callback methods can be registered to collect the primitives (trangles, lines and points) generated by shapes in the scene graph. These primitives are the actual geometry if the shape contains triangles, lines or points, else they represent or approximate the actual geometry. NOTE: Most, but not all, shapes can generate primitives. See below for a complete list. Triangle primitives are used for all surfaces (such as cubes, face sets, or 3D text), line segment primitives are used for line shapes, and point primitives are used for point shapes. Note that the type of primitives generated for a shape is the same, regardless of drawing style or other properties.
Most of the methods on this class access information from the traversal state. They should be called only by callback functions that are invoked during traversal, so there is a valid state to work with.
EXAMPLE Apply a callback action to visit all shape nodes.
SoCallbackAction action = new SoCallbackAction(); action.addPreCallback ( SoShape.class, new NodeCallback(), null ); action.addTriangleCallback( SoShape.class, new TriangleCallback(), null ); action.apply( root ); class NodeCallback extends SoCallbackActionCB { @Override public int invoke( SoCallbackAction s, SoNode node ) { // Print node's name (if any) and class name System.out.println( "Shape \"" + node.getName() + "\": " + node.getClass().getName() ); return SoCallbackAction.Responses.CONTINUE.getValue(); } } class TriangleCallback extends SoTriangleCB { @Override public void invoke( SoCallbackAction action, SoPrimitiveVertex v1, SoPrimitiveVertex v2, SoPrimitiveVertex v3 ) { System.out.println(" Triangle:"); printVertex(v1, "1"); printVertex(v2, "2"); printVertex(v3, "3"); } private void printVertex(SoPrimitiveVertex vertex, String label) { SbVec3f point = vertex.getPoint(); System.out.println(" Vert" + label + " = " + point.getX() + ", " + point.getY() + ", " + point.getZ()); } } Example output:
Shape "": SoCone Triangle: Vert1 = 0.0, -1.0, -1.0 Vert2 = 0.0, 1.0, -0.0 Vert3 = 0.38268346, -1.0, -0.9238795 Triangle: Vert1 = 0.38268346, -1.0, -0.9238795 Vert2 = 0.0, 1.0, -0.0 Vert3 = 0.0, 1.0, -0.0 . . . - See Also:
SoCallback
,SoEventCallback
,SoShape
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SoCallbackAction.Material
static class
SoCallbackAction.Responses
Possible responses from a pre or post callback.static class
SoCallbackAction.TextureImage
-
Nested classes/interfaces inherited from class com.openinventor.inventor.actions.SoAction
SoAction.AppliedCodes, SoAction.DistribModes, SoAction.PathCodes, SoAction.PathIndices
-
Nested classes/interfaces inherited from class com.openinventor.inventor.Inventor
Inventor.ConstructorCommand
-
-
Field Summary
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SoCallbackAction()
The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLineSegmentCallback(java.lang.Class<? extends SoNode> nodeClass, SoLineSegmentCB cb, java.lang.Object userData)
void
addPointCallback(java.lang.Class<? extends SoNode> nodeClass, SoPointCB cb, java.lang.Object userData)
void
addPostCallback(java.lang.Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, java.lang.Object userData)
void
addPostTailCallback(SoCallbackActionCB cb, java.lang.Object userData)
void
addPreCallback(java.lang.Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, java.lang.Object userData)
void
addPreTailCallback(SoCallbackActionCB cb, java.lang.Object userData)
void
addTriangleCallback(java.lang.Class<? extends SoNode> nodeClass, SoTriangleCB cb, java.lang.Object userData)
static void
enableElement(java.lang.Class<? extends Inventor> t, int stkIndex)
float
getComplexity()
Returns complexity information from the state.SoComplexity.Types
getComplexityType()
Returns complexity information from the state.SbVec3f
getCoordinate3(int index)
Returns the current coordinates from the state.SbVec4f
getCoordinate4(int index)
Returns the current coordinates from the state.float
getCreaseAngle()
Returns the current shape hints from the state.SoCallbackAction.Responses
getCurrentResponse()
float
getDecimationPercentage()
Returns the current decimation percentage from the state.SoDecimationTypeElement.Types
getDecimationType()
Returns the current decimation type from the state.SoDrawStyle.Styles
getDrawStyle()
Returns the current drawing style information from the state.SoShapeHints.FaceTypes
getFaceType()
Returns the current shape hints from the state.float
getFocalDistance()
Returns the current camera and viewing information from the state.java.lang.String
getFontName()
Returns the current font information from the state.SoFont.RenderStyles
getFontRenderStyle()
Returns the current font information from the state.float
getFontSize()
Returns the current font information from the state.SbVec3f
getLightAttenuation()
Returns the current lighting model information from the state.SoLightModel.Models
getLightModel()
Returns the current lighting model information from the state.short
getLinePattern()
Returns the current drawing style information from the state.int
getLinePatternScaleFactor()
Returns the current drawing style information from the state.float
getLineWidth()
Returns the current drawing style information from the state.SoCallbackAction.Material
getMaterial()
Calls getMaterial((int)0).SoCallbackAction.Material
getMaterial(int mtlIndex)
Returns the current material information from the state.SoMaterialBinding.Bindings
getMaterialBinding()
Returns the current material information from the state.SbMatrix
getModelMatrix()
Returns the current modeling transformation from the state.SbVec3f
getNormal(int index)
Returns the current normal information from the state.SoNormalBinding.Bindings
getNormalBinding()
Returns the current normal information from the state.int
getNumCoordinates()
Returns the current coordinates from the state.int
getNumNormals()
Returns the current normal information from the state.int
getNumProfileCoordinates()
Returns the current profiles and their coordinates from the state.int
getNumTextureCoordinates()
Returns texture information from the state.SoPickStyle.Styles
getPickStyle()
Returns the current picking style.float
getPointSize()
Returns the current drawing style information from the state.java.util.Vector<SoNode>
getProfile()
Returns the current profiles and their coordinates from the state.SbVec2f
getProfileCoordinate2(int index)
Returns the current profiles and their coordinates from the state.SbVec3f
getProfileCoordinate3(int index)
Returns the current profiles and their coordinates from the state.SbMatrix
getProjectionMatrix()
Returns the current camera and viewing information from the state.SoShapeHints.ShapeTypes
getShapeType()
Returns the current shape hints from the state.int
getSwitch()
Returns the current switch value.SbColor
getTextureBlendColor()
Returns texture information from the state.SbVec2f
getTextureCoordinate2(int index)
Returns texture information from the state.SbVec4f
getTextureCoordinate4(int index)
Returns texture information from the state.SoTextureCoordinateBinding.Bindings
getTextureCoordinateBinding()
Returns texture information from the state.java.lang.String
getTextureFileName()
Returns texture information from the state.SoCallbackAction.TextureImage
getTextureImage()
Returns texture information from the state.SbMatrix
getTextureMatrix()
Returns the current texture mapping information from the state.SoTexture.Models
getTextureModel()
Returns the current texture mapping information from the state.SoTexture2Transform
getTextureTransformNode()
Returns the current texture mapping information from the state.SoTexture.WrapType
getTextureWrapS()
Returns the current texture mapping information from the state.SoTexture.WrapType
getTextureWrapT()
Returns the current texture mapping information from the state.SoGLRenderAction.TransparencyTypes
getTransparencyType()
Returns the current Transparency Type information from the state.SoUnits.UnitsType
getUnits()
Returns the current units from the state.SoShapeHints.VertexOrderings
getVertexOrdering()
Returns the current shape hints from the state.SbMatrix
getViewingMatrix()
Returns the current camera and viewing information from the state.SbViewVolume
getViewVolume()
Returns the current camera and viewing information from the state.void
invokeLineSegmentCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2)
void
invokePointCallbacks(SoShape shape, SoPrimitiveVertex[] v)
void
invokePostCallbacks(SoNode node)
void
invokePreCallbacks(SoNode node)
void
invokeTriangleCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2, SoPrimitiveVertex[] v3)
boolean
isCallbackAll()
Returns whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node.void
setCallbackAll(boolean flag)
Sets whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node.boolean
shouldGeneratePrimitives(SoShape shape)
-
Methods inherited from class com.openinventor.inventor.actions.SoAction
apply, apply, clearApplyResult, forwardTraversal, forwardTraversal, getContinueActionInBranchFlag, getCurPath, getDistribMode, getNodeAppliedTo, getOriginalPathListAppliedTo, getPathAppliedTo, getPathCode, getPathListAppliedTo, getPipeId, getSceneManager, getState, getWhatAppliedTo, hasTerminated, invalidateState, isBeingApplied, isLastPathListAppliedTo, isUsingAlternateRep, nullAction, postDelayedTraversal, preDelayedTraversal, resetContinueActionInBranchFlag, setPipeId, setSceneManager, setUpState, stopActionInBranch, traverse, useAlternateRep
-
Methods inherited from class com.openinventor.inventor.Inventor
dispose, getNativeResourceHandle
-
-
-
-
Method Detail
-
addPreTailCallback
public void addPreTailCallback(SoCallbackActionCB cb, java.lang.Object userData)
-
addPostTailCallback
public void addPostTailCallback(SoCallbackActionCB cb, java.lang.Object userData)
-
addPreCallback
public void addPreCallback(java.lang.Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, java.lang.Object userData)
-
addPostCallback
public void addPostCallback(java.lang.Class<? extends SoNode> nodeClass, SoCallbackActionCB cb, java.lang.Object userData)
-
addTriangleCallback
public void addTriangleCallback(java.lang.Class<? extends SoNode> nodeClass, SoTriangleCB cb, java.lang.Object userData)
-
addLineSegmentCallback
public void addLineSegmentCallback(java.lang.Class<? extends SoNode> nodeClass, SoLineSegmentCB cb, java.lang.Object userData)
-
addPointCallback
public void addPointCallback(java.lang.Class<? extends SoNode> nodeClass, SoPointCB cb, java.lang.Object userData)
-
getMaterial
public SoCallbackAction.Material getMaterial()
Calls getMaterial((int)0).
-
getFontRenderStyle
public SoFont.RenderStyles getFontRenderStyle()
Returns the current font information from the state.
-
getFontSize
public float getFontSize()
Returns the current font information from the state.
-
invokePreCallbacks
public void invokePreCallbacks(SoNode node)
-
invokeTriangleCallbacks
public void invokeTriangleCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2, SoPrimitiveVertex[] v3)
-
getPointSize
public float getPointSize()
Returns the current drawing style information from the state.
-
invokePostCallbacks
public void invokePostCallbacks(SoNode node)
-
getFontName
public java.lang.String getFontName()
Returns the current font information from the state.
-
getMaterial
public SoCallbackAction.Material getMaterial(int mtlIndex)
Returns the current material information from the state. Providing a mtlIndex will return the material defined for that index.
-
getMaterialBinding
public SoMaterialBinding.Bindings getMaterialBinding()
Returns the current material information from the state.
-
getTransparencyType
public SoGLRenderAction.TransparencyTypes getTransparencyType()
Returns the current Transparency Type information from the state.
-
enableElement
public static void enableElement(java.lang.Class<? extends Inventor> t, int stkIndex)
-
getCurrentResponse
public SoCallbackAction.Responses getCurrentResponse()
-
getLightModel
public SoLightModel.Models getLightModel()
Returns the current lighting model information from the state.
-
getLightAttenuation
public SbVec3f getLightAttenuation()
Returns the current lighting model information from the state.
-
invokeLineSegmentCallbacks
public void invokeLineSegmentCallbacks(SoShape shape, SoPrimitiveVertex[] v1, SoPrimitiveVertex[] v2)
-
getNumCoordinates
public int getNumCoordinates()
Returns the current coordinates from the state.
-
getCoordinate3
public SbVec3f getCoordinate3(int index)
Returns the current coordinates from the state.
-
getCoordinate4
public SbVec4f getCoordinate4(int index)
Returns the current coordinates from the state.
-
getComplexityType
public SoComplexity.Types getComplexityType()
Returns complexity information from the state.
-
getTextureCoordinate4
public SbVec4f getTextureCoordinate4(int index)
Returns texture information from the state.
-
getComplexity
public float getComplexity()
Returns complexity information from the state.
-
getDecimationType
public SoDecimationTypeElement.Types getDecimationType()
Returns the current decimation type from the state.
-
getLinePatternScaleFactor
public int getLinePatternScaleFactor()
Returns the current drawing style information from the state.
-
invokePointCallbacks
public void invokePointCallbacks(SoShape shape, SoPrimitiveVertex[] v)
-
getLineWidth
public float getLineWidth()
Returns the current drawing style information from the state.
-
shouldGeneratePrimitives
public boolean shouldGeneratePrimitives(SoShape shape)
-
getDecimationPercentage
public float getDecimationPercentage()
Returns the current decimation percentage from the state.
-
getDrawStyle
public SoDrawStyle.Styles getDrawStyle()
Returns the current drawing style information from the state.
-
getLinePattern
public short getLinePattern()
Returns the current drawing style information from the state.
-
getTextureWrapT
public SoTexture.WrapType getTextureWrapT()
Returns the current texture mapping information from the state.
-
getCreaseAngle
public float getCreaseAngle()
Returns the current shape hints from the state.
-
getTextureWrapS
public SoTexture.WrapType getTextureWrapS()
Returns the current texture mapping information from the state.
-
getNumTextureCoordinates
public int getNumTextureCoordinates()
Returns texture information from the state.getNumTextureCoordinates()
returns 0 if texture coordinates are generated by a function.
-
getUnits
public SoUnits.UnitsType getUnits()
Returns the current units from the state.
-
getShapeType
public SoShapeHints.ShapeTypes getShapeType()
Returns the current shape hints from the state.
-
getModelMatrix
public SbMatrix getModelMatrix()
Returns the current modeling transformation from the state.
-
getFaceType
public SoShapeHints.FaceTypes getFaceType()
Returns the current shape hints from the state.
-
getTextureBlendColor
public SbColor getTextureBlendColor()
Returns texture information from the state.
-
getTextureMatrix
public SbMatrix getTextureMatrix()
Returns the current texture mapping information from the state.
-
getTextureImage
public SoCallbackAction.TextureImage getTextureImage()
Returns texture information from the state.getTextureImage()
returns NULL if no texture is enabled.
-
getTextureFileName
public java.lang.String getTextureFileName()
Returns texture information from the state.
-
getTextureModel
public SoTexture.Models getTextureModel()
Returns the current texture mapping information from the state.
-
getTextureCoordinate2
public SbVec2f getTextureCoordinate2(int index)
Returns texture information from the state.
-
getTextureCoordinateBinding
public SoTextureCoordinateBinding.Bindings getTextureCoordinateBinding()
Returns texture information from the state.
-
getTextureTransformNode
public SoTexture2Transform getTextureTransformNode()
Returns the current texture mapping information from the state.
-
getSwitch
public int getSwitch()
Returns the current switch value.
-
getNormalBinding
public SoNormalBinding.Bindings getNormalBinding()
Returns the current normal information from the state.
-
getPickStyle
public SoPickStyle.Styles getPickStyle()
Returns the current picking style.
-
getNumProfileCoordinates
public int getNumProfileCoordinates()
Returns the current profiles and their coordinates from the state.
-
isCallbackAll
public boolean isCallbackAll()
Returns whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node.
-
getNumNormals
public int getNumNormals()
Returns the current normal information from the state.
-
setCallbackAll
public void setCallbackAll(boolean flag)
Sets whether the callback uses normal traversal (switches, etc.) or whether it traverses every single node. Default is false.
-
getNormal
public SbVec3f getNormal(int index)
Returns the current normal information from the state.
-
getProjectionMatrix
public SbMatrix getProjectionMatrix()
Returns the current camera and viewing information from the state.
-
getProfile
public java.util.Vector<SoNode> getProfile()
Returns the current profiles and their coordinates from the state.
-
getFocalDistance
public float getFocalDistance()
Returns the current camera and viewing information from the state.
-
getVertexOrdering
public SoShapeHints.VertexOrderings getVertexOrdering()
Returns the current shape hints from the state.
-
getViewVolume
public SbViewVolume getViewVolume()
Returns the current camera and viewing information from the state.
-
getProfileCoordinate2
public SbVec2f getProfileCoordinate2(int index)
Returns the current profiles and their coordinates from the state.
-
getViewingMatrix
public SbMatrix getViewingMatrix()
Returns the current camera and viewing information from the state.
-
getProfileCoordinate3
public SbVec3f getProfileCoordinate3(int index)
Returns the current profiles and their coordinates from the state.
-
-