If the user enters a coordinate in the command line, your class triggers 'pickCoordinate(event, preview)'.
Where 'event.getModelPosition()' is an RVector with the coordinate entered and 'preview' is 'true' if the user is still busy entering the coordinate and 'false' if the user has pressed enter to confirm the input.
'pickCoordinate' is also called when the user clicks a coordinate with the mouse, so you might already have that implemented anyway.
If the user enters anything that is not a coordinate (i.e. a double value or simply text), 'applyCommand(event, preview)' is called. 'event.getCommand()' holds the exact string that was entered by the user. You can separate between values and commands by trying to interpret the input:
- Code: Select all
var value = RMath.eval(event.getCommand());
if (isNaN(value)) {
qDebug("Entered command is: ", event.getCommand());
}
else {
qDebug("Entered value is: ", value);
}
For a complete and simple example, have a look at the script 'scripts/Draw/Circle/CircleCR/CircleCR.js' which allows the user to enter the circle radius in the command line, followed by the circle center coordinate.