Skip to content

Commit

Permalink
Add ability to create detector datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Neakita committed Sep 4, 2024
1 parent 311f30a commit 74f1eee
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 142 deletions.
4 changes: 2 additions & 2 deletions SightKeeper.Avalonia/DataSets/DataSetsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private async Task CreateDataSetAsync()
if (await _dialogManager.ShowDialogAsync(dialog))
_dataSetCreator.CreateDataSet(
dialog.DataSetEditor,
dialog.SpecificDataSetEditor.Tags,
dialog.SpecificDataSetEditor.DataSetType);
dialog.TagsEditor.Tags,
dialog.DataSetType);
}
}
21 changes: 4 additions & 17 deletions SightKeeper.Avalonia/DataSets/Dialogs/CreateDataSetDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SightKeeper.Avalonia.DataSets.Dialogs"
xmlns:specific="clr-namespace:SightKeeper.Avalonia.DataSets.Dialogs.Specific"
xmlns:icons="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SightKeeper.Avalonia.DataSets.Dialogs.CreateDataSetDialog"
Expand All @@ -12,23 +11,11 @@
<ScrollViewer>
<StackPanel Classes="regular-spacing">
<local:GeneralDataSetEditor DataContext="{Binding DataSetEditor}"/>
<ListBox SelectedItem="{Binding SpecificDataSetEditor}"
ItemsSource="{Binding SpecificDataSetEditors}"
<ListBox SelectedItem="{Binding DataSetType}"
ItemsSource="{Binding DataSetTypes}"
Theme="{DynamicResource RadioButtonsListBoxTheme}"
Classes="horizontal">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ContentControl Content="{Binding SpecificDataSetEditor}">
<ContentControl.DataTemplates>
<DataTemplate x:DataType="specific:ClassifierDataSetEditorViewModel">
<specific:ClassifierDataSetEditor/>
</DataTemplate>
</ContentControl.DataTemplates>
</ContentControl>
Classes="horizontal"/>
<local:TagsEditor DataContext="{Binding TagsEditor}"/>
<StackPanel Orientation="Horizontal"
Classes="regular-spacing"
HorizontalAlignment="Right">
Expand Down
27 changes: 12 additions & 15 deletions SightKeeper.Avalonia/DataSets/Dialogs/CreateDataSetViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
using System.Collections.Immutable;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Linq;
using CommunityToolkit.Diagnostics;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using SightKeeper.Avalonia.DataSets.Dialogs.Specific;
using SightKeeper.Avalonia.Dialogs;
using SightKeeper.Domain.Model.DataSets;

Expand All @@ -18,36 +16,35 @@ internal sealed partial class CreateDataSetViewModel : DialogViewModel<bool>, ID
protected override bool DefaultResult => false;

public DataSetEditorViewModel DataSetEditor { get; }
public TagsEditorViewModel TagsEditor { get; } = new();

public ImmutableArray<SpecificDataSetEditorViewModel> SpecificDataSetEditors { get; } =
public ImmutableArray<DataSetType> DataSetTypes { get; } =
[
new ClassifierDataSetEditorViewModel(),
new DetectorDataSetEditorViewModel(),
new Poser2DDataSetEditorViewModel(),
new Poser3DDataSetEditorViewModel()
DataSetType.Classifier,
DataSetType.Detector,
DataSetType.Poser2D,
DataSetType.Poser3D
];

public CreateDataSetViewModel(DataSetEditorViewModel dataSetDataSetEditor)
{
DataSetEditor = dataSetDataSetEditor;
DataSetEditor.Resolution = DataSet.DefaultResolution;
_specificDataSetEditor = SpecificDataSetEditors.First();
_dataSetType = DataSetTypes.First();
DataSetEditor.ErrorsChanged += OnDataSetEditorErrorsChanged;
_constructorDisposable = SpecificDataSetEditors.Select(editor => editor.IsValid).Cast<IObservable<bool>>()
.Aggregate((x, y) => x.Merge(y)).Subscribe(_ => ApplyCommand.NotifyCanExecuteChanged());
_constructorDisposable = TagsEditor.IsValid.Subscribe(_ => ApplyCommand.NotifyCanExecuteChanged());
}

