diff options
Diffstat (limited to 'src/kicadtoNgspice')
-rwxr-xr-x | src/kicadtoNgspice/Convert.py | 154 | ||||
-rwxr-xr-x | src/kicadtoNgspice/DeviceModel.py | 136 | ||||
-rw-r--r-- | src/kicadtoNgspice/KicadtoNgspice.py | 138 | ||||
-rw-r--r-- | src/kicadtoNgspice/Microcontroller.py | 283 | ||||
-rw-r--r-- | src/kicadtoNgspice/Model.py | 224 | ||||
-rw-r--r-- | src/kicadtoNgspice/Processing.py | 2 | ||||
-rw-r--r-- | src/kicadtoNgspice/TrackWidget.py | 2 |
7 files changed, 738 insertions, 201 deletions
diff --git a/src/kicadtoNgspice/Convert.py b/src/kicadtoNgspice/Convert.py index 566182e0..66f8a7c0 100755 --- a/src/kicadtoNgspice/Convert.py +++ b/src/kicadtoNgspice/Convert.py @@ -1,9 +1,11 @@ -from PyQt5 import QtWidgets import os import shutil -from . import TrackWidget from xml.etree import ElementTree as ET +from PyQt5 import QtWidgets + +from . import TrackWidget + class Convert: """ @@ -67,9 +69,8 @@ class Convert: theta_val = str(self.entry_var[self.end].text()) if len( str(self.entry_var[self.end].text())) > 0 else '0' self.addline = self.addline.partition( - '(')[0] + "(" + vo_val + " " + va_val + " " +\ - freq_val + " " + td_val + " " +\ - theta_val + ")" + '(')[0] + "(" + vo_val + " " + va_val + " " + \ + freq_val + " " + td_val + " " + theta_val + ")" self.sourcelistvalue.append([self.index, self.addline]) except BaseException: print( @@ -102,8 +103,8 @@ class Convert: str(self.entry_var[self.end].text())) > 0 else '0' self.addline = self.addline.partition( - '(')[0] + "(" + v1_val + " " + v2_val + " " +\ - td_val + " " + tr_val + " " + tf_val + " " +\ + '(')[0] + "(" + v1_val + " " + v2_val + " " + \ + td_val + " " + tr_val + " " + tf_val + " " + \ pw_val + " " + tp_val + ")" self.sourcelistvalue.append([self.index, self.addline]) except BaseException: @@ -183,8 +184,8 @@ class Convert: str(self.entry_var[self.end].text())) > 0 else '0' self.addline = self.addline.partition( - '(')[0] + "(" + v1_val + " " + v2_val + " " +\ - td1_val + " " + tau1_val + " " + td2_val +\ + '(')[0] + "(" + v1_val + " " + v2_val + " " + \ + td1_val + " " + tau1_val + " " + td2_val + \ " " + tau2_val + ")" self.sourcelistvalue.append([self.index, self.addline]) except BaseException: @@ -403,18 +404,21 @@ class Convert: if num_turns2 == "": num_turns2 = "620" addmodelLine = ".model " + \ - line[3] + \ - "_primary lcouple (num_turns= " + num_turns + ")" + line[3] + \ + "_primary lcouple (num_turns= " + \ + num_turns + ")" modelParamValue.append( [line[0], addmodelLine, "*primary lcouple"]) addmodelLine = ".model " + \ - line[3] + "_iron_core core (" + bh_array + \ - " area = " + area + " length =" + length + ")" + line[3] + "_iron_core core (" + bh_array + \ + " area = " + area + " length =" + length + \ + ")" modelParamValue.append( [line[0], addmodelLine, "*iron core"]) addmodelLine = ".model " + \ - line[3] + \ - "_secondary lcouple (num_turns =" + num_turns2 + ")" + line[3] + \ + "_secondary lcouple (num_turns =" + \ + num_turns2 + ")" modelParamValue.append( [line[0], addmodelLine, "*secondary lcouple"]) except Exception as e: @@ -456,8 +460,8 @@ class Convert: default = 0 # Checking if value is iterable.its for vector if ( - not isinstance(value, str) and - hasattr(value, '__iter__') + not isinstance(value, str) and + hasattr(value, '__iter__') ): addmodelLine += param + "=[" for lineVar in value: @@ -500,6 +504,122 @@ class Convert: return schematicInfo + def addMicrocontrollerParameter(self, schematicInfo): + """ + This function adds the Microcontroller Model details to schematicInfo + """ + + # Create object of TrackWidget + self.obj_track = TrackWidget.TrackWidget() + + # List to store model line + addmodelLine = [] + modelParamValue = [] + + for line in self.obj_track.microcontrollerTrack: + # print "Model Track :",line + try: + start = line[7] + # end = line[8] + addmodelLine = ".model " + line[3] + " " + line[2] + "(" + z = 0 + for key, value in line[9].items(): + # Checking for default value and accordingly assign + # param and default. + if ':' in key: + key = key.split(':') + param = key[0] + default = key[1] + else: + param = key + default = 0 + # Checking if value is iterable.its for vector + if ( + not isinstance(value, str) and + hasattr(value, '__iter__') + ): + addmodelLine += param + "=[" + for lineVar in value: + if str( + self.obj_track.microcontroller_var + [lineVar].text()) == "": + paramVal = default + else: + paramVal = str( + self.obj_track.microcontroller_var + [lineVar].text()) + # Checks For 5th Parameter(Hex File Path) + if z == 4: + chosen_file_path = paramVal + star_file_path = chosen_file_path + star_count = 0 + for c in chosen_file_path: + # If character is uppercase + if c.isupper(): + c_in = chosen_file_path.index(c) + c_in += star_count + # Adding asterisks(*) to the path + # around the character + star_file_path = \ + star_file_path[ + :c_in] + "*" + star_file_path[ + c_in] + "**" + star_file_path[ + c_in + 1:] + star_count += 3 + + paramVal = "\"" + star_file_path + "\"" + + addmodelLine += paramVal + " " + z = z + 1 + addmodelLine += "] " + else: + if str( + self.obj_track.microcontroller_var + [value].text()) == "": + paramVal = default + else: + paramVal = str( + self.obj_track.microcontroller_var + [value].text()) + # Checks For 5th Parameter(Hex File Path) + if z == 4: + chosen_file_path = paramVal + star_file_path = chosen_file_path + star_count = 0 + for c in chosen_file_path: + # If character is uppercase + if c.isupper(): + c_in = chosen_file_path.index(c) + c_in += star_count + # Adding asterisks(*) to the path around + # the character + star_file_path = \ + star_file_path[:c_in] + "*" + \ + star_file_path[c_in] + "**" + \ + star_file_path[c_in + 1:] + star_count += 3 + + paramVal = "\"" + star_file_path + "\"" + z = z + 1 + addmodelLine += param + "=" + paramVal + " " + + addmodelLine += ") " + modelParamValue.append([line[0], addmodelLine, line[4]]) + except Exception as e: + print("Caught an exception in microcontroller ", line[1]) + print("Exception Message : ", str(e)) + + # Adding it to schematic + for item in modelParamValue: + if ".ic" in item[1]: + schematicInfo.insert(0, item[1]) + schematicInfo.insert(0, item[2]) + else: + schematicInfo.append(item[2]) # Adding Comment + schematicInfo.append(item[1]) # Adding model line + + return schematicInfo + def addDeviceLibrary(self, schematicInfo, kicadFile): """ This function add the library details to schematicInfo diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 7fb9776e..ccbe8986 100755 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -15,6 +15,8 @@ class DeviceModel(QtWidgets.QWidget): - d DIODE - j JFET - m MOSFET + - s SWITCH + - tx single lossy transmission line - Other 2 functions same as the ones in subCircuit - trackLibrary - trackLibraryWithoutButton @@ -436,6 +438,131 @@ class DeviceModel(QtWidgets.QWidget): self.grid.addWidget(jfetbox) # Adding Device Details # + # Increment row and widget count + self.row = self.row + 1 + self.devicemodel_dict_end[words[0]] = self.count + self.count = self.count + 1 + + elif eachline[0] == 's': + # print("Device Model Switch:", words[0]) + self.devicemodel_dict_beg[words[0]] = self.count + switchbox = QtWidgets.QGroupBox() + switchgrid = QtWidgets.QGridLayout() + switchbox.setTitle( + "Add library for Switch " + + words[0] + + " : " + + words[5]) + self.entry_var[self.count] = QtWidgets.QLineEdit() + self.entry_var[self.count].setText("") + # global path_name + try: + for child in root: + if child.tag == words[0]: + # print("DEVICE MODEL MATCHING---", \ + # child.tag, words[0]) + try: + if child[0].text \ + and os.path.exists(child[0].text): + path_name = child[0].text + self.entry_var[self.count] \ + .setText(child[0].text) + else: + self.entry_var[self.count].setText("") + except BaseException as e: + print("Error when set text of device " + + "model switch :", str(e)) + except BaseException: + pass + + switchgrid.addWidget(self.entry_var[self.count], self.row, 1) + self.addbtn = QtWidgets.QPushButton("Add") + self.addbtn.setObjectName("%d" % self.count) + self.addbtn.clicked.connect(self.trackLibrary) + self.deviceDetail[self.count] = words[0] + + if self.entry_var[self.count].text() == "": + pass + else: + self.trackLibraryWithoutButton(self.count, path_name) + + switchgrid.addWidget(self.addbtn, self.row, 2) + switchbox.setLayout(switchgrid) + + # CSS + switchbox.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(switchbox) + + # Adding Device Details # + + # Increment row and widget count + self.row = self.row + 1 + self.devicemodel_dict_end[words[0]] = self.count + self.count = self.count + 1 + + elif eachline[0] == 'ytxl': + # print("Device Model ymod:", words[0]) + self.devicemodel_dict_beg[words[0]] = self.count + ymodbox = QtWidgets.QGroupBox() + ymodgrid = QtWidgets.QGridLayout() + ymodbox.setTitle( + "Add library for ymod " + + words[0] + + " : " + + words[4]) + self.entry_var[self.count] = QtWidgets.QLineEdit() + self.entry_var[self.count].setText("") + # global path_name + try: + for child in root: + if child.tag == words[0]: + # print("DEVICE MODEL MATCHING---", \ + # child.tag, words[0]) + try: + if child[0].text \ + and os.path.exists(child[0].text): + path_name = child[0].text + self.entry_var[self.count] \ + .setText(child[0].text) + else: + self.entry_var[self.count].setText("") + except BaseException as e: + print("Error when set text of device " + + "model ymod :", str(e)) + except BaseException: + pass + + ymodgrid.addWidget(self.entry_var[self.count], self.row, 1) + self.addbtn = QtWidgets.QPushButton("Add") + self.addbtn.setObjectName("%d" % self.count) + self.addbtn.clicked.connect(self.trackLibrary) + self.deviceDetail[self.count] = words[0] + + if self.entry_var[self.count].text() == "": + pass + else: + self.trackLibraryWithoutButton(self.count, path_name) + + ymodgrid.addWidget(self.addbtn, self.row, 2) + ymodbox.setLayout(ymodgrid) + + # CSS + ymodbox.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(ymodbox) + + # Adding Device Details # # Increment row and widget count self.row = self.row + 1 @@ -443,6 +570,7 @@ class DeviceModel(QtWidgets.QWidget): self.count = self.count + 1 elif eachline[0] == 'm': + self.devicemodel_dict_beg[words[0]] = self.count mosfetbox = QtWidgets.QGroupBox() mosfetgrid = QtWidgets.QGridLayout() @@ -452,7 +580,7 @@ class DeviceModel(QtWidgets.QWidget): "Add library for MOSFET " + words[0] + " : " + - words[5]) + words[4]) self.entry_var[self.count] = QtWidgets.QLineEdit() self.entry_var[self.count].setText("") self.entry_var[self.count].setReadOnly(True) @@ -512,12 +640,12 @@ class DeviceModel(QtWidgets.QWidget): # print("DEVICE MODEL MATCHING---", \ # child.tag, words[0]) while i <= end: - self.entry_var[i].setText(child[i-beg].text) + self.entry_var[i].setText(child[i - beg].text) if (i - beg) == 0: if os.path.exists(child[0].text): self.entry_var[i] \ - .setText(child[i-beg].text) - path_name = child[i-beg].text + .setText(child[i - beg].text) + path_name = child[i - beg].text else: self.entry_var[i].setText("") i = i + 1 diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py index 231efd52..e018143f 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: Sunday 18 September 2022 +# 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: @@ -552,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 @@ -568,16 +585,16 @@ class MainWindow(QtWidgets.QWidget): 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 +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 @@ -615,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) @@ -650,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) @@ -761,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'): diff --git a/src/kicadtoNgspice/Microcontroller.py b/src/kicadtoNgspice/Microcontroller.py new file mode 100644 index 00000000..a9360147 --- /dev/null +++ b/src/kicadtoNgspice/Microcontroller.py @@ -0,0 +1,283 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +import os +import random +from configparser import ConfigParser +from xml.etree import ElementTree as ET + +from PyQt5 import QtWidgets, QtCore + +from . import TrackWidget + + +# Created By Vatsal Patel on 01/07/2022 + +class Microcontroller(QtWidgets.QWidget): + """ + - This class creates Model Tab of KicadtoNgspice window. + The widgets are created dynamically in the Model Tab. + """ + + 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('~') + + 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", os.path.expanduser('~'), + "HEX files (*.hex);;Text files (*.txt)" + )[0] + ) + + if not self.hexfile: + """If no path is selected by user function returns""" + return + + chosen_file_path = os.path.abspath(self.hexfile) + btn = self.sender() + + # If path is selected the clicked button is stored in btn variable and + # checked from list of buttons to add the file path to correct + # QLineEdit + + if btn in self.hex_btns: + if "Add Hex File" in self.sender().text(): + self.obj_trac.microcontroller_var[ + 4 + (5 * self.hex_btns.index(btn))].setText( + chosen_file_path) + + def __init__( + self, + schematicInfo, + modelList, + clarg1, + ): + + QtWidgets.QWidget.__init__(self) + + # Processing for getting previous values + + kicadFile = clarg1 + (projpath, filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + check = 1 + try: + f = open( + os.path.join(projpath, project_name + "_Previous_Values.xml"), + "r", + ) + tree = ET.parse(f) + parent_root = tree.getroot() + for parent in parent_root: + if parent.tag == "microcontroller": + self.root = parent + except BaseException: + + check = 0 + print("Microcontroller Previous Values XML is Empty") + + # Creating track widget object + + self.obj_trac = TrackWidget.TrackWidget() + + # for increasing row and counting/tracking line edit widget + + self.nextrow = 0 + self.nextcount = 0 + + # for storing line edit details position details + + self.start = 0 + self.end = 0 + self.entry_var = [] + self.hex_btns = [] + self.text = "" + + # Creating GUI dynamically for Model tab + + self.grid = QtWidgets.QGridLayout() + self.setLayout(self.grid) + + for line in modelList: + # print "ModelList Item:",line + # Adding title label for model + # Key: Tag name,Value:Entry widget number + + tag_dict = {} + modelbox = QtWidgets.QGroupBox() + modelgrid = QtWidgets.QGridLayout() + modelbox.setTitle(line[5]) + self.start = self.nextcount + + # line[7] is parameter dictionary holding parameter tags. + + i = 0 + for (key, value) in line[7].items(): + # Check if value is iterable + + if not isinstance(value, str) and hasattr(value, "__iter__"): + + # For tag having vector value + + temp_tag = [] + for item in value: + + paramLabel = QtWidgets.QLabel(item) + modelgrid.addWidget(paramLabel, self.nextrow, 0) + self.obj_trac.microcontroller_var[ + self.nextcount + ] = QtWidgets.QLineEdit() + self.obj_trac.microcontroller_var[ + self.nextcount] = QtWidgets.QLineEdit() + self.obj_trac.microcontroller_var[ + self.nextcount].setText("") + + if "Enter Instance ID (Between 0-99)" in value: + self.obj_trac.microcontroller_var[ + self.nextcount].hide() + self.obj_trac.microcontroller_var[ + self.nextcount].setText( + str(random.randint(0, 99))) + else: + modelgrid.addWidget(paramLabel, self.nextrow, 0) + + if "Path of your .hex file" in value: + self.obj_trac.microcontroller_var[ + self.nextcount].setReadOnly(True) + addbtn = QtWidgets.QPushButton("Add Hex File") + addbtn.setObjectName("%d" % self.nextcount) + addbtn.clicked.connect(self.addHex) + modelgrid.addWidget(addbtn, self.nextrow, 2) + modelbox.setLayout(modelgrid) + self.hex_btns.append(addbtn) + try: + for child in root: + if ( + child.text == line[2] + and child.tag == line[3] + ): + self.obj_trac.microcontroller_var[ + self.nextcount].setText(child[i].text) + i = i + 1 + except BaseException: + print("Passes previous values") + + modelgrid.addWidget( + self.obj_trac.microcontroller_var[self.nextcount], + self.nextrow, + 1, ) + + temp_tag.append(self.nextcount) + self.nextcount = self.nextcount + 1 + self.nextrow = self.nextrow + 1 + + tag_dict[key] = temp_tag + + else: + + paramLabel = QtWidgets.QLabel(value) + self.obj_trac.microcontroller_var[ + self.nextcount + ] = QtWidgets.QLineEdit() + self.obj_trac.microcontroller_var[ + self.nextcount] = QtWidgets.QLineEdit() + self.obj_trac.microcontroller_var[self.nextcount].setText( + "") + + if "Enter Instance ID (Between 0-99)" in value: + self.obj_trac.microcontroller_var[ + self.nextcount].hide() + self.obj_trac.microcontroller_var[ + self.nextcount].setText(str(random.randint(0, 99))) + else: + modelgrid.addWidget(paramLabel, self.nextrow, 0) + + if "Path of your .hex file" in value: + self.obj_trac.microcontroller_var[ + self.nextcount].setReadOnly(True) + addbtn = QtWidgets.QPushButton("Add Hex File") + addbtn.setObjectName("%d" % self.nextcount) + addbtn.clicked.connect(self.addHex) + modelgrid.addWidget(addbtn, self.nextrow, 2) + modelbox.setLayout(modelgrid) + self.hex_btns.append(addbtn) + + # 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) + + try: + for child in root: + if child.text == line[2] and child.tag == line[3]: + self.obj_trac.microcontroller_var[ + self.nextcount].setText(child[i].text) + i = i + 1 + + except BaseException: + print("Passes previous values") + + modelgrid.addWidget( + self.obj_trac.microcontroller_var[self.nextcount], + self.nextrow, + 1, ) + + tag_dict[key] = self.nextcount + self.nextcount = self.nextcount + 1 + self.nextrow = self.nextrow + 1 + + self.end = self.nextcount - 1 + 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) + + # This keeps the track of Microcontroller Tab Widget + + lst = [ + line[0], + line[1], + line[2], + line[3], + line[4], + line[5], + line[6], + self.start, + self.end, + tag_dict, + ] + check = 0 + for itr in self.obj_trac.microcontrollerTrack: + if itr == lst: + check = 1 + if check == 0: + self.obj_trac.microcontrollerTrack.append(lst) + + self.show() diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 75c0eaf5..55a988c0 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -1,69 +1,27 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -from PyQt5 import QtWidgets, QtCore -from . import TrackWidget -from xml.etree import ElementTree as ET import os +from xml.etree import ElementTree as ET +from PyQt5 import QtWidgets +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 - def addHex(self): - """ - This function is use to keep track of all Device Model widget - """ - - # print("Calling Track Device Model Library funtion") - - init_path = "../../../" - if os.name == "nt": - init_path = "" - - self.hexfile = QtCore.QDir.toNativeSeparators( - QtWidgets.QFileDialog.getOpenFileName( - self, "Open Hex Directory", init_path + "home", "*.hex" - )[0] - ) - self.text = open(self.hexfile).read() - - # By Sumanto and Jay - def uploadHex(self): - """ - This function is use to keep track of all Device Model widget - """ - - # 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.file.write(self.text) - self.file.close() - def __init__( - self, - schematicInfo, - modelList, - clarg1, + self, + schematicInfo, + modelList, + clarg1, ): QtWidgets.QWidget.__init__(self) # Processing for getting previous values - kicadFile = clarg1 (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) @@ -79,33 +37,27 @@ class Model(QtWidgets.QWidget): if child.tag == "model": root = child except BaseException: - check = 0 - print("Model Previous Values XML is Empty") # Creating track widget object - self.obj_trac = TrackWidget.TrackWidget() # for increasing row and counting/tracking line edit widget - self.nextrow = 0 self.nextcount = 0 # for storing line edit details position details - self.start = 0 self.end = 0 - self.entry_var = {} + self.entry_var = [] + self.hex_btns = [] self.text = "" # Creating GUI dynamically for Model tab - self.grid = QtWidgets.QGridLayout() self.setLayout(self.grid) for line in modelList: - # print "ModelList Item:",line # Adding title label for model # Key: Tag name,Value:Entry widget number @@ -115,99 +67,79 @@ 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. - i = 0 for (key, value) in line[7].items(): + print(value) + print(key) # Check if value is iterable - if not isinstance(value, str) and hasattr(value, "__iter__"): - # For tag having vector value - 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.obj_trac.model_entry_var[ + self.nextcount] = QtWidgets.QLineEdit() + self.obj_trac.model_entry_var[self.nextcount].setText( + "") 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) + + modelgrid.addWidget( + self.obj_trac.model_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: + else: paramLabel = QtWidgets.QLabel(value) 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.obj_trac.model_entry_var[ + self.nextcount] = QtWidgets.QLineEdit() + self.obj_trac.model_entry_var[self.nextcount].setText("") + + # 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) try: for child in root: @@ -215,56 +147,27 @@ 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) + modelgrid.addWidget( + self.obj_trac.model_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) # CSS - modelbox.setStyleSheet( " \ QGroupBox { border: 1px solid gray; border-radius: \ @@ -277,7 +180,6 @@ class Model(QtWidgets.QWidget): self.grid.addWidget(modelbox) # This keeps the track of Model Tab Widget - lst = [ line[0], line[1], @@ -298,3 +200,21 @@ 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) diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py index a0b20ada..11c95965 100644 --- a/src/kicadtoNgspice/Processing.py +++ b/src/kicadtoNgspice/Processing.py @@ -408,7 +408,7 @@ class PrcocessNetlist: # Insert comment at remove line schematicInfo.insert(index, "* " + compline) comment = "* Schematic Name:\ - " + compType + ", NgSpice Name: " + modelname + " + compType + ", Ngspice Name: " + modelname # Here instead of adding compType(use for XML), # added modelName(Unique Model Name) modelList.append( diff --git a/src/kicadtoNgspice/TrackWidget.py b/src/kicadtoNgspice/TrackWidget.py index 3a8b0dac..9f1d07c2 100644 --- a/src/kicadtoNgspice/TrackWidget.py +++ b/src/kicadtoNgspice/TrackWidget.py @@ -24,7 +24,9 @@ class TrackWidget: op_check = [] # Track widget for Model detail modelTrack = [] + microcontrollerTrack = [] model_entry_var = {} + microcontroller_var = {} # Track Widget for Device Model detail deviceModelTrack = {} |