using System;
namespace MECF.Framework.Common.Device.Bases
{
///
/// 预设的信号灯塔元件动作。
///
public class STAction : IComparable, ICloneable
{
#region Constructors
///
/// 信号灯塔元件动作构造函数。
///
/// 动作名称。
/// 信号塔组件对象的实例。
/// 信号塔组件输出状态。
/// 信号塔组件工作模式。如果传入空值,则自动调用
/// 以创建默认工作模式。
public STAction(string eventName, SignalTowerLightBase light, SignalTowerActions action, STBlinkPattern blinkPattern = null)
{
EventName = eventName;
Light = light;
Output = action;
BlinkPattern = blinkPattern ?? STBlinkPattern.GetDefaultPattern();
IsCycleDone = false;
}
#endregion
#region Properties
///
/// 动作对应的事件名称。
///
public string EventName { get; }
///
/// 返回执行当前动作的信号灯。
///
public STLightTypes LightType => Light.Type;
///
/// 返回信号灯实例。
///
public SignalTowerLightBase Light { get; }
///
/// 设置或返回信号灯的输出状态。
/// 支持的状态请参考枚举。
///
public SignalTowerActions Output { get; set; }
///
/// 设置或返回信号灯闪烁模式。
///
public STBlinkPattern BlinkPattern { get; set; }
///
/// 设置或返回是否循环结束。
///
public bool IsCycleDone { get; set; }
#endregion
#region Methods
///
public int CompareTo(object obj)
{
if (obj is not STAction target)
return -1;
return (BlinkPattern.CompareTo(target.BlinkPattern) == 0
&& Output == target.Output
&& Light == target.Light)
? 0
: -1;
}
///
public object Clone()
{
return new STAction(EventName, Light, Output, (STBlinkPattern)BlinkPattern.Clone());
}
///
public override string ToString()
{
return $"{Light}, {Output}";
}
#endregion
}
}