summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice
diff options
context:
space:
mode:
authorRahul P2023-04-25 10:06:19 +0530
committerGitHub2023-04-25 10:06:19 +0530
commit8293597cd3263f788fea1eaa6e9bb63be02f1b72 (patch)
tree021398d19b8b3d4abbce7c3a626828d13f70c3e7 /src/kicadtoNgspice
parent2b3b684b9f6b039beace62272c3d46dc8ec22147 (diff)
parent65c2f99de14c204a22c42c6ad22dfa5d77ffbd3c (diff)
downloadeSim-8293597cd3263f788fea1eaa6e9bb63be02f1b72.tar.gz
eSim-8293597cd3263f788fea1eaa6e9bb63be02f1b72.tar.bz2
eSim-8293597cd3263f788fea1eaa6e9bb63be02f1b72.zip
Merge pull request #204 from PatelVatsalB21/microcontroller_add_hex
Microcontroller Widget
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py156
-rw-r--r--src/kicadtoNgspice/Model.py198
2 files changed, 192 insertions, 162 deletions
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index 6a919de9..83e1642e 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -16,18 +16,20 @@
# REVISION: Sunday 18 September 2022
# =========================================================================
-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 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 +95,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,6 +112,10 @@ class MainWindow(QtWidgets.QWidget):
) = obj_proc.convertICintoBasicBlocks(
schematicInfo, outputOption, modelList, plotText
)
+ for line in modelList:
+ if line[6] == "Nghdl":
+ microcontrollerList.append(line)
+ modelList.remove(line)
# print("=======================================")
# print("Model available in the Schematic :", modelList)
@@ -124,7 +131,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 +141,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 +186,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 +223,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 = Model.Model(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 +237,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 +264,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:
@@ -552,7 +569,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
@@ -560,24 +578,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
@@ -596,7 +614,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
@@ -615,9 +633,71 @@ 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_model = ET.SubElement(attr_parent, "microcontroller")
+ if check == 1:
+ for child in attr_parent:
+ if child.tag == "microcontroller":
+ attr_model = 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 modelList:
+ tmp_check = 0
+ if line[6] == "Nghdl":
+ for rand_itr in obj_model.obj_trac.modelTrack:
+ 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_model:
+ if child.text == line[2] and child.tag == line[3]:
+ for grand_child in child:
+ if i <= end:
+ grand_child.text = str(
+ obj_model.obj_trac.model_entry_var[
+ i].text())
+ i = i + 1
+ tmp_check = 1
+
+ if tmp_check == 0:
+ 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)
+ ):
+ for item in value:
+ ET.SubElement(
+ attr_ui, "field" + str(i + 1), name=item
+ ).text = str(
+ obj_microcontroller.obj_trac.
+ model_entry_var[i].text()
+ )
+ i = i + 1
+
+ else:
+ ET.SubElement(
+ attr_ui, "field" + str(i + 1), name=value
+ ).text = str(
+ obj_microcontroller.obj_trac.model_entry_var[
+ i].text()
+ )
+ i = i + 1
+
# xml written to previous value file for the project
tree = ET.ElementTree(attr_parent)
tree.write(fw)
@@ -761,14 +841,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'):
@@ -849,17 +929,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":
diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py
index 1389e556..f12e7af2 100644
--- a/src/kicadtoNgspice/Model.py
+++ b/src/kicadtoNgspice/Model.py
@@ -1,68 +1,64 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-from PyQt5 import QtWidgets, QtCore, QtGui
-from PyQt5.QtCore import QObject, pyqtSlot
-from . import TrackWidget
-from xml.etree import ElementTree as ET
import os
-import sys
+from configparser import ConfigParser
+from xml.etree import ElementTree as ET
+from PyQt5 import QtWidgets, QtCore
+
+from . import TrackWidget
-class Model(QtWidgets.QWidget):
+class Model(QtWidgets.QWidget):
"""
- This class creates Model Tab of KicadtoNgspice window.
The widgets are created dynamically in the Model Tab.
"""
- # by Sumanto and Jay
+ # by Sumanto, Jay and Vatsal
def addHex(self):
"""
This function is use to keep track of all Device Model widget
"""
+ if os.name == 'nt':
+ self.home = os.path.join('library', 'config')
+ else:
+ self.home = os.path.expanduser('~')
- # print("Calling Track Device Model Library funtion")
-
- init_path = "../../../"
- if os.name == "nt":
- init_path = ""
+ self.parser = ConfigParser()
+ self.parser.read(os.path.join(
+ self.home, os.path.join('.nghdl', 'config.ini')))
+ self.nghdl_home = self.parser.get('NGHDL', 'NGHDL_HOME')
self.hexfile = QtCore.QDir.toNativeSeparators(
QtWidgets.QFileDialog.getOpenFileName(
- self, "Open Hex Directory", init_path + "home", "*.hex"
+ self, "Open Hex Directory", os.path.expanduser('~'),
+ "Text files (*.txt);;HEX files (*.hex)"
)[0]
)
+
self.text = open(self.hexfile).read()
chosen_file_path = os.path.abspath(self.hexfile)
+ filename = os.path.basename(chosen_file_path)
- # By Sumanto and Jay
+ path1 = os.sep + "src" + os.sep + "xspice" + os.sep + "icm" \
+ + os.sep + "ghdl" + os.sep + self.model_name
+ path2 = os.sep + "DUTghdl" + os.sep
- def uploadHex(self):
- """
- This function is use to keep track of all Device Model widget
- """
+ path_new = self.nghdl_home + path1 + path2
- # print("Calling Track Device Model Library funtion")
-
- path1 = os.path.expanduser("~")
- path2 = "/ngspice-nghdl/src/xspice/icm/ghdl"
- init_path = path1 + path2
- if os.name == "nt":
- init_path = ""
-
- self.hexloc = QtWidgets.QFileDialog.getExistingDirectory(
- self, "Open Hex Directory", init_path
- )
- self.file = open(self.hexloc + "/hex.txt", "w")
+ self.hexloc = path_new + filename
+ self.file = open(self.hexloc, "w")
self.file.write(self.text)
self.file.close()
+ self.entry_var[self.nextcount - 1].setText(chosen_file_path)
def __init__(
- self,
- schematicInfo,
- modelList,
- clarg1,
+ self,
+ schematicInfo,
+ modelList,
+ clarg1,
):
QtWidgets.QWidget.__init__(self)
@@ -110,7 +106,6 @@ class Model(QtWidgets.QWidget):
self.setLayout(self.grid)
for line in modelList:
-
# print "ModelList Item:",line
# Adding title label for model
# Key: Tag name,Value:Entry widget number
@@ -120,6 +115,7 @@ class Model(QtWidgets.QWidget):
modelgrid = QtWidgets.QGridLayout()
modelbox.setTitle(line[5])
self.start = self.nextcount
+ self.model_name = line[2]
# line[7] is parameter dictionary holding parameter tags.
@@ -134,73 +130,41 @@ class Model(QtWidgets.QWidget):
temp_tag = []
for item in value:
+
paramLabel = QtWidgets.QLabel(item)
modelgrid.addWidget(paramLabel, self.nextrow, 0)
self.obj_trac.model_entry_var[
self.nextcount
] = QtWidgets.QLineEdit()
- modelgrid.addWidget(
- self.obj_trac.model_entry_var[self.nextcount],
- self.nextrow,
- 1,
- )
+ self.entry_var[self.count] = QtWidgets.QLineEdit()
+ self.entry_var[self.count].setText("")
+
+ if value == "Path of your .hex file":
+ self.entry_var[self.nextcount].setReadOnly(True)
+ self.add_hex_btn(modelgrid, modelbox)
try:
for child in root:
if (
- child.text == line[2]
- and child.tag == line[3]
+ child.text == line[2]
+ and child.tag == line[3]
):
self.obj_trac.model_entry_var
[self.nextcount].setText(child[i].text)
+ self.entry_var[self.count].setText(
+ child[0].text)
i = i + 1
except BaseException:
pass
+ modelgrid.addWidget(self.entry_var[self.nextcount],
+ self.nextrow, 1)
temp_tag.append(self.nextcount)
self.nextcount = self.nextcount + 1
self.nextrow = self.nextrow + 1
- if "upload_hex_file:1" in tag_dict:
- self.addbtn = QtWidgets.QPushButton("Add Hex File")
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.addHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 2)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title {subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
- self.addbtn = QtWidgets.QPushButton(
- "Upload Hex File"
- )
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.uploadHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 3)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title {subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
tag_dict[key] = temp_tag
+
else:
paramLabel = QtWidgets.QLabel(value)
@@ -208,11 +172,12 @@ class Model(QtWidgets.QWidget):
self.obj_trac.model_entry_var[
self.nextcount
] = QtWidgets.QLineEdit()
- modelgrid.addWidget(
- self.obj_trac.model_entry_var[self.nextcount],
- self.nextrow,
- 1,
- )
+ self.entry_var[self.nextcount] = QtWidgets.QLineEdit()
+ self.entry_var[self.nextcount].setText("")
+
+ if value == "Path of your .hex file":
+ self.entry_var[self.nextcount].setReadOnly(True)
+ self.add_hex_btn(modelgrid, modelbox)
try:
for child in root:
@@ -220,50 +185,16 @@ class Model(QtWidgets.QWidget):
self.obj_trac.model_entry_var[
self.nextcount
].setText(child[i].text)
+ self.entry_var[self.count].setText(
+ child[0].text)
i = i + 1
except BaseException:
pass
-
+ modelgrid.addWidget(self.entry_var[self.nextcount],
+ self.nextrow, 1)
tag_dict[key] = self.nextcount
self.nextcount = self.nextcount + 1
self.nextrow = self.nextrow + 1
- if "upload_hex_file:1" in tag_dict:
- self.addbtn = QtWidgets.QPushButton("Add Hex File")
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.addHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 2)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title { subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
- self.addbtn = QtWidgets.QPushButton("Upload Hex File")
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.uploadHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 3)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title { subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
self.end = self.nextcount - 1
modelbox.setLayout(modelgrid)
@@ -303,3 +234,22 @@ class Model(QtWidgets.QWidget):
self.obj_trac.modelTrack.append(lst)
self.show()
+
+ def add_hex_btn(self, modelgrid, modelbox):
+ self.addbtn = QtWidgets.QPushButton("Add Hex File")
+ self.addbtn.setObjectName("%d" % self.nextcount)
+ self.addbtn.clicked.connect(self.addHex)
+ modelgrid.addWidget(self.addbtn, self.nextrow, 2)
+ modelbox.setLayout(modelgrid)
+
+ # CSS
+
+ modelbox.setStyleSheet(
+ " \
+ QGroupBox { border: 1px solid gray; border-radius:\
+ 9px; margin-top: 0.5em; } \
+ QGroupBox::title { subcontrol-origin: margin; left:\
+ 10px; padding: 0 3px 0 3px; } \
+ "
+ )
+ self.grid.addWidget(modelbox)