summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPranav P2023-05-23 17:11:33 +0530
committerPranav P2023-05-23 17:11:33 +0530
commit7b36bfed265309672689cd6ddd04c9a24d115e9c (patch)
treea865782fcc37447fec610a6383c133a48f7d7f41 /src
parent1c0b9197069c12f2a9b0c35be936e97d38c6a372 (diff)
downloadeSim-7b36bfed265309672689cd6ddd04c9a24d115e9c.tar.gz
eSim-7b36bfed265309672689cd6ddd04c9a24d115e9c.tar.bz2
eSim-7b36bfed265309672689cd6ddd04c9a24d115e9c.zip
Changed the polling approach to check ngspice simulation completion
Diffstat (limited to 'src')
-rw-r--r--src/frontEnd/Application.py54
-rwxr-xr-xsrc/frontEnd/DockArea.py3
-rw-r--r--src/ngspiceSimulation/NgspiceWidget.py9
-rw-r--r--src/progressBar/progressBar.py16
4 files changed, 18 insertions, 64 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py
index 7457ba7d..3b403279 100644
--- a/src/frontEnd/Application.py
+++ b/src/frontEnd/Application.py
@@ -559,59 +559,16 @@ class Application(QtWidgets.QMainWindow):
# else:
# proc = 'xterm'
- # Edited by Sumanto Kar 25/08/2021
- if False and os.name != 'nt' and \
- self.checkIfProcessRunning('xterm') is False:
- self.msg = QtWidgets.QErrorMessage()
- self.msg.setModal(True)
- self.msg.setWindowTitle("Warning Message")
- self.msg.showMessage(
- 'Simulation was interrupted/failed. '
- 'Please close all the Ngspice windows '
- 'and then rerun the simulation.'
- )
- self.msg.exec_()
- return
-
st = os.stat(os.path.join(self.projDir, "plot_data_i.txt"))
is_ngspice_running = self.checkIfProcessRunning("ngspice")
if not is_ngspice_running:
+ self.simulationCompleted = True
if st.st_mtime >= currTime - 1:
self.is_file_changed = True
- self.timer.stop()
-
self.plot_simulation()
- return
- else:
- self.timer.stop()
- return
+ return
except Exception:
pass
-
- if self.is_file_changed is False:
- self.timer.start()
-
- # Fail Safe ===>
- self.count += 1
- if self.count >= 10:
- self.timer.stop()
- print(
- "Ngspice taking too long for simulation. "
- "Check netlist file (*.cir.out) "
- "to change simulation parameters."
- )
-
- self.msg = QtWidgets.QErrorMessage()
- self.msg.setModal(True)
- self.msg.setWindowTitle("Warning Message")
- self.msg.showMessage(
- 'Ngspice taking too long for simulation. '
- 'Check netlist file (*.cir.out) '
- 'to change simulation parameters.'
- )
- self.msg.exec_()
-
- return
def enableButtons(self, state):
self.ngspice.setEnabled(state)
@@ -629,14 +586,14 @@ class Application(QtWidgets.QMainWindow):
def open_ngspice(self):
"""This Function execute ngspice on current project."""
self.projDir = self.obj_appconfig.current_project["ProjectName"]
- self.timer = QtCore.QTimer(self)
self.is_file_changed = False
+ self.simulationCompleted = False
self.simulationEssentials = {
- "timer": self.timer,
"enableButtons": self.enableButtons,
"isSimulationSuccess": self.isSimulationSuccess,
"resetSimulationVariables": self.resetSimulationVariables,
+ "checkChangeInPlotFile": self.check_change_in_plotfile,
}
if self.projDir is not None:
@@ -660,9 +617,6 @@ class Application(QtWidgets.QMainWindow):
return
self.count = 0
- self.timer.setInterval(1000)
- self.timer.timeout.connect(lambda: self.check_change_in_plotfile(self.currTime))
- self.timer.start()
else:
self.msg = QtWidgets.QErrorMessage()
diff --git a/src/frontEnd/DockArea.py b/src/frontEnd/DockArea.py
index cf21199d..acf5b3d1 100755
--- a/src/frontEnd/DockArea.py
+++ b/src/frontEnd/DockArea.py
@@ -120,7 +120,6 @@ class DockArea(QtWidgets.QMainWindow):
def ngspiceEditor(self, projDir, simulationEssentials):
""" This function creates widget for Ngspice window."""
self.projDir = projDir
- self.simulationEssentials = simulationEssentials
self.projName = os.path.basename(self.projDir)
self.ngspiceNetlist = os.path.join(
self.projDir, self.projName + ".cir.out")
@@ -134,7 +133,7 @@ class DockArea(QtWidgets.QMainWindow):
self.ngspiceLayout = QtWidgets.QVBoxLayout()
self.ngspiceLayout.addWidget(
- NgspiceWidget(self.ngspiceNetlist, self.projDir, self.simulationEssentials)
+ NgspiceWidget(self.ngspiceNetlist, self.projDir, simulationEssentials)
)
# Adding to main Layout
diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py
index cbcd381b..13a5ece9 100644
--- a/src/ngspiceSimulation/NgspiceWidget.py
+++ b/src/ngspiceSimulation/NgspiceWidget.py
@@ -20,7 +20,7 @@ class NgspiceWidget(QtWidgets.QWidget):
self.process = QtCore.QProcess(self)
self.terminal = QtWidgets.QWidget(self)
self.simulationEssentials = simulationEssentials
- self.qTimer = simulationEssentials['timer']
+ self.checkChangeInPlotFile = simulationEssentials['checkChangeInPlotFile']
self.progressBarUi = progressBar.Ui_Form(self.process, self.simulationEssentials)
self.progressBarUi.setupUi(self.terminal)
self.layout = QtWidgets.QVBoxLayout(self)
@@ -50,6 +50,7 @@ class NgspiceWidget(QtWidgets.QWidget):
# ";ngspice -r " + command.replace(".cir.out", ".raw") + \
# " " + command
# Creating argument for process
+ self.currTime = time.time()
self.args = ['-b', '-r', command.replace(".cir.out", ".raw"), command]
self.process.setWorkingDirectory(projPath)
self.progressBarUi.setNgspiceArgs(self.args)
@@ -68,14 +69,16 @@ class NgspiceWidget(QtWidgets.QWidget):
self.gawProcess.start('sh', ['-c', self.gawCommand])
print(self.gawCommand)
- def finishSimulation(self):
+ def finishSimulation(self, exitCode, exitStatus):
+ if exitStatus == QtCore.QProcess.NormalExit:
+ self.checkChangeInPlotFile(self.currTime)
self.readyToPrintSimulationStatus = True
self.enableButtons = self.simulationEssentials['enableButtons']
self.enableButtons(True)
self.progressBarUi.showProgressCompleted()
- self.qTimer.timeout.connect(self.writeSimulationStatus)
+ self.writeSimulationStatus()
def writeSimulationStatus(self):
if self.readyToPrintSimulationStatus is False:
diff --git a/src/progressBar/progressBar.py b/src/progressBar/progressBar.py
index 5b667db7..e1b9be34 100644
--- a/src/progressBar/progressBar.py
+++ b/src/progressBar/progressBar.py
@@ -15,7 +15,6 @@ import os
class Ui_Form(object):
def __init__(self, qProcess, simulationEssentials):
self.qProcess = qProcess
- self.qTimer = simulationEssentials['timer']
self.enableButtons = simulationEssentials['enableButtons']
self.isSimulationSuccess = simulationEssentials['isSimulationSuccess']
self.resetSimulationVariables = simulationEssentials['resetSimulationVariables']
@@ -114,10 +113,11 @@ class Ui_Form(object):
failedFormat = '<span style="color:#ff3333;">{}</span>'
successFormat = '<span style="color:#00ff00;">{}</span>'
- if isSuccess:
- self.simulationConsole.append(successFormat.format("Simulation Completed Successfully!"))
- else:
- self.simulationConsole.append(failedFormat.format("Simulation Failed!"))
+ if self.qProcess.exitStatus() == QtCore.QProcess.NormalExit:
+ if isSuccess:
+ self.simulationConsole.append(successFormat.format("Simulation Completed Successfully!"))
+ else:
+ self.simulationConsole.append(failedFormat.format("Simulation Failed!"))
def scrollConsoleToBottom(self):
scrollLength = self.simulationConsole.verticalScrollBar().maximum()
@@ -132,10 +132,9 @@ class Ui_Form(object):
self.progressBar.setProperty("value", 100)
def cancelSimulation(self):
- if not self.qTimer.isActive():
+ if (self.qProcess.state() == QtCore.QProcess.NotRunning):
return
cancelFormat = '<span style="color:#3385ff;">{}</span>'
- self.qTimer.stop()
self.qProcess.kill()
self.showProgressCompleted()
self.simulationConsole.append(cancelFormat.format("Simulation Cancelled!"))
@@ -145,13 +144,12 @@ class Ui_Form(object):
self.args = args
def redoSimulation(self):
- if self.qTimer.isActive():
+ if (self.qProcess.state() == QtCore.QProcess.Running):
return
self.showProgressRunning()
self.simulationConsole.setText("")
self.resetSimulationVariables()
self.qProcess.start('ngspice', self.args)
- self.qTimer.start()
def changeColor(self):
if self.dark_color is True: