using OpenSEMI.ClientBase; using System; using System.Collections.Generic; using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Animation; namespace CyberX8_Themes.CustomControls { public class WaferIntToColorConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return int.Parse(value.ToString()) == 1 ? new SolidColorBrush(Colors.Red) : new SolidColorBrush(Colors.Green); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public class WaferIntToVisibilityConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return int.Parse(value.ToString()) == 1 ? Visibility.Visible : Visibility.Hidden; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } public enum WaferRobotXAction { X_Origin, Extend, Retract, Extend2, Retract2 } public enum WaferRobotTAction { T_Origin, PMA, PMB, PMC, PMD, LLA, LLB, LP1, LP2, LP3, Aligner1, RightLocation, LeftLocation, PUF1, PUF2, Dummy1, Dummy2, SRD1, SRD2 } public class WaferRobotControl : Control { static WaferRobotControl() { DefaultStyleKeyProperty.OverrideMetadata(typeof(WaferRobotControl), new FrameworkPropertyMetadata(typeof(WaferRobotControl))); } public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(WaferRobotControl)); public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); } public static readonly DependencyProperty ExtendTimeProperty = DependencyProperty.Register("ExtendTime", typeof(KeyTime), typeof(WaferRobotControl),new PropertyMetadata (KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9)))); public KeyTime ExtendTime { get => (KeyTime)GetValue(ExtendTimeProperty); set => SetValue(ExtendTimeProperty, value); } public static readonly DependencyProperty RobotWaferProperty = DependencyProperty.Register( "RobotWafer", typeof(WaferInfo), typeof(WaferRobotControl)); public WaferInfo RobotWafer { get => (WaferInfo)GetValue(RobotWaferProperty); set => SetValue(RobotWaferProperty, value); } public static readonly DependencyProperty RobotXActionProperty = DependencyProperty.Register( "RobotXAction", typeof(WaferRobotXAction), typeof(WaferRobotControl), new PropertyMetadata(WaferRobotXAction.X_Origin, RobotXActionPropertyChangedCallback)); public WaferRobotXAction RobotXAction { get => (WaferRobotXAction)GetValue(RobotXActionProperty); set => SetValue(RobotXActionProperty, value); } private static void RobotXActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { //KeyTime value = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(9)); var control = d as WaferRobotControl; var oldAct = (WaferRobotXAction)e.OldValue; var newAct = (WaferRobotXAction)e.NewValue; switch (newAct) { case WaferRobotXAction.X_Origin: VisualStateManager.GoToState(control, newAct.ToString(), true); break; case WaferRobotXAction.Extend: if (newAct != oldAct) { VisualStateManager.GoToState(control, newAct.ToString(), true); } break; case WaferRobotXAction.Extend2: if (newAct != oldAct) { VisualStateManager.GoToState(control, newAct.ToString(), true); } break; case WaferRobotXAction.Retract2: if (newAct != oldAct) { VisualStateManager.GoToState(control, newAct.ToString(), true); } break; case WaferRobotXAction.Retract: if (newAct != oldAct) { VisualStateManager.GoToState(control, newAct.ToString(), true); } break; default: break; } } public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register( "RobotTAction", typeof(WaferRobotTAction), typeof(WaferRobotControl), new PropertyMetadata(WaferRobotTAction.T_Origin, RobotTActionPropertyChangedCallback)); public WaferRobotTAction RobotTAction { get => (WaferRobotTAction)GetValue(RobotTActionProperty); set => SetValue(RobotTActionProperty, value); } public static readonly DependencyProperty RobotSpeedProperty = DependencyProperty.Register( "RobotSpeed", typeof(double), typeof(WaferRobotControl), new PropertyMetadata(9.0d, RobotSpeedPropertyChangedCallback)); public double RobotSpeed { get => (double)GetValue(RobotSpeedProperty); set => SetValue(RobotSpeedProperty, value); } private static void RobotSpeedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { } public string OriginT { get; set; } private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { var control = d as WaferRobotControl; var oldAct = (WaferRobotTAction)e.OldValue; var newAct = (WaferRobotTAction)e.NewValue; if(oldAct!=newAct) { VisualStateManager.GoToState(control, newAct.ToString(), true); } } public override void OnApplyTemplate() { base.OnApplyTemplate(); VisualStateManager.GoToState(this, WaferRobotXAction.X_Origin.ToString(), true); VisualStateManager.GoToState(this, OriginT, true); } } }