主要内容

使用报告API生成系统设计报告

这个例子展示了如何生成一个基于Report api的系统设计报告。系统设计报告描述了由Simulink®系统模型生成的动态系统的设计。金宝app

基于Report API的系统设计报告使用Report API类的对象来报告系统组件。看到生成Simulink和状态流元素的报告金宝app

gensdd函数

gensdd函数,它将生成一个包含以下部分的报告:

  • 标题页

  • 表的内容

  • 数据列表

  • 名单表

  • 系统层次结构

  • 根系统章节,包含根块图、任务和块执行顺序,以及根图中每个块的属性

  • 子系统一章,其中包含了图表、块执行顺序和模型子系统的块属性

  • 图表一章,其中包含图表和每个模型图表的图表对象属性

  • 包含模型变量的设计数据章节

  • “系统模型配置”一章,其中包含有关模型的活动配置集的详细信息

完整的gensdd函数列在本示例的最后。您可以修改gensdd.m文件创建自定义系统设计报告。

生成PDF系统设计报告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.CFunction

  • slreportgen.report.DocBlock

  • slreportgen.report.MATLABFunction

  • slreportgen.report.金宝appSimulinkObjectProperties

  • slreportgen.report.TestSequence

  • slreportgen.report.Bus

您可以使用这些对象的属性来筛选和格式化所报告的信息。例如,在makeSystemHierarchy功能gensdd.m文件时,可以通过设置L将系统层次列表格式更改为有序列表istFormatter财产的slreportgen.report.SystemHierarchy记者。

function makeSystemHierarchy(rpt, hModel) %创建一个章节报告系统层次导入mlreportgen.report。*进口slreportgen.report。* ch =章(“标题”,“系统层次”);ol = mlreportgen.dom.OrderedList ();add (ch SystemHierarchy (hModel“源”,“ListFormatter ol));add (rpt, ch);结束

报告还使用这些report API类的对象来创建和格式化报告的各个部分:

  • mlreportgen.report.TitlePage

  • mlreportgen.report.TableOfContents

  • mlreportgen.report.ListOfFigures

  • mlreportgen.report.ListOfTables

  • mlreportgen.report.Chapter

  • mlreportgen.report.Section

您可以自定义报表和部分的外观。看到报告格式的方法

完整的gensdd函数

类型gensdd.m
函数gensdd(model,doctype)%gensdd从系统模型生成系统设计说明%gensdd()为%slrgex\u sf\u车型生成PDF系统设计说明。%%GENDD(模型)为%指定模型生成PDF系统设计说明。%%GENDD(model,doctype)根据指定的模型和文档类型生成系统设计说明文档%:“html”、“docx”或“pdf”。%%生成的文档是从Simulink模型生成的动态系统设计%的描述。描述包含以下%部分:%%*标题页%*目录%*图表列表%*表格列表%*系统层次结构%*根系统章节--包含根框图、任务和块%执行顺序以及根图中每个块的属性。%%*子系统章节——包含图、块执行顺序和模型子系统的%块属性。%*图表章节--包含模型图表中每%的图表和图表对象属性。%*设计数据章节——包含模型变量。%*系统模型配置章节--包含有关模型的%活动配置集的详细信息。导入mlreportgen.dom.*导入mlreportgen.report.*导入slreportgen.report.*如果nargin<1 model='slrgex\u sf\u car';doctype='pdf';如果narg金宝appin<2 doctype='pdf',则结束;end hModel=负载系统(模型);rpt=slreportgen.report.report(['sdd\'get\'param(model,'Name')],doctype);开放式(rpt);制作标题页(rpt,hModel);添加(rpt,目录);添加(rpt,图表列表);添加(rpt,列表);makeSystemHierarchy(rpt,hModel);makeRootSystemChapter(rpt,hModel);MakeSubsystems章(rpt,hModel);makeChartsChapter(rpt,hModel);makeDesignDataChapter(rpt,hModel);makeModelConfigurationChapter(rpt,hModel);关闭(rpt);rptview(rpt);封闭式系统(模型);end函数makeTitlePage(rpt,hModel)导入mlreportgen.report.*导入slreportgen.report.*tp=TitlePage;tp.Title=upper(get_param(hModel,'Name'));tp.副标题=‘系统设计说明’;tp.Author='johndoe';diag=图表(hModel);诊断缩放='自定义';诊断高度='2in';诊断宽度='3in';tp.Image=getSnapshotImage(diag,rpt);添加(rpt,tp);end function makeSystemHierarchy(rpt,hModel)%import mlreportgen.report.*import slreportgen.report.*ch=章节(“标题”,“系统层次结构”);添加(ch,系统层次结构(hModel));添加(rpt,ch);结束函数makeRootSystemChapter(rpt,hModel)%在根系统图及其块%上创建一个章节报告,并将该章节添加到主报告中。导入mlreportgen.report.*导入slreportgen.report.*导入slreportgen.finder.*ch=章节(“标题”、“根系统”);diag=图表(hModel);添加(ch,diag);添加(ch,SystemIO(hModel));%添加块执行顺序节makeExecutionOrderSection(ch,hModel);%添加包含%子系统关系图中每个块的属性的子部分。制作块段(ch、hModel);添加(rpt,ch);结束函数makeSubsystemsChapter(rpt,hModel)%1创建一个关于模型子系统及其包含的块的章节报告,并将该章节添加到主报告中。导入mlreportgen.report.*导入slreportgen.report.*导入slreportgen.finder.*%创建一个章节来保存子系统。ch=章节(“标题”、“子系统”);%使用查找器查找模型中的所有子系统图。finder%返回SystemDiagramResult对象的数组,每个对象%都包含一个图表报告器,用于创建子系统%Diagram finder=SystemDiagramFinder(hModel)的快照;finder.IncludeRoot=false;系统=查找(查找器);%将子系统图结果添加到章节中。对于system=systems%,创建一个子节以包含子系统图。节=节(“标题”,系统名称);%将子系统关系图报告器添加到“关系图”小节中。%将子系统图结果添加到章节中。diag=getReporter(系统);diag.MaskedSystemLinkPolicy='system';添加(第节,diag);ioSect=部分(“标题”、“系统接口”);添加(ioSect,SystemIO('Object',system,'ShowDetails',false));添加(节,ioSect);%如果子系统是非虚拟的,则在strcmp(get_param(system.Object,“IsSubsystemVirtual”),“off”)makeExecutionOrderSection(section,system)中添加一个小节,详细说明块%的执行顺序;结束%添加包含%子系统关系图中每个块的属性的子部分。makeBlockSections(节,系统);%将子系统图部分添加到本章中。添加(第章,第节);结束%将子系统章节添加到主报告中。添加(rpt,ch);end function makeChartsChapter(rpt,hModel)%创建一个关于模型状态流程图及其包含的对象%的章节报告,并将该章节添加到主报告中。导入mlreportgen.report.*导入slreportgen.report.*导入slreportgen.finder.*finder=ChartDiagramFinder(hModel);图表=查找(查找器);如果~isempty(图表)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

另请参阅

|||||||||||||

相关的话题