124 lines
5.0 KiB
C#
124 lines
5.0 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using Aurora.Api;
|
|
using Aurora.View;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Reactive.Linq;
|
|
using System.Windows;
|
|
using VisionSequence.Aligner;
|
|
using VisionAligner;
|
|
|
|
namespace VisionUI.Aligner {
|
|
/// <summary> 패턴 로그 뷰 모델 </summary>
|
|
public class PatternLogViewModel : NotifyPropertyChangedBase {
|
|
private Logger _Logger = new Logger(typeof(PatternLogViewModel).Name);
|
|
|
|
private ObservableCollection<PatternResultItem> patternResultItems;
|
|
/// <summary>Pattern 결과 Items</summary>
|
|
public ObservableCollection<PatternResultItem> PatternResultItems { get => patternResultItems; set => SetProperty(ref patternResultItems, value); }
|
|
|
|
private DateTime selectedDate;
|
|
/// <summary>선택한 날짜</summary>
|
|
public DateTime SelectedDate { get => selectedDate; set { SetProperty(ref selectedDate, value); CalendarChanged(value); } }
|
|
|
|
private SubSysInfo _SubSysInfo;
|
|
private SubSysRecipe _SubSysRecipe;
|
|
private CsvManager _CsvManager = new CsvManager();
|
|
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="subSysInfo">서브시스템 정보</param>
|
|
public PatternLogViewModel(SubSysInfo subSysInfo) {
|
|
_SubSysInfo = subSysInfo;
|
|
_SubSysRecipe = VisionRecipeManager.GetSubSysRecipe(_SubSysInfo);
|
|
PatternResultItems = new ObservableCollection<PatternResultItem>();
|
|
//ProcResultItemManager.SetPatternResultItems(_SubSysInfo, PatternResultItems);
|
|
SelectedDate = DateTime.Now.Date;
|
|
|
|
SetObservable();
|
|
}
|
|
|
|
private void SetObservable() {
|
|
foreach (var fovRecipe in _SubSysRecipe.FovRecipes) {
|
|
var fovInfo = VisionRecipeManager.GetFovInfo(_SubSysInfo, fovRecipe.FovId);
|
|
|
|
var disposable_1 = VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.UPDATE_PATTERN_RESULT).
|
|
Where(x => x.From == fovInfo.GetKey()).Subscribe(msg => UpdatePatternResult(msg));
|
|
DisposableManager.AddDisposable(eDpsGroupKey.SubMenu_Align, disposable_1);
|
|
|
|
var disposable_2 = VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.UPDATE_PATTERN_RESULTS).
|
|
Where(x => x.From == fovInfo.GetKey()).Subscribe(msg => UpdatePatternResults(msg));
|
|
DisposableManager.AddDisposable(eDpsGroupKey.SubMenu_Align, disposable_2);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 패턴 결과 업데이트
|
|
/// </summary>
|
|
/// <param name="msg">이벤트 메세지</param>
|
|
public void UpdatePatternResult(EventMessage msg) {
|
|
var patternResult = msg.Param as PatternResult;
|
|
PatternResultItem item = PatternResultItemManager.GetPatternResultItem(_SubSysInfo, patternResult);
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new Action(() => {
|
|
PatternResultItems.Add(item);
|
|
}));
|
|
_CsvManager.SaveCsv(_SubSysInfo, item, eSaveDataType.Pattern);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 여러개의 패턴 결과 업데이트
|
|
/// </summary>
|
|
/// <param name="msg">이벤트 메세지</param>
|
|
public void UpdatePatternResults(EventMessage msg) {
|
|
if (msg.Param == null) {
|
|
_Logger.FuncE("msg.Param is null.");
|
|
return;
|
|
}
|
|
|
|
var patternResults = msg.Param as List<PatternResult>;
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new Action(() => {
|
|
foreach (var patternResult in patternResults) {
|
|
var item = PatternResultItemManager.GetPatternResultItem(_SubSysInfo, patternResult);
|
|
PatternResultItems.Add(item);
|
|
}
|
|
}));
|
|
|
|
var dataList = new List<PatternResultItem>();
|
|
foreach (var patternResult in patternResults) {
|
|
dataList.Add(PatternResultItemManager.GetPatternResultItem(_SubSysInfo, patternResult));
|
|
}
|
|
_CsvManager.SaveCsv(_SubSysInfo, dataList, eSaveDataType.Pattern);
|
|
}
|
|
|
|
private void CalendarChanged(DateTime dateTime) {
|
|
LoadCsv(dateTime);
|
|
}
|
|
|
|
private void LoadCsv(DateTime dateTime) {
|
|
try {
|
|
PatternResultItems?.Clear();
|
|
List<PatternResultItem> items =
|
|
_CsvManager.LoadCsv<PatternResultItem>(_SubSysInfo, dateTime, eSaveDataType.Pattern);
|
|
if (items != null) { // 로드할 파일이 없으면 items가 null임.
|
|
foreach (PatternResultItem item in items) {
|
|
PatternResultItems.Add(item);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|