/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora;
using Aurora.Api;
using Aurora.View;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using VisionCommon;
using VisionSequence.Setup;
using VisionUI.Aligner;
namespace VisionUI.Setup {
///
/// 캘리브레이션 로그 뷰 모델
///
class CalLogViewModel : NotifyPropertyChangedBase {
private Logger _Logger = new Logger(typeof(CalLogViewModel).Name);
private SubSysInfo _SubSysInfo;
private CsvManager _CsvManager = new CsvManager();
public event PropertyChangedEventHandler PropertyChanged;
#region Binding Properties
private ObservableCollection mPlanListItems;
///
/// 캘리브레이션 계획 아이템 컬렉션
///
public ObservableCollection PlanListItems {
get {
return mPlanListItems;
}
set {
mPlanListItems = value;
NotifyPropertyChanged("PlanListItems");
}
}
private DateTime selectedDate;
/// 선택된 날짜
public DateTime SelectedDate { get => selectedDate; set { SetProperty(ref selectedDate, value); CalendarChanged(value); } }
#endregion
///
/// 생성자
///
/// 서브시스템 정보
public CalLogViewModel(SubSysInfo subSysInfo) {
_SubSysInfo = subSysInfo;
PlanListItems = new ObservableCollection();
SelectedDate = DateTime.Now.Date;
}
///
/// 플랜 아이템컬렉션 설정
///
/// 설정 할 플랜아이템 컬렉션
public void SetPlan(ObservableCollection plans) {
Application.Current.Dispatcher.Invoke(() => { PlanListItems = plans; });
}
///
/// 현재 시간 기준으로 CSV 불러오기
///
public void LoadCsvNow() {
DateTime dateTime = DateTime.Now;
LoadCsv(dateTime);
}
private void CalendarChanged(DateTime dateTime) {
LoadCsv(dateTime);
}
private void LoadCsv(DateTime date) {
try {
PlanListItems?.Clear();
List items = _CsvManager.LoadCsv(_SubSysInfo, date, eSaveDataType.Calibration);
if (items != null) {
foreach (CalResultItem item in items) {
PlanListItems.Add(CalItemManager.CalItemToPlanItem(item));
}
}
}
catch (Exception e) {
_Logger.FuncE(e.Message);
}
}
private void NotifyPropertyChanged(string propName) {
PropertyChanged?.Invoke(
this,
new PropertyChangedEventArgs(propName));
}
}
}