Main Content

이 페이지는 기계 번역을 사용하여 번역되었습니다. 영어 원문을 보려면 여기를 클릭하십시오.

ModelAdvisor.FormatTemplate

Model Advisor 분석 결과 형식을 지정하기 위한 템플릿

설명

ModelAdvisor.FormatTemplate 클래스를 사용하여 Model Advisor의 분석 결과 창에서 검사 결과 형식을 지정하여 생성한 검사 간에 통일된 모양과 느낌을 줍니다. 분석 결과를 테이블이나 목록 형식으로 지정할 수 있습니다.

생성

설명

obj = ModelAdvisor.FormatTemplate(type)ModelAdvisor.FormatTemplate 클래스의 객체를 생성합니다. type은 템플릿(목록 또는 테이블)의 형식 유형을 식별하는 문자 벡터입니다.

분석 결과 창에 형식화된 결과를 표시하려면 결과 개체를 Model Advisor에 반환해야 합니다.

참고

검사 콜백에는 ModelAdvisor.FormatTemplate 클래스를 사용하세요.

입력 인수

모두 확장

ModelAdvisor.FormatTemplate 유형입니다.

객체 함수

addRowModel Advisor 분석 결과의 테이블에 행 추가
setCheckText결과에 검사 설명 추가
setColTitlesModel Advisor 분석 결과의 테이블에 열 제목 추가
setInformation결과에 하위 검사 설명 추가
setListObj모델 객체에 하이퍼링크 목록 추가
setRecAction권장 조치 섹션 및 텍스트 추가
setRefLink참고 항목 섹션 및 링크 추가
setSubBar하위 검사 결과 사이에 줄 추가
setSubResultStatus점검 또는 하위 점검 결과에 상태 추가
setSubResultStatusText결과 상태 아래에 텍스트 추가
setSubTitle결과에 하위 검사 제목 추가
setTableInfo테이블에 데이터 추가
setTableTitleModel Advisor 분석 결과의 테이블에 제목 추가

예제

모두 축소

  1. 다음 sl_customization 파일에는 ft1ft2라는 두 개의 템플릿 개체를 생성하고 이를 사용하여 테이블과 목록에서 검사 실행 결과의 형식을 지정하는 코드가 포함되어 있습니다. 결과는 모델의 블록을 식별합니다.

    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');
    
    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).ViolationType = 'warn';
        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).ViolationType = 'pass';
            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).ViolationType = 'warn';
         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).ViolationType = 'pass';       
            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에 표시되는 출력을 표시합니다.

    Model Advisor output when the check passes

    다음 그래픽은 검사 경고 시 Model Advisor에 표시되는 출력을 표시합니다.

    Model Advisor check output when the check warns

대안

ModelAdvisor.Check 객체를 정의할 때 CallbackStyle 속성에 대해 DetailStyle를 지정하면 ModelAdvisor.FormatTemplate API 또는 기타 형식 지정 API를 사용하여 형식을 지정할 필요가 없습니다. Model Advisor 보고서에 나타나는 결과입니다. DetailStyle를 사용하면 블록, 하위 시스템 또는 권장 조치별로 결과를 볼 수도 있습니다.

기본 형식이 요구 사항을 충족하지 않는 경우 ModelAdvisor.FormatTemplate API 또는 기타 형식 API를 사용하세요. ModelAdvisor.FormatTemplate 클래스는 생성한 검사에 통일된 모양과 느낌을 제공합니다.

버전 내역

R2009a에 개발됨