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.Web.Hosting;
using TeamAAS_VP.Controls;
using TeamAAS_VP.Enums;
using TeamAAS_VP.Events;
using TeamAAS_VP.Core;
using TeamAAS_VP.Interfaces;
using TeamAAS_VP.Models;
using TeamAAS_VP.Views.Product;
using TeamAAS_VP;
using Microsoft.Win32;
using System.Windows;
using TeamAAS_VP.Resources.Languages;
using TeamAAS_VP.Models.Robot;
using TeamAAS_VP.Services;
using TeamAAS_VP.Core.Robots;
namespace TeamAAS_VP.ViewModels.Product
{
public class PalletManageViewModel : BindableBase, IDialogAware
{
IRegionManager _regionManager;
IEventAggregator _eventAggregator;
IContainerProvider _container;
IDialogService _dialogService;
IRobotService _robotService;
IConfigService _configService;
#region 属性
public string Title => "Pallet";
private ProductModel _SelectProduct;
///
/// 选中的产品
///
public ProductModel SelectProduct
{
get { return _SelectProduct; }
set { SetProperty(ref _SelectProduct, value); }
}
private RobotPointStore _SelectedRobot;
public RobotPointStore SelectedRobot
{
get { return _SelectedRobot; }
set { SetProperty(ref _SelectedRobot, value); }
}
private ObservableCollection _Pallets;
///
/// 托盘集合
///
public ObservableCollection Pallets
{
get { return _Pallets; }
set { SetProperty(ref _Pallets, value); }
}
private Pallet _SelectPallet;
///
/// 选中的托盘
///
public Pallet SelectPallet
{
get { return _SelectPallet; }
set
{
SetProperty(ref _SelectPallet, value);
if (value == null)
return;
Points = new ObservableCollection();
Points.Add(value.P0);
Points.Add(value.P1);
Points.Add(value.P2);
Row = value.Row;
Column = value.Column;
Arrangement = value.Arrangement;
}
}
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 _Row;
public int Row
{
get { return _Row; }
set
{
SetProperty(ref _Row, value);
if (SelectPallet != null)
{
SelectPallet.Row = value;
_eventAggregator.GetEvent().Publish(SelectPallet);
}
}
}
private int _Column;
public int Column
{
get { return _Column; }
set
{
SetProperty(ref _Column, value);
if (SelectPallet != null)
{
SelectPallet.Column = value;
_eventAggregator.GetEvent().Publish(SelectPallet);
}
}
}
private PalletArrangement _Arrangement;
public PalletArrangement Arrangement
{
get
{
return _Arrangement;
}
set
{
SetProperty(ref _Arrangement, value);
if (SelectPallet != null)
{
SelectPallet.Arrangement = value;
_eventAggregator.GetEvent().Publish(SelectPallet);
}
}
}
private ObservableCollection _Points;
public ObservableCollection Points
{
get { return _Points; }
set { SetProperty(ref _Points, 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 bool CanRemove
{
get
{
if (SelectPallet != null)
return true;
else return false;
}
}
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 _CreateCommand;
public DelegateCommand CreateCommand =>
_CreateCommand ?? (_CreateCommand = new DelegateCommand(ExecuteCreateCommand));
private DelegateCommand _RemoveCommand;
public DelegateCommand RemoveCommand =>
_RemoveCommand ?? (_RemoveCommand = new DelegateCommand(ExecuteRemoveCommand).ObservesCanExecute(() => CanRemove).ObservesProperty(() => SelectPallet));
private DelegateCommand _ProductSelectionChangedCommand;
public DelegateCommand ProductSelectionChangedCommand =>
_ProductSelectionChangedCommand ?? (_ProductSelectionChangedCommand = new DelegateCommand(ExecuteProductSelectionChangedCommand));
private DelegateCommand _ConfirmCommand;
public DelegateCommand ConfirmCommand =>
_ConfirmCommand ?? (_ConfirmCommand = new DelegateCommand(ExecuteConfirmCommand));
private DelegateCommand _CancelCommand;
public DelegateCommand CancelCommand =>
_CancelCommand ?? (_CancelCommand = new DelegateCommand(ExecuteCancelCommand));
private DelegateCommand _CopyCommand;
public DelegateCommand CopyCommand =>
_CopyCommand ?? (_CopyCommand = new DelegateCommand(ExecuteCopyCommand));
private DelegateCommand _EditNameCommand;
public DelegateCommand EditNameCommand =>
_EditNameCommand ?? (_EditNameCommand = new DelegateCommand(ExecuteEditNameCommand));
private DelegateCommand