Main Content

systemcomposer.interaction.LoopFragment

Loop fragment in interaction

Since R2024a

    Description

    A LoopFragment object is a container for operands in a sequence diagram that specifies the behavior of the contained elements.

    A Loop Fragment contains an operate that repeats a certain number of times. The number of iterations has a minimum and a maximum number of iterations associated with it.

    A loop fragment is drawn as a box in the sequence diagram, with the label Loop in the box header. The minimum and maximum number of expected iterations is noted below this label. The operand is then drawn within this box as a separate section.

    Creation

    Access Fragment objects via the RootFragment property of the corresponding systemcomposer.interaction.Interaction object. Access the Operand property of the root fragment and then, if fragments are within the root operand, access the Fragment property of the root operand and iterate over it to view details about each of the fragments.

    Properties

    expand all

    Operands, specified as an array of systemcomposer.interaction.Operand objects.

    Lifelines covered, specified as an array of systemcomposer.interaction.Lifeline objects.

    Parent operand, specified as a systemcomposer.interaction.Operand object.

    Minimum number of iterations, specified as a double. Only integers are supported.

    Data Types: double

    Maximum number of iterations, specified as a double. Only integers are supported.

    Data Types: double

    Unique external identifier, specified as a character vector. The external ID is preserved over the lifespan of the element and through all operations that preserve the UUID.

    Data Types: char

    Universal unique identifier, specified as a character vector.

    Example: '91d5de2c-b14c-4c76-a5d6-5dd0037c52df'

    Data Types: char

    Object Functions

    addOperandAdd operand to fragment
    moveMove fragment within interaction
    destroyRemove model element

    Examples

    collapse all

    You can use read-only API workflows to navigate sequence diagrams in System Composer™ and display information about each element.

    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");

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

    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 Inhibit.
    

    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 source lifeline represents the source component.
    The poller lifeline represents the poller component.
    The switch lifeline represents the switch component.
    The controller lifeline represents the controller component.
    The lampController lifeline represents the lampController component.
    

    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){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