189 lines
8.7 KiB
C#
189 lines
8.7 KiB
C#
using Aurora.Api;
|
|
using Aurora.View;
|
|
using VisionAligner;
|
|
using VisionCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Reactive.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace VisionUI.Aligner {
|
|
/// <summary>
|
|
/// 얼라인 로그 뷰 모델
|
|
/// </summary>
|
|
public class AlignLogViewModel : NotifyPropertyChangedBase {
|
|
private Logger _Logger = new Logger(typeof(AlignLogViewModel).Name);
|
|
|
|
private ObservableCollection<AlignResultItem> alignResultItems;
|
|
/// <summary>얼라인 결과 아이템 리스트</summary>
|
|
public ObservableCollection<AlignResultItem> AlignResultItems { get => alignResultItems; set => SetProperty(ref alignResultItems, 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();
|
|
private AlignLogView _AlignLogView;
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="subSysInfo">서브시스템 정보</param>
|
|
/// <param name="alignLogView">얼라인 로그 뷰</param>
|
|
public AlignLogViewModel(SubSysInfo subSysInfo, AlignLogView alignLogView) {
|
|
_SubSysInfo = subSysInfo;
|
|
_SubSysRecipe = VisionRecipeManager.GetSubSysRecipe(_SubSysInfo);
|
|
_AlignLogView = alignLogView;
|
|
AlignResultItems = new ObservableCollection<AlignResultItem>();
|
|
//ProcResultItemManager.SetAlignResultItems(_SubSysInfo, AlignResultItems);
|
|
SelectedDate = DateTime.Now.Date;
|
|
|
|
SetObservable();
|
|
}
|
|
|
|
private void SetObservable() {
|
|
VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.UPDATE_ALIGN_RESULT).
|
|
Where(x => x.From == _SubSysInfo.GetKey()).Subscribe(alignResult => UpdateAlignResult(alignResult));
|
|
|
|
VisionEnv.AuroraEnv.EventObservable.AsObservable(VisionEventId.UPDATE_ALIGN_RESULTS).
|
|
Where(x => x.From == _SubSysInfo.GetKey()).Subscribe(alignResultsParam => UpdateAlignResults(alignResultsParam));
|
|
}
|
|
/// <summary>
|
|
/// 얼라인 결과 업데이트
|
|
/// </summary>
|
|
/// <param name="msg">이벤트 메세지</param>
|
|
public void UpdateAlignResult(EventMessage msg) {
|
|
var alignResult = msg.Param as AlignResult;
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new Action(() => {
|
|
AlignResultItems.Add(AlignResultItemManager.GetAlignResultItem(_SubSysInfo, alignResult));
|
|
}));
|
|
|
|
// Dispatcher에 같이 넣을 경우, 전체적으로 느려질 수 있음
|
|
Task.Run(() => { PrintAlignResult(alignResult, new ImagePoint(30, 20)); });
|
|
}
|
|
/// <summary>
|
|
/// 여러개의 얼라인 결과 업데이트
|
|
/// </summary>
|
|
/// <param name="msg">이벤트 메세지</param>
|
|
public void UpdateAlignResults(EventMessage msg) {
|
|
var alignResultsParam = msg.Param as AlignResultsParam;
|
|
|
|
Application.Current.Dispatcher.BeginInvoke(
|
|
new Action(() => {
|
|
foreach (var itemPairs in alignResultsParam.AlignResults) {
|
|
AlignResult alignResult = itemPairs.Value;
|
|
AlignResultItems.Add(AlignResultItemManager.GetAlignResultItem(_SubSysInfo, alignResult));
|
|
}
|
|
}));
|
|
|
|
// Dispatcher에 같이 넣을 경우, 전체적으로 느려질 수 있음
|
|
Task.Run(() => {
|
|
foreach (var itemPairs in alignResultsParam.AlignResults) {
|
|
int alignPosIdx = itemPairs.Key;
|
|
if (alignResultsParam.MeasureResults.ContainsKey(alignPosIdx) && itemPairs.Value.Status != AlignStatus.NOT_FOUND) {
|
|
AlignResult alignResult = itemPairs.Value;
|
|
BaseResult baseResult = alignResultsParam.MeasureResults[alignPosIdx];
|
|
if (baseResult != null) {
|
|
ImagePoint printPosOffset = new ImagePoint(0, -210);
|
|
ImagePoint printPos = new ImagePoint(
|
|
baseResult.ImagePosition.X + printPosOffset.X,
|
|
baseResult.ImagePosition.Y + printPosOffset.Y);
|
|
PrintSimpleAlignResult(alignResult, printPos);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
// 얼라인 결과를 화면에 텍스트로 뿌린다.
|
|
private void PrintAlignResult(AlignResult alignResult, ImagePoint printPos) {
|
|
var displayType = alignResult.DisplayType;
|
|
var fovInfo = VisionRecipeManager.GetLastFovInfo(_SubSysInfo);
|
|
var cameraDisplay = CameraDisplayManager.GetDisplay(fovInfo, displayType);
|
|
|
|
var msgs = new List<string>();
|
|
msgs.Add(string.Format("Name : {0}", alignResult.AlignName));
|
|
msgs.Add(string.Format("Status : {0}", alignResult.Status));
|
|
msgs.Add(string.Format("AlignCnt : {0}", alignResult.AlignCnt));
|
|
msgs.Add(ConvertAlignDeltaX(alignResult.Delta.X));
|
|
msgs.Add(ConvertAlignDeltaY(alignResult.Delta.Y));
|
|
msgs.Add(string.Format("{0} : {1:0.000}", "dT", alignResult.Delta.T.Degree));
|
|
|
|
eColor color = IpViewManager.GetGraphicColor(alignResult.Status);
|
|
|
|
if (alignResult.AlignName.Contains("Mixed")) {
|
|
// AlignMixerSeq 수행 결과 업데이트
|
|
// Source 얼라인 결과 아래에 바인딩하기 위한 위치 조정
|
|
printPos = new ImagePoint(30, 500);
|
|
}
|
|
|
|
cameraDisplay.AddTextList(color, printPos, msgs);
|
|
}
|
|
|
|
// 얼라인 요약 결과를 화면의 패턴 결과 위에 텍스트로 뿌린다.
|
|
private void PrintSimpleAlignResult(AlignResult alignResult, ImagePoint printPos) {
|
|
var displayType = alignResult.DisplayType;
|
|
var fovInfo = VisionRecipeManager.GetLastFovInfo(_SubSysInfo);
|
|
var cameraDisplay = CameraDisplayManager.GetDisplay(fovInfo, displayType);
|
|
|
|
var msgs = new List<string>();
|
|
msgs.Add(string.Format("PosIdx : {0}", alignResult.AlignCnt));
|
|
msgs.Add(string.Format("Status : {0}", alignResult.Status));
|
|
msgs.Add(string.Format("{0} / {1} / {2:0.000}",
|
|
ConvertSimpleAlignDeltaXY(alignResult.Delta.X), ConvertSimpleAlignDeltaXY(alignResult.Delta.Y), alignResult.Delta.T.Degree));
|
|
|
|
eColor color = IpViewManager.GetGraphicColor(alignResult.Status);
|
|
color = (color == eColor.Green) ? eColor.Orange : color;
|
|
cameraDisplay.AddTextList(color, printPos, msgs);
|
|
}
|
|
|
|
private string ConvertAlignDeltaX(double delta) {
|
|
if (VisionSettingManager.VisionSetting.CoordUnit == eCoordUnit.UM) {
|
|
return string.Format("{0} : {1:0.0}", "dX", MathUtil.ConvertUnitMilliToMicro(delta));
|
|
}
|
|
return string.Format("{0} : {1:0.000}", "dX", delta);
|
|
}
|
|
|
|
private string ConvertAlignDeltaY(double delta) {
|
|
if (VisionSettingManager.VisionSetting.CoordUnit == eCoordUnit.UM) {
|
|
return string.Format("{0} : {1:0.0}", "dY", MathUtil.ConvertUnitMilliToMicro(delta));
|
|
}
|
|
return string.Format("{0} : {1:0.000}", "dY", delta);
|
|
}
|
|
|
|
private string ConvertSimpleAlignDeltaXY(double delta) {
|
|
if (VisionSettingManager.VisionSetting.CoordUnit == eCoordUnit.UM) {
|
|
return string.Format("{0:0.0}", MathUtil.ConvertUnitMilliToMicro(delta));
|
|
}
|
|
return string.Format("{0:0.000}", delta);
|
|
}
|
|
|
|
private void CalendarChanged(DateTime dateTime) {
|
|
_AlignLogView.LoadOverlayImages(dateTime);
|
|
LoadCsv(dateTime);
|
|
}
|
|
|
|
private void LoadCsv(DateTime dateTime) {
|
|
try {
|
|
AlignResultItems?.Clear();
|
|
List<AlignResultItem> items =
|
|
_CsvManager.LoadCsv<AlignResultItem>(_SubSysInfo, dateTime, eSaveDataType.Align);
|
|
if (items != null) { // 로드할 파일이 없으면 items가 null임.
|
|
foreach (AlignResultItem item in items) {
|
|
AlignResultItems.Add(item);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|