В этом примере показано, как создать отчет о конструкции системы на основе Report API. Отчет о конструкции системы представляет собой описание конструкции динамической системы, созданной на основе модели системы Simulink ® .
Отчет о конструкции системы на основе API-интерфейса Report использует объекты классов API-интерфейса Report для создания отчетов о компонентах системы. См. раздел Создание отчетов для элементов Simulink и Stateflow.
gensdd Функция gensdd функция, включенная в этот пример, создает отчет, включающий следующие разделы:
Титульная страница
Оглавление
Список рисунков
Список таблиц
Иерархия системы
Глава корневой системы, содержащая корневую блок-схему, порядок выполнения задач и блоков, а также свойства каждого блока корневой схемы
Глава SubSystems, содержащая схему, порядок выполнения блока и свойства блока подсистем модели
Глава «Диаграммы», содержащая характеристики диаграмм и объектов диаграмм каждой из диаграмм модели
Глава «Конструкторские данные», содержащая переменные модели
Глава «Конфигурация модели системы», содержащая подробные сведения об активном наборе конфигурации для модели
Полное gensdd в конце этого примера указана функция. Вы можете изменить gensdd.m file для создания пользовательского отчета о конструкции системы.
slrgex_sf_car МодельСоздание отчета о конструкции системы для slrgex_sf_car и укажите, что документ является PDF.
gensdd('slrgex_sf_car','PDF');
Вот первая страница доклада:

Копия отчета включается вместе с этим примером в файл. sdd_slrgex_sf_car_copy.pdf.
gensdd функция использует объекты этих классов Report API для поиска элементов конструкции системы и отчета о конструкции системы:
slreportgen.report.SystemHierarchy
slreportgen.report.Diagram
slreportgen.report.SystemIO
slreportgen.report.ExecutionOrder
slreportgen.report.ModelConfiguration
slreportgen.finder.SystemDiagramFinder
slreportgen.finder.ChartDiagramFinder
slreportgen.finder.DiagramResult
slreportgen.finder.StateflowDiagramElementFinder
slreportgen.finder.DiagramElementResult
slreportgen.report.LookupTable
slreportgen.report.StateflowObjectProperties
slreportgen.report.TruthTable
slreportgen.finder.ModelVariableFinder
slreportgen.finder.ModelVariableResult
slreportgen.report.ModelVariable
slreportgen.finder.BlockFinder
slreportgen.finder.BlockResult
slreportgen.report.DocBlock
slreportgen.report.MATLABFunction
slreportgen.report.SimulinkObjectProperties
slreportgen.report.TestSequence
slreportgen.report.Bus
Свойства этих объектов можно использовать для фильтрации и форматирования сообщаемой информации. Например, в makeSystemHierarchy функции в gensdd.m файл, вы можете изменить формат списка иерархии системы на упорядоченный список, установив ListFormatter имущества slreportgen.report.SystemHierarchy репортер.
function makeSystemHierarchy(rpt, hModel)
% Create a chapter reporting on the system hiearchy
import mlreportgen.report.*
import slreportgen.report.*
ch = Chapter("Title", "System Hierarchy");
ol = mlreportgen.dom.OrderedList();
add(ch,SystemHierarchy("Source",hModel,"ListFormatter",ol));
add(rpt, ch);
end

