Viewer provide OccViewer.OccViewerCommands for defining interactive commands. Commands API relies on events API OccViewer.EventManager by listening and producing some events from OccViewer.UserEvents. For instance, 'onTextRequest' event is emitted when interactive text input is expected from user. Developer may register a listener to this event to show some text input form to the user. Viewer implements several standard interactive commands like OccViewer.AddTextLabelCommand.

Example of usage:

import { AddTextLabelCommand, AddLengthDimensionCommand, CommandExecutor } from '/wasm32/OccViewer.js';

// create command executor
const aCommandExecutor = new CommandExecutor(OccViewerModule);

// add on command success handler
OccViewerModule.eventManager.addEventListener(UserEvents.onSuccess, ()=>{
// on command success handler
...
return 0;
});

// add on command cancel handler
OccViewerModule.eventManager.addEventListener(UserEvents.onCancel, ()=>{
// on command cancel handler code
...
return 0;
});

// add on text request handler which provides an input from user
// and pass it to the command executor
OccViewerModule.eventManager.addEventListener(UserEvents.onTextRequest, ()=>{
let anInitialValue = aCommandExecutor.activeCommand().initialValue;
let aText = prompt( "Please input the text", anInitialValue);
aCommandExecutor.onTextInput(aText);
return 0;
});

// add on onUserMessage handler (usually it is text with information for user)
OccViewerModule.eventManager.addEventListener(UserEvents.onUserMessage, ()=>{
console.log(aCommandExecutor.message);
return 0;
});

...

// execute example of command
aCommandExecutor.call(AddTextLabelCommand);