Interactive UI: Declarative Interface Example

Updated: 2025-05-24

This example demonstrates the use of all available UI element types in GPSS-Plus.

By declaring UI blocks, a floating window is automatically created containing the defined controls (buttons, inputs, sliders, etc.). Each control has a TRIGGER, which executes when the user interacts with it. The trigger launches a virtual entity that carries the interaction data and can act upon the model.

Additionally, GPSS can modify control values in real-time using the SET_UI command, allowing for two-way synchronization between the simulation state and the user interface.

Key Features:

  • Declarative Design: No complex coding required to build control panels.
  • Interactive Triggers: Use PP$A to get the element ID and PP$B for its value.
  • Dynamic Feedback: Update the UI from within the simulation logic to show status changes.

Example

;========== DECLARATIVE UI ==========
UI {TYPE: BUTTON, id:botonA, TEXT: "Launch Entity A", LABEL: "Button A", TRIGGER: lanzarA}
UI {TYPE: BUTTON, id:botonB, TEXT: "Launch Entity B", LABEL: "Factory Reset", TRIGGER: lanzarB}

UI {TYPE: INPUT, ID: unInput, LABEL: "Name", VALUE: "Alice", TRIGGER: capturarInput}
UI {
  TYPE: SLIDER, ID: unSlider, LABEL: "Speed",
  VALUE: 1, MIN: 0.1, MAX: 2, STEP: 0.1,
  TRIGGER: capturarInput
}
UI {TYPE: SELECT, id:unSelect, LABEL: "Mode", OPTIONS: "Normal,Advanced,Turbo", TRIGGER: capturarInput}
UI {TYPE: CHECKBOX, id:unCheck, LABEL: "Activate Turbo", VALUE: 1, TRIGGER: capturarInput}
UI {TYPE: RADIO, id:unRadio, LABEL: "Color", OPTIONS: "Red,Green,Blue", TRIGGER: capturarInput}

;========== GRAPHICS ==========
GRAPHIC {NAME:infoTexto, TYPE:TEXT, X:400, Y:100, TEXT:"Waiting..."}
GRAPHIC {NAME:infoDato, TYPE:TEXT, X:400, Y:130, TEXT:"No value yet"}

;========== POSITIONS AND ANIMATION ==========
POSITION {NAME:ENTRADA, X:200, Y:220}
POSITION {NAME:SALIDA, X:500, Y:220}

START 100
;-----------------------------------------------------------------

GENERATE 0,0,0,0 {NAME:GEN_A, X:102,Y:161,ECOLOR:#0099ff}
ADVANCE 10,0 {TO:ENTRADA}
ADVANCE 10,0 {TO:SALIDA}
TERMINATE 1

GENERATE 0,0,0,0 {NAME:GEN_B, X:104,Y:406,ECOLOR:#ff9900}
ADVANCE 10,0 {TO:ENTRADA}
ADVANCE 10,0 {TO:SALIDA}
SET_UI unSlider, 1.5
SET_UI unInput, "Path B Finished"
SET_UI unSelect, "Turbo"
SET_UI unRadio, "Blue"
SET_UI unCheck, 1

TERMINATE 1

;========== PROCEDURES ==========
PROCEDURE lanzarA
  NEW GEN_A
  TERMINATE
ENDPROCEDURE 1

PROCEDURE lanzarB
  NEW GEN_B
  TERMINATE
ENDPROCEDURE 1

PROCEDURE capturarInput
  MOVE {NAME:infoTexto, TEXT:"ID = PP$A"}
  MOVE {NAME:infoDato, TEXT:"VALUE = PP$B"}

  ; Example: if specific ID is interacted with, update UI from GPSS
  IF "botonA",==,"PP$A"
    SET_UI velSlider, 1.5
  ENDIF

  TERMINATE
ENDPROCEDURE 1