Main Content

slreportgen.report.BusObject Class

Namespace: slreportgen.report
Superclasses: slreportgen.report.Reporter

Simulink bus object reporter

Description

Creates a reporter that generates information about a Simulink.Bus object in a report.

Note

To use a bus object reporter in a report, you must create the report using the slreportgen.report.Report class or subclass.

The slreportgen.report.BusObject class is a handle class.

Class Attributes

HandleCompatible
true

For information on class attributes, see Class Attributes.

Creation

Description

reporter = slreportgen.report.BusObject creates an empty slreportgen.report.BusObject reporter object. Customize the content and formatting of the information reported for a bus object by using the reporter object properties. Before you add the reporter to a report, you must set the Object property of the reporter to an slreportgen.report.ModelVariableResult or Simulink.VariableUsage object that specifies a Simulink.Bus object. Adding an empty reporter to a report produces an error.

reporter = slreportgen.report.BusObject(object) creates a reporter for the Simulink.Bus object specified by an slreportgen.report.ModelVariableResult or Simulink.VariableUsage object. See the Object property.

example

reporter = slreportgen.report.BusObject(Name=Value) sets the reporter properties using name-value pairs. You can specify multiple name-value pair arguments in any order.

Properties

expand all

Object that specifies the Simulink.Bus object to report, specified as an slreportgen.finder.ModelVariableResult object or a Simulink.VariableUsage object.

This read-only property contains the name of bus object to report, specified as a string scalar.

Bus object properties to report, specified as a string array or a cell array of character vectors. The properties specified by the ReportedBusProperties property are further filtered by the PropertyFilterFcn property. If the ReportedBusProperties property is empty, the reporter includes all properties in the report, except the properties filtered by the PropertyFilterFcn property. The reporter excludes any bus object property that is not valid for the bus object.

Bus element properties to report, specified as a string array or a cell array of character vectors. The properties specified by the ReportedElementProperties property are further filtered by the function or code specified in the PropertyFilterFcn property. If the ReportedElementProperties property is empty, the reporter includes all properties in the report, except the properties filtered by the PropertyFilterFcn property. The reporter excludes any bus element property that is not valid for the bus element.

Whether to show the name of the bus object in the report, specified as true or false.

Whether to include a nested list that represents the bus hierarchy in the report, specified as true or false.

Whether to show the bus object properties table in the report, specified as true or false.

Whether to show the bus element properties table in the report, specified as true or false.

Whether to show a list of the blocks that use the bus object, specified as true or false. If the ShowUsedBy property is set to true, the reporter includes a list of the blocks that use the bus object in the report. If the ShowUsedBySnapshot property is also set to true, the reporter includes a diagram snapshot for each parent subsystem that uses the bus object. Blocks that use the bus object are highlighted in the snapshot.

Whether to show diagram snapshots of parent subsystems and highlight the blocks that use the bus object, specified as true or false. If the ShowUsedBySnapshot property is set to true, the report includes a snapshot for each parent subsystem that uses the bus object. Blocks that use the bus object are highlighted in the snapshot. If a parent subsystem has more than one block that uses the bus object, the reporter shows only one diagram snapshot that highlights the blocks that use the bus object.

Whether to create a separate section for each type of information about the bus object in the report. If the CreateSections property is set to true, the reporter creates an mlreportgen.report.Section with a title for each of these types of information:

  • hierarchy

  • properties

  • elements

  • blocks that use the bus object

If the CreateSections property is set to false, the reporter generates labels for tables and lists. For a table, the reporter generates a table title. For a list, the reporter generates text that precedes the list.

List formatter that formats the generated bus hierarchy, specified as an mlreportgen.dom.UnorderedList object or an mlreportgen.dom.OrderedList object. The default value of this property is an object of mlreportgen.dom.UnorderedList. To customize the list formatting, modify the list object properties or replace the list object with a customized list object that does not contain list items.

List formatter that formats the generated list of blocks that use the bus object, specified as an mlreportgen.dom.UnorderedList object or an mlreportgen.dom.OrderedList object. The default value of this property is an object of mlreportgen.dom.UnorderedList. To customize the list formatting, modify the list object properties or replace the list object with a customized list object that does not contain list items.

Table reporter used to format the table of bus object properties, specified as an mlreportgen.report.BaseTable object. The default value of this property is a BaseTable object with the TableStyleName property set to the BusObjectPropertiesTable style, which is defined in the default template for a BusObject reporter.

To customize the appearance of the table, modify the properties of the default table reporter or replace it with a customized table reporter. If you add content to the Title property of the default or customized table reporter, the content appears in front of the table title in the generated report.

Table reporter used to format the table of bus element properties, specified as an mlreportgen.report.BaseTable object. The default value of this property is a BaseTable object with the TableStyleName property set to the BusObjectElementsTable style, which is defined in the default template for a BusObject reporter.

To customize the appearance of the table, modify the properties of the default table reporter or replace it with a customized table reporter. If you add content to the Title property of the default or customized table reporter, the content appears in front of the table title in the generated report.

Whether to display properties horizontally in the table of element properties, specified as true or false.

If the HorizontalElementsTable property is set to true, the table has one column for each property. For example:

Table with columns for each property, as when the HorizontalElementsTable property is set to true

If the HorizontalElementsTable property is set to false, the property and value cells in the row for the element are split into multiple rows. For example:

Table with value cells split into multiple rows, as when the HorizontalElementsTable property is set to false

Reporter for formatting sections when the CreateSections property is set to true, specified as an mlreportgen.report.Section object. To customize the appearance of the section, modify the properties of the default section reporter or replace it with a customized section reporter.

