SmartComponent GUI
This walk-through showcases the SmartComponent's User Interface's customization that RobotStudio automatically generates from the Properties and Signals declared on the SmartComponent's XML file.
The User Interface not only represents the value of the property/signal, but it can also be customized to show data or accept input in many different ways by tweaking with the Properties Attributes (as well as some declaration options in the Signals). In this walk through, the process of creating a SmartComponent that showcases the attributes of its Dynamic Properties is created.
Download
The files for this project can be downloaded here.
Assigning the Dynamic Properties' Attributes
Create a default DynamicProperty (i.e. with no Attributes) with the following snippet.
<DynamicProperty name="DefaultProperty" valueType="System.Double"></DynamicProperty>
Dynamic Properties also accept the ReadOnly , UIVisible and Value properties in the same way as IOsignals. For more information, refer to the IO Signals topic.
Assign MinValue and MaxValue to set value limits for a property. In this snippet, the declared property will take values between 0 and 10.
<DynamicProperty name="RangedProperty" valueType="System.Double"> <Attribute key="MinValue" value="0" /> <Attribute key="MaxValue" value="10"/> </DynamicProperty>
Use the AllowedValues attribute to let the user chose from a set of predefined values presented in a combo-box,
<DynamicProperty name="EvenNumbersProperty" valueType="System.Int32"> <Attribute key="AllowedValues" value="0;2;4;6;8;10" /> </DynamicProperty>
Control the length of a string using the MinLength and MaxLength attribute.
<DynamicProperty name="fiveToTenChars" valueType="System.String"> <Attribute key="minLength" value="5"/> <Attribute key="maxLength" value="10"/> </DynamicProperty>
Control which characters can be part of the string property with the AllowedCharacters attribute.
<DynamicProperty name="onlyVowels" valueType="System.String"> <Attribute key="AllowedCharacters" value="a;e;i;o;u;A;E;I;O;U"/> </DynamicProperty>
Use the Quantity attribute to specify what type of numeric magnitude the property represents. Properties with this attribute enabled will display the type of unit they represent in their labels, the setting will be also be reflected in the available options for the property.
<DynamicProperty name="Seconds" valueType="System.Int32"> <Attribute key="Quantity" value="Time"/> </DynamicProperty>
Enable the AutoApply attribute so the user does not need to click the Apply button to update the value of the property.
<DynamicProperty name="AutomaticApply" valueType="System.Int32"> <Attribute key="AutoApply" value="true"/> </DynamicProperty>
Use the Slider attribute changes the Property's control to a Slider. Remember to specify the MinValue and MaxValue attributes too.
<DynamicProperty name="Slider" valueType="System.Double" value="5" > <Attribute key="MinValue" value ="1"/> <Attribute key="MaxValue" value ="20"/> <Attribute key="Slider" value="True"/> </DynamicProperty>
Enable the CustomValidation attribute so that the QueryPropertyValueValid(SmartComponent, DynamicProperty, Object) method is called when a new value is introduced.
<DynamicProperty name="NotifyWhenChanged" valueType="System.Int32"> <Attribute key="CustomValidation" value="true"></Attribute> </DynamicProperty>
Modify the QueryPropertyValueValid(SmartComponent, DynamicProperty, Object) function in the "CodeBehind.cs" file by adding the following snippet. The following code will print messages when the Dynamic Property "NotifyWhenChanged" changes.
public override ValueValidationInfo QueryPropertyValueValid( SmartComponent component, DynamicProperty owningProperty, object newValue) { // Debug the SC and change the properties value to see the messages Logger.AddMessage(new LogMessage("The property " + owningProperty.Name + ", of the Component " + component.Name +" has changed")); Logger.AddMessage(new LogMessage("The new value is " + newValue.ToString())); return base.QueryPropertyValueValid( component, owningProperty, newValue); }
Note
It is a common scenario to use several Properties or SmartComponents that call the QueryPropertyValueValid(SmartComponent, DynamicProperty, Object) function. In this case, use the "component" and the "owningProperty" arguments to address several SmartComponents and/or Properties with the same function.
Allow only values that compel with the declared string in the ValueFilter attribute.
<DynamicProperty name="StartsWithHello" valueType="System.String"> <Attribute key="ValueFilter" value="Hello*"/> </DynamicProperty>
Add the property value to the name of the SmartComponent by enabling the AddToDisplayName attribute.
<DynamicProperty name="AddToName" valueType="System.String"> <Attribute key="AddToDisplayName" value="True"></Attribute> </DynamicProperty>
Use the DisplayValues attribute to specify the names of the values that appear in the user interface. For this attribute to take effect, the AllowedValues must be in use.
<DynamicProperty name="DisplayValues" valueType="System.Int32"> <Attribute key="DisplayValues" value="first;second;third"></Attribute> </DynamicProperty>
Specify between "Position" and "Direction" in the VectorUsage attribute in order to clarify what the vector dataType represents.
<DynamicProperty name="Direction" valueType="ABB.Robotics.Math.Vector3"> <Attribute key="VectorUsage" value="Direction"/> </DynamicProperty>
Allow string values with one or several lines and display a bigger text box in the user interface with the Multiline attribute.
<DynamicProperty name="MultiLine" valueType="System.String"> <Attribute key="Multiline" value="True"/> </DynamicProperty>