预订演示

请注意 : 本帮助页面不适用于最新版本的Enterprise Architect. 最新的帮助文档在这里.

前页 后页

示例:历史伪状态

“状态历史记录”是与复合状态区域相关联的一种方便的概念,通过“区域历史记录”,区域可以跟踪上一次退出状态所处的状态。这样,在必要时,下一个Region变为活动状态时(例如,从处理中断返回后),或者存在返回其历史记录的本地Transition,可以轻松返回到该State配置。

Enterprise Architect支持两种历史记录伪状态:

  • 深度历史-代表最近对该访问区域的访问的完整状态配置;效果与终止于deepHistory伪状态的Transition相反地终止于保留状态配置的最内部状态(包括执行沿路径遇到的所有条目行为)相同
  • 浅历史记录-表示仅返回到最新状态配置的最顶层子状态,该状态使用默认输入规则输入
在此示例中,类DeepTurbineManagerShallowTurbineManager完全相同,除了所包含的StateMachine中的第一个具有DeepHistory伪状态,而第二个所包含的StateMachine具有deepHistory伪状态。

两个StateMachines都具有三个复合状态: Turbine_01Turbine_02Turbine_03 ,每个复合状态都具有“ 关闭”和“ 打开”状态,并且在其区域中具有历史伪状态。

为了更好地观察“深层历史记录”和“浅层历史记录”之间的差异,我们在一次仿真中执行了两个StateMachines。

DeepHistory and ShallowHistory Pseudostates in Sparx Systems Enterprise Architect

下图说明了DeepTurbineManager中的StateMachine:

DeepHistory Pseudostate Simulation StateMachine in Sparx Systems Enterprise Architect

下图说明了ShallowTurbineManager中的StateMachine:

ShallowHistory Pseudostate Simulation StateMachine, Sparx Systems Enterprise Architect

提示:如果您在图表上的“历史记录”节点上单击鼠标右键,然后选择“高级|深度历史”选项,您可以在浅和深之间切换历史伪状态的类型。

首次激活国家

After simulation starts, Turbine_01 and its substate Off are activated.

Trigger Sequence: [MODE, SPEED]

Shallow and Deep History pseudostates example in executable statemachines

Then the active State configuration includes:

  • Turbine_01
  • Turbine_01.On
  • Turbine_01.On.High

This applies to both deepManager and shallowManager.

Trigger Sequence: [NEXT]

Shallow and Deep History pseudostates example in executable statemachines

This trace sequence can be observed from the Simulation window (Simulate > Dynamic Simulation > Simulator > Open Simulation Window):

        01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On_High EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On EXIT

        03    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01 EXIT

        04    shallowManager[ShallowTurbineManager].Turbine_01__TO__History2_105720_61730 Effect

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 ENTRY

        06    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 DO

        07    shallowManager[ShallowTurbineManager].History2_105720__TO__Off_61731 Effect

        08    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off ENTRY

        09    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off DO

Note: Since deepManager has exactly the same trace as shallowManager, the trace for deepManager is filtered out from this sequence.

We can learn that:

  • Exiting a Composite State commences with the innermost State in the active State configuration (see lines 01 - 03 in the trace sequence)
  • The Default History Transition is only taken if execution leads to the History node (see line 04) and the State has never been active before (see line 07)

Then the active State configuration includes:

  • Turbine_02
  • Turbine_02.Off

This applies to both deepManager and shallowManager.

Trigger Sequence: [NEXT, MODE]

Shallow and Deep History pseudostates example in executable statemachines

This trace sequence can be observed from the Simulation window:

          Trigger [NEXT]

        01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 EXIT

        03    shallowManager[ShallowTurbineManager].Turbine_02__TO__History3_105713_61725 Effect

        04    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 ENTRY

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 DO

        06    shallowManager[ShallowTurbineManager].Initial_105706__TO__Off_61718 Effect

        07    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_Off ENTRY

        08    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_Off DO

          Trigger [MODE]

           Message omitted...

Note: Since deepManager has exactly the same trace as shallowManager, the trace for deepManager is filtered out from this sequence.

