主要内容

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

systemcomposer.interaction.Fragment

交互中的片段

自 R2024a 起

    创建对象

    通过相应 systemcomposer.interaction.Interaction 对象的 RootFragment 属性访问 Fragment 对象。访问根操作数片段的 Operand 属性,然后,如果片段位于根操作数内,则访问根操作数的 Fragment 属性并遍历它,以查看每个片段的详细信息。

    属性

    全部展开

    操作数,指定为 systemcomposer.interaction.Operand 对象数组。

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

    父操作数,指定为 systemcomposer.interaction.Operand 对象。

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

    数据类型: char

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

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

    数据类型: char

    对象函数

    addOperand在片段中添加操作数
    move在交互中移动片段
    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 中推出