using Aitex.Core.Common; using Aitex.Sorter.Common; using System; using System.Globalization; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using MECF.Framework.Common.Equipment; namespace Aitex.Sorter.UI.Controls { /// /// AtmRobot.xaml 的交互逻辑 /// public partial class AtmRobot4LP : UserControl { private const int ms = 300; public int RotateAngle { get { return (int)GetValue(RotateAngleProperty); } set { SetValue(RotateAngleProperty, value); } } // Using a DependencyProperty as the backing store for RotateAngel. This enables animation, styling, binding, etc... public static readonly DependencyProperty RotateAngleProperty = DependencyProperty.Register("RotateAngel", typeof(int), typeof(AtmRobot4LP), new PropertyMetadata(0)); public int RobotWidth { get { return (int)GetValue(RobotWidthProperty); } set { SetValue(RobotWidthProperty, value); } } // Using a DependencyProperty as the backing store for RobotWidth. This enables animation, styling, binding, etc... public static readonly DependencyProperty RobotWidthProperty = DependencyProperty.Register("RobotWidth", typeof(int), typeof(AtmRobot4LP), new PropertyMetadata(0)); public int RobotHeight { get { return (int)GetValue(RobotHeightProperty); } set { SetValue(RobotHeightProperty, value); } } // Using a DependencyProperty as the backing store for RobotHeight. This enables animation, styling, binding, etc... public static readonly DependencyProperty RobotHeightProperty = DependencyProperty.Register("RobotHeight", typeof(int), typeof(AtmRobot4LP), new PropertyMetadata(60)); public int DockerWidth { get { return (int)GetValue(DockerWidthProperty); } set { SetValue(DockerWidthProperty, value); } } // Using a DependencyProperty as the backing store for DockerWidth. This enables animation, styling, binding, etc... public static readonly DependencyProperty DockerWidthProperty = DependencyProperty.Register("DockerWidth", typeof(int), typeof(AtmRobot4LP), new PropertyMetadata(0)); public WaferInfo Wafer1 { get { return (WaferInfo)GetValue(Wafer1Property); } set { SetValue(Wafer1Property, value); } } // Using a DependencyProperty as the backing store for WaferItem. This enables animation, styling, binding, etc... public static readonly DependencyProperty Wafer1Property = DependencyProperty.Register("Wafer1", typeof(WaferInfo), typeof(AtmRobot4LP), new PropertyMetadata(null)); public WaferInfo Wafer2 { get { return (WaferInfo)GetValue(Wafer2Property); } set { SetValue(Wafer2Property, value); } } // Using a DependencyProperty as the backing store for WaferItem. This enables animation, styling, binding, etc... public static readonly DependencyProperty Wafer2Property = DependencyProperty.Register("Wafer2", typeof(WaferInfo), typeof(AtmRobot4LP), new PropertyMetadata(null)); public ModuleName Station { get { return (ModuleName)GetValue(StationProperty); } set { SetValue(StationProperty, value); } } // Using a DependencyProperty as the backing store for Station. This enables animation, styling, binding, etc... public static readonly DependencyProperty StationProperty = DependencyProperty.Register("Station", typeof(ModuleName), typeof(AtmRobot4LP), new PropertyMetadata(ModuleName.Robot)); public ICommand Command { get { return (ICommand)GetValue(CommandProperty); } set { SetValue(CommandProperty, value); } } // Using a DependencyProperty as the backing store for Command. This enables animation, styling, binding, etc... public static readonly DependencyProperty CommandProperty = DependencyProperty.Register("Command", typeof(ICommand), typeof(AtmRobot4LP), new PropertyMetadata(null)); public ModuleName RobotBladeTarget { get { return (ModuleName)GetValue(RobotBladeTargetProperty); } set { SetValue(RobotBladeTargetProperty, value); } } public static readonly DependencyProperty RobotBladeTargetProperty = DependencyProperty.Register("RobotBladeTarget", typeof(ModuleName), typeof(AtmRobot4LP), new FrameworkPropertyMetadata(ModuleName.System, FrameworkPropertyMetadataOptions.AffectsRender)); public AtmRobot4LP() { InitializeComponent(); root.DataContext = this; canvas1.Rotate(90); canvas2.Rotate(180); canvas3.Rotate(180); canvas23.Rotate(180); Blade1Status = BladeStatus4LP.Retract; Blade2Status = BladeStatus4LP.Retract; } protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); //var text = new FormattedText(RobotBladeTarget.ToString(), CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Black); //drawingContext.DrawText(text, new Point(10, 0)); if (Blade1Status == BladeStatus4LP.Extend && (RobotBladeTarget == ModuleName.System || RobotBladeTarget == ModuleName.Robot)) { RetractBlade1(); RetractBlade2(); } if (Blade1Status == BladeStatus4LP.Retract && RobotBladeTarget != ModuleName.System && RobotBladeTarget != ModuleName.Robot) { ExtendBlade1(); ExtendBlade2(); } if (Blade1Status == BladeStatus4LP.Retract && Blade2Status == BladeStatus4LP.Retract) { MoveToHome(); return; } if (Blade1Status == BladeStatus4LP.Extend || Blade2Status == BladeStatus4LP.Extend) { MoveRobot(RobotBladeTarget); } } private bool MoveRobot(ModuleName chamberSet) { switch (chamberSet) { case ModuleName.System: break; case ModuleName.LP1: return MoveToLP1(); case ModuleName.LP2: return MoveToLP2(); case ModuleName.LP3: return MoveToLP3(); case ModuleName.LP4: return MoveToLP4(); case ModuleName.Robot: return MoveToHome(); case ModuleName.Aligner: return MoveToAligner(); case ModuleName.Upender: return MoveToInvertion(); default: break; } return false; } public RobotPostion4LP CurrentPosition { get; set; } public BladeStatus4LP Blade1Status { get; set; } public BladeStatus4LP Blade2Status { get; set; } private void MenuItem_Click(object sender, RoutedEventArgs e) { var cmd = ((MenuItem)sender).Tag; Command.Execute(new[] { Station.ToString(), cmd }); } private bool MoveToLP1() { switch (CurrentPosition) { case RobotPostion4LP.Home: HomeToLP1(); return true; case RobotPostion4LP.LP1: break; case RobotPostion4LP.LP2: LP2ToLP1(); return true; case RobotPostion4LP.LP3: LP3ToLP1(); return true; case RobotPostion4LP.LP4: LP4ToLP1(); return true; case RobotPostion4LP.Invertion: InvertionToLP1(); return true; case RobotPostion4LP.Aligner: AlignerToLP1(); return true; default: break; } return false; } private bool MoveToLP2() { switch (CurrentPosition) { case RobotPostion4LP.Home: HomeToLP2(); return true; case RobotPostion4LP.LP1: LP1ToLP2(); return true; case RobotPostion4LP.LP2: break; case RobotPostion4LP.LP3: LP3ToLP2(); return true; case RobotPostion4LP.LP4: LP4ToLP2(); return true; case RobotPostion4LP.Invertion: InvertionToLP2(); return true; case RobotPostion4LP.Aligner: AlignerToLP2(); return true; default: break; } return false; } private bool MoveToLP3() { switch (CurrentPosition) { case RobotPostion4LP.Home: HomeToLP3(); return true; case RobotPostion4LP.LP1: LP1ToLP3(); return true; case RobotPostion4LP.LP2: LP2ToLP3(); return true; case RobotPostion4LP.LP3: break; case RobotPostion4LP.LP4: LP4ToLP3(); return true; case RobotPostion4LP.Invertion: InvertionToLP3(); return true; case RobotPostion4LP.Aligner: AlignerToLP3(); return true; default: break; } return false; } private bool MoveToLP4() { switch (CurrentPosition) { case RobotPostion4LP.Home: HomeToLP4(); return true; case RobotPostion4LP.LP1: LP1ToLP4(); return true; case RobotPostion4LP.LP2: LP2ToLP4(); return true; case RobotPostion4LP.LP3: LP3ToLP4(); return true; case RobotPostion4LP.LP4: break; case RobotPostion4LP.Invertion: InvertionToLP4(); return true; case RobotPostion4LP.Aligner: AlignerToLP4(); return true; default: break; } return false; } private bool MoveToInvertion() { switch (CurrentPosition) { case RobotPostion4LP.Home: HomeToInvertion(); return true; case RobotPostion4LP.LP1: LP1ToInvertion(); break; case RobotPostion4LP.LP2: LP2ToInvertion(); return true; case RobotPostion4LP.LP3: LP3ToInvertion(); return true; case RobotPostion4LP.LP4: LP4ToInvertion(); return true; case RobotPostion4LP.Aligner: AlignerToInvertion(); return true; case RobotPostion4LP.Invertion: break; default: break; } return false; } private bool MoveToAligner() { switch (CurrentPosition) { case RobotPostion4LP.Home: HomeToAligner(); return true; case RobotPostion4LP.LP1: LP1ToAligner(); return true; case RobotPostion4LP.LP2: LP2ToAligner(); return true; case RobotPostion4LP.LP3: LP3ToAligner(); return true; case RobotPostion4LP.LP4: LP4ToAligner(); return true; case RobotPostion4LP.Invertion: InvertionToAligner(); return true; case RobotPostion4LP.Aligner: break; default: break; } return false; } private bool MoveToHome() { switch (CurrentPosition) { case RobotPostion4LP.Home: break; case RobotPostion4LP.LP1: LP1ToHome(); return true; case RobotPostion4LP.LP2: LP2ToHome(); return true; case RobotPostion4LP.Aligner: AlignerToHome(); return true; default: break; } return false; } private void ExtendBlade1() { canvas3.Rotate(0, true, ms); Blade1Status = BladeStatus4LP.Extend; } private void RetractBlade1() { canvas3.Rotate(180, true, ms); Blade1Status = BladeStatus4LP.Retract; } private void ExtendBlade2() { canvas23.Rotate(0, true, ms); Blade2Status = BladeStatus4LP.Extend; } private void RetractBlade2() { canvas23.Rotate(180, true, ms); Blade2Status = BladeStatus4LP.Retract; } private void RetractBlade() { canvas3.Rotate(180, true); canvas23.Rotate(180, true); } private void ExtendBlade(int angle) { canvas3.Rotate(angle, true); canvas23.Rotate(angle, true); } private void HomeToLP1() { ToLP1Start(ToLP1End); } private void LP1ToAligner() { ToLP1Start(() => ToAlignerStart(ToAlignerEnd)); } private void LP3ToAligner() { ToLP3Start(() => ToAlignerStart(ToAlignerEnd)); } private void LP4ToAligner() { ToLP4Start(() => ToAlignerStart(ToAlignerEnd)); } private void InvertionToAligner() { ToAlignerStart(ToAlignerEnd); } private void LP1ToLP2() { ToLP1Start(() => ToLP2Start(ToLP2End)); } private void LP3ToLP2() { ToLP3Start(() => ToLP2Start(ToLP2End)); } private void LP4ToLP2() { ToLP4Start(() => ToLP2Start(ToLP2End)); } private void HomeToLP2() { ToLP2Start(ToLP2End); } private void HomeToLP3() { ToLP3Start(ToLP3End); } private void LP1ToLP3() { ToLP1Start(() => ToLP3Start(ToLP3End)); } private void LP2ToLP3() { ToLP2Start(() => ToLP3Start(ToLP3End)); } private void LP4ToLP3() { ToLP4Start(() => ToLP3Start(ToLP3End)); } private void HomeToLP4() { ToLP4Start(ToLP4End); } private void LP1ToLP4() { ToLP1Start(() => ToLP4Start(ToLP4End)); } private void LP2ToLP4() { ToLP2Start(() => ToLP4Start(ToLP4End)); } private void LP3ToLP4() { ToLP3Start(() => ToLP4Start(ToLP4End)); } private void InvertionToLP1() { ToLP1Start(ToLP1End); } private void InvertionToLP2() { ToLP2Start(ToLP2End); } private void InvertionToLP3() { ToLP3Start(ToLP3End); } private void InvertionToLP4() { ToLP4Start(ToLP4End); } private void LP2ToLP1() { ToLP2Start(() => ToLP1Start(ToLP1End)); } private void LP3ToLP1() { ToLP3Start(() => ToLP1Start(ToLP1End)); } private void LP4ToLP1() { ToLP4Start(() => ToLP1Start(ToLP1End)); } private void LP2ToAligner() { ToLP2Start(() => { RetractBlade(); ToAlignerStart(() => { ExtendBlade(0); ToAlignerEnd(); }); }); } private void HomeToAligner() { ToAlignerStart(ToAlignerEnd); } private void AlignerToLP1() { ToAlignerStart(() => ToLP1Start(ToLP1End)); } private void AlignerToLP2() { ToAlignerStart( () => { RetractBlade(); ToLP2Start(() => { ExtendBlade(90); ToLP2End(); }); } ); } private void AlignerToLP3() { ToAlignerStart(() => ToLP3Start(ToLP3End)); } private void AlignerToLP4() { ToAlignerStart(() => ToLP4Start(ToLP4End)); } private void LP1ToHome() { ToLP1Start(ToHome); } private void LP2ToHome() { ToLP2Start(ToHome); } private void AlignerToHome() { ToAlignerStart(ToHome); } private void HomeToInvertion() { ToInvertionEnd(); } private void LP1ToInvertion() { ToLP1Start(ToInvertionEnd); } private void LP2ToInvertion() { ToLP2Start(ToInvertionEnd); } private void LP3ToInvertion() { ToLP3Start(ToInvertionEnd); } private void LP4ToInvertion() { ToLP4Start(ToInvertionEnd); } private void AlignerToInvertion() { ToAlignerStart(ToInvertionEnd); } private void ToLP1Start(Action action = null) { canvas1.Rotate(80, true, ms, 0, 0, () => { if (action != null) action(); }); canvas2.Rotate(280, true, ms, 0.5); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(270, true, ms); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(270, true, ms); CurrentPosition = RobotPostion4LP.LP1; } private void ToLP2Start(Action action = null) { canvas1.Rotate(120, true, ms, 0, 0, () => { if (action != null) action(); }); canvas2.Rotate(260, true, ms, 0.5); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(250, true, ms); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(250, true, ms); CurrentPosition = RobotPostion4LP.LP2; } private void ToLP3Start(Action action = null) { canvas1.Rotate(50, true, ms, 0, 0, () => { if (action != null) action(); }); canvas2.Rotate(130, true, ms, 0.5); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(90, true, ms); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(90, true, ms); CurrentPosition = RobotPostion4LP.LP3; } private void ToLP4Start(Action action = null) { canvas1.Rotate(120, true, ms, 0, 0, () => { if (action != null) action(); }); canvas2.Rotate(60, true, ms, 0.5); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(90, true, ms); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(90, true, ms); CurrentPosition = RobotPostion4LP.LP4; } private void ToAlignerStart(Action action = null) { canvas1.Rotate(45, true, ms, 0, 0, () => { if (action != null) action(); }); canvas2.Rotate(135, true, ms, 0); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(0, true, ms); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(0, true, ms); CurrentPosition = RobotPostion4LP.Aligner; } private void ToLP1End() { canvas1.Rotate(40, true, ms, 0); canvas2.Rotate(290, true, ms, 0); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(300, true, ms, 0); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(300, true, ms, 0); CurrentPosition = RobotPostion4LP.LP1; } private void ToLP2End() { canvas1.Rotate(70, true, ms, 0); canvas2.Rotate(210, true, ms, 0); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(350, true, ms, 0); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(350, true, ms, 0); CurrentPosition = RobotPostion4LP.LP2; } private void ToLP3End() { canvas1.Rotate(100, true, ms, 0); canvas2.Rotate(150, true, ms, 0); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(20, true, ms, 0); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(20, true, ms, 0); CurrentPosition = RobotPostion4LP.LP3; } private void ToLP4End() { canvas1.Rotate(145, true, ms, 0); canvas2.Rotate(75, true, ms, 0); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(50, true, ms, 0); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(50, true, ms, 0); CurrentPosition = RobotPostion4LP.LP4; } private void ToAlignerEnd() { canvas1.Rotate(150, true, ms, 0); canvas2.Rotate(30, true, ms, 0); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(0, true, ms, 0); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(0, true, ms, 0); CurrentPosition = RobotPostion4LP.Aligner; } private void ToHome() { canvas1.Rotate(90, true, ms); canvas2.Rotate(180, true, ms); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(180, true, ms); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(180, true, ms); CurrentPosition = RobotPostion4LP.Home; } private void ToInvertionEnd() { canvas1.Rotate(30, true, ms); canvas2.Rotate(120, true, ms); if (Blade1Status == BladeStatus4LP.Extend) canvas3.Rotate(300, true, ms); if (Blade2Status == BladeStatus4LP.Extend) canvas23.Rotate(300, true, ms); CurrentPosition = RobotPostion4LP.Invertion; } private void mnuToLP1_Click(object sender, RoutedEventArgs e) { MoveToLP1(); } private void mnuToLP2_Click(object sender, RoutedEventArgs e) { MoveToLP2(); } private void mnuToHome_Click(object sender, RoutedEventArgs e) { MoveToHome(); } private void mnuToAligner_Click(object sender, RoutedEventArgs e) { MoveToAligner(); } private void mnuToInvertion_Click(object sender, RoutedEventArgs e) { MoveToInvertion(); } private void mnuToLP3_Click(object sender, RoutedEventArgs e) { MoveToLP3(); } private void mnuToLP4_Click(object sender, RoutedEventArgs e) { MoveToLP4(); } } public enum RobotPostion4LP { Home, LP1, LP2, LP3, LP4, Aligner, Invertion } public enum BladeStatus4LP { Extend, Retract } }