public void Dispose()
{
DataSetEditor.Dispose();
DataSetEditor.ErrorsChanged -= OnDataSetEditorErrorsChanged;
foreach (var editor in SpecificDataSetEditors)
editor.Dispose();
TagsEditor.Dispose();
_constructorDisposable.Dispose();
}

[ObservableProperty] private SpecificDataSetEditorViewModel _specificDataSetEditor;
private IDisposable _constructorDisposable;
[ObservableProperty] private DataSetType _dataSetType;
private readonly IDisposable _constructorDisposable;

private void OnDataSetEditorErrorsChanged(object? sender, DataErrorsChangedEventArgs e)
{
Expand All @@ -63,6 +60,6 @@ private void Apply()

private bool CanApply()
{
return !DataSetEditor.HasErrors && SpecificDataSetEditor.IsValid;
return !DataSetEditor.HasErrors && TagsEditor.IsValid;
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<UserControl xmlns="https://github.com/avaloniaui"
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:SightKeeper.Avalonia.DataSets.Dialogs.Specific"
xmlns:local="clr-namespace:SightKeeper.Avalonia.DataSets.Dialogs"
xmlns:behaviors="clr-namespace:SightKeeper.Avalonia.Behaviors"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="SightKeeper.Avalonia.DataSets.Dialogs.Specific.ClassifierDataSetEditor"
x:DataType="local:ClassifierDataSetEditorViewModel">
<StackPanel Classes="regular-spacing">
x:Class="SightKeeper.Avalonia.DataSets.Dialogs.TagsEditor"
x:DataType="local:TagsEditorViewModel">
<StackPanel Classes="regular-spacing">
<Grid ColumnDefinitions="* 8 Auto">
<TextBox Grid.Column="0"
Name="TagNameTextBox"
Expand All @@ -28,12 +28,12 @@
</Interaction.Behaviors>
</Button>
</Grid>
<ItemsControl ItemsSource="{Binding Tags}">
<ItemsControl ItemsSource="{Binding Tags}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Name}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</UserControl>
</UserControl>
11 changes: 11 additions & 0 deletions SightKeeper.Avalonia/DataSets/Dialogs/TagsEditor.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Avalonia.Controls;

namespace SightKeeper.Avalonia.DataSets.Dialogs;

internal sealed partial class TagsEditor : UserControl
{
public TagsEditor()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reactive.Subjects;
using Avalonia.Collections;
using CommunityToolkit.Diagnostics;
using CommunityToolkit.Mvvm.Input;
using SightKeeper.Application.DataSets.Tags;
using SightKeeper.Avalonia.Extensions;
using SightKeeper.Domain.Model.DataSets;

namespace SightKeeper.Avalonia.DataSets.Dialogs.Specific;
namespace SightKeeper.Avalonia.DataSets.Dialogs;

internal sealed partial class ClassifierDataSetEditorViewModel : SpecificDataSetEditorViewModel
internal sealed partial class TagsEditorViewModel : ViewModel, IDisposable
{
public override string Header => "Classifier";
public override DataSetType DataSetType => DataSetType.Classifier;
public BehaviorObservable<bool> IsValid => _isValid;
public IReadOnlyCollection<TagViewModel> Tags => _tags;

public override IReadOnlyCollection<TagViewModel> Tags => _tags;

public ClassifierDataSetEditorViewModel() : base(true)
{
}

public override void Dispose()
public void Dispose()
{
base.Dispose();
foreach (var tag in Tags)
{
tag.PropertyChanged -= OnTagPropertyChanged;
tag.ErrorsChanged -= OnTagErrorsChanged;
}
}

private readonly BehaviorSubject<bool> _isValid = new(true);
private readonly AvaloniaList<TagViewModel> _tags = new();

[RelayCommand(CanExecute = nameof(CanAddTag))]
Expand Down

0 comments on commit 74f1eee

Please sign in to comment.