Skip to content

Commit

Permalink
vhdl nodeprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 12, 2023
1 parent c3aad91 commit 0c9a828
Show file tree
Hide file tree
Showing 19 changed files with 296 additions and 45 deletions.
3 changes: 1 addition & 2 deletions demo/OneWare.Demo/DemoApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ public override void Initialize()
protected override void ConfigureModuleCatalog(IModuleCatalog moduleCatalog)
{
base.ConfigureModuleCatalog(moduleCatalog);
moduleCatalog.AddModule<UniversalFpgaProjectSystemModule>();
moduleCatalog.AddModule<VhdlModule>();
moduleCatalog.AddModule<VerilogModule>();
moduleCatalog.AddModule<JsonModule>();
moduleCatalog.AddModule<TomlModule>();
moduleCatalog.AddModule<VcdViewerModule>();
moduleCatalog.AddModule<UniversalFpgaProjectSystemModule>();

moduleCatalog.AddModule<IceBreakerModule>();
}
}
3 changes: 1 addition & 2 deletions src/OneWare.Core/Services/Paths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Paths(string appName, string appIconPath)
Directory.CreateDirectory(CrashReportsDirectory);
Directory.CreateDirectory(ProjectsDirectory);
//...

var sessionsDir = Path.Combine(TempDirectory, "OneWare", "Sessions");
CleanupSessions(sessionsDir);

Expand All @@ -53,7 +53,6 @@ public Paths(string appName, string appIconPath)

