Data Accessors
Data accessors hold a value or a pointer to values. They define the type of a given attribute. They are similar to variable declarations in a programming language such as C++. All attributes should contain one of these accessors and no more.
Note: Some accessors also hold a value (Rotate for instance), which means values that hold them do not need an extra Data accessor. |
The different Data accessors are described as follows:
Value
The Value accessor (class
IlvValueAccessor) lets you attach an attribute holding a value to a prototype. When the value is modified, it is simply stored. When the value is queried, the last value stored is returned.
Parameters
No parameters, but the type of the value must be specified since it cannot be deduced.
Example:
The invertedColor attribute in the pump prototype of the samples prototype library stores a color name as a temporary variable.
Reference
The Reference accessor (class
IlvNodeAccessor) is used to reference an attribute of one of the prototype nodes (also called sub-attributes) at the prototype level. When the corresponding attribute is changed, the new value is forwarded to the specified sub-accessor. Conversely, when the attribute is queried, it is first queried from the node and forwarded to the prototype. A Reference accessor is similar to a reference (a pointer or an alias) in a programming language.
Parameters
Accessor: Node attribute or prototype value that holds the value. The type of the value is determined by what the accessor points to.
Example
The steps attribute in the thermo prototype of the samples library points directly to the steps attribute of the scale object. When the attribute steps is set, it is assigned to the scale.step attribute. If the scale.step attribute is changed by the program, any query of the attribute returns the new value.
Group
The Group accessor (class
IlvGroupUserAccessor) defines an attribute that will collectively reference all the sub-attributes of the same name in all group nodes. For example, you can use this accessor with the name
foreground and the type
Color to change the foreground color of all the prototype elements in one single assignment.
Parameters
No parameters. The name of the attribute is used to determine the subattribute that will be referenced by this accessor. The type of the accessor is implicitly determined.
Example
In the pump prototype of the samples prototype library, a lineWidth attribute can be added. The attribute should be of type UInt. Changing this attribute from the Group Inspector (using the Attributes notebook page) changes the line width of all the graphic objects that have a lineWidth defined.
Script
The Script accessor (
IlvJavaScriptAccessor) class lets you program the behavior of your prototypes using the scripting language interpreter included in Rogue Wave Views Studio.
A Script accessor has two parameters, which are the names of script functions:
The
set function is called when the value of the accessor is changed. It must be of the form:
function SetX(obj, newval)
{
...
}
The obj argument is the prototype associated with the accessor. The newval argument is the new value that has been assigned to the attribute.
The
get function is called when the value of the accessor is queried. It must be of the form:
function GetX(obj)
{
...
return(val);
}
The obj argument is the prototype associated with the accessor. The function must return a value, which becomes the new value of the attribute.
In the functions associated with a Script accessor, you can access and modify any prototype attribute or a prototype node. Either one of the two function names of the Script accessors can be none, in which case no function is called.
The functions associated with a Script accessor can be edited using the Rogue Wave Views Studio Script Editor. They will be saved in a file with a .ijs suffix in the same directory and with the same file name as the prototype. Otherwise, they are saved in the prototype file or its library file.
Note: Naming conflicts can occur if you load several prototype instances with the same function names in the same panel. Therefore, it is a good idea to prefix the names of all the prototype script functions with the prototype name they belong to. For instance, in the samples.thermo prototype, if the Temp value has a Script accessor, its functions should be called SamplesThermoTempGet() and SamplesThermoTempSet(). |
Parameters
Script function (set): The name of the script function to execute when the attribute is changed.
Script function (get): The name of the script function to execute when the attribute is queried.
The type is determined by the value returned from the
set function or taken as a parameter by the
get function. It can, therefore, change dynamically.
Examples
The following function can be used to perform an action similar to a Condition accessor:
function SetTemperature(obj, temperature)
{
if(temperature > obj. threshold) {
obj.gauge.foreground = "red";
} else {
obj.gauge.foreground = "blue";
}
}
function GetTemperature(obj)
{
return obj.gauge.foreground;
}
Version 6.2.1
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.