Main Content

addFragment

Add fragment to operand

Since R2024b

    Description

    fragment = addFragment(operand,fragmentType) adds a fragment of type fragmentType to the specified operand.

    example

    fragment = addFragment(___,Name=Value) specifies options using one or more name-value arguments in addition to the input arguments in previous syntaxes. For example, to add the fragment after an existing fragment, set After to a valid fragment object.

    example

    Examples

    collapse all

    You can create a sequence diagram programmatically. This example shows you how to programmatically create a sequence diagram to describe the scenario of a pedestrian crossing the street at an intersection with traffic lights.

    To learn more about sequence diagrams, see Author Sequence Diagrams Interactively.

    Open Traffic Light Example

    Load the TLExample architecture model.

    model = systemcomposer.openModel('TLExample');

    TLExample architecture model with various components.

    Create a new sequence diagram named 'InhibitCopy'.

    diagram = model.addInteraction('InhibitCopy');

    Add Lifelines

    Add a lifeline for each component in the architecture.

    sourceLifeline = diagram.addLifeline('TLExample/source');
    pollerLifeline = diagram.addLifeline('TLExample/poller');
    switchLifeline = diagram.addLifeline('TLExample/switch');
    lampLifeline = diagram.addLifeline('TLExample/lampController');
    controllerLifeline = diagram.addLifeline('TLExample/controller');

    Get the root fragment and root operand of the interaction.

    rootFragment = diagram.RootFragment;
    rootOperand = rootFragment.Operands(1);

    Add Messages and Fragments

    Add two messages to the root operand.

    rootOperand.addMessage(sourceLifeline, "switchout", pollerLifeline, "sw", "rising(sw-1){sw==1}");
    rootOperand.addMessage(pollerLifeline, "switchEvent", switchLifeline, "switchEvent", "switchEvent{switchEvent==1}");

    Add an alternative fragment to the root operand.

    altFrag = rootOperand.addFragment('Alt');

    Specify the guard expressions for each operand of the alternative fragment.

    op1 = altFrag.Operands(1);
    op1.Guard = "switch/inhibit==0";
    op2 = altFrag.addOperand("switch/inhibit==1");

    Add two messages to the first operand of the alternative fragment.

    op1.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==1}");
    op1.addMessage(switchLifeline, "switchPush", controllerLifeline, "pedRequest", "pedRequest");

    Add a message to the second operand of the alternative fragment.

    op2.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==2}");

    Open Sequence Diagram

    Open the newly created sequence diagram.

    diagram.open

    Newly created sequence diagram called 'InhibitCopy'.

    Input Arguments

    collapse all

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

    Type of fragment, specified as one of these values:

    • "Opt" – An optional fragment.

    • "Alt" – An alternative fragment.

    • "Loop" – A loop fragment.

    • "Par" – A parallel fragment.

    • "Strict" – A weak sequencing fragment.

    • "Seq" – A strict sequencing fragment.

    Data Types: char | string

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: addFragment(op, "Loop", MinIterations=1, MaxIterations=5)

    Fragments

    collapse all

    Interaction element object, specified as one of these objects:

    Example: addFragment(op, "Seq", After=frag)

    Number of operands in new fragment specified as a double.

    Only systemcomposer.interaction.AltFragment and systemcomposer.interaction.ParFragment objects support more than one operand.

    Example: addFragment(op, "Alt", NumOperands=2)

    Data Types: double

    Loop Fragments

    collapse all

    Minimum number of times a loop fragment repeats specified as a double.

    Example: addFragment(op, "Loop", MinIterations=1, MaxIterations=5)

    Data Types: double

    Maximum number of times a loop fragment repeats specified as a double.

    Example: addFragment(op, "Loop", MinIterations=1, MaxIterations=5)

    Data Types: double

    More About

    collapse all

    Definitions

    TermDefinitionApplicationMore Information
    sequence diagram

    A sequence diagram represents the expected interaction between structural elements of an architecture as a sequence of message exchanges.

    Use sequence diagrams to describe how the parts of a system interact.

    Describe System Behavior Using Sequence Diagrams
    lifeline

    A lifeline is represented by a head and a timeline that proceeds down a vertical dotted line.

    The head of a lifeline represents a component in an architecture model.

    Add Lifelines and Messages
    message

    A message sends information from one lifeline to another. Messages are specified with a message label.

    A message label has a trigger, an optional guard, and an optional constraint where a trigger represents the identifying event for this message, a guard represents an additional condition to determine whether the message occurs, and a constraint is an expression that is expected to be true when this message occurs.

    Create Messages in Sequence Diagram
    gate

    A gate represents the root architecture of the corresponding architecture model.

    Connect messages to gates to represent architecture ports.

    Create Sequence Diagram Gates
    annotation

    An annotation describes the elements of a sequence diagram.

    Use annotations to provide detailed explanations of elements or workflows captured by sequence diagrams.

    Use Annotations to Describe Elements of Sequence Diagram
    fragment

    A fragment indicates how a group of messages execute or interact.

    A fragment is used to model complex sequences, such as alternatives, in a sequence diagram.

    Author Sequence Diagram Fragments
    operand

    An operand is a region in a fragment. Fragments have one or more operands depending on the kind of fragment. Operands can contain messages and additional fragments.

    Each operand can include a constraint to specify whether the messages inside the operand execute. You can express the precondition of an operand as a MATLAB® Boolean expression using the input signal of a lifeline.

    Add Fragments and Operands

    Version History

    Introduced in R2024b