Skip to content

Commit

Permalink
oss cad suite integration
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 15, 2023
1 parent 8476c37 commit bd6de9b
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 25 deletions.
10 changes: 10 additions & 0 deletions OneWare.sln
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "actions", "actions", "{60A1
.github\workflows\test.yml = .github\workflows\test.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{BD761CED-3D61-4D9E-A2A1-494584F2ED5F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneWare.OssCadSuiteIntegration", "src\OneWare.OssCadSuiteIntegration\OneWare.OssCadSuiteIntegration.csproj", "{4E2FD886-862B-4DE9-A69E-AE82E52979B5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -273,6 +277,10 @@ Global
{B970E17F-ED6D-4A50-9477-BF2809198416}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B970E17F-ED6D-4A50-9477-BF2809198416}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B970E17F-ED6D-4A50-9477-BF2809198416}.Release|Any CPU.Build.0 = Release|Any CPU
{4E2FD886-862B-4DE9-A69E-AE82E52979B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E2FD886-862B-4DE9-A69E-AE82E52979B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E2FD886-862B-4DE9-A69E-AE82E52979B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E2FD886-862B-4DE9-A69E-AE82E52979B5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F08B36E8-AB80-42CD-BD47-6B05E96DA390} = {0761690C-7DA0-4554-9F6B-211088412DCD}
Expand Down Expand Up @@ -312,5 +320,7 @@ Global
{52DDC84A-27F8-4AF0-93C4-903614BE613D} = {6FF7E7F6-DA3F-477E-AAD7-47E3655FA34D}
{B970E17F-ED6D-4A50-9477-BF2809198416} = {52DDC84A-27F8-4AF0-93C4-903614BE613D}
{60A1DF89-0129-42B7-A509-D717A887667C} = {3782EFDF-2990-4B2C-907F-12739A839A3C}
{BD761CED-3D61-4D9E-A2A1-494584F2ED5F} = {6FF7E7F6-DA3F-477E-AAD7-47E3655FA34D}
{4E2FD886-862B-4DE9-A69E-AE82E52979B5} = {BD761CED-3D61-4D9E-A2A1-494584F2ED5F}
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions demo/OneWare.Demo.Desktop/DesktopDemoApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using OneWare.Core.Views.Windows;
using OneWare.Cpp;
using OneWare.Demo.Desktop.ViewModels;
using OneWare.OssCadSuiteIntegration;
using OneWare.PackageManager;
using OneWare.SerialMonitor;
using OneWare.Shared.Enums;
Expand All @@ -37,6 +38,7 @@ protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
moduleCatalog.AddModule<SourceControlModule>();
moduleCatalog.AddModule<SerialMonitorModule>();
moduleCatalog.AddModule<CppModule>();
moduleCatalog.AddModule<OssCadSuiteIntegrationModule>();

