Main Content

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

ModelAdvisor.FormatTemplate

モデル アドバイザーの解析結果を書式設定するためのテンプレート

説明

ModelAdvisor.FormatTemplate クラスを使用してモデル アドバイザーの解析結果ペインでのチェック結果を書式設定することにより、作成したチェックの外観を統一します。解析結果はテーブルまたはリストとして書式設定できます。

作成

説明

obj = ModelAdvisor.FormatTemplate(type) は、ModelAdvisor.FormatTemplate クラスのオブジェクトを作成します。type は、テンプレートの書式タイプ (リストまたはテーブル) を識別する文字ベクトルです。

書式設定された結果を解析結果ペインに表示するには、結果オブジェクトをモデル アドバイザーに返す必要があります。

メモ

チェックのコールバックで ModelAdvisor.FormatTemplate クラスを使用します。

入力引数

すべて展開する

ModelAdvisor.FormatTemplate のタイプ

オブジェクト関数

addRowモデル アドバイザー解析結果で行をテーブルに追加
setCheckTextAdd description of check to result
setColTitlesモデル アドバイザー解析結果で列タイトルをテーブルに追加
setInformationAdd description of subcheck to result
setListObjモデル オブジェクトへのハイパーリンクのリストの追加
setRecActionAdd Recommended Action section and text
setRefLink[参考] セクションおよびリンクを追加する
setSubBarサブチェックの結果と結果の間にラインを追加する
setSubResultStatusステータスをチェックまたはサブチェックの結果に追加する
setSubResultStatusTextAdd text below status in result
setSubTitle結果にサブチェックのタイトルを追加する
setTableInfoAdd data to table
setTableTitleAdd title to table in Model Advisor analysis results