We can learn that:

  • Since there is no default History Transition defined for History3, the standard default entry of the State is performed; an Initial node is found in the Region contained by Turbine_03, so the Transition originating from Initial is enabled (see line 06)

Then the active state configuration includes:

  • Turbine_03
  • Turbine_03.On
  • Turbine_03.On.Low

This applies to both deepManager and shallowManager.

国家的历史录入

As a reference, we show the Deep History snapshot of each Turbine after its first activation:

Turbine_01

  • Turbine_01.On
  • Turbine_01.On.High

Turbine_02

  • Turbine_02.Off

Turbine_03

  • Turbine_03.On
  • Turbine_03.On.Low

When we further Trigger NEXT, Turbine_01 will be activated again.

Shallow and Deep History pseudostates example in executable statemachines

This trace sequence can be observed from the Simulation window:

For shallowManager:

          Trigger [NEXT]

        01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On_Low EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On EXIT

        03    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 EXIT

        04    shallowManager[ShallowTurbineManager].Turbine_03__TO__History1_105711_61732 Effect

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01 ENTRY

        06    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01 DO

        07    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On ENTRY

        08    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On DO

        09    shallowManager[ShallowTurbineManager].Initial_105721__TO__Low_61729 Effect

        10    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On_Low ENTRY

        11    shallowManager[ShallowTurbineManager].StateMachine_Turbine_01_On_Low DO

We can learn that:

  • The shallowHistory node restores Turbine_01 as far as Turbine_01.On
  • Then the Region contained by Composite State Turbine_01.On will be activated by the Initial node, which activated at Low

For deepManager:

          Trigger [NEXT]

        01    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On_Low EXIT

        02    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On EXIT

        03    deepManager[DeepTurbineManager].StateMachine_Turbine_03 EXIT

        04    deepManager[DeepTurbineManager].Turbine_03__TO__History1_105679_61708 Effect

        05    deepManager[DeepTurbineManager].StateMachine_Turbine_01 ENTRY

        06    deepManager[DeepTurbineManager].StateMachine_Turbine_01 DO

        07    deepManager[DeepTurbineManager].StateMachine_Turbine_01_On ENTRY

        08    deepManager[DeepTurbineManager].StateMachine_Turbine_01_On_High ENTRY

We can learn that:

  • The deepHistory node restores Turbine_01 as far as Turbine_01.On.High

Trigger [NEXT] to exit Turbine_01 and activate Turbine_02

Both shallowManager and deepManager activate Turbine_02.Off, which is the History snapshot when they exited.

Trigger [NEXT] to exit Turbine_02 and activate Turbine_03

Both shallowManager and deepManager activate Turbine_03.On.Low. However, the sequences of shallowManager and deepManager are different.

For shallowManager, the shallowHistory can only restore as far as Turbine_03.On. Since an Initial node is defined in Turbine_03.On, the Transition originating from Initial will be enabled and Turbine_03.On.Low is reached.

        01    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02_Off EXIT

        02    shallowManager[ShallowTurbineManager].StateMachine_Turbine_02 EXIT

        03    shallowManager[ShallowTurbineManager].Turbine_02__TO__History3_105713_61725 Effect

        04    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 ENTRY

        05    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03 DO

        06    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On ENTRY

        07    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On DO

        08    shallowManager[ShallowTurbineManager].Initial_105727__TO__Low_61728 Effect

        09    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On_Low ENTRY

        10    shallowManager[ShallowTurbineManager].StateMachine_Turbine_03_On_Low DO

For deepManager, the deephistory can restore as far as Turbine_03.On.Low directly.

        01    deepManager[DeepTurbineManager].StateMachine_Turbine_02_Off EXIT

        02    deepManager[DeepTurbineManager].StateMachine_Turbine_02 EXIT

        03    deepManager[DeepTurbineManager].Turbine_02__TO__History3_105680_61701 Effect

        04    deepManager[DeepTurbineManager].StateMachine_Turbine_03 ENTRY

        05    deepManager[DeepTurbineManager].StateMachine_Turbine_03 DO

        06    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On ENTRY

        07    deepManager[DeepTurbineManager].StateMachine_Turbine_03_On_Low ENTRY