186 lines
6.8 KiB
C#
186 lines
6.8 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 MilCommon;
|
|
using VisionCommon;
|
|
using MilPattern;
|
|
using VisionCommonUI;
|
|
using VisionCommonUI.Resources;
|
|
|
|
namespace MilUI {
|
|
public class CodeSettingViewModel : NotifyPropertyChangedBase {
|
|
private Logger _logger = new Logger(typeof(CodeSettingViewModel).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 PatternInfo _patternInfo;
|
|
public PatternInfo PatternInfo { get => _patternInfo; set => SetProperty(ref _patternInfo, value); }
|
|
|
|
private CodeRunParam _runParam;
|
|
public CodeRunParam RunParam { get => _runParam; set => SetProperty(ref _runParam, value); }
|
|
|
|
private IEnumerable<int> _fixturePatterns;
|
|
public IEnumerable<int> FixturePatterns { get => _fixturePatterns; set => SetProperty(ref _fixturePatterns, value); }
|
|
|
|
public IEnumerable<eMilCodeType> CodeTypeItems { get; } = Enum.GetValues(typeof(eMilCodeType)).Cast<eMilCodeType>();
|
|
public IEnumerable<eMilThresholdMode> ThresholdModeItems { get; } = Enum.GetValues(typeof(eMilThresholdMode)).Cast<eMilThresholdMode>();
|
|
public IEnumerable<eMilSpeed> SpeedItems { get; } = Enum.GetValues(typeof(eMilSpeed)).Cast<eMilSpeed>();
|
|
|
|
private PatternAgentBase _patternAgent;
|
|
private CameraDisplay _milCameraDisplay;
|
|
private FovInfo _fovInfo;
|
|
private Window _childWindow = null;
|
|
|
|
public CodeSettingViewModel(
|
|
PatternAgentBase patternAgent, PatternInfo patternInfo, ICameraDisplay cameraDisplay, FovInfo fovInfo) {
|
|
_patternAgent = patternAgent;
|
|
_patternInfo = patternInfo;
|
|
_milCameraDisplay = (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);
|
|
|
|
InitRunParam();
|
|
InitFixturePatterns();
|
|
}
|
|
|
|
public void InitRunParam() {
|
|
RunParam = _patternAgent.GetRunParam(_patternInfo) as CodeRunParam;
|
|
}
|
|
|
|
public void InitFixturePatterns() {
|
|
FixturePatterns = _patternAgent.GetFixturePatternIndexListForFov(_patternInfo);
|
|
}
|
|
|
|
private void VisibleChanged(object obj) {
|
|
bool visible = (bool)obj;
|
|
if (visible == false) {
|
|
ClosingWindow();
|
|
}
|
|
}
|
|
|
|
private void Save(object obj) {
|
|
if (_milCameraDisplay.HasFindRoi()) {
|
|
RunParam.SetFindROI(_milCameraDisplay.GetFindRoi().Clone() as ROI);
|
|
}
|
|
_patternAgent.SetRunParam(_patternInfo, RunParam);
|
|
_patternAgent.Save(_patternInfo);
|
|
MessageBoxUtil.ShowMessageBoxOk(StrTokens.MSG_O_SaveCompleted);
|
|
}
|
|
|
|
private void Cancel(object obj) {
|
|
ClosingWindow();
|
|
CloseWindow(obj);
|
|
}
|
|
|
|
private void ClosingWindow() {
|
|
_milCameraDisplay.ClearFindGraphics();
|
|
}
|
|
|
|
private void CloseWindow(object obj) {
|
|
var window = obj as Window;
|
|
if (window != null) {
|
|
window.Close();
|
|
}
|
|
}
|
|
|
|
private void SetLight(object obj) {
|
|
PatternLightWindowManager.ShowLightSettingWindow(_fovInfo, _patternInfo);
|
|
}
|
|
|
|
private void SetPreProc(object obj) {
|
|
if (_childWindow == null) {
|
|
_childWindow = new PreProcessingWindow(_patternInfo, _milCameraDisplay);
|
|
(_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) {
|
|
var milImage = _milCameraDisplay.GetImage();
|
|
if (milImage != 0) {
|
|
var imageSize = MilEnvironment.GetImageSize(milImage);
|
|
var findRoi = GetFindROIFromRunParam(imageSize, RunParam);
|
|
_milCameraDisplay.AddFindRoi(findRoi);
|
|
}
|
|
}
|
|
|
|
private ROI GetFindROIFromRunParam(ImageSize imageSize, CodeRunParam runParam) {
|
|
if (runParam.IsValidFindRoi(imageSize)) {
|
|
return runParam.GetFindRoi();
|
|
}
|
|
|
|
return new ROI(
|
|
new ImagePoint(imageSize.Width * 0.5, imageSize.Height * 0.5),
|
|
100, 300,
|
|
Angle.CreateWithDegree(0));
|
|
}
|
|
|
|
private void FindPattern(object obj) {
|
|
if (!_patternInfo.IsActivated) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_PatternNotActivated);
|
|
return;
|
|
}
|
|
|
|
if (_milCameraDisplay != null) {
|
|
var image = _milCameraDisplay.GetImage();
|
|
if (image == null) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_ImageNotReady);
|
|
return;
|
|
}
|
|
if (_milCameraDisplay.HasFindRoi()) {
|
|
RunParam.SetFindROI(_milCameraDisplay.GetFindRoi().Clone() as ROI);
|
|
}
|
|
|
|
_milCameraDisplay.ClearFindGraphics();
|
|
_milCameraDisplay.ClearMeasureGraphics();
|
|
|
|
_patternAgent.SetRunParam(_patternInfo, RunParam);
|
|
var patternResult = _patternAgent.Find(_patternInfo, image);
|
|
_patternAgent.Draw(_patternInfo, patternResult, _milCameraDisplay);
|
|
|
|
if (patternResult.Status == eFoundStatus.NotFound) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_PatternNotFound);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |