Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrof committed Nov 15, 2024
1 parent 05daa2e commit f564c4e
Show file tree
Hide file tree
Showing 22 changed files with 588 additions and 0 deletions.
6 changes: 6 additions & 0 deletions EDSEditor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ 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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -36,6 +38,10 @@ 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
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/*
15 changes: 15 additions & 0 deletions EDSEditorGUI2/App.axaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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 />
</Application.Styles>
</Application>
33 changes: 33 additions & 0 deletions EDSEditorGUI2/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core;
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.
27 changes: 27 additions & 0 deletions EDSEditorGUI2/EDSEditorGUI2.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<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.2.1" />
<PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.4" />
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.2.1" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.3.2" />
</ItemGroup>
</Project>
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 System;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using EDSEditorGUI2.ViewModels;

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;
}
}
47 changes: 47 additions & 0 deletions EDSEditorGUI2/ViewModels/Device.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommunityToolkit.Mvvm.ComponentModel;
using LibCanOpen;
using System.ComponentModel;
using System.Xml.Linq;

namespace EDSEditorGUI2.ViewModels
{
public partial class Device : ObservableObject
{
[ObservableProperty]
CanOpenDevice _model;
public Device(CanOpenDevice model) { Model = model;

Check warning on line 12 in EDSEditorGUI2/ViewModels/Device.cs

View workflow job for this annotation

GitHub Actions / build (net481, Debug)

Non-nullable field '_objects' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

_DeviceInfo = new(Model.DeviceInfo);
_DeviceInfo.PropertyChanged += (s, e) => { OnPropertyChanged(nameof(DeviceInfo)); };
//Model.Objects
}

private DeviceInfo _DeviceInfo;
public DeviceInfo DeviceInfo
{
get => _DeviceInfo;
set
{
Model.DeviceInfo = value.Model;
OnPropertyChanged(nameof(DeviceInfo));
}
}

private DeviceOD _objects;

Check warning on line 30 in EDSEditorGUI2/ViewModels/Device.cs

View workflow job for this annotation

GitHub Actions / build (net481, Debug)

Field 'Device._objects' is never assigned to, and will always have its default value null
public DeviceOD Objects
{
get => _objects;
set
{
//Model.Objects = value.Model;
OnPropertyChanged(nameof(Objects));
}
}

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

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

namespace EDSEditorGUI2.ViewModels
{
public partial class DeviceInfo : ObservableObject
{
[ObservableProperty]
private CanOpen_DeviceInfo _model;
public DeviceInfo(CanOpen_DeviceInfo model) { Model = model; }

public string VendorName
{
get => Model.VendorName;
set
{
Model.VendorName = value;
OnPropertyChanged(nameof(VendorName));
}
}
public string ProductName
{
get => Model.ProductName;
set
{
SetProperty(Model.ProductName, value, Model, (u, n) => u.ProductName = n);
}
}
public bool BaudRate10
{
get => Model.BaudRate10;
set
{
SetProperty(Model.BaudRate10, value, Model, (u, n) => u.BaudRate10 = n);
}
}
public bool BaudRate20
{
get => Model.BaudRate20;
set
{
SetProperty(Model.BaudRate20, value, Model, (u, n) => u.BaudRate20 = n);
}
}
public bool BaudRate50
{
get => Model.BaudRate50;
set
{
SetProperty(Model.BaudRate50, value, Model, (u, n) => u.BaudRate50 = n);
}
}
public bool BaudRate125
{
get => Model.BaudRate125;
set
{
SetProperty(Model.BaudRate125, value, Model, (u, n) => u.BaudRate125 = n);
}
}
public bool BaudRate250
{
get => Model.BaudRate250;
set
{
SetProperty(Model.BaudRate250, value, Model, (u, n) => u.BaudRate250 = n);
}
}
public bool BaudRate500
{
get => Model.BaudRate500;
set
{
SetProperty(Model.BaudRate500, value, Model, (u, n) => u.BaudRate500 = n);
}
}
public bool BaudRate800
{
get => Model.BaudRate800;
set
{
SetProperty(Model.BaudRate800, value, Model, (u, n) => u.BaudRate800 = n);
}
}
public bool BaudRate1000
{
get => Model.BaudRate1000;
set
{
SetProperty(Model.BaudRate1000, value, Model, (u, n) => u.BaudRate1000 = n);
}
}
public bool BaudRateAuto
{
get => Model.BaudRateAuto;
set
{
SetProperty(Model.BaudRateAuto, value, Model, (u, n) => u.BaudRateAuto = n);
}
}
public bool LssSlave
{
get => Model.LssSlave;
set
{
SetProperty(Model.LssSlave, value, Model, (u, n) => u.LssSlave = n);
}
}
public bool LssMaster
{
get => Model.LssMaster;
set
{
SetProperty(Model.LssMaster, value, Model, (u, n) => u.LssMaster = n);
}
}
}
}
25 changes: 25 additions & 0 deletions EDSEditorGUI2/ViewModels/DeviceOD.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using CommunityToolkit.Mvvm.ComponentModel;
using Google.Protobuf.Collections;
using LibCanOpen;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace EDSEditorGUI2.ViewModels;
public partial class DeviceOD : ObservableObject
{
[ObservableProperty]
private MapField<string, OdObject> _model;
public DeviceOD(MapField<string, OdObject> model)
{
Model = model;
_viewModel = new(Model);
_viewModel.CollectionChanged += ViewModel_CollectionChanged;
}

private void ViewModel_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
OnPropertyChanged(nameof(ViewModel));
}
[ObservableProperty]
ObservableCollection<KeyValuePair<string, OdObject>> _viewModel;
}
47 changes: 47 additions & 0 deletions EDSEditorGUI2/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.Metrics;
using Avalonia.Interactivity;
using CommunityToolkit.Mvvm.ComponentModel;
using LibCanOpen;

namespace EDSEditorGUI2.ViewModels;

public partial class MainWindowViewModel : ViewModelBase
{
int Counter = 0;
public void AddNewDevice(object sender)
{
var device = new LibCanOpen.CanOpenDevice
{
DeviceInfo = new()
{
ProductName = "New Product" + Counter.ToString()
},
};

Counter++;

//string dir = Environment.OSVersion.Platform == PlatformID.Win32NT ? "\\" : "/";
//eds.projectFilename = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + dir + "project";

//DeviceView device = new DeviceView(eds, network);
//device.UpdateODViewForEDS += Device_UpdateODViewForEDS;

//eds.OnDataDirty += Eds_onDataDirty;

//device.Dock = DockStyle.Fill;
//device.dispatch_updateOD();

Network.Add(new Device(device));
}
#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;


}
Loading

0 comments on commit f564c4e

Please sign in to comment.