Skip to content

Commit

Permalink
impro
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Nov 15, 2023
1 parent a0a5e64 commit b93d09e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/OneWare.Cpp/CppModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ public void OnInitialized(IContainerProvider containerProvider)
{
containerProvider.Resolve<IErrorService>().RegisterErrorSource("Clang");
containerProvider.Resolve<ILanguageManager>().RegisterService(typeof(LanguageServiceCpp),false, ".cpp", ".h", ".c", ".hpp");

containerProvider.Resolve<IModuleTracker>().RecordModuleInitialized(GetType().Name);
}
}
30 changes: 20 additions & 10 deletions src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public string SearchTextNodes

public FpgaModelBase()
{
ConnectCommand = new RelayCommand(Connect, () => SelectedNode is not null && SelectedPin is not null);
ConnectCommand = new RelayCommand(ConnectSelected, () => SelectedNode is not null && SelectedPin is not null);

DisconnectCommand = new RelayCommand(Disconnect, () => SelectedPin is {Connection: not null});
DisconnectCommand = new RelayCommand(DisconnectSelected, () => SelectedPin is {Connection: not null});

this.WhenValueChanged(x => x.SelectedNode).Subscribe(x =>
{
Expand Down Expand Up @@ -112,25 +112,35 @@ private void SearchNodes(string? search)
SelectedNode = VisibleNodes.FirstOrDefault(x => x.Name.Contains(search, StringComparison.OrdinalIgnoreCase));
}

private void Connect()
public void Connect(FpgaPinModel pin, NodeModel node)
{
if (SelectedPin is null || SelectedNode is null) return;
SelectedPin.Connection = SelectedNode;
SelectedNode.Connection = SelectedPin;
pin.Connection = SelectedNode;
node.Connection = SelectedPin;
ConnectCommand.NotifyCanExecuteChanged();
DisconnectCommand.NotifyCanExecuteChanged();
NodeConnected?.Invoke(this, EventArgs.Empty);
}

private void Disconnect()
public void Disconnect(FpgaPinModel pin)
{
if (SelectedPin is null || SelectedNode is null) return;
SelectedPin!.Connection = null;
SelectedNode!.Connection = null;
if (pin.Connection != null) pin.Connection.Connection = null;
pin.Connection = null;
ConnectCommand.NotifyCanExecuteChanged();
DisconnectCommand.NotifyCanExecuteChanged();
NodeDisconnected?.Invoke(this, EventArgs.Empty);
}

private void ConnectSelected()
{
if (SelectedPin is null || SelectedNode is null) return;
Connect(SelectedPin, SelectedNode);
}

private void DisconnectSelected()
{
if (SelectedPin is null) return;
Disconnect(SelectedPin);
}

protected void LoadFromJson(string path)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using OneWare.Shared.ViewModels;
using OneWare.UniversalFpgaProjectSystem.Models;
using OneWare.UniversalFpgaProjectSystem.Services;
using Prism.Ioc;

namespace OneWare.UniversalFpgaProjectSystem.ViewModels;

Expand Down Expand Up @@ -90,13 +91,17 @@ private async Task SafeQuitAsync(FlexibleWindow window)
break;
case MessageBoxStatus.Canceled:
return;
}
}

IsDirty = false;
window.Close();
}

public void SaveAndClose(FlexibleWindow window)
{
CreatePcf();
IsDirty = false;
window.Close();
}

private string RemoveLine(string file, string find)
Expand All @@ -113,6 +118,32 @@ private string RemoveLine(string file, string find)
return file;
}

private void LoadConnectionsFromPcf(string pcf, FpgaModelBase fpga)
{
var lines = pcf.Split('\n');
foreach (var line in lines)
{
var trimmedLine = line.Trim();
if (trimmedLine.StartsWith("set_io"))
{
var parts = trimmedLine.Split(' ');
if (parts.Length != 3)
{
ContainerLocator.Container.Resolve<ILogger>().Warning("PCF Line invalid: " + trimmedLine);
continue;
}

var signal = parts[1];
var pin = parts[2];

if (fpga.Pins.TryGetValue(pin, out var pinModel) && fpga.Nodes.TryGetValue(signal, out var signalModel))
{
fpga.Connect(pinModel, signalModel);
}
}
}
}

private void CreatePcf()
{
if (SelectedFpga == null) return;
Expand All @@ -123,13 +154,14 @@ private void CreatePcf()
{
var existingPcf = File.ReadAllText(pcfPath);
existingPcf = RemoveLine(existingPcf, "set_io");
pcf = existingPcf.Trim() + "\n";
pcf = existingPcf.Trim();
}

foreach (var conn in SelectedFpga.Pins.Where(x => x.Value.Connection is not null))
{
pcf += $"set_io {conn.Value.Connection!.Name} {conn.Value.Name}\n";
pcf += $"\nset_io {conn.Value.Connection!.Name} {conn.Value.Name}";
}
pcf = pcf.Trim() + '\n';

File.WriteAllText(pcfPath, pcf);
}
Expand Down

0 comments on commit b93d09e

Please sign in to comment.