主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

systemcomposer.interaction.DurationConstraint

持续时间约束

自 R2025a 起

    说明

    DurationConstraint 对象表示对两个消息事件之间经过时间的约束。使用持续时间约束,可以明确表达对开始事件和结束事件之间持续时间的约束

    创建对象

    通过相应 systemcomposer.interaction.Interaction 对象的 DurationConstraints 属性访问 DurationConstraint 对象。

    属性

    全部展开

    定义持续时间约束的表达式,指定为字符串。

    持续时间约束的表达式包含:

    • 表示观察持续时间的关键字。使用:tduration

    • 一个关系运算符。使用:><>=<=

    • 一个时间值。

    • 一个时间单位。使用:secmsecusec

    示例: duration < 10sec

    示例: 1 >= t > 3msec

    与持续时间约束开始相对应的消息事件,指定为 systemcomposer.interaction.MessageEvent 对象。

    与持续时间约束结束相对应的消息事件,指定为 systemcomposer.interaction.MessageEvent 对象。

    对象函数

    destroy移除模型元素

    示例

    全部折叠

    以编程方式创建一个序列图,描述行人在有交通信号灯的十字路口过马路的情景。

    要了解有关序列图的更多信息,请参阅以交互方式编写序列图

    打开交通灯示例

    加载 TLExample 架构模型。

    model = systemcomposer.openModel('TLExample');

    TLExample architecture model with various components.

    创建一个名为 '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);

    Newly created sequence diagram called 'InhibitCopy'.

    详细信息

    全部展开

    版本历史记录

    在 R2025a 中推出