| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 | using MECF.Framework.Common.CommonData;using VirgoUI.Controls.Common;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 System.Windows.Media.Animation;using OpenSEMI.ClientBase;namespace VirgoUI.Controls.Parts{    /// <summary>    /// AtmRobot.xaml 的交互逻辑    /// </summary>    public partial class AtmRobot : UserControl, INotifyPropertyChanged    {        private int moveTime = 300;        private const int AnimationTimeout = 3000; // ms        private string CurrentPosition        {            get; set;        }        private RobotAction CurrentAction        {            get; set;        }        public int MoveTime        {            get => moveTime;            set            {                moveTime = 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(AtmRobot), new PropertyMetadata(0));        public int TranslateX        {            get { return (int)GetValue(TranslateXProperty); }            set { SetValue(TranslateXProperty, value); }        }        // Using a DependencyProperty as the backing store for TranslateX.  This enables animation, styling, binding, etc...        public static readonly DependencyProperty TranslateXProperty =            DependencyProperty.Register("TranslateX", typeof(int), typeof(AtmRobot), new PropertyMetadata(0));        public WaferInfo Wafer1        {            get { return (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( WaferInfo), typeof(AtmRobot), new PropertyMetadata(null));        public WaferInfo Wafer2        {            get { return (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(WaferInfo), typeof(AtmRobot), new PropertyMetadata(null));        public string Station        {            get { return (string)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(string), typeof(AtmRobot), new PropertyMetadata("Robot"));        public RobotMoveInfo RobotMoveInfo        {            get { return (RobotMoveInfo)GetValue(RobotMoveInfoProperty); }            set { SetValue(RobotMoveInfoProperty, value); }        }        public static readonly DependencyProperty RobotMoveInfoProperty =            DependencyProperty.Register("RobotMoveInfo", typeof(RobotMoveInfo), typeof(AtmRobot), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));        public bool WaferPresentA        {            get { return (bool)GetValue(WaferPresentAProperty); }            set { SetValue(WaferPresentAProperty, value); }        }        // Using a DependencyProperty as the backing store for WaferPresent.  This enables animation, styling, binding, etc...        public static readonly DependencyProperty WaferPresentAProperty =            DependencyProperty.Register("WaferPresentA", typeof(bool), typeof(AtmRobot), new PropertyMetadata(false));        public bool WaferPresentB        {            get { return (bool)GetValue(WaferPresentBProperty); }            set { SetValue(WaferPresentBProperty, value); }        }        // Using a DependencyProperty as the backing store for WaferPresent.  This enables animation, styling, binding, etc...        public static readonly DependencyProperty WaferPresentBProperty =            DependencyProperty.Register("WaferPresentB", typeof(bool), typeof(AtmRobot), new PropertyMetadata(false));        public ICommand CreateDeleteWaferCommand        {            get { return (ICommand)GetValue(CreateDeleteWaferCommandProperty); }            set { SetValue(CreateDeleteWaferCommandProperty, value); }        }        // Using a DependencyProperty as the backing store for CreateDeleteWaferCommand.  This enables animation, styling, binding, etc...        public static readonly DependencyProperty CreateDeleteWaferCommandProperty =            DependencyProperty.Register("CreateDeleteWaferCommand", typeof(ICommand), typeof(AtmRobot), new PropertyMetadata(null));        public ICommand MoveWaferCommand        {            get { return (ICommand)GetValue(MoveWaferCommandProperty); }            set { SetValue(MoveWaferCommandProperty, value); }        }        // Using a DependencyProperty as the backing store for MoveWaferCommand.  This enables animation, styling, binding, etc...        public static readonly DependencyProperty MoveWaferCommandProperty =            DependencyProperty.Register("MoveWaferCommand", typeof(ICommand), typeof(AtmRobot), new PropertyMetadata(null));        //public Dictionary<string, StationPosition> StationPosition        //{        //    get { return (Dictionary<string, StationPosition>)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<string, StationPosition>), typeof(AtmRobot), new PropertyMetadata(null, StationPositionChangedCallback));        public Dictionary<string, StationPosition> StationPosition        {            get            {                return new Dictionary<string, StationPosition>                {                    { "ArmA.System",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=0,                                Root=90,                                Arm=180,                                Hand=180                             },                             EndPosition= new RobotPosition()                             {                                Root=90,                                Arm=180,                                Hand=180                             }                        }                    },                    { "ArmB.System",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=0,                                Root=90,                                Arm=180,                                Hand=180                             },                             EndPosition= new RobotPosition()                             {                                Root=90,                                Arm=180,                                Hand=180                             }                        }                    },                    { "ArmA.LP1",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=-186,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmB.LP1",new StationPosition()                        {                            StartPosition= new RobotPosition()                             {                                Z=-186,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmA.LP2",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=-93,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmB.LP2",new StationPosition()                        {                            StartPosition= new RobotPosition()                             {                                Z=-93,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmA.LP3",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=-1,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmB.LP3",new StationPosition()                        {                            StartPosition= new RobotPosition()                             {                                Z=-1,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmA.LP4",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=91,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmB.LP4",new StationPosition()                        {                            StartPosition= new RobotPosition()                             {                                Z=91,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=120,                                Hand=304                             }                        }                    },                    { "ArmA.Aligner",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=181,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=107,                                Hand=317                             }                        }                    },                    { "ArmB.Aligner",new StationPosition()                        {                              StartPosition= new RobotPosition()                             {                                Z=181,                                Root=8,                                Arm=166,                                Hand=276                             },                             EndPosition= new RobotPosition()                             {                                Root=25,                                Arm=107,                                Hand=317                             }                        }                    },                    { "ArmA.Buffer",new StationPosition()                        {                            StartPosition= new RobotPosition()                            {                                Z=181,                                Root=8,                                Arm=166,                                Hand=276                            },                            EndPosition= new RobotPosition()                            {                                Root=25,                                Arm=107,                                Hand=317                            }                        }                    },                    { "ArmB.Buffer",new StationPosition()                        {                            StartPosition= new RobotPosition()                            {                                Z=181,                                Root=8,                                Arm=166,                                Hand=276                            },                            EndPosition= new RobotPosition()                            {                                Root=25,                                Arm=107,                                Hand=317                            }                        }                    },                    { "ArmA.PM1",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=-90,                                Root=178,                                Arm=155,                                Hand=298                             },                             EndPosition= new RobotPosition()                             {                                Root=235,                                Arm=66,                                Hand=330                             }                        }                    },                    { "ArmB.PM1",new StationPosition()                        {                              StartPosition= new RobotPosition()                             {                                Z=-90,                                Root=178,                                Arm=155,                                Hand=298                             },                             EndPosition= new RobotPosition()                             {                                Root=235,                                Arm=66,                                Hand=330                             }                        }                    },                    { "ArmA.PM2",new StationPosition()                        {                             StartPosition= new RobotPosition()                             {                                Z=76,                                Root=178,                                Arm=155,                                Hand=298                             },                             EndPosition= new RobotPosition()                             {                                Root=235,                                Arm=66,                                Hand=330                             }                        }                    },                    { "ArmB.PM2",new StationPosition()                        {                            StartPosition= new RobotPosition()                             {                                Z=76,                                Root=178,                                Arm=155,                                Hand=298                             },                             EndPosition= new RobotPosition()                             {                                Root=235,                                Arm=66,                                Hand=330                             }                        }                    }                };            }        }        private List<MenuItem> menu;        public event PropertyChangedEventHandler PropertyChanged;        public List<MenuItem> Menu        {            get            {                return menu;            }            set            {                menu = value;                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Menu"));            }        }        private ICommand MoveCommand        {            get; set;        }        private void MoveTo(object target)        {            MoveRobot((RobotMoveInfo)target);        }        public AtmRobot()        {            InitializeComponent();            root.DataContext = this;            MoveCommand = new RelayCommand(MoveTo);            CurrentPosition = "ArmA.System";            canvas1.Rotate(90);            canvas2.Rotate(180);            canvas3.Rotate(180);            canvas21.Rotate(90);            canvas22.Rotate(180);            canvas23.Rotate(180);        }        static void StationPositionChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)        {            var self = (AtmRobot)d;            var positions = (Dictionary<string, StationPosition>)e.NewValue;            var menus = new List<MenuItem>();            foreach (var position in positions)            {                var m = new MenuItem() { Header = position.Key };                Enum.TryParse<RobotArm>(position.Key.Split('.')[0], out RobotArm arm);                m.Items.Add(new MenuItem() { Header = "Pick", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Picking, ArmTarget = arm } });                m.Items.Add(new MenuItem() { Header = "Place", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Placing, ArmTarget = arm } });                m.Items.Add(new MenuItem() { Header = "Move", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Moving, ArmTarget = arm } });                menus.Add(m);            }            self.Menu = menus;            self.MoveTo(new RobotMoveInfo() { BladeTarget = positions.First().Key, Action = RobotAction.None });        }        protected override void OnRender(DrawingContext drawingContext)        {            base.OnRender(drawingContext);            if (DesignerProperties.GetIsInDesignMode(this))            {                return;            }            if (RobotMoveInfo != null)            {                var needMove = CurrentPosition != RobotMoveInfo.BladeTarget || CurrentAction != RobotMoveInfo.Action;                if (needMove)                {                    LogMsg($" RobotMoveInfo, action:{RobotMoveInfo.Action}  armTarget:{RobotMoveInfo.ArmTarget} bladeTarget:{RobotMoveInfo.BladeTarget}");                    Invoke(() => MoveRobot(RobotMoveInfo));                    CurrentAction = RobotMoveInfo.Action;                    CurrentPosition = RobotMoveInfo.BladeTarget;                }            }        }        private void Invoke(Action action)        {            Dispatcher.Invoke(action);        }        private void LogMsg(string msg)        {            var source = "ATM Robot";            Console.WriteLine("{0} {1}", source, msg);        }        private void MoveRobot(RobotMoveInfo moveInfo)        {            canvas1.Stop();            canvas2.Stop();            canvas3.Stop();            canvas21.Stop();            canvas22.Stop();            canvas23.Stop();            var target = moveInfo.BladeTarget;            var arm = moveInfo.ArmTarget;            MoveToStart(arm, CurrentPosition            ,            () => TranslateTo(target, () => MoveToStart(arm, target, () =>            {                if (moveInfo.Action != RobotAction.Moving)                {                    MoveToEnd(arm, target, () => UpdateWafer(moveInfo));                }            })));        }        private void RotateTo(string station, Action onComplete = null)        {            var position = StationPosition[station];            LogMsg($"Rotate to {position.StartPosition.X}");            container.Rotate(position.StartPosition.X, true, MoveTime, 0, 0, onComplete);        }        private void TranslateTo(string station, Action onComplete = null)        {            var position = StationPosition[station];            LogMsg($"Translate to {position.StartPosition.Z}");            Translate(StationPosition[CurrentPosition].StartPosition.Z, position.StartPosition.Z, onComplete);        }        private void MoveToStart(RobotArm arm, string station, Action onComplete = null)        {            LogMsg($"{arm} Move to start {station}");            var position = StationPosition[station];            var storyboard = new Storyboard();            storyboard.Completed += (s, e) => onComplete?.Invoke();            var needRotate = new List<bool>();            //if (arm == RobotArm.ArmA)            {                needRotate.Add(canvas1.Rotate(storyboard, position.StartPosition.Root, true, MoveTime));                needRotate.Add(canvas2.Rotate(storyboard, position.StartPosition.Arm, true, MoveTime));                needRotate.Add(canvas3.Rotate(storyboard, position.StartPosition.Hand, true, MoveTime));            }            //else if (arm == RobotArm.ArmB)            {                needRotate.Add(canvas21.Rotate(storyboard, position.StartPosition.Root, true, MoveTime));                needRotate.Add(canvas22.Rotate(storyboard, position.StartPosition.Arm, true, MoveTime));                needRotate.Add(canvas23.Rotate(storyboard, position.StartPosition.Hand, true, MoveTime));            }            if (needRotate.Any(x => x))            {                storyboard.Begin();            }            else            {                onComplete?.Invoke();            }            CurrentPosition = station;        }        private void MoveToEnd(RobotArm arm, string station, Action onComplete = null)        {            LogMsg($"{arm} move to end {station}");            var position = StationPosition[station];            var storyboard = new Storyboard();            storyboard.Completed += (s, e) => onComplete?.Invoke();            var needRotate = new List<bool>();            if (arm == RobotArm.ArmA || arm == RobotArm.Both)            {                needRotate.Add(canvas1.Rotate(storyboard, position.EndPosition.Root, true, MoveTime));                needRotate.Add(canvas2.Rotate(storyboard, position.EndPosition.Arm, true, MoveTime));                needRotate.Add(canvas3.Rotate(storyboard, position.EndPosition.Hand, true, MoveTime));            }            if (arm == RobotArm.ArmB || arm == RobotArm.Both)            {                needRotate.Add(canvas21.Rotate(storyboard, position.EndPosition.Root, true, MoveTime));                needRotate.Add(canvas22.Rotate(storyboard, position.EndPosition.Arm, true, MoveTime));                needRotate.Add(canvas23.Rotate(storyboard, position.EndPosition.Hand, true, MoveTime));            }            if (needRotate.Any(x => x))            {                storyboard.Begin();            }            else            {                onComplete?.Invoke();            }            CurrentPosition = station;        }        private void UpdateWafer(RobotMoveInfo moveInfo)        {            var waferPresent = false;            switch (moveInfo.Action)            {                case RobotAction.None:                case RobotAction.Moving:                    return;                case RobotAction.Picking:                    waferPresent = true;                    break;                case RobotAction.Placing:                    waferPresent = false;                    break;                default:                    break;            }            switch (moveInfo.ArmTarget)            {                case RobotArm.ArmA:                    WaferPresentA = waferPresent;                    break;                case RobotArm.ArmB:                    WaferPresentB = waferPresent;                    break;                case RobotArm.Both:                    WaferPresentA = waferPresent;                    WaferPresentB = waferPresent;                    break;                default:                    break;            }        }        private void Translate(int start, int target, Action onComplete = null)        {            AnimationHelper.TranslateX(root, start, target, MoveTime, onComplete);        }    }}
 |