Main Content

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

システムの階層的なレポート

この例では、システム階層に従って番号を付けた節をもつレポートの作成方法を説明します。各節には、システムのスナップショットと、サブシステムのスナップショットを含むサブセクションが含まれます。このような節を作成するには、セクション オブジェクトを作成し、ブロック線図のスナップショットを追加したうえで、サブシステム節を追加します。サブシステム節を作成するには、もう一度節を作成し、サブシステムのブロック線図のスナップショットを追加したうえで、そのサブシステム節を追加します。節を作成するアルゴリズムは再帰的です。この例では、再帰アルゴリズムを実装する、createSystemSection というローカル関数を作成して使用します。

関数 createSystemSection を使用した階層的レポートの作成

モデルを開きます。

model = "slrgex_sf_car";
open_system(model);

レポート オブジェクトを作成して開きます。

% Change the output type from "pdf" to "docx" or "html" to create a 
% Word or HTML report, respectively.
rpt = slreportgen.report.Report("myreport", "pdf");
open(rpt);

タイトル ページを追加します。

titlepage = mlreportgen.report.TitlePage();
titlepage.Title = "Hierarchical Report";
add(rpt, titlepage);

レベルの数を最大値 6 に設定して、目次を追加します。

toc = mlreportgen.report.TableOfContents();
toc.TOCObj.NumberOfLevels = 6;
add(rpt, toc);

ローカル関数 createSystemSection (以下を参照) を呼び出して、モデルのシステムの節を作成します。この関数は、それ自身を再帰的に呼び出して、サブシステムの節を作成します。

section = createSystemSection(model);
add(rpt, section);

レポートを生成して表示します。

close(rpt);
rptview(rpt);

ローカル関数 createSystemSection の定義

システム節は、システムのスナップショットとそのサブシステムのサブセクションで構成されます。システム節を作成するには、SearchDepth を 1 に指定して slreportgen.finder.DiagramFinder を使用し、1 階層深いシステムをすべて検索します。

function section = createSystemSection(sys)
    df = slreportgen.finder.DiagramFinder(sys);
    df.SearchDepth = 1;

    % Use the finder in iterator mode. The next function returns search results
    % one-by-one and the hasNext function determines when there are no more 
    % search results. To obtain the current system, call the next function 
    % once.
    sysResult = next(df);

    % Now, create a section using mlreportgen.report.Section with the system 
    % name as the title.
    section = mlreportgen.report.Section( ...
        "Title", mlreportgen.utils.normalizeString(sysResult.Name));

    % Add a system snapshot and a caption that shows the full diagram path. 
    % To include additional information about the system, add it to the 
    % section object.
    diag = slreportgen.report.Diagram(sysResult.Object);
    diag.Snapshot.appendCaption(sysResult.Path);
    add(section, diag);
    
    % To create subsections, loop through all subsystems and recursively call 
    % createSystemSection. Before calling createSystemSection, add a page break
    % so each system starts on a new page. Note that adding a page break right 
    % after the system snapshot would add a blank page at the end of the report.
    while hasNext(df)
        childSysResult = next(df);
        add(section, mlreportgen.dom.PageBreak());
        subSection = createSystemSection(childSysResult.Object);
        add(section, subSection);
    end
end