180 lines
7.2 KiB
C#
180 lines
7.2 KiB
C#
/*
|
|
* Copyright (c) 2025 LG Electronics Inc.
|
|
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
|
|
*/
|
|
using System;
|
|
using Aurora.Api;
|
|
using Aurora.Api.DataType;
|
|
using Aurora.View;
|
|
using VisionCommon;
|
|
using MilPattern;
|
|
using Hermes;
|
|
using MilCommon;
|
|
using VisionCommonUI;
|
|
using VisionCommonUI.Resources;
|
|
|
|
namespace MilUI {
|
|
public class MultiLineParamSettingViewModel : NotifyPropertyChangedBase, IGraEventSubscriber, IDisposable {
|
|
private Logger _logger = new Logger(typeof(MultiLineParamSettingViewModel).Name);
|
|
|
|
#region Binding Properties
|
|
private PatternInfo _PatternInfo;
|
|
public PatternInfo PatternInfo { get => _PatternInfo; set => SetProperty(ref _PatternInfo, value); }
|
|
|
|
private eRoiIdx _RoiIdx;
|
|
public eRoiIdx RoiIdx { get => _RoiIdx; set => SetProperty(ref _RoiIdx, value); }
|
|
|
|
private eColor _RoiColor = eColor.Cyan;
|
|
public eColor RoiColor { get => _RoiColor; set => SetProperty(ref _RoiColor, value); }
|
|
|
|
private LineFinderRunParam _runParam;
|
|
public LineFinderRunParam RunParam { get => _runParam; set => SetProperty(ref _runParam, value); }
|
|
#endregion
|
|
|
|
private PatternAgentBase _patternAgent;
|
|
private CameraDisplay _cameraDisplay;
|
|
private FovInfo _fovInfo;
|
|
|
|
public MultiLineParamSettingViewModel(
|
|
PatternAgentBase patternAgent, PatternInfo subPatternInfo, CameraDisplay cameraDisplay, FovInfo fovInfo, eRoiIdx roiIdx) {
|
|
|
|
_patternAgent = patternAgent;
|
|
_cameraDisplay = cameraDisplay;
|
|
_fovInfo = fovInfo;
|
|
|
|
PatternInfo = subPatternInfo;
|
|
RoiIdx = roiIdx;
|
|
|
|
CreatePattern();
|
|
|
|
_cameraDisplay.SetGraEventSubscriber(PatternInfo, this);
|
|
}
|
|
|
|
public void SetEnabled(bool isActivated) {
|
|
PatternInfo.IsActivated = isActivated;
|
|
}
|
|
|
|
public void CreatePattern() {
|
|
if (!_patternAgent.IsPatternExist(PatternInfo.GetPatternIndex())) {
|
|
if (E1.OK == _patternAgent.Create(PatternInfo)) {
|
|
PatternInfo.IsActivated = false;
|
|
RunParam = new LineFinderRunParam();
|
|
_patternAgent.SetRunParam(PatternInfo, RunParam);
|
|
|
|
if (E1.OK != _patternAgent.Save(PatternInfo)) {
|
|
_logger.FuncE("Failed to save multi line.");
|
|
}
|
|
}
|
|
else {
|
|
_logger.FuncE("Failed to create multi line.");
|
|
}
|
|
}
|
|
else {
|
|
RunParam = (_patternAgent.GetRunParam(PatternInfo) as LineFinderRunParam).Clone() as LineFinderRunParam;
|
|
}
|
|
|
|
RoiColor = RunParam.MrkParamExt.FindROI.RoiColor;
|
|
RunParam.MrkParamExt.FindROI.RoiIdx = RoiIdx;
|
|
RunParam.MrkParamExt.FindROI.Angle.Degree = ConvertDegreeDecimalPlaces(RunParam.MrkParamExt.FindROI.Angle.Degree);
|
|
}
|
|
|
|
public void ShowFindROI() {
|
|
RunParam.MrkParamExt.FindROI.RoiIdx = RoiIdx;
|
|
RunParam.MrkParamExt.FindROI.RoiColor = RoiColor;
|
|
|
|
_cameraDisplay.SetPatternInfo(PatternInfo, RunParam.MrkParamExt.FindROI.RoiIdx);
|
|
|
|
var milImage = _cameraDisplay.GetImage();
|
|
if (milImage != 0) {
|
|
var imageSize = MilEnvironment.GetImageSize(milImage);
|
|
var findRoi = GetFindROIFromRunParam(imageSize, RunParam);
|
|
_cameraDisplay.AddFindRoi(findRoi, true);
|
|
}
|
|
}
|
|
|
|
public void HideFindROI() {
|
|
_cameraDisplay.ClearFindRoi(RunParam.MrkParamExt.FindROI.RoiIdx);
|
|
_cameraDisplay.ClearFindLabelNumGraphics(RunParam.MrkParamExt.FindROI.RoiIdx);
|
|
}
|
|
|
|
public void Clear() {
|
|
var subPatternIndex = PatternInfo.GetPatternIndex();
|
|
PatternInfo = _patternAgent.GetPatternInfo(subPatternIndex).Clone() as PatternInfo;
|
|
|
|
RunParam = (_patternAgent.GetRunParam(PatternInfo) as LineFinderRunParam).Clone() as LineFinderRunParam;
|
|
RoiIdx = RunParam.MrkParamExt.FindROI.RoiIdx;
|
|
RoiColor = RunParam.MrkParamExt.FindROI.RoiColor;
|
|
RunParam.MrkParamExt.FindROI.Angle.Degree = ConvertDegreeDecimalPlaces(RunParam.MrkParamExt.FindROI.Angle.Degree);
|
|
|
|
if (PatternInfo.IsActivated) {
|
|
ShowFindROI();
|
|
}
|
|
}
|
|
|
|
public void Save() {
|
|
if (_cameraDisplay.HasFindRoi(RunParam.MrkParamExt.FindROI.RoiIdx)) {
|
|
RunParam.MrkParamExt.FindROI = _cameraDisplay.GetFindRoi(RunParam.MrkParamExt.FindROI.RoiIdx).Clone() as ROI;
|
|
}
|
|
RunParam.MrkParamExt.FindROI.RoiIdx = RoiIdx;
|
|
RunParam.MrkParamExt.FindROI.RoiColor = RoiColor;
|
|
|
|
_patternAgent.SetRunParam(PatternInfo, RunParam);
|
|
_patternAgent.Save(PatternInfo);
|
|
}
|
|
|
|
public void Find() {
|
|
var image = _cameraDisplay.GetImage();
|
|
if (image == null) {
|
|
MessageBoxUtil.ShowMessageBoxError(StrTokens.MSG_E_ImageNotReady);
|
|
return;
|
|
}
|
|
|
|
if (PatternInfo.IsActivated) {
|
|
_cameraDisplay.ClearMeasureGraphics();
|
|
|
|
if (_cameraDisplay.HasFindRoi(RunParam.MrkParamExt.FindROI.RoiIdx)) {
|
|
RunParam.MrkParamExt.FindROI = _cameraDisplay.GetFindRoi(RunParam.MrkParamExt.FindROI.RoiIdx).Clone() as ROI;
|
|
}
|
|
|
|
var oldRunParam = _patternAgent.GetRunParam(PatternInfo) as LineFinderRunParam;
|
|
_patternAgent.SetRunParam(PatternInfo, RunParam);
|
|
var patternResult = _patternAgent.Find(PatternInfo, image);
|
|
_patternAgent.Draw(PatternInfo, patternResult, _cameraDisplay);
|
|
_patternAgent.SetRunParam(PatternInfo, oldRunParam); // Find가 끝난 후, 원본 RunParam으로 복원
|
|
}
|
|
}
|
|
|
|
private ROI GetFindROIFromRunParam(ImageSize imageSize, LineFinderRunParam runParam) {
|
|
if ((0 < runParam.MrkParamExt.FindROI.Width && runParam.MrkParamExt.FindROI.Width < imageSize.Width) &&
|
|
(0 < runParam.MrkParamExt.FindROI.Height && runParam.MrkParamExt.FindROI.Height < imageSize.Height)) {
|
|
return runParam.MrkParamExt.FindROI.Clone() as ROI;
|
|
}
|
|
|
|
int pixelOffset = (int)runParam.MrkParamExt.FindROI.RoiIdx * 50;
|
|
return new ROI(
|
|
new ImagePoint(imageSize.Width * 0.5 + pixelOffset, imageSize.Height * 0.5 + pixelOffset),
|
|
100, 300,
|
|
Angle.CreateWithDegree(0),
|
|
RoiIdx,
|
|
RoiColor);
|
|
}
|
|
|
|
public void UpdateAngleOfFindRoi(double roiAngle) {
|
|
_cameraDisplay.UpdateAngleOfFindRoi(roiAngle, RunParam.MrkParamExt.FindROI.RoiIdx);
|
|
}
|
|
|
|
public void UpdateAngleOfRoi(eGraRoiType graRoiType, object param) {
|
|
if (graRoiType == eGraRoiType.FindRoi) {
|
|
RunParam.MrkParamExt.FindROI.Angle.Degree = ConvertDegreeDecimalPlaces((double)param);
|
|
NotifyPropertyChanged(nameof(RunParam));
|
|
}
|
|
}
|
|
|
|
private double ConvertDegreeDecimalPlaces(double degree) {
|
|
return Math.Round(degree, 1);
|
|
}
|
|
|
|
public void Dispose() {
|
|
}
|
|
}
|
|
} |