Main Content

本页采用了机器翻译。点击此处可查看英文原文。

addAttribute

类: slreq.ReqSet
命名空间: slreq

将自定义属性添加到需求集

自 R2020b 起

语法

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

说明

addAttribute(rs,name,type) 将具有 name 指定的名称和 type 指定的自定义属性类型的自定义属性添加到需求集rs 中。

addAttribute(rs,name,'Checkbox','DefaultValue',value) 向需求集rs 添加 Checkbox 自定义属性,其名称由 name 指定,默认值由 value 指定。

addAttribute(rs,name,'Combobox','List',options)name 指定的名称的 Combobox 自定义属性和 options 指定的列表选项添加到需求集rs 中。

addAttribute(rs,___,'Description',descr) 将具有 name 指定的名称、type 指定的类型和 descr 指定的描述的自定义属性添加到需求集rs 中。

输入参数

全部展开

需求集,指定为 slreq.ReqSet 对象。

自定义属性名称,指定为字符数组。

自定义属性类型,指定为字符数组。有效的自定义属性类型是 EditCheckboxComboboxDateTime

自定义属性描述,指定为字符数组。

Checkbox 默认值,指定为逻辑 1 (true)0 (false)

Combobox 列出选项,指定为元胞数组。仅当 'Unset' 是第一个条目时,选项列表才有效。'Unset' 表示用户尚未从组合框中选择选项。如果列表不是以 'Unset' 开头,它将自动附加为第一个条目。

示例: {'Unset','A','B','C'}

示例

全部展开

此示例显示如何向需求集添加所有四种类型的自定义属性,EditCheckbox、Combobox 和 DateTime,以及如何添加带有描述的自定义属性。

添加 Edit 自定义属性

加载描述巡航控制系统的crs_req_func_spec并将其分配给变量。

rs = slreq.load('crs_req_func_spec');

添加Edit自定义属性。使用 inspectAttribute 确认属性已成功添加。

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

添加 Checkbox 自定义属性

添加具有默认值 trueCheckbox 自定义属性。使用 inspectAttribute 确认属性已成功添加。

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

添加 Combobox 自定义属性

添加 ComboBox 自定义属性,其选项为 UnsetABC。使用 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'}

添加 DateTime 自定义属性

添加DateTime自定义属性。使用 inspectAttribute 确认属性已成功添加。

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

添加带有说明的自定义属性

添加Edit自定义属性。为自定义属性添加描述。使用 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.'

添加 ComboBox 自定义属性,其选项为 UnsetABC。为自定义属性添加描述。使用 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'}

清理

清除打开的需求集并关闭打开的模型而不保存更改。

slreq.clear;
bdclose all;

版本历史记录

在 R2020b 中推出