forked from robincornelius/libedssharp
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
588 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/obj/* | ||
/bin/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
||
|
||
_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; | ||
public DeviceOD Objects | ||
{ | ||
get => _objects; | ||
set | ||
{ | ||
//Model.Objects = value.Model; | ||
OnPropertyChanged(nameof(Objects)); | ||
} | ||
} | ||
|
||
public void OnClickCommand() | ||
{ | ||
// do something | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
||
} |
Oops, something went wrong.