summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice/KicadtoNgspice.py
diff options
context:
space:
mode:
authorSumanto Kar2023-05-04 13:59:44 +0530
committerGitHub2023-05-04 13:59:44 +0530
commit3d3bef144fc47ac3149a09a4f6f0f04879c7d46d (patch)
treee6c8b69d1a58d031e48258cc1cc0c5311a7daf48 /src/kicadtoNgspice/KicadtoNgspice.py
parenta58c718d43d3d3611bba5b6a67fc811450514a6c (diff)
parentadd82494ea6cdcc8a37609cd54aa0c5e772b2668 (diff)
downloadeSim-3d3bef144fc47ac3149a09a4f6f0f04879c7d46d.tar.gz
eSim-3d3bef144fc47ac3149a09a4f6f0f04879c7d46d.tar.bz2
eSim-3d3bef144fc47ac3149a09a4f6f0f04879c7d46d.zip
Merge branch 'master' into master
Diffstat (limited to 'src/kicadtoNgspice/KicadtoNgspice.py')
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py252
1 files changed, 179 insertions, 73 deletions
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index 28294be1..f549c5c6 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -13,21 +13,24 @@
# MODIFIED: Rahul Paknikar, rahulp@iitb.ac.in
# ORGANIZATION: eSim Team at FOSSEE, IIT Bombay
# CREATED: Wednesday 04 March 2015
-# REVISION: Saturday 25 July 2020
+# REVISION: Tuesday 25 April 2023
# =========================================================================
-import sys
import os
+import sys
+from xml.etree import ElementTree as ET
+
from PyQt5 import QtWidgets
-from .Processing import PrcocessNetlist
+
from . import Analysis
-from . import Source
-from . import Model
+from . import Convert
from . import DeviceModel
+from . import Model
+from . import Microcontroller
+from . import Source
from . import SubcircuitTab
-from . import Convert
from . import TrackWidget
-from xml.etree import ElementTree as ET
+from .Processing import PrcocessNetlist
class MainWindow(QtWidgets.QWidget):
@@ -93,10 +96,11 @@ class MainWindow(QtWidgets.QWidget):
schematicInfo, sourcelist)
# List storing model detail
- global modelList, outputOption,\
- unknownModelList, multipleModelList, plotText
+ global modelList, outputOption, unknownModelList, multipleModelList, \
+ plotText, microcontrollerList
modelList = []
+ microcontrollerList = []
outputOption = []
plotText = []
(
@@ -109,8 +113,10 @@ class MainWindow(QtWidgets.QWidget):
) = obj_proc.convertICintoBasicBlocks(
schematicInfo, outputOption, modelList, plotText
)
- # print("=======================================")
- # print("Model available in the Schematic :", modelList)
+ for line in modelList:
+ if line[6] == "Nghdl":
+ microcontrollerList.append(line)
+ modelList.remove(line)
"""
- Checking if any unknown model is used in schematic which is not
@@ -124,7 +130,7 @@ class MainWindow(QtWidgets.QWidget):
self.msg.setModal(True)
self.msg.setWindowTitle("Unknown Models")
self.content = "Your schematic contain unknown model " + \
- ', '.join(unknownModelList)
+ ', '.join(unknownModelList)
self.msg.showMessage(self.content)
self.msg.exec_()
@@ -134,7 +140,7 @@ class MainWindow(QtWidgets.QWidget):
self.msg.setWindowTitle("Multiple Models")
self.mcontent = "Look like you have duplicate model in \
modelParamXML directory " + \
- ', '.join(multipleModelList[0])
+ ', '.join(multipleModelList[0])
self.msg.showMessage(self.mcontent)
self.msg.exec_()
@@ -179,6 +185,9 @@ class MainWindow(QtWidgets.QWidget):
- Subcircuits => obj_subcircuitTab
=> SubcircuitTab.SubcircuitTab(`schematicInfo`,`path_to_projFile`)
+ - Microcontrollers => obj_microcontroller
+ => Model.Model(schematicInfo, microcontrollerList, self.clarg1)
+
- Finally pass each of these objects, to widgets
- convertWindow > mainLayout > tabWidgets > AnalysisTab, SourceTab ...
"""
@@ -213,6 +222,12 @@ class MainWindow(QtWidgets.QWidget):
schematicInfo, self.clarg1)
self.subcircuitTab.setWidget(obj_subcircuitTab)
self.subcircuitTab.setWidgetResizable(True)
+ global obj_microcontroller
+ self.microcontrollerTab = QtWidgets.QScrollArea()
+ obj_microcontroller = Microcontroller.\
+ Microcontroller(schematicInfo, microcontrollerList, self.clarg1)
+ self.microcontrollerTab.setWidget(obj_microcontroller)
+ self.microcontrollerTab.setWidgetResizable(True)
self.tabWidget = QtWidgets.QTabWidget()
# self.tabWidget.TabShape(QtWidgets.QTabWidget.Rounded)
@@ -221,6 +236,7 @@ class MainWindow(QtWidgets.QWidget):
self.tabWidget.addTab(self.modelTab, "Ngspice Model")
self.tabWidget.addTab(self.deviceModelTab, "Device Modeling")
self.tabWidget.addTab(self.subcircuitTab, "Subcircuits")
+ self.tabWidget.addTab(self.microcontrollerTab, "Microcontroller")
self.mainLayout = QtWidgets.QVBoxLayout()
self.mainLayout.addWidget(self.tabWidget)
# self.mainLayout.addStretch(1)
@@ -247,9 +263,9 @@ class MainWindow(QtWidgets.QWidget):
try:
fr = open(
- os.path.join(
- projpath, project_name + "_Previous_Values.xml"), 'r'
- )
+ os.path.join(
+ projpath, project_name + "_Previous_Values.xml"), 'r'
+ )
temp_tree = ET.parse(fr)
temp_root = temp_tree.getroot()
except BaseException:
@@ -376,9 +392,9 @@ class MainWindow(QtWidgets.QWidget):
if child.tag == "source":
attr_source = child
- count = 1
+ count = 0
grand_child_count = 0
- keys = list(obj_source.entry_var.keys())
+ entry_var_keys = list(obj_source.entry_var.keys())
for i in store_schematicInfo:
tmp_check = 0
@@ -390,7 +406,7 @@ class MainWindow(QtWidgets.QWidget):
for grand_child in child:
grand_child.text = \
str(obj_source.entry_var
- [keys[grand_child_count]].text())
+ [entry_var_keys[grand_child_count]].text())
grand_child_count += 1
if tmp_check == 0:
words = i.split(' ')
@@ -406,102 +422,124 @@ class MainWindow(QtWidgets.QWidget):
# attr_ac = ET.SubElement(attr_var, "ac")
ET.SubElement(
attr_var, "field1", name="Amplitude"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field2", name="Phase"
- ).text = str(obj_source.entry_var[count].text())
- count += 2
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
+ count += 1
elif words[len(words) - 1] == "dc":
# attr_dc = ET.SubElement(attr_var, "dc")
ET.SubElement(
attr_var, "field1", name="Value"
- ).text = str(obj_source.entry_var[count].text())
- count += 2
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
+ count += 1
elif words[len(words) - 1] == "sine":
# attr_sine = ET.SubElement(attr_var, "sine")
ET.SubElement(
attr_var, "field1", name="Offset Value"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field2", name="Amplitude"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field3", name="Frequency"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field4", name="Delay Time"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field5", name="Damping Factor"
- ).text = str(obj_source.entry_var[count].text())
- count += 2
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
+ count += 1
elif words[len(words) - 1] == "pulse":
# attr_pulse=ET.SubElement(attr_var,"pulse")
ET.SubElement(
attr_var, "field1", name="Initial Value"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field2", name="Pulse Value"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field3", name="Delay Time"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field4", name="Rise Time"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field5", name="Fall Time"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field5", name="Pulse width"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field5", name="Period"
- ).text = str(obj_source.entry_var[count].text())
- count += 2
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
+ count += 1
elif words[len(words) - 1] == "pwl":
# attr_pwl=ET.SubElement(attr_var,"pwl")
ET.SubElement(
attr_var, "field1", name="Enter in pwl format"
- ).text = str(obj_source.entry_var[count].text())
- count += 2
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
+ count += 1
elif words[len(words) - 1] == "exp":
# attr_exp=ET.SubElement(attr_var,"exp")
ET.SubElement(
attr_var, "field1", name="Initial Value"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field2", name="Pulsed Value"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field3", name="Rise Delay Time"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field4", name="Rise Time Constant"
- ).text = str(obj_source.entry_var[count].text())
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
- attr_var, "field5", name="Fall TIme"
- ).text = str(obj_source.entry_var[count].text())
+ attr_var, "field5", name="Fall Time"
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
count += 1
ET.SubElement(
attr_var, "field6", name="Fall Time Constant"
- ).text = str(obj_source.entry_var[count].text())
- count += 2
+ ).text = str(obj_source.entry_var
+ [entry_var_keys[count]].text())
+ count += 1
if check == 0:
attr_model = ET.SubElement(attr_parent, "model")
@@ -530,7 +568,8 @@ class MainWindow(QtWidgets.QWidget):
for grand_child in child:
if i <= end:
grand_child.text = \
- str(obj_model.obj_trac.model_entry_var[i].text())
+ str(obj_model.obj_trac.model_entry_var[
+ i].text())
i = i + 1
tmp_check = 1
@@ -538,24 +577,24 @@ class MainWindow(QtWidgets.QWidget):
attr_ui = ET.SubElement(attr_model, line[3], name="type")
attr_ui.text = line[2]
for key, value in line[7].items():
- if(
- hasattr(value, '__iter__') and
- i <= end and not isinstance(value, str)
+ if (
+ hasattr(value, '__iter__') and
+ i <= end and not isinstance(value, str)
):
for item in value:
ET.SubElement(
attr_ui, "field" + str(i + 1), name=item
).text = str(
- obj_model.obj_trac.model_entry_var[i].text()
- )
+ obj_model.obj_trac.model_entry_var[i].text()
+ )
i = i + 1
else:
ET.SubElement(
attr_ui, "field" + str(i + 1), name=value
).text = str(
- obj_model.obj_trac.model_entry_var[i].text()
- )
+ obj_model.obj_trac.model_entry_var[i].text()
+ )
i = i + 1
# Writing Device Model values
@@ -574,7 +613,7 @@ class MainWindow(QtWidgets.QWidget):
while it <= end:
ET.SubElement(attr_var, "field").text = \
- str(obj_devicemodel.entry_var[it].text())
+ str(obj_devicemodel.entry_var[it].text())
it = it + 1
# Writing Subcircuit values
@@ -593,9 +632,70 @@ class MainWindow(QtWidgets.QWidget):
while it <= end:
ET.SubElement(attr_var, "field").text = \
- str(obj_subcircuitTab.entry_var[it].text())
+ str(obj_subcircuitTab.entry_var[it].text())
it = it + 1
+ # Writing for Microcontroller
+ if check == 0:
+ attr_microcontroller = ET.SubElement(attr_parent,
+ "microcontroller")
+ if check == 1:
+ for child in attr_parent:
+ if child.tag == "microcontroller":
+ attr_microcontroller = child
+ i = 0
+
+ # tmp_check is a variable to check for duplicates in the xml file
+ tmp_check = 0
+ # tmp_i is the iterator in case duplicates are there;
+ # then in that case we need to replace only the child node and
+ # not create a new parent node
+
+ for line in microcontrollerList:
+ tmp_check = 0
+ for rand_itr in obj_microcontroller.obj_trac.microcontrollerTrack:
+ if rand_itr[2] == line[2] and rand_itr[3] == line[3]:
+ start = rand_itr[7]
+ end = rand_itr[8]
+
+ i = start
+ for child in attr_microcontroller:
+ if child.text == line[2] and child.tag == line[3]:
+ for grand_child in child:
+ if i <= end:
+ grand_child.text = \
+ str(
+ obj_microcontroller.
+ obj_trac.microcontroller_var[i].text())
+ i = i + 1
+ tmp_check = 1
+
+ if tmp_check == 0:
+ attr_ui = ET.SubElement(attr_microcontroller, line[3],
+ name="type")
+ attr_ui.text = line[2]
+ for key, value in line[7].items():
+ if (
+ hasattr(value, '__iter__') and
+ i <= end and not isinstance(value, str)
+ ):
+ for item in value:
+ ET.SubElement(
+ attr_ui, "field" + str(i + 1), name=item
+ ).text = str(
+ obj_microcontroller.
+ obj_trac.microcontroller_var[i].text()
+ )
+ i = i + 1
+ else:
+ ET.SubElement(
+ attr_ui, "field" + str(i + 1), name=value
+ ).text = str(
+ obj_microcontroller.obj_trac.microcontroller_var[
+ i].text()
+ )
+ i = i + 1
+
# xml written to previous value file for the project
tree = ET.ElementTree(attr_parent)
tree.write(fw)
@@ -628,6 +728,12 @@ class MainWindow(QtWidgets.QWidget):
print("=========================================================")
print("Netlist After Adding Ngspice Model :", store_schematicInfo)
+ store_schematicInfo = self.obj_convert.addMicrocontrollerParameter(
+ store_schematicInfo)
+ print("=========================================================")
+ print("Netlist After Adding Microcontroller Model :",
+ store_schematicInfo)
+
# Adding Device Library to SchematicInfo
store_schematicInfo = self.obj_convert.addDeviceLibrary(
store_schematicInfo, self.kicadFile)
@@ -739,14 +845,14 @@ class MainWindow(QtWidgets.QWidget):
words = eachline.split()
option = words[0]
if (option == '.ac' or option == '.dc' or option ==
- '.disto' or option == '.noise' or
- option == '.op' or option == '.pz' or option ==
- '.sens' or option == '.tf' or
+ '.disto' or option == '.noise' or
+ option == '.op' or option == '.pz' or option ==
+ '.sens' or option == '.tf' or
option == '.tran'):
analysisOption.append(eachline + '\n')
elif (option == '.save' or option == '.print' or option ==
- '.plot' or option == '.four'):
+ '.plot' or option == '.four'):
eachline = eachline.strip('.')
outputOption.append(eachline + '\n')
elif (option == '.nodeset' or option == '.ic'):
@@ -827,17 +933,17 @@ class MainWindow(QtWidgets.QWidget):
for i in range(2, len(words) - 1):
subcktInfo += words[i] + " "
continue
- if(
- words[0] == ".end" or
- words[0] == ".ac" or
- words[0] == ".dc" or
- words[0] == ".tran" or
- words[0] == '.disto' or
- words[0] == '.noise' or
- words[0] == '.op' or
- words[0] == '.pz' or
- words[0] == '.sens' or
- words[0] == '.tf'
+ if (
+ words[0] == ".end" or
+ words[0] == ".ac" or
+ words[0] == ".dc" or
+ words[0] == ".tran" or
+ words[0] == '.disto' or
+ words[0] == '.noise' or
+ words[0] == '.op' or
+ words[0] == '.pz' or
+ words[0] == '.sens' or
+ words[0] == '.tf'
):
continue
elif words[0] == ".control":