addLifeline - Create new lifeline in interaction - MATLAB (original) (raw)

Main Content

Create new lifeline in interaction

Since R2024b

Syntax

Description

[lifeline](#mw%5F8c589ce4-53a1-4cc7-858f-d32625c01080) = addLifeline([interaction](#mw%5Fa87dcbdb-1431-458f-bd6c-307021f4f81e%5Fsep%5Fmw%5F91e5b2bb-cf28-4f8d-bb2b-48061211fa8f),[component](#mw%5F7d74ca37-6446-4318-b1dc-45dfb4ea4521)) creates a lifeline in a sequence diagram corresponding to interaction,interaction, in a System Composerâ„¢ model using the component component.

example

Examples

collapse all

Create a sequence diagram programmatically 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.

sourceToPollerMsg = rootOperand.addMessage(sourceLifeline, "switchout", pollerLifeline, "sw", "rising(sw-1){sw==1}"); pollerToSwitchMsg = 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.

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

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

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

Add Duration Constraints

Add a duration constraint between the two messages in the first operand of the alternative fragment.

startEvent = switchToLampControllerMsg1.End; endEvent = switchToControllerMsg.End; expression = "t > 12msec"; durationConstraint = diagram.addDurationConstraint(startEvent, endEvent, expression);

Open Sequence Diagram

Open the newly created sequence diagram.

Newly created sequence diagram called 'InhibitCopy'.

Output Arguments

More About

collapse all

Term Definition Application More Information
Interaction An interaction specifies how each part of a system should interact as a sequence of message exchanges. Use interactions to describe operational system behaviors. Describe System Behavior Using Sequence Diagrams
Sequence diagram A sequence diagram is a visual representation of an interaction. Use sequence diagrams to visually specify how each part of a system should interact. Describe System Behavior Using Sequence Diagrams
Lifeline A lifeline represents an instance of a component as a participant of an interaction. A lifeline corresponds to a component in an architecture. Describe Interactions with Lifelines and Messages
Message A message represents communication between two lifelines. Messages have labels to specify the expected condition for the message to occur. 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. Describe Interactions with Lifelines and Messages
Gate A gate represents the root of an architectural hierarchy. A gate allows you to describe the exchange of messages between the architecture and its environment. Describe Interactions with Lifelines and Messages
Annotation An annotation describes the elements of a sequence diagram. Use annotations to provide detailed explanations of elements or workflows captured by sequence diagrams. Annotate Sequence Diagrams with Annotations
Fragment A fragment encloses a group of lifelines and messages within an interaction to allow for the specification of more complex patterns of interaction. A fragment defines the type of ordering logic such as looping and alternatives. Fragments can have one or more operands. Model Complex Interactions with Fragments and Operands
Operand An operand is a region in a fragment, or group of messages. The condition of an operand specifies whether the messages inside the operand execute. The condition of an operand can specify constraints on the input signal of a lifeline as a MATLAB® Boolean expression. Model Complex Interactions with Fragments and Operands
Duration constraint A duration constraint defines a constraint on elapsed time between a start and an end occurrence. Use duration constraints to explicitly express a constraint on the duration between a start occurrence and an end occurrence. Specify Timing Constraints Between Message Events with Duration Constraints

Version History

Introduced in R2024b

See Also

Tools

Functions

Objects

Topics