mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 11:06:30 +00:00
fix initialization, throttle operations
day/winter/night switcher fixes
This commit is contained in:
@@ -22,10 +22,10 @@ public partial class DatasetExplorer
|
||||
private readonly AnnotationConfig _annotationConfig;
|
||||
private readonly DirectoriesConfig _directoriesConfig;
|
||||
|
||||
private Dictionary<int, List<Annotation>> _annotationsDict = new();
|
||||
private readonly Dictionary<int, List<Annotation>> _annotationsDict;
|
||||
private readonly CancellationTokenSource _cts = new();
|
||||
|
||||
public ObservableCollection<DetectionClass> AllDetectionClasses { get; set; } = new();
|
||||
public List<DetectionClass> AllDetectionClasses { get; set; }
|
||||
public ObservableCollection<AnnotationThumbnail> SelectedAnnotations { get; set; } = new();
|
||||
public readonly Dictionary<string, AnnotationThumbnail> SelectedAnnotationDict = new();
|
||||
|
||||
@@ -34,6 +34,8 @@ public partial class DatasetExplorer
|
||||
private readonly IDbFactory _dbFactory;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public readonly List<DetectionClass> AnnotationsClasses;
|
||||
|
||||
|
||||
public bool ThumbnailLoading { get; set; }
|
||||
|
||||
@@ -48,6 +50,8 @@ public partial class DatasetExplorer
|
||||
IDbFactory dbFactory,
|
||||
IMediator mediator)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_directoriesConfig = directoriesConfig.Value;
|
||||
_annotationConfig = annotationConfig.Value;
|
||||
_logger = logger;
|
||||
@@ -55,7 +59,13 @@ public partial class DatasetExplorer
|
||||
_dbFactory = dbFactory;
|
||||
_mediator = mediator;
|
||||
|
||||
InitializeComponent();
|
||||
var photoModes = Enum.GetValues(typeof(PhotoMode)).Cast<PhotoMode>().ToList();
|
||||
_annotationsDict = _annotationConfig.DetectionClasses.SelectMany(cls => photoModes.Select(mode => (int)mode + cls.Id))
|
||||
.ToDictionary(x => x, _ => new List<Annotation>());
|
||||
_annotationsDict.Add(-1, []);
|
||||
|
||||
AnnotationsClasses = annotationConfig.Value.DetectionClasses;
|
||||
|
||||
Loaded += OnLoaded;
|
||||
Activated += (_, _) => formState.ActiveWindow = WindowEnum.DatasetExplorer;
|
||||
|
||||
@@ -86,15 +96,29 @@ public partial class DatasetExplorer
|
||||
Dispatcher.Invoke(() => RefreshThumbBar.Value = thumbnailsPercentage);
|
||||
};
|
||||
Closing += (_, _) => _cts.Cancel();
|
||||
|
||||
AllDetectionClasses = new List<DetectionClass>(
|
||||
new List<DetectionClass> { new() {Id = -1, Name = "All", ShortName = "All"}}
|
||||
.Concat(_annotationConfig.DetectionClasses));
|
||||
LvClasses.Init(AllDetectionClasses);
|
||||
|
||||
_dbFactory.Run(async db =>
|
||||
{
|
||||
var allAnnotations = await db.Annotations
|
||||
.LoadWith(x => x.Detections)
|
||||
.OrderBy(x => x.AnnotationStatus)
|
||||
.ThenByDescending(x => x.CreatedDate)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var annotation in allAnnotations)
|
||||
AddAnnotationToDict(annotation);
|
||||
}).GetAwaiter().GetResult();
|
||||
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
private async void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
AllDetectionClasses = new ObservableCollection<DetectionClass>(
|
||||
new List<DetectionClass> { new() {Id = -1, Name = "All", ShortName = "All"}}
|
||||
.Concat(_annotationConfig.AnnotationClasses));
|
||||
LvClasses.DetectionDataGrid.ItemsSource = AllDetectionClasses;
|
||||
|
||||
LvClasses.DetectionClassChanged += async (_, args) =>
|
||||
{
|
||||
ExplorerEditor.CurrentAnnClass = args.DetectionClass;
|
||||
@@ -106,20 +130,8 @@ public partial class DatasetExplorer
|
||||
ann.DetectionClass = args.DetectionClass;
|
||||
};
|
||||
|
||||
ExplorerEditor.CurrentAnnClass = (DetectionClass)LvClasses.CurrentDetectionClass;
|
||||
ExplorerEditor.CurrentAnnClass = LvClasses.CurrentDetectionClass ?? _annotationConfig.DetectionClasses.First();
|
||||
|
||||
await _dbFactory.Run(async db =>
|
||||
{
|
||||
var allAnnotations = await db.Annotations
|
||||
.LoadWith(x => x.Detections)
|
||||
.OrderBy(x => x.AnnotationStatus)
|
||||
.ThenByDescending(x => x.CreatedDate)
|
||||
.ToListAsync();
|
||||
_annotationsDict = AllDetectionClasses.ToDictionary(x => x.Id, _ => new List<Annotation>());
|
||||
|
||||
foreach (var annotation in allAnnotations)
|
||||
AddAnnotationToDict(annotation);
|
||||
});
|
||||
await ReloadThumbnails();
|
||||
await LoadClassDistribution();
|
||||
|
||||
@@ -239,7 +251,7 @@ public partial class DatasetExplorer
|
||||
AnnotationsTab.Visibility = Visibility.Collapsed;
|
||||
EditorTab.Visibility = Visibility.Visible;
|
||||
_tempSelectedClassIdx = LvClasses.CurrentClassNumber;
|
||||
LvClasses.DetectionDataGrid.ItemsSource = _annotationConfig.AnnotationClasses;
|
||||
LvClasses.DetectionDataGrid.ItemsSource = _annotationConfig.DetectionClasses;
|
||||
|
||||
Switcher.SelectedIndex = 1;
|
||||
LvClasses.SelectNum(Math.Max(0, _tempSelectedClassIdx - 1));
|
||||
|
||||
Reference in New Issue
Block a user