123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- using Aitex.Core.UI.MVVM;
- using Aitex.Sorter.Common;
- using MECF.Framework.Common.CommonData;
- using MECF.Framework.Common.ControlDataContext;
- using MECF.Framework.Common.DataCenter;
- using MECF.Framework.Common.Equipment;
- using MECF.Framework.Common.OperationCenter;
- using MECF.Framework.Common.Utilities;
- using Newtonsoft.Json;
- using OpenSEMI.ClientBase.Command;
- using Prism.Mvvm;
- using PunkHPX8_Core;
- using PunkHPX8_MainPages.Roles;
- using PunkHPX8_MainPages.Views;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Windows.Forms.VisualStyles;
- using System.Windows.Input;
- using System.Windows.Threading;
- namespace PunkHPX8_MainPages.ViewModels
- {
- public class RobotCycleViewModel : BindableBase
- {
- #region 内部变量
- /// <summary>
- /// 输入的Cycle次数
- /// </summary>
- private int _inPutCycleTimes = 1;
- /// <summary>
- /// Aligner旋转的角度
- /// </summary>
- private int _alignerAngle = 0;
- /// <summary>
- /// 当前正在执行第几次Cycle
- /// </summary>
- private int _currentCycle;
- /// <summary>
- /// 是否可以输入参数
- /// </summary>
- private bool _isInputParameterEnable;
- #region 系统数据
- /// <summary>
- /// 定时器
- /// </summary>
- DispatcherTimer _timer;
- /// <summary>
- /// 查询后台数据集合
- /// </summary>
- private List<string> _rtDataKeys = new List<string>();
- /// <summary>
- /// rt查询key数值字典
- /// </summary>
- private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
- #endregion
- #endregion
- #region 属性
- public int InPutCycleTimes
- {
- get { return _inPutCycleTimes; }
- set { SetProperty(ref _inPutCycleTimes, value); }
- }
- public int AlignerAngle
- {
- get { return _alignerAngle; }
- set { SetProperty(ref _alignerAngle, value); }
- }
- public int CurrentCycle
- {
- get { return _currentCycle; }
- set { SetProperty(ref _currentCycle, value); }
- }
- public bool IsInputParameterEnable
- {
- get { return _isInputParameterEnable; }
- set { SetProperty(ref _isInputParameterEnable, value); }
- }
- #endregion
- public class PositionItem : INotifyPropertyChanged
- {
- private string _destination;
- public string ModuleType { get; set; }
- public ModuleName ModuleName { get; set; }
- public string Parameter { get; set; }
- public Hand RobotHand { get; set; }
- public Flip PickRobotFlip { get; set; }
- public Flip PlaceRobotFlip { get; set; }
- public string Destination {
- get => _destination;
- set
- {
- _destination = value;
- OnPropertyChanged(nameof(Destination)); // 触发通知
- }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged(string propertyName)
- => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- private ObservableCollection<PositionItem> _positions = new ObservableCollection<PositionItem>();
- public ObservableCollection<PositionItem> Positions
- {
- get { return _positions; }
- set { SetProperty(ref _positions, value); }
- }
- public ObservableCollection<string> PositionTypes { get; } = new ObservableCollection<string>
- {
- "LP", "Aligner", "Dummy", "SRD", "VPW","PlatingCell"
- };
- public ObservableCollection<string> HandsTypes { get; } = new ObservableCollection<string>
- {
- "Blade1", "Blade2"
- };
- public ObservableCollection<string> FlipTypes { get; } = new ObservableCollection<string>
- {
- "Upper", "Down"
- };
- private string _selectedPositionType;
- public string SelectedPositionType
- {
- get { return _selectedPositionType; }
- set
- {
- SetProperty(ref _selectedPositionType, value);
- UpdateAvailableSelections();
- }
- }
- public ObservableCollection<ModuleName> AvailableSelections { get; } = new ObservableCollection<ModuleName>();
- private ModuleName _selectedSelection;
- public ModuleName SelectedSelection
- {
- get { return _selectedSelection; }
- set { SetProperty(ref _selectedSelection, value); }
- }
- private string _parameter;
- public string Parameter
- {
- get { return _parameter; }
- set { SetProperty(ref _parameter, value); }
- }
- private Hand _robotHand;
- public Hand RobotHand
- {
- get { return _robotHand; }
- set { SetProperty(ref _robotHand, value); }
- }
- private Flip _pickRobotFlip;
- public Flip PickRobotFlip
- {
- get { return _pickRobotFlip; }
- set { SetProperty(ref _pickRobotFlip, value); }
- }
- private Flip _placeRobotFlip;
- public Flip PlaceRobotFlip
- {
- get { return _placeRobotFlip; }
- set { SetProperty(ref _placeRobotFlip, value); }
- }
- #region 命令
- public ICommand RobotCycleConfirmCommand { get; set; }
-
- public ICommand RobotCycleStartCommand { get; set; }
- public ICommand RobotCycleAbortCommand { get; set; }
- public ICommand AddPositionCommand { get; set; }
- public ICommand MoveUpCommand { get; set; }
- public ICommand MoveDownCommand { get; set; }
- public ICommand RemoveCommand { get; set; }
- #endregion
- /// <summary>
- /// 构造器
- /// </summary>
- public RobotCycleViewModel()
- {
- RobotCycleConfirmCommand = new DelegateCommand<object>(RobotCycleConfirmAction);
- RobotCycleStartCommand = new DelegateCommand<object>(RobotCycleStartAction);
- RobotCycleAbortCommand = new DelegateCommand<object>(RobotCycleAbortAction);
- AddPositionCommand = new DelegateCommand<object>(AddPosition);
- MoveUpCommand = new DelegateCommand<object>(MovePositionUp);
- MoveDownCommand = new DelegateCommand<object>(MovePositionDown);
- RemoveCommand = new DelegateCommand<object>(RemovePosition);
- SelectedPositionType = PositionTypes.FirstOrDefault();
- RobotHand = Hand.Blade1;
- PickRobotFlip = Flip.Upper;
- PlaceRobotFlip = Flip.Upper;
- }
- private void UpdateAvailableSelections()
- {
- AvailableSelections.Clear();
- switch (SelectedPositionType)
- {
- case "LP":
- AvailableSelections.Add(ModuleName.LP1);
- AvailableSelections.Add(ModuleName.LP2);
- break;
- case "Aligner":
- AvailableSelections.Add(ModuleName.Aligner1);
- Parameter = "0"; // 默认角度
- break;
- case "Dummy":
- AvailableSelections.Add(ModuleName.Dummy1);
- AvailableSelections.Add(ModuleName.Dummy2);
- break;
- case "SRD":
- AvailableSelections.Add(ModuleName.SRD1);
- AvailableSelections.Add(ModuleName.SRD2);
- break;
- case "VPW":
- AvailableSelections.Add(ModuleName.VPW1);
- AvailableSelections.Add(ModuleName.VPW2);
- break;
- case "PlatingCell":
- AvailableSelections.Add(ModuleName.PlatingCell1);
- AvailableSelections.Add(ModuleName.PlatingCell2);
- AvailableSelections.Add(ModuleName.PlatingCell3);
- AvailableSelections.Add(ModuleName.PlatingCell4);
- break;
- }
- SelectedSelection = AvailableSelections.FirstOrDefault();
- RobotHand = Hand.Blade1;
- PickRobotFlip = Flip.Upper;
- PlaceRobotFlip = Flip.Upper;
- }
- private void AddPosition(object obj)
- {
- if ("Aligner".Equals(SelectedPositionType)) //目前就aligner的条目需要参数
- {
- Positions.Add(new PositionItem
- {
- ModuleType = SelectedPositionType,
- ModuleName = SelectedSelection,
- Parameter = Parameter,
- RobotHand = RobotHand,
- PickRobotFlip = PickRobotFlip,
- PlaceRobotFlip = PlaceRobotFlip
- });
- }
- else
- {
- Positions.Add(new PositionItem
- {
- ModuleType = SelectedPositionType,
- ModuleName = SelectedSelection,
- RobotHand = RobotHand,
- PickRobotFlip = PickRobotFlip,
- PlaceRobotFlip = PlaceRobotFlip
- });
- }
-
- }
- private void MovePositionUp(object obj)
- {
- if (obj is PositionItem item)
- {
- int index = Positions.IndexOf(item);
- if (index > 0)
- {
- Positions.Move(index, index - 1);
- }
- }
- }
- private void MovePositionDown(object obj)
- {
- if (obj is PositionItem item)
- {
- int index = Positions.IndexOf(item);
- if (index < Positions.Count - 1)
- {
- Positions.Move(index, index + 1);
- }
- }
- }
- private void RemovePosition(object obj)
- {
- if (obj is PositionItem item)
- {
- Positions.Remove(item);
- }
- }
- private void RobotCycleConfirmAction(object param)
- {
- if(Positions.Count == 0)
- {
- return;
- }
- else if (Positions.Count == 1)
- {
- Positions[0].Destination = Positions[0].ModuleName.ToString();
- }
- else
- {
- for (int i = 0; i < Positions.Count; i++)
- {
- if(i < Positions.Count - 1)
- {
- Positions[i].Destination = Positions[i + 1].ModuleName.ToString();
- }
- else
- {
- Positions[i].Destination = Positions[0].ModuleName.ToString();
- }
- }
- }
- }
- private void RobotCycleStartAction(object param)
- {
- List<RobotCycleParameter> parameters = new List<RobotCycleParameter>();
- foreach(var parameter in Positions)
- {
- RobotCycleParameter robotCycleParameter = new RobotCycleParameter();
- robotCycleParameter.ModuleName = parameter.ModuleName;
- robotCycleParameter.RobotArm = parameter.RobotHand;
- robotCycleParameter.PickRobotFlip = parameter.PickRobotFlip;
- robotCycleParameter.PlaceRobotFlip = parameter.PlaceRobotFlip;
- robotCycleParameter.Parameter = parameter.Parameter;
- parameters.Add(robotCycleParameter);
- }
- InvokeClient.Instance.Service.DoOperation($"EFEM.{EfemOperation.RobotCycle}", JsonConvert.SerializeObject(parameters), InPutCycleTimes);
- }
- private void RobotCycleAbortAction(object param)
- {
- InvokeClient.Instance.Service.DoOperation($"{ModuleName.EfemRobot}.{EfemOperation.Abort}");
- }
- /// <summary>
- /// 加载数据
- /// </summary>
- public void LoadData(string systemName)
- {
- _rtDataKeys.Clear();
- _rtDataKeys.Add("EFEM.CurrentRobotCycleTime");
- if (_timer == null)
- {
- _timer = new DispatcherTimer();
- _timer.Interval = TimeSpan.FromMilliseconds(200);
- _timer.Tick += Timer_Tick;
- }
- _timer.Start();
- }
- /// <summary>
- /// 定时器执行
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Timer_Tick(object sender, EventArgs e)
- {
- if (_rtDataKeys.Count != 0)
- {
-
-
- IsInputParameterEnable = "Aligner".Equals(SelectedPositionType) ? true : false;
-
- _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
- if (_rtDataValueDic != null)
- {
- CurrentCycle = CommonFunction.GetValue<int>(_rtDataValueDic, $"EFEM.CurrentRobotCycleTime");
- }
- }
- }
- /// <summary>
- /// 隐藏
- /// </summary>
- public void Hide()
- {
- }
- }
- }
|