123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- using Aitex.Core.UI.MVVM;
- using Aitex.Core.Util;
- using Aitex.Sorter.Common;
- using Aitex.Sorter.UI.Controls.Common;
- using MECF.Framework.Common.OperationCenter;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- 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.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using MECF.Framework.Common.Equipment;
- using System.Globalization;
- namespace Aitex.Sorter.UI.Controls
- {
- /// <summary>
- /// RobotControl.xaml 的交互逻辑
- /// </summary>
- public partial class RobotControl : ViewModelControl
- {
- public Dictionary<ModuleName, int> Target
- {
- get { return (Dictionary<ModuleName, int>)GetValue(TargetProperty); }
- set { SetValue(TargetProperty, value); }
- }
- // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty TargetProperty =
- DependencyProperty.Register("Target", typeof(Dictionary<ModuleName, int>), typeof(RobotControl), new PropertyMetadata(null));
- public bool EnableHighSpeed
- {
- get { return (bool)GetValue(EnableHighSpeedProperty); }
- set { SetValue(EnableHighSpeedProperty, value); }
- }
- // Using a DependencyProperty as the backing store for Target. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty EnableHighSpeedProperty =
- DependencyProperty.Register("EnableHighSpeed", typeof(bool), typeof(RobotControl), new PropertyMetadata(null));
- public RobotControl()
- {
- InitializeComponent();
- OperationCommand = new DelegateCommand<DependencyObject>(Operation, x => !IsMaintenanceMode && !IsAutoMode);
- Command = new DelegateCommand<DependencyObject>(DoCommand, x => !IsMaintenanceMode && !IsAutoMode);
- SetSpeedCommand = new DelegateCommand<DependencyObject>(Operation, CanSetSpeed);
-
- var hands = new List<Hand>();
- hands.Add(Hand.Blade1);
- hands.Add(Hand.Blade2);
- Hands = hands.ToArray();
- EnableHighSpeed = true;
- root.DataContext = this;
- }
- private bool CanSetSpeed(DependencyObject sender)
- {
- var command = CommandHelper.GetCommandItem(sender);
- var lstParameter = new List<object>(command.Parameters);
- if (lstParameter[0].ToString() == RobotSpeed)
- return false;
- return true;
- }
- [Subscription(ParamName.RTStatus, "System")]
- public int RoutManagerState
- {
- get;
- set;
- }
- public bool IsMaintenanceMode
- {
- get => RoutManagerState == (int)RtState.Maintenance;
- }
- [Subscription(ParamName.IsAutoMode, "System")]
- public bool IsAutoMode { get; set; }
- public ICommand OperationCommand
- {
- get;
- private set;
- }
- public ICommand Command
- {
- get;
- private set;
- }
- public ICommand SetSpeedCommand
- {
- get;
- private set;
- }
-
- void Operation(DependencyObject sender)
- {
- var command = CommandHelper.GetCommandItem(sender);
- InvokeClient.Instance.Service.DoOperation(command.CommandName, command.Parameters);
- }
- private void DoCommand(DependencyObject sender)
- {
- var command = CommandHelper.GetCommandItem(sender);
- var lstParameter = new List<object>(command.Parameters);
- lstParameter.Insert(0, command.Target);
- lstParameter.Insert(1, command.CommandName);
- InvokeClient.Instance.Service.DoOperation(OperationName.DeviceOperation, lstParameter.ToArray());
- }
- [Subscription(ParamName.RobotState, DeviceName.Robot)]
- public string Status
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotPosRotationAxis, DeviceName.Robot)]
- public string RobotPosRotationAxis
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotPosExtensionAxis, DeviceName.Robot)]
- public string RobotPosExtensionAxis
- {
- get; set;
- }
- [Subscription(ParamName.RobotPosWrist1Axis, DeviceName.Robot)]
- public string RobotPosWrist1Axis
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotPosWrist2Axis, DeviceName.Robot)]
- public string RobotPosWrist2Axis
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotPosEvevationAxis, DeviceName.Robot)]
- public string RobotPosEvevationAxis
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotBlade1Traget, DeviceName.Robot)]
- public string RobotBlade1Traget
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotBlade2Traget, DeviceName.Robot)]
- public string RobotBlade2Traget
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotSpeed, DeviceName.Robot)]
- public string RobotSpeed
- {
- get;
- set;
- }
- [Subscription(ParamName.RobotError, DeviceName.Robot)]
- public string ErrorCode
- {
- get;
- set;
- }
- public Hand[] Hands
- {
- get;
- set;
- }
- }
- public class TargetSlotConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value != null)
- {
- var count = (int)value;
- return Enumerable.Range(0, count).ToDictionary(x => x + 1, x => x);
- }
- return new Dictionary<int, int>();
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
-
- public class TargetKeyValueConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- if (value != null)
- {
- var kvp = (KeyValuePair<ModuleName,int>)value;
- return Enum.Parse(typeof(ModuleName),kvp.Key.ToString());
- }
- return "";
- }
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
- }
|