using Aitex.Core.Common; using Aitex.Core.UI.MVVM; using FurnaceUI.Controls.Common; //using FurnaceUI.Views.Maintenances; using MECF.Framework.Common.Equipment; using Caliburn.Micro; using Caliburn.Micro.Core; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using CB = MECF.Framework.UI.Client.ClientBase; using MECF.Framework.Common.CommonData; using MECF.Framework.Common.SubstrateTrackings; using FurnaceUI.Views.Maintenances; using System.Windows.Media.Animation; using System.Windows.Media.Media3D; namespace FurnaceUI.Controls.Parts { /// /// ATMDualArmRobot.xaml 的交互逻辑 /// public partial class ATMArmRobot : UserControl, INotifyPropertyChanged { protected readonly int MoveTime = 300; private const int AnimationTimeout = 3000; // seconds public int RotateAngle { get { return (int)GetValue(RotateAngleProperty); } set { SetValue(RotateAngleProperty, value); } } private RobotAction CurrentAction { get; set; } // 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(ATMArmRobot), new PropertyMetadata(0)); 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(ATMArmRobot), 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(ATMArmRobot), new PropertyMetadata(null)); public string RobotTarget { get { return (string)GetValue(RobotTargetProperty); } set { SetValue(RobotTargetProperty, value); } } public static readonly DependencyProperty RobotTargetProperty = DependencyProperty.Register("RobotTarget", typeof(string), typeof(ATMArmRobot), new FrameworkPropertyMetadata(ModuleName.Robot.ToString(), FrameworkPropertyMetadataOptions.AffectsRender)); public Dictionary StationPosition { get { return (Dictionary)GetValue(StationPositionProperty); } set { SetValue(StationPositionProperty, value); } } // Using a DependencyProperty as the backing store for StationPosition. This enables animation, styling, binding, etc... public static readonly DependencyProperty StationPositionProperty = DependencyProperty.Register("StationPosition", typeof(Dictionary), typeof(ATMArmRobot), new PropertyMetadata(null, PropertyChangedCallback)); public string ArmAExtended { get { return (string)GetValue(ArmAExtendedProperty); } set { SetValue(ArmAExtendedProperty, value); } } // Using a DependencyProperty as the backing store for ArmAExtended. This enables animation, styling, binding, etc... public static readonly DependencyProperty ArmAExtendedProperty = DependencyProperty.Register("ArmAExtended", typeof(string), typeof(ATMArmRobot), new FrameworkPropertyMetadata(RobotConstant.RobotRetract, FrameworkPropertyMetadataOptions.AffectsRender)); public string ArmBExtended { get { return (string)GetValue(ArmBExtendedProperty); } set { SetValue(ArmBExtendedProperty, value); } } // Using a DependencyProperty as the backing store for armBExtended. This enables animation, styling, binding, etc... public static readonly DependencyProperty ArmBExtendedProperty = DependencyProperty.Register("ArmBExtended", typeof(string), typeof(ATMArmRobot), new FrameworkPropertyMetadata(RobotConstant.RobotRetract, FrameworkPropertyMetadataOptions.AffectsRender)); public WaferInfo[] RobotWafers { get { return (WaferInfo[])GetValue(RobotWafersProperty); } set { SetValue(RobotWafersProperty, value); } } // Using a DependencyProperty as the backing store for RobotWafers. This enables animation, styling, binding, etc... public static readonly DependencyProperty RobotWafersProperty = DependencyProperty.Register("RobotWafers", typeof(WaferInfo[]), typeof(ATMArmRobot), new PropertyMetadata(null, PropertyChangedCallback)); public CB.WaferInfo Wafer1 { get { return (CB.WaferInfo)GetValue(Wafer1Property); } set { SetValue(Wafer1Property, value); } } // Using a DependencyProperty as the backing store for Wafer1. This enables animation, styling, binding, etc... public static readonly DependencyProperty Wafer1Property = DependencyProperty.Register("Wafer1", typeof(CB.WaferInfo), typeof(ATMArmRobot), new PropertyMetadata(null)); public CB.WaferInfo Wafer2 { get { return (CB.WaferInfo)GetValue(Wafer2Property); } set { SetValue(Wafer2Property, value); } } // Using a DependencyProperty as the backing store for Wafer2. This enables animation, styling, binding, etc... public static readonly DependencyProperty Wafer2Property = DependencyProperty.Register("Wafer2", typeof(CB.WaferInfo), typeof(ATMArmRobot), new PropertyMetadata(null)); public CarrierInfo CarrierData { get { return (CarrierInfo)GetValue(CarrierDataProperty); } set { SetValue(CarrierDataProperty, value); } } // Using a DependencyProperty as the backing store for Wafer2. This enables animation, styling, binding, etc... public static readonly DependencyProperty CarrierDataProperty = DependencyProperty.Register("CarrierData", typeof(CarrierInfo), typeof(ATMArmRobot), new PropertyMetadata(null)); public RobotMoveInfo RobotMoveInfo { get { return (RobotMoveInfo)GetValue(RobotMoveInfoProperty); } set { SetValue(RobotMoveInfoProperty, value); } } public static readonly DependencyProperty RobotMoveInfoProperty = DependencyProperty.Register("RobotMoveInfo", typeof(RobotMoveInfo), typeof(ATMArmRobot), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender)); public string CassetteType { get { return (string)GetValue(CassetteTypeProperty); } set { SetValue(CassetteTypeProperty, value); } } // Using a DependencyProperty as the backing store for CassetteType. This enables animation, styling, binding, etc... public static readonly DependencyProperty CassetteTypeProperty = DependencyProperty.Register("CassetteType", typeof(string), typeof(ATMArmRobot), new PropertyMetadata(null)); public int WaferCount { get { return (int)GetValue(WaferCountProperty); } set { SetValue(WaferCountProperty, value); } } // Using a DependencyProperty as the backing store for WaferCount. This enables animation, styling, binding, etc... public static readonly DependencyProperty WaferCountProperty = DependencyProperty.Register("WaferCount", typeof(int), typeof(ATMArmRobot), new PropertyMetadata(0)); public string CassetteRobotStatus { get { return (string )GetValue(CassetteRobotStatusProperty); } set { SetValue(CassetteRobotStatusProperty, value); } } // Using a DependencyProperty as the backing store for WaferRobotStatus. This enables animation, styling, binding, etc... public static readonly DependencyProperty CassetteRobotStatusProperty = DependencyProperty.Register("CassetteRobotStatus", typeof(string ), typeof(ATMArmRobot), new PropertyMetadata(null, CassetteRobotStatusChangedCallback)); static void CassetteRobotStatusChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { var self = (ATMArmRobot)d; var test = d; switch ((string)e.NewValue) { case "Homing": self.RootImagePath = "/FurnaceUI;component/Resources/Images/Controls3/hgz1y.png"; self.Canvas1ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb1y.png"; self.Canvas2ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb1y.png"; self.Canvas3ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb2y.png"; break; case "Idle": case "InTransfer": case "Picking": case "Placing": self.RootImagePath = "/FurnaceUI;component/Resources/Images/Controls3/hgz1g.png"; self.Canvas1ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb1g.png"; self.Canvas2ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb1g.png"; self.Canvas3ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb2g.png"; break; case "Error": self.RootImagePath = "/FurnaceUI;component/Resources/Images/Controls3/hgz1r.png"; self.Canvas1ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb1r.png"; self.Canvas2ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb1r.png"; self.Canvas3ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/rb2r.png"; break; default: break; } } public string RootImagePath { get { return (string)GetValue(RootImagePathProperty); } set { SetValue(RootImagePathProperty, value); } } // Using a DependencyProperty as the backing store for RootImagePath. This enables animation, styling, binding, etc... public static readonly DependencyProperty RootImagePathProperty = DependencyProperty.Register("RootImagePath", typeof(string), typeof(ATMArmRobot), new FrameworkPropertyMetadata("/FurnaceUI;component/Resources/Images/Controls3/hgz1y.png", FrameworkPropertyMetadataOptions.AffectsRender)); public string Canvas1ImagePath { get { return (string)GetValue(Canvas1ImagePathProperty); } set { SetValue(Canvas1ImagePathProperty, value); } } // Using a DependencyProperty as the backing store for RootImagePath. This enables animation, styling, binding, etc... public static readonly DependencyProperty Canvas1ImagePathProperty = DependencyProperty.Register("Canvas1ImagePath", typeof(string), typeof(ATMArmRobot), new FrameworkPropertyMetadata("/FurnaceUI;component/Resources/Images/Controls3/rb1y.png", FrameworkPropertyMetadataOptions.AffectsRender)); public string Canvas2ImagePath { get { return (string)GetValue(Canvas2ImagePathProperty); } set { SetValue(Canvas2ImagePathProperty, value); } } // Using a DependencyProperty as the backing store for RootImagePath. This enables animation, styling, binding, etc... public static readonly DependencyProperty Canvas2ImagePathProperty = DependencyProperty.Register("Canvas2ImagePath", typeof(string), typeof(ATMArmRobot), new FrameworkPropertyMetadata("/FurnaceUI;component/Resources/Images/Controls3/rb1y.png", FrameworkPropertyMetadataOptions.AffectsRender)); public string Canvas3ImagePath { get { return (string)GetValue(Canvas3ImagePathProperty); } set { SetValue(Canvas3ImagePathProperty, value); } } // Using a DependencyProperty as the backing store for RootImagePath. This enables animation, styling, binding, etc... public static readonly DependencyProperty Canvas3ImagePathProperty = DependencyProperty.Register("Canvas3ImagePath", typeof(string), typeof(ATMArmRobot), new FrameworkPropertyMetadata("/FurnaceUI;component/Resources/Images/Controls3/rb2y.png", FrameworkPropertyMetadataOptions.AffectsRender)); private string CurrentPosition; //private string CurrentArmA; private List menu; public List Menu { get { return menu; } set { menu = value; PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Menu")); } } public ICommand MoveCommand { get { return new DelegateCommand(MoveTo); } } private AnimationQueue queue; public event PropertyChangedEventHandler PropertyChanged; static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { var self = (ATMArmRobot)d; switch (e.Property.Name) { case "StationPosition": var positions = (Dictionary)e.NewValue; //var menu1 = new MenuItem() { Header = "Arm" }; var subMenu1 = positions.Select(x => new MenuItem() { Header = x.Key, Command = self.MoveCommand, CommandParameter = new Tuple(x.Key, RobotConstant.RobotExtend, RobotConstant.RobotRetract) }).ToList(); //foreach (var menu in subMenu1) //{ // menu1.Items.Add(menu); //} self.menu = subMenu1;// new List().Add(subMenu1); break; case "RobotWafers": //if (e.NewValue == null) //{ // self.Wafer1 = null; // self.Wafer2 = null; //} //else //{ // if (self.RobotWafers.Length > 1) // { // self.Wafer1 = self.RobotWafers[0]; // self.Wafer2 = self.RobotWafers[1]; // } //} break; default: break; } } public ATMArmRobot() { #if DEBUG System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level = System.Diagnostics.SourceLevels.Critical; #endif InitializeComponent(); root.DataContext = this; queue = new AnimationQueue("Robot Animation"); // queue.StatusUpdated += Queue_StatusUpdated; canvas1.Rotate(0); canvas2.Rotate(180); canvas3.Rotate(180); CurrentPosition = ModuleName.System.ToString(); //CurrentArmA = RobotConstant.RobotRetract; } protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); if (DesignerProperties.GetIsInDesignMode(this)) { return; } if (RobotMoveInfo != null && RobotMoveInfo.BladeTarget != "Robot") { var needMove = CurrentPosition != RobotMoveInfo.BladeTarget && RobotMoveInfo.BladeTarget!= "HomePosition"; if (needMove) { CurrentAction = RobotMoveInfo.Action; CurrentPosition = RobotMoveInfo.BladeTarget; LogMsg($" RobotMoveInfo, action:{RobotMoveInfo.Action} armTarget:{RobotMoveInfo.ArmTarget} bladeTarget:{RobotMoveInfo.BladeTarget}"); Invoke(() => MoveRobot(RobotMoveInfo)); } } //if (RobotTarget != null || ArmAExtended != null || ArmBExtended != null) //{ // LogMsg(string.Format("Received ------ Target: {0} ArmA: {1} ArmB: {2} ", RobotTarget, ArmAExtended, ArmBExtended)); // queue.EnqueueStatus(new AnimationParameter() { Target = RobotTarget, ArmA = ArmAExtended, ArmB = ArmBExtended }); //} } //private void Queue_StatusUpdated(object sender, StatusUpdateArgs e) //{ // LogMsg(string.Format("Target: {0} - {1}", CurrentPosition, e.Parameter.Target)); // var nextEvent = new AutoResetEvent(false); // var next = new Action(() => // { // nextEvent.Set(); // }); // var wait = new Action(() => // { // if (!nextEvent.WaitOne(AnimationTimeout)) // { // LogMsg("Aniamtion time out!"); // } // }); // var done = new Action(() => // { // CurrentPosition = e.Parameter.Target; // CurrentArmA = e.Parameter.ArmA; // CurrentArmB = e.Parameter.ArmB; // e.Event.Set(); // }); // var needMove = CurrentPosition != e.Parameter.Target || CurrentArmA != e.Parameter.ArmA || CurrentArmB != e.Parameter.ArmB; // if (needMove) // { // Invoke(() => MoveRobot(e.Parameter, next)); // wait(); // } // done(); //} private void MoveRobot(AnimationParameter parameter, System.Action onComplete = null) { MoveToStart(parameter.Target, () => TranslateTo(parameter.Target, () => MoveToEnd(parameter, onComplete))); } private void MoveRobot(RobotMoveInfo moveInfo) { canvas1.Stop(); canvas2.Stop(); canvas3.Stop(); var target = moveInfo.BladeTarget; var arm = moveInfo.ArmTarget; AnimationParameter animationParameter = new AnimationParameter() { ArmA= moveInfo.ArmTarget.ToString(), Target= moveInfo.BladeTarget }; MoveToStart(target, () => TranslateTo(target, () => MoveToEnd(animationParameter, null))); } private void MoveToStart(string station, System.Action onComplete = null) { if (StationPosition == null) return; var position = StationPosition[station]; canvas1.Rotate(position.StartPosition.Root, true, MoveTime); canvas2.Rotate(position.StartPosition.Arm, true, MoveTime); canvas3.Rotate(position.StartPosition.Hand, true, MoveTime); cassette.Filp(position.StartPosition.Root, 0, true, MoveTime); CurrentPosition = station; onComplete?.Invoke(); } private void MoveToEnd(AnimationParameter parameter, System.Action onComplete = null) { //var position = StationPosition[parameter.Target]; //var extended = false; //if (parameter.ArmA == RobotConstant.RobotExtend) //{ // extended = true; // canvas1.Rotate(position.EndPosition.Root, true, MoveTime, 0, 0, onComplete); // canvas2.Rotate(position.EndPosition.Arm, true, MoveTime); //} if (StationPosition == null) return; var position = StationPosition[parameter.Target]; canvas1.Rotate(position.EndPosition.Root, true, MoveTime); canvas2.Rotate(position.EndPosition.Arm, true, MoveTime); canvas3.Rotate(position.EndPosition.Hand, true, MoveTime); CassetteCanvas.Rotate(-(position.EndPosition.Arm % 90), true, MoveTime); cassette.Filp(position.EndPosition.Root, 0, true, MoveTime); //if (!extended) //{ onComplete?.Invoke(); //} // CurrentPosition = parameter.Target; } private void TranslateTo(string station, System.Action onComplete = null) { var position = StationPosition[station]; if (position.StartPosition.X.HasValue) { Translate(position.StartPosition.X.Value, onComplete); } //else //{ onComplete?.Invoke(); //} } static double oldX = 0; private void Translate(int x, System.Action onComplete = null) { //var storyBoard = new Storyboard(); //var oldX = translate.X; AnimationHelper.TranslateY(root, (int)oldX, x, MoveTime, onComplete); oldX = x; //var animation = new DoubleAnimation(oldX, x, TimeSpan.FromMilliseconds(MoveTime)); //storyBoard.Children.Add(animation); //Storyboard.SetTarget(animation, root); //var propertyChain = new DependencyProperty[] // { // Canvas.RenderTransformProperty, // TransformGroup.ChildrenProperty, // TranslateTransform.XProperty // }; //string thePath = "(0).(1)[1].(2)"; //PropertyPath myPropertyPath = new PropertyPath(thePath, propertyChain); //Storyboard.SetTargetProperty(animation, myPropertyPath); //storyBoard.Completed += (s, e) => //{ // //InvalidateVisual(); // if (onComplete != null) // { // onComplete(); // } //}; //storyBoard.Begin(); } private void MoveTo(object obj) { var para = (Tuple)obj; MoveRobot(new AnimationParameter() { Target = para.Item1, ArmA = para.Item2, ArmB = para.Item3 }); } private void Invoke(System.Action action) { Dispatcher.Invoke(action); } private void LogMsg(string msg) { var source = "ATMRobot"; Console.WriteLine("{0} {1}", source, msg); } private void Viewbox_MouseDown(object sender, MouseButtonEventArgs e) { var windowManager = IoC.Get(); CassetteRobotViewModel cassetteRobotViewModel = new CassetteRobotViewModel(); cassetteRobotViewModel.SystemName = "SMIFA"; (windowManager as WindowManager)?.ShowDialogWithTitle(cassetteRobotViewModel, null, "CarrierRobot Status"); } } }