Documentation

slreportgen.finder.DiagramElementFinder class

Package: slreportgen.finder
Superclasses:

Create diagram element finder object

Description

Finds elements in a Simulink® block or Stateflow® chart diagram.

Construction

finder = DiagramElementFinder(diagram) creates a finder that finds elements of a Simulink block or Stateflow chart diagram. By default this finder finds blocks, annotations, lines, states, and other elements in the diagram. Use the properties of the finder to constrain the search to specific types of elements.

Note

This finder has two ways to find objects — find mode and iterator mode. In find mode, use its find method to return the results of a search as an array of results. Then, use a for loop to process the results. In iterator mode, use its hasNext and next methods to return the results of a search one at a time. Using these iterator methods, use a while loop to process the results. Neither of these methods has a performance advantage over the other, so use either mode depending on whether you prefer while or for loops.

finder = DiagramElementFinder(Name,Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order. Enclose each property name in single quotes.

Input Arguments

expand all

See Container property.

Properties

expand all

Diagram in which to search, specified as one of these values:

  • Handle to a Simulink block

  • Path to a Simulink block

  • Handle to a Stateflow chart block

  • Path to a Stateflow chart block

  • Stateflow chart ID

  • Stateflow chart object

Types of Simulinkor Stateflowdiagram elements to find, specified as a string, character array, array of strings, or a cell array of character arrays. If the type is an array, it specifies a set of element types. The default is All or all, which finds all elements in all diagrams. Use one of these values to constrain the search to specific diagram element types. You can use either the fully qualified name or the short name.

Fully Qualified NameShort Name
Allall
Simulink.Annotationannotation
Simulink.Blockblock
Simulink.Segmentline
Simulink.Portport
Stateflow.Annotationsf_annotation
Stateflow.Boxbox
Stateflow.EMFunctionemfunction
Stateflow.Functionfunction
Stateflow.Junctionjunction
Stateflow.SLFunctionslfunction
Stateflow.Statestate
Stateflow.Transitiontransition
Stateflow.TruthTabletruthtable

Choice to include commented-out diagram elements in the search results, specified as a logical. If false, commented-out elements are excluded from the search results.

Properties of objects to find, specified as a cell array of name-value pairs. The finder returns only objects that have the specified properties with the specified values.

Example: finder.Properties = {'Gain','5'}

Methods

results = find(finder) finds diagram elements in the diagram specified by the finder. This method returns the diagram elements it finds wrapped in result objects of type slreportgen.finder.DiagramElementResult. To add tables of the diagram element properties, add the results objects directly to the report or add them to a reporter that you then add to a report. The reports to which you can add the results of this method must be reports of type slreportgen.report.Report.

tf = hasNext(finder) determines if the diagram that the finder searches contains at least one element. If the diagram has at least one element, the hasNext method queues that element as the next element that the next method will return. The hasNext method then returns true. Use the next method to obtain that element. On subsequent calls, the hasNext method determines if the diagram has an element that the next method has not yet retrieved. It queues the element for the next method to retrieve and returns true. If there are no more elements exist to be retrieved, this method returns false. To search a diagram progressively for elements, use the hasNext method with the next method in a while loop.

result = next(finder) returns the next search result in the result queue that the hasNext method created. This method returns the diagram element that it finds wrapped in a result object of type slreportgen.finder.DiagramElementResult. To add tables of the diagram element properties, add the results objects directly to the report or add them to a reporter that you then add to a report. The reports to which you can add the results of this method must be of type slreportgen.report.Report.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).

Examples

Find Block, Annotation, and Line Elements

Find the block, annotation, and line diagram elements to a search depth of 1 in the f14 model.

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

model_name = 'f14';
load_system(model_name);

rpt = slreportgen.report.Report('output','pdf');
add(rpt, TitlePage("Title",sprintf('%s Model',...
    model_name)));
add(rpt, TableOfContents);

diagFinder = SystemDiagramFinder("Container", ...
     model_name,"SearchDepth",1);
while hasNext(diagFinder)
    system = next(diagFinder);
    chapter = Chapter("Title",system.Name);
    add(chapter,system);
    sect = Section("Title","Diagram Elements");
    elemFinder = DiagramElementFinder("Container", ...
        system.Object, "Types",...
        ["block" "annotation" "line"]);
    elems = find(elemFinder);
    for elem = elems
        add(sect, elem);
    end  
    add(chapter, sect);
    add(rpt, chapter);
end

close(rpt);
close_system(model_name);
rptview(rpt);

Introduced in R2017b

Was this topic helpful?