From e2028123c56be69b41f517126367b9f26553cdbe Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Fri, 2 Aug 2024 03:03:12 +0200 Subject: [PATCH] generic fpga gui progress --- .../Fpga/Gui/FpgaGui.cs | 4 ++ .../Fpga/Gui/FpgaGuiElement.cs | 10 +++ .../FpgaGuiElementButtonViewModel.cs | 10 +++ .../FpgaGuiElementViewModelBase.cs | 14 ++++ .../ViewModels/GenericFpgaViewModel.cs | 68 +++++++++++++++++-- .../FpgaGuiElementButtonView.axaml | 9 +++ .../FpgaGuiElementButtonView.axaml.cs | 13 ++++ .../Views/GenericFpgaView.axaml | 37 +++++++--- 8 files changed, 151 insertions(+), 14 deletions(-) create mode 100644 src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGuiElement.cs create mode 100644 src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementButtonViewModel.cs create mode 100644 src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementViewModelBase.cs create mode 100644 src/OneWare.UniversalFpgaProjectSystem/Views/FpgaGuiElements/FpgaGuiElementButtonView.axaml create mode 100644 src/OneWare.UniversalFpgaProjectSystem/Views/FpgaGuiElements/FpgaGuiElementButtonView.axaml.cs diff --git a/src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGui.cs b/src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGui.cs index 471e0e85..8e46d173 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGui.cs +++ b/src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGui.cs @@ -5,4 +5,8 @@ public class FpgaGui public int Width { get; set; } public int Height { get; set; } + + public string? Image { get; set; } + + public FpgaGuiElement[]? Elements { get; set; } } \ No newline at end of file diff --git a/src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGuiElement.cs b/src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGuiElement.cs new file mode 100644 index 00000000..e3aea88a --- /dev/null +++ b/src/OneWare.UniversalFpgaProjectSystem/Fpga/Gui/FpgaGuiElement.cs @@ -0,0 +1,10 @@ +namespace OneWare.UniversalFpgaProjectSystem.Fpga.Gui; + +public class FpgaGuiElement +{ + public string? Type { get; set; } + + public int X { get; set; } + + public int Y { get; set; } +} \ No newline at end of file diff --git a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementButtonViewModel.cs b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementButtonViewModel.cs new file mode 100644 index 00000000..2a9b128a --- /dev/null +++ b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementButtonViewModel.cs @@ -0,0 +1,10 @@ +using OneWare.UniversalFpgaProjectSystem.Fpga.Gui; + +namespace OneWare.UniversalFpgaProjectSystem.ViewModels.FpgaGuiElements; + +public class FpgaGuiElementButtonViewModel : FpgaGuiElementViewModelBase +{ + public FpgaGuiElementButtonViewModel(FpgaGuiElement element) : base(element) + { + } +} \ No newline at end of file diff --git a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementViewModelBase.cs b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementViewModelBase.cs new file mode 100644 index 00000000..3bbaceb4 --- /dev/null +++ b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/FpgaGuiElements/FpgaGuiElementViewModelBase.cs @@ -0,0 +1,14 @@ +using CommunityToolkit.Mvvm.ComponentModel; +using OneWare.UniversalFpgaProjectSystem.Fpga.Gui; + +namespace OneWare.UniversalFpgaProjectSystem.ViewModels.FpgaGuiElements; + +public class FpgaGuiElementViewModelBase : ObservableObject +{ + public FpgaGuiElement Element { get; } + + public FpgaGuiElementViewModelBase(FpgaGuiElement element) + { + Element = element; + } +} \ No newline at end of file diff --git a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/GenericFpgaViewModel.cs b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/GenericFpgaViewModel.cs index 0903a2c6..3117ad74 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/GenericFpgaViewModel.cs +++ b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/GenericFpgaViewModel.cs @@ -1,18 +1,28 @@ +using System.Collections.ObjectModel; using System.Text.Json; +using CommunityToolkit.Mvvm.ComponentModel; using OneWare.Essentials.Helpers; using OneWare.Essentials.Services; using OneWare.UniversalFpgaProjectSystem.Fpga.Gui; using OneWare.UniversalFpgaProjectSystem.Models; +using OneWare.UniversalFpgaProjectSystem.ViewModels.FpgaGuiElements; using Prism.Ioc; namespace OneWare.UniversalFpgaProjectSystem.ViewModels; public class GenericFpgaViewModel : FpgaViewModelBase { - private FpgaGui? _fpgaGui; private readonly string _guiPath; private readonly IDisposable? _fileWatcher; + + private bool _isLoading; + + private int _width; + + private int _height; + + private string? _image; public GenericFpgaViewModel(FpgaModel fpgaModel, string guiPath) : base(fpgaModel) { @@ -23,27 +33,73 @@ public GenericFpgaViewModel(FpgaModel fpgaModel, string guiPath) : base(fpgaMode _fileWatcher = FileSystemWatcherHelper.WatchFile(guiPath, () => _ = LoadGuiAsync()); } - public FpgaGui? FpgaGui + public bool IsLoading + { + get => _isLoading; + set => SetProperty(ref _isLoading, value); + } + + public int Width + { + get => _width; + set => SetProperty(ref _width, value); + } + + public int Height { - get => _fpgaGui; - set => SetProperty(ref _fpgaGui, value); + get => _height; + set => SetProperty(ref _height, value); } + + public string? Image + { + get => _image; + set => SetProperty(ref _image, value); + } + + public ObservableCollection Elements { get; } = new(); private async Task LoadGuiAsync() { - Console.WriteLine("load"); + IsLoading = true; + Width = 0; + Height = 0; + Image = null; + Elements.Clear(); + try { await using var stream = File.OpenRead(_guiPath); - FpgaGui = await JsonSerializer.DeserializeAsync(stream, new JsonSerializerOptions() + var gui = await JsonSerializer.DeserializeAsync(stream, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true }); + + if (gui == null) + { + return; + } + + Width = gui.Width; + Height = gui.Height; + Image = gui.Image != null ? Path.Combine(Path.GetDirectoryName(_guiPath)!, gui.Image) : null; + + if (gui.Elements != null) + { + foreach (var element in gui.Elements) + { + if (element.Type == "button") + { + Elements.Add(new FpgaGuiElementButtonViewModel(element)); + } + } + } } catch (Exception e) { ContainerLocator.Container.Resolve().Error(e.Message, e); } + IsLoading = false; } public override void Dispose() diff --git a/src/OneWare.UniversalFpgaProjectSystem/Views/FpgaGuiElements/FpgaGuiElementButtonView.axaml b/src/OneWare.UniversalFpgaProjectSystem/Views/FpgaGuiElements/FpgaGuiElementButtonView.axaml new file mode 100644 index 00000000..1e20fa12 --- /dev/null +++ b/src/OneWare.UniversalFpgaProjectSystem/Views/FpgaGuiElements/FpgaGuiElementButtonView.axaml @@ -0,0 +1,9 @@ + +