前页 后页

示例:历史伪状态

“状态历史记录”是与复合状态区域相关联的一种方便的概念,通过“区域历史记录”,区域可以跟踪上一次退出状态所处的状态。这样,在必要时,下一个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

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

首次激活国家

模拟开始后,将激活Turbine_01及其子状态“ 关闭”

触发顺序:[模式,速度]

Shallow and Deep History pseudostates example in executable statemachines

然后,活动状态配置包括:

  • 涡轮_01
  • Turbine_01.On
  • Turbine_01.On.High
这适用于deepManagershallowManager。

触发顺序:[NEXT]

Shallow and Deep History pseudostates example in executable statemachines

可以从“模拟”窗口(“模拟”>“动态模拟”>“模拟器”>“打开模拟”窗口)观察此跟踪序列:

01 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_01_On_High退出

02 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_01_On退出

03 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_01 EXIT

04 horizontalManager [ShallowTurbineManager] .Turbine_01__TO__History2_105720_61730效果

05 horizontalManager [ShallowTurbineManager] .StateMachine_Turbine_02 ENTRY

06算法shallowManager [ShallowTurbineManager] .StateMachine_Turbine_02 DO

       07 ShallowManager [ShallowTurbineManager] .History2_105720__TO__Off_61731效果

08算法浅层管理器[浅层涡轮管理器] .StateMachine_Turbine_02_OffENTRY

09 thinManager [ShallowTurbineManager] .StateMachine_Turbine_02_Off DO

注:由于deepManager具有完全相同的轨迹作为shallowManager,deepManager的轨迹由该序列过滤掉。

我们可以了解到:

  • 退出复合状态从活动状态配置中的最内部状态开始(请参见跟踪序列中的第01-03行)
  • 仅当执行导致“历史记录”节点(请参见第04行)并且状态从未处于活动状态(请参见第07行)时,才执行“默认历史记录过渡”。

然后,活动状态配置包括:

  • Turbine_02
  • Turbine_02.Off
这适用于deepManagershallowManager。

触发顺序:[下一个,模式]

Shallow and Deep History pseudostates example in executable statemachines

可以从“模拟”窗口中观察到此跟踪序列:

触发[NEXT]

01allowManager [ShallowTurbineManager] .StateMachine_Turbine_02_Off退出

02 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_02 EXIT

03 ShallowManager [ShallowTurbineManager] .Turbine_02__TO__History3_105713_61725效果

04 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03 ENTRY

05 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03 DO

         06shallowManager [ShallowTurbineManager] .Initial_105706__TO__Off_61718效果

07 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03_Off ENTRY

08算法shallowManager [ShallowTurbineManager] .StateMachine_Turbine_03_Off DO

触发[模式]

讯息已省略...

注:由于deepManager具有完全相同的轨迹作为shallowManager,deepManager的轨迹由该序列过滤掉。

我们可以了解到:

  • 由于没有为History3定义默认的History Transition,因此将执行State的标准默认条目。在Turbine_03包含的Region中找到一个Initial节点因此启用了从Initial发起的转换(请参见第06行)

然后,活动状态配置包括:

  • 涡轮_03
  • Turbine_03.On
  • Turbine_03.On.Low
这适用于deepManagershallowManager。

国家的历史录入

作为参考,我们显示了每个涡轮首次激活后的“深度历史记录”快照:

涡轮_01

  • Turbine_01.On
  • Turbine_01.On.High
Turbine_02
  • Turbine_02.Off
涡轮_03
  • Turbine_03.On
  • Turbine_03.On.Low

当我们进一步触发NEXT时,Turbine_01将再次被激活。

Shallow and Deep History pseudostates example in executable statemachines

可以从“模拟”窗口中观察到此跟踪序列:

对于shallowManager:

触发[NEXT]

01allowManager [ShallowTurbineManager] .StateMachine_Turbine_03_On_Low退出

02 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03_On退出

03 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03 EXIT

04 slowManager [ShallowTurbineManager] .Turbine_03__TO__History1_105711_61732效果

05 HorizontalManager [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 thinManager [ShallowTurbineManager] .Initial_105721__TO__Low_61729效果

10 thinManager [ShallowTurbineManager] .StateMachine_Turbine_01_On_Low ENTRY

11.shallowManager [ShallowTurbineManager] .StateMachine_Turbine_01_On_Low DO

我们可以了解到:

  • ``shallowHistory''节点将Turbine_01还原到Turbine_01为止。
  • 然后,复合状态Turbine_01.On包含的Region将被Initial节点激活,该节点在Low下激活。

对于deepManager:

触发[NEXT]

01 deepManager [DeepTurbineManager] .StateMachine_Turbine_03_On_Low退出

02 deepManager [DeepTurbineManager] .StateMachine_Turbine_03_On退出

03 deepManager [DeepTurbineManager] .StateMachine_Turbine_03 EXIT

04 deepManager [DeepTurbineManager] .Turbine_03__TO__History1_105679_61708效果

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

我们可以了解到:

  • deepHistory节点将Turbine_01还原到Turbine_01.On.High

触发[NEXT]退出Turbine_01并激活Turbine_02

浅层管理器deepManager都激活Turbine_02.Off,这是退出时的历史记录快照。

触发[NEXT]退出Turbine_02并激活Turbine_03

deepManagerdeepManager都激活Turbine_03.On.Low。但是, shallowManagerdeepManager的顺序不同。

对于shallowManagershallowHistory只能还原到Turbine_03.On。由于在Turbine_03.On中定义了Initial节点,因此将启用从Initial发起的过渡,并达到Turbine_03.On.Low。

01allowManager [ShallowTurbineManager] .StateMachine_Turbine_02_Off退出

02 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_02 EXIT

03 ShallowManager [ShallowTurbineManager] .Turbine_02__TO__History3_105713_61725效果

04 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03 ENTRY

05 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03 DO

06 ShallowManager [ShallowTurbineManager] .StateMachine_Turbine_03_On ENTRY

07 thinManager [ShallowTurbineManager] .StateMachine_Turbine_03_On DO

        08 depthManager [ShallowTurbineManager] .Initial_105727__TO__Low_61728效果

09 thinManager [ShallowTurbineManager] .StateMachine_Turbine_03_On_Low ENTRY

10 thinManager [ShallowTurbineManager] .StateMachine_Turbine_03_On_Low DO

对于deepManager深度历史记录可以直接还原到Turbine_03.On.Low。

01 deepManager [DeepTurbineManager] .StateMachine_Turbine_02_Off退出

02 deepManager [DeepTurbineManager] .StateMachine_Turbine_02 EXIT

03 deepManager [DeepTurbineManager] .Turbine_02__TO__History3_105680_61701效果

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