The control that lets a user graphically select a numeric value within a bounded interval by sliding the knob.
Slider elements are commonly used for modifying values of numeric
variables and parameters at the model runtime.
Use sliders to choose an int or a double value from the defined range. To work with text variables or parameters of String type, use text input in the edit boxes instead. To control the values of boolean type variables, use the check-boxes.
Demo model: Slider Linked To Parameter
To add a slider
Name – The name of the slider. It is used to identify and access the control from code.
Ignore – If selected, the slider will be excluded from the model.
Visible on upper agent – If selected, the control will be also visible on the upper agent where this agent lives.
Lock – If selected, the slider is locked. Locked shapes do not react to mouse clicks - it is impossible to select them in the graphical editor until you unlock them.
Orientation – Orientation of the slider, either Vertical or Horizontal.
Link to – If you want to bind the slider with a numeric variable or a parameter (on changing the value of the slider, the linked variable/parameter immediately gets this value), select this checkbox and enter the name of the variable/parameter that you want to link to the slider.
Minimum value – The minimum value of the slider.Maximum value – The maximum value of the slider.
Step
– Here you can specify the increment in which the slider's knob can
move along the interval from the minimum value to the maximum value.
The step can be of either int or double type. The default type is double.
Default value – [Visible if the Link to checkbox is not selected] The expression that defines the default slider value. If this slider is linked to some variable or parameter, it uses the default value of this variable/parameter (or the nearest possible value from the slider's range of available values) as its default value.
Enabled – Here you can specify the boolean expression determining whether the slider is enabled or disabled.
Add labels – Click this button to add labels displaying maximum, minimum, and current values of the slider (min, value, max). The dynamic properties of the labels are set up to display min, current and max values of the slider at the model runtime. These labels are regular text shapes, which can be relocated, resized, deleted, and recolored.
Here you can type the code to execute when the user changes the slider position. The current value of the slider is available here as value (variable of type double).
Level – Level to which this control belongs.
X – X-coordinate of the control's upper left corner.
Y – Y-coordinate of the control's upper left corner.
Width – The width of the control (in pixels).
Height – The height of
the control (in pixels).
Visible – The control's visibility. The control is visible when the specified expression evaluates to true, otherwise it is not visible.
Replication – Here you specify the number copies of this control you want to be created. If you leave this field empty, only one such control will be created.
Show name – If
selected, the name of the control will be displayed on a presentation
diagram.
A slider is frequently bound with a numeric variable or a parameter (on
changing the value of the slider, the linked parameter/variable
immediately gets this value).
To link a slider to a
parameter
Another way to link to a parameter is to select the required parameter, or the flowchart block in the graphical editor.
To link a slider to a
parameter by selecting it in the graphical editor
You can set the value of the slider:
In case of using the value of the linked element to
set the value of the slider, the new value can be outside of the
slider's step grid, defined in the Step property of the slider, or the
slider's range, defined by the slider's Minimum value and Maximum value. In this case, a warning will be appear in the Console view, the knob of the slider will move to the closest value that fits the slider's specified Range and Step, and the linked parameter or variable will be set to this value as well.
Function |
Description |
double getValue() |
Returns the current value of the slider. |
int getIntValue() |
Returns the current int
value of the slider. |
Function |
Description |
void setValue(double value) |
Sets
the value of the slider. If you
call this function at runtime and set the new value out of the
specified range, the slider's value will be corrected to the closest
possible value inside the slider's range and step grid and a warning
will be displayed. Doesn't execute user action code. Parameter: |
void setValue(double value, boolean callAction) |
Sets the value of the slider. Action is executed in
the
same thread. Executes user action code (if there is any) if the callAction parameter is true. If
you call this function at runtime and set the new value out of the
specified range, the slider's value will be corrected to the closest
possible value inside the slider's range and step grid and a warning
will be displayed. If the user action code refers to the new value, the
corrected value will be applied. |
void setValueToDefault() |
Sets the value of the slider to what was provided as the default one. Doesn't execute user action code. |
Function |
Description |
double getMin() |
Returns the minimum value of the slider. |
double getMax() |
Returns the maximum value of the slider. |
void setRange(double min, double max) |
Sets the minimum and maximum values of the slider. Doesn't execute user action code. If the slider is configured to work with int values (linked to a variable or parameter of the int type), the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds). This function does nothing if the slider already has such range. If the current value of the slider is out of the new specified range, it will be snapped to the closest possible value inside the slider's new range. The value of the linked parameter will remain unchanged.
Parameters: |
void setRange(double min, double max, boolean callAction) |
Sets the minimum and maximum values of the slider. If the value of the current slider changes, the function will execute user action code (if there is any) in the same thread - if the callAction parameter is true. If slider is configured to work with int values (linked to a variable or parameter of the int type), the given [min, max] range may be automatically corrected to have integer bounds (within the given double bounds). This function does nothing if the slider already has such range. If the current value of the slider is out of the new specified range, it will be snapped to the closest possible value inside the slider's new range. The value of the linked parameter will remain unchanged. Parameters: |
Function |
Description |
double getStep() |
Returns the value of the slider's step. |
void setStep(double step) |
Sets the value of the slider's step. If the current value of the slider is not on of the slider's new step grid, it will be snapped to the closest possible value inside the slider's new step grid. The value of the linked parameter will remain unchanged. Parameter: |
Function |
Description |
boolean isEnabled() |
Tests if the control is enabled or disabled. Returns true if enabled, otherwise false. |
void setEnabled(boolean yes) |
Sets the control enabled or disabled. Parameter: |
Function |
Description |
void action() |
Executes the action associated with the slider. |
Function |
Description |
double getX() |
Returns the X coordinate of the control (namely, the X coordinate of its upper left corner). |
double getY() |
Returns the Y coordinate of the control (namely, the Y coordinate of its upper left corner). |
void setX(double x) |
Sets the X coordinate of the control. |
void setY(double y) |
Sets the Y coordinate of the control. |
void setPos(double x, double y) |
Sets new coordinates for the control. Parameters: |
Function |
Description |
boolean isVisible() |
Returns the visibility of the control. |
void setVisible(boolean v) |
Sets the visibility of the control. Parameter: |