2023-05-10 16:21:45 +08:00
|
|
|
|
namespace MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel.Params
|
2023-04-13 11:51:03 +08:00
|
|
|
|
{
|
|
|
|
|
public class Sets3RatioParam : ParamBaseWithGenericValue<string>
|
|
|
|
|
{
|
|
|
|
|
#region Variables
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
|
|
public Sets3RatioParam()
|
|
|
|
|
{
|
|
|
|
|
_value = "1:1:1";
|
|
|
|
|
Ratio = new [] { 1.0, 1.0, 1.0 };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Sets3RatioParam(string initValue) : base(initValue)
|
|
|
|
|
{
|
|
|
|
|
Ratio = new[] { 1.0, 1.0, 1.0 };
|
|
|
|
|
ParseRatio(initValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
public override string Value
|
|
|
|
|
{
|
|
|
|
|
get => _value;
|
|
|
|
|
set
|
|
|
|
|
{
|
2023-09-22 14:58:18 +08:00
|
|
|
|
Set(ref _value, value);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
2023-06-16 13:43:26 +08:00
|
|
|
|
ColumnPermChangedCallback?.Invoke(this);
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
|
|
|
|
_isSaved = _value.Equals(_valueSnapshot);
|
2023-09-22 14:58:18 +08:00
|
|
|
|
OnPropertyChanged(nameof(IsSaved));
|
2023-04-13 11:51:03 +08:00
|
|
|
|
|
|
|
|
|
Validate();
|
|
|
|
|
ParseRatio(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public double[] Ratio { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Methods
|
|
|
|
|
|
|
|
|
|
private void ParseRatio(string value)
|
|
|
|
|
{
|
|
|
|
|
var nums = value.Split(':');
|
|
|
|
|
if (nums.Length == 3
|
|
|
|
|
&& double.TryParse(nums[0], out var r1)
|
|
|
|
|
&& double.TryParse(nums[1], out var r2)
|
|
|
|
|
&& double.TryParse(nums[2], out var r3))
|
|
|
|
|
{
|
|
|
|
|
Ratio[0] = r1;
|
|
|
|
|
Ratio[1] = r2;
|
|
|
|
|
Ratio[2] = r3;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Ratio[0] = double.NaN;
|
|
|
|
|
Ratio[1] = double.NaN;
|
|
|
|
|
Ratio[2] = double.NaN;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Validate()
|
|
|
|
|
{
|
|
|
|
|
if (ValidateRatioString(_value))
|
|
|
|
|
{
|
2023-06-16 09:51:51 +08:00
|
|
|
|
IsValid = true;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
ValidationError = null;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-16 09:51:51 +08:00
|
|
|
|
IsValid = false;
|
2023-04-13 11:51:03 +08:00
|
|
|
|
ValidationError = "Format error";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
public static bool ValidateRatioString(string value)
|
|
|
|
|
{
|
2023-05-10 16:21:45 +08:00
|
|
|
|
var nums = value.Split(':');
|
2023-04-13 11:51:03 +08:00
|
|
|
|
return nums.Length == 3
|
|
|
|
|
&& double.TryParse(nums[0], out _)
|
|
|
|
|
&& double.TryParse(nums[1], out _)
|
|
|
|
|
&& double.TryParse(nums[2], out _);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|