Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions EDSEditorGUI2/Converter/BrushConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;
using Avalonia.Media;

namespace EDSEditorGUI2.Converter;

public sealed class BrushConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
// TODO: Get theme and use the correct brush based on that
if (value is Boolean bValue)
{
if (bValue)
{
return new SolidColorBrush(Colors.Red);
}
else
{
var currentThemeVariant = Application.Current?.ActualThemeVariant;

// TODO: figure out how to get the default forground from theme instead of hardcoding it
if (currentThemeVariant == Avalonia.Styling.ThemeVariant.Dark)
{
return new SolidColorBrush(Colors.White);
}
else
{
return new SolidColorBrush(Colors.Black);
}
}
}
return new SolidColorBrush(Colors.Orange);
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
11 changes: 11 additions & 0 deletions EDSEditorGUI2/EDSEditorGUI2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
<ProjectReference Include="..\libEDSsharp\libEDSsharp.csproj" />
</ItemGroup>

<Target Name="CopyProfilesDirectory" AfterTargets="Build">
<ItemGroup>
<ResourceFiles Include="../EDSEditorGUI/Profiles/**/*.*" />
</ItemGroup>

<Copy
SourceFiles="@(ResourceFiles)"
DestinationFolder="$(OutDir)Profiles\%(RecursiveDir)"
SkipUnchangedFiles="true" />
</Target>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.5" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.5" />
Expand Down
2 changes: 2 additions & 0 deletions EDSEditorGUI2/Icons.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PathIcon Data="{StaticResource remove_regular}" />
<PathIcon Data="{StaticResource add_regular}" />
<PathIcon Data="{StaticResource save_regular}" />
<PathIcon Data="{StaticResource book_add_regular}" />
</StackPanel>
</Border>
</Design.PreviewWith>
Expand All @@ -16,6 +17,7 @@
<StreamGeometry x:Key="remove_regular">M3.7547787,12.4995322 L20.2466903,12.4995322 C20.6609039,12.4995322 20.9966903,12.1637458 20.9966903,11.7495322 C20.9966903,11.3353187 20.6609039,10.9995322 20.2466903,10.9995322 L3.7547787,10.9995322 C3.34056514,10.9995322 3.0047787,11.3353187 3.0047787,11.7495322 C3.0047787,12.1637458 3.34056514,12.4995322 3.7547787,12.4995322 Z</StreamGeometry>
<StreamGeometry x:Key="add_regular">M14.5,13 L14.5,3.75378577 C14.5,3.33978577 14.164,3.00378577 13.75,3.00378577 C13.336,3.00378577 13,3.33978577 13,3.75378577 L13,13 L3.75387573,13 C3.33987573,13 3.00387573,13.336 3.00387573,13.75 C3.00387573,14.164 3.33987573,14.5 3.75387573,14.5 L13,14.5 L13,23.7523651 C13,24.1663651 13.336,24.5023651 13.75,24.5023651 C14.164,24.5023651 14.5,24.1663651 14.5,23.7523651 L14.5,14.5 L23.7498262,14.5030754 C24.1638262,14.5030754 24.4998262,14.1670754 24.4998262,13.7530754 C24.4998262,13.3390754 24.1638262,13.0030754 23.7498262,13.0030754 L14.5,13 Z</StreamGeometry>
<StreamGeometry x:Key="save_regular">M3 5.75C3 4.23122 4.23122 3 5.75 3H15.7145C16.5764 3 17.4031 3.34241 18.0126 3.9519L20.0481 5.98744C20.6576 6.59693 21 7.42358 21 8.28553V18.25C21 19.7688 19.7688 21 18.25 21H5.75C4.23122 21 3 19.7688 3 18.25V5.75ZM5.75 4.5C5.05964 4.5 4.5 5.05964 4.5 5.75V18.25C4.5 18.9404 5.05964 19.5 5.75 19.5H6V14.25C6 13.0074 7.00736 12 8.25 12H15.75C16.9926 12 18 13.0074 18 14.25V19.5H18.25C18.9404 19.5 19.5 18.9404 19.5 18.25V8.28553C19.5 7.8214 19.3156 7.37629 18.9874 7.0481L16.9519 5.01256C16.6918 4.75246 16.3582 4.58269 16 4.52344V7.25C16 8.49264 14.9926 9.5 13.75 9.5H9.25C8.00736 9.5 7 8.49264 7 7.25V4.5H5.75ZM16.5 19.5V14.25C16.5 13.8358 16.1642 13.5 15.75 13.5H8.25C7.83579 13.5 7.5 13.8358 7.5 14.25V19.5H16.5ZM8.5 4.5V7.25C8.5 7.66421 8.83579 8 9.25 8H13.75C14.1642 8 14.5 7.66421 14.5 7.25V4.5H8.5Z</StreamGeometry>
<StreamGeometry x:Key="book_add_regular">M3 4.5C3 3.11929 4.11929 2 5.5 2H17C18.3807 2 19.5 3.11929 19.5 4.5V11.3135C19.0218 11.159 18.5195 11.0585 18 11.0189V4.5C18 3.94772 17.5523 3.5 17 3.5H5.5C4.94772 3.5 4.5 3.94772 4.5 4.5V18H11.0189C11.0585 18.5195 11.159 19.0218 11.3135 19.5H4.5C4.5 20.0523 4.94772 20.5 5.5 20.5H11.7322C12.0194 21.051 12.3832 21.5557 12.8096 22H5.5C4.11929 22 3 20.8807 3 19.5V4.5Z M17.5 12C20.5376 12 23 14.4624 23 17.5C23 20.5376 20.5376 23 17.5 23C14.4624 23 12 20.5376 12 17.5C12 14.4624 14.4624 12 17.5 12ZM18.0011 20.5035L18.0006 18H20.503C20.7792 18 21.003 17.7762 21.003 17.5C21.003 17.2239 20.7792 17 20.503 17H18.0005L18 14.4993C18 14.2231 17.7761 13.9993 17.5 13.9993C17.2239 13.9993 17 14.2231 17 14.4993L17.0005 17H14.4961C14.22 17 13.9961 17.2239 13.9961 17.5C13.9961 17.7762 14.22 18 14.4961 18H17.0006L17.0011 20.5035C17.0011 20.7797 17.225 21.0035 17.5011 21.0035C17.7773 21.0035 18.0011 20.7797 18.0011 20.5035Z M6 6C6 5.44772 6.44772 5 7 5H15C15.5523 5 16 5.44772 16 6V8C16 8.55228 15.5523 9 15 9H7C6.44772 9 6 8.55228 6 8V6ZM7.5 7.5H14.5V6.5H7.5V7.5Z</StreamGeometry>
</Styles.Resources>
</Styles>
</Styles>
12 changes: 12 additions & 0 deletions EDSEditorGUI2/ViewModels/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ public Device()
{
}

