- 오토런 시작 시 RCC 패턴 폴더 변경 감지 → B2506 ON, PLC ACK(B2409) 수신 시 OFF - 서브 패턴 1~10, 패턴 목록에 서브 썸네일 표시(행 내 좌우 스크롤) - 서브 패턴 등록 직후 활성화 OFF - 패턴 파일이 다른 프로그램에서 열려 있으면 삭제하지 않고 안내 - 현장 소스 반영: Train ROI 슬라이더, KS 조명 밝기 저장/적용, 조명 ID 분리, 스캔 후 카메라 라이브 재시작, 레시피 21 RCC NG 우회, 오토런 상태 판단
226 lines
8.0 KiB
C#
226 lines
8.0 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using Aurora.Api;
|
|
using Aurora.Api.DataType;
|
|
using Aurora.View;
|
|
using CogCommon;
|
|
using VisionCommon;
|
|
using CogPattern;
|
|
using VisionCommonUI;
|
|
using VisionCommonUI.Resources;
|
|
|
|
namespace CogUI {
|
|
public class CaliperSettingViewModel : NotifyPropertyChangedBase, IGraEventSubscriber {
|
|
private Logger _logger = new Logger(typeof(CaliperSettingViewModel).Name);
|
|
|
|
public ICommand CMD_VisibleChanged { get; }
|
|
public ICommand CMD_Save { get; }
|
|
public ICommand CMD_Cancel { get; }
|
|
public ICommand CMD_SetLight { get; }
|
|
public ICommand CMD_SetPreProc { get; }
|
|
public ICommand CMD_SetFindROI { get; }
|
|
public ICommand CMD_FindPattern { get; }
|
|
|
|
private bool _isPatternRegistered;
|
|
public bool IsPatternRegistered { get => _isPatternRegistered; set => SetProperty(ref _isPatternRegistered, value); }
|
|
|
|
private PatternInfo _patternInfo;
|
|
public PatternInfo PatternInfo { get => _patternInfo; set => SetProperty(ref _patternInfo, value); }
|
|
|
|
private CaliperRunParam _runParam;
|
|
public CaliperRunParam RunParam { get => _runParam; set => SetProperty(ref _runParam, value); }
|
|
|
|
private IEnumerable<int> _fixturePatterns;
|
|
public IEnumerable<int> FixturePatterns { get => _fixturePatterns; set => SetProperty(ref _fixturePatterns, value); }
|
|
|
|
private PatternAgentBase _patternAgent;
|
|
private CameraDisplay _cameraDisplay;
|
|
private FovInfo _fovInfo;
|
|
private Window _childWindow = null;
|
|
|
|
public CaliperSettingViewModel(
|
|
PatternAgentBase patternAgent, PatternInfo patternInfo, ICameraDisplay cameraDisplay, FovInfo fovInfo) {
|
|
_patternAgent = patternAgent;
|
|
_patternInfo = patternInfo;
|
|
_cameraDisplay = (CameraDisplay)cameraDisplay;
|
|
_fovInfo = fovInfo;
|
|
|
|
CMD_VisibleChanged = new DelegateCommand(VisibleChanged);
|
|
CMD_Save = new DelegateCommand(Save);
|
|
CMD_Cancel = new DelegateCommand(Cancel);
|
|
CMD_SetLight = new DelegateCommand(SetLight);
|
|
CMD_SetPreProc = new DelegateCommand(SetPreProc);
|
|
CMD_SetFindROI = new DelegateCommand(SetFindROI);
|
|
CMD_FindPattern = new DelegateCommand(FindPattern);
|
|
|
|
InitRegistered();
|
|
InitRunParam();
|
|
InitFixturePatterns();
|
|
|
|
_cameraDisplay.SetGraEventSubscriber(_patternInfo, this);
|
|
}
|
|
|
|
public void InitRegistered() {
|
|
IsPatternRegistered = _patternAgent.IsPatternExist(_patternInfo.GetPatternIndex());
|
|
}
|
|
|
|
public void InitRunParam() {
|
|
if (IsPatternRegistered) {
|
|
RunParam = _patternAgent.GetRunParam(_patternInfo) as CaliperRunParam;
|
|
}
|
|
}
|
|
|
|
public void InitFixturePatterns() {
|
|
FixturePatterns = _patternAgent.GetFixturePatternIndexListForFov(_patternInfo);
|
|
}
|
|
|
|
private void VisibleChanged(object obj) {
|
|
bool visible = (bool)obj;
|
|
if (visible == false) {
|
|
CloseChildWindow();
|
|
ClosingWindow();
|
|
}
|
|
else {
|
|
_cameraDisplay.ClearFindGraphics();
|
|
_cameraDisplay.ClearMeasureGraphics();
|
|
}
|
|
}
|
|
|
|
private void Save(object obj) {
|
|
Save();
|
|
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
|
|
}
|
|
|
|
public void Save() {
|
|
if (_cameraDisplay.HasFindRoi()) {
|
|
RunParam.FindROI = _cameraDisplay.GetFindRoi().Clone() as ROI;
|
|
}
|
|
_patternAgent.SetRunParam(_patternInfo, RunParam);
|
|
_patternAgent.Save(_patternInfo);
|
|
}
|
|
|
|
private void Cancel(object obj) {
|
|
CloseChildWindow();
|
|
ClosingWindow();
|
|
CloseWindow(obj);
|
|
}
|
|
|
|
private void ClosingWindow() {
|
|
_cameraDisplay.ClearFindGraphics();
|
|
}
|
|
|
|
private void CloseWindow(object obj) {
|
|
var window = obj as Window;
|
|
if (window != null) {
|
|
window.Close();
|
|
}
|
|
}
|
|
|
|
private void CloseChildWindow() {
|
|
if (_childWindow != null) {
|
|
_childWindow.Close();
|
|
}
|
|
}
|
|
|
|
private void SetLight(object obj) {
|
|
PatternLightWindowManager.ShowLightSettingWindow(_fovInfo, _patternInfo);
|
|
}
|
|
|
|
private void SetPreProc(object obj) {
|
|
if (_childWindow == null) {
|
|
_childWindow = new PreProcessingWindow(_patternInfo, _cameraDisplay);
|
|
(_childWindow as IPatternSettingWindow).ResetPosition();
|
|
_childWindow.Closed += OnWindowClosed;
|
|
_childWindow.Owner = Application.Current.MainWindow;
|
|
_childWindow.Show();
|
|
}
|
|
else {
|
|
ResetWindow();
|
|
}
|
|
}
|
|
|
|
private void ResetWindow() {
|
|
if (_childWindow.WindowState == WindowState.Minimized) {
|
|
_childWindow.WindowState = WindowState.Normal;
|
|
}
|
|
|
|
(_childWindow as IPatternSettingWindow).ResetPosition();
|
|
}
|
|
|
|
private void OnWindowClosed(object sender, EventArgs e) {
|
|
_childWindow = null;
|
|
}
|
|
|
|
private void SetFindROI(object obj) {
|
|
_cameraDisplay.SetPatternInfo(_patternInfo);
|
|
var cogImage = _cameraDisplay.GetImage();
|
|
if (cogImage != null) {
|
|
var imageSize = CogEnvironment.GetImageSize(cogImage);
|
|
var findRoi = GetFindROIFromRunParam(imageSize, RunParam);
|
|
_cameraDisplay.AddFindRoi(findRoi, true);
|
|
}
|
|
}
|
|
|
|
private ROI GetFindROIFromRunParam(ImageSize imageSize, CaliperRunParam runParam) {
|
|
if ((0 < runParam.FindROI.Width && runParam.FindROI.Width < imageSize.Width) &&
|
|
(0 < runParam.FindROI.Height && runParam.FindROI.Height < imageSize.Height)) {
|
|
return runParam.FindROI.Clone() as ROI;
|
|
}
|
|
|
|
return new ROI(
|
|
new ImagePoint(imageSize.Width * 0.5, imageSize.Height * 0.5),
|
|
100, 300,
|
|
Angle.CreateWithDegree(0));
|
|
}
|
|
|
|
public void UpdateAngleOfFindRoi(double roiAngle) {
|
|
_cameraDisplay.UpdateAngleOfFindRoi(roiAngle);
|
|
}
|
|
|
|
private void FindPattern(object obj) {
|
|
if (!_patternInfo.IsActivated) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_PatternNotActivated);
|
|
return;
|
|
}
|
|
|
|
if (_cameraDisplay != null) {
|
|
var image = _cameraDisplay.GetImage();
|
|
if (image == null) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_ImageNotReady);
|
|
return;
|
|
}
|
|
if (_cameraDisplay.HasFindRoi()) {
|
|
RunParam.FindROI = _cameraDisplay.GetFindRoi().Clone() as ROI;
|
|
}
|
|
|
|
_cameraDisplay.ClearFindGraphics();
|
|
_cameraDisplay.ClearMeasureGraphics();
|
|
|
|
_patternAgent.SetRunParam(_patternInfo, RunParam);
|
|
var patternResult = _patternAgent.Find(_patternInfo, image);
|
|
_patternAgent.Draw(_patternInfo, patternResult, _cameraDisplay);
|
|
|
|
if (patternResult.Status == eFoundStatus.NotFound) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_PatternNotFound);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateAngleOfRoi(eGraRoiType graRoiType, object param) {
|
|
if (graRoiType == eGraRoiType.FindRoi) {
|
|
RunParam.FindROI.Angle.Degree = Math.Round((double)param, 1);
|
|
NotifyPropertyChanged(nameof(RunParam));
|
|
}
|
|
}
|
|
|
|
public void UpdateRadiusOfRoi(eGraRoiType graRoiType, double radius) {
|
|
}
|
|
}
|
|
} |