Main Content

systemcomposer.interaction.Iterator

Iterator utility to navigate interactions

Since R2024a

    Description

    An Iterator object is a utility that visits every element of the interaction in a predefined order.

    Creation

    Instantiate an Iterator object by passing in a systemcomposer.interaction.Fragment object as your scope fragment.

    iterator = systemcomposer.interaction.Iterator(interaction.RootFragment)

    Properties

    expand all

    Scope of iterator, specified as a systemcomposer.interaction.Fragment object.

    Whether iterator is still valid, specified as a logical. Iterators become invalid when the interaction changes. You can change the interaction by editing and saving your changes to the current sequence diagram.

    Data Types: logical

    Object Functions

    nextReturn next element in fragment
    currentReturn the currently visited element of the fragment
    resetReset the iterator

    Examples

    collapse all

    This example shows how to use read-only API workflows to navigate sequence diagrams in System Composer™ and display information about each of the elements.

    Open Traffic Light Example

    Open the traffic light example architecture model so that you can inspect the sequence diagrams visually and confirm the programmatic outputs.

    model = systemcomposer.openModel("TLExample");

    On the System Composer toolstrip, navigate to Modeling > Sequence Diagram to view the sequence diagrams associated with the model.

    The press detection sequence diagram in the views gallery of the top model.

    Programmatically Navigate Sequence Diagram

    Collect the sequence diagrams represented by interactions that contain specific interactions of elements in the model.

    interactions = model.getInteractions;

    For the first interaction, extract the name of the sequence diagram.

    disp("The first sequence diagram is called " + interactions(1).Name + ".")
    The first sequence diagram is called SignalSequence.
    

    For this sequence diagram, display each lifeline and the component the lifeline represents.

    for i = 1:length(interactions(1).Lifelines)
        disp("The " + interactions(1).Lifelines(i).Name + ...
        " lifeline represents the " + ...
        interactions(1).Lifelines(i).RelatedElements.Name + ...
        " component.")
    end
    The ped lamp lifeline represents the ped lamp component.
    The lampController lifeline represents the lampController component.
    The poller lifeline represents the poller component.
    The source lifeline represents the source component.
    

    Now, display the contents of one message in the root fragment.

    disp("The sequence diagram message starting at the " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Name + ...
        " message end is of type " + ...
        string(interactions(1).RootFragment.Operands.Fragments(1).Message.Type) + ...
        " and the message label is " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Message.Condition + ".")
    The sequence diagram message starting at the switchout message end is of type Signal and the message label is rising(sw-1).
    

    Use Iterator Utility to Step Through Sequence Diagram

    Step through the Inhibit sequence diagram using the Iterator utility.

    interaction = model.getInteraction('Inhibit');
    interaction.open

    Inhibit sequence diagram from the top model.

    Display the annotation from the interaction.

    disp(interaction.Annotations.Content)
    When inhibit is true, it means pedestrian crossing is not controlled by a walk signal on this intersection.
    

    Use an iterator to navigate through all elements of a sequence diagram before extracting their properties.

    iterator = systemcomposer.interaction.Iterator(interaction.RootFragment);
    next = iterator.next;
    while ~isempty(next)
        disp(class(next))
        next = iterator.next;
    end
    systemcomposer.interaction.RootFragment
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.AltFragment
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    

    More About

    expand all

    Version History

    Introduced in R2024a