119 lines
4.2 KiB
C#
119 lines
4.2 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Windows.Input;
|
|
using Aurora.Api;
|
|
using Aurora.View;
|
|
using VisionCommon;
|
|
using System.Windows;
|
|
using VisionCommonUI.Resources;
|
|
using Hermes;
|
|
using Aurora;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
using System.Drawing;
|
|
using System.Diagnostics;
|
|
using System.Windows.Media.Imaging;
|
|
|
|
namespace VisionCommonUI {
|
|
public class CamDeviceSettingViewModel : NotifyPropertyChangedBase, IDisposable {
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
private Logger _Logger;
|
|
private FovInfo _FovInfo;
|
|
private FovRecipe _FovRecipe;
|
|
private eCamId _CamId;
|
|
private CameraAgentBase _CameraAgent;
|
|
private ICameraDisplay _CameraDisplay;
|
|
|
|
private IDisposable _EventDisposable;
|
|
|
|
#region Binding Properties
|
|
private CamConfig _CamConfig;
|
|
public CamConfig CamConfig { get => _CamConfig; set => SetProperty(ref _CamConfig, value); }
|
|
#endregion
|
|
|
|
#region ButtonCommand
|
|
public ICommand CMD_EditChildImage { get; set; }
|
|
public ICommand CMD_Reload { get; set; }
|
|
public ICommand CMD_Save { get; set; }
|
|
public ICommand CMD_Close { get; set; }
|
|
|
|
#endregion
|
|
|
|
public CamDeviceSettingViewModel(FovInfo fovInfo, ICameraDisplay cameraDisplay) {
|
|
_FovInfo = fovInfo;
|
|
_CamId = VisionRecipeManager.GetCamRecipe(_FovInfo).CamId;
|
|
_CameraAgent = CameraAgentManager.GetCameraAgent(_FovInfo);
|
|
_CameraDisplay = cameraDisplay;
|
|
|
|
var camConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(_CamId.ToString()) as CamConfig;
|
|
CamConfig = camConfig.Clone();
|
|
|
|
SetButtonCommands();
|
|
}
|
|
|
|
private void SetButtonCommands() {
|
|
CMD_EditChildImage = new DelegateCommand(new Action<object>(EditChildImage));
|
|
CMD_Reload = new DelegateCommand(new Action<object>(Reload));
|
|
CMD_Save = new DelegateCommand(new Action<object>(Save));
|
|
CMD_Close = new DelegateCommand(new Action<object>(Close));
|
|
}
|
|
|
|
public void SetExposureTime(int exposureTime) {
|
|
_CameraAgent.SetExposure(exposureTime);
|
|
}
|
|
|
|
public void SetImageRotationOffset(double rotationOffset) {
|
|
CamConfig.FlipAndRotation.ImageRotationOffset = rotationOffset;
|
|
}
|
|
|
|
public void ResetFlipAndRotation() {
|
|
_CameraAgent.ResetFlipAndRotation(CamConfig.FlipAndRotation.Clone() as FlipAndRotation);
|
|
}
|
|
|
|
public void EditChildImage(object o) {
|
|
var camConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(_CamId.ToString()) as CamConfig;
|
|
CamConfig = camConfig.Clone();
|
|
|
|
ChildImageSettingWindow.Instance?.Show(_FovInfo, _CameraDisplay);
|
|
}
|
|
|
|
public void Reload(object o) {
|
|
var camConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(_CamId.ToString()) as CamConfig;
|
|
CamConfig = camConfig.Clone();
|
|
|
|
_CameraAgent.ResetFlipAndRotation(CamConfig.FlipAndRotation.Clone() as FlipAndRotation);
|
|
}
|
|
|
|
public void Save(object o) {
|
|
var camConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(_CamId.ToString()) as CamConfig;
|
|
camConfig.FlipAndRotation.ImageFlip = CamConfig.FlipAndRotation.ImageFlip;
|
|
camConfig.FlipAndRotation.ImageRotation = CamConfig.FlipAndRotation.ImageRotation;
|
|
camConfig.FlipAndRotation.ImageRotationOffset = CamConfig.FlipAndRotation.ImageRotationOffset;
|
|
camConfig.ExposureTime_Ms = CamConfig.ExposureTime_Ms;
|
|
|
|
_CameraAgent.ResetFlipAndRotation(camConfig.FlipAndRotation.Clone() as FlipAndRotation);
|
|
VisionEnv.AuroraEnv.DeviceManager.SaveDeviceConfig(_CamId.ToString());
|
|
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
|
|
}
|
|
|
|
public void Close(object o) {
|
|
Reload(null);
|
|
|
|
var window = o as Window;
|
|
if (window != null) {
|
|
window.Close();
|
|
}
|
|
}
|
|
|
|
public void Dispose() {
|
|
RemoveObservable();
|
|
}
|
|
|
|
private void RemoveObservable() {
|
|
_EventDisposable?.Dispose();
|
|
_EventDisposable = null;
|
|
}
|
|
}
|
|
}
|