121 lines
3.8 KiB
C#
121 lines
3.8 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora;
|
|
using Aurora.View;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using VisionCommon;
|
|
using VisionCommonUI;
|
|
using VisionCommonUI.Resources;
|
|
|
|
namespace VisionUI.Layout {
|
|
|
|
class CamLayoutSettingViewModel : NotifyPropertyChangedBase {
|
|
/// <summary>
|
|
/// Visible 변경 Command
|
|
/// </summary>
|
|
public ICommand CMD_VisibleChanged { get; }
|
|
/// <summary>
|
|
/// 저장 Command
|
|
/// </summary>
|
|
public ICommand CMD_Save { get; }
|
|
|
|
private bool _isActivated;
|
|
/// <summary>
|
|
/// 활성화 여부
|
|
/// 활성화 여부에 따라 카메라 디바이스 Active
|
|
/// </summary>
|
|
public bool IsActivated {
|
|
get => _isActivated;
|
|
set {
|
|
SetProperty(ref _isActivated, value);
|
|
ActivateDevice(_isActivated);
|
|
}
|
|
}
|
|
|
|
private eCoordSysType _camCoordSysType;
|
|
/// <summary>
|
|
/// 카메라 좌표계 시스템 타입
|
|
/// </summary>
|
|
public eCoordSysType CamCoordSysType { get => _camCoordSysType; set { SetProperty(ref _camCoordSysType, value); } }
|
|
|
|
private string _camId;
|
|
private CameraBase _camDev;
|
|
private bool _initialIsActivated;
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="camId">캠 Id</param>
|
|
public CamLayoutSettingViewModel(string camId) {
|
|
_camId = camId;
|
|
_camDev = VisionEnv.AuroraEnv.DeviceManager[_camId] as CameraBase;
|
|
if (_camDev != null) {
|
|
_initialIsActivated = _camDev.IsActivated;
|
|
}
|
|
|
|
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
|
|
CMD_Save = new DelegateCommand(Save);
|
|
|
|
UpdateRecipe();
|
|
UpdateDeivceStatus();
|
|
}
|
|
|
|
private void VisibleChanged(object obj) {
|
|
bool visible = (bool)obj;
|
|
if (visible) {
|
|
UpdateRecipe();
|
|
UpdateDeivceStatus();
|
|
}
|
|
else {
|
|
if (_initialIsActivated && !IsActivated) {
|
|
IsActivated = true;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 레시피 업데이트
|
|
/// </summary>
|
|
public void UpdateRecipe() {
|
|
var deviceConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(_camId) as CamConfig;
|
|
if (deviceConfig != null) {
|
|
CamCoordSysType = CoordSystem.ToCoordSysType(
|
|
Angle.CreateWithDegree(deviceConfig.SetupDirection.RotationX),
|
|
deviceConfig.SetupDirection.FlipY);
|
|
}
|
|
}
|
|
|
|
private void UpdateDeivceStatus() {
|
|
if (_camDev != null) {
|
|
IsActivated = _camDev.IsActivated;
|
|
}
|
|
}
|
|
|
|
private void ActivateDevice(bool activate) {
|
|
if (activate) {
|
|
_camDev?.Activate();
|
|
}
|
|
else {
|
|
_camDev?.Deactivate();
|
|
}
|
|
}
|
|
|
|
private void Save(object obj) {
|
|
var deviceConfig = VisionEnv.AuroraEnv.DeviceManager.GetDeviceConfig(_camId) as CamConfig;
|
|
var rotationX = CoordSystem.GetRotationX(CamCoordSysType);
|
|
deviceConfig.SetupDirection.RotationX = (int)rotationX.Degree;
|
|
deviceConfig.SetupDirection.FlipY = CoordSystem.GetFlipY(CamCoordSysType);
|
|
VisionEnv.AuroraEnv.DeviceManager.SaveDeviceConfig(_camId);
|
|
IsActivated = true;
|
|
|
|
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
|
|
}
|
|
}
|
|
}
|