check point
This commit is contained in:
102
VisionBuilder.UI.Common/ViewModel/ErrorPreviewVM.cs
Normal file
102
VisionBuilder.UI.Common/ViewModel/ErrorPreviewVM.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using OpenCvSharp;
|
||||
using VisionBuilder.UI.Common.Commands;
|
||||
using VisionBuilder.UI.Common.Commands.Interfaces;
|
||||
using VisionBuilder.UI.Common.ViewModel.Classes;
|
||||
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace VisionBuilder.UI.Common.ViewModel;
|
||||
|
||||
public partial class ErrorPreviewVM:ObservableObject
|
||||
{
|
||||
|
||||
private ErrorsVM _errorsVm;
|
||||
private ErrorData _errorData;
|
||||
|
||||
private readonly ILearningTool _learningTool;
|
||||
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
private string _recipeName;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _learnButtonVisible;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isNextImageEnabled;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isPreviousImageEnabled;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _imageName;
|
||||
|
||||
[ObservableProperty]
|
||||
private Mat _imageAnalysis;
|
||||
|
||||
public ErrorPreviewVM(ErrorsVM errorsVm, ErrorData errorData, string recipeName, UIConfiguration uiConfiguration, ILearningTool learningTool)
|
||||
{
|
||||
_errorsVm = errorsVm;
|
||||
_errorData = errorData;
|
||||
_recipeName = recipeName;
|
||||
_learningTool = learningTool;
|
||||
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[RelayCommand(CanExecute = nameof(IsNextImageEnabled))]
|
||||
public void NextImage()
|
||||
{
|
||||
var imageIndex = _errorsVm.Errors.IndexOf(_errorData);
|
||||
if (imageIndex >= _errorsVm.Errors.Count) return;
|
||||
imageIndex++;
|
||||
_errorData = _errorsVm.Errors[imageIndex];
|
||||
UpdateData();
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(IsPreviousImageEnabled))]
|
||||
public void PreviousImage()
|
||||
{
|
||||
var imageIndex = _errorsVm.Errors.IndexOf(_errorData);
|
||||
if (imageIndex <= 0) return;
|
||||
imageIndex--;
|
||||
_errorData = _errorsVm.Errors[imageIndex];
|
||||
UpdateData();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void UpdateData()
|
||||
{
|
||||
var imageIndex = _errorsVm.Errors.IndexOf(_errorData);
|
||||
|
||||
if (imageIndex < 0)
|
||||
{
|
||||
IsNextImageEnabled = false;
|
||||
IsPreviousImageEnabled = false;
|
||||
ImageName = string.Empty;
|
||||
ImageAnalysis = null;
|
||||
return;
|
||||
}
|
||||
|
||||
IsNextImageEnabled = imageIndex < _errorsVm.Errors.Count - 1;
|
||||
IsPreviousImageEnabled = imageIndex > 0;
|
||||
ImageName = _errorData.Title;
|
||||
ImageAnalysis = _errorData.ImageAnalysis;
|
||||
LearnButtonVisible = _learningTool.IsLearningEnabled(_errorData.RecipeName);
|
||||
}
|
||||
|
||||
[RelayCommand(CanExecute = nameof(LearnButtonVisible))]
|
||||
public void Learn()
|
||||
{
|
||||
_learningTool.Learn(_errorData.RecipeName, _errorData.ImageOriginal);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user