Main Content

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

Requirements Toolbox API を使用したリンクのカスタム属性の管理

この例では、Requirements Toolbox™ API を使用して、リンク セットのカスタム属性を作成および管理する方法と、リンクにカスタム属性値を設定する方法を説明します。

リンク セットの設定

クルーズ コントロール システムを表す crs_req 要件ファイルを読み込みます。crs_req という名前のリンク セットを探し、変数に代入します。

slreq.load('crs_req');
ls = slreq.find('Type','LinkSet','Name','crs_req')
ls = 
  LinkSet with properties:

             Description: 'crs_req'
                Filename: '/tmp/Bdoc23b_2347338_3723397/tp40773858/slrequirements-ex23809012/crs_req.slmx'
                Artifact: '/tmp/Bdoc23b_2347338_3723397/tp40773858/slrequirements-ex23809012/crs_req.slreqx'
                  Domain: 'linktype_rmi_slreq'
                Revision: 11
                   Dirty: 0
    CustomAttributeNames: {'Target Speed Change'}

カスタム属性の削除

リンク セットには、Target Speed Change という名前のカスタム属性が既に存在します。このカスタム属性を削除し、リンク セットの既存のカスタム属性名をチェックすることによって、その結果を確認します。

deleteAttribute(ls,'Target Speed Change','Force',true);
ls.CustomAttributeNames
ans =

  0x0 empty cell array

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

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

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

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

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

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

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

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

addAttribute(ls,'MyDateTimeAttribute','DateTime')

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

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

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

リンクへのカスタム属性値の設定

リンク セット内のリンクを見つけ、作成した 4 つのカスタム属性すべてについてカスタム属性値を設定します。

lk = find(ls,'SID',3);
setAttribute(lk,'MyEditAttribute','Value for edit attribute.');
setAttribute(lk,'MyCheckboxAttribute',false);
setAttribute(lk,'MyComboboxAttribute','B');

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

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

属性値を表示します。

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

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

カスタム属性の編集

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

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

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

atrb3 = inspectAttribute(ls,'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.' に設定されているすべてのリンクを求めます。

lk2 = find(ls,'MyEditAttribute','Value for edit attribute.')
lk2 = 
  Link with properties:

           Type: 'Derive'
    Description: '#8: Set Switch Detection'
       Keywords: {}
      Rationale: ''
      CreatedOn: 20-May-2017 13:14:40
      CreatedBy: 'itoy'
     ModifiedOn: 03-Aug-2023 22:54:41
     ModifiedBy: 'batserve'
       Revision: 5
            SID: 3
       Comments: [0x0 struct]

リンク セットを検索し、MyCheckboxAttributetrue に設定されているすべてのリンクを求めます。

lkArray = find(ls,'MyCheckboxAttribute',true)
lkArray=1×11 object
  1x11 Link array with properties:

    Type
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedOn
    ModifiedBy
    Revision
    SID
    Comments

リンク セットを検索し、MyComboboxAttribute'Unset' に設定されているすべてのリンクを求めます。

lkArray2 = find(ls,'MyComboboxAttribute','Unset')
lkArray2=1×12 object
  1x12 Link array with properties:

    Type
    Description
    Keywords
    Rationale
    CreatedOn
    CreatedBy
    ModifiedOn
    ModifiedBy
    Revision
    SID
    Comments

カスタム属性の削除

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

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

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

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

NewEditAttribute は、どのリンクにも使用されていないため、Forcefalse に設定して、deleteAttribute を使用して削除できます。変更を確認します。

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

クリーンアップ

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

slreq.clear;
bdclose all;

参考

| | | | | |

関連する例

詳細