主要内容

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

systemcomposer.interaction.Interaction

交互

自 R2024a 起

    说明

    Interaction 对象表示序列图的根层级。交互通过消息交换序列来指定系统各个部分的交互方式。

    创建对象

    通过相应 systemcomposer.arch.Model 对象的 getInteractionsgetInteraction 函数访问 Interaction 对象。

    属性

    全部展开

    交互名称,指定为字符串。

    示例: "mySequenceDiagram"

    数据类型: string

    生命线,指定为 systemcomposer.interaction.Lifeline 对象数组。

    交互中元素的根级容器,指定为 systemcomposer.interaction.Fragment 对象。

    交互中的注解,指定为 systemcomposer.interaction.Annotation 对象数组。

    交互中的持续时间约束,指定为 systemcomposer.interaction.DurationConstraint 对象数组。

    包含交互的架构模型,指定为 systemcomposer.arch.Model 对象。

    唯一外部标识符,指定为字符向量。外部 ID 在元素的整个生命周期以及所有保留 UUID 的操作中都会被保留。

    数据类型: char

    统一唯一标识符,指定为字符向量

    示例: '91d5de2c-b14c-4c76-a5d6-5dd0037c52df'

    数据类型: char

    对象函数

    open打开交互
    addLifeline在交互中创建新的生命线
    addAnnotation在交互中创建新注解
    findLifeline查找交互中的生命线
    findElement在交互中查找元素
    destroy移除模型元素

    示例

    全部折叠

    您可以使用只读 API 工作流浏览 System Composer™ 中的序列图,并显示每个元素的相关信息。

    打开交通灯示例

    打开交通灯示例架构模型,以便直观地检查序列图并确认程序输出。

    model = systemcomposer.openModel("TLExample");

    要查看与模型关联的序列图,请在 System Composer 工具条上导航至建模 > 序列图

    The press detection sequence diagram in the views gallery of the top model.

    以编程方式浏览序列图

    收集由 interactions 表示的序列图,其中包含模型中元素的特定交互。

    interactions = model.getInteractions;

    对于第一个交互,提取序列图的名称。

    disp("The first sequence diagram is called " + interactions(1).Name + ".")
    The first sequence diagram is called SignalSequence.
    

    在该序列图中,显示每条生命线以及生命线所代表的组件。

    for i = 1:length(interactions(1).Lifelines)
        disp("The " + interactions(1).Lifelines(i).Name + ...
        " lifeline represents the " + ...
        interactions(1).Lifelines(i).RelatedElements.Name + ...
        " component.")
    end
    The source lifeline represents the source component.
    The poller lifeline represents the poller component.
    The lampController lifeline represents the lampController component.
    The ped lamp lifeline represents the ped lamp component.
    

    显示根片段中一条消息的内容。

    disp("The sequence diagram message starting at the " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Name + ...
        " message end is of type " + ...
        string(interactions(1).RootFragment.Operands.Fragments(1).Message.Type) + ...
        " and the message label is " + ...
        interactions(1).RootFragment.Operands.Fragments(1).Message.Condition + ".")
    The sequence diagram message starting at the switchout message end is of type Signal and the message label is rising(sw-1){sw==1}.
    

    使用迭代器实用工具逐步浏览序列图

    使用 Inhibit 实用工具逐步浏览 Iterator 序列图。

    interaction = model.getInteraction('Inhibit');
    interaction.open

    Inhibit sequence diagram from the top model.

    显示交互中的注解。

    disp(interaction.Annotations.Content)
    When inhibit is true, it means pedestrian crossing is not controlled by a walk signal on this intersection.
    

    在提取序列图的属性之前,使用迭代器浏览序列图的所有元素。

    iterator = systemcomposer.interaction.Iterator(interaction.RootFragment);
    next = iterator.next;
    while ~isempty(next)
        disp(class(next))
        next = iterator.next;
    end
    systemcomposer.interaction.RootFragment
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.AltFragment
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.Operand
    systemcomposer.interaction.MessageEvent
    systemcomposer.interaction.MessageEvent
    

    详细信息

    全部展开

    版本历史记录

    在 R2024a 中推出