123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- using Bolt.Toolkit.Wpf.Data;
- using MECF.Framework.Common.CommonData;
- using OpenSEMI.ClientBase;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Media;
- using VirgoUI.Controls.Common;
- using RobotPosition = Bolt.Toolkit.Wpf.Data.RobotPosition;
- using StationPosition = Bolt.Toolkit.Wpf.Data.StationPosition;
- namespace VirgoUI.Client.Controls.Parts
- {
- /// <summary>
- /// SingleArmRobot.xaml 的交互逻辑
- /// </summary>
- public partial class SingleArmRobot : UserControl, INotifyPropertyChanged
- {
- protected int moveTime = 300;
- private const int AnimationTimeout = 3000;
- private string CurrentPosition
- {
- get; set;
- }
- private RobotAction CurrentAction
- {
- get; set;
- }
- public int MoveTime
- {
- get => moveTime;
- set
- {
- moveTime = value;
- }
- }
- 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(SingleArmRobot), new PropertyMetadata(0));
- 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(SingleArmRobot), new PropertyMetadata(null, StationPositionChangedCallback));
- public RobotMoveInfo RobotMoveInfo
- {
- get { return (RobotMoveInfo)GetValue(RobotMoveInfoProperty); }
- set { SetValue(RobotMoveInfoProperty, value); }
- }
- public static readonly DependencyProperty RobotMoveInfoProperty =
- DependencyProperty.Register("RobotMoveInfo", typeof(RobotMoveInfo), typeof(SingleArmRobot), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
- 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(SingleArmRobot), 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(SingleArmRobot), 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(SingleArmRobot), new PropertyMetadata("Robot"));
- 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(SingleArmRobot), 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(SingleArmRobot), new PropertyMetadata(null));
- public bool WaferPresent
- {
- get { return (bool)GetValue(WaferPresentProperty); }
- set { SetValue(WaferPresentProperty, value); }
- }
- // Using a DependencyProperty as the backing store for WaferPresent. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty WaferPresentProperty =
- DependencyProperty.Register("WaferPresent", typeof(bool), typeof(SingleArmRobot), new PropertyMetadata(false));
- 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;
- }
- public Dictionary<string, StationPosition> EfemStationPosition
- {
- get
- {
- return new Dictionary<string, StationPosition>()
- {
- { "System", new StationPosition() {
- StartPosition = new RobotPosition() {Root = 160, Arm = 191, Hand = 99 }
- ,EndPosition = new RobotPosition() {Root = 160, Arm = 191, Hand = 99 }}
- }
- ,{ "EfemRobot", new StationPosition() {
- StartPosition = new RobotPosition() {Root = 160, Arm = 191, Hand = 99 }
- ,EndPosition = new RobotPosition() {Root = 160, Arm = 191, Hand = 99 }}
- }
- ,{ "LP1", new StationPosition() {
- StartPosition = new RobotPosition() {X = 0, Root = 160, Arm = 191, Hand = 99 }
- ,EndPosition = new RobotPosition() { Root = 140, Arm = 260, Hand = 50 }}
- }
- ,{ "Cooling1", new StationPosition() {
- StartPosition = new RobotPosition() {X = 63, Root = 160, Arm = 191, Hand = 99 }
- ,EndPosition = new RobotPosition() { Root = 140, Arm = 260, Hand = 50 }}
- }
- ,{ "PMA", new StationPosition() {
- StartPosition = new RobotPosition() {X = 180, Root = 160, Arm = 191, Hand = 99 }
- ,EndPosition = new RobotPosition() { Root = 90, Arm = 360, Hand = 0 }}
- }
- };
- }
- }
- public SingleArmRobot()
- {
- InitializeComponent();
- root.DataContext = this;
- MoveCommand = new RelayCommand(MoveTo);
- canvas1.Rotate(90);
- canvas2.Rotate(180);
- canvas3.Rotate(180);
- CurrentPosition = "System";
- StationPosition = EfemStationPosition;
- }
- static void StationPositionChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- //return;
- // following is for test purpose
- var self = (SingleArmRobot)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 };
- m.Items.Add(new MenuItem() { Header = "Pick", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Picking } });
- m.Items.Add(new MenuItem() { Header = "Place", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Placing } });
- m.Items.Add(new MenuItem() { Header = "Move", Command = self.MoveCommand, CommandParameter = new RobotMoveInfo() { BladeTarget = position.Key, Action = RobotAction.Moving } });
- menus.Add(m);
- }
- self.Menu = menus;
- self.MoveTo(new RobotMoveInfo() { BladeTarget = "System", 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(string.Format("Target: {0} - {1}", CurrentPosition, RobotMoveInfo.BladeTarget));
- Invoke(() => MoveRobot(RobotMoveInfo));
- CurrentAction = RobotMoveInfo.Action;
- CurrentPosition = RobotMoveInfo.BladeTarget;
- }
- }
- }
- private void MoveRobot(RobotMoveInfo moveInfo, Action onComplete = null)
- {
- canvas1.Stop();
- canvas2.Stop();
- canvas3.Stop();
- var target = moveInfo.BladeTarget;
- if (string.IsNullOrEmpty(target))
- return;
- MoveToStart(CurrentPosition
- , () => RotateTo(target
- , () =>
- {
- if (moveInfo.Action != RobotAction.Moving)
- {
- MoveToEnd(target, () => MoveToEnd(target, () => UpdateWafer(moveInfo)));
- }
- }));
- }
- private void RotateTo(string station, Action onComplete = null)
- {
- var position = StationPosition[station];
- root.Rotate(position.StartPosition.X, true, MoveTime, 0, 0, onComplete);
- }
- private void MoveToStart(string station, Action onComplete = null)
- {
- var position = StationPosition[station];
- canvas1.Rotate(position.StartPosition.Root, true, MoveTime, 0, 0, onComplete);
- canvas2.Rotate(position.StartPosition.Arm, true, MoveTime);
- canvas3.Rotate(position.StartPosition.Hand, true, MoveTime);
- CurrentPosition = station;
- }
- private void MoveToEnd(string station, Action onComplete = null)
- {
- canvas1.Stop();
- canvas2.Stop();
- canvas3.Stop();
- var position = StationPosition[station];
- canvas1.Rotate(position.EndPosition.Root, true, MoveTime, 0, 0, onComplete);
- canvas2.Rotate(position.EndPosition.Arm, true, MoveTime);
- canvas3.Rotate(position.EndPosition.Hand, true, MoveTime);
- CurrentPosition = station;
- }
- private void UpdateWafer(RobotMoveInfo moveInfo, Action onComplete = null)
- {
- switch (moveInfo.Action)
- {
- case RobotAction.None:
- break;
- case RobotAction.Picking:
- WaferPresent = true;
- break;
- case RobotAction.Placing:
- WaferPresent = false;
- break;
- default:
- break;
- }
- }
- private void Invoke(Action action)
- {
- Dispatcher.Invoke(action);
- }
- private void LogMsg(string msg)
- {
- var source = "Robot";
- Console.WriteLine("{0} {1}", source, msg);
- }
- private void MoveTo(object target)
- {
- MoveRobot((RobotMoveInfo)target);
- }
- }
- }
|