addFragment - Add fragment to operand - MATLAB (original) (raw)
Add fragment to operand
Since R2024b
Syntax
Description
[fragment](#mw%5F6d40d305-d7bb-4402-9eeb-9d46fc108541) = addFragment([operand](#mw%5F1659dc78-c23e-42e5-a0eb-f1ceb6abd18c%5Fsep%5Fmw%5F888a4f38-9c31-4535-8558-55c2509d50c4),[fragmentType](#mw%5F76692bf9-3964-431b-9827-26d4b642538f))
adds a fragment of type fragmentType
to the operand specified byoperand
.
[fragment](#mw%5F6d40d305-d7bb-4402-9eeb-9d46fc108541) = addFragment(___,[Name=Value](#namevaluepairarguments))
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, setAfter to a valid fragment object.
Examples
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');
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.
Input Arguments
Type of fragment, specified as one of these values:
"Opt"
– Optional fragment"Alt"
– Alternative fragment"Loop"
– Loop fragment"Par"
– Parallel fragment"Strict"
– Weak sequencing fragment"Seq"
– Strict sequencing fragment
Data Types: char
| string
Name-Value Arguments
Specify optional pairs of arguments asName1=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
Loop Fragments
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
Output Arguments
More About
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
- openViews | sim | addInteraction | getInteraction | getInteractions | open | addLifeline | addOperand | addMessage | addDurationConstraint | addAnnotation | findLifeline | findElement | move | move | move | destroy | next | current | reset
Objects
- systemcomposer.arch.Model | systemcomposer.interaction.Interaction | systemcomposer.interaction.Iterator | systemcomposer.interaction.Lifeline | systemcomposer.interaction.MessageEvent | systemcomposer.interaction.FormalGate | systemcomposer.interaction.Message | systemcomposer.interaction.Fragment | systemcomposer.interaction.Operand | systemcomposer.interaction.DurationConstraint | systemcomposer.interaction.Annotation