State Properties
User interactions with the display are not delivered through callbacks or events. Instead, they are exposed as boolean flag properties on the controller that you read in a cyclic script or a while loop.
The pattern is always the same:
- Check if the flag is
true - Reset the flag to
falseto acknowledge the interaction - Read the associated data property
Always reset the flag before doing heavy work. If your script takes a long time between the check and the reset, you may miss a second interaction.
Image click
imageClicked
Set to true when the user clicks on the image in the full-screen view.
imageClicked: boolean;
positionX / positionY
The image-space coordinates (in pixels) of the last click.
positionX: number;
positionY: number;
// INIT script
global var ctrl = Visu.page0.display1.getController();
// CYCLIC script
if (ctrl.imageClicked) {
ctrl.imageClicked = false;
var x = ctrl.positionX;
var y = ctrl.positionY;
printLog("Clicked at: " + x.toString() + ", " + y.toString());
}
Entity created
entityCreated
Set to true when the user finishes drawing a new entity with the draw tool.
entityCreated: boolean;
createdEntityData
Contains the data of the newly created entity. The shape of this object depends on the entity type — check the type field to discriminate. See the full interface reference for each entity type.
createdEntityData: IEntityCreatedData;
// CYCLIC script
if (ctrl.entityCreated) {
ctrl.entityCreated = false;
var data = ctrl.createdEntityData;
if (data.type === Ve.EVisionElement.Rect2d) {
var rect = data.data; // IEntityEditedData_Rect2d
printLog("New rect: " + rect.centerX.toString() + ", " + rect.centerY.toString());
}
}
After reading the created entity, you typically want to call setTool({ type: "select" }) to switch back to the selection tool, unless you want the user to draw again immediately.
Entity edited
entityEdited
Set to true when the user finishes editing an entity (moving nodes, resizing, etc.).
entityEdited: boolean;
editedEntityData
Contains the updated geometry of the edited entity. See the full interface reference for each entity type.
editedEntityData: IEntityEditedData;
// CYCLIC script
if (ctrl.entityEdited) {
ctrl.entityEdited = false;
var data = ctrl.editedEntityData;
printLog("Edited entity id: " + data.id.toString());
}
Selection changed
selectedIdsChanged
Set to true when the user changes the selection interactively in the display.
selectedIdsChanged: boolean;
selectedIds
The IDs of the currently selected elements.
selectedIds: number[];
// CYCLIC script
if (ctrl.selectedIdsChanged) {
ctrl.selectedIdsChanged = false;
var ids = ctrl.selectedIds;
printLog("Selected: " + ids.length.toString() + " elements");
}
selectedIds reflects the current selection at the moment you read it. If the user selects and then deselects before your cyclic script runs, selectedIdsChanged will be true but selectedIds will be empty.