123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502 |
- using Aitex.Core.Common;
- using Aitex.Core.UI.MVVM;
- using FurnaceUI.Controls.Common;
- using MECF.Framework.Common.Equipment;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using CB = MECF.Framework.UI.Client.ClientBase;
- namespace FurnaceUI.Controls.Parts
- {
- /// <summary>
- /// ATMDualArmRobot.xaml 的交互逻辑
- /// </summary>
- public partial class BoatElevatorRobot : UserControl, INotifyPropertyChanged
- {
- protected readonly int MoveTime = 300;
- private const int AnimationTimeout = 3000; // seconds
- public int MinValue
- {
- get { return (int)GetValue(MinValueProperty); }
- set { SetValue(MinValueProperty, value); }
- }
- // Using a DependencyProperty as the backing store for MinValue. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty MinValueProperty =
- DependencyProperty.Register("MinValue", typeof(int), typeof(BoatElevatorRobot), new PropertyMetadata(0));
- public int MaxValue
- {
- get { return (int)GetValue(MaxValueProperty); }
- set { SetValue(MaxValueProperty, value); }
- }
- // Using a DependencyProperty as the backing store for MaxValue. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty MaxValueProperty =
- DependencyProperty.Register("MaxValue", typeof(int), typeof(BoatElevatorRobot), new PropertyMetadata(1000));
- public int CurrentValue
- {
- get { return (int)GetValue(CurrentValueProperty); }
- set { SetValue(CurrentValueProperty, value); }
- }
- // Using a DependencyProperty as the backing store for CurrentValue. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty CurrentValueProperty =
- DependencyProperty.Register("CurrentValue", typeof(int), typeof(BoatElevatorRobot), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.AffectsRender));
- 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(BoatElevatorRobot), 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(BoatElevatorRobot), 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(BoatElevatorRobot), 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(BoatElevatorRobot), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
- 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(BoatElevatorRobot), 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(BoatElevatorRobot), 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(BoatElevatorRobot), 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(BoatElevatorRobot), 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(BoatElevatorRobot), 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(BoatElevatorRobot), new PropertyMetadata(null));
- private string CurrentPosition;
- private string CurrentArmA;
- private string CurrentArmB;
- public string BoatStatus
- {
- get
- {
- return (string)GetValue(BoatStatusProperty);
- }
- set
- {
- SetValue(BoatStatusProperty, value);
- }
- }
- // Using a DependencyProperty as the backing store for armBExtended. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty BoatStatusProperty =
- DependencyProperty.Register("BoatStatus", typeof(string), typeof(BoatElevatorRobot), new FrameworkPropertyMetadata("Init", RobotStatusChangedCallback));
- 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(BoatElevatorRobot), new FrameworkPropertyMetadata("/FurnaceUI;component/Resources/Images/Controls3/02.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(BoatElevatorRobot), new FrameworkPropertyMetadata("/FurnaceUI;component/Resources/Images/Controls3/lghg.png", FrameworkPropertyMetadataOptions.AffectsRender));
- static void RobotStatusChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var self = (BoatElevatorRobot)d;
- var test = d;
- switch ((string)e.NewValue)
- {
- case "Homing":
- self.Canvas1ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/lghg.png";
- break;
- case "Error":
- self.Canvas1ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/lghg.png";
- break;
- default:
- self.Canvas1ImagePath = "/FurnaceUI;component/Resources/Images/Controls3/lghg.png";
- break;
- }
- }
- private List<MenuItem> menu;
- public List<MenuItem> Menu
- {
- get
- {
- return menu;
- }
- set
- {
- menu = value;
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Menu"));
- }
- }
- public ICommand MoveCommand
- {
- get
- {
- return new DelegateCommand<object>(MoveTo);
- }
- }
- private AnimationQueue queue;
- protected int homePositionX = 0;
- protected int processPositionX = 0;
- public event PropertyChangedEventHandler PropertyChanged;
- static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- //var self = (BoatElevatorRobot)d;
- //switch (e.Property.Name)
- //{
- // case "StationPosition":
- // var positions = (Dictionary<string, StationPosition>)e.NewValue;
- // //var menu1 = new MenuItem() { Header = "Arm" };
- // //var subMenu1 = positions.Select(x => new MenuItem() { Header = x.Key, Command = self.MoveCommand, CommandParameter = new Tuple<string, string, string>(x.Key, RobotConstant.RobotExtend, RobotConstant.RobotRetract) }).ToList();
- // //foreach (var menu in subMenu1)
- // //{
- // // menu1.Items.Add(menu);
- // //}
- // //self.menu = subMenu1;// new List<MenuItem>().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;
- //}
- var self = (BoatElevatorRobot)d;
- switch (e.Property.Name)
- {
- case "StationPosition":
- var positions = (Dictionary<string, StationPosition>)e.NewValue;
- //var param = new AnimationParameter() { Target = positions.Keys.ToList()[0], ArmA = RobotConstant.RobotExtend, ArmB = RobotConstant.RobotRetract };
- ////if (self.CurrentPosition != param.Target || self.CurrentArmA != param.ArmA || self.CurrentArmB != param.ArmB)
- ////{
- //// self.MoveRobot((AnimationParameter)param);
- ////}
- //self.CurrentPosition = param.Target;
- //self.CurrentArmA = param.ArmA;
- //self.CurrentArmB = param.ArmB;
- //var menu1 = new MenuItem() { Header = "Arm" };
- //var subMenu1 = positions.Select(x => new MenuItem() { Header = x.Key, Command = self.MoveCommand, CommandParameter = new Tuple<string, string, string>(x.Key, RobotConstant.RobotExtend, RobotConstant.RobotRetract) }).ToList();
- //foreach (var menu in subMenu1)
- //{
- // menu1.Items.Add(menu);
- //}
- //self.menu = subMenu1;// new List<MenuItem>().Add(subMenu1);
- self.homePositionX = (int)positions["HomePosition"]?.StartPosition.X;
- self.processPositionX = (int)positions["ProcessPosition"]?.StartPosition.X;
- break;
- }
- }
- public BoatElevatorRobot()
- {
- #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(200);
- //canvas2.Rotate(260);
- //canvasRoot.Rotate(90);
- CurrentPosition = ModuleName.System.ToString();
- CurrentArmA = CurrentArmB = RobotConstant.RobotRetract;
- }
- protected override void OnRender(DrawingContext drawingContext)
- {
- base.OnRender(drawingContext);
- if (DesignerProperties.GetIsInDesignMode(this))
- {
- return;
- }
- //if (RobotTarget != null || ArmAExtended != null || ArmBExtended != null)
- //{
- // LogMsg(string.Format("Received ------ Target: {0} ArmA: {1} ArmB: {2} ", RobotTarget, ArmAExtended, ArmBExtended));
- Invoke(() => MoveRobot(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, Action onComplete = null)
- {
- MoveToStart(parameter.Target, () => TranslateTo(parameter.Target, () => MoveToEnd(parameter, onComplete)));
- }
- private void MoveToStart(string station, Action onComplete = null)
- {
- //if (StationPosition == null || station == "Unknown" || station == null)
- // return;
- //var position = StationPosition[station];
- //canvas1.Rotate(position.StartPosition.Root, true, MoveTime);
- //CurrentPosition = station;
- onComplete?.Invoke();
- }
- private void MoveToEnd(AnimationParameter parameter, 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);
- //}
- //CurrentPosition = parameter.Target;
- //if (!extended)
- //{
- onComplete?.Invoke();
- //}
- }
- private void TranslateTo(string station, Action onComplete = null)
- {
- //var position = StationPosition[station];
- //if (position.StartPosition.X.HasValue)
- //{
- // Translate(position.StartPosition.X.Value, onComplete);
- //}
- //else
- //{
- Translate(CurrentValue, onComplete);
- onComplete?.Invoke();
- //}
- }
- private int oldCurrentValue = 0;
- int oldX = 0;
- private void Translate(int x, Action onComplete = null)
- {
- //var storyBoard = new Storyboard();
- //var oldX = translate.X;
- //AnimationHelper.TranslateY(canvasRoot, (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();
- if (oldCurrentValue != x)
- {
- var xValue = (int)((((float)x) / (MinValue - MaxValue)) * (homePositionX - processPositionX));
- AnimationHelper.TranslateY(canvasRoot, oldX, xValue, MoveTime, onComplete);
- oldX = xValue;
- oldCurrentValue = x;
- }
- }
- private void MoveTo(object obj)
- {
- var para = (Tuple<string, string, string>)obj;
- MoveRobot(new AnimationParameter() { Target = para.Item1, ArmA = para.Item2, ArmB = para.Item3 });
- }
- private void Invoke(Action action)
- {
- Dispatcher.Invoke(action);
- }
- private void LogMsg(string msg)
- {
- var source = "ATMRobot";
- Console.WriteLine("{0} {1}", source, msg);
- }
- }
- }
|