主要内容

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

getInteraction

获取模型中的交互

自 R2024a 起

    说明

    interaction = getInteraction(model,name) 通过 name 指定的序列图获取架构模型 model 中代表序列图 interaction 的交互对象。

    示例

    示例

    全部折叠

    您可以使用只读 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
    

    输入参数

    全部折叠

    架构模型,指定为 systemcomposer.arch.Model 对象。

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

    示例: "inhibit"

    数据类型: char | string

    输出参量

    全部折叠

    交互,以 systemcomposer.interaction.Interaction 对象的形式返回。

    详细信息

    全部折叠

    版本历史记录

    在 R2024a 中推出