207 lines
7.1 KiB
C#
207 lines
7.1 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using VisionCommon;
|
|
using System.Windows.Controls;
|
|
using System;
|
|
using Aurora.Api;
|
|
using VisionCommonUI;
|
|
using VisionCommonUI.Resources;
|
|
using System.Windows;
|
|
|
|
namespace VisionUI.Setup {
|
|
/// <summary>
|
|
/// 센터 튜닝 뷰
|
|
/// CenterTuningView.xaml behind code
|
|
/// </summary>
|
|
public partial class CenterTuningView : UserControl, IUpdateRecipe, IDisposable {
|
|
private SubSysInfo _SubSysInfo;
|
|
private SubSysRecipe _SubSysRecipe;
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="subSysInfo">서브시스템 정보</param>
|
|
public CenterTuningView(SubSysInfo subSysInfo) {
|
|
_SubSysInfo = subSysInfo;
|
|
_SubSysRecipe = VisionRecipeManager.GetSubSysRecipe(subSysInfo);
|
|
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Init() {
|
|
if (VisionRecipeManager.GetFovCnt(_SubSysInfo) == 1) {
|
|
CreateCameraView_Single();
|
|
}
|
|
else {
|
|
CreateCameraView_Multi();
|
|
}
|
|
|
|
CreateCenterTuningLogView();
|
|
CreateCenterTuningSettingView();
|
|
}
|
|
|
|
private void CreateCameraView_Single() {
|
|
var fovInfo = new FovInfo(_SubSysInfo, eFovId.Fov1);
|
|
var cameraView = IpViewManager.CreateCameraView(fovInfo, eDisplayType.CenterTuning);
|
|
gridCameraView.Children.Add(cameraView);
|
|
}
|
|
|
|
private void CreateCameraView_Multi() {
|
|
// Create 2x2 grid
|
|
var grid = new Grid();
|
|
var rowDef1 = new RowDefinition();
|
|
var rowDef2 = new RowDefinition();
|
|
var colDef1 = new ColumnDefinition();
|
|
var colDef2 = new ColumnDefinition();
|
|
|
|
grid.RowDefinitions.Add(rowDef1);
|
|
grid.RowDefinitions.Add(rowDef2);
|
|
grid.ColumnDefinitions.Add(colDef1);
|
|
grid.ColumnDefinitions.Add(colDef2);
|
|
|
|
var fovInfos = VisionRecipeManager.GetFovInfos(_SubSysInfo);
|
|
foreach (var fovInfo in fovInfos) {
|
|
var cameraView = IpViewManager.CreateCameraView(fovInfo, eDisplayType.CenterTuning);
|
|
|
|
switch (fovInfo.FovId) {
|
|
case eFovId.Fov1:
|
|
Grid.SetRow(cameraView, 0);
|
|
Grid.SetColumn(cameraView, 0);
|
|
break;
|
|
case eFovId.Fov2:
|
|
Grid.SetRow(cameraView, 0);
|
|
Grid.SetColumn(cameraView, 1);
|
|
break;
|
|
case eFovId.Fov3:
|
|
Grid.SetRow(cameraView, 1);
|
|
Grid.SetColumn(cameraView, 0);
|
|
break;
|
|
case eFovId.Fov4:
|
|
Grid.SetRow(cameraView, 1);
|
|
Grid.SetColumn(cameraView, 1);
|
|
break;
|
|
}
|
|
|
|
grid.Children.Add(cameraView);
|
|
}
|
|
|
|
if (fovInfos.Count == 0 || grid.Children.Count < fovInfos.Count) {
|
|
PrintRecipeError(typeof(FovRecipe).Name, gridCameraView);
|
|
}
|
|
else {
|
|
gridCameraView.Children.Add(grid);
|
|
}
|
|
}
|
|
|
|
private void CreateCenterTuningLogView() {
|
|
var centerTuningLogView = new CenterTuningLogView(_SubSysInfo);
|
|
gridCenterTuningLogView.Children.Add(centerTuningLogView);
|
|
}
|
|
|
|
private void CreateCenterTuningSettingView() {
|
|
var centerTuningSettingView = new CenterTuningSettingView(_SubSysInfo);
|
|
gridCenterTuningSettingView.Children.Add(centerTuningSettingView);
|
|
}
|
|
|
|
private void PrintRecipeError(string recipeName, Grid grid) {
|
|
var errMsg = string.Format(StrTokens.RecipeErrorMessage, recipeName);
|
|
grid.Children.Add(new UCRecipeErrorTextBlock(errMsg) { Margin = new Thickness(15) });
|
|
grid.VerticalAlignment = VerticalAlignment.Center;
|
|
grid.HorizontalAlignment = HorizontalAlignment.Center;
|
|
}
|
|
|
|
private void UserControl_IsVisibleChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e) {
|
|
bool isVisible = (bool)e.NewValue;
|
|
if (isVisible == true) {
|
|
RefreshVisionRecipes();
|
|
Init();
|
|
(DataContext as CenterTuningViewModel).CenterTuningLogViewModel.LoadCsvNow();
|
|
}
|
|
else {
|
|
ISequence seq = VisionEnv.AuroraEnv.SequenceEntry[VisionKeys.CenterTuningSeqKey];
|
|
if (seq != null) {
|
|
if (seq.RunState != SequenceRunState.Idle) {
|
|
seq.EmergencyStop();
|
|
}
|
|
}
|
|
Dispose();
|
|
}
|
|
}
|
|
|
|
public void RefreshVisionRecipes() {
|
|
_SubSysInfo = VisionRecipeManager.GetSubSysInfo(_SubSysInfo);
|
|
}
|
|
|
|
public void UpdateRecipeFromFile() {
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
public void UpdateRecipeFromUI() {
|
|
throw new System.NotImplementedException();
|
|
}
|
|
|
|
#region Dispose
|
|
public void Dispose() {
|
|
CheckRecipeErrorGrid(gridCameraView);
|
|
|
|
if (VisionRecipeManager.GetFovCnt(_SubSysInfo) == 1) {
|
|
RemoveCameraView_Single();
|
|
}
|
|
else {
|
|
RemoveCameraView_Multi();
|
|
}
|
|
|
|
RemoveCenterTuningLogView();
|
|
RemoveCenterTuningSettingView();
|
|
}
|
|
|
|
private void CheckRecipeErrorGrid(Grid grid) {
|
|
if (grid.Children.Count == 1) {
|
|
if (grid.Children[0] is UCRecipeErrorTextBlock) {
|
|
grid.Children.Clear();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RemoveCameraView_Single() {
|
|
foreach (var child in gridCameraView.Children) {
|
|
if (child is UserControl view) {
|
|
IpViewManager.DisposeCameraView(view);
|
|
}
|
|
}
|
|
gridCameraView.Children.Clear();
|
|
}
|
|
|
|
private void RemoveCameraView_Multi() {
|
|
foreach (Grid child in gridCameraView.Children) {
|
|
foreach (var innerChild in child.Children) {
|
|
if (innerChild is UserControl view) {
|
|
IpViewManager.DisposeCameraView(view);
|
|
}
|
|
}
|
|
child.Children.Clear();
|
|
}
|
|
gridCameraView.Children.Clear();
|
|
}
|
|
|
|
private void RemoveCenterTuningLogView() {
|
|
foreach (var child in gridCenterTuningLogView.Children) {
|
|
if (child is CenterTuningLogView view) {
|
|
view = null;
|
|
}
|
|
}
|
|
gridCenterTuningLogView.Children.Clear();
|
|
}
|
|
|
|
private void RemoveCenterTuningSettingView() {
|
|
foreach (var child in gridCenterTuningSettingView.Children) {
|
|
if (child is CenterTuningSettingView view) {
|
|
view = null;
|
|
}
|
|
}
|
|
gridCenterTuningSettingView.Children.Clear();
|
|
}
|
|
#endregion
|
|
}
|
|
} |