using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;
using MaterialDesignThemes.Wpf;
using MathNet.Numerics.LinearAlgebra;
using OpenCvSharp;
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.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web.UI.WebControls;
using System.Windows;
using System.Windows.Media.Imaging;
using Team.FFFeederService;
using Team.FFFeederService.Interfaces;
using Team.FFFeederService.Models;
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.Feeder;
using TeamAAS_VP.Resources.Languages;
using TeamAAS_VP.Views.Product;
namespace TeamAAS_VP.ViewModels.Product
{
public class FeederParamsViewModel : BindableBase, IConfirmNavigationRequest
{
IRegionManager _regionManager;
IEventAggregator _eventAggregator;
IContainerProvider _container;
IDialogService _dialogService;
IConfigService _configService;
IRobotService _robotService;
ICameraService _cameraService;
IFeederService _feederService;
ICalibrationService _calibrationService;
IRemoteCommandService _remoteCommandService;
ISystemDatabaseService _systemDatabaseService;
CancellationTokenSource TokenSource;
CancellationTokenSource AutoFindVirCTS;
#region 属性
private ProductModel _SelectProduct;
///
/// 选中的产品
///
public ProductModel SelectProduct
{
get { return _SelectProduct; }
set { SetProperty(ref _SelectProduct, value); }
}
private ProcedureModel _SelectProcedure;
///
/// 选中的流程
///
public ProcedureModel SelectProcedure
{
get { return _SelectProcedure; }
set { SetProperty(ref _SelectProcedure, value); }
}
private int _SelectFeederFunctionIndex;
public int SelectFeederFunctionIndex
{
get { return _SelectFeederFunctionIndex; }
set
{
SetProperty(ref _SelectFeederFunctionIndex, value);
if (value >= 0 && value <= 25)
{
SelectFeederFunction = (VibrationFunction)value;
}
else
{
SelectFeederFunction = VibrationFunction.Delay;
}
}
}
private VibrationFunction _SelectFeederFunction;
///
/// 选中的feeder振动功能码
///
public VibrationFunction SelectFeederFunction
{
get { return _SelectFeederFunction; }
set { SetProperty(ref _SelectFeederFunction, value); }
}
private int _SelectStockFeederFunctionIndex;
public int SelectStockFeederFunctionIndex
{
get { return _SelectStockFeederFunctionIndex; }
set
{
SetProperty(ref _SelectStockFeederFunctionIndex, value);
if (value >= 0 && value <= 25)
{
SelectStockFeederFunction = (VibrationFunction)value;
}
else
{
SelectStockFeederFunction = VibrationFunction.Delay;
}
}
}
private VibrationFunction _SelectStockFunction;
///
/// 选中的feeder料仓功能码
///
public VibrationFunction SelectStockFunction
{
get { return _SelectStockFunction; }
set { SetProperty(ref _SelectStockFunction, value); }
}
private VibrationFunction _SelectStockFeederFunction;
///
/// 选中的feeder料仓振动盘功能码
///
public VibrationFunction SelectStockFeederFunction
{
get { return _SelectStockFeederFunction; }
set { SetProperty(ref _SelectStockFeederFunction, value); }
}
public Management management { get; set; }
private IVoiceCoilMotorFeeder _Feeder;
public IVoiceCoilMotorFeeder Feeder
{
get { return _Feeder; }
set { SetProperty(ref _Feeder, value); }
}
private int _SelectActionIndex = -1;
///
/// Feeder动作索引
///
public int SelectActionIndex
{
get { return _SelectActionIndex; }
set
{
SetProperty(ref _SelectActionIndex, value);
if (value >= 0 && SelectProcedure.FeederFindFrequency != null && SelectProcedure.FeederFindFrequency.FeederFindFrequency != null)
{
SelectedActionParam = SelectProcedure.FeederFindFrequency.FeederFindFrequency.FirstOrDefault(f => f.ActionIndex == value);
if (SelectedActionParam.AmplitudeMax == SelectedActionParam.AmplitudeMin || SelectedActionParam.FrequencyMax == SelectedActionParam.FrequencyMin)
{
AutoAdjustmentParameter findVirTask = new AutoAdjustmentParameter(Feeder, SelectedActionParam.ActionIndex, ExecuteVisualPhoto);
var defultpar = findVirTask.detector.GetLogicParameters();
SelectedActionParam.AmplitudeMax = defultpar.u16MaxAmp;
SelectedActionParam.AmplitudeMin = defultpar.u16MinAmp;
SelectedActionParam.FrequencyMax = defultpar.u16MaxFre;
SelectedActionParam.FrequencyMin = defultpar.u16MinFre;
SelectedActionParam.Duration= defultpar.u16Tim;
findVirTask.Dispose();
}
}
else
{
SelectedActionParam = null;
}
}
}
private ActionParamsExtModel _SelectedActionParam;
public ActionParamsExtModel SelectedActionParam
{
get { return _SelectedActionParam; }
set { SetProperty(ref _SelectedActionParam, value); }
}
private bool _InExecutionFindVibP;
///
/// 正在执行自动寻找振动参数
///
public bool InExecutionFindVibP
{
get { return _InExecutionFindVibP; }
set { SetProperty(ref _InExecutionFindVibP, value); }
}
private BitmapSource _CameraImage;
public BitmapSource CameraImage
{
get { return _CameraImage; }
set { SetProperty(ref _CameraImage, value); }
}
private bool _FeederDirectionInverse;
public bool FeederDirectionInverse
{
get { return _FeederDirectionInverse; }
set { SetProperty(ref _FeederDirectionInverse, value); }
}
private SingleActionParam _SingleActionParam=new SingleActionParam();
///
/// 自动调频时的动作参数
///
public SingleActionParam SingleActionParam
{
get { return _SingleActionParam; }
set { SetProperty(ref _SingleActionParam, value); }
}
private string _StateMesg;
public string StateMesg
{
get { return _StateMesg; }
set { SetProperty(ref _StateMesg, 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 _AddFunctionCommand;
public DelegateCommand AddFunctionCommand =>
_AddFunctionCommand ?? (_AddFunctionCommand = new DelegateCommand(ExecuteAddFunctionCommand));
private DelegateCommand