public override string ToString()
{
if (DeviceInfo == null)
{
return "unnamed device";
}
else
{
return DeviceInfo.ProductName;
}
}

[ObservableProperty]
private FileInfo _fileInfo = new();

Expand Down
111 changes: 108 additions & 3 deletions EDSEditorGUI2/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using EDSEditorGUI2.Mapper;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace EDSEditorGUI2.ViewModels;
Expand Down Expand Up @@ -33,13 +36,115 @@ public void AddNewDevice(object sender)
var DeviceView = ProtobufferViewModelMapper.MapFromProtobuffer(device);
Network.Add(DeviceView);
}

public void InitMergeStatus(Device profile, List<int> offsets)
{
MergeStatus.Clear();
if (SelectedDevice is not null)
{
foreach (var obj in profile.Objects)
{
int mergeIndex = Int32.Parse(obj.Key);
List<ODIndexMergeOffsetStatus> objectOffset = [];
foreach (var offset in offsets)
{
objectOffset.Add(new(mergeIndex + offset, false));
}

ODIndexMergeStatus ms = new()
{
Insert = true,
OriginalObject = $"0x{mergeIndex:x} - {obj.Value.Name}",
Offsets = objectOffset,
OriginalIndex = mergeIndex,
#pragma warning disable MVVMTK0034 // Direct field reference to [ObservableProperty] backing field
_object = obj.Value,
#pragma warning restore MVVMTK0034 // Direct field reference to [ObservableProperty] backing field
TextBrush = new SolidColorBrush(Colors.Black),
};

MergeStatus.Add(ms);
}
UpdateMergeStatus(offsets);
}
}

/// <summary>
/// Update profile merge status by checking for collisions
/// </summary>
/// <param name="offsets">list of offsets in profile import</param>
public void UpdateMergeStatus(List<int> offsets)
{
if (SelectedDevice is not null && MergeStatus.Count != 0)
{
foreach (var obj in MergeStatus)
{
//first calculate all the offsets
//remember that the number of offsets could have changed
List<ODIndexMergeOffsetStatus> objectOffset = [];
foreach (var offset in offsets)
{
int mergeIndex = obj.OriginalIndex + offset;
objectOffset.Add(new(mergeIndex, false));
}
obj.Offsets = objectOffset;
}

// check for collision with selected device objects
foreach (var obj in MergeStatus)
{
foreach (var offsetStatus in obj.Offsets)
{
foreach (var ob in SelectedDevice.Objects)
{
if (offsetStatus.Index == ob.Key.ToInteger())
{
offsetStatus.Collision = true;
offsetStatus.Index *= -1;
}
}
}
}

// check for collision with other offsets objects, collum by collum
var numberOfOffsets = MergeStatus[0].Offsets.Count;

// Check each collum from left to right.
// you only check for collision with collums to the left
for (int i = 0; i < numberOfOffsets; i++)
{
foreach (var leftRow in MergeStatus)
{
int rightCollumIndex = leftRow.Offsets[i].Index;
for (int j = i; j >= 0; j--)
{
if (j != i)
{
foreach (var rightRow in MergeStatus)
{
int leftCollumIndex = rightRow.Offsets[j].Index;
if (rightCollumIndex == leftCollumIndex)
{
leftRow.Offsets[i].Collision = true;
}
}
}
}
}
}
}
}
#pragma warning disable CA1822 // Mark members as static
public string Greeting => "Welcome to Avalonia!";
#pragma warning restore CA1822 // Mark members as static
public ObservableCollection<Device> Network { get; set; } = [];

