ToolInterface
new ToolInterface()
Base class for new interaction tools.
Can also be used simply as a template for creating a new tool.
Methods
getNames()
This method should return an array containing the names of all tools implemented by this class. Often this would be a single name but it is possible to support multiple interactions with a single tool. When this tool is registered with the ToolController each name gets registered as an available tool.
Returns
| type | description |
|---|---|
| array | Array of strings. Should not be empty. |
getName()
This is an optional convenience method to obtain the first name of this tool.
Returns
| type | description |
|---|---|
| string | The tools default name. |
getPriority()
This method should return the priority of the tool inside the tool stack. A tool with higher priority will get events first.
Returns
| type | description |
|---|---|
| number | The tool’s priority. |
register()
This method is called by Autodesk.Viewing.ToolController#registerTool. Use this for initialization.
deregister()
This method is called by Autodesk.Viewing.ToolController#deregisterTool. Use this to clean up your tool.
activate(name, viewerApi)
The activate method is called by the ToolController when it adds this tool to the list of those to receive event handling calls. Once activated, a tool’s "handle*" methods may be called if no other higher priority tool handles the given event. Each active tool’s "update" method also gets called once during each redraw loop.
Parameters
| name* string | The name under which the tool has been activated. |
| viewerApi* Autodesk.Viewing.Viewer3D | Viewer instance. |
deactivate(name)
The deactivate method is called by the ToolController when it removes this tool from the list of those to receive event handling calls. Once deactivated, a tool’s "handle*" methods and "update" method will no longer be called.
Parameters
| name* string | The name under which the tool has been deactivated. |
update(highResTimestamp)
The update method is called by the ToolController once per frame and provides each tool with the oportunity to make modifications to the scene or the view.
Parameters
| highResTimestamp* number | The process timestamp passed to requestAnimationFrame by the web browser. |
Returns
| type | description |
|---|---|
| boolean | A state value indicating whether the tool has modified the view or the sceneand a full refresh is required. |
handleSingleTap(event)
This method is called when a single tap on a touch device occurs.
Parameters
| event* Event | The triggering event. For tap events the canvasX, canvasY properties containthe canvas relative device coordinates of the tap and the normalizedX, normalizedY properties containthe tap coordinates in the normalized [-1, 1] range. The event.pointers array will containeither one or two touch events depending on whether the tap used one or two fingers. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleDoubleTap(event)
This method is called when a double tap on a touch device occurs.
Parameters
| event* Event | The triggering event. For tap events the canvasX, canvasY properties containthe canvas relative device coordinates of the tap and the normalizedX, normalizedY properties containthe tap coordinates in the normalized [-1, 1] range. The event.pointers array will containeither one or two touch events depending on whether the tap used one or two fingers. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleKeyDown(event, keyCode)
This method is called when a keyboard button is depressed.
Parameters
| event* KeyboardEvent | The event object that triggered this call. |
| keyCode* number | The numerical key code identifying the key that was depressed.Note that the keyCode parameter value may be different that the value indicated in the event objectdue to key re-mapping preferences that may be applied. This value should be respectedover the value in the event object. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleKeyUp(event, keyCode)
This method is called when a keyboard button is released.
Parameters
| event* KeyboardEvent | The event object that triggered this call. |
| keyCode* number | The numerical key code identifying the key that was released.Note that the keyCode parameter value may be different that the value indicated in the event objectdue to key re-mapping preferences that may be applied. This value should be respectedover the value in the event object. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleWheelInput(delta)
This method is called when a mouse wheel event occurs.
Parameters
| delta* number | A numerical value indicating the amount of wheel motion applied.Note that this value may be modified from the orignal event values so as to provide consistent resultsacross browser families. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleMouseMove(event)
This method is called when a mouse motion event occurs.
Parameters
| event* MouseEvent | The event object that triggered this call. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleGesture(event)
This method is called when a touch gesture event occurs.
Parameters
| event* Event | The event object that triggered this call. The event.type attribute will indicatethe gesture event type. This will be one of: dragstart, dragmove, dragend, panstart, panmove, panend,pinchstart, pinchmove, pinchend, rotatestart, rotatemove, rotateend, drag3start, drag3move, drag3end.The event.canvas[XY] attributes will contain the coresponding touch position.The event.scale and event.rotation attributes contain pinch scaling and two finger rotation quantitiesrespectively. The deltaX and deltaY attributes will contain drag offsets. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleBlur(event)
This method is called when the canvas area loses focus.
Parameters
| event* FocusEvent | The event object that triggered this call. |
Returns
| type | description |
|---|---|
| boolean | True if this tool wishes to consume the event and false to continue to pass the eventto lower priority active tools. |
handleResize()
This method is called on every active tool whenever the screen area changes. The new canvas area can be obtained from the Navigation interface via the getScreenViewport method.