diff options
author | Sumanto Kar | 2023-05-04 13:59:44 +0530 |
---|---|---|
committer | GitHub | 2023-05-04 13:59:44 +0530 |
commit | 3d3bef144fc47ac3149a09a4f6f0f04879c7d46d (patch) | |
tree | e6c8b69d1a58d031e48258cc1cc0c5311a7daf48 /src/kicadtoNgspice | |
parent | a58c718d43d3d3611bba5b6a67fc811450514a6c (diff) | |
parent | add82494ea6cdcc8a37609cd54aa0c5e772b2668 (diff) | |
download | eSim-3d3bef144fc47ac3149a09a4f6f0f04879c7d46d.tar.gz eSim-3d3bef144fc47ac3149a09a4f6f0f04879c7d46d.tar.bz2 eSim-3d3bef144fc47ac3149a09a4f6f0f04879c7d46d.zip |
Merge branch 'master' into master
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r-- | src/kicadtoNgspice/Analysis.py | 12 | ||||
-rw-r--r-- | src/kicadtoNgspice/Convert.py | 154 | ||||
-rw-r--r-- | src/kicadtoNgspice/DeviceModel.py | 4 | ||||
-rw-r--r-- | src/kicadtoNgspice/KicadtoNgspice.py | 252 | ||||
-rw-r--r-- | src/kicadtoNgspice/Microcontroller.py | 283 | ||||
-rw-r--r-- | src/kicadtoNgspice/Model.py | 220 | ||||
-rw-r--r-- | src/kicadtoNgspice/Processing.py | 12 | ||||
-rw-r--r-- | src/kicadtoNgspice/SubcircuitTab.py | 2 | ||||
-rw-r--r-- | src/kicadtoNgspice/TrackWidget.py | 2 |
9 files changed, 693 insertions, 248 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py index 32902a81..f3784287 100644 --- a/src/kicadtoNgspice/Analysis.py +++ b/src/kicadtoNgspice/Analysis.py @@ -734,7 +734,7 @@ class Analysis(QtWidgets.QWidget): self.parameter_cnt = 0 self.start_combobox = QtWidgets.QComboBox() - self.start_combobox.addItem("Sec") + self.start_combobox.addItem("sec") self.start_combobox.addItem("ms") self.start_combobox.addItem("us") self.start_combobox.addItem("ns") @@ -744,13 +744,13 @@ class Analysis(QtWidgets.QWidget): try: self.tran_parameter[self.parameter_cnt] = str(root[2][3].text) except BaseException: - self.tran_parameter[self.parameter_cnt] = "Sec" + self.tran_parameter[self.parameter_cnt] = "sec" self.start_combobox.activated[str].connect(self.start_combo_change) self.parameter_cnt += 1 self.step_combobox = QtWidgets.QComboBox() - self.step_combobox.addItem("Sec") + self.step_combobox.addItem("sec") self.step_combobox.addItem("ms") self.step_combobox.addItem("us") self.step_combobox.addItem("ns") @@ -759,13 +759,13 @@ class Analysis(QtWidgets.QWidget): try: self.tran_parameter[self.parameter_cnt] = str(root[2][4].text) except BaseException: - self.tran_parameter[self.parameter_cnt] = "Sec" + self.tran_parameter[self.parameter_cnt] = "sec" self.step_combobox.activated[str].connect(self.step_combo_change) self.parameter_cnt += 1 self.stop_combobox = QtWidgets.QComboBox() - self.stop_combobox.addItem("Sec") + self.stop_combobox.addItem("sec") self.stop_combobox.addItem("ms") self.stop_combobox.addItem("us") self.stop_combobox.addItem("ns") @@ -774,7 +774,7 @@ class Analysis(QtWidgets.QWidget): try: self.tran_parameter[self.parameter_cnt] = str(root[2][5].text) except BaseException: - self.tran_parameter[self.parameter_cnt] = "Sec" + self.tran_parameter[self.parameter_cnt] = "sec" self.stop_combobox.activated[str].connect(self.stop_combo_change) self.parameter_cnt += 1 diff --git a/src/kicadtoNgspice/Convert.py b/src/kicadtoNgspice/Convert.py index 24449a3b..a5b34cee 100644 --- 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 31406929..d2cd0e73 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -84,6 +84,7 @@ class DeviceModel(QtWidgets.QWidget): words[4]) self.entry_var[self.count] = QtWidgets.QLineEdit() self.entry_var[self.count].setText("") + self.entry_var[self.count].setReadOnly(True) global path_name try: @@ -148,6 +149,7 @@ class DeviceModel(QtWidgets.QWidget): words[3]) self.entry_var[self.count] = QtWidgets.QLineEdit() self.entry_var[self.count].setText("") + self.entry_var[self.count].setReadOnly(True) # global path_name try: for child in root: @@ -211,6 +213,7 @@ class DeviceModel(QtWidgets.QWidget): words[4]) self.entry_var[self.count] = QtWidgets.QLineEdit() self.entry_var[self.count].setText("") + self.entry_var[self.count].setReadOnly(True) # global path_name try: for child in root: @@ -401,6 +404,7 @@ class DeviceModel(QtWidgets.QWidget): words[4]) self.entry_var[self.count] = QtWidgets.QLineEdit() self.entry_var[self.count].setText("") + self.entry_var[self.count].setReadOnly(True) mosfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtWidgets.QPushButton("Add") self.addbtn.setObjectName("%d" % self.count) 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": 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 1389e556..22fa02b5 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -1,68 +1,25 @@ #!/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 - - 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() - chosen_file_path = os.path.abspath(self.hexfile) - - # 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) @@ -84,9 +41,7 @@ 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 @@ -101,7 +56,8 @@ class Model(QtWidgets.QWidget): self.start = 0 self.end = 0 - self.entry_var = {} + self.entry_var = [] + self.hex_btns = [] self.text = "" # Creating GUI dynamically for Model tab @@ -110,7 +66,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,12 +75,14 @@ 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__"): @@ -134,73 +91,45 @@ 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.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: paramLabel = QtWidgets.QLabel(value) @@ -208,11 +137,21 @@ 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.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: @@ -220,50 +159,22 @@ 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) @@ -303,3 +214,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) diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py index 94a2e51f..11c95965 100644 --- a/src/kicadtoNgspice/Processing.py +++ b/src/kicadtoNgspice/Processing.py @@ -143,8 +143,8 @@ class PrcocessNetlist: index = schematicInfo.index(compline) if words[3] == "pulse": Title = "Add parameters for pulse source " + compName - v1 = ' Enter initial value(Volts/Amps): ' - v2 = ' Enter pulsed value(Volts/Amps): ' + v1 = ' Enter initial value (Volts/Amps): ' + v2 = ' Enter pulsed value (Volts/Amps): ' td = ' Enter delay time (seconds): ' tr = ' Enter rise time (seconds): ' tf = ' Enter fall time (seconds): ' @@ -180,8 +180,8 @@ class PrcocessNetlist: elif words[3] == "exp": Title = "Add parameters for exponential source " + compName - v1 = ' Enter initial value(Volts/Amps): ' - v2 = ' Enter pulsed value(Volts/Amps): ' + v1 = ' Enter initial value (Volts/Amps): ' + v2 = ' Enter pulsed value (Volts/Amps): ' td1 = ' Enter rise delay time (seconds): ' tau1 = ' Enter rise time constant (seconds): ' td2 = ' Enter fall time (seconds): ' @@ -192,7 +192,7 @@ class PrcocessNetlist: elif words[3] == "dc": Title = "Add parameters for DC source " + compName - v1 = ' Enter value(Volts/Amps): ' + v1 = ' Enter value (Volts/Amps): ' v2 = ' Enter zero frequency: ' sourcelist.append( [index, compline, words[3], Title, v1, v2]) @@ -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/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py index 6b98167d..59bc3ffb 100644 --- a/src/kicadtoNgspice/SubcircuitTab.py +++ b/src/kicadtoNgspice/SubcircuitTab.py @@ -71,7 +71,7 @@ class SubcircuitTab(QtWidgets.QWidget): subbox.setTitle("Add subcircuit for " + words[len(words) - 1]) self.entry_var[self.count] = QtWidgets.QLineEdit() self.entry_var[self.count].setText("") - + self.entry_var[self.count].setReadOnly(True) global path_name try: for child in root: 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 = {} |