236 lines
10 KiB
C#
236 lines
10 KiB
C#
using Aurora.Api;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Media;
|
|
using VisionLight;
|
|
using Hermes;
|
|
using VisionCommonUI.Resources;
|
|
|
|
namespace VisionCommonUI {
|
|
public partial class PatternLightSettingView : UserControl {
|
|
private Logger _Logger = new Logger("PatternLightSettingView");
|
|
private FovInfo _FovInfo;
|
|
private PatternAgentBase _PatternAgent;
|
|
private PatternInfo _PatternInfo;
|
|
private PatternInfo _ClonedPatternInfo;
|
|
private Dictionary<LightIndex, PatternLightSettingViewEachCh> _LightSettingViewEachChs = new Dictionary<LightIndex, PatternLightSettingViewEachCh>();
|
|
private List<LightConfigInfo> _LightConfigInfos = new List<LightConfigInfo>();
|
|
|
|
public PatternLightSettingView(FovInfo fovInfo, PatternInfo patternInfo) {
|
|
if (fovInfo == null) {
|
|
_Logger.FuncE("fovInfo is null.");
|
|
return;
|
|
}
|
|
|
|
InitializeComponent();
|
|
|
|
_FovInfo = fovInfo;
|
|
_PatternInfo = patternInfo; // 창 나갈 때, 부모의 PatternInfo 업데이트를 위해 원본 Keep
|
|
_ClonedPatternInfo = patternInfo.Clone() as PatternInfo; // UI 수정을 위한 복사본
|
|
SetPatternAgent();
|
|
|
|
var fovRecipe = VisionRecipeManager.GetFovRecipe(_FovInfo);
|
|
_LightConfigInfos = LightHub.Instance.GetLightConfigInfo(fovRecipe.CamRecipe.CamId);
|
|
|
|
CreateView();
|
|
}
|
|
|
|
private void SetPatternAgent() {
|
|
if(_PatternInfo is FovPatternInfo) {
|
|
_PatternAgent = FovPatternAgentManager.GetAgent(_FovInfo.ToSubSysInfo());
|
|
}
|
|
else {
|
|
_PatternAgent = CamPatternAgentManager.GetAgent(VisionRecipeManager.GetFovRecipe(_FovInfo).CamRecipe.CamId);
|
|
}
|
|
}
|
|
|
|
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 PatternLightSettingViewEachCh(_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.FontSize = 17;
|
|
gb.FontWeight = FontWeights.Regular;
|
|
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.FontSize = 17;
|
|
gb.FontWeight = FontWeights.Regular;
|
|
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 (LightParam lightParam in _ClonedPatternInfo.LightInfo.LightParams) {
|
|
LightIndex lightIndex = new LightIndex();
|
|
lightIndex.LightId = lightParam.LightId;
|
|
lightIndex.Ch = lightParam.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 (LightParam lightParam in _ClonedPatternInfo.LightInfo.LightParams) {
|
|
LightIndex lightIndex = new LightIndex();
|
|
lightIndex.LightId = lightParam.LightId;
|
|
lightIndex.Ch = lightParam.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() {
|
|
_ClonedPatternInfo = _PatternAgent.GetPatternInfo(_PatternInfo.GetPatternIndex());
|
|
if(_PatternInfo.LightInfo.LightParams.Count < _LightSettingViewEachChs.Count) {
|
|
foreach(var lightIndex in _LightSettingViewEachChs.Keys) {
|
|
bool checkLight = false;
|
|
foreach(var lightParam in _PatternInfo.LightInfo.LightParams) {
|
|
if(lightParam.Ch == lightIndex.Ch && lightParam.LightId == lightIndex.LightId) {
|
|
checkLight = true;
|
|
}
|
|
}
|
|
if(checkLight == false) {
|
|
LightParam lightParam = new LightParam();
|
|
lightParam.Ch = lightIndex.Ch;
|
|
lightParam.LightId = lightIndex.LightId;
|
|
_PatternInfo.LightInfo.LightParams.Add(lightParam);
|
|
}
|
|
}
|
|
}
|
|
|
|
var lightChColorConverter = new LightChColorConverter();
|
|
foreach (LightParam lightParam in _PatternInfo.LightInfo.LightParams) {
|
|
LightIndex lightIndex = new LightIndex();
|
|
lightIndex.LightId = lightParam.LightId;
|
|
lightIndex.Ch = lightParam.Ch;
|
|
if (_LightSettingViewEachChs.ContainsKey(lightIndex)) {
|
|
LightConfigInfo lightConfigInfo = LightHub.Instance.GetLightConfigInfo(lightParam.LightId, lightParam.Ch);
|
|
_LightSettingViewEachChs[lightIndex].bdChColor.Background = lightChColorConverter.Convert(lightParam.Ch, null, null, null) as SolidColorBrush;
|
|
_LightSettingViewEachChs[lightIndex].tbChName.Text = string.Format("CH {0}", lightParam.Ch.ToString());
|
|
_LightSettingViewEachChs[lightIndex].tbLevelRange.Text = string.Format("[{0},{1}]", lightConfigInfo.DimRange.Min, lightConfigInfo.DimRange.Max);
|
|
_LightSettingViewEachChs[lightIndex].cbOnOff.IsChecked = lightParam.OnOff;
|
|
_LightSettingViewEachChs[lightIndex].SliderLED.Value = lightParam.Level;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnSaveButtonClicked(object sender, RoutedEventArgs e) {
|
|
try {
|
|
Save();
|
|
}
|
|
catch (Exception ex) {
|
|
_Logger.FuncE(ex.Message);
|
|
}
|
|
}
|
|
|
|
private void Save() {
|
|
foreach (LightParam lightParam in _PatternInfo.LightInfo.LightParams) {
|
|
LightIndex lightIndex = new LightIndex();
|
|
lightIndex.LightId = lightParam.LightId;
|
|
lightIndex.Ch = lightParam.Ch;
|
|
if (_LightSettingViewEachChs.ContainsKey(lightIndex)) {
|
|
lightParam.OnOff = (bool)_LightSettingViewEachChs[lightIndex].cbOnOff.IsChecked;
|
|
lightParam.Level = (int)_LightSettingViewEachChs[lightIndex].SliderLED.Value;
|
|
}
|
|
}
|
|
|
|
if (_PatternAgent.Save(_PatternInfo) == E1.OK) {
|
|
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
|
|
}
|
|
}
|
|
|
|
private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) {
|
|
bool isVisible = (bool)e.NewValue;
|
|
if (isVisible == true) {
|
|
Reload();
|
|
}
|
|
else {
|
|
// 창 닫을 때, 원본 PatternInfo에 조명 정보 업데이트
|
|
// 부모 창에서도 PatternInfo Save버튼이 있으므로, 여기서 조명 정보를 저장된 값으로 업데이트 해준다.
|
|
_ClonedPatternInfo = _PatternAgent.GetPatternInfo(_PatternInfo.GetPatternIndex());
|
|
_PatternInfo.LightInfo = _ClonedPatternInfo.LightInfo;
|
|
}
|
|
}
|
|
}
|
|
} |