diff options
author | PatelVatsalB21 | 2022-09-01 14:10:15 +0530 |
---|---|---|
committer | PatelVatsalB21 | 2022-09-01 14:10:15 +0530 |
commit | 44fcfba014e212164787da16978f849a57ccebab (patch) | |
tree | ef11e04631bc48c87e7b9152aeb9f1fff233a052 /src/kicadtoNgspice/KicadtoNgspice.py | |
parent | 49efba6b6844f0c90f48159dfcdab84804e3df02 (diff) | |
download | eSim-44fcfba014e212164787da16978f849a57ccebab.tar.gz eSim-44fcfba014e212164787da16978f849a57ccebab.tar.bz2 eSim-44fcfba014e212164787da16978f849a57ccebab.zip |
Added Multiple Instance Functionality And Updated GUI
Diffstat (limited to 'src/kicadtoNgspice/KicadtoNgspice.py')
-rw-r--r-- | src/kicadtoNgspice/KicadtoNgspice.py | 164 |
1 files changed, 124 insertions, 40 deletions
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py index 28294be1..7ca65776 100644 --- a/src/kicadtoNgspice/KicadtoNgspice.py +++ b/src/kicadtoNgspice/KicadtoNgspice.py @@ -16,18 +16,21 @@ # REVISION: Saturday 25 July 2020 # ========================================================================= -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: @@ -530,7 +546,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 +555,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 +591,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 +610,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 +706,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 +823,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 +911,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": |