63 lines
2.7 KiB
C#
63 lines
2.7 KiB
C#
using System.Windows.Media;
|
|
using Prism.Mvvm;
|
|
using XP.Common.Localization.Interfaces;
|
|
|
|
namespace XP.Calibration.ViewModels;
|
|
|
|
/// <summary>
|
|
/// Detector Centering 结果对话框 ViewModel
|
|
/// </summary>
|
|
public class DetectorCenteringResultViewModel : BindableBase
|
|
{
|
|
private const double MaxAllowedOffset = 0.2; // mm
|
|
private const double MaxAllowedTwist = 0.2; // degrees
|
|
|
|
private readonly ILocalizationService _loc;
|
|
|
|
public DetectorCenteringResultViewModel(ILocalizationService localizationService)
|
|
{
|
|
_loc = localizationService;
|
|
}
|
|
|
|
public double XOffset_mm { get; set; }
|
|
public double YOffset_mm { get; set; }
|
|
public double TwistAngle_deg { get; set; }
|
|
|
|
public string XOffsetText => $"{XOffset_mm:F2}";
|
|
public string YOffsetText => $"{YOffset_mm:F2}";
|
|
public string TwistAngleText => $"{TwistAngle_deg:F2}";
|
|
|
|
public bool XPass => Math.Abs(XOffset_mm) <= MaxAllowedOffset;
|
|
public bool YPass => Math.Abs(YOffset_mm) <= MaxAllowedOffset;
|
|
public bool TwistPass => Math.Abs(TwistAngle_deg) <= MaxAllowedTwist;
|
|
public bool AllPass => XPass && YPass && TwistPass;
|
|
|
|
public string XPassText => XPass ? _loc.GetString("Cal_DC_Pass") : _loc.GetString("Cal_DC_Fail");
|
|
public string YPassText => YPass ? _loc.GetString("Cal_DC_Pass") : _loc.GetString("Cal_DC_Fail");
|
|
public string TwistPassText => TwistPass ? _loc.GetString("Cal_DC_Pass") : _loc.GetString("Cal_DC_Fail");
|
|
|
|
public Brush XPassColor => XPass ? Brushes.Green : Brushes.Red;
|
|
public Brush YPassColor => YPass ? Brushes.Green : Brushes.Red;
|
|
public Brush TwistPassColor => TwistPass ? Brushes.Green : Brushes.Red;
|
|
|
|
public string XHintText => FormatMoveHint(XOffset_mm, _loc.GetString("Cal_DC_DirLeft"), _loc.GetString("Cal_DC_DirRight"));
|
|
public string YHintText => FormatMoveHint(YOffset_mm, _loc.GetString("Cal_DC_DirFront"), _loc.GetString("Cal_DC_DirBack"));
|
|
public string TwistHintText => FormatRotateHint(TwistAngle_deg);
|
|
|
|
private string FormatMoveHint(double offset, string negDir, string posDir)
|
|
{
|
|
double abs = Math.Abs(offset);
|
|
if (abs < 0.005) return _loc.GetString("Cal_DC_MoveZero");
|
|
string dir = offset < 0 ? negDir : posDir;
|
|
return string.Format(_loc.GetString("Cal_DC_MoveHint"), $"{abs:F2}", dir);
|
|
}
|
|
|
|
private string FormatRotateHint(double angle)
|
|
{
|
|
double abs = Math.Abs(angle);
|
|
if (abs < 0.005) return _loc.GetString("Cal_DC_RotateZero");
|
|
string dir = angle < 0 ? _loc.GetString("Cal_DC_DirCW") : _loc.GetString("Cal_DC_DirCCW");
|
|
return string.Format(_loc.GetString("Cal_DC_RotateHint"), $"{abs:F2}", dir);
|
|
}
|
|
}
|