add db WIP 2, 80%

refactor, renames
This commit is contained in:
Alex Bezdieniezhnykh
2024-12-24 06:07:13 +02:00
parent 5fa18aa514
commit 48c9ccbfda
32 changed files with 499 additions and 459 deletions
+16 -16
View File
@@ -24,7 +24,7 @@ public class CanvasEditor : Canvas
private readonly TextBlock _classNameHint;
private Rectangle _curRec = new();
private AnnotationControl _curAnn = null!;
private DetectionControl _curAnn = null!;
private const int MIN_SIZE = 20;
private readonly TimeSpan _viewThreshold = TimeSpan.FromMilliseconds(400);
@@ -44,8 +44,8 @@ public class CanvasEditor : Canvas
set => SetValue(GetTimeFuncProp, value);
}
private AnnotationClass _currentAnnClass = null!;
public AnnotationClass CurrentAnnClass
private DetectionClass _currentAnnClass = null!;
public DetectionClass CurrentAnnClass
{
get => _currentAnnClass;
set
@@ -62,7 +62,7 @@ public class CanvasEditor : Canvas
}
}
public readonly List<AnnotationControl> CurrentAnns = new();
public readonly List<DetectionControl> CurrentDetections = new();
public CanvasEditor()
{
@@ -173,7 +173,7 @@ public class CanvasEditor : Canvas
SelectionState = SelectionState.AnnResizing;
_lastPos = e.GetPosition(this);
_curRec = (Rectangle)sender;
_curAnn = (AnnotationControl)((Grid)_curRec.Parent).Parent;
_curAnn = (DetectionControl)((Grid)_curRec.Parent).Parent;
e.Handled = true;
}
@@ -233,7 +233,7 @@ public class CanvasEditor : Canvas
private void AnnotationPositionStart(object sender, MouseEventArgs e)
{
_lastPos = e.GetPosition(this);
_curAnn = (AnnotationControl)sender;
_curAnn = (DetectionControl)sender;
if (!Keyboard.IsKeyDown(Key.LeftCtrl) && !Keyboard.IsKeyDown(Key.RightCtrl))
ClearSelections();
@@ -310,9 +310,9 @@ public class CanvasEditor : Canvas
});
}
public AnnotationControl CreateAnnotation(AnnotationClass annClass, TimeSpan? time, CanvasLabel canvasLabel)
public DetectionControl CreateAnnotation(DetectionClass annClass, TimeSpan? time, CanvasLabel canvasLabel)
{
var annotationControl = new AnnotationControl(annClass, time, AnnotationResizeStart, canvasLabel.Probability)
var annotationControl = new DetectionControl(annClass, time, AnnotationResizeStart, canvasLabel.Probability)
{
Width = canvasLabel.Width,
Height = canvasLabel.Height
@@ -321,40 +321,40 @@ public class CanvasEditor : Canvas
SetLeft(annotationControl, canvasLabel.X );
SetTop(annotationControl, canvasLabel.Y);
Children.Add(annotationControl);
CurrentAnns.Add(annotationControl);
CurrentDetections.Add(annotationControl);
_newAnnotationRect.Fill = new SolidColorBrush(annClass.Color);
return annotationControl;
}
#endregion
private void RemoveAnnotations(IEnumerable<AnnotationControl> listToRemove)
private void RemoveAnnotations(IEnumerable<DetectionControl> listToRemove)
{
foreach (var ann in listToRemove)
{
Children.Remove(ann);
CurrentAnns.Remove(ann);
CurrentDetections.Remove(ann);
}
}
public void RemoveAllAnns()
{
foreach (var ann in CurrentAnns)
foreach (var ann in CurrentDetections)
Children.Remove(ann);
CurrentAnns.Clear();
CurrentDetections.Clear();
}
public void RemoveSelectedAnns() => RemoveAnnotations(CurrentAnns.Where(x => x.IsSelected).ToList());
public void RemoveSelectedAnns() => RemoveAnnotations(CurrentDetections.Where(x => x.IsSelected).ToList());
private void ClearSelections()
{
foreach (var ann in CurrentAnns)
foreach (var ann in CurrentDetections)
ann.IsSelected = false;
}
public void ClearExpiredAnnotations(TimeSpan time)
{
var expiredAnns = CurrentAnns.Where(x =>
var expiredAnns = CurrentDetections.Where(x =>
x.Time.HasValue &&
Math.Abs((time - x.Time.Value).TotalMilliseconds) > _viewThreshold.TotalMilliseconds)
.ToList();