2D Graphics > Prototypes > Predefined Accessors > Control Accessors
 
Control Accessors
Control accessors perform side effects on other attributes when they are evaluated. They represent the control structures and instructions of a programming language. In the Group Inspector, you can view them from the “Behaviors” and “Interaction” notebook pages, under the “do” clause attached to each attribute.
Note: These accessors are write-only. They do not record the last value tested. If you only define a Control accessor for a value, you will not be able to read this value back. To store the value associated with an accessor, you must define a Value accessor with the same name.
The different Control accessors are described as follows:
*Assign
*Condition
*Format
*Increment
*Min/Max
*Multiple
*Notify
*Script
*Switch
*Toggle
Assign
The Assign accessor (class IlvTriggerAccessor) is used to assign a value to another attribute or sub-attribute. When the attribute is set, the target attribute specified by the target parameter is assigned the specified value.
Parameters
*Attribute: Attribute that is modified when this accessor is evaluated.
*Send: Attribute or expression that is assigned to Attribute.
*The type of the accessor is undetermined and irrelevant.
Example
The lcd2 prototype of the lcd library uses the Assign accessor.
Condition
The Condition accessor (class IlvConditionAccessor) is used to perform a conditional assignment of another attribute when the attribute is changed.
The first parameter defines a condition operator that is applied to the new value of the attribute. For example, if the value of the attribute is changed to 10, the operator parameter is >, and the operand is 5, the condition tested is 10 > 5. If the operator is [Operand_value], the condition tested is only the value of the operand parameter (that is, the new value passed to changeValue is ignored).
Depending on the test result, the attribute specified by the Attribute parameter is set to one of two values: Value if True or Value if False. The parameters Operand, Value if True, or Value if False can be either immediate values (such as 1 or "red"), the names of other attributes that will be queried to get the values used, or an expression containing these immediate values or attribute names.
Parameters
*Operator: The operator used to test the conditions. It can be one of the following: ==, !=, >=, <, <=, or [Operand_value].
*Operand: The operand value.
*Attribute: Prototype value or node attribute that will be set to true or false, depending on the condition.
*Value if True: Value to which the output is set if the condition is true (or non 0).
*Value if False: Value to which the output is set if the condition is false (or 0).
*The type of the accessor is undetermined and irrelevant. However, it needs to be compatible with the operand type.
Example
The following example shows the thermo prototype in the samples prototype library. If the temperature attribute is above 30, the gauge is drawn in red. Otherwise, it is drawn in blue.
Format
The Format accessor (class IlvFormatAccessor) can be used to convert a numeric value of type Double to a character string using a user-specified format. The formatted string is then copied to another accessor. The format of the value is specified by the Format parameter, which is defined in the C library function printf. The numeric value is passed to the conversion function as an IlDouble, so the format should contain a %g specifier.
Parameters
*Format (printf-style): Format string as defined by the printf C library function and must be a String value. This string must contain at least one %g, since this accessor can only convert values of type Double.
*Max # of chars: Maximum length of the string after the conversion. If this length is exceeded, the value is replaced by * characters. It must be an Integer value.
*Attribute: Attribute to which the formatted value is assigned.
Example
In the display prototype in the samples prototype library, the Format accessor allows you to change in NumberField.label the way the value is displayed.
Increment
The Increment accessor (class IlvCounterAccessor) is used to increment another attribute. Each time the attribute containing this attribute is set, another attribute, called a counter, is increased by one until a specified maximum value is reached. When this value is reached, the counter is reset to zero.
Parameters
*Maximum: Maximum value. The value to increase is reset to 0 if it is equal to the maximum value.
*Attribute: Attribute to increment.
*The type of the accessor is undetermined and irrelevant.
Example
A three-state button can be implemented by using a Counter accessor linked to a MultiRep accessor. The following accessor has been added to the symbol prototype of the samples prototype library. Changing the state_incr value in the Attributes notebook page of the Group Inspector increments the state and switches its representation.
Min/Max
The Min/Max accessor (class IlvMinMaxAccessor) is similar to the Condition accessor but handles common cases when an attribute must be tested against a minimum and a maximum threshold. When the attribute is changed, another attribute is set. The assigned value depends on whether the value of the current attribute is less than the minimum, between the minimum and the maximum, or greater than the maximum. In addition, an exception condition can be specified: if the exception condition is true, no value is changed.
Parameters
*Minimum: Defines the minimum value.
*Maximum: Defines the maximum value.
*Except if: If this value is true, the value is ignored and the output value or attribute is not set. The expression must result in a Boolean value.
*Attribute: Attribute that is set to one of the following three values.
*If x < min: Value to which the attribute is set if the value is less than the minimum.
*If min < x < max: Value to which the attribute is set if the value is between the minimum and the maximum.
*If x > max: Value to which the attribute is set if the value is greater than the maximum.
Example 1
This accessor is attached to a Temperature attribute. When Temperature is set, if Nobody’s at Home is true, nothing is done. If the Temperature is below 15, HeatOn is assigned to ClimateControl. If Temperature is above 25, CoolingOn is assigned to ClimateControl. If the temperature is between 15 and 25, AllOff is assigned to ClimateControl.
Example 2
This example shows the vertGauge prototype in the sample library.
Multiple
The Multiple accessor (class IlvCompositeAccessor) assigns the value of the attribute to multiple other attributes or sub-attributes. It can be used, for example, to change the colors of two graphic nodes using a single public value of the prototype.
Parameters
*This accessor has a variable number of parameters. Each of these parameters is an attribute or subattribute, to which the value is assigned.
*All parameters must have compatible types.
Example
This example shows the Color accessor in the thermo prototype.
Notify
The Notify accessor (class IlvOutputAccessor) turns changeValue calls on the attribute to which it is attached into pushValue calls. Values that are watching the given attribute will execute all their behaviors.
This accessor triggers behaviors of other attributes that depend on the notifying value. For example, you can make a change in the Threshold attribute to also re-evaluate the Temperature attribute. This can be done by attaching a Notify accessor to the Threshold attribute, and a Watch (Threshold) behavior to the Temperature attribute.
Parameters
*No parameters.
Example
The following example shows the X_Scale attributes of the transformer prototype in the samples library.
Script
This accessor is described in Data accessors under Script.
Switch
The Switch accessor (class IlvSwitchAccessor) implements a switch statement.
Parameters
*Switch: An expression that should return an integer. Depending on its result, the attribute 0...N will be assigned the value of the parameter.
*case 0: Must be an attribute of the prototype or the value "". If Switch evaluates to 0, the behaviors of the attribute named in this parameter will be executed.
*case 1: If Switch evaluates to 1, the behaviors of the attribute named in this parameter will be executed.
*...
*case N: If Switch evaluates to a value equal to or greater than N, the behaviors of the attribute named in this parameter will be executed.
Example
A traffic light with varying settings can be implemented like this:
Value Integer
do
Switch Value
case 0 doRed
case 1 doOrange
case 2 doGreen
case 3 Anomaly
 
doRed
do
greenEllipse.visible=False
orangeellipse.visible=False
redEllipse.visible=True
doBlink=False
 
doOrange
do
greenEllipse.visible=False
orangeellipse.visible=True
redEllipse.visible=False
doBlink=False
 
doGreen
do
greenEllipse.visible=True
orangeellipse.visible=False
redEllipse.visible=False
doBlink=False
 
Anomaly
do
greenEllipse.visible=False
orangeellipse.visible=True
redEllipse.visible=False
doBlink=true
 
doBlink Boolean
do
blink orangeEllipse.visible 150
Toggle
The Toggle accessor (class IlvToggleAccessor) switches another attribute between true and false each time the attribute is set. The value assigned to the attribute containing a toggle behavior is ignored.
Parameters
*Boolean Attribute: Attribute that is switched when the behavior is evaluated. It must be a Boolean type (for example, the visibility attribute of the object).
Example
The following example shows the random prototype in the sources prototype library with the value toggle.

Version 6.1
Copyright © 2016, Rogue Wave Software, Inc. All Rights Reserved.