using MaterialDesignThemes.Wpf;
using Prism.Commands;
using Prism.Events;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using TeamAAS_VP;
using TeamAAS_VP.Controls;
using TeamAAS_VP.Core;
using TeamAAS_VP.Enums;
using TeamAAS_VP.Events;
using TeamAAS_VP.Interfaces;
using TeamAAS_VP.Models;
using TeamAAS_VP.Models.Robot;
using TeamAAS_VP.Resources.Languages;
using TeamAAS_VP.Services;
namespace TeamAAS_VP.ViewModels.Product
{
public class RobotPointParamsViewModel : BindableBase, IConfirmNavigationRequest
{
IRegionManager _regionManager;
IEventAggregator _eventAggregator;
IContainerProvider _container;
IDialogService _dialogService;
IConfigService _configService;
IRobotService _robotService;
ISystemDatabaseService _systemDatabaseService;
#region 属性
private ProductModel _SelectProduct;
///
/// 选中的产品
///
public ProductModel SelectProduct
{
get { return _SelectProduct; }
set { SetProperty(ref _SelectProduct, value); }
}
private RobotPointStore _SelectedRobot;
public RobotPointStore SelectedRobot
{
get { return _SelectedRobot; }
set {
if (SetProperty(ref _SelectedRobot, value))
{
try
{
if (value != null)
{
if (Robot != null)
{
Robot.EnterDebugMode = false;
}
Robot = _robotService.GetRobot(value.Id);
Robot.EnterDebugMode = true;
SelectedPointInDataGrid = value.Points.FirstOrDefault();
SelectedPointInComboBox = value.Points.FirstOrDefault();
this.Distance = _configService.GetRobotStepDistance(Robot.Id);
}
}
catch (Exception)
{
}
}
}
}
private RPoint _SelectPoint;
public RPoint SelectPoint
{
get { return _SelectPoint; }
set { SetProperty(ref _SelectPoint,value); }
}
private RPoint _selectedPointInDataGrid;
public RPoint SelectedPointInDataGrid
{
get { return _selectedPointInDataGrid; }
set
{
if (SetProperty(ref _selectedPointInDataGrid, value))
{
SelectedPointInComboBox = value;
}
// 可以同步到 SelectPoint 属性
SelectPoint = value;
}
}
private RPoint _selectedPointInComboBox;
public RPoint SelectedPointInComboBox
{
get { return _selectedPointInComboBox; }
set
{
if (SetProperty(ref _selectedPointInComboBox, value))
{
SelectedPointInDataGrid = value;
}
// 可以同步到 SelectPoint 属性
SelectPoint = value;
}
}
private MotionCommand _SelectMotionCommand;
///
/// 选中的运动指令
///
public MotionCommand SelectMotionCommand
{
get { return _SelectMotionCommand; }
set { SetProperty(ref _SelectMotionCommand,value); }
}
public Management management { get; set; }
private IRobot _Robot;
public IRobot Robot
{
get { return _Robot; }
set
{
SetProperty(ref _Robot, value);
}
}
private double _Distance = 1;
public double Distance
{
get { return _Distance; }
set
{
SetProperty(ref _Distance, value);
try
{
if (Robot == null)
{
return;
}
_configService.UpdateRobotStepDistance(Robot.Id, value);
}
catch (Exception)
{
}
}
}
private ObservableCollection _Tools = new ObservableCollection(new int[] {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15});
///
/// 机器人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)
{
}
}
}
}
}
private bool _IsHaveRobot = false;
public bool IsHaveRobot
{
get { return _IsHaveRobot; }
set { SetProperty(ref _IsHaveRobot, value); }
}
#endregion
#region 命令
private DelegateCommand _NextCommand;
public DelegateCommand NextCommand =>
_NextCommand ?? (_NextCommand = new DelegateCommand(ExecuteNextCommand));
private DelegateCommand _BackCommand;
public DelegateCommand BackCommand =>
_BackCommand ?? (_BackCommand = new DelegateCommand(ExecuteBackCommand));
private DelegateCommand _GoPalletCommand;
public DelegateCommand GoPalletCommand =>
_GoPalletCommand ?? (_GoPalletCommand = new DelegateCommand(ExecuteGoPalletCommand));
private DelegateCommand _LoadedCommand;
public DelegateCommand LoadedCommand =>
_LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
private DelegateCommand