Class SoPolyLineScreenDrawer
- java.lang.Object
-
- com.openinventor.inventor.Inventor
-
- com.openinventor.inventor.misc.SoBase
-
- com.openinventor.inventor.fields.SoFieldContainer
-
- com.openinventor.inventor.nodes.SoNode
-
- com.openinventor.inventor.drawers.SoScreenDrawer
-
- com.openinventor.inventor.drawers.SoPolyLineScreenDrawer
-
- All Implemented Interfaces:
SafeDisposable
- Direct Known Subclasses:
SoEllipseScreenDrawer
,SoLassoScreenDrawer
,SoPolygonScreenDrawer
,SoRectangleScreenDrawer
public class SoPolyLineScreenDrawer extends SoScreenDrawer
Interactively draw a polyline in normalized screen space. This class is a base class used to allow the user to dynamically draw line-based shapes (lasso, circle, rectangle, ...) on screen. The geometry is defined in normalized screen space ([-1, 1]x[-1, 1]).Applications will typically use one of the derived classes, for example,
SoEllipseScreenDrawer
,SoRectangleScreenDrawer
,SoPolygonScreenDrawer
orSoLassoScreenDrawer
.The line color is specified by the
color
field (default is red).SoPolyLineScreenDrawer
classes can automatically reduce the number of points in the shape drawn by the user. This is especially useful withSoLassoScreenDrawer
. See thesimplificationThreshold
field.Sub-classes can implement the onMouseDown, onMouseMove, etc... methods, to add and edit points.
Notes:
- Viewer:
- Screen drawers, like draggers, depend on
SoHandleEventAction
to get events. Therefore when using one of the Open Inventor viewer classes, screen drawers will only work when the viewer is in "selection" mode (arrow cursor). (In "viewing" mode, mouse events are handled by the viewer to control the camera.)
- The escape key (ESC) can be used to cancel creation of the polyline. However, currently it also changes the viewer mode (this is a known problem).
- Screen drawers, like draggers, depend on
- Event handling:
The drawer will automatically begin a new polyline when it sees a mouse button 1 down event. However the drawer does not call setHandled(), so other nodes in the scene graph, e.g.SoEventCallback
or a dragger, may also handle this event. - Finish notification:
- An event is raised to notify the application when the line is finished. (see onFinish ). This event is called at the end of line finalization (after simplification etc). See
SbEventHandler
for methods to set a callback to be notified when this event is raised.
- In this callback the application can retrieve coordinates from the
point
field. These points are in Open Inventor normalized device coordinates (-1 to 1), not pixel coordinates.
- The drawer does not call the
SoHandleEventAction
's setHandled() method for the event that finished the polyline. The application can call setHandled() in this callback.
- With some drawers it is possible to get a call with zero points if the user pressed ESC to cancel the interaction. Applications should check for this case.
- With some drawers it is also possible to get a call with a non-zero number of points, but all points are the same coordinate. E.g.
SoRectangleScreenDrawer
stores four points even if the mouse down/up events are at the same location.
- Typically the application will want to remove the polyline from the screen in this callback. See the next note.
- An event is raised to notify the application when the line is finished. (see onFinish ). This event is called at the end of line finalization (after simplification etc). See
- Part of the scene graph:
- Note that the polyline remains on the screen (because it is part of the scene graph) until
clear()
is called or the user starts a new interaction.
- Changing the color field or the isClosed field will immediately change the appearance of a polyline currently on the screen.
- Note that the polyline remains on the screen (because it is part of the scene graph) until
- Simplification:
Simplification is done (if > 0) when the user releases the mouse button and also if the simplificationThreshold is changed. But note that the old points are thrown away, so you can't re-simplify with a different value. - isClosed field:
If true (default), the polyline will be closed while being drawn (not just when the user releases the mouse button). The default in this class is false, but most sub-classes set it to true. - Coordinates:
This node and its subclasses use screen coordinates ranging from -1 to 1. (Because this is the default view volume for anSoOrthographicCamera
node.) Be careful because other classes in Open Inventor use normalized screen coordinates ranging from 0 to 1. In particular theSbViewportRegion
normalize() methods and theSbViewVolume
methods that project from 3D to 2D and vice-versa. - There should only be one
SoScreenDrawer
derived node in the sceneGraph (to avoid conflicts in mouse events).
EXAMPLE Create a screen drawer, set the callback and add it to the scene graph:
SoRectangleScreenDrawer drawer = new SoRectangleScreenDrawer(); drawer.onFinish.addEventListener(new LineDrawerListener()); root.addChild( drawer ); class LineDrawerListener implements SbEventListener<EventArg> { @Override public void onEvent(EventArg eventArg) { SoPolyLineScreenDrawer drawer = eventArg.getSource(); SoHandleEventAction action = eventArg.getAction(); int numPoints = drawer.point.getNum(); if ( numPoints > 0 ) { // Use points SbVec2f point0 = drawer.point.getValueAt(0); } drawer.clear(); // Remove polyline from screen action.setHandled(); } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SoPolyLineScreenDrawer.EventArg
Structure given to callback when an event is raised.-
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 SoSFColor
color
Color of line.SoSFBool
doCCW
Make the line counter-clockwise when it is finalized.SoSFBool
isClosed
Close the line during display (connect last point to first point).SoSFUShort
linePattern
Stipple pattern.SoSFInt32
linePatternScaleFactor
Stipple pattern scale factor.SoSFFloat
lineWidth
Width of lines.SbEventHandler<SoPolyLineScreenDrawer.EventArg>
onFinish
Event raised when the line is finished.SbEventHandler<SoPolyLineScreenDrawer.EventArg>
onMove
Event raised during polyline drawing.SbEventHandler<SoPolyLineScreenDrawer.EventArg>
onStart
Event raised when starting to draw a polyline.SoMFVec2f
point
Points of line.SoSFUInt32
simplificationThreshold
Threshold (in pixels) used to simplify line when it is finished.-
Fields inherited from class com.openinventor.inventor.drawers.SoScreenDrawer
sceneGraph
-
Fields inherited from class com.openinventor.inventor.Inventor
VERBOSE_LEVEL, ZeroHandle
-
-
Constructor Summary
Constructors Constructor Description SoPolyLineScreenDrawer()
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Convenience method to clear the points in the line.-
Methods inherited from class com.openinventor.inventor.drawers.SoScreenDrawer
reset
-
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
-
simplificationThreshold
public final SoSFUInt32 simplificationThreshold
Threshold (in pixels) used to simplify line when it is finished. A value of 0 means no simplification. Default value is 5 pixels.
-
doCCW
public final SoSFBool doCCW
Make the line counter-clockwise when it is finalized. This can change order of points. Default is true.Note Some shapes (like "8") do not have a defined clockwiseness. In these cases, the result is undefined.
- Since:
- Open Inventor 9.0
-
color
public final SoSFColor color
Color of line. Default value is red.
-
point
public final SoMFVec2f point
Points of line. Default is empty.
-
isClosed
public final SoSFBool isClosed
Close the line during display (connect last point to first point). Default is false (but most sub-classes automatically set it to true).Warning This only affects the display.
-
linePattern
public final SoSFUShort linePattern
Stipple pattern. This specifies how dashed or dotted lines will be drawn. The pattern is a 16-bit series of 0s and 1s and is repeated as necessary to stipple a given line. A 1 indicates that drawing occurs, and a 0 that it does not, on a pixel-by-pixel basis, starting with the low-order bits of the pattern. Values can range from 0 (invisible) to 0xffff (solid). Default is 0xffff.The line pattern can be stretched using the
linePatternScaleFactor
field.
-
linePatternScaleFactor
public final SoSFInt32 linePatternScaleFactor
Stipple pattern scale factor. It stretches the line pattern (seelinePattern
) by multiplying each subseries of consecutive 1s and 0s. Scale factors are clamped to lie between 1 and 255. Default is 1.
-
lineWidth
public final SoSFFloat lineWidth
Width of lines. The default line width is 0, meaning to use the default OpenGL value (1). Line widths greater than zero are considered to be specified in printer's points, where 1 inch = 72 printer's points. However the default pixels-per-inch value (managed bySbViewportRegion
) is also 72. So effectively line width is specified in pixels unless the application sets a different pixels-per-inch value.
-
onStart
public final SbEventHandler<SoPolyLineScreenDrawer.EventArg> onStart
Event raised when starting to draw a polyline. SeeSbEventHandler
for methods to set a callback to be notified when this event is raised. The callback will be called with anEventArg
from which it can query the current action and drawer objects.
Note that the callback parameter must be declared const .
-
onMove
public final SbEventHandler<SoPolyLineScreenDrawer.EventArg> onMove
Event raised during polyline drawing. SeeSbEventHandler
for methods to set a callback to be notified when this event is raised. The callback will be called with anEventArg
from which it can query the current action and drawer objects. Note that the callback parameter must be declared const .
-
onFinish
public final SbEventHandler<SoPolyLineScreenDrawer.EventArg> onFinish
Event raised when the line is finished. SeeSbEventHandler
for methods to set a callback to be notified when this event is raised. The callback will be called with a line drawer specificEventArg
from which you can query the current action and drawer objects. Note that the callback parameter in this case is not const.
-
-