private static void CleanupSessions(string sessionsDir)
{
//Cleanup
try
{
if (Directory.Exists(sessionsDir))
Expand Down
87 changes: 60 additions & 27 deletions src/OneWare.Core/Styles/Icons.axaml

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/OneWare.ProjectExplorer/Views/ProjectExplorerView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@
<Grid VerticalAlignment="Center">
<Image Height="16" Width="16"
Source="{Binding Icon}" />
<ItemsControl ItemsSource="{Binding IconOverlays}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Panel/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Image Source="{Binding }"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<Image Height="16" Width="16"
Source="{DynamicResource VsImageLib.StatusCriticalErrorOverlayExp16X}"
IsVisible="{Binding LoadingFailed}" />
Expand Down
2 changes: 2 additions & 0 deletions src/OneWare.ProjectSystem/Models/ProjectEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public IImage? Icon
get => _icon;
set => SetProperty(ref _icon, value);
}

public ObservableCollection<IImage> IconOverlays { get; } = new();

private string _header;
public string Header
Expand Down
4 changes: 2 additions & 2 deletions src/OneWare.ProjectSystem/Models/ProjectRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ protected ProjectRoot(string rootFolderPath) : base(Path.GetFileName(rootFolderP
TopFolder = this;
}

internal void RegisterEntry(IProjectEntry entry)
public virtual void RegisterEntry(IProjectEntry entry)
{
if(entry is ProjectFile file) Files.Add(file);
}

internal void UnregisterEntry(IProjectEntry entry)
public virtual void UnregisterEntry(IProjectEntry entry)
{
if (entry is ProjectFile file) Files.Remove(file);
}
Expand Down
2 changes: 2 additions & 0 deletions src/OneWare.Shared/Models/IProjectEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IProjectEntry : IHasPath

public IImage Icon { get; }

public ObservableCollection<IImage> IconOverlays { get; }

public bool IsExpanded { get; set; }

public IBrush Background { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions src/OneWare.UniversalFpgaProjectSystem/INodeProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using OneWare.Shared.Models;
using OneWare.UniversalFpgaProjectSystem.Models;

namespace OneWare.UniversalFpgaProjectSystem;

public interface INodeProvider
{
public IEnumerable<NodeModel> ExtractNodes(IProjectFile file);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public abstract class FpgaModelBase : ObservableObject

public Dictionary<string, FpgaPinModel> Pins { get; } = new();
public ObservableCollection<FpgaPinModel> VisiblePins { get; } = new();

public Dictionary<string, NodeModel> Nodes { get; } = new();
public ObservableCollection<NodeModel> VisibleNodes { get; } = new();


private FpgaPinModel? _selectedPin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System.Text.Json;
using System.Text.Json.Nodes;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using Avalonia.Styling;
using OneWare.ProjectSystem.Models;
using OneWare.Shared.Converters;
using OneWare.Shared.Helpers;
Expand All @@ -20,14 +24,46 @@ public class UniversalFpgaProjectRoot : ProjectRoot, IProjectRootWithFile
public string ProjectFilePath { get; }
public JsonObject Properties { get; }

private readonly IImage _topEntityOverlay;

private IProjectEntry? _topEntity;

public IProjectEntry? TopEntity
{
get => _topEntity;
set
{
_topEntity?.IconOverlays.Remove(_topEntityOverlay);
SetProperty(ref _topEntity, value);
_topEntity?.IconOverlays.Add(_topEntityOverlay);

if (_topEntity != null)
Properties[nameof(TopEntity)] = _topEntity.RelativePath;
else
Properties.Remove(nameof(TopEntity));
}
}

public UniversalFpgaProjectRoot(string projectFilePath, JsonObject properties) : base(Path.GetDirectoryName(projectFilePath) ?? throw new NullReferenceException("Invalid Project Path"))
{
ProjectFilePath = projectFilePath;
Properties = properties;

_topEntityOverlay = Application.Current!.FindResource(ThemeVariant.Dark, "VsImageLib2019.DownloadOverlay16X") as IImage
?? throw new NullReferenceException("TopEntity Icon");

Icon = SharedConverters.PathToBitmapConverter.Convert(ContainerLocator.Container.Resolve<IPaths>().AppIconPath, typeof(Bitmap), null, null) as Bitmap;
}


public override void UnregisterEntry(IProjectEntry entry)
{
if (entry == TopEntity)
{
TopEntity = null;
}
base.UnregisterEntry(entry);
}

public override bool IsPathIncluded(string relativePath)
{
var includes = Properties["Include"].Deserialize<string[]>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace OneWare.UniversalFpgaProjectSystem.Services;

public class NodeProviderService
{
private readonly Dictionary<string, INodeProvider> _providers = new();

public NodeProviderService()
{
Console.WriteLine("?");
}

public void RegisterNodeProvider(INodeProvider provider, params string[] extensions)
{
foreach (var ext in extensions)
{
_providers[ext] = provider;
}
}

public INodeProvider? GetNodeProvider(string extension)
{
return _providers.TryGetValue(extension, out var provider) ? provider : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ await _windowService.ShowDialogAsync(new UniversalFpgaProjectCreatorView()
public async Task<IProjectRoot?> LoadProjectAsync(string path)
{
var root = await UniversalFpgaProjectParser.DeserializeAsync(path);

if (root == null) return root;

if(root != null)
ProjectHelper.ImportEntries(root.FullPath, root);
ProjectHelper.ImportEntries(root.FullPath, root);

//Load Properties
var top = root.Properties["TopEntity"];
if (top != null && root.Search(top.ToString()) is {} entity)
{
root.TopEntity = entity;
}

return root;
}

Expand Down Expand Up @@ -71,6 +79,30 @@ public IEnumerable<MenuItemModel> ConstructContextMenu(IProjectEntry entry)
Command = new AsyncRelayCommand(() => _dockService.OpenFileAsync(_projectExplorerService.GetTemporaryFile(root.ProjectFilePath))),
};
break;
case IProjectFile { Root: UniversalFpgaProjectRoot universalFpgaProjectRoot } file:
if (universalFpgaProjectRoot.TopEntity == file)
{
yield return new MenuItemModel("Unset Top Entity")
{
Header = $"Unset Top Entity",
Command = new RelayCommand(() =>
{
universalFpgaProjectRoot.TopEntity = null;
}),
};
}
else
{
yield return new MenuItemModel("Set Top Entity")
{
Header = $"Set Top Entity",
Command = new RelayCommand(() =>
{
universalFpgaProjectRoot.TopEntity = file;
}),
};
}
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterSingleton<UniversalFpgaProjectManager>();
containerRegistry.RegisterSingleton<FpgaService>();
containerRegistry.RegisterSingleton<NodeProviderService>();
}

public void OnInitialized(IContainerProvider containerProvider)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Collections.ObjectModel;
using AvaloniaEdit.Utils;
using CommunityToolkit.Mvvm.ComponentModel;
using OneWare.Shared.Controls;
using OneWare.Shared.Models;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Services;
using OneWare.UniversalFpgaProjectSystem.Views;
Expand Down Expand Up @@ -28,13 +30,23 @@ public bool HideExtensions
set => SetProperty(ref _hideExtensions, value);
}

public UniversalFpgaProjectCompileViewModel(FpgaService fpgaService, UniversalFpgaProjectRoot project)
public UniversalFpgaProjectCompileViewModel(FpgaService fpgaService, NodeProviderService nodeProviderService, UniversalFpgaProjectRoot project)
{
_project = project;

FpgaModels = fpgaService.FpgaModels;

SelectedFpga = FpgaModels.FirstOrDefault();

if (project.TopEntity is IProjectFile file)
{
var provider = nodeProviderService.GetNodeProvider(file.Extension);
if (provider is not null)
{
var nodes = provider.ExtractNodes(file);
SelectedFpga?.VisibleNodes.AddRange(nodes);
}
}
}

public async Task SaveAsync(FlexibleWindow window)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@
IsVisible="{Binding Converter={x:Static converters:SharedConverters.ViewFoundConverter}}"
Content="{Binding }" />

<Border BorderThickness="1" BorderBrush="{DynamicResource ThemeBorderLowBrush}" Background="{DynamicResource ThemeControlLowBrush}">
<DockPanel >
<Grid ColumnDefinitions="*, 100, *" RowDefinitions="Auto, *" DockPanel.Dock="Top">
<TextBlock Text="Nodes"></TextBlock>
<Border Grid.Column="0" Grid.Row="1" Background="{DynamicResource ThemeControlLowBrush}" BorderThickness="1" BorderBrush="{DynamicResource ThemeBorderLowBrush}">
<DockPanel Background="{DynamicResource ThemeControlLowBrush}">
<controls:SearchBox DockPanel.Dock="Top" VerticalAlignment="Center"
Background="{DynamicResource ThemeBackgroundBrush}"
VerticalContentAlignment="Center" />

<ListBox DockPanel.Dock="Top" AutoScrollToSelectedItem="True"
<ListBox AutoScrollToSelectedItem="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
BorderThickness="0,1,0,0" BorderBrush="{DynamicResource ThemeBorderLowBrush}"
Name="SignalList" ItemsSource="{Binding VisiblePins}"
SelectedItem="{Binding Path=SelectedPin, Mode=TwoWay}" VerticalAlignment="Stretch">
Name="SignalList" ItemsSource="{Binding VisibleNodes}"
SelectedItem="{Binding Path=SelectedNode, Mode=TwoWay}" VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
Expand All @@ -61,7 +62,41 @@
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Border>
</Border>

<Border Grid.Column="1" Grid.Row="0" Grid.RowSpan="2" Background="{DynamicResource ThemeBackgroundBrush}">
<StackPanel Orientation="Vertical" VerticalAlignment="Center" Spacing="15">
<Button Classes="BorderButton" Height="40" Width="40" CornerRadius="5">
<Image Source="{DynamicResource VSImageLib2019.Plugged_16x}" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
<Button Classes="BorderButton" Height="40" Width="40" CornerRadius="5">
<Image Source="{DynamicResource VSImageLib2019.Unplugged_16x}" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Button>
</StackPanel>
</Border>

<TextBlock Grid.Row="0" Grid.Column="2" Text="Pins"></TextBlock>
<Border Grid.Column="2" Grid.Row="1" Background="{DynamicResource ThemeControlLowBrush}" BorderThickness="1" BorderBrush="{DynamicResource ThemeBorderLowBrush}">
<DockPanel Background="{DynamicResource ThemeControlLowBrush}">
<controls:SearchBox DockPanel.Dock="Top" VerticalAlignment="Center"
Background="{DynamicResource ThemeBackgroundBrush}"
VerticalContentAlignment="Center" />
<ListBox AutoScrollToSelectedItem="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
BorderThickness="0,1,0,0" BorderBrush="{DynamicResource ThemeBorderLowBrush}"
Name="PinList" ItemsSource="{Binding VisiblePins}"
SelectedItem="{Binding Path=SelectedPin, Mode=TwoWay}" VerticalAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<TextBlock Text="{Binding Name}" />
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Border>
</Grid>
</DockPanel>
</Grid>
</Border>
Expand Down
1 change: 1 addition & 0 deletions src/OneWare.Vhdl/OneWare.Vhdl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<ItemGroup>
<ProjectReference Include="..\OneWare.Shared\OneWare.Shared.csproj" Private="true" ExcludeAssets="runtime"/>
<ProjectReference Include="..\OneWare.UniversalFpgaProjectSystem\OneWare.UniversalFpgaProjectSystem.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 0c9a828

Please sign in to comment.