添加 MX-PD-盘古 项目文件
将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using MainShell.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class BondingPathModeToBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
BondingPathMode speedMode = (BondingPathMode)value;
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
|
||||
return mode == (int)speedMode ? true : false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
return (BondingPathMode)mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using MainShell.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class BondingRegionModeToBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
BondingStagePathMode speedMode = (BondingStagePathMode)value;
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
|
||||
return mode == (int)speedMode ? true : false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
return (BondingStagePathMode)mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using MainShell.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class BondingWsPathModeToBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
BondingWSPathMode speedMode = (BondingWSPathMode)value;
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
|
||||
return mode == (int)speedMode ? true : false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
return (BondingWSPathMode)mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class BoolToInversionConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
return !System.Convert.ToBoolean(value);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class BoolToVisibleConverter : IValueConverter
|
||||
{
|
||||
// 将 bool (或可转换为 bool 的值) 转换为 Visibility
|
||||
// parameter 支持:
|
||||
// 包含 "invert" / "inverse" / "not" / "!" 的字符串 — 反转布尔值
|
||||
// 包含 "hidden" 的字符串 — 当为 false 时返回 Visibility.Hidden 而不是 Collapsed
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
bool isVisible = false;
|
||||
|
||||
if (value is bool b)
|
||||
{
|
||||
isVisible = b;
|
||||
}
|
||||
else if (value is bool?)
|
||||
{
|
||||
isVisible = ((bool?)value) ?? false;
|
||||
}
|
||||
else if (value is string s)
|
||||
{
|
||||
bool.TryParse(s, out isVisible);
|
||||
}
|
||||
else if (value != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
isVisible = System.Convert.ToBoolean(value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
isVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
var paramString = parameter as string;
|
||||
bool invert = false;
|
||||
bool useHidden = false;
|
||||
if (!string.IsNullOrEmpty(paramString))
|
||||
{
|
||||
var p = paramString.ToLowerInvariant();
|
||||
if (p.Contains("invert") || p.Contains("inverse") || p.Contains("not") || p.Contains("!"))
|
||||
invert = true;
|
||||
if (p.Contains("hidden"))
|
||||
useHidden = true;
|
||||
}
|
||||
|
||||
if (invert)
|
||||
isVisible = !isVisible;
|
||||
|
||||
return isVisible ? Visibility.Visible : (useHidden ? Visibility.Hidden : Visibility.Collapsed);
|
||||
}
|
||||
|
||||
// 将 Visibility 转换回 bool
|
||||
// Visible => true;Hidden/Collapsed => false
|
||||
// 支持与 Convert 相同的 parameter 反转语义
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is Visibility))
|
||||
return Binding.DoNothing;
|
||||
|
||||
var vis = (Visibility)value;
|
||||
bool result = vis == Visibility.Visible;
|
||||
|
||||
var paramString = parameter as string;
|
||||
if (!string.IsNullOrEmpty(paramString))
|
||||
{
|
||||
var p = paramString.ToLowerInvariant();
|
||||
if (p.Contains("invert") || p.Contains("inverse") || p.Contains("not") || p.Contains("!"))
|
||||
result = !result;
|
||||
}
|
||||
|
||||
if (targetType == typeof(bool) || targetType == typeof(object))
|
||||
return result;
|
||||
if (targetType == typeof(bool?))
|
||||
return (bool?)result;
|
||||
|
||||
try
|
||||
{
|
||||
return System.Convert.ChangeType(result, targetType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class DateTimeToStringConverter : IValueConverter
|
||||
{
|
||||
public string Format { get; set; } = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null) return string.Empty;
|
||||
if (!(value is DateTime dt)) return string.Empty;
|
||||
if (dt == DateTime.MinValue) return string.Empty;
|
||||
|
||||
// parameter 优先用于临时格式覆盖
|
||||
var fmt = parameter as string ?? Format;
|
||||
return dt.ToString(fmt, culture);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Markup;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
// XAML 中可直接写 {conv:EnumBindingSource {x:Type local:MyEnum}}
|
||||
public class EnumBindingSourceExtension : MarkupExtension
|
||||
{
|
||||
public Type EnumType { get; set; }
|
||||
public bool UseDescription { get; set; } = true;
|
||||
|
||||
public EnumBindingSourceExtension() { }
|
||||
|
||||
public EnumBindingSourceExtension(Type enumType)
|
||||
{
|
||||
EnumType = enumType;
|
||||
}
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
if (EnumType == null || !EnumType.IsEnum) return null;
|
||||
|
||||
var values = Enum.GetValues(EnumType).Cast<Enum>();
|
||||
return values.Select(v => new EnumItem
|
||||
{
|
||||
Value = v,
|
||||
Description = UseDescription ? EnumHelper.GetEnumDescription(v) : v.ToString()
|
||||
}).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public class EnumItem
|
||||
{
|
||||
public Enum Value { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int IntValue => Convert.ToInt32(Value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using MwFramework.Device;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取枚举类型的Description描述信息
|
||||
/// </summary>
|
||||
public class EnumDescriptionConverter : IValueConverter
|
||||
{
|
||||
object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value.ToString() != "")
|
||||
{
|
||||
Enum myEnum = (Enum)value;
|
||||
string description = EnumHelper.GetEnumDescription(myEnum);
|
||||
return description;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public class EnumToBool : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return (int)value == (int)parameter;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if ((bool)value)
|
||||
{
|
||||
return parameter;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class EnumHelper
|
||||
{
|
||||
public static string GetEnumDescription(Enum enumObj)
|
||||
{
|
||||
FieldInfo fieldInfo = enumObj.GetType().GetField(enumObj.ToString());
|
||||
var descriptionAttr = fieldInfo
|
||||
.GetCustomAttributes(false)
|
||||
.OfType<DescriptionAttribute>()
|
||||
.Cast<DescriptionAttribute>()
|
||||
.SingleOrDefault();
|
||||
if (descriptionAttr == null)
|
||||
{
|
||||
return enumObj.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return descriptionAttr.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class ObjectToBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value != null;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using MainShell.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class RunningModeEnumToBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
RunningMode speedMode = (RunningMode)value;
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
|
||||
return mode == (int)speedMode ? true : false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
|
||||
int mode = System.Convert.ToInt32(parameter.ToString());
|
||||
return (RunningMode)mode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class ScreenToViewModelConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value == null) return null;
|
||||
|
||||
var viewModelType = value.GetType();
|
||||
var viewName = viewModelType.FullName.Replace("ViewModel", "View");
|
||||
var viewType = Type.GetType(viewName);
|
||||
|
||||
if (viewType != null)
|
||||
{
|
||||
// 创建View实例,并设置其DataContext为当前的ViewModel
|
||||
var view = (FrameworkElement)Activator.CreateInstance(viewType);
|
||||
view.DataContext = value;
|
||||
return view;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using MainShell.Recipe.Models.SubstrateParameter;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class SubstrateHeightMeasureModeToBoolConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
var mode = value is SubstrateHeightMeasureMode measureMode ? measureMode : SubstrateHeightMeasureMode.StandardTeachPosition;
|
||||
var parameterValue = System.Convert.ToInt32(parameter, CultureInfo.InvariantCulture);
|
||||
|
||||
return parameterValue == (int)mode;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (!(value is bool isChecked) || !isChecked)
|
||||
{
|
||||
return Binding.DoNothing;
|
||||
}
|
||||
|
||||
var parameterValue = System.Convert.ToInt32(parameter, CultureInfo.InvariantCulture);
|
||||
return (SubstrateHeightMeasureMode)parameterValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace MainShell.Converter
|
||||
{
|
||||
public class WidthToMarginConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
double actualWidth = 0;
|
||||
if (value is double d) actualWidth = d;
|
||||
|
||||
double expanded = 200;
|
||||
double extra = 0;
|
||||
|
||||
if (parameter is string s)
|
||||
{
|
||||
var parts = s.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length >= 1 && double.TryParse(parts[0], out var p0)) expanded = p0;
|
||||
if (parts.Length >= 2 && double.TryParse(parts[1], out var p1)) extra = p1;
|
||||
}
|
||||
|
||||
// 计算右侧 Margin:
|
||||
// 当 actualWidth == expanded 时返回 0(不偏移)
|
||||
// 当 actualWidth 减小时会返回正值,从而把 ToggleButton 向左推(或根据需要调整公式)
|
||||
double right = Math.Max(0, expanded - actualWidth) + extra;
|
||||
|
||||
// 根据布局需要你可以修改这里返回的 Thickness 的哪一项(Left/Right)
|
||||
return new Thickness(-30, 0, 0, 0);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user