190 lines
7.7 KiB
C#
190 lines
7.7 KiB
C#
/*
|
|
* 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.Linq;
|
|
using System.Reactive.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Data;
|
|
using System.Windows.Input;
|
|
using VisionCommon;
|
|
using VisionCommonUI;
|
|
using VisionCommonUI.Resources;
|
|
using VisionSequence.Setup;
|
|
|
|
namespace VisionUI.Setup {
|
|
/// <summary>
|
|
/// 캘리브레이션 세팅 뷰 모델
|
|
/// </summary>
|
|
public class CalSettingViewModel : NotifyPropertyChangedBase, IUpdateRecipe {
|
|
private Logger _Logger = new Logger(typeof(CalSettingViewModel).Name);
|
|
|
|
private IEventObservable _EventObservable = VisionEnv.AuroraEnv.EventObservable;
|
|
/// <summary>캘리브레이션 플랜 아이템 컬렉션</summary>
|
|
public ObservableCollection<PlanItem> _PlanItems;
|
|
|
|
/// <summary>캘리브레이션 플랜 생성 이벤트 핸들러</summary>
|
|
public event EventHandler<CalSeqParams> CalPlanCreated;
|
|
/// <summary>캘리브레이션 시퀀스 취소 이벤트 핸들러</summary>
|
|
public event EventHandler CancelSequence;
|
|
|
|
private SubSysInfo _SubSysInfo;
|
|
private SubSysRecipe _SubSysRecipe;
|
|
|
|
#region Binding Properties
|
|
private CalSetupRecipe _CalSetupRecipe;
|
|
|
|
/// <summary>캘리브레이션 셋업 레시피</summary>
|
|
public CalSetupRecipe CalSetupRecipe { get => _CalSetupRecipe; set => SetProperty(ref _CalSetupRecipe, value); }
|
|
#endregion
|
|
|
|
#region ButtonCommand
|
|
public ICommand ButtonCommandStart { get; set; }
|
|
public ICommand ButtonCommandStop { get; set; }
|
|
public ICommand ButtonCommandSave { get; set; }
|
|
#endregion
|
|
/// <summary>
|
|
/// 생성자
|
|
/// </summary>
|
|
/// <param name="subSysInfo">서브시스템 정보</param>
|
|
public CalSettingViewModel(SubSysInfo subSysInfo) {
|
|
_SubSysInfo = subSysInfo;
|
|
_SubSysRecipe = VisionRecipeManager.GetSubSysRecipe(_SubSysInfo);
|
|
_PlanItems = new ObservableCollection<PlanItem>();
|
|
|
|
ButtonCommandStart = new DelegateCommand(new Action<object>(DoStart));
|
|
ButtonCommandStop = new DelegateCommand(new Action<object>(DoStop));
|
|
ButtonCommandSave = new DelegateCommand(new Action<object>(DoSave));
|
|
}
|
|
/// <summary>
|
|
/// 시작
|
|
/// </summary>
|
|
/// <param name="o">null</param>
|
|
public void DoStart(object o = null) {
|
|
if (MessageBoxUtil.ShowMessageBoxQuestion(
|
|
string.Format(StrTokens.MSG_Q_ConfirmRunCalibration)) == MessageBoxResult.Yes) {
|
|
if (!IsCalSettingParamsValid()) {
|
|
return;
|
|
}
|
|
StartCalSeq();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 시퀀스 정지
|
|
/// </summary>
|
|
/// <param name="o">null</param>
|
|
public void DoStop(object o = null) {
|
|
CancelSequence.Invoke(this, new EventArgs());
|
|
}
|
|
/// <summary>
|
|
/// 세팅레시피 저장
|
|
/// </summary>
|
|
/// <param name="o">null</param>
|
|
public void DoSave(object o = null) {
|
|
UpdateRecipeFromUI();
|
|
RecipeFileManager.SaveVisionRecipe();
|
|
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
|
|
}
|
|
|
|
private void StartCalSeq() {
|
|
try {
|
|
var plan = new CalPlan((int)CalSetupRecipe.DistanceStep,
|
|
CalSetupRecipe.DistanceUnit,
|
|
(int)CalSetupRecipe.RotationStep,
|
|
CalSetupRecipe.RotationUnit);
|
|
MakePlanItems(plan.MakeCalPlan(true,
|
|
CalSetupRecipe.isX(), CalSetupRecipe.isY(), CalSetupRecipe.isT()));
|
|
|
|
// 기존
|
|
//CalPlanCreated.Invoke(this, new SetupSeqParams_Cal() {
|
|
// FovInfo = _FovInfo,
|
|
// PlanItems = _PlanItems.ToList(),
|
|
// DisplayType = eDisplayType.Calibration
|
|
//});
|
|
|
|
// 변경 (0124)
|
|
CalPlanCreated.Invoke(this, new CalSeqParams()
|
|
{
|
|
SubSysInfo = _SubSysInfo,
|
|
DisplayType = eDisplayType.Calibration,
|
|
PlanItems = _PlanItems.ToList(),
|
|
CalSetupRecipe = CalSetupRecipe
|
|
});
|
|
}
|
|
catch (Exception e) {
|
|
_Logger.FuncE(e.Message);
|
|
}
|
|
}
|
|
|
|
private bool IsCalSettingParamsValid() {
|
|
var distanceUnitMax = 3; // 한 스텝당 이동은 3mm를 넘을 수 없음.
|
|
var rotationUnitMax = 90; // 한 스텝당 회전은 90도를 넘을 수 없음.
|
|
|
|
if (CalSetupRecipe.DistanceUnit <= 0 || CalSetupRecipe.DistanceUnit > distanceUnitMax) {
|
|
MessageBoxUtil.ShowMessageBoxError(
|
|
string.Format(StrTokens.MSG_E_NumberInvalid, "DistanceUnit", 0, distanceUnitMax));
|
|
return false;
|
|
}
|
|
if (CalSetupRecipe.RotationUnit <= 0 || CalSetupRecipe.RotationUnit > rotationUnitMax) {
|
|
MessageBoxUtil.ShowMessageBoxError(
|
|
string.Format(StrTokens.MSG_E_NumberInvalid, "RotationUnit", 0, rotationUnitMax));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
private void MakePlanItems(Dictionary<string, object> plan) {
|
|
_PlanItems.Clear();
|
|
string planStep, planPurpose, planTarget, planAction, planX, planY, planT;
|
|
planStep = planPurpose = planTarget = planAction = planX = planY = planT = "";
|
|
foreach (var step in plan) {
|
|
planStep = step.Key;
|
|
foreach (var purpose in (Dictionary<string, object>)step.Value) {
|
|
planPurpose = purpose.Key;
|
|
foreach (var target in (Dictionary<string, object>)purpose.Value) {
|
|
planTarget = target.Key;
|
|
foreach (var action in (Dictionary<string, object>)target.Value) {
|
|
planAction = action.Key;
|
|
foreach (var position in (Dictionary<string, object>)action.Value) {
|
|
if (position.Key == "x") {
|
|
planX = position.Value.ToString();
|
|
}
|
|
else if (position.Key == "y") {
|
|
planY = position.Value.ToString();
|
|
}
|
|
else if (position.Key == "t") {
|
|
planT = position.Value.ToString();
|
|
}
|
|
else {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
PlanItem planItem = new PlanItem(planStep, planPurpose, planTarget, planAction, planX, planY, planT);
|
|
_PlanItems.Add(planItem);
|
|
}
|
|
}
|
|
|
|
public void RefreshVisionRecipes() {
|
|
_SubSysRecipe = VisionRecipeManager.GetSubSysRecipe(_SubSysInfo);
|
|
}
|
|
|
|
public void UpdateRecipeFromFile() {
|
|
var calSetupRecipe = VisionRecipeManager.GetCalSetupRecipe(_SubSysInfo);
|
|
CalSetupRecipe = calSetupRecipe.Clone();
|
|
}
|
|
|
|
public void UpdateRecipeFromUI() {
|
|
var calSetupRecipe = VisionRecipeManager.GetCalSetupRecipe(_SubSysInfo);
|
|
CalSetupRecipe.CopyTo(calSetupRecipe);
|
|
}
|
|
}
|
|
} |