using Cognex.VisionPro;
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.Drawing;
using System.Linq;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Team.FFFeederService.Interfaces;
using TeamAAS_VP;
using TeamAAS_VP.Controls;
using TeamAAS_VP.Core;
using TeamAAS_VP.Data;
using TeamAAS_VP.Enums;
using TeamAAS_VP.Events;
using TeamAAS_VP.Interfaces;
using TeamAAS_VP.Models;
using TeamAAS_VP.Models.Lights;
using TeamAAS_VP.Resources.Languages;
using TeamAAS_VP.Services;
using static NPOI.HSSF.Util.HSSFColor;
namespace TeamAAS_VP.ViewModels.Product
{
public class CameraParamsViewModel : BindableBase, IConfirmNavigationRequest
{
IRegionManager _regionManager;
IEventAggregator _eventAggregator;
IContainerProvider _container;
IDialogService _dialogService;
IConfigService _configService;
IRobotService _robotService;
ICameraService _cameraService;
IFeederService _feederService;
IProductService _productService;
IRemoteCommandService _remoteCommandService;
ISystemDatabaseService _systemDatabaseService;
ILightManagerService _lightManagerService;
// 创建Channel
private readonly Channel<(int channel, int brightness)> _brightnessChannel;
private CancellationTokenSource _cancellationTokenSource;
#region 属性
private bool _IsPhotosUse = false;
public bool IsPhotosUse
{
get { return _IsPhotosUse; }
set { SetProperty(ref _IsPhotosUse, value); }
}
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 bool _IsHaveFeeder=false;
public bool IsHaveFeeder
{
get { return _IsHaveFeeder; }
set { SetProperty(ref _IsHaveFeeder, value); }
}
private bool _IsHaveRobot = false;
public bool IsHaveRobot
{
get { return _IsHaveRobot; }
set { SetProperty(ref _IsHaveRobot, value); }
}
private IRobot _Robot;
public IRobot Robot
{
get { return _Robot; }
set { SetProperty(ref _Robot, value); }
}
private ICamera _Camera;
public ICamera Camera
{
get { return _Camera; }
set { SetProperty(ref _Camera, value); }
}
public IVoiceCoilMotorFeeder Feeder { get; set; }
private ICogImage _Image;
public ICogImage Image
{
get { return _Image; }
set { SetProperty(ref _Image, value); }
}
private string _Message;
public string Message
{
get { return _Message; }
set { SetProperty(ref _Message, value); }
}
private float _ExposureTime;
///
/// 相机曝光时间
///
public float ExposureTime
{
get { return _ExposureTime; }
set { SetProperty(ref _ExposureTime, value);
SelectProcedure.ExposureTime = value;
if (Camera != null)
{
try
{
Camera.SetExposureTime(value);
}
catch (Exception)
{
}
}
}
}
private float _ExposureTime2;
///
/// 相机曝光2时间
///
public float ExposureTime2
{
get { return _ExposureTime2; }
set
{
SetProperty(ref _ExposureTime2, value);
SelectProcedure.ExposureTime2 = value;
}
}
private float _Gain;
///
/// 相机增益
///
public float Gain
{
get { return _Gain; }
set { SetProperty(ref _Gain, value);
SelectProcedure.Gain=value;
if (Camera != null)
{
try
{
Camera.SetGain(value);
}
catch (Exception)
{
}
}
}
}
private float _Gain2;
///
/// 相机增益2
///
public float Gain2
{
get { return _Gain2; }
set
{
SetProperty(ref _Gain2, value);
SelectProcedure.Gain2 = value;
}
}
private int _Photo1Light1;
///
/// 第一次拍照光源1亮度
///
public int Photo1Light1
{
get { return _Photo1Light1; }
set
{
SetProperty(ref _Photo1Light1, value);
SelectProcedure.Photo1Light1 = value;
}
}
private int _Photo1Light2;
///
/// 第一次拍照光源2亮度
///
public int Photo1Light2
{
get { return _Photo1Light2; }
set
{
SetProperty(ref _Photo1Light2, value);
SelectProcedure.Photo1Light2 = value;
}
}
private int _Photo1Light3;
///
/// 第一次拍照光源3亮度
///
public int Photo1Light3
{
get { return _Photo1Light3; }
set
{
SetProperty(ref _Photo1Light3, value);
SelectProcedure.Photo1Light3 = value;
}
}
private int _Photo1Light4;
///
/// 第一次拍照光源4亮度
///
public int Photo1Light4
{
get { return _Photo1Light4; }
set
{
SetProperty(ref _Photo1Light4, value);
SelectProcedure.Photo1Light4 = value;
}
}
private int _Photo1Light5;
///
/// 第一次拍照光源5亮度
///
public int Photo1Light5
{
get { return _Photo1Light5; }
set
{
SetProperty(ref _Photo1Light5, value);
SelectProcedure.Photo1Light5 = value;
}
}
private int _Photo1Light6;
///
/// 第一次拍照光源6亮度
///
public int Photo1Light6
{
get { return _Photo1Light6; }
set
{
SetProperty(ref _Photo1Light6, value);
SelectProcedure.Photo1Light6 = value;
}
}
private int _Photo1Light7;
///
/// 第一次拍照光源7亮度
///
public int Photo1Light7
{
get { return _Photo1Light7; }
set
{
SetProperty(ref _Photo1Light7, value);
SelectProcedure.Photo1Light7 = value;
}
}
private int _Photo2Light1;
///
/// 第二次拍照光源1亮度
///
public int Photo2Light1
{
get { return _Photo2Light1; }
set
{
SetProperty(ref _Photo2Light1, value);
SelectProcedure.Photo2Light1 = value;
}
}
private int _Photo2Light2;
///
/// 第二次拍照光源2亮度
///
public int Photo2Light2
{
get { return _Photo2Light2; }
set
{
SetProperty(ref _Photo2Light2, value);
SelectProcedure.Photo2Light2 = value;
}
}
private int _Photo2Light3;
///
/// 第二次拍照光源3亮度
///
public int Photo2Light3
{
get { return _Photo2Light3; }
set
{
SetProperty(ref _Photo2Light3, value);
SelectProcedure.Photo2Light3 = value;
}
}
private int _Photo2Light4;
///
/// 第二次拍照光源4亮度
///
public int Photo2Light4
{
get { return _Photo2Light4; }
set
{
SetProperty(ref _Photo2Light4, value);
SelectProcedure.Photo2Light4 = value;
}
}
private int _Photo2Light5;
///
/// 第二次拍照光源5亮度
///
public int Photo2Light5
{
get { return _Photo2Light5; }
set
{
SetProperty(ref _Photo2Light5, value);
SelectProcedure.Photo2Light5 = value;
}
}
private int _Photo2Light6;
///
/// 第二次拍照光源6亮度
///
public int Photo2Light6
{
get { return _Photo2Light6; }
set
{
SetProperty(ref _Photo2Light6, value);
SelectProcedure.Photo2Light6 = value;
}
}
private int _Photo2Light7;
///
/// 第二次拍照光源7亮度
///
public int Photo2Light7
{
get { return _Photo2Light7; }
set
{
SetProperty(ref _Photo2Light7, value);
SelectProcedure.Photo2Light7 = value;
}
}
private int _PhotoCount;
///
/// 拍照次数
///
public int PhotoCount
{
get { return _PhotoCount; }
set
{
SetProperty(ref _PhotoCount, value);
SelectProcedure.PhotoCount = value;
}
}
private bool _IsGrap=true;
public bool IsGrap
{
get { return _IsGrap; }
set { SetProperty(ref _IsGrap, 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 _LoadedCommand;
public DelegateCommand LoadedCommand =>
_LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
private DelegateCommand _LightValueChangedCommand;
public DelegateCommand LightValueChangedCommand =>
_LightValueChangedCommand ?? (_LightValueChangedCommand = new DelegateCommand(ExecuteLightValueChangedCommand));
private DelegateCommand _StartGrabbingCommand;
public DelegateCommand StartGrabbingCommand =>
_StartGrabbingCommand ?? (_StartGrabbingCommand = new DelegateCommand(ExecuteStartGrabbingCommand).ObservesProperty(() => IsGrap));
private DelegateCommand _StopGrabbingCommand;
public DelegateCommand StopGrabbingCommand =>
_StopGrabbingCommand ?? (_StopGrabbingCommand = new DelegateCommand(ExecuteStopGrabbingCommand).ObservesProperty(() => IsGrap));
private DelegateCommand _LightValueAddCommand;
public DelegateCommand LightValueAddCommand =>
_LightValueAddCommand ?? (_LightValueAddCommand = new DelegateCommand(ExecuteLightValueAddCommand));
private DelegateCommand _LightValueSubCommand;
public DelegateCommand LightValueSubCommand =>
_LightValueSubCommand ?? (_LightValueSubCommand = new DelegateCommand(ExecuteLightValueSubCommand));
private DelegateCommand