try
{
Expand Down
1 change: 1 addition & 0 deletions demo/OneWare.Demo.Desktop/OneWare.Demo.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\OneWare.OssCadSuiteIntegration\OneWare.OssCadSuiteIntegration.csproj" />
<ProjectReference Include="..\..\src\OneWare.PackageManager\OneWare.PackageManager.csproj" />
<ProjectReference Include="..\..\src\OneWare.SerialMonitor\OneWare.SerialMonitor.csproj" />
<ProjectReference Include="..\..\src\OneWare.SourceControl\OneWare.SourceControl.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/OneWare.Core/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ protected override AvaloniaObject CreateShell()

//Editor settings
settingsService.RegisterSettingCategory("Editor", 0, "BoxIcons.RegularCode");

settingsService.RegisterSettingCategory("Tools", 0, "FeatherIcons.Tool");

settingsService.RegisterTitledCombo("Editor", "Appearance", "Editor_FontFamily", "Font",
"Editor Font Family",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\props\Base.props" />
<Import Project="..\..\build\props\OneWare.Module.props" />

<ItemGroup>
<ProjectReference Include="..\OneWare.Shared\OneWare.Shared.csproj" />
</ItemGroup>
</Project>
54 changes: 54 additions & 0 deletions src/OneWare.OssCadSuiteIntegration/OssCadSuiteIntegrationModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using OneWare.Shared.Helpers;
using OneWare.Shared.Services;
using Prism.Ioc;
using Prism.Modularity;
// ReSharper disable StringLiteralTypo

namespace OneWare.OssCadSuiteIntegration;

public class OssCadSuiteIntegrationModule : IModule
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{

}

public void OnInitialized(IContainerProvider containerProvider)
{
var settingsService = containerProvider.Resolve<ISettingsService>();

settingsService.RegisterTitledPath("Tools", "OSS Cad Suite", "OssCadSuite_Path", "OSS CAD Suite Path",
"Sets the path for the Yosys OSS CAD Suite", "", null, null, IsOssPathValid);

string? environmentPathSetting;

settingsService.GetSettingObservable<string>("OssCadSuite_Path").Subscribe(x =>
{
if (!IsOssPathValid(x))
{
containerProvider.Resolve<ILogger>().Warning("OSS CAD Suite path invalid", null, false);
return;
}

var binPath = Path.Combine(x, "bin");
var pythonBin = Path.Combine(x, "py3bin");
var lib = Path.Combine(x, "lib");

environmentPathSetting = $";{binPath};{pythonBin};{lib};";
var currentPath = Environment.GetEnvironmentVariable("PATH");

//TODO Add all
Environment.SetEnvironmentVariable("PATH", $"{currentPath}{environmentPathSetting}");
Environment.SetEnvironmentVariable("OPENFPGALOADER_SOJ_DIR", Path.Combine(x, "share", "openFPGALoader"));
Environment.SetEnvironmentVariable("PYTHON_EXECUTABLE", Path.Combine(x, "py3bin", $"python3{PlatformHelper.ExecutableExtension}"));
});
}

private static bool IsOssPathValid(string path)
{
if (!Directory.Exists(path)) return false;
if (!File.Exists(Path.Combine(path, "bin", $"yosys{PlatformHelper.ExecutableExtension}"))) return false;
if (!File.Exists(Path.Combine(path, "bin", $"openFPGALoader{PlatformHelper.ExecutableExtension}"))) return false;
return true;
}
}
7 changes: 3 additions & 4 deletions src/OneWare.Settings/Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Avalonia.Platform.Storage;
using CommunityToolkit.Mvvm.ComponentModel;
using DynamicData.Binding;
using OneWare.Shared;
using OneWare.Shared.Helpers;

namespace OneWare.Settings;
Expand Down Expand Up @@ -59,7 +58,7 @@ public ComboBoxSetting(string title, string description, object defaultValue, IE

public abstract class PathSetting : TextBoxSetting
{
public string StartDirectory { get; }
public string? StartDirectory { get; }
public bool CanVerify { get; }

private bool _isValid = true;
Expand All @@ -70,7 +69,7 @@ public bool IsValid
set => SetProperty(ref _isValid, value);
}

protected PathSetting(string title, string description, object defaultValue, string? watermark, string startDirectory, Func<string, bool>? checkPath) : base(title, description, defaultValue, watermark)
protected PathSetting(string title, string description, object defaultValue, string? watermark, string? startDirectory, Func<string, bool>? checkPath) : base(title, description, defaultValue, watermark)
{
StartDirectory = startDirectory;

Expand All @@ -88,7 +87,7 @@ protected PathSetting(string title, string description, object defaultValue, str
}
public class FolderPathSetting : PathSetting
{
public FolderPathSetting(string title, string description, object defaultValue, string? watermark, string startDirectory, Func<string, bool>? checkPath)
public FolderPathSetting(string title, string description, object defaultValue, string? watermark, string? startDirectory, Func<string, bool>? checkPath)
: base(title, description, defaultValue, watermark, startDirectory, checkPath)
{
}
Expand Down
8 changes: 7 additions & 1 deletion src/OneWare.Settings/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ public void RegisterTitled<T>(string category, string subCategory, string key, s
if (defaultValue == null) throw new NullReferenceException(nameof(defaultValue));
AddSetting(category, subCategory, key, new TitledSetting(title, description, defaultValue));
}


public void RegisterTitledPath(string category, string subCategory, string key, string title, string description,
string defaultValue, string? watermark, string? startDir, Func<string, bool>? validate)
{
AddSetting(category, subCategory, key, new FolderPathSetting(title, description, defaultValue, watermark,startDir, validate));
}

public void RegisterTitledCombo<T>(string category, string subCategory, string key, string title, string description, T defaultValue, params T[] options)
{
if (defaultValue == null) throw new NullReferenceException(nameof(defaultValue));
Expand Down
51 changes: 31 additions & 20 deletions src/OneWare.Settings/ViewModels/ApplicationSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,38 @@ public ApplicationSettingsViewModel(ISettingsService settingsService, IPaths pat

foreach (var setting in subCategory.Value.Settings)
{
if (setting is ComboBoxSetting cS)
switch (setting)
{
subCategoryModel.SettingModels.Add(new ComboBoxSettingViewModel(cS));
}
else
{
switch (setting.Value)
{
case bool:
subCategoryModel.SettingModels.Add(new CheckBoxSettingViewModel(setting));
break;
case string:
case int:
case float:
case double:
subCategoryModel.SettingModels.Add(new TextBoxSettingViewModel(setting));
break;
case Color:
subCategoryModel.SettingModels.Add(new ColorPickerSettingViewModel(setting));
break;
}
case ComboBoxSetting cS:
subCategoryModel.SettingModels.Add(new ComboBoxSettingViewModel(cS));
break;
case FolderPathSetting pS:
subCategoryModel.SettingModels.Add(new PathSettingViewModel(pS));
break;
case FilePathSetting pS:
subCategoryModel.SettingModels.Add(new PathSettingViewModel(pS));
break;
case PathSetting pS:
subCategoryModel.SettingModels.Add(new PathSettingViewModel(pS));
break;
default:
switch (setting.Value)
{
case bool:
subCategoryModel.SettingModels.Add(new CheckBoxSettingViewModel(setting));
break;
case string:
case int:
case float:
case double:
subCategoryModel.SettingModels.Add(new TextBoxSettingViewModel(setting));
break;
case Color:
subCategoryModel.SettingModels.Add(new ColorPickerSettingViewModel(setting));
break;
}

break;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/OneWare.Shared/Services/ISettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public void RegisterSettingSubCategory(string category, string subCategory, int
public void RegisterTitled<T>(string category, string subCategory, string key, string title, string description,
T defaultValue);

public void RegisterTitledPath(string category, string subCategory, string key, string title, string description,
string defaultValue, string? watermark, string? startDir, Func<string, bool>? validate);

public void RegisterTitledCombo<T>(string category, string subCategory, string key, string title, string description,
T defaultValue, params T[] options);

Expand Down

0 comments on commit bd6de9b

Please sign in to comment.