158 lines
6.0 KiB
C#
158 lines
6.0 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using VisionCommon;
|
|
using System;
|
|
using VisionCommonUI.Resources;
|
|
using VisionCommonUI;
|
|
|
|
namespace VisionUI.ProcTest {
|
|
/// <summary>
|
|
/// SubMenuProcTestView.xaml에 대한 상호 작용 논리
|
|
/// </summary>
|
|
public partial class SubMenuProcTestView : UserControl {
|
|
private enum eTabType {
|
|
MaterialTolerance, // 자재 공차 변화에 다른 얼라인 보정량 테스트
|
|
}
|
|
|
|
private static readonly Logger _Logger = new Logger(typeof(SubMenuProcTestView).Name);
|
|
private IDisposable _EventDisposable;
|
|
|
|
private bool _IsViewInitialized = false;
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
public SubMenuProcTestView() {
|
|
InitializeComponent();
|
|
SetObservable();
|
|
}
|
|
|
|
private void SetObservable() {
|
|
if (_EventDisposable == null) {
|
|
var observable = VisionEventId.GetRecipeUpdateObservable();
|
|
_EventDisposable = observable.Subscribe(_ => ClearView());
|
|
}
|
|
}
|
|
|
|
private void ClearView() {
|
|
if (IsVisible) {
|
|
return;
|
|
}
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new System.Action(() => {
|
|
subMenuProcTestTabControl.Items.Clear();
|
|
_IsViewInitialized = false;
|
|
}));
|
|
}
|
|
|
|
private void InitializeView() {
|
|
foreach (eTabType tabType in Enum.GetValues(typeof(eTabType))) {
|
|
var tabItem = new TabItem();
|
|
tabItem.Header = tabType.ToString();
|
|
tabItem.Style = FindResource("styleSubMenuRootTabItem") as Style;
|
|
|
|
switch (tabType) {
|
|
case eTabType.MaterialTolerance:
|
|
tabItem.Content = GetUnitTabControl(tabType);
|
|
break;
|
|
}
|
|
subMenuProcTestTabControl.Items.Add(tabItem);
|
|
}
|
|
subMenuProcTestTabControl.SelectedIndex = 0;
|
|
_IsViewInitialized = true;
|
|
}
|
|
|
|
private TabControl GetUnitTabControl(eTabType tabType) {
|
|
var unitTabControl = new TabControl();
|
|
unitTabControl.Style = FindResource("styleSubMenuRootTabControl") as Style;
|
|
unitTabControl.Margin = new System.Windows.Thickness(10, 0, 0, 0);
|
|
|
|
var unitInfos = VisionRecipeManager.GetUnitInfos();
|
|
foreach (UnitInfo unitInfo in unitInfos) {
|
|
var unitTabItem = new TabItem() {
|
|
Header = unitInfo.UnitName,
|
|
Content = GetSubSystemTabControl(unitInfo, tabType)
|
|
};
|
|
unitTabItem.Style = FindResource("styleSubMenuRootTabItem") as Style;
|
|
unitTabControl.Items.Add(unitTabItem);
|
|
}
|
|
|
|
if (unitInfos.Count == 0 || unitTabControl.Items.Count < unitInfos.Count) {
|
|
PrintRecipeError(typeof(UnitRecipe).Name, unitTabControl);
|
|
}
|
|
return unitTabControl;
|
|
}
|
|
|
|
private TabControl GetSubSystemTabControl(UnitInfo unitInfo, eTabType tabType) {
|
|
try {
|
|
var subSystemTabControl = new TabControl();
|
|
subSystemTabControl.Style = FindResource("styleSubMenuRootTabControl") as Style;
|
|
subSystemTabControl.Margin = new System.Windows.Thickness(10, 0, 0, 0);
|
|
|
|
var subSysInfos = VisionRecipeManager.GetSubSysInfos(unitInfo.UnitId);
|
|
foreach (SubSysInfo subSysInfo in subSysInfos) {
|
|
if (VisionRecipeManager.GetSubSysType(subSysInfo) != eSubSysType.Align) {
|
|
continue;
|
|
}
|
|
|
|
var subSystemTabItem = new TabItem() {
|
|
Header = subSysInfo.SubSysName,
|
|
Content = CreateProcTestView(subSysInfo, tabType)
|
|
};
|
|
subSystemTabItem.Style = FindResource("styleSubMenuRootTabItem") as Style;
|
|
subSystemTabControl.Items.Add(subSystemTabItem);
|
|
}
|
|
|
|
if (subSysInfos.Count == 0) {
|
|
PrintRecipeError(typeof(SubSysRecipe).Name, subSystemTabControl);
|
|
}
|
|
|
|
return subSystemTabControl;
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private UserControl CreateProcTestView(SubSysInfo subSysInfo, eTabType tabType) {
|
|
switch (tabType) {
|
|
case eTabType.MaterialTolerance:
|
|
var materialToleranceTestView = new MaterialToleranceTestView(subSysInfo);
|
|
var materialToleranceTestViewModel = new MaterialToleranceTestViewModel(subSysInfo);
|
|
materialToleranceTestView.DataContext = materialToleranceTestViewModel;
|
|
|
|
return materialToleranceTestView;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void PrintRecipeError(string recipeName, TabControl tabControl) {
|
|
var errMsg = string.Format(StrTokens.RecipeErrorMessage, recipeName);
|
|
var errTabItem = new TabItem() {
|
|
Header = "Undefined",
|
|
Content = new UCRecipeErrorTextBlock(errMsg) { Margin = new Thickness(15) }
|
|
};
|
|
errTabItem.Style = FindResource("styleSubMenuRootTabItem") as Style;
|
|
errTabItem.VerticalContentAlignment = VerticalAlignment.Center;
|
|
errTabItem.HorizontalContentAlignment = HorizontalAlignment.Center;
|
|
tabControl.Items.Add(errTabItem);
|
|
}
|
|
|
|
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
|
|
bool isVisible = (bool)e.NewValue;
|
|
if (isVisible == true) {
|
|
if (!_IsViewInitialized) {
|
|
InitializeView();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|