123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553 |
- 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.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;
- using MECF.Framework.Common.CommonData;
- using FurnaceUI.Views.Maintenances;
- namespace FurnaceUI.Controls.Parts
- {
- /// <summary>
- /// ATMDualArmRobot.xaml 的交互逻辑
- /// </summary>
- public partial class ATMArmRobotTwo : 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); }
- }
- // 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), new PropertyMetadata(null));
- public string RobotTarget
- {
- get { return (string)GetValue(RobotTargetProperty); }
- set { SetValue(RobotTargetProperty, value); }
- }
- private RobotAction CurrentAction
- {
- get; set;
- }
- public string WaferRobotStatus
- {
- get { return (string)GetValue(WaferRobotStatusProperty); }
- set { SetValue(WaferRobotStatusProperty, value); }
- }
- // Using a DependencyProperty as the backing store for WaferRobotStatus. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty WaferRobotStatusProperty =
- DependencyProperty.Register("WaferRobotStatus", typeof(string), typeof(ATMArmRobotTwo), new PropertyMetadata(null, WaferRobotStatusChangedCallback));
- static void WaferRobotStatusChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var self = (ATMArmRobotTwo)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/rb3y.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/rb3g.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/rb3r.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(ATMArmRobotTwo), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), new FrameworkPropertyMetadata("/FurnaceUI;component/Resources/Images/Controls3/rb3y.png", FrameworkPropertyMetadataOptions.AffectsRender));
- public static readonly DependencyProperty RobotTargetProperty =
- DependencyProperty.Register("RobotTarget", typeof(string), typeof(ATMArmRobotTwo), new FrameworkPropertyMetadata(ModuleName.Robot.ToString(), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), 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(ATMArmRobotTwo), new PropertyMetadata(null));
- public CB.WaferInfo Wafer3
- {
- get { return (CB.WaferInfo)GetValue(Wafer3Property); }
- set { SetValue(Wafer3Property, value); }
- }
- // Using a DependencyProperty as the backing store for Wafer3. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Wafer3Property =
- DependencyProperty.Register("Wafer3", typeof(CB.WaferInfo), typeof(ATMArmRobotTwo), new PropertyMetadata(null));
- public CB.WaferInfo Wafer4
- {
- get { return (CB.WaferInfo)GetValue(Wafer4Property); }
- set { SetValue(Wafer4Property, value); }
- }
- // Using a DependencyProperty as the backing store for Wafer2. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Wafer4Property =
- DependencyProperty.Register("Wafer4", typeof(CB.WaferInfo), typeof(ATMArmRobotTwo), new PropertyMetadata(null));
- public CB.WaferInfo Wafer5
- {
- get { return (CB.WaferInfo)GetValue(Wafer5Property); }
- set { SetValue(Wafer5Property, value); }
- }
- // Using a DependencyProperty as the backing store for Wafer2. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty Wafer5Property =
- DependencyProperty.Register("Wafer5", typeof(CB.WaferInfo), typeof(ATMArmRobotTwo), 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(ATMArmRobotTwo), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
- private string CurrentPosition;
- private string CurrentArmA;
- private string CurrentArmB;
- 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;
- public event PropertyChangedEventHandler PropertyChanged;
- static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- var self = (ATMArmRobotTwo)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;
- }
- }
- public ATMArmRobotTwo()
- {
- #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 = CurrentArmB = 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;
- 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 System.Action(() =>
- {
- nextEvent.Set();
- });
- var wait = new System.Action(() =>
- {
- if (!nextEvent.WaitOne(AnimationTimeout))
- {
- LogMsg("Aniamtion time out!");
- }
- });
- var done = new System.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);
- 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);
- canvas3.Rotate(position.EndPosition.Hand, 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();
- //}
- }
- 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 = translate.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<string, string, string>)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<IWindowManager>();
- WaferRobotViewModel waferRobotViewModel = new WaferRobotViewModel();
- waferRobotViewModel.SystemName = "SMIFA";
- (windowManager as WindowManager)?.ShowDialogWithTitle(waferRobotViewModel, null, "WaferRobot Status");
- }
- }
-
- }
|