56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
|
|
namespace VisionCommon {
|
|
public class CoordUnitValueConverter : IValueConverter {
|
|
private eCoordUnit _coordUnit;
|
|
|
|
public CoordUnitValueConverter() {
|
|
_coordUnit = VisionSettingManager.VisionSetting.CoordUnit;
|
|
}
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
|
|
var doubleValue = (double)value;
|
|
if (_coordUnit == eCoordUnit.UM) {
|
|
return MathUtil.ConvertUnitMilliToMicro(doubleValue);
|
|
}
|
|
return doubleValue;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
|
|
string strValue = value.ToString();
|
|
double doubleValue = 0;
|
|
|
|
if (!Double.TryParse(strValue, out doubleValue)) {
|
|
return 0;
|
|
}
|
|
|
|
if (_coordUnit == eCoordUnit.UM) {
|
|
return MathUtil.ConvertUnitMicroToMilli(doubleValue);
|
|
}
|
|
|
|
return doubleValue;
|
|
}
|
|
|
|
public static double GetCoordUnitValue(double value) {
|
|
if (VisionSettingManager.VisionSetting.CoordUnit == eCoordUnit.UM) {
|
|
return MathUtil.ConvertUnitMilliToMicro(value);
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
public static string GetCoordUnitString(double value) {
|
|
if (VisionSettingManager.VisionSetting.CoordUnit == eCoordUnit.UM) {
|
|
return MathUtil.ConvertUnitMilliToMicro(value).ToString("F1");
|
|
}
|
|
return value.ToString("F4");
|
|
}
|
|
}
|
|
}
|