以编程方式创建序列图
以编程方式创建一个序列图,描述行人在有交通信号灯的十字路口过马路的情景。
要了解有关序列图的更多信息,请参阅以交互方式编写序列图。
打开交通灯示例
加载 TLExample
架构模型。
model = systemcomposer.openModel('TLExample');
创建一个名为 'InhibitCopy
' 的新序列图。
diagram = model.addInteraction('InhibitCopy');
添加生命线
为架构中的每个组件添加生命线。
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');
获取交互的根片段和根操作数。
rootFragment = diagram.RootFragment; rootOperand = rootFragment.Operands(1);
添加消息和片段
向根操作数添加两条消息。
sourceToPollerMsg = rootOperand.addMessage(sourceLifeline, "switchout", pollerLifeline, "sw", "rising(sw-1){sw==1}"); pollerToSwitchMsg = rootOperand.addMessage(pollerLifeline, "switchEvent", switchLifeline, "switchEvent", "switchEvent{switchEvent==1}");
向根操作数添加一个条件片段。
altFrag = rootOperand.addFragment('Alt');
为条件片段的每个操作数指定保护表达式。
op1 = altFrag.Operands(1); op1.Guard = "switch/inhibit==0"; op2 = altFrag.addOperand("switch/inhibit==1");
向条件片段的第一个操作数添加两条消息。
switchToLampControllerMsg1 = op1.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==1}"); switchToControllerMsg = op1.addMessage(switchLifeline, "switchPush", controllerLifeline, "pedRequest", "pedRequest");
在条件片段的第二个操作数中添加一条消息。
switchToLampControllerMsg2 = op2.addMessage(switchLifeline, "lampColor", lampLifeline, "switchPed", "switchPed{switchPed==2}");
添加持续时间约束
在条件片段第一个操作数中的两个消息之间添加一个持续时间约束。
startEvent = switchToLampControllerMsg1.End;
endEvent = switchToControllerMsg.End;
expression = "t > 12msec";
durationConstraint = diagram.addDurationConstraint(startEvent, endEvent, expression);
打开序列图
打开新创建的序列图。
open(diagram);
另请参阅
systemcomposer.interaction.Interaction
| systemcomposer.interaction.Lifeline
另请参阅
工具
函数
openViews
|sim
|addInteraction
|getInteraction
|getInteractions
|open
|addLifeline
|addFragment
|addOperand
|addMessage
|addDurationConstraint
|addAnnotation
|findLifeline
|findElement
|move
|move
|move
|destroy
|next
|current
|reset
对象
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