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
{
    /// 
    /// AtmRobot.xaml 的交互逻辑
    /// 
    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 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(AtmRobot), new PropertyMetadata(null, StationPositionChangedCallback));
        public Dictionary StationPosition
        {
            get
            {
                return new Dictionary
                {
                    { "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