Kyungshin-Welder/AuroraVision/VisionCommonUI/Light/Camera/CameraLightSettingView.xaml.cs
2026-01-26 14:51:28 +09:00

205 lines
8.4 KiB
C#

/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora.Api;
using VisionCommon;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using VisionLight;
namespace VisionCommonUI {
public partial class CameraLightSettingView : UserControl {
private Logger _Logger = new Logger(typeof(CameraLightSettingView).Name);
private FovInfo _FovInfo;
private Dictionary<LightIndex, CameraLightSettingViewEachCh> _LightSettingViewEachChs = new Dictionary<LightIndex, CameraLightSettingViewEachCh>();
private List<LightConfigInfo> _LightConfigInfos = new List<LightConfigInfo>();
public CameraLightSettingView(FovInfo fovInfo) {
if (fovInfo == null) {
_Logger.FuncE("fovInfo is null.");
return;
}
InitializeComponent();
_FovInfo = fovInfo;
var fovRecipe = VisionRecipeManager.GetFovRecipe(_FovInfo);
_LightConfigInfos = LightHub.Instance.GetLightConfigInfo(fovRecipe.CamRecipe.CamId);
CreateView();
}
private void CreateView() {
try {
tbLightSettingHeader.Text = VisionRecipeManager.GetDisplayName(_FovInfo.SubSysName, _FovInfo.FovName);
var gbLightIds = new Dictionary<eLightId, GroupBox>();
foreach (var lightConfigInfo in _LightConfigInfos) {
var chTypeName = lightConfigInfo.ChConfig.DeviceType.ToString();
var lightSettingViewEachCh = new CameraLightSettingViewEachCh(_FovInfo, lightConfigInfo);
LightIndex lightIndex = new LightIndex();
lightIndex.LightId = lightConfigInfo.LightId;
lightIndex.Ch = lightConfigInfo.ChConfig.Ch;
if (!_LightSettingViewEachChs.ContainsKey(lightIndex))
_LightSettingViewEachChs.Add(lightIndex, lightSettingViewEachCh);
if (!gbLightIds.ContainsKey(lightConfigInfo.LightId)) {
var gb = new GroupBox();
gb.Header = lightConfigInfo.LightId.ToString();
gb.Foreground = Brushes.White;
gb.Style = FindResource("AVDefaultGB") as Style;
gb.FontSize = 17;
gb.FontWeight = FontWeights.Bold;
gb.Padding = new Thickness(0, 0, 0, 5);
gbLightIds.Add(lightConfigInfo.LightId, gb);
}
}
foreach(var gbLightId in gbLightIds) {
var spLightId = new StackPanel();
spLightId.Orientation = Orientation.Vertical;
var gbs = new Dictionary<string, GroupBox>();
foreach (var lightConfigInfo in _LightConfigInfos) {
var chTypeName = lightConfigInfo.ChConfig.DeviceType.ToString();
if (!gbs.ContainsKey(chTypeName)) {
var gb = new GroupBox();
gb.Header = chTypeName;
gb.Foreground = Brushes.White;
gb.Style = FindResource("AVDefaultGB") as Style;
gb.FontSize = 17;
gb.FontWeight = FontWeights.Bold;
gbs.Add(chTypeName, gb);
}
}
foreach (var gb in gbs) {
var spInside = new StackPanel();
spInside.Orientation = Orientation.Vertical;
foreach (var view in _LightSettingViewEachChs) {
if (view.Value.GetLightType().ToString() == gb.Key && view.Key.LightId == gbLightId.Key)
spInside.Children.Add(view.Value);
}
if (spInside.Children.Count == 0)
continue;
gb.Value.Content = spInside;
spLightId.Children.Add(gb.Value);
}
if (spLightId.Children.Count == 0)
continue;
gbLightId.Value.Content = spLightId;
stackPanelLightSettingView.Children.Add(gbLightId.Value);
}
}
catch (Exception e) {
_Logger.FuncE(e.Message);
}
}
private void OnAllLightOnButtonClicked(object sender, RoutedEventArgs e) {
try {
foreach (var lightConfigInfo in _LightConfigInfos) {
LightIndex lightIndex = new LightIndex();
lightIndex.LightId = lightConfigInfo.LightId;
lightIndex.Ch = lightConfigInfo.ChConfig.Ch;
if (_LightSettingViewEachChs.ContainsKey(lightIndex)) {
_LightSettingViewEachChs[lightIndex].cbOnOff.IsChecked = true;
}
}
}
catch (Exception ex) {
_Logger.FuncE(ex.Message);
}
}
private void OnAllLightOffButtonClicked(object sender, RoutedEventArgs e) {
try {
foreach (var lightConfigInfo in _LightConfigInfos) {
LightIndex lightIndex = new LightIndex();
lightIndex.LightId = lightConfigInfo.LightId;
lightIndex.Ch = lightConfigInfo.ChConfig.Ch;
if (_LightSettingViewEachChs.ContainsKey(lightIndex)) {
_LightSettingViewEachChs[lightIndex].cbOnOff.IsChecked = false;
}
}
}
catch (Exception ex) {
_Logger.FuncE(ex.Message);
}
}
public void OnReloadButtonClicked(object sender, RoutedEventArgs e) {
try {
Reload();
}
catch (Exception ex) {
_Logger.FuncE(ex.Message);
}
}
private void Reload() {
var lightChColorConverter = new LightChColorConverter();
foreach (var lightConfigInfo in _LightConfigInfos) {
LightIndex lightIndex = new LightIndex();
lightIndex.LightId = lightConfigInfo.LightId;
lightIndex.Ch = lightConfigInfo.ChConfig.Ch;
if (_LightSettingViewEachChs.ContainsKey(lightIndex)) {
var chColor = lightConfigInfo.ChConfig.ColorType;
_LightSettingViewEachChs[lightIndex].bdChColor.Background = lightChColorConverter.Convert(chColor, null, null, null) as SolidColorBrush;
_LightSettingViewEachChs[lightIndex].tbChName.Text = string.Format("CH {0}", lightConfigInfo.ChConfig.Ch.ToString());
_LightSettingViewEachChs[lightIndex].tbLevelRange.Text = string.Format("[{0},{1}]", lightConfigInfo.DimRange.Min, lightConfigInfo.DimRange.Max);
_LightSettingViewEachChs[lightIndex].cbOnOff.IsChecked = lightConfigInfo.ChConfig.OnOff;
_LightSettingViewEachChs[lightIndex].SliderLED.Value = lightConfigInfo.ChConfig.Level;
}
}
}
private void OnSaveButtonClicked(object sender, RoutedEventArgs e) {
try {
Save();
}
catch (Exception ex) {
_Logger.FuncE(ex.Message);
}
}
private void Save() {
foreach (var lightConfigInfo in _LightConfigInfos) {
LightIndex lightIndex = new LightIndex();
lightIndex.LightId = lightConfigInfo.LightId;
lightIndex.Ch = lightConfigInfo.ChConfig.Ch;
if (_LightSettingViewEachChs.ContainsKey(lightIndex)) {
lightConfigInfo.ChConfig.OnOff = (bool)_LightSettingViewEachChs[lightIndex].cbOnOff.IsChecked;
lightConfigInfo.ChConfig.Level = (int)_LightSettingViewEachChs[lightIndex].SliderLED.Value;
}
}
LightHub.Instance.SaveLightConfigInfo(_LightConfigInfos);
}
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
bool isVisible = (bool)e.NewValue;
if (isVisible == true) {
Reload();
}
}
}
}