Main Content

addAttribute

Class: slreq.ReqSet
Package: slreq

Add custom attribute to requirement set

Syntax

addAttribute(rs,name,type)
addAttribute(rs,name,'Checkbox','DefaultValue',value)
addAttribute(rs,name,'Combobox','List',options)
addAttribute(rs,___,'Description',descr)

Description

addAttribute(rs,name,type) adds a custom attribute with the name specified by name and the custom attribute type specified by type to the requirement set rs.

addAttribute(rs,name,'Checkbox','DefaultValue',value) adds a Checkbox custom attribute with the name specified by name and the default value specified by value to the requirement set rs.

addAttribute(rs,name,'Combobox','List',options) adds a Combobox custom attribute with the name specified by name, and the list options specified by options to the requirement set rs.

addAttribute(rs,___,'Description',descr) adds a custom attribute with the name specified by name, the type specified by type, and the description specified by descr to the requirement set rs.

Input Arguments

expand all

Requirement set, specified as an slreq.ReqSet object.

Custom attribute name, specified as a character array.

Custom attribute type, specified as a character array. The valid custom attribute types are Edit, Checkbox, Combobox, and DateTime.

Custom attribute description, specified as a character array.

Checkbox default value, specified as a logical 1 (true) or 0 (false).

Combobox list options, specified as a cell array. The list of options is valid only if 'Unset' is the first entry. 'Unset' indicates that the user hasn't chosen an option from the combo box. If the list does not start with 'Unset', it will be automatically appended as the first entry.

Example: {'Unset','A','B','C'}

Examples

expand all

This example shows how to add a custom attribute of all four types to a requirement set, Edit, Checkbox, Combobox, and DateTime, and how to add a custom attribute with a description.

Add an Edit Custom Attribute

Load crs_req_func_spec, which describes a cruise control system. Find the requirement set and assign it to a variable.

slreq.load('crs_req_func_spec');
rs = slreq.find('Type','ReqSet');

Add an Edit custom attribute. Confirm that the attribute was successfully added by using inspectAttribute.

addAttribute(rs,'MyEditAttribute','Edit');
atrb = inspectAttribute(rs,'MyEditAttribute')
atrb = struct with fields:
           name: 'MyEditAttribute'
           type: Edit
    description: ''

Add a Checkbox Custom Attribute

Add a Checkbox custom attribute with the default value true. Confirm that the attribute was successfully added by using inspectAttribute.

addAttribute(rs,'MyCheckbox','Checkbox','DefaultValue',true);
atrb2 = inspectAttribute(rs,'MyCheckbox')
atrb2 = struct with fields:
           name: 'MyCheckbox'
           type: Checkbox
    description: ''
        default: 1

Add a Combobox Custom Attribute

Add a ComboBox custom attribute with the options Unset, A, B, and C. Confirm that the attribute was successfully added by using inspectAttribute.

addAttribute(rs,'MyCombobox','Combobox','List',{'Unset','A','B','C'});
atrb3 = inspectAttribute(rs,'MyCombobox')
atrb3 = struct with fields:
           name: 'MyCombobox'
           type: Combobox
    description: ''
           list: {'Unset'  'A'  'B'  'C'}

Add a DateTime Custom Attribute

Add a DateTime custom attribute. Confirm that the attribute was successfully added by using inspectAttribute.

addAttribute(rs,'MyDateTime','DateTime');
atrb4 = inspectAttribute(rs,'MyDateTime')
atrb4 = struct with fields:
           name: 'MyDateTime'
           type: DateTime
    description: ''

Add a Custom Attribute with a Description

Add an Edit custom attribute. Add a description to the custom attribute. Confirm that the attribute was successfully added by using inspectAttribute.

addAttribute(rs,'MyEditAttribute2','Edit','Description',...
    'You can enter text as the custom attribute value.');
atrb5 = inspectAttribute(rs,'MyEditAttribute2')
atrb5 = struct with fields:
           name: 'MyEditAttribute2'
           type: Edit
    description: 'You can enter text as the custom attribute value.'

Add a ComboBox custom attribute with the options Unset, A, B, and C. Add a description to the custom attribute. Confirm that the attribute was successfully added by using inspectAttribute.

addAttribute(rs,'MyCombobox2','Combobox','List',{'Unset','A','B','C'},'Description',...
    'This combobox attribute has 4 options.');
atrb6 = inspectAttribute(rs,'MyCombobox2')
atrb6 = struct with fields:
           name: 'MyCombobox2'
           type: Combobox
    description: 'This combobox attribute has 4 options.'
           list: {'Unset'  'A'  'B'  'C'}

Cleanup

Clear the open requirement sets and close the open models without saving changes.

slreq.clear;
bdclose all;
Introduced in R2020b