Function or expression to filter the properties of a reported bus or bus element from a report. Specify a function as a function handle. Specify an expression as a string scalar or character vector.

If you provide a function handle, the associated function must:

  • Take these arguments:

    • variableName — Name of the model variable that designates the bus or bus element being reported

    • variableObject — The bus or bus element being reported

    • propertyName — Name of the property of the bus or bus element being reported

  • Return true to filter the specified property from the report, or false to include the property in the report.

For example, this code prevents the display of the HeaderFile and Description properties of a bus object and the Complexity property of a bus element:

import slreportgen.finder.*
import slreportgen.report.*

rpt = slreportgen.report.Report('busrpt','pdf');

model = load_system('sldemo_bus_arrays');

modelVariableFinder = ModelVariableFinder(model);
results = find(modelVariableFinder);
for result = results
    if isa(getVariableValue(result),'Simulink.Bus')
        busRptr = slreportgen.report.BusObject(result);
        busRptr.PropertyFilterFcn = @busPropertyFilter;
        % Create a Chapter
        chapter = mlreportgen.report.Chapter(busRptr.Name);
        add(chapter, busRptr);   
        add(rpt,chapter)
    end
end
close(rpt);

close_system(model);
rptview(rpt);

function tf = busPropertyFilter(~, variableObject,propertyName)
if isa(variableObject, 'Simulink.Bus')
    tf = (propertyName == "HeaderFile") ||  ...
        (propertyName == "Description");
else
    % Filter Simulink.BusElement Complexity property
    tf = propertyName == "Complexity";
end
end

If you provide a string scalar or a character vector, it must contain an expression. The expression:

  • Can use the variables variableName, variableObject, and propertyName

  • Must set the variable isFiltered to true to filter the specified property from the report, or false to include the property in the report

For example, this code filters the HeaderFile property of a bus object from the report:

import slreportgen.finder.*
import slreportgen.report.*

rpt = slreportgen.report.Report('busrpt','pdf');

model = load_system('sldemo_bus_arrays');

modelVariableFinder = ModelVariableFinder(model);
results = find(modelVariableFinder);
for result = results
    if isa(getVariableValue(result),'Simulink.Bus')
        busRptr = slreportgen.report.BusObject(result);
        busRptr.PropertyFilterFcn = "isFiltered = " + ...
            "isa(variableObject, 'Simulink.Bus') && " + ...
            "propertyName == 'HeaderFile';";
        % Create a Chapter
        chapter = mlreportgen.report.Chapter(busRptr.Name);
        add(chapter, busRptr);   
        add(rpt,chapter)
end
end
close(rpt);

close_system(model);
rptview(rpt);

Source of the template for this reporter, specified in one of these ways:

  • Character vector or string scalar that specifies the path of the file that contains the template for this reporter

  • Reporter or report whose template is used for this reporter or whose template library contains the template for this reporter

  • Document Object Model (DOM) document or document part whose template is used for this reporter or whose template library contains the template for this reporter

The specified template must be the same type as the report to which you append this reporter. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template. If the TemplateSrc property is empty, this reporter uses the default reporter template for the output type of the report.

Name of the template for this reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template specified by the TemplateSrc property of this reporter.

Data Types: char | string

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID, or an mlreportgen.dom.LinkTarget object. A character vector or string scalar value converts to a LinkTarget object. The link target immediately precedes the content of this reporter in the output report.

Methods

expand all

Examples

collapse all

Report on bus objects in a model by using a model variable finder to find all variables used in the model and then creating a bus reporter for each variable that is a bus object.

% Create a Report
rpt = slreportgen.report.Report("MyReport","pdf");
open(rpt);

% Load a model
model_name = "sldemo_bus_arrays";
load_system(model_name);

% Find all variables used by the model
finder = slreportgen.finder.ModelVariableFinder(model_name);

% Create a Bus object reporter object for all results representing a
% Simulink.Bus object
while hasNext(finder)
    result = next(finder);
    if isa(getVariableValue(result), "Simulink.Bus")
        % Create a Bus object reporter
        busReporter = slreportgen.report.BusObject(result);
        % Create a Chapter
        chapter = mlreportgen.report.Chapter(busReporter.Name);
        % Add bus to chapter
        add(chapter, busReporter)
        % Add chapter to the report
        add(rpt,chapter);
    end
end

% Close and view the report
close(rpt);
rptview(rpt);

Customize the reported content and formatting of the content by setting properties of the bus object reporter. This example uses the ReportedElementProperties property to constrain the element properties that are reported. It uses the HorizontalElementsTable property to generate a properties table with one column for each property.

% Create a Report
rpt = slreportgen.report.Report("MyReport","pdf");
open(rpt);

% Load a model
model_name = "sldemo_bus_arrays";
load_system(model_name);

% Find all variables used by the model
finder = slreportgen.finder.ModelVariableFinder(model_name);

% Create a Bus object reporter object for all results representing a
% Simulink.BusObject object
while hasNext(finder)
    result = next(finder);
    if isa(getVariableValue(result), "Simulink.Bus")
        % Create a Bus object reporter
        busReporter = slreportgen.report.BusObject(result);
        % Limit the properties that are reported
        busReporter.ReportedElementProperties = {'Name','DataType','Min','Max'};
        % Display element properties horizontally
        busReporter.HorizontalElementsTable = true;
        % Create a Chapter
        chapter = mlreportgen.report.Chapter(busReporter.Name);
        % Add bus to chapter
        add(chapter, busReporter)
        % Add chapter to the report
        add(rpt,chapter);
    end
end

% Close and view the report
close(rpt);
rptview(rpt);

Version History

Introduced in R2019b