[ObservableProperty]
public Device? selectedDevice;
//Used for profile import
public ObservableCollection<ODIndexMergeStatus> MergeStatus { get; set; } = [];

[ObservableProperty]
public int _insertObjectsOffset;

[ObservableProperty]
public Device? _selectedDevice;
}
49 changes: 49 additions & 0 deletions EDSEditorGUI2/ViewModels/ODIndexMergeStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Avalonia.Media;
using CommunityToolkit.Mvvm.ComponentModel;
using System.Collections.Generic;

namespace EDSEditorGUI2.ViewModels;

/// <summary>
/// Viewmodel for merging one index
/// </summary>
public partial class ODIndexMergeOffsetStatus : ObservableObject
{
public ODIndexMergeOffsetStatus(int index, bool collision)
{
Index = index;
Collision = collision;
}
[ObservableProperty]
private int _index;

[ObservableProperty]
private bool _collision;
}

/// <summary>
/// Used as a view model when merging ODs or inserting profiles
/// </summary>
public partial class ODIndexMergeStatus : ObservableObject
{
[ObservableProperty]
private bool _insert;

[ObservableProperty]
private string _originalObject = string.Empty;

[ObservableProperty]
private List<ODIndexMergeOffsetStatus> _offsets = [];

[ObservableProperty]
private bool _indexCollision;

[ObservableProperty]
private int _originalIndex;

[ObservableProperty]
public required OdObject _object;

[ObservableProperty]
public IBrush _textBrush = new SolidColorBrush(Colors.Black);
}
42 changes: 36 additions & 6 deletions EDSEditorGUI2/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
xmlns:vm="using:EDSEditorGUI2.ViewModels"
xmlns:view="using:EDSEditorGUI2.Views"
xmlns:converter="using:EDSEditorGUI2.Converter"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
Expand All @@ -15,10 +17,10 @@
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainWindowViewModel/>
</Design.DataContext>

<dialogHost:DialogHost Identifier="RootDialogHost" >
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<Menu DockPanel.Dock="Top" x:Name="menu">
<MenuItem Header="_File" x:Name="fileMenu" >
<MenuItem Header="_New" Command="{Binding AddNewDevice}"/>
<MenuItem Header="_Open"/>
<MenuItem Header="_Save Project" IsEnabled="{Binding SelectedDevice, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
Expand All @@ -35,8 +37,7 @@
<Separator/>
<MenuItem Header="_Quit"/>
</MenuItem>
<MenuItem Header="_Insert Profile">
</MenuItem>
<MenuItem Header="_Insert Profile" x:Name="profileMenu" IsEnabled="{Binding SelectedDevice, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"/>
<MenuItem Header="_Reports">
</MenuItem>
<MenuItem Header="Tools">
Expand All @@ -55,7 +56,36 @@
</ListBox>
</StackPanel>
<view:DeviceView DataContext="{Binding SelectedDevice}" />
</DockPanel>
</DockPanel>
</dialogHost:DialogHost>

<Window.Resources>
<!-- Insert Objects dialog -->
<StackPanel x:Key="InsertObjectsDialog" MaxWidth="900">
<TextBlock Text="Target:" />
<ComboBox x:Name="InsertObjects_target" ItemsSource="{Binding Network}" SelectedItem="{Binding SelectedDevice}" MaxDropDownHeight="100" />
<TextBlock Text="Index Offset (single or space separated list for multiple insert)" />
<TextBox x:Name="InsertObjects_Offsets" Watermark="1 100 500" Text="0" TextChanged="OnOffsetTextChanged"/>

<ScrollViewer>
<DataGrid Margin="20" ItemsSource="{Binding MergeStatus}"
GridLinesVisibility="All"
BorderThickness="1" BorderBrush="Gray"
MaxHeight="500"
x:Name="grid">

<DataGrid.Columns>
<DataGridCheckBoxColumn Header="Insert" Width="*"
Binding="{Binding Insert}"/>
<DataGridTextColumn Header="Original Object" Width="*" IsReadOnly="True"
Binding="{Binding OriginalObject}" />
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>
<StackPanel Orientation="Horizontal">
<Button x:Name="InsertObjects_Insert" IsDefault="True" Margin="10" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}" CommandParameter="insert">Insert</Button>
<Button x:Name="InsertObjects_Cancel" IsCancel="True" Margin="10" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=dialogHost:DialogHost}, Path=CloseDialogCommand}">Cancel</Button>
</StackPanel>
</StackPanel>
</Window.Resources>
</Window>
Loading
Loading