Author Sequence Diagrams to Co-Create Architecture Models
You can author sequence diagrams to describe expected system behavior as a sequence of interactions between components of a System Composer™ architecture model. Lifelines correspond to components in an architecture model, and messages correspond to the connectors between the components. You can create multiple sequence diagrams to represent different operational scenarios of the system. Sequence diagrams are integrated into the Architecture Views Gallery in System Composer.
For a roadmap of the sequence diagram topics, see Describe System Behavior Using Sequence Diagrams.
This traffic light example will show you how to:
Create a sequence diagram.
Add child lifelines in a sequence diagram.
Interact with root architecture ports in a sequence diagram using gates.
Co-create components and keep the architecture model and the sequence diagram in sync.
Create messages in a sequence diagram.
Use the model browser to add components.
Link elements of a sequence diagram to requirements.
Note
This example uses Stateflow® blocks. If you do not have a Stateflow license, you can open and simulate the model but can only make basic changes, such as modifying block parameters.
Traffic Light Example with Hierarchy for Sequence Diagrams
This traffic light example contains sequence diagrams to describe pedestrians crossing an intersection. The model describes these steps:
The traffic signal cycles from green to yellow to red.
When the pedestrian crossing button is pressed, if the traffic signal is green, the traffic signal transitions from yellow to red for a limited time.
The pedestrians cross while the walk signal is active.
Open the System Composer model that contains the sequence diagrams.
model = systemcomposer.openModel("TrafficLight");
To view the sequence diagrams, open the Architecture Views Gallery.
openViews(model)
The sequence diagram in this example represents an operative scenario in the architecture model.
In the InputPollNested
sequence diagram, the poller
lifeline recognizes a signal event as inValue
rises to 1
, the pedestrian crossing button is pressed. Next, the switch
lifeline recognizes a signal event to lampcontroller
as switchPed
rises to 1
, which activates the pedestrian crossing signal.
Create Sequence Diagram
Create an architecture model in System Composer to represent how a traffic light system operates.
To open sequence diagrams in the Architecture Views Gallery, navigate to Modeling > Sequence Diagram.
To create a new sequence diagram, click New > Sequence Diagram.
In Sequence Diagram Properties on the right, enter the name
PedLoop
.From the menu, select Component > Add Lifeline. A box with a vertical dotted line appears on the canvas. This box is the new lifeline.
To view available options, click the down arrow on the lifeline. Select the component named
lampSubsystem
to be represented by the lifeline.
Add Child Lifelines to Sequence Diagram
You can add child lifelines to a sequence diagram to represent model hierarchy and describe the interactions between lifelines.
From the menu, select Component > Add Lifeline. From the list that appears, select the
Controller
component.Child components called
lampcontroller
andcontroller
are located inside thelampSubsystem
andController
components, respectively.Select the
lampSubsystem
lifeline. Navigate to Component > Add Lifeline > Add Child Lifeline. Selectlampcontroller
. Thelampcontroller
child lifeline is now situated belowlampSubsystem
in the hierarchy.Repeat these steps for the
Controller
lifeline to add thecontroller
child lifeline.
Create Sequence Diagram Gates
A gate represents the root architecture of the corresponding architecture model.
Connect messages to gates to represent architecture ports.
Select the
lampcontroller
lifeline, then click and drag it to the gutter region. Start typingtSwitch
into the To box and selecttSwitch
from the list. See that a gate calledtSwitch
has been created with a message from thelampcontroller
lifeline at the porttSwitch
.Return to the architecture diagram. Observe that
tSwitch
is a root architecture port connected to thelampcontroller
component in the hierarchy through thelampSubsystem
component.
Co-Create Components
The co-creation workflow between the sequence diagram and the architecture model keeps the model synchronized as you make changes to the sequence diagram. Adding both lifelines and messages in a sequence diagram results in updates to the architecture model. This example shows component co-creation.
From the toolstrip menu, select Component > Add Lifeline. Another box with a vertical dotted line appears on the canvas to represent a lifeline. In the box, enter the name of a new component named
Machine
.Observe that the
Machine
component is co-created in the architecture diagram.
Synchronize Sequence Diagram and Model
Remove the
Machine
component from the architecture diagram.Return to the sequence diagram and select Synchronize > Check Consistency. See that the
Machine
lifeline is highlighted, as it does not correspond to a component.To restore consistency, either remove the
Machine
lifeline or click Undo in the architecture model to restore theMachine
component.Click Check Consistency again.
For advanced sequence diagram synchronization techniques, see Synchronize Sequence Diagrams and Architecture Models.
Create Messages in Sequence Diagram
You can create a message from an existing connection.
Draw a line from the
controller
lifeline to thelampcontroller
lifeline. Start to typetraffic
in the To box, which fills in automatically as you type. Once the text fills in, selecttraffic
.Since the
trafficColor
port andtraffic
port are connected in the model, a message is created from thetraffic
port to thetrafficColor
port in the sequence diagram.You can modify the source and destination of a message after the message has been created. Click the
trafficColor
message end to select it.Click and drag the
trafficColor
message end to theController
parent lifeline, then select thetrafficColor
port.Once the
trafficColor
port is selected, the message end moves from thecontroller
child lifeline to theController
parent lifeline.You can also rename message ends and the associated ports by double-clicking the name of a message end.
Modify Sequence Diagram Using Model Browser
The Architecture Views Gallery model browser located on the bottom left of the canvas is called Model Components. Click and drag the
switch
child component into the sequence diagram.The sequence diagram is updated with a new lifeline.
Click and drag to reorder the
lampSubsystem
and theController
lifelines.
Use Annotations to Describe Elements of Sequence Diagram
An annotation describes the elements of a sequence diagram.
Use annotations to provide detailed explanations of elements or workflows captured by sequence diagrams.
You can add plain-text annotations to a sequence diagram to describe elements, such as lifelines, messages, and fragments.
To create an annotation, double-click the canvas at the desired location. Then, enter the annotation text in the text box that appears on the canvas.
Press Esc or click anywhere outside the text box to apply the changes.
Create Sequence Diagram from View
In the MATLAB® Command Window, enter
scKeylessEntrySystem
. The architecture model opens in the Simulink Editor.To open the Architecture Views Gallery for the model, navigate to Modeling > Views > Architecture Views.
Right-click the
Sound System Supplier Breakdown
view and select New Sequence Diagram.A new sequence diagram of lifelines is created with all the components from the view.
Link Elements of Sequence Diagram to Requirements
You can link a sequence diagram as a whole or individual elements of a sequence diagram to requirements in the Architecture Views Gallery. A Requirements Toolbox™ license is required.
On the Views tab, in the Requirement section, click Open Requirements Editor to open the Requirements Editor (Requirements Toolbox). From here, you can author requirements, create requirement sets, and organize requirements into hierarchies.
With the Requirements Editor open, select the sequence diagram element that you want to link to a requirement. To select a lifeline, gate, fragment, or message, click the element on the sequence diagram canvas. To select the sequence diagram as a whole, click the name of the sequence diagram in the View Browser pane.
In the Requirements Editor, click the requirement that you want to link the selected sequence diagram element to.
You can link from the selected sequence diagram element to the requirement in three ways.
In the Architecture Views Gallery, on the Views tab, in the Requirement section, click Link to selected requirement.
In the Requirements Editor, right-click the selected requirement and click Link from for the specific sequence diagram element.
In the Requirements Editor, click Add Link and select Link from for the specific sequence diagram element.
Note
In a sequence diagram, links from lifelines and gates to requirements connect to the respective elements in the underlying architecture diagram. This type of link is called an implemented link. If you delete an architecture diagram element corresponding to a lifeline or gate, then the option to link a requirement from this element is disabled. If you delete an element after linking to a requirement, then the link is invalid.
On the other hand, requirement links from sequence diagrams, messages, and fragments link locally to the respective element in the sequence diagram. This type of link is a verified link.
To view the requirements linked from sequence diagram elements, select a particular element on the sequence diagram canvas and click Requirements Manager in the Requirement section of the Views tab. The requirements linked from the selected element are listed in the Requirement Links pane that appears at the bottom of the window.
If the Requirements Manager button is selected, gray badges appear over sequence diagram elements that are linked to requirements. To display the corresponding requirement ID
and the requirement Summary
text, point to the badge.
To view these requirements in the Requirements Editor, point to the requirements in the Requirement Links pane and click the Show in Links View button. You can delete requirement links from sequence diagram elements by pausing your cursor on the requirement name, and clicking the Delete Link button.