diff --git a/src/OneWare.Cpp/CppModule.cs b/src/OneWare.Cpp/CppModule.cs index 737061dc..b5a6265d 100644 --- a/src/OneWare.Cpp/CppModule.cs +++ b/src/OneWare.Cpp/CppModule.cs @@ -15,7 +15,5 @@ public void OnInitialized(IContainerProvider containerProvider) { containerProvider.Resolve().RegisterErrorSource("Clang"); containerProvider.Resolve().RegisterService(typeof(LanguageServiceCpp),false, ".cpp", ".h", ".c", ".hpp"); - - containerProvider.Resolve().RecordModuleInitialized(GetType().Name); } } \ No newline at end of file diff --git a/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs b/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs index 40844e4f..2f2587e4 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs +++ b/src/OneWare.UniversalFpgaProjectSystem/Models/FpgaModelBase.cs @@ -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 => { @@ -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) { diff --git a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs index 0a3f09e5..eb65f802 100644 --- a/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs +++ b/src/OneWare.UniversalFpgaProjectSystem/ViewModels/UniversalFpgaProjectCompileViewModel.cs @@ -8,6 +8,7 @@ using OneWare.Shared.ViewModels; using OneWare.UniversalFpgaProjectSystem.Models; using OneWare.UniversalFpgaProjectSystem.Services; +using Prism.Ioc; namespace OneWare.UniversalFpgaProjectSystem.ViewModels; @@ -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) @@ -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().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; @@ -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); }