/* * Copyright (c) 2025 LG Electronics Inc. * SPDX-License-Identifier: LicenseRef-LGE-Proprietary */ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Aurora; using Aurora.Api; using VisionCommon; using VisionCommonUI; using VisionCommonUI.Resources; namespace VisionUI.Setup { /// /// Interaction logic for SubMenuVisionRepeatView.xaml /// public partial class SubMenuVisionRepeatView : UserControl { private static readonly Logger _Logger = new Logger("SubMenuVisionRepeatView"); private IDisposable _EventDisposable; private bool _IsViewInitialized = false; /// /// 생성자 /// public SubMenuVisionRepeatView() { 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(() => { DisposableManager.ClearDisposable(eDpsGroupKey.SubMenu_VisionRepeat); unitTabControl.Items.Clear(); _IsViewInitialized = false; })); } private void InitializeView() { int tabIdx = 0; var uinitInfos = VisionRecipeManager.GetUnitInfos(); foreach (UnitInfo unitInfo in uinitInfos) { var unitTabItem = new TabItem() { Header = unitInfo.UnitName, TabIndex = tabIdx++, Content = GetSubSystemTabControl(unitInfo.UnitId) }; unitTabItem.Style = FindResource("styleSubMenuRootTabItem") as Style; unitTabControl.Items.Add(unitTabItem); } unitTabControl.SelectedIndex = 0; _IsViewInitialized = true; if (unitTabControl.Items.Count == 0 || unitTabControl.Items.Count < uinitInfos.Count) { PrintRecipeError(typeof(UnitRecipe).Name, unitTabControl); } } private TabControl GetSubSystemTabControl(eUnitId unitId) { try { var subSystemTabControl = new TabControl(); subSystemTabControl.Style = FindResource("styleSubMenuRootTabControl") as Style; subSystemTabControl.Margin = new System.Windows.Thickness(10, 0, 0, 0); int tabIdx = 0; var subSysInfos = VisionRecipeManager.GetSubSysInfos(unitId); foreach (var subSysInfo in subSysInfos) { if (VisionRecipeManager.GetSubSysType(subSysInfo) == eSubSysType.Review) { continue; } var subSystemTabItem = new TabItem() { Header = subSysInfo.SubSysName, TabIndex = tabIdx++, Content = GetFovTabControl(subSysInfo) }; subSystemTabItem.Style = FindResource("styleSubMenuRootTabItem") as Style; subSystemTabControl.Items.Add(subSystemTabItem); } if (subSystemTabControl.Items.Count == 0) { PrintRecipeError(typeof(SubSysRecipe).Name, subSystemTabControl); } return subSystemTabControl; } catch (Exception e) { _Logger.FuncE(e.Message); } return null; } private TabControl GetFovTabControl(SubSysInfo subSysInfo) { try { var fovTabControl = new TabControl(); fovTabControl.Style = FindResource("styleSubMenuRootTabControl") as Style; fovTabControl.Margin = new System.Windows.Thickness(10, 0, 0, 0); int tabIdx = 0; var fovInfos = VisionRecipeManager.GetFovInfos(subSysInfo); foreach (var fovInfo in fovInfos) { var fovRecipe = VisionRecipeManager.GetFovRecipe(fovInfo); if (fovRecipe.FovSetupRecipe.VisionRepeatRecipe == null) { continue; } var fovTabItem = new TabItem() { Header = fovRecipe.FovName, TabIndex = tabIdx++, Content = CreateVisionRepeatView(fovInfo) }; fovTabItem.Style = FindResource("styleSubMenuRootTabItem") as Style; fovTabControl.Items.Add(fovTabItem); } if (fovTabControl.Items.Count == 0 || fovTabControl.Items.Count < fovInfos.Count) { PrintRecipeError(typeof(FovSetupRecipe).Name, fovTabControl); } return fovTabControl; } catch (Exception e) { _Logger.FuncE(e.Message); } return null; } private VisionRepeatView CreateVisionRepeatView(FovInfo fovInfo) { var visionRepeatView = new VisionRepeatView(fovInfo); var visionRepeatViewModel = new VisionRepeatViewModel(fovInfo); visionRepeatView.DataContext = visionRepeatViewModel; return visionRepeatView; } 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(); } } } } }