From eb3aad2452ea6a69c22e25182fdaf5b98549758f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammet=20=C5=9E=C3=BCkr=C3=BC=20Demir?= <41967334+dsm@users.noreply.github.com> Date: Sat, 7 Dec 2024 20:08:02 +0300 Subject: [PATCH 1/2] fix ngspice and qucsator_rf path search. --- qucs/main.cpp | 8 +++--- qucs/qucs.cpp | 75 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/qucs/main.cpp b/qucs/main.cpp index 287cd5b83..a015a7687 100644 --- a/qucs/main.cpp +++ b/qucs/main.cpp @@ -106,12 +106,12 @@ bool loadSettings() QFileInfo inf(QucsSettings.Qucsator); QucsSettings.QucsatorDir = inf.canonicalPath() + QDir::separator(); if (QucsSettings.Qucsconv.isEmpty()) - QucsSettings.Qucsconv = QucsSettings.QucsatorDir + QDir::separator() + "qucsconv_rf" + executableSuffix; + QucsSettings.Qucsconv = QStandardPaths::findExecutable("qucsconv_rf",{QucsSettings.QucsatorDir}); } else { - QucsSettings.Qucsator = QucsSettings.BinDir + "qucsator_rf" + executableSuffix; + QucsSettings.Qucsator = QStandardPaths::findExecutable("qucsator_rf",{QucsSettings.BinDir}); QucsSettings.QucsatorDir = QucsSettings.BinDir; if (QucsSettings.Qucsconv.isEmpty()) - QucsSettings.Qucsconv = QucsSettings.BinDir + "qucsconv_rf" + executableSuffix; + QucsSettings.Qucsconv = QStandardPaths::findExecutable("qucsconv_rf",{QucsSettings.BinDir}); } QucsSettings.AdmsXmlBinDir.setPath(_settings::Get().item("AdmsXmlBinDir")); @@ -798,7 +798,7 @@ int main(int argc, char *argv[]) QucsDir.cdUp(); #endif - QucsSettings.BinDir = QucsDir.absolutePath() + "/bin/"; + QucsSettings.BinDir = QucsApplicationPath.contains("bin") ? QucsApplicationPath : QucsDir.absoluteFilePath("bin"); QucsSettings.LangDir = QucsDir.canonicalPath() + "/share/" QUCS_NAME "/lang/"; QucsSettings.LibDir = QucsDir.canonicalPath() + "/share/" QUCS_NAME "/library/"; diff --git a/qucs/qucs.cpp b/qucs/qucs.cpp index 07d0eb4f4..e78479b53 100644 --- a/qucs/qucs.cpp +++ b/qucs/qucs.cpp @@ -156,8 +156,8 @@ QucsApp::QucsApp() select->setChecked(true); // switch on the 'select' action switchSchematicDoc(true); // "untitled" document is schematic - - lastExportFilename = QDir::homePath() + QDir::separator() + "export.png"; + QDir homeDir = QDir::homePath(); + lastExportFilename = homeDir.absoluteFilePath("export.png"); // load documents given as command line arguments for(int z=1; zarguments().size(); z++) { @@ -172,42 +172,54 @@ QucsApp::QucsApp() } } + QDir QucsBinDir(QucsSettings.BinDir); if (QucsSettings.firstRun) { // try to find Ngspice + QString ngspice_exe_name = "ngspice"; #ifdef Q_OS_WIN - QString ngspice_exe1 = QucsSettings.BinDir + QDir::separator() + "ngspice_con.exe"; - QString ngspice_exe2 = "C:\\Spice64\\bin\\ngspice_con.exe"; - QString qucsator_exe = QucsSettings.BinDir + QDir::separator() + "qucsator_rf.exe"; -#else - QString ngspice_exe1 = QucsSettings.BinDir + QDir::separator() + "ngspice"; - QString qucsator_exe = QucsSettings.BinDir + QDir::separator() + "qucsator_rf"; + ngspice_exe_name+="_con"; #endif + /* search own path */ + QString ngspice_exe1 = QStandardPaths::findExecutable(ngspice_exe_name,{QucsBinDir.absolutePath()}); + /* search system path */ + QString ngspice_exe2 = QStandardPaths::findExecutable(ngspice_exe_name); + + /* search own path */ + QString qucsator_exe1 = QStandardPaths::findExecutable("qucsator_rf",{QucsBinDir.absolutePath()}); + /* search system path */ + QString qucsator_exe2 = QStandardPaths::findExecutable("qucsator_rf"); + QString ngspice_exe; bool ngspice_found = false; - if (QFile::exists(ngspice_exe1)) { + if(!ngspice_exe1.isEmpty()){ ngspice_found = true; ngspice_exe = ngspice_exe1; + }else if(!ngspice_exe2.isEmpty()){ + ngspice_found = true; + ngspice_exe = ngspice_exe2; } + + QString qucsator_exe; bool qucsator_found = false; - if (QFile::exists(qucsator_exe)) { + if(!qucsator_exe1.isEmpty()){ qucsator_found = true; - QucsSettings.Qucsator = qucsator_exe; - } -#ifdef Q_OS_WIN - if (!ngspice_found && QFile::exists(ngspice_exe2)) { - ngspice_found = true; - ngspice_exe = ngspice_exe2; + qucsator_exe = qucsator_exe1; + }else if(!qucsator_exe2.isEmpty()){ + qucsator_found = true; + qucsator_exe = qucsator_exe2; } -#endif - ngspice_exe = QDir::toNativeSeparators(ngspice_exe); + QString info_string; if (ngspice_found) { - QucsSettings.DefaultSimulator = spicecompat::simNgspice; + QucsSettings.DefaultSimulator = spicecompat::simNgspice; QucsSettings.NgspiceExecutable = ngspice_exe; info_string += tr("Ngspice found at: ") + ngspice_exe + "\n"; } - if (qucsator_found) { + + if(qucsator_found){ + QucsSettings.Qucsator = qucsator_exe; info_string += tr("QucsatorRF found at: ") + qucsator_exe + "\n"; } + info_string += tr("\nYou can specify another location later" " using Simulation->Simulators Setings\n"); if (!ngspice_found && qucsator_found) { @@ -220,18 +232,27 @@ QucsApp::QucsApp() QMessageBox::information(nullptr,tr("Set simulator"), info_string); fillSimulatorsComboBox(); } else { +#ifdef Q_OS_WIN + QucsSettings.NgspiceExecutable = "ngspice_con.exe"; + QucsSettings.Qucsator = "qucsator_rf.exe"; +#else + QucsSettings.NgspiceExecutable = "ngspice"; + QucsSettings.Qucsator = "qucsator_rf"; +#endif QMessageBox::information(this,tr("Qucs"),tr("No simulators found automatically. Please specify simulators" " in the next dialog window.")); slotSimSettings(); } QucsSettings.firstRun = false; - } else if (!QFile::exists(QucsSettings.Qucsator)) { - QucsSettings.Qucsator = QucsSettings.BinDir + QDir::separator() + "qucsator_rf"; -#ifdef Q_OS_WIN - QucsSettings.Qucsator += ".exe"; -#endif - QMessageBox::information(this, "Qucs", - tr("QucsatorRF found at: ") + QucsSettings.Qucsator + "\n"); + } else { + if (!QucsSettings.Qucsator.contains("qucsator_rf")) { + QucsSettings.Qucsator = QStandardPaths::findExecutable("qucsator_rf",{QucsBinDir.absolutePath()}); + + if(!QucsSettings.Qucsator.isEmpty()){ + QMessageBox::information(this, "Qucs", + tr("QucsatorRF found at: ") + QucsSettings.Qucsator + "\n"); + } + } } // fillLibrariesTreeView(); From 591313332460bd31fe73b1fdd2e926079f5a6579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Muhammet=20=C5=9E=C3=BCkr=C3=BC=20Demir?= <41967334+dsm@users.noreply.github.com> Date: Sat, 7 Dec 2024 22:36:43 +0300 Subject: [PATCH 2/2] search ngspice using homebrew path on macos. --- qucs/qucs.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qucs/qucs.cpp b/qucs/qucs.cpp index e78479b53..8477853cd 100644 --- a/qucs/qucs.cpp +++ b/qucs/qucs.cpp @@ -179,7 +179,12 @@ QucsApp::QucsApp() ngspice_exe_name+="_con"; #endif /* search own path */ +#ifdef Q_OS_MACOS + QString ngspice_exe1 = QStandardPaths::findExecutable(ngspice_exe_name,{"/opt/homebrew/bin"}); +#else QString ngspice_exe1 = QStandardPaths::findExecutable(ngspice_exe_name,{QucsBinDir.absolutePath()}); +#endif + /* search system path */ QString ngspice_exe2 = QStandardPaths::findExecutable(ngspice_exe_name);