System Composer Report Generation for System Architectures
This example shows the different parts of a report generation script for a System Composer™ architecture model and its artifacts.
Import the relevant packages and then add the folder with the example files to the MATLAB® path.
import mlreportgen.report.* import slreportgen.report.* import slreportgen.finder.* import mlreportgen.dom.* import mlreportgen.utils.* import systemcomposer.query.* import systemcomposer.rptgen.finder.* addpath(fullfile(matlabroot,'toolbox','systemcomposer','examples','rpt'))
Initialize the report.
rpt = slreportgen.report.Report(CompileModelBeforeReporting=false,output="SystemArchitectureReport");
Load the model and reference model.
systemcomposer.loadModel(fullfile(matlabroot,'toolbox','systemcomposer','examples','rpt','mTest')); model = systemcomposer.loadModel("mTestModel");
Append the title page and the table of contents.
add(rpt,TitlePage("Title",sprintf('%s',model.Name))); add(rpt,TableOfContents);
Introduction
Add sections and paragraphs to add textual information to the report.
Introduction = Chapter("Title", "Introduction"); sec1_1 = Section('Title', "Purpose"); p1 = Paragraph(['This document provides a comprehensive architectural ...' ... 'overview of the system using a number of different architecture views...' ... ' to depict different aspects of the system. It is intended to capture...' ... ' and convey the significant architectural decisions which have been...' ... ' made for the system.']); append(sec1_1, p1); sec1_2 = Section("Scope"); p2 = Paragraph(['This System Architecture Description provides an architectural...' ... ' overview of the Mobile Robot System being designed and developed by the...' ... ' Acme Corporation. The document was generated directly from the Mobile...' ... ' Robot models implemented in MATLAB, Simulink and System Composer.']); append(sec1_2, p2); append(Introduction, sec1_1); append(Introduction, sec1_2);
Architectural Elements
Create a new chapter to represent architectural elements.
ArchitecturalElements = Chapter("Architecture Description");
Use the Simulink® slreportgen.finder.SystemDiagramFinder
(Simulink Report Generator) finder to add a snapshot of the model to the report.
systemContext = Section(model.Name); finder = SystemDiagramFinder(model.Name); finder.SearchDepth = 0; results = find(finder); append(systemContext, results); append(ArchitecturalElements, systemContext);
Use the systemcomposer.rptgen.finder.ComponentFinder
finder to report on components in the model.
cf = ComponentFinder(model.Name); cf.Query = AnyComponent(); comp_finder = find(cf); for comp = comp_finder componentSection = Section("Title", comp.Name);
Create a list of components allocated from or to a particular component using the systemcomposer.rptgen.finder.AllocationListFinder
finder.
d = AllocationListFinder(fullfile(matlabroot, 'toolbox', 'systemcomposer', 'examples', 'rpt', "AllocationSet.mldatx")); compObject = lookup(model,'UUID',comp.Object); d.ComponentName = getfullname(compObject.SimulinkHandle); result = find(d); append(componentSection, comp);
Append the component information to the report.
append(systemContext,componentSection);
Append the allocation information to the report.
append(systemContext, result);
end
Allocation Sets
Create a chapter to report on the allocation sets associated with the model.
Find all allocation sets using the systemcomposer.rptgen.finder.AllocationSetFinder
finder.
allocation_finder = AllocationSetFinder(fullfile(matlabroot, 'toolbox', 'systemcomposer', 'examples', 'rpt', "AllocationSet.mldatx")); AllocationChapter = Chapter("Allocations"); while hasNext(allocation_finder) alloc = next(allocation_finder); allocationName = Section(alloc.Name); append(allocationName, alloc); append(AllocationChapter, allocationName); end
Architecture Views
Create a chapter to display information about the architecture views in the model.
Find all the views using the systemcomposer.rptgen.finder.ViewFinder
finder.
ViewChapter = Chapter("Architecture Views"); view_finder = ViewFinder(model.Name); while(hasNext(view_finder)) v = next(view_finder); viewName = Section('Title', v.Name); append(viewName, v); append(ViewChapter, viewName); end
Dependency Graph
Create a chapter to display the dependency graph image using the systemcomposer.rptgen.report.DependencyGraph
reporter.
Packaging = Chapter("Packaging"); packaging = Section('Title', 'Packaging'); graph = systemcomposer.rptgen.report.DependencyGraph("Source", [model.Name '.slx']); append(packaging, graph); append(Packaging, packaging);
Requirements Analysis
Report on all the requirement sets and requirement link sets associated with the model.
ReqChapter = Chapter("Requirements Analysis");
Requirement Sets
Collect the requirement sets using the systemcomposer.rptgen.finder.RequirementSetFinder
finder.
RequirementSetSection = Section("Requirement Sets"); reqFinder1 = RequirementSetFinder(fullfile(matlabroot, 'toolbox', 'systemcomposer', 'examples', 'rpt', "TestRequirement.slreqx")); result = find(reqFinder1); pp = Paragraph("This requirement set describes the system requirements for the mobile robot that are derived from the stakeholder needs document."); append(RequirementSetSection, pp); append(RequirementSetSection, result.getReporter);
Requirement Link Sets
Collect the requirement link sets using the systemcomposer.rptgen.finder.RequirementLinkFinder
finder.
RequirementLinkSection = Section("Requirement Link Sets"); reqLinkFinder = RequirementLinkFinder(fullfile(matlabroot, 'toolbox', 'systemcomposer', 'examples', 'rpt', "TestRequirement.slmx")); resultL = find(reqLinkFinder); rptr = systemcomposer.rptgen.report.RequirementLink("Source", resultL); append(RequirementLinkSection, rptr); append(ReqChapter, RequirementSetSection); append(ReqChapter, RequirementLinkSection);
Interfaces
Create a chapter to report on all the interfaces in the model.
Check if any dictionaries are linked within the model using the systemcomposer.rptgen.finder.DictionaryFinder
finder.
df = DictionaryFinder(model.Name); dictionary = find(df);
No Dictionaries present in the Model
boolHasNoDictionary = isempty(dictionary)
boolHasNoDictionary = logical
1
Since boolHasNoDictionary
is true
, create a separate chapter for interfaces to report on all the interfaces associated with the model using the systemcomposer.rptgen.finder.InterfaceFinder
finder.
if boolHasNoDictionary InterfaceChapter = Chapter("Interfaces Appendix"); interfaceFinder = InterfaceFinder(model.Name); interfaceFinder.SearchIn = "Model"; while hasNext(interfaceFinder) intf = next(interfaceFinder); interfaceName = Section(intf.InterfaceName); append(interfaceName, intf); append(InterfaceChapter, interfaceName); end end
Profiles
Create a chapter to report on all the profiles in the model.
Find all the profiles using the systemcomposer.rptgen.finder.ProfileFinder
finder.
ProfileChapter = Chapter("Profiles Appendix"); pf = ProfileFinder("TestProfile.xml"); while hasNext(pf) intf = next(pf); profileName = Section(intf.Name); append(profileName, intf); append(ProfileChapter, profileName); end
Stereotypes
Create a section to report on all the stereotypes in the profiles in the model.
Find all the stereotypes using the systemcomposer.rptgen.finder.StereotypeFinder
finder.
StereotypeSection = Section("Stereotypes"); sf = StereotypeFinder("TestProfile.xml"); while hasNext(sf) stf = next(sf); stereotypeName = Section(stf.Name); append(stereotypeName, stf); append(StereotypeSection, stereotypeName); end append(ProfileChapter, StereotypeSection);
Final Report
Add all the chapters to the report in the desired order.
append(rpt, Introduction); append(rpt, ArchitecturalElements); append(rpt, ViewChapter); append(rpt, Packaging); append(rpt, AllocationChapter); append(rpt, ReqChapter); append(rpt, InterfaceChapter); append(rpt, ProfileChapter); rptview(rpt)