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 TeamAAS_VP.Enums;
using TeamAAS_VP.Events;
using TeamAAS_VP.Core;
using TeamAAS_VP.Interfaces;
using TeamAAS_VP.Models;
using System.Windows;
using TeamAAS_VP;
using TeamAAS_VP.Resources.Languages;
namespace TeamAAS_VP.ViewModels.Product
{
public class RobotPointParamsViewModel : BindableBase
{
IRegionManager _regionManager;
IEventAggregator _eventAggregator;
IContainerProvider _container;
IDialogService _dialogService;
ProductsViewModel productsViewModel;
#region 属性
private ProductModel _SelectProduct;
///
/// 选中的产品
///
public ProductModel SelectProduct
{
get { return _SelectProduct; }
set { SetProperty(ref _SelectProduct, value); }
}
private RPoint _SelectPoint;
public RPoint SelectPoint
{
get { return _SelectPoint; }
set { SetProperty(ref _SelectPoint,value); }
}
private MotionCommand _SelectMotionCommand;
///
/// 选中的运动指令
///
public MotionCommand SelectMotionCommand
{
get { return _SelectMotionCommand; }
set { SetProperty(ref _SelectMotionCommand,value); }
}
private int _SelectPointIndex=-1;
public int SelectPointIndex
{
get { return _SelectPointIndex; }
set { SetProperty(ref _SelectPointIndex,value); }
}
public Management management { get; set; }
public RobotService robotService { get; set; }
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;
}
}
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 _Robots = new ObservableCollection();
///
/// 机器人参数
///
public ObservableCollection Robots
{
get { return _Robots; }
set { SetProperty(ref _Robots, value);
if (value!=null)
{
if (value.Count<=0)
{
IsHaveRobot = false;
}
else
{
IsHaveRobot = true;
}
}
}
}
private RobotInfo _RobotInfo = new RobotInfo();
///
/// 机器人
///
public RobotInfo SelectRobotInfo
{
get { return _RobotInfo; }
set { SetProperty(ref _RobotInfo, value);
if (value != null)
{
Robot = robotService.GetRobot(value.Id);
if (value.RobotBrand == RobotBrand.FANUC)
{
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;
}
}
}
}
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)
{
}
}
}
}
}
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 _AddPointCommand;
public DelegateCommand AddPointCommand =>
_AddPointCommand ?? (_AddPointCommand = new DelegateCommand(ExecuteAddPointCommand));
private DelegateCommand _RemovePointCommand;
public DelegateCommand RemovePointCommand =>
_RemovePointCommand ?? (_RemovePointCommand = new DelegateCommand(ExecuteRemovePointCommand, () => { return SelectPointIndex >= 0 ? true : false; }).ObservesProperty(()=> SelectPointIndex));
private DelegateCommand _GoPalletCommand;
public DelegateCommand GoPalletCommand =>
_GoPalletCommand ?? (_GoPalletCommand = new DelegateCommand(ExecuteGoPalletCommand));
private DelegateCommand _LoadedCommand;
public DelegateCommand LoadedCommand =>
_LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
private DelegateCommand