131 lines
4.6 KiB
C#
131 lines
4.6 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using DevExpress.Xpf.Charts;
|
|
using VisionCommon;
|
|
using VisionSequence.Setup;
|
|
using System.Reactive.Linq;
|
|
using System.Reactive.Disposables;
|
|
|
|
namespace VisionUI.Setup {
|
|
/// <summary>
|
|
/// 오토포커스 뷰
|
|
/// AutoFocusView.xaml behind code
|
|
/// </summary>
|
|
public partial class AutoFocusView : UserControl, IUpdateRecipe, IDisposable {
|
|
private static Logger _Logger;
|
|
|
|
private FovInfo _FovInfo;
|
|
private FovRecipe _FovRecipe;
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="fovInfo">Fov 정보</param>
|
|
public AutoFocusView(FovInfo fovInfo) {
|
|
_FovInfo = fovInfo;
|
|
_FovRecipe = VisionRecipeManager.GetFovRecipe(_FovInfo);
|
|
_Logger = new Logger($"AutoFocusView[{_FovInfo.SubSysName}][{_FovRecipe.FovName}]");
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Init() {
|
|
CreateCameraView();
|
|
SetObservable();
|
|
}
|
|
|
|
private void CreateCameraView() {
|
|
var cameraView = IpViewManager.CreateCameraView(_FovInfo, eDisplayType.AutoFocus);
|
|
gridCameraView.Children.Add(cameraView);
|
|
}
|
|
|
|
private void SetObservable() {
|
|
var disposable = VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.UPDATE_AUTO_FOCUS_BEST_POS).
|
|
Where(x => x.From == _FovInfo.GetKey()).Subscribe(autoFocusLog => UpdateAutoFocusBestPos(autoFocusLog));
|
|
DisposableManager.AddDisposable(eDpsGroupKey.SubMenu_AutoFocus, disposable);
|
|
}
|
|
/// <summary>
|
|
/// 오토포커스를 최선의 위치로 업데이트 (비동기)
|
|
/// </summary>
|
|
/// <param name="msg">이벤트 메세지</param>
|
|
public void UpdateAutoFocusBestPos(EventMessage msg) {
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new Action(() => {
|
|
try {
|
|
var autoFocusLog = msg.Param as AutoFocusLog;
|
|
dataGridAutoFocus.SelectedIndex = autoFocusLog.Step - 1;
|
|
|
|
XYDiagram2D diagram = (XYDiagram2D)graphAutoFocus.Diagram;
|
|
AxisX2D axisX = new AxisX2D();
|
|
AxisY2D axisY = new AxisY2D();
|
|
diagram.AxisX = axisX;
|
|
diagram.AxisY = axisY;
|
|
|
|
ConstantLine constantLineX = new ConstantLine() {
|
|
Value = autoFocusLog.Step,
|
|
};
|
|
axisX.ConstantLinesBehind.Add(constantLineX);
|
|
|
|
ConstantLine constantLineY = new ConstantLine() {
|
|
Value = autoFocusLog.Sharpness,
|
|
};
|
|
axisY.ConstantLinesBehind.Add(constantLineY);
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}));
|
|
}
|
|
|
|
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
|
|
bool isVisible = (bool)e.NewValue;
|
|
if (isVisible == true) {
|
|
RefreshVisionRecipes();
|
|
Init();
|
|
(DataContext as AutoFocusViewModel).LoadCsvNow();
|
|
}
|
|
else {
|
|
ISequence seq = VisionEnv.AuroraEnv.SequenceEntry[VisionKeys.AutoFocusSeqKey];
|
|
if (seq != null) {
|
|
if (seq.RunState != SequenceRunState.Idle) {
|
|
seq.EmergencyStop();
|
|
}
|
|
}
|
|
Dispose();
|
|
}
|
|
}
|
|
|
|
public void RefreshVisionRecipes() {
|
|
_FovInfo = VisionRecipeManager.GetFovInfo(_FovInfo);
|
|
(DataContext as AutoFocusViewModel).RefreshVisionRecipes();
|
|
}
|
|
|
|
public void UpdateRecipeFromFile() {
|
|
(DataContext as AutoFocusViewModel).UpdateRecipeFromFile();
|
|
}
|
|
|
|
public void UpdateRecipeFromUI() {
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#region Dispose
|
|
public void Dispose() {
|
|
RemoveCameraView();
|
|
}
|
|
|
|
private void RemoveCameraView() {
|
|
foreach (var child in gridCameraView.Children) {
|
|
if (child is UserControl view) {
|
|
IpViewManager.DisposeCameraView(view);
|
|
}
|
|
}
|
|
gridCameraView.Children.Clear();
|
|
}
|
|
#endregion
|
|
}
|
|
} |