195 lines
7.6 KiB
C#
195 lines
7.6 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Reactive.Linq;
|
|
using DevExpress.Data.Extensions;
|
|
|
|
namespace VisionUI.Camera {
|
|
/// <summary>
|
|
/// 카메라 Usercontrol 매니저
|
|
/// </summary>
|
|
public class CameraUcManager {
|
|
private static Logger _Logger = new Logger("CameraUcManager");
|
|
private static object LockObj = new object();
|
|
|
|
private static CameraUcManager _instance = null;
|
|
/// <summary>
|
|
/// 싱글톤 패턴 객체
|
|
/// </summary>
|
|
public static CameraUcManager Instance {
|
|
get {
|
|
lock (LockObj) {
|
|
if (_instance == null) {
|
|
_instance = new CameraUcManager();
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
}
|
|
|
|
private CameraUcManager() {
|
|
SetObservable();
|
|
}
|
|
|
|
private void SetObservable() {
|
|
VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.SHOW_FOV_CAMERA_VIEW_WINDOW).
|
|
Subscribe(msg => ShowFovCameraViewWindow(msg));
|
|
|
|
var observable = VisionEventId.GetRecipeActivatedObservable();
|
|
observable.Subscribe(_ => CloseFovCameraViewWindows());
|
|
}
|
|
|
|
private void ShowFovCameraViewWindow(EventMessage msg) {
|
|
FovCameraViewWindowParam fovCameraViewWindowParam = msg.Param as FovCameraViewWindowParam;
|
|
ShowFovCameraViewWindow(fovCameraViewWindowParam.fovInfo, fovCameraViewWindowParam.displayType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 개별 카메라 뷰 윈도우 띄우기
|
|
/// </summary>
|
|
///
|
|
public void ShowFovCameraViewWindow(FovInfo fovInfo, eDisplayType displayType) {
|
|
try {
|
|
CamViewWindowUtil.SetFovCamViewWindowActivated(fovInfo, displayType, true);
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
var cameraViewWindow = new CameraViewWindow(fovInfo, displayType);
|
|
cameraViewWindow.Title = CamViewWindowUtil.GetFovCamViewWindowTitle(fovInfo, displayType);
|
|
cameraViewWindow?.Show();
|
|
cameraViewWindow.Activate();
|
|
}));
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 떠있는 개별 카메라 뷰 모두 닫기
|
|
/// </summary>
|
|
public void CloseFovCameraViewWindows() {
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
foreach (Window window in Application.Current.Windows) {
|
|
if (window.Title.Contains(VisionKeys.Title_FovCameraViewWindow)) {
|
|
window.Close();
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 메인 카메라 윈도우 보여주기
|
|
/// </summary>
|
|
public void ShowMainCameraViewWindow() {
|
|
try {
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new Action(() => {
|
|
if (!MainCameraViewWindow.Instance.IsVisible) {
|
|
System.Windows.Forms.Screen Monitor = System.Windows.Forms.Screen.AllScreens.Where(s => s.Primary).FirstOrDefault();
|
|
if (VisionSettingManager.VisionSetting.SetPopupMonitor != eMonitor.Primary_MainMonitor) {
|
|
// SubMonitor - Not Primary
|
|
if (VisionSettingManager.VisionSetting.SetPopupMonitor == eMonitor.NotPrimary_SubMonitor) {
|
|
Monitor = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).FirstOrDefault() ?? Monitor;
|
|
}
|
|
// SelectMonitor
|
|
else {
|
|
System.Windows.Forms.Screen.AllScreens.ToList().TryGetValue((int)VisionSettingManager.VisionSetting.SetPopupMonitor, out System.Windows.Forms.Screen findMonitor);
|
|
Monitor = findMonitor ?? Monitor;
|
|
}
|
|
}
|
|
|
|
if (Monitor != null) {
|
|
var workingArea = Monitor.WorkingArea;
|
|
MainCameraViewWindow.Instance.WindowStartupLocation = WindowStartupLocation.Manual;
|
|
MainCameraViewWindow.Instance.WindowState = WindowState.Normal;
|
|
MainCameraViewWindow.Instance.Left = workingArea.Left;
|
|
MainCameraViewWindow.Instance.Top = workingArea.Top;
|
|
MainCameraViewWindow.Instance.WindowState = WindowState.Maximized;
|
|
}
|
|
|
|
MainCameraViewWindow.Instance?.Show();
|
|
MainCameraViewWindow.Instance.Activate();
|
|
}
|
|
else {
|
|
if (!MainCameraViewWindow.Instance.IsActive) {
|
|
MainCameraViewWindow.Instance.Activate();
|
|
}
|
|
}
|
|
}));
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
#region 카메라 라이브 On/Off
|
|
/// <summary>
|
|
/// 카메라 라이브 전체 켜기
|
|
/// </summary>
|
|
/// <param name="displayType">라이브 전체 On시킬 디스플레이 타입</param>
|
|
public void StartLiveAll(eDisplayType displayType) {
|
|
try {
|
|
foreach (FovInfo fovInfo in VisionRecipeManager.GetFovInfos()) {
|
|
StartLive(fovInfo, displayType);
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카메라 라이브 전체 끄기
|
|
/// </summary>
|
|
public void StopLiveAll() {
|
|
try {
|
|
foreach (FovInfo fovInfo in VisionRecipeManager.GetFovInfos()) {
|
|
StopLive(fovInfo);
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카메라 라이브 켜기
|
|
/// </summary>
|
|
/// <param name="fovInfo">FOV 정보</param>
|
|
/// <param name="displayType">디스플레이 유형</param>
|
|
public void StartLive(FovInfo fovInfo, eDisplayType displayType) {
|
|
try {
|
|
var camAgent = CameraAgentManager.GetCameraAgent(fovInfo);
|
|
var camDisplay = CameraDisplayManager.GetDisplay(fovInfo, displayType);
|
|
|
|
if (camAgent != null && !camAgent.IsLiveRunning()) {
|
|
camAgent.StartLive(camDisplay);
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 카메라 라이브 중지
|
|
/// </summary>
|
|
/// <param name="fovInfo">FOV 정보</param>
|
|
public void StopLive(FovInfo fovInfo) {
|
|
var camAgent = CameraAgentManager.GetCameraAgent(fovInfo);
|
|
|
|
if (camAgent != null && camAgent.IsLiveRunning()) {
|
|
camAgent.StopLive();
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
} |