213 lines
8.2 KiB
C#
213 lines
8.2 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 VisionLight;
|
|
using CogCommon;
|
|
using VisionCommon;
|
|
using CogPattern;
|
|
using VisionCommonUI;
|
|
using System.Collections.ObjectModel;
|
|
using VisionCommonUI.Resources;
|
|
|
|
namespace CogUI {
|
|
public class LineIntersectionSettingViewModel : NotifyPropertyChangedBase {
|
|
private Logger _logger = new Logger("LineIntersectionSettingViewModel");
|
|
|
|
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_FindPattern { get; }
|
|
public ICommand CMD_PatternBlockChanged { get; }
|
|
|
|
private PatternInfo _patternInfo;
|
|
public PatternInfo PatternInfo { get => _patternInfo; set => SetProperty(ref _patternInfo, value); }
|
|
|
|
private LineIntersectionRunParam _runParam;
|
|
public LineIntersectionRunParam RunParam { get => _runParam; set => SetProperty(ref _runParam, value); }
|
|
|
|
private IEnumerable<int> _fixturePatterns;
|
|
public IEnumerable<int> FixturePatterns { get => _fixturePatterns; set => SetProperty(ref _fixturePatterns, value); }
|
|
|
|
public ObservableCollection<int> BlockPatterns { get; set; }
|
|
|
|
private PatternBlockSettingViewModel _patternBlock1SettingVM;
|
|
public PatternBlockSettingViewModel PatternBlock1SettingVM { get => _patternBlock1SettingVM; set => SetProperty(ref _patternBlock1SettingVM, value); }
|
|
|
|
private PatternBlockSettingViewModel _patternBlock2SettingVM;
|
|
public PatternBlockSettingViewModel PatternBlock2SettingVM { get => _patternBlock2SettingVM; set => SetProperty(ref _patternBlock2SettingVM, value); }
|
|
|
|
private LineSettingViewModel _line1ViewModel;
|
|
public LineSettingViewModel Line1ViewModel { get => _line1ViewModel; set => SetProperty(ref _line1ViewModel, value); }
|
|
|
|
private LineSettingViewModel _line2ViewModel;
|
|
public LineSettingViewModel Line2ViewModel { get => _line2ViewModel; set => SetProperty(ref _line2ViewModel, value); }
|
|
|
|
private PatternAgentBase _patternAgent;
|
|
private CameraDisplay _cameraDisplay;
|
|
private FovInfo _fovInfo;
|
|
private Window _childWindow = null;
|
|
|
|
public LineIntersectionSettingViewModel(
|
|
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_FindPattern = new DelegateCommand(FindPattern);
|
|
CMD_PatternBlockChanged = new DelegateCommand(PatternBlockChanged);
|
|
|
|
SetPatternBlockId();
|
|
SetLineViewModel();
|
|
InitRunParam();
|
|
InitFixturePatterns();
|
|
}
|
|
|
|
public void SetPatternBlockId() {
|
|
PatternBlock1SettingVM = new PatternBlockSettingViewModel(_patternInfo, 1);
|
|
PatternBlock2SettingVM = new PatternBlockSettingViewModel(_patternInfo, 2);
|
|
|
|
var patternIndex = _patternInfo.GetPatternIndex();
|
|
_patternAgent = PatternAgentManager.GetAgent(
|
|
VisionRecipeManager.GetFovInfo(
|
|
patternIndex.UnitId,
|
|
patternIndex.SubSysId,
|
|
patternIndex.FovId));
|
|
|
|
var patternInfoList = _patternAgent.GetMainPatterns(
|
|
_patternInfo, ePatternType.LineFinder);
|
|
BlockPatterns = new ObservableCollection<int>(
|
|
patternInfoList.Select(pi => pi.GetPatternId()).ToList());
|
|
}
|
|
|
|
public void SetLineViewModel() {
|
|
var pattern = _patternAgent.GetPattern(_patternInfo);
|
|
var patternBlock = pattern as IPatternBlock;
|
|
var patternBlockIds = patternBlock.GetPatternBlockIds();
|
|
var curPatternIndex = _patternInfo.GetPatternIndex().Clone() as PatternIndex;
|
|
|
|
curPatternIndex.PatternId = patternBlockIds[0];
|
|
if (0 <= curPatternIndex.PatternId) {
|
|
Line1ViewModel = new LineSettingViewModel(_patternAgent, _patternAgent.GetPatternInfo(curPatternIndex), _cameraDisplay, _fovInfo);
|
|
}
|
|
|
|
curPatternIndex = _patternInfo.GetPatternIndex().Clone() as PatternIndex;
|
|
curPatternIndex.PatternId = patternBlockIds[1];
|
|
if (0 <= curPatternIndex.PatternId) {
|
|
Line2ViewModel = new LineSettingViewModel(_patternAgent, _patternAgent.GetPatternInfo(curPatternIndex), _cameraDisplay, _fovInfo);
|
|
}
|
|
}
|
|
|
|
public void InitRunParam() {
|
|
RunParam = _patternAgent.GetRunParam(_patternInfo) as LineIntersectionRunParam;
|
|
}
|
|
|
|
public void InitFixturePatterns() {
|
|
FixturePatterns = _patternAgent.GetFixturePatternIndexListForFov(_patternInfo);
|
|
}
|
|
|
|
private void VisibleChanged(object obj) {
|
|
bool visible = (bool)obj;
|
|
if (visible == false) {
|
|
CloseChildWindow();
|
|
ClosingWindow();
|
|
}
|
|
}
|
|
|
|
private void Save(object obj) {
|
|
_patternAgent.SetRunParam(_patternInfo, RunParam);
|
|
_patternAgent.Save(_patternInfo);
|
|
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
|
|
}
|
|
|
|
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 FindPattern(object obj) {
|
|
if (_cameraDisplay != null) {
|
|
var image = _cameraDisplay.GetImage();
|
|
_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);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void PatternBlockChanged(object obj) {
|
|
if (_cameraDisplay != null) {
|
|
_cameraDisplay.ClearFindGraphics();
|
|
}
|
|
}
|
|
}
|
|
} |