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
12 changes: 12 additions & 0 deletions EDSEditor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDSSharp", "EDSSharp\EDSSharp.csproj", "{8B7A7545-6257-44BF-8868-F429E1B72C77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EDSEditorGUI2", "EDSEditorGUI2\EDSEditorGUI2.csproj", "{F175A47B-8BB8-480F-8D31-AF802086B8B4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GUITests", "GUITests\GUITests.csproj", "{9B9B5461-1864-484D-A49D-D39422DA16E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,6 +40,14 @@ Global
{8B7A7545-6257-44BF-8868-F429E1B72C77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8B7A7545-6257-44BF-8868-F429E1B72C77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8B7A7545-6257-44BF-8868-F429E1B72C77}.Release|Any CPU.Build.0 = Release|Any CPU
{F175A47B-8BB8-480F-8D31-AF802086B8B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F175A47B-8BB8-480F-8D31-AF802086B8B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F175A47B-8BB8-480F-8D31-AF802086B8B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F175A47B-8BB8-480F-8D31-AF802086B8B4}.Release|Any CPU.Build.0 = Release|Any CPU
{9B9B5461-1864-484D-A49D-D39422DA16E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B9B5461-1864-484D-A49D-D39422DA16E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B9B5461-1864-484D-A49D-D39422DA16E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B9B5461-1864-484D-A49D-D39422DA16E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 2 additions & 0 deletions EDSEditorGUI2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/obj/*
/bin/*
19 changes: 19 additions & 0 deletions EDSEditorGUI2/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia"
x:Class="EDSEditorGUI2.App"
xmlns:local="using:EDSEditorGUI2"
RequestedThemeVariant="Default">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.DataTemplates>
<local:ViewLocator/>
</Application.DataTemplates>

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
<StyleInclude Source="avares://EDSEditorGUI2/Icons.axaml"/>
<dialogHostAvalonia:DialogHostStyles />
</Application.Styles>
</Application>
32 changes: 32 additions & 0 deletions EDSEditorGUI2/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
using EDSEditorGUI2.ViewModels;
using EDSEditorGUI2.Views;

namespace EDSEditorGUI2;

public partial class App : Application
{
public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
// Line below is needed to remove Avalonia data validation.
// Without this line you will get duplicate validations from both Avalonia and CT
BindingPlugins.DataValidators.RemoveAt(0);
desktop.MainWindow = new MainWindow
{
DataContext = new MainWindowViewModel(),
};
}

base.OnFrameworkInitializationCompleted();
}
}
Binary file added EDSEditorGUI2/Assets/avalonia-logo.ico
Binary file not shown.
46 changes: 46 additions & 0 deletions EDSEditorGUI2/Converter/NewIndexMultiConvert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using Avalonia.Data;
using Avalonia.Data.Converters;
using Avalonia.Media.Immutable;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace EDSEditorGUI2.Converter;

public class NewIndexRequest(int index, string name, LibCanOpen.OdObject.Types.ObjectType type)
{
public int Index { get; } = index;
public string Name { get; } = name;
public LibCanOpen.OdObject.Types.ObjectType Type { get; } = type;
}

public sealed class NewIndexMultiConvert : IMultiValueConverter
{
public object? Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
// Ensure all bindings are provided and attached to correct target type
if (values?.Count != 3 || !targetType.IsAssignableFrom(typeof(ImmutableSolidColorBrush)))
throw new NotSupportedException();

if (values[0] is not string rawindex ||
values[1] is not string name ||
values[2] is not int typeIndex)
return BindingOperations.DoNothing;

int index = int.Parse(rawindex, NumberStyles.HexNumber);

var typeValues = Enum.GetNames(typeof(LibCanOpen.OdObject.Types.ObjectType)).Skip(1).ToArray();
bool parseOk = Enum.TryParse(typeValues[typeIndex], out LibCanOpen.OdObject.Types.ObjectType type);

if (parseOk)
{
var indexRequest = new NewIndexRequest(index, name, type);
return indexRequest;
}
else
{
return BindingOperations.DoNothing;
}
}
}
30 changes: 30 additions & 0 deletions EDSEditorGUI2/EDSEditorGUI2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>

<ItemGroup>
<Folder Include="Models\" />
<AvaloniaResource Include="Assets\**" />
<ProjectReference Include="..\libEDSsharp\libEDSsharp.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.5" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.5" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.5" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.5" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.5" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.1.5" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.5" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
<PackageReference Include="DialogHost.Avalonia" Version="0.8.1" />
<PackageReference Include="AutoMapper" Version="13.0.1" />
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions EDSEditorGUI2/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace EDSEditorGUI2
{
public static class StringExtensions
{
/// <summary>
/// Convert different types of hex/dec string to integer
/// </summary>
public static UInt16 ToInteger(this String val)
{
return (UInt16)Convert.ToInt32(val, 16);
}
}
}
21 changes: 21 additions & 0 deletions EDSEditorGUI2/Icons.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<Border Padding="5" >
<StackPanel Orientation="Vertical" >
<PathIcon Data="{StaticResource remove_regular}" />
<PathIcon Data="{StaticResource add_regular}" />
<PathIcon Data="{StaticResource save_regular}" />
</StackPanel>
</Border>
</Design.PreviewWith>

<!-- source http://avaloniaui.github.io/icons.html -->
<Styles>
<Styles.Resources>
<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>
</Styles.Resources>
</Styles>
</Styles>
51 changes: 51 additions & 0 deletions EDSEditorGUI2/Mapper/ProtobufferViewModelMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using AutoMapper;
using Google.Protobuf.WellKnownTypes;
using LibCanOpen;
using System;

namespace EDSEditorGUI2.Mapper
{
public partial class ProtobufferViewModelMapper
{
public static ViewModels.Device MapFromProtobuffer(CanOpenDevice source)
{
var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Timestamp, DateTime>().ConvertUsing(ts => ts.ToDateTime());
cfg.CreateMap<CanOpen_FileInfo, ViewModels.FileInfo>()
.ForMember(dest => dest.FileVersion, opt => opt.MapFrom(src => src.FileVersion))
.ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
.ForMember(dest => dest.CreationTime, opt => opt.MapFrom(src => src.CreationTime))
.ForMember(dest => dest.CreatedBy, opt => opt.MapFrom(src => src.CreatedBy))
.ForMember(dest => dest.ModificationTime, opt => opt.MapFrom(src => src.ModificationTime))
.ForMember(dest => dest.ModifiedBy, opt => opt.MapFrom(src => src.ModifiedBy));
cfg.CreateMap<CanOpenDevice, ViewModels.Device>()
.ForMember(dest => dest.FileInfo, opt => opt.MapFrom(src => src.FileInfo))
.ForMember(dest => dest.DeviceInfo, opt => opt.MapFrom(src => src.DeviceInfo))
.ForMember(dest => dest.DeviceCommissioning, opt => opt.MapFrom(src => src.DeviceCommissioning))
.ForPath(dest => dest.Objects.Data, opt => opt.MapFrom(src => src.Objects));

cfg.CreateMap<CanOpen_DeviceInfo, ViewModels.DeviceInfo>();
cfg.CreateMap<CanOpen_DeviceCommissioning, ViewModels.DeviceCommissioning>();
cfg.CreateMap<OdObject, ViewModels.OdObject>();

});
config.AssertConfigurationIsValid();
var mapper = config.CreateMapper();
var result = mapper.Map<ViewModels.Device>(source);
return result;
}

public static CanOpenDevice MapToProtobuffer(ViewModels.Device source)
{
var config = new MapperConfiguration(cfg =>
{
//TODO
});
config.AssertConfigurationIsValid();
var mapper = config.CreateMapper();
var result = mapper.Map<CanOpenDevice>(source);
return result;
}
}
}
21 changes: 21 additions & 0 deletions EDSEditorGUI2/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Avalonia;
using System;

namespace EDSEditorGUI2;

sealed class Program
{
// Initialization code. Don't use any Avalonia, third-party APIs or any
// SynchronizationContext-reliant code before AppMain is called: things aren't initialized
// yet and stuff might break.
[STAThread]
public static void Main(string[] args) => BuildAvaloniaApp()
.StartWithClassicDesktopLifetime(args);

// Avalonia configuration, don't remove; also used by visual designer.
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
33 changes: 33 additions & 0 deletions EDSEditorGUI2/ViewLocator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using EDSEditorGUI2.ViewModels;
using System;

namespace EDSEditorGUI2;

public class ViewLocator : IDataTemplate
{

public Control? Build(object? data)
{
if (data is null)
return null;

var name = data.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal);
var type = Type.GetType(name);

if (type != null)
{
var control = (Control)Activator.CreateInstance(type)!;
control.DataContext = data;
return control;
}

return new TextBlock { Text = "Not Found: " + name };
}

public bool Match(object? data)
{
return data is ViewModelBase;
}
}
29 changes: 29 additions & 0 deletions EDSEditorGUI2/ViewModels/Device.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CommunityToolkit.Mvvm.ComponentModel;

namespace EDSEditorGUI2.ViewModels
{
public partial class Device : ObservableObject
{
public Device()
{
}

[ObservableProperty]
private FileInfo _fileInfo = new();

[ObservableProperty]
private DeviceInfo _deviceInfo = new();

[ObservableProperty]
private DeviceCommissioning _deviceCommissioning = new();

[ObservableProperty]
private DeviceOD _objects = new();

public void OnClickCommand()
{
// do something
}
}
}

16 changes: 16 additions & 0 deletions EDSEditorGUI2/ViewModels/DeviceCommissioning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using CommunityToolkit.Mvvm.ComponentModel;
using System;

namespace EDSEditorGUI2.ViewModels;

public partial class DeviceCommissioning : ObservableObject
{
[ObservableProperty]
private UInt32 _nodeId;

[ObservableProperty]
private string _nodeName = string.Empty;

[ObservableProperty]
private UInt32 _baudrate;
}
Loading
Loading