using Prism.Commands;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
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 TeamAAS_VP.Events;
using TeamAAS_VP.Core;
using TeamAAS_VP.Interfaces;
using TeamAAS_VP.ViewModels;
using TeamAAS_VP;
using System.Collections.ObjectModel;
using TeamAAS_VP.Enums;
using TeamAAS_VP.Core.Robots;
using TeamAAS_VP.Resources.Languages;
namespace TeamAAS_VP.Controls
{
///
/// RobotManual.xaml 的交互逻辑
///
public partial class RobotManual : UserControl,INotifyPropertyChanged
{
public RobotManual()
{
InitializeComponent();
DataContext = this;
this.Loaded += RobotManual_Loaded;
}
private void RobotManual_Loaded(object sender, RoutedEventArgs e)
{
}
#region 属性
private IRobot _Robot;
public IRobot Robot
{
get { return _Robot; }
set { SetProperty(ref _Robot,value);
try
{
var config = FileHelper.ReadApplicationConfiguration();
if (config.RobotJogSetpDistance.TryGetValue(value.Id,out double distance))
{
this.Distance = distance;
}
if (value is FanucRobot)
{
Tools = new ObservableCollection { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
SelectTool = Robot.SelectedTool;
}
else
{
Tools = new ObservableCollection { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
SelectTool = Robot.SelectedTool;
}
}
catch (Exception)
{
}
}
}
private double _Distance=1;
public double Distance
{
get { return _Distance; }
set { SetProperty(ref _Distance, value);
try
{
if (Robot==null)
{
return;
}
var config = FileHelper.ReadApplicationConfiguration();
if (config.RobotJogSetpDistance.ContainsKey(Robot.Id))
{
config.RobotJogSetpDistance[Robot.Id] =value;
}
else
{
config.RobotJogSetpDistance.Add(Robot.Id,value);
}
FileHelper.SaveApplicationConfiguration(config);
}
catch (Exception)
{
}
}
}
private ObservableCollection _Tools = new ObservableCollection();
///
/// 机器人Tool集合
///
public ObservableCollection Tools
{
get { return _Tools; }
set { SetProperty(ref _Tools, value); }
}
private int _SelectTool;
///
/// 选中的Tool
///
public int SelectTool
{
get { return _SelectTool; }
set
{
SetProperty(ref _SelectTool, value);
if (value >= 0)
{
if (Robot != null && Robot.IsConnected)
{
try
{
Robot.SelectToolAsync(value);
}
catch (Exception)
{
}
}
}
}
}
#endregion
#region 命令
private DelegateCommand _ConnectCommand;
public DelegateCommand ConnectCommand =>
_ConnectCommand ?? (_ConnectCommand = new DelegateCommand(ExecuteConnectCommand));
private DelegateCommand _DisConnectCommand;
public DelegateCommand DisConnectCommand =>
_DisConnectCommand ?? (_DisConnectCommand = new DelegateCommand(ExecuteDisConnectCommand));
private DelegateCommand _MotorCommand;
public DelegateCommand MotorCommand =>
_MotorCommand ?? (_MotorCommand = new DelegateCommand(ExecuteMotorCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(()=>Robot).ObservesProperty(() => Robot.CanExecute));
private DelegateCommand _ResetCommand;
public DelegateCommand ResetCommand =>
_ResetCommand ?? (_ResetCommand = new DelegateCommand(ExecuteResetCommand).ObservesCanExecute(() => CanExecute).ObservesProperty(() => Robot).ObservesProperty(() => Robot.CanExecute));
private DelegateCommand