Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

Requirements Toolbox API を使用した要件のカスタム属性の管理

この例では、Requirements Toolbox™ API を使用して、要件セットにカスタム属性を作成する方法と、要件にカスタム属性値を設定する方法を説明します。

要件セットの設定

クルーズ コントロール システムを表す要件ファイル crs_req_func_spec を読み込み、変数に代入します。

rs = slreq.load('crs_req_func_spec');

各タイプのカスタム属性の追加

要件セットに各タイプのカスタム属性を追加します。Edit カスタム属性を、説明付きで作成します。

addAttribute(rs,'MyEditAttribute','Edit','Description',...
    'You can enter text as the custom attribute value.')

Checkbox タイプの属性を作成し、その DefaultValue プロパティを true に設定します。

addAttribute(rs,'MyCheckboxAttribute','Checkbox','DefaultValue',true)

Combobox カスタム属性を作成します。1 つ目のオプションは 'Unset' でなければならないため、オプション 'Unset', 'A', 'B', and 'C' を追加します。

addAttribute(rs,'MyComboboxAttribute','Combobox','List',{'Unset','A','B','C'})

DateTime カスタム属性を作成します。

addAttribute(rs,'MyDateTimeAttribute','DateTime')

要件セットに定義されたカスタム属性をチェックします。MyComboboxAttribute に関する情報を取得し、追加したオプションを確認します。

rs.CustomAttributeNames
ans = 1x4 cell
    {'MyCheckboxAttribute'}    {'MyComboboxAttribute'}    {'MyDateTimeAttribute'}    {'MyEditAttribute'}

atrb = inspectAttribute(rs,'MyComboboxAttribute')
atrb = struct with fields:
           name: 'MyComboboxAttribute'
           type: Combobox
    description: ''
           list: {'Unset'  'A'  'B'  'C'}

要件に対するカスタム属性値の設定

要件セットに含まれる要件を 1 つ特定し、作成した 4 つのカスタム属性すべてにカスタム属性値を設定します。

req = find(rs,'Type','Requirement','SID',3);
setAttribute(req,'MyEditAttribute','Value for edit attribute.');
setAttribute(req,'MyCheckboxAttribute',false);
setAttribute(req,'MyComboboxAttribute','B');

MyDateTimeAttribute を必要に応じたロケールで設定し、他のロケールのシステムで日時が正しい形式で設定されていることを確認します。詳細については、Localeを参照してください。

localDateTimeStr = datestr(datetime('15-Jul-2018 11:00:00','Locale','en_US'),'Local');
setAttribute(req,'MyDateTimeAttribute',localDateTimeStr);

属性値を表示します。

getAttribute(req,'MyEditAttribute')
ans = 
'Value for edit attribute.'
getAttribute(req,'MyCheckboxAttribute')
ans = logical
   0

getAttribute(req,'MyComboboxAttribute')
ans = 
'B'
getAttribute(req,'MyDateTimeAttribute')
ans = datetime
   15-Jul-2018 11:00:00

カスタム属性の編集

リンク セットにカスタム属性を定義した後、カスタム属性に限定的な変更を行えます。

MyCheckboxAttributeMyComboboxAttribute に説明を追加し、MyComboboxAttribute のオプション リストを変更します。Checkbox 属性の既定値は更新できないため、MyCheckboxAttribute では説明のみを更新できます。変更内容を表示します。

updateAttribute(rs,'MyCheckboxAttribute','Description',...
    'The checkbox value can be true or false.');
updateAttribute(rs,'MyComboboxAttribute','Description',...
    'Choose an option from the list.','List',{'Unset','1','2','3'});
atrb2 = inspectAttribute(rs,'MyCheckboxAttribute')
atrb2 = struct with fields:
           name: 'MyCheckboxAttribute'
           type: Checkbox
    description: 'The checkbox value can be true or false.'
        default: 1

atrb3 = inspectAttribute(rs,'MyComboboxAttribute')
atrb3 = struct with fields:
           name: 'MyComboboxAttribute'
           type: Combobox
    description: 'Choose an option from the list.'
           list: {'Unset'  '1'  '2'  '3'}

カスタム属性値に一致する要件の検索

要件セットで、'MyEditAttribute''Value for edit attribute.' に設定されているすべての要件を検索します。

req2 = find(rs,'Type','Requirement','MyEditAttribute','Value for edit attribute.')
req2 = 
  Requirement with properties:

            Type: 'Functional'
              Id: '#3'
         Summary: 'Avoid repeating commands'
     Description: '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">...'
        Keywords: {}
       Rationale: ''
       CreatedOn: 27-Feb-2017 10:15:38
       CreatedBy: 'itoy'
      ModifiedBy: 'batserve'
    IndexEnabled: 1
     IndexNumber: []
             SID: 3
    FileRevision: 46
      ModifiedOn: 03-Aug-2023 22:54:44
           Dirty: 1
        Comments: [0x0 struct]
           Index: '1.2'

要件セットで、'MyCheckboxAtribute'true に設定されているすべての要件を検索します。

reqsArray = find(rs,'Type','Requirement','MyCheckboxAttribute',true)
reqsArray=1×69 object
  1x69 Requirement array with properties:

    Type
    Id
    Summary
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedBy
    IndexEnabled
    IndexNumber
    SID
    FileRevision
    ModifiedOn
    Dirty
    Comments
    Index

要件セットで、'MyComboboxAttribute''Unset' に設定されているすべての要件を検索します。

reqsArray2 = find(rs,'Type','Requirement','MyComboboxAttribute','Unset')
reqsArray2=1×70 object
  1x70 Requirement array with properties:

    Type
    Id
    Summary
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedBy
    IndexEnabled
    IndexNumber
    SID
    FileRevision
    ModifiedOn
    Dirty
    Comments
    Index

カスタム属性の削除

deleteAttribute を使用すると、属性を削除できます。ただし、この例で作成したカスタム属性は要件に割り当てられているため、属性を削除するためには 'Force'true に設定しなければなりません。'MyEditAttribute' を削除し、変更を確認します。

deleteAttribute(rs,'MyEditAttribute','Force',true);
rs.CustomAttributeNames
ans = 1x3 cell
    {'MyCheckboxAttribute'}    {'MyComboboxAttribute'}    {'MyDateTimeAttribute'}

新しいカスタム属性を追加しますが、要件に対して要件のカスタム属性値は設定しないでください。

addAttribute(rs,'NewEditAttribute','Edit');
rs.CustomAttributeNames
ans = 1x4 cell
    {'MyCheckboxAttribute'}    {'MyComboboxAttribute'}    {'MyDateTimeAttribute'}    {'NewEditAttribute'}

'NewEditAttribute' は、どの要件にも使用されていないため、'Force'false に設定して、deleteAttribute を使用して削除できます。変更を確認します。

deleteAttribute(rs,'NewEditAttribute','Force',false);
rs.CustomAttributeNames
ans = 1x3 cell
    {'MyCheckboxAttribute'}    {'MyComboboxAttribute'}    {'MyDateTimeAttribute'}

クリーンアップ

開いている要件セットを変更を保存せずにクリアし、開いているモデルを変更を保存せずに閉じます。

slreq.clear;
bdclose all;

参考

| | | | | |

関連する例

詳細