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.Windows;
using TeamAAS_VP.Core;
using TeamAAS_VP.Core.PLCs;
using TeamAAS_VP.DxfModule;
using TeamAAS_VP.Enums;
using TeamAAS_VP.Events;
using TeamAAS_VP.Interfaces;
using TeamAAS_VP.Models;
using TeamAAS_VP.Models.PLC;
using TeamAAS_VP.Models.Robot;
using TeamAAS_VP.Resources.Languages;
using TeamAAS_VP.Views.Product;
namespace TeamAAS_VP.ViewModels.Product
{
public class PlcPointParamsViewModel : 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 PlcPoint _SelectedPoint;
public PlcPoint SelectedPoint
{
get { return _SelectedPoint; }
set { SetProperty(ref _SelectedPoint, value); }
}
private PlcPoint _selectedPointInDataGrid;
public PlcPoint SelectedPointInDataGrid
{
get { return _selectedPointInDataGrid; }
set
{
if (SetProperty(ref _selectedPointInDataGrid, value))
{
SelectedPointInComboBox = value;
// update command availability
_MovePointUpCommand?.RaiseCanExecuteChanged();
_MovePointDownCommand?.RaiseCanExecuteChanged();
// 更新依赖可执行状态的命令
_TechPointCommand?.RaiseCanExecuteChanged();
_ExecuteMotion?.RaiseCanExecuteChanged();
}
// 可以同步到 SelectPoint 属性
SelectedPoint = value;
}
}
private PlcPoint _selectedPointInComboBox;
public PlcPoint SelectedPointInComboBox
{
get { return _selectedPointInComboBox; }
set
{
if (SetProperty(ref _selectedPointInComboBox, value))
{
SelectedPointInDataGrid = value;
}
// 可以同步到 SelectPoint 属性
SelectedPoint = value;
}
}
private ObservableCollection _Points = new ObservableCollection();
///
/// 点位集合
///
public ObservableCollection Points
{
get { return _Points; }
set { SetProperty(ref _Points, 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 int _SelectedIndex;
public int SelectedIndex
{
get { return _SelectedIndex; }
set { SetProperty(ref _SelectedIndex, 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)
{
}
}
}
#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 _LoadedCommand;
public DelegateCommand LoadedCommand =>
_LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
private DelegateCommand