main content

report systems hierarchically -凯发k8网页登录

this example shows how to create a report with sections that are numbered according to system hierarchy. each section contains a system snapshot and subsections that contain subsystem snapshots. to create such a section, create a section object, add a diagram snapshot, and then add subsystem sections. to create the subsystem sections, again create a section, add a subsystem diagram snapshot and then add its subsystem sections. the algorithm to create the sections is recursive. this example creates and uses a local function called createsystemsection, which implements the recursive algorithm.

create hierarchical report using createsystemsection function

open a model.

model = "slrgex_sf_car";
open_system(model);

create and open a report object.

% 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);

add a title page.

titlepage = mlreportgen.report.titlepage();
titlepage.title = "hierarchical report";
add(rpt, titlepage);

add a table of contents with the number of levels set to 6, which is the maximum.

toc = mlreportgen.report.tableofcontents();
toc.tocobj.numberoflevels = 6;
add(rpt, toc);

create system sections for the model by calling the createsystemsection local function (see below). this function recursively calls itself to create sections for the subsystems.

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

generate and display the report.

close(rpt);
rptview(rpt);

define createsystemsection local function

a system section is composed of a system snapshot and its subsystems in subsections. to create a system section, find all systems one level deep by using an slreportgen.finder.diagramfinder with a searchdepth of 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
网站地图