Main Content

System Composer Report Generation for Software Architectures

This example shows the different parts of a report generation script for a System Composer™ software architecture model and its artifacts.

Import the relevant namespaces.

import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.finder.*
import mlreportgen.dom.*
import mlreportgen.utils.*
import systemcomposer.query.*
import systemcomposer.rptgen.finder.*

Initialize the report.

rpt = slreportgen.report.Report('OutputPath','SoftwareModel'+".pdf",...
    'CompileModelBeforeReporting',false);

% for html: rpt = slreportgen.report.Report('Type','html-file','OutputPath',...
% 'SoftwareModel','CompileModelBeforeReporting',false);

Load the model and reference model.

systemcomposer.loadModel('mTest.slx');
model = systemcomposer.loadModel('SoftwareModel.slx');

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("SWArchAllocationSet.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("SWArchAllocationSet.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

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('SWArchProfile.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('SWArchProfile.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,AllocationChapter);
append(rpt,ProfileChapter);

rptview(rpt);

Interactively Generate Report for Architectures

Alternatively, you can use this command to interactively generate custom reports for your architectures.

systemcomposer.rptgen.app.launch

Generate Report for AUTOSAR Software Architectures

You can generate a report for an AUTOSAR architecture model and its artifacts using the script in this example. To load an AUTOSAR model, use autosar.arch.loadModel (AUTOSAR Blockset). Check that the model, profile, requirements, and dictionary file names are updated in accordance with your AUTOSAR model. For more information on AUTOSAR architectures, see Software Architecture Modeling (AUTOSAR Blockset).

See Also

Classes

Related Topics