mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 09:06:30 +00:00
big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@@ -63,6 +63,11 @@ public partial class Annotator
|
||||
public CameraConfig Camera => _appConfig?.CameraConfig ?? new CameraConfig();
|
||||
private static readonly Guid ReloadTaskId = Guid.NewGuid();
|
||||
|
||||
private readonly IAnnotationPathResolver _pathResolver;
|
||||
private readonly IDetectionClassProvider _classProvider;
|
||||
|
||||
public IDetectionClassProvider ClassProvider => _classProvider;
|
||||
|
||||
public Annotator(
|
||||
IConfigUpdater configUpdater,
|
||||
IOptions<AppConfig> appConfig,
|
||||
@@ -75,8 +80,12 @@ public partial class Annotator
|
||||
IDbFactory dbFactory,
|
||||
IInferenceService inferenceService,
|
||||
IInferenceClient inferenceClient,
|
||||
IGpsMatcherService gpsMatcherService)
|
||||
IGpsMatcherService gpsMatcherService,
|
||||
IAnnotationPathResolver pathResolver,
|
||||
IDetectionClassProvider classProvider)
|
||||
{
|
||||
_pathResolver = pathResolver;
|
||||
_classProvider = classProvider;
|
||||
// Initialize configuration and services BEFORE InitializeComponent so bindings can see real values
|
||||
_appConfig = appConfig.Value;
|
||||
_configUpdater = configUpdater;
|
||||
@@ -270,9 +279,10 @@ public partial class Annotator
|
||||
{
|
||||
Dispatcher.Invoke(async () =>
|
||||
{
|
||||
if (showImage && !annotation.IsSplit && File.Exists(annotation.ImagePath))
|
||||
var imagePath = _pathResolver.GetImagePath(annotation);
|
||||
if (showImage && !annotation.IsSplit && File.Exists(imagePath))
|
||||
{
|
||||
Editor.SetBackground(await annotation.ImagePath.OpenImage());
|
||||
Editor.SetBackground(await imagePath.OpenImage());
|
||||
_formState.BackgroundTime = annotation.Time;
|
||||
}
|
||||
|
||||
@@ -648,11 +658,30 @@ public partial class Annotator
|
||||
|
||||
public class GradientStyleSelector : StyleSelector
|
||||
{
|
||||
public static readonly DependencyProperty ClassProviderProperty = DependencyProperty.RegisterAttached(
|
||||
"ClassProvider",
|
||||
typeof(IDetectionClassProvider),
|
||||
typeof(GradientStyleSelector),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public static void SetClassProvider(DependencyObject element, IDetectionClassProvider value)
|
||||
{
|
||||
element.SetValue(ClassProviderProperty, value);
|
||||
}
|
||||
|
||||
public static IDetectionClassProvider GetClassProvider(DependencyObject element)
|
||||
{
|
||||
return (IDetectionClassProvider)element.GetValue(ClassProviderProperty);
|
||||
}
|
||||
|
||||
public override Style? SelectStyle(object item, DependencyObject container)
|
||||
{
|
||||
if (container is not DataGridRow row || row.DataContext is not Annotation result)
|
||||
return null;
|
||||
|
||||
var dataGrid = FindParent<DataGrid>(row);
|
||||
var classProvider = dataGrid != null ? GetClassProvider(dataGrid) : null;
|
||||
|
||||
var style = new Style(typeof(DataGridRow));
|
||||
var brush = new LinearGradientBrush
|
||||
{
|
||||
@@ -661,16 +690,17 @@ public class GradientStyleSelector : StyleSelector
|
||||
};
|
||||
|
||||
var gradients = new List<GradientStop>();
|
||||
if (result.Colors.Count == 0)
|
||||
var colors = classProvider?.GetColors(result) ?? [];
|
||||
if (colors.Count == 0)
|
||||
{
|
||||
var color = (Color)ColorConverter.ConvertFromString("#40DDDDDD");
|
||||
gradients = [new GradientStop(color, 0.99)];
|
||||
}
|
||||
else
|
||||
{
|
||||
var increment = 1.0 / result.Colors.Count;
|
||||
var increment = 1.0 / colors.Count;
|
||||
var currentStop = increment;
|
||||
foreach (var c in result.Colors)
|
||||
foreach (var c in colors)
|
||||
{
|
||||
var resultColor = c.Color.ToConfidenceColor(c.Confidence);
|
||||
brush.GradientStops.Add(new GradientStop(resultColor, currentStop));
|
||||
@@ -683,4 +713,16 @@ public class GradientStyleSelector : StyleSelector
|
||||
style.Setters.Add(new Setter(Control.BackgroundProperty, brush));
|
||||
return style;
|
||||
}
|
||||
|
||||
private static T? FindParent<T>(DependencyObject child) where T : DependencyObject
|
||||
{
|
||||
var parent = VisualTreeHelper.GetParent(child);
|
||||
while (parent != null)
|
||||
{
|
||||
if (parent is T typedParent)
|
||||
return typedParent;
|
||||
parent = VisualTreeHelper.GetParent(parent);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user