В отчете также используются объекты этих классов API Report для создания и форматирования разделов отчета:
mlreportgen.report.TitlePage
mlreportgen.report.TableOfContents
mlreportgen.report.ListOfFigures
mlreportgen.report.ListOfTables
mlreportgen.report.Chapter
mlreportgen.report.Section
Можно настроить внешний вид отчета и разделов. См. раздел Подходы к форматированию отчетов.
gensdd Функция type gensdd.mfunction gensdd(model,doctype)
%GENSDD Generates a system design description from the system's model
% gensdd() generates a PDF system design description for the
% slrgex_sf_car model.
%
% gensdd(model) generates a PDF system design description for the
% specified model.
%
% gensdd(model, doctype) generates a system design description document
% from the specified model and document type: 'html', 'docx', or 'pdf'.
%
% The generated document is a description of a dynamic system's design
% generated from its Simulink model. The description contains the
% following sections:
%
% * Title Page
% * Table of Contents
% * List of Figures
% * List of Tables
% * System Hierarchy
% * Root System Chapter -- Contains root block diagram, task and block
% execution order, and properties of each block in the root diagram.
% * Subsystems Chapter -- Contains diagram, block execution order, and
% block properties of model's subsystems.
% * Charts Chapter -- Contains charts and chart object properties of each
% of the model's charts.
% * Design Data Chapter -- Contains the model variables.
% * System Model Configuration Chapter -- Contains details about the
% active configuration set for the model.
import mlreportgen.dom.*
import mlreportgen.report.*
import slreportgen.report.*
if nargin < 1
model = 'slrgex_sf_car';
doctype = 'pdf';
end
if nargin < 2
doctype = 'pdf';
end
hModel = load_system(model);
rpt = slreportgen.report.Report(['sdd_' get_param(model, 'Name')], doctype);
open(rpt);
makeTitlePage(rpt, hModel);
add(rpt, TableOfContents);
add(rpt, ListOfFigures);
add(rpt, ListOfTables);
makeSystemHierarchy(rpt, hModel);
makeRootSystemChapter(rpt, hModel);
makeSubsystemsChapter(rpt, hModel);
makeChartsChapter(rpt, hModel);
makeDesignDataChapter(rpt, hModel);
makeModelConfigurationChapter(rpt, hModel);
close(rpt);
rptview(rpt);
close_system(model);
end
function makeTitlePage(rpt, hModel)
import mlreportgen.report.*
import slreportgen.report.*
tp = TitlePage;
tp.Title = upper(get_param(hModel, 'Name'));
tp.Subtitle = 'System Design Description';
tp.Author = 'John Doe';
diag = Diagram(hModel);
diag.Scaling = 'custom';
diag.Height = '2in';
diag.Width = '3in';
tp.Image = getSnapshotImage(diag, rpt);
add(rpt, tp);
end
function makeSystemHierarchy(rpt, hModel)
% Create a chapter reporting on the system hierarchy
import mlreportgen.report.*
import slreportgen.report.*
ch = Chapter("Title", "System Hierarchy");
add(ch,SystemHierarchy(hModel));
add(rpt, ch);
end
function makeRootSystemChapter(rpt, hModel)
% Create a chapter reporting on the root system diagram and its blocks
% and add the chapter to the main report.
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
ch = Chapter("Title", "Root System");
diag = Diagram(hModel);
add(ch, diag);
add(ch, SystemIO(hModel));
% Add block execution order section
makeExecutionOrderSection(ch, hModel);
% Add subsections containing the properties for each block in the
% subsystem diagram.
makeBlockSections(ch, hModel);
add(rpt, ch);
end
function makeSubsystemsChapter(rpt, hModel)
% Create a chapter reporting on a model's subsystems and the blocks that
% they contain and add the chapter to the main report.
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
% Create a chapter to hold the subsystems.
ch = Chapter("Title", "Subsystems");
% Use a finder to find all the subsystem diagrams in the model. The finder
% returns an array of SystemDiagramResult objects, each of which
% contains a Diagram reporter that creates a snapshot of the subsystem
% diagram
finder = SystemDiagramFinder(hModel);
finder.IncludeRoot = false;
systems = find(finder);
% Add the subsystem diagram results to the chapter.
for system = systems
% Create a subsection to contain the subsystem diagram.
section = Section("Title", system.Name);
% Add the subsystem diagram reporter to the diagram subsection.
% Add the subsystem diagram results to the chapter.
diag = getReporter(system);
diag.MaskedSystemLinkPolicy = 'system';
add(section, diag);
ioSect = Section('Title', 'System Interface');
add(ioSect, SystemIO('Object', system, 'ShowDetails', false));
add(section, ioSect);
% If the subsystem is nonvirtual, add a subsection detailing the block
% execution order
if strcmp(get_param(system.Object, "IsSubsystemVirtual"), "off")
makeExecutionOrderSection(section, system);
end
% Add subsections containing the properties for each block in the
% subsystem diagram.
makeBlockSections(section, system);
% Add the subsystem diagram section to the chapter.
add(ch, section);
end
% Add the subsystems chapter to the main report.
add(rpt, ch);
end
function makeChartsChapter(rpt, hModel)
% Create a chapter reporting on a model's Stateflow charts and the objects
% that they contain and add the chapter to the main report.
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
finder = ChartDiagramFinder(hModel);
charts = find(finder);
if ~isempty(charts)
ch = Chapter("Title", "Charts");
for chart = charts
section = Section("Title", chart.Name);
diag = getReporter(chart);
add(section, diag);
% Report the objects in this chart
objFinder = StateflowDiagramElementFinder(chart);
sfObjects = find(objFinder);
for sfObj = sfObjects
objSection = Section("Title", sfObj.Name);
add(objSection, sfObj);
add(section, objSection);
end
add(ch, section);
end
add(rpt, ch);
end
end
function makeDesignDataChapter(rpt, hModel)
% Create a chapter reporting on the model variables
import mlreportgen.dom.*
import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
ch = Chapter("Title", "Design Data");
finder = ModelVariableFinder(hModel);
results = find(finder);
n = numel(results);
if n > 0
s = Section("Title", "Design Data Summary");
vars = cell(n, 4);
for i = 1:n
result = results(i);
% Get link target for variable reporter
lt = getVariableID(result);
value = getVariableValue(results(i));
vars{i, 1} = InternalLink(lt, results(i).Name);
vars{i, 2} = class(value);
vars{i, 3} = results(i).Source;
vars{i, 4} = results(i).SourceType;
end
t = FormalTable(["Name", "Type", "Source", "Source Type"], vars);
% Set styles for table header
t.Header.TableEntriesStyle = {Bold, BackgroundColor("lightgrey")};
% Set styles for entire table
t.Width = "100%";
t.Border = "solid";
t.RowSep = "solid";
t.ColSep = "solid";
add(s, t);
add(ch, s);
s = Section("Title", "Design Data Details");
% Separate multiple variable details be a horizontal rule
if n > 1
for result = results(1:end-1)
add(s, result);
add(s, HorizontalRule);
end
end
add(s, results(end));
add(ch, s);
add(rpt, ch);
end
end
function makeModelConfigurationChapter(rpt, hModel)
% Create a chapter reporting on the active configuration set of the
% reported model.
import mlreportgen.report.*
import slreportgen.report.*
ch = Chapter("Title", "System Model Configuration");
modelConfig = ModelConfiguration(hModel);
% Add the reporter to the chapter and chapter to the report
add(ch,modelConfig);
add(rpt,ch);
end
function section = makeBlockSections(parent, system)
% Create subsections containing the properties of each block in the
% system and add it to the parent chapter or subsection.
import mlreportgen.report.*
import slreportgen.finder.*
blocksSection = Section("Title", "Blocks");
finder = BlockFinder(system);
elems = find(finder);
for elem = elems
section = Section("Title", strrep(elem.Name, newline, ' '));
add(section, elem);
% If this block creates a bus or selects signals from a bus, report the
% bus signal details
busRptr = slreportgen.report.Bus(elem);
add(section, busRptr);
add(blocksSection, section);
end
add(parent, blocksSection);
end
function makeExecutionOrderSection(parent, system)
% Create a section to display a list of blocks in the system in order of
% execution. If the system is a top-level model, display information about
% all tasks in the model.
import mlreportgen.report.*
import slreportgen.report.*
section = Section('Title', 'Block Execution Order');
eo = ExecutionOrder(system);
if ~slreportgen.utils.isModel(system)
% Only show task details for top-level models
eo.ShowTaskDetails = false;
end
add(section, eo)
add(parent, section);
end
slreportgen.finder.BlockFinder | slreportgen.finder.BlockResult | slreportgen.finder.ChartDiagramFinder | slreportgen.finder.DiagramElementResult | slreportgen.finder.DiagramResult | slreportgen.finder.ModelVariableFinder | slreportgen.finder.ModelVariableResult | slreportgen.finder.StateflowDiagramElementFinder | slreportgen.finder.SystemDiagramFinder | slreportgen.report.Diagram | slreportgen.report.ModelVariable | slreportgen.report.SimulinkObjectProperties | slreportgen.report.SystemHierarchy | slreportgen.report.SystemIO