add offset

fixes
add visual validation border and validate functionality
This commit is contained in:
Alex Bezdieniezhnykh
2024-12-28 15:51:27 +02:00
parent 5fe46cd6f5
commit 8b94837f18
27 changed files with 251 additions and 128 deletions
+31 -16
View File
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
@@ -8,6 +7,8 @@ using Azaion.Common.Database;
using Azaion.Common.DTO;
using Azaion.Common.DTO.Config;
using Azaion.Common.Services;
using Azaion.CommonSecurity.DTO;
using Azaion.CommonSecurity.Services;
using LinqToDB;
using MediatR;
using Microsoft.Extensions.Logging;
@@ -26,13 +27,15 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
private Dictionary<int, List<Annotation>> _annotationsDict;
public ObservableCollection<AnnotationImageView> SelectedAnnotations { get; set; } = new();
private ObservableCollection<DetectionClass> AllAnnotationClasses { get; set; } = new();
public ObservableCollection<DetectionClass> AllAnnotationClasses { get; set; } = new();
public Dictionary<string, LabelInfo> LabelsCache { get; set; } = new();
private Dictionary<string, LabelInfo> LabelsCache { get; set; } = new();
private int _tempSelectedClassIdx = 0;
private readonly IGalleryService _galleryService;
private readonly IDbFactory _dbFactory;
private readonly IMediator _mediator;
private readonly AzaionApiClient _apiClient;
public bool ThumbnailLoading { get; set; }
@@ -44,13 +47,17 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
ILogger<DatasetExplorer> logger,
IGalleryService galleryService,
FormState formState,
IDbFactory dbFactory)
IDbFactory dbFactory,
IMediator mediator,
AzaionApiClient apiClient)
{
_directoriesConfig = directoriesConfig.Value;
_annotationConfig = annotationConfig.Value;
_logger = logger;
_galleryService = galleryService;
_dbFactory = dbFactory;
_mediator = mediator;
_apiClient = apiClient;
InitializeComponent();
Loaded += OnLoaded;
@@ -73,14 +80,11 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
ThumbnailsView.SelectionChanged += (_, _) =>
{
StatusText.Text = $"Обрано: {ThumbnailsView.SelectedItems.Count} | {ThumbnailsView.SelectedIndex} / {SelectedAnnotations.Count}";
ValidateBtn.Visibility = ThumbnailsView.SelectedItems.Cast<AnnotationImageView>().Any(x => x.IsSeed)
? Visibility.Visible
: Visibility.Hidden;
};
ExplorerEditor.GetTimeFunc = () => Constants.GetTime(CurrentAnnotation!.Annotation.ImagePath);
galleryService.ThumbnailsUpdate += thumbnailsPercentage =>
{
Dispatcher.Invoke(() => RefreshThumbBar.Value = thumbnailsPercentage);
};
}
private async void OnLoaded(object sender, RoutedEventArgs e)
@@ -135,7 +139,6 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
await ReloadThumbnails();
await LoadClassDistribution();
RefreshThumbBar.Value = _galleryService.ProcessedThumbnailsPercentage;
DataContext = this;
}
@@ -285,18 +288,30 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
SelectedAnnotations.Add(new AnnotationImageView(ann));
}
private void AddThumbnail(Annotation annotation)
public async Task Handle(AnnotationCreatedEvent notification, CancellationToken cancellationToken)
{
var annotation = notification.Annotation;
var selectedClass = ((DetectionClass?)LvClasses.SelectedItem)?.Id;
if (selectedClass == null)
return;
//TODO: For editing existing need to handle updates
AddAnnotationToDict(annotation);
if (annotation.Classes.Contains(selectedClass.Value))
{
SelectedAnnotations.Add(new AnnotationImageView(annotation));
}
}
public async Task Handle(AnnotationCreatedEvent notification, CancellationToken cancellationToken) =>
AddThumbnail(notification.Annotation);
}
private async void ValidateAnnotationsClick(object sender, RoutedEventArgs e)
{
try
{
await _mediator.Publish(new DatasetExplorerControlEvent(PlaybackControlEnum.ValidateAnnotations));
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
}
}
}