170 lines
6.3 KiB
C#
170 lines
6.3 KiB
C#
using Aurora;
|
|
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using VisionCommonUI.Resources;
|
|
using VisionCommonUI;
|
|
|
|
namespace VisionUI.Setup {
|
|
/// <summary>
|
|
/// 서브메뉴 : 오토포커스 뷰
|
|
/// SubMenuAutoFocusView.xaml behind code
|
|
/// </summary>
|
|
public partial class SubMenuAutoFocusView : UserControl {
|
|
private static readonly Logger _Logger = new Logger("SubMenuAutoFocusView");
|
|
private IDisposable _EventDisposable;
|
|
|
|
private bool _IsViewInitialized = false;
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
public SubMenuAutoFocusView() {
|
|
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(() => {
|
|
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.AutoFocusRecipe == null) {
|
|
continue;
|
|
}
|
|
|
|
var fovTabItem = new TabItem() {
|
|
Header = fovRecipe.FovName,
|
|
TabIndex = tabIdx++,
|
|
Content = CreateAutoFocusView(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 AutoFocusView CreateAutoFocusView(FovInfo fovInfo) {
|
|
var autoFocusView = new AutoFocusView(fovInfo);
|
|
var autoFocusViewModel = new AutoFocusViewModel(fovInfo);
|
|
autoFocusView.DataContext = autoFocusViewModel;
|
|
|
|
return autoFocusView;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|