すべて折りたたむ

  1. 以下の sl_customization ファイルには、2 つのテンプレート オブジェクト ft1 および ft2 を作成し、それらを使用してチェックの実行結果をテーブルとリストで書式設定するコードが含まれています。結果では、モデル内のブロックが識別されています。

    function sl_customization(cm)
    
    % register custom checks
    cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);
    
    % register custom factory group 
    cm.addModelAdvisorTaskFcn(@defineModelAdvisorTasks);
    
    end
    
    
    % -----------------------------
    % defines Model Advisor Checks
    % -----------------------------
    function defineModelAdvisorChecks
    
    % Define and register a sample check 
    rec = ModelAdvisor.Check('mathworks.example.SampleDetailStyle');
    rec.Title = 'Sample check for Model Advisor using the ModelAdvisor.FormatTemplate';
    setCallbackFcn(rec, @SampleDetailStyleCallback,'None','DetailStyle');
    rec.setReportStyle('ModelAdvisor.Report.DefaultStyle');
    
    mdladvRoot = ModelAdvisor.Root;
    mdladvRoot.register(rec);
    
    end
    
    
    % -----------------------------
    % defines Model Advisor Tasks
    % -----------------------------
    function defineModelAdvisorTasks
    mdladvRoot = ModelAdvisor.Root;
     
    % --- sample factory group
    rec = ModelAdvisor.FactoryGroup('com.mathworks.sample.factorygroup');
    rec.DisplayName='My Group 1';
    rec.Description='Demo Factory Group';
    rec.addCheck('mathworks.example.SampleDetailStyle');
    mdladvRoot.publish(rec); % publish inside By Group list
    
    end
    
    
    % -----------------------------
    % Sample Check With Subchecks Callback Function
    % -----------------------------
    function [ResultDescription] = SampleDetailStyleCallback(system, CheckObj)
    
    % Initialize variables
    ElementResults = ModelAdvisor.ResultDetail.empty();
    
    % Perform the check actions
    allBlocks = find_system(system);
    [ResultDescription] = getFormattedTemplate(allBlocks);
    
    % Perform the subcheck actions - Result Details - Table
    if length(allBlocks) == 1
        % Add result details for detailed style check
        ElementResults(end + 1) = ModelAdvisor.ResultDetail;
        ElementResults(end).IsViolation = true;
        ElementResults(end).Description =  ['Find and report all blocks in a table. '...
            '(setInformation method - Description of what the subcheck reviews)'];
        ElementResults(end).Status =  ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)'];   
    else  
        for i=1:numel(allBlocks)
            ElementResults(end+1) = ModelAdvisor.ResultDetail;
            ElementResults(end).IsViolation = false;
            ElementResults(end).Format = 'Table';       
            ModelAdvisor.ResultDetail.setData(ElementResults(end),'SID',allBlocks{i});
            ElementResults(end).Description =  ['Find and report all blocks in a table. '...
                '(setInformation method - Description of what the subcheck reviews)'];
            ElementResults(end).Status = ['The model contains blocks. '...
                '(setSubResultStatusText method - Description of result status)'];
        end    
    end
    
    % Perform the subcheck actions  - Result Details - List
    if length(allBlocks) == 1
         ElementResults(end+1) = ModelAdvisor.ResultDetail;
         ElementResults(end).IsViolation = true;
         ElementResults(end).Description =  ['Find and report all blocks in a table. '...
            '(setInformation method - Description of what the subcheck reviews)'];
         ElementResults(end).Status =  ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)'];    
    else   
        for i= 1:numel(allBlocks) 
            ElementResults(end+1) = ModelAdvisor.ResultDetail;
            ElementResults(end).IsViolation = false;       
            ModelAdvisor.ResultDetail.setData(ElementResults(end),'SID',allBlocks{i});
            ElementResults(end).Description =  ['Find and report all blocks in a list. '...
                '(setInformation method - Description of what the subcheck reviews)'];
            ElementResults(end).Status = ['The model contains blocks. '...
                '(setSubResultStatusText method - Description of result status)'];  
        end    
    end
    
    %Set check result details
    CheckObj.setResultDetails(ElementResults);
    
    end
    
    function [ResultDescription] = getFormattedTemplate(allBlocks)
    ResultDescription={};
    
    % Create FormatTemplate object for first subcheck, specify table format
    ft1 = ModelAdvisor.FormatTemplate('TableTemplate');
    
    % Add information describing the overall check
    setCheckText(ft1, ['Find and report all blocks in the model. '...
        '(setCheckText method - Description of what the check reviews)']);
    
    % Add information describing the subcheck
    setSubTitle(ft1, 'Table of Blocks (setSubTitle method - Title of the subcheck)');
    setInformation(ft1, ['Find and report all blocks in a table. '...
        '(setInformation method - Description of what the subcheck reviews)']);
    
    % Add See Also section for references to standards
    setRefLink(ft1, {{'Standard 1 reference (setRefLink method)'},
        {'Standard 2 reference (setRefLink method)'}});
    
    % Add information to the table
    setTableTitle(ft1, {'Blocks in the Model (setTableTitle method)'});
    setColTitles(ft1, {'Index (setColTitles method)',
        'Block Name (setColTitles method)'});
    
    
    if length(allBlocks) == 1
        % Add status for subcheck
        setSubResultStatus(ft1, 'Warn');
        setSubResultStatusText(ft1, ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        setRecAction(ft1, {'Add blocks to the model. '...
            '(setRecAction method - Description of how to fix the problem)'});    
    else
        % Add status for subcheck
        setSubResultStatus(ft1, 'Pass');
        setSubResultStatusText(ft1, ['The model contains blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        for inx = 2 : length(allBlocks)
            % Add information to the table
            addRow(ft1, {inx-1,allBlocks(inx)});
        end    
    end
    
    % Pass table template object for subcheck to Model Advisor
    ResultDescription{end+1} = ft1;
    
    % Create FormatTemplate object for second subcheck, specify list format
    ft2 = ModelAdvisor.FormatTemplate('ListTemplate');
    
    % Add information describing the subcheck
    setSubTitle(ft2, 'List of Blocks (setSubTitle method - Title of the subcheck)');
    setInformation(ft2, ['Find and report all blocks in a list. '...
        '(setInformation method - Description of what the subcheck reviews)']);
    
    % Add See Also section for references to standards
    setRefLink(ft2, {{'Standard 1 reference (setRefLink method)'},
        {'Standard 2 reference (setRefLink method)'}});
    
    % Last subcheck, suppress line
    setSubBar(ft2, false);
    
    % Perform the subcheck actions
    if length(allBlocks) == 1
        % Add status for subcheck
        setSubResultStatus(ft2, 'Warn');
        setSubResultStatusText(ft2, ['The model does not contain blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        setRecAction(ft2, {'Add blocks to the model. '...
            '(setRecAction method - Description of how to fix the problem)'});
       
    else
        % Add status for subcheck
        setSubResultStatus(ft2, 'Pass');
        setSubResultStatusText(ft2, ['The model contains blocks. '...
            '(setSubResultStatusText method - Description of result status)']);
        % Add information to the list
        setListObj(ft2, allBlocks);
    end
    
    % Pass list template object for the subcheck to Model Advisor
    ResultDescription{end+1} = ft2;
    
    end
    
  2. sl_customization ファイルを作業ディレクトリに保存します。

  3. MATLAB コマンド ウィンドウで次を入力します。

    Advisor.Manager.refresh_customizations

  4. モデルを開きます。

  5. [モデル化] タブで、[モデル アドバイザー] を選択します。

  6. [タスク別][My Group 1] フォルダーで、[Sample check for Model Advisor using ModelAdvisor.FormatTemplate] を選択します。

  7. [このチェックを実行] をクリックします。

    次の図は、チェックがパスしたときにモデル アドバイザーに表示される出力です。

    Model Advisor output when the check passes

    次の図は、チェックから警告が出たときにモデル アドバイザーに表示される出力です。

    Model Advisor check output when the check warns

代替方法

ModelAdvisor.Check オブジェクトを定義する際に、CallbackStyle プロパティで DetailStyle を指定すれば、モデル アドバイザー レポートに表示される結果を ModelAdvisor.FormatTemplate API などの書式設定 API を使用して書式設定しなくても済みます。DetailStyle ではブロック、サブシステム、または推奨アクション別に結果を表示することもできます。

既定の書式設定では要件が満たされない場合、ModelAdvisor.FormatTemplate API または他の書式設定 API を使用します。ModelAdvisor.FormatTemplate クラスを使用すると、作成したチェック間の外観を統一できます。

バージョン履歴

R2009a で導入