Sic.Framework/MECF.Framework.UI.Client/RecipeEditorLib/RecipeModel/Params/Param.cs

313 lines
7.4 KiB
C#
Raw Normal View History

using System;
2023-04-13 11:51:03 +08:00
using System.Collections.Generic;
using System.Windows;
using Caliburn.Micro.Core;
2023-04-13 11:51:03 +08:00
using ExtendedGrid.Microsoft.Windows.Controls;
namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params
2023-04-13 11:51:03 +08:00
{
public abstract class Param : PropertyChangedBase, IParam
{
#region Variables
public event EventHandler<object> OnValueChanged;
2023-04-13 11:51:03 +08:00
protected string _name;
protected string _displayName;
protected string _unitName;
protected bool _isEnabled;
protected bool _isSaved;
protected bool _isColumnSelected;
protected Visibility _visibility;
protected bool _isValidated;
protected string _validationError;
protected bool _isEqualsToPrevious;
protected bool _isHighlighted;
protected bool _isHideValue;
#endregion
#region Constructors
protected Param()
{
_isSaved = true;
_isEnabled = true;
_isValidated = true;
_validationError = null;
_isEqualsToPrevious = true;
_visibility = Visibility.Visible;
_isHighlighted = false;
_isHideValue = false;
}
#endregion
#region Properties
public Action<Param> Feedback { get; set; }
public Func<Param, bool> Check { get; set; }
public RecipeStep Parent { get; set; }
public DataGridRow RowOwner { get; set; }
public DataGridColumn ColumnOwner { get; set; }
public virtual IParam Previous { get; set; }
public virtual IParam Next { get; set; }
/// <summary>
/// 设置或返回当前参数的控制名称。
/// <remarks>
/// 对应RecipeFormat.xml文件中的ControlName。
/// </remarks>
/// </summary>
2023-04-13 11:51:03 +08:00
public string Name
{
get => _name;
set
{
_name = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 设置或返回当前参数的显示名称。
/// </summary>
2023-04-13 11:51:03 +08:00
public string DisplayName
{
get => _displayName;
set
{
_displayName = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 设置或返回当前参数的单位。
/// </summary>
2023-04-13 11:51:03 +08:00
public string UnitName
{
get => _unitName;
set
{
_unitName = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
public bool IsEnabled
{
get => _isEnabled;
set
{
_isEnabled = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 设置或返回当前参数是否为已保存状态。
/// </summary>
2023-04-13 11:51:03 +08:00
public virtual bool IsSaved
{
get => _isSaved;
set
{
_isSaved = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 设置或返回当前参数的数值是否和前序参数的数值相等。
2023-04-13 11:51:03 +08:00
/// </summary>
/// <remarks>
/// 该属性用于渲染DataGrid单元格文本颜色当不等于前序参数数值时当前参数显示为绿色。
/// </remarks>
2023-04-13 11:51:03 +08:00
public bool IsEqualsToPrevious
{
get => _isEqualsToPrevious;
set
{
_isEqualsToPrevious = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 返回当前参数是否通过验证。
2023-04-13 11:51:03 +08:00
/// </summary>
public bool IsValidated
{
get => _isValidated;
internal set
{
_isValidated = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 返回当前参数校验错误原因。
2023-04-13 11:51:03 +08:00
/// </summary>
public string ValidationError
{
get => _validationError;
protected set
{
_validationError = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 返回是否高亮当前参数。
/// </summary>
public bool IsHighlighted
{
get => _isHighlighted;
private set
{
_isHighlighted = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
/// <summary>
/// 返回是否隐藏参数的值。
/// </summary>
public virtual bool IsHideValue
{
get => _isHideValue;
set
{
_isHideValue = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
public bool IsColumnSelected
{
get => _isColumnSelected;
set
{
_isColumnSelected = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
public Visibility Visible
{
get => _visibility;
set
{
_visibility = value;
NotifyOfPropertyChange();
2023-04-13 11:51:03 +08:00
}
}
public bool EnableConfig { get; set; }
public bool EnableTolerance { get; set; }
public Visibility StepCheckVisibility { get; set; }
#region Methods
2023-04-13 11:51:03 +08:00
/// <summary>
/// 高亮显示当前参数。
/// </summary>
public void Highlight()
{
IsHighlighted = true;
}
/// <summary>
/// 取消高亮显示。
/// </summary>
public void ResetHighlight()
{
IsHighlighted = false;
}
#endregion
#region Methods
/// <summary>
/// 将当前参数所对应的前序、后续参数链表转换为数组。
2023-04-13 11:51:03 +08:00
/// </summary>
/// <returns></returns>
public virtual List<IParam> Flatten()
{
if (Previous != null)
return Previous.Flatten();
var list = new List<IParam>();
IParam p = this;
while (p != null)
{
list.Add(p);
p = p.Next;
}
return list;
}
/// <summary>
/// 校验当前参数的数值。
2023-04-13 11:51:03 +08:00
/// </summary>
/// <returns></returns>
public virtual void Validate()
{
IsValidated = true;
ValidationError = "";
}
/// <summary>
/// 将当前参数标记为已保存状态。
/// </summary>
2023-04-13 11:51:03 +08:00
public virtual void Save()
{
IsSaved = true;
}
/// <summary>
/// 获取当前参数的数值。
/// </summary>
/// <returns></returns>
2023-04-13 11:51:03 +08:00
public virtual object GetValue()
{
return default;
2023-04-13 11:51:03 +08:00
}
public void SetValue(object value)
{
HandleSetValue(value);
OnValueChanged?.Invoke(this, value);
}
2023-04-13 11:51:03 +08:00
public override string ToString()
{
return $"{DisplayName}, ControlName={Name}";
}
protected virtual void HandleSetValue(object value)
{
}
2023-04-13 11:51:03 +08:00
#endregion
#endregion
2023-04-13 11:51:03 +08:00
}
}