diff options
author | maddy-2 | 2019-05-27 12:32:49 +0530 |
---|---|---|
committer | nilshah98 | 2019-06-07 11:03:14 +0530 |
commit | 28d8fd378bf717e8daba8a564708856769f24b98 (patch) | |
tree | ee8cc6592c690708d5f35cb5304feeae3d014c97 /src/kicadtoNgspice | |
parent | 7e7b6d372aac718f857fcad5c49faf019ff83bb4 (diff) | |
download | eSim-28d8fd378bf717e8daba8a564708856769f24b98.tar.gz eSim-28d8fd378bf717e8daba8a564708856769f24b98.tar.bz2 eSim-28d8fd378bf717e8daba8a564708856769f24b98.zip |
initialise pep8 compliance, using autopep8
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r-- | src/kicadtoNgspice/Analysis.py | 364 | ||||
-rw-r--r-- | src/kicadtoNgspice/Convert.py | 616 | ||||
-rw-r--r-- | src/kicadtoNgspice/DeviceModel.py | 295 | ||||
-rw-r--r-- | src/kicadtoNgspice/KicadtoNgspice.py | 562 | ||||
-rw-r--r-- | src/kicadtoNgspice/Model.py | 120 | ||||
-rw-r--r-- | src/kicadtoNgspice/Processing.py | 487 | ||||
-rw-r--r-- | src/kicadtoNgspice/Source.py | 201 | ||||
-rw-r--r-- | src/kicadtoNgspice/SubcircuitTab.py | 137 | ||||
-rw-r--r-- | src/kicadtoNgspice/TrackWidget.py | 40 |
9 files changed, 1581 insertions, 1241 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py index 6aa167d6..fde9a3e3 100644 --- a/src/kicadtoNgspice/Analysis.py +++ b/src/kicadtoNgspice/Analysis.py @@ -5,11 +5,13 @@ import os #from xml.etree import ElementTree as ET import json + class Analysis(QtGui.QWidget): """ This class create Analysis Tab in KicadtoNgspice Window. """ - def __init__(self,clarg1): + + def __init__(self, clarg1): self.clarg1 = clarg1 QtGui.QWidget.__init__(self) self.track_obj = TrackWidget.TrackWidget() @@ -22,24 +24,24 @@ class Analysis(QtGui.QWidget): self.dc_parameter = {} self.tran_parameter = {} self.createAnalysisWidget() - + def createAnalysisWidget(self): self.grid = QtGui.QGridLayout() self.grid.addWidget(self.createCheckBox(), 0, 0) self.grid.addWidget(self.createACgroup(), 1, 0) self.grid.addWidget(self.createDCgroup(), 2, 0) self.grid.addWidget(self.createTRANgroup(), 3, 0) - + try: kicadFile = self.clarg1 - (projpath,filename) = os.path.split(kicadFile) + (projpath, filename) = os.path.split(kicadFile) if os.path.isfile(os.path.join(projpath, 'analysis')): print("Analysis file is present") - - analysisfile = open(os.path.join(projpath,'analysis')) + + analysisfile = open(os.path.join(projpath, 'analysis')) content = analysisfile.readline() print("Content of Analysis file :", content) - contentlist= content.split() + contentlist = content.split() if contentlist[0] == '.ac': self.checkAC.setChecked(True) @@ -56,21 +58,21 @@ class Analysis(QtGui.QWidget): elif contentlist[1] == 'oct': self.Oct.setChecked(True) self.track_obj.AC_type["ITEMS"] = "oct" - + elif contentlist[0] == '.dc': self.checkDC.setChecked(True) self.dcbox.setDisabled(False) self.acbox.setDisabled(True) self.trbox.setDisabled(True) - self.track_obj.set_CheckBox["ITEMS"] ="DC" - + self.track_obj.set_CheckBox["ITEMS"] = "DC" + elif contentlist[0] == '.tran': self.checkTRAN.setChecked(True) self.trbox.setDisabled(False) self.acbox.setDisabled(True) self.dcbox.setDisabled(True) self.track_obj.set_CheckBox["ITEMS"] = "TRAN" - + elif contentlist[0] == '.op': self.checkDC.setChecked(True) self.dcbox.setDisabled(False) @@ -79,18 +81,18 @@ class Analysis(QtGui.QWidget): self.check.setChecked(True) self.track_obj.set_CheckBox["ITEMS"] = "DC" - except: + except BaseException: self.checkTRAN.setChecked(True) - self.track_obj.set_CheckBox["ITEMS"]="TRAN" - + self.track_obj.set_CheckBox["ITEMS"] = "TRAN" + self.setLayout(self.grid) self.show() - + def createCheckBox(self): self.checkbox = QtGui.QGroupBox() self.checkbox.setTitle("Select Analysis Type") self.checkgrid = QtGui.QGridLayout() - + self.checkgroupbtn = QtGui.QButtonGroup() self.checkAC = QtGui.QCheckBox("AC") self.checkDC = QtGui.QCheckBox("DC") @@ -101,52 +103,57 @@ class Analysis(QtGui.QWidget): self.checkgroupbtn.addButton(self.checkTRAN) self.checkgroupbtn.setExclusive(True) self.checkgroupbtn.buttonClicked.connect(self.enableBox) - + self.checkgrid.addWidget(self.checkAC, 0, 0) self.checkgrid.addWidget(self.checkDC, 0, 1) self.checkgrid.addWidget(self.checkTRAN, 0, 2) self.checkbox.setLayout(self.checkgrid) - + return self.checkbox - + def enableBox(self): if self.checkAC.isChecked(): self.acbox.setDisabled(False) self.dcbox.setDisabled(True) self.trbox.setDisabled(True) self.track_obj.set_CheckBox["ITEMS"] = "AC" - + elif self.checkDC.isChecked(): self.dcbox.setDisabled(False) self.acbox.setDisabled(True) self.trbox.setDisabled(True) self.track_obj.set_CheckBox["ITEMS"] = "DC" - + elif self.checkTRAN.isChecked(): self.trbox.setDisabled(False) self.acbox.setDisabled(True) self.dcbox.setDisabled(True) self.track_obj.set_CheckBox["ITEMS"] = "TRAN" - + def createACgroup(self): kicadFile = self.clarg1 - (projpath,filename) = os.path.split(kicadFile) + (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.json"),'r') + f = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'r') data = f.read() json_data = json.loads(data) - except: + except BaseException: check = 0 print("AC Previous Values JSON is Empty") - + self.acbox = QtGui.QGroupBox() self.acbox.setTitle("AC Analysis") self.acbox.setDisabled(True) self.acgrid = QtGui.QGridLayout() - self.radiobuttongroup= QtGui.QButtonGroup() + self.radiobuttongroup = QtGui.QButtonGroup() self.Lin = QtGui.QRadioButton("Lin") self.Dec = QtGui.QRadioButton("Dec") self.Oct = QtGui.QRadioButton("Oct") @@ -155,13 +162,13 @@ class Analysis(QtGui.QWidget): self.radiobuttongroup.addButton(self.Oct) self.radiobuttongroup.setExclusive(True) self.Lin.setChecked(True) - self.track_obj.AC_type["ITEMS"]="lin" + self.track_obj.AC_type["ITEMS"] = "lin" self.radiobuttongroup.buttonClicked.connect(self.set_ac_type) self.acgrid.addWidget(self.Lin, 1, 1) self.acgrid.addWidget(self.Dec, 1, 2) self.acgrid.addWidget(self.Oct, 1, 3) self.acbox.setLayout(self.acgrid) - + self.scale = QtGui.QLabel("Scale") self.start_fre_lable = QtGui.QLabel("Start Frequency") self.stop_fre_lable = QtGui.QLabel("Stop Frequency") @@ -170,20 +177,20 @@ class Analysis(QtGui.QWidget): self.acgrid.addWidget(self.start_fre_lable, 2, 0) self.acgrid.addWidget(self.stop_fre_lable, 3, 0) self.acgrid.addWidget(self.no_of_points, 4, 0) - + self.count = 0 - self.ac_entry_var[self.count] = QtGui.QLineEdit()#start + self.ac_entry_var[self.count] = QtGui.QLineEdit() # start self.acgrid.addWidget(self.ac_entry_var[self.count], 2, 1) self.ac_entry_var[self.count].setMaximumWidth(150) - self.count = self.count+1 - self.ac_entry_var[self.count] = QtGui.QLineEdit()#stop + self.count = self.count + 1 + self.ac_entry_var[self.count] = QtGui.QLineEdit() # stop self.acgrid.addWidget(self.ac_entry_var[self.count], 3, 1) self.ac_entry_var[self.count].setMaximumWidth(150) - self.count = self.count+1 - self.ac_entry_var[self.count] = QtGui.QLineEdit()#no of pts + self.count = self.count + 1 + self.ac_entry_var[self.count] = QtGui.QLineEdit() # no of pts self.acgrid.addWidget(self.ac_entry_var[self.count], 4, 1) self.ac_entry_var[self.count].setMaximumWidth(150) - + self.parameter_cnt = 0 self.start_fre_combo = QtGui.QComboBox() self.start_fre_combo.addItem("Hz",) @@ -196,12 +203,13 @@ class Analysis(QtGui.QWidget): self.ac_parameter[0] = "Hz" try: - self.ac_parameter[self.parameter_cnt] = str(json_data["analysis"]["ac"]["Start Fre Combo"]) - except: + self.ac_parameter[self.parameter_cnt] = str( + json_data["analysis"]["ac"]["Start Fre Combo"]) + except BaseException: self.ac_parameter[self.parameter_cnt] = "Hz" self.start_fre_combo.activated[str].connect(self.start_combovalue) - + self.parameter_cnt = self.parameter_cnt + 1 self.stop_fre_combo = QtGui.QComboBox() self.stop_fre_combo.addItem("Hz") @@ -214,16 +222,17 @@ class Analysis(QtGui.QWidget): self.ac_parameter[1] = "Hz" try: - self.ac_parameter[self.parameter_cnt] = str(json_data["analysis"]["ac"]["Stop Fre Combo"]) - except: + self.ac_parameter[self.parameter_cnt] = str( + json_data["analysis"]["ac"]["Stop Fre Combo"]) + except BaseException: self.ac_parameter[self.parameter_cnt] = "Hz" self.stop_fre_combo.activated[str].connect(self.stop_combovalue) - + self.track_obj.AC_entry_var["ITEMS"] = self.ac_entry_var self.track_obj.AC_Parameter["ITEMS"] = self.ac_parameter - - #CSS + + # CSS self.acbox.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; } \ @@ -245,48 +254,58 @@ class Analysis(QtGui.QWidget): else: pass - self.ac_entry_var[0].setText(json_data["analysis"]["ac"]["Start Frequency"]) - self.ac_entry_var[1].setText(json_data["analysis"]["ac"]["Stop Frequency"]) - self.ac_entry_var[2].setText(json_data["analysis"]["ac"]["No. of points"]) - index = self.start_fre_combo.findText(json_data["analysis"]["ac"]["Start Fre Combo"]) + self.ac_entry_var[0].setText( + json_data["analysis"]["ac"]["Start Frequency"]) + self.ac_entry_var[1].setText( + json_data["analysis"]["ac"]["Stop Frequency"]) + self.ac_entry_var[2].setText( + json_data["analysis"]["ac"]["No. of points"]) + index = self.start_fre_combo.findText( + json_data["analysis"]["ac"]["Start Fre Combo"]) self.start_fre_combo.setCurrentIndex(index) - index = self.stop_fre_combo.findText(json_data["analysis"]["ac"]["Stop Fre Combo"]) + index = self.stop_fre_combo.findText( + json_data["analysis"]["ac"]["Stop Fre Combo"]) self.stop_fre_combo.setCurrentIndex(index) - except: + except BaseException: print("AC Analysis JSON Parse Error") - + return self.acbox - + def start_combovalue(self, text): self.ac_parameter[0] = str(text) - + def stop_combovalue(self, text): self.ac_parameter[1] = str(text) - + def set_ac_type(self): self.parameter_cnt = 0 if self.Lin.isChecked(): self.track_obj.AC_type["ITEMS"] = "lin" elif self.Dec.isChecked(): - self.track_obj.AC_type["ITEMS"] = "dec" + self.track_obj.AC_type["ITEMS"] = "dec" elif self.Oct.isChecked(): self.track_obj.AC_type["ITEMS"] = "oct" else: - pass - + pass + def createDCgroup(self): kicadFile = self.clarg1 - (projpath,filename) = os.path.split(kicadFile) + (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.json"),'r') + f = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'r') data = f.read() json_data = json.loads(data) - except: + except BaseException: check = 0 print("DC Previous Values JSON is empty") @@ -295,16 +314,16 @@ class Analysis(QtGui.QWidget): self.dcbox.setDisabled(True) self.dcgrid = QtGui.QGridLayout() self.dcbox.setLayout(self.dcgrid) - + self.source_name = QtGui.QLabel('Enter Source 1', self) self.source_name.setMaximumWidth(150) self.start = QtGui.QLabel('Start', self) self.start.setMaximumWidth(150) self.increment = QtGui.QLabel('Increment', self) self.increment.setMaximumWidth(150) - self.stop = QtGui.QLabel('Stop',self) + self.stop = QtGui.QLabel('Stop', self) self.stop.setMaximumWidth(150) - + self.source_name2 = QtGui.QLabel('Enter Source 2', self) self.source_name2.setMaximumWidth(150) self.start2 = QtGui.QLabel('Start', self) @@ -313,55 +332,55 @@ class Analysis(QtGui.QWidget): self.increment2.setMaximumWidth(150) self.stop2 = QtGui.QLabel('Stop', self) self.stop2.setMaximumWidth(150) - - self.dcgrid.addWidget(self.source_name, 1, 0) + + self.dcgrid.addWidget(self.source_name, 1, 0) self.dcgrid.addWidget(self.start, 2, 0) self.dcgrid.addWidget(self.increment, 3, 0) - self.dcgrid.addWidget(self.stop, 4, 0) + self.dcgrid.addWidget(self.stop, 4, 0) - self.dcgrid.addWidget(self.source_name2, 5, 0) + self.dcgrid.addWidget(self.source_name2, 5, 0) self.dcgrid.addWidget(self.start2, 6, 0) self.dcgrid.addWidget(self.increment2, 7, 0) self.dcgrid.addWidget(self.stop2, 8, 0) - + self.count = 0 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#source + self.dc_entry_var[self.count] = QtGui.QLineEdit() # source self.dcgrid.addWidget(self.dc_entry_var[self.count], 1, 1) self.dc_entry_var[self.count].setMaximumWidth(150) self.count += 1 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#start + self.dc_entry_var[self.count] = QtGui.QLineEdit() # start self.dcgrid.addWidget(self.dc_entry_var[self.count], 2, 1) self.dc_entry_var[self.count].setMaximumWidth(150) self.count += 1 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#increment + self.dc_entry_var[self.count] = QtGui.QLineEdit() # increment self.dcgrid.addWidget(self.dc_entry_var[self.count], 3, 1) self.dc_entry_var[self.count].setMaximumWidth(150) self.count += 1 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#stop + self.dc_entry_var[self.count] = QtGui.QLineEdit() # stop self.dcgrid.addWidget(self.dc_entry_var[self.count], 4, 1) self.dc_entry_var[self.count].setMaximumWidth(150) self.count += 1 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#source + self.dc_entry_var[self.count] = QtGui.QLineEdit() # source self.dcgrid.addWidget(self.dc_entry_var[self.count], 5, 1) self.dc_entry_var[self.count].setMaximumWidth(150) self.count += 1 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#start + self.dc_entry_var[self.count] = QtGui.QLineEdit() # start self.dcgrid.addWidget(self.dc_entry_var[self.count], 6, 1) self.dc_entry_var[self.count].setMaximumWidth(150) self.count += 1 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#increment + self.dc_entry_var[self.count] = QtGui.QLineEdit() # increment self.dcgrid.addWidget(self.dc_entry_var[self.count], 7, 1) self.dc_entry_var[self.count].setMaximumWidth(150) self.count += 1 - self.dc_entry_var[self.count] = QtGui.QLineEdit()#stop + self.dc_entry_var[self.count] = QtGui.QLineEdit() # stop self.dcgrid.addWidget(self.dc_entry_var[self.count], 8, 1) self.dc_entry_var[self.count].setMaximumWidth(150) @@ -376,14 +395,15 @@ class Analysis(QtGui.QWidget): self.dcgrid.addWidget(self.start_combo, 2, 2) try: - self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Start Combo"]) - except: + self.dc_parameter[self.parameter_cnt] = str( + json_data["analysis"]["dc"]["Start Combo"]) + except BaseException: self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" self.start_combo.activated[str].connect(self.start_changecombo) self.parameter_cnt += 1 - - self.increment_combo=QtGui.QComboBox(self) + + self.increment_combo = QtGui.QComboBox(self) self.increment_combo.setMaximumWidth(150) self.increment_combo.addItem("Volts or Amperes") self.increment_combo.addItem("mV or mA") @@ -393,30 +413,32 @@ class Analysis(QtGui.QWidget): self.dcgrid.addWidget(self.increment_combo, 3, 2) try: - self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Increment Combo"]) - except: + self.dc_parameter[self.parameter_cnt] = str( + json_data["analysis"]["dc"]["Increment Combo"]) + except BaseException: self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" self.increment_combo.activated[str].connect(self.increment_changecombo) self.parameter_cnt += 1 - + self.stop_combo = QtGui.QComboBox(self) self.stop_combo.setMaximumWidth(150) self.stop_combo.addItem("Volts or Amperes") self.stop_combo.addItem("mV or mA") self.stop_combo.addItem("uV or uA") self.stop_combo.addItem("nV or nA") - self.stop_combo.addItem("pV or pA") + self.stop_combo.addItem("pV or pA") self.dcgrid.addWidget(self.stop_combo, 4, 2) try: - self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Stop Combo"]) - except: + self.dc_parameter[self.parameter_cnt] = str( + json_data["analysis"]["dc"]["Stop Combo"]) + except BaseException: self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" self.stop_combo.activated[str].connect(self.stop_changecombo) self.parameter_cnt += 1 - + self.start_combo2 = QtGui.QComboBox(self) self.start_combo2.setMaximumWidth(150) self.start_combo2.addItem('Volts or Amperes') @@ -427,8 +449,9 @@ class Analysis(QtGui.QWidget): self.dcgrid.addWidget(self.start_combo2, 6, 2) try: - self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Start Combo2"]) - except: + self.dc_parameter[self.parameter_cnt] = str( + json_data["analysis"]["dc"]["Start Combo2"]) + except BaseException: self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" self.start_combo2.activated[str].connect(self.start_changecombo2) @@ -444,11 +467,13 @@ class Analysis(QtGui.QWidget): self.dcgrid.addWidget(self.increment_combo2, 7, 2) try: - self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Increment Combo2"]) - except: + self.dc_parameter[self.parameter_cnt] = str( + json_data["analysis"]["dc"]["Increment Combo2"]) + except BaseException: self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" - self.increment_combo2.activated[str].connect(self.increment_changecombo2) + self.increment_combo2.activated[str].connect( + self.increment_changecombo2) self.parameter_cnt += 1 self.stop_combo2 = QtGui.QComboBox(self) @@ -461,73 +486,89 @@ class Analysis(QtGui.QWidget): self.dcgrid.addWidget(self.stop_combo2, 8, 2) try: - self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Stop Combo2"]) - except: + self.dc_parameter[self.parameter_cnt] = str( + json_data["analysis"]["dc"]["Stop Combo2"]) + except BaseException: self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" self.stop_combo2.activated[str].connect(self.stop_changecombo2) self.parameter_cnt += 1 - self.check = QtGui.QCheckBox('Operating Point Analysis',self) + self.check = QtGui.QCheckBox('Operating Point Analysis', self) try: - self.track_obj.op_check.append(str(json_data["analysis"]["dc"]["Operating Point"])) - except: + self.track_obj.op_check.append( + str(json_data["analysis"]["dc"]["Operating Point"])) + except BaseException: self.track_obj.op_check.append('0') - - #QtCore.QObject.connect(check,SIGNAL("stateChanged()"),check,SLOT("checkedSlot")) + + # QtCore.QObject.connect(check,SIGNAL("stateChanged()"),check,SLOT("checkedSlot")) self.check.stateChanged.connect(self.setflag) #self.flagcheck = 1 #self.flagcheck= 2 self.dcgrid.addWidget(self.check, 9, 1, 9, 2) self.track_obj.DC_entry_var["ITEMS"] = self.dc_entry_var self.track_obj.DC_Parameter["ITEMS"] = self.dc_parameter - - #CSS + + # CSS self.dcbox.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; } \ ") if check: try: - self.dc_entry_var[0].setText(json_data["analysis"]["dc"]["Source 1"]) - self.dc_entry_var[1].setText(json_data["analysis"]["dc"]["Start"]) - self.dc_entry_var[2].setText(json_data["analysis"]["dc"]["Increment"]) - self.dc_entry_var[3].setText(json_data["analysis"]["dc"]["Stop"]) - index = self.start_combo.findText(json_data["analysis"]["dc"]["Start Combo"]) + self.dc_entry_var[0].setText( + json_data["analysis"]["dc"]["Source 1"]) + self.dc_entry_var[1].setText( + json_data["analysis"]["dc"]["Start"]) + self.dc_entry_var[2].setText( + json_data["analysis"]["dc"]["Increment"]) + self.dc_entry_var[3].setText( + json_data["analysis"]["dc"]["Stop"]) + index = self.start_combo.findText( + json_data["analysis"]["dc"]["Start Combo"]) self.start_combo.setCurrentIndex(index) - index = self.increment_combo.findText(json_data["analysis"]["dc"]["Increment Combo"]) + index = self.increment_combo.findText( + json_data["analysis"]["dc"]["Increment Combo"]) self.increment_combo.setCurrentIndex(index) - index = self.stop_combo.findText(json_data["analysis"]["dc"]["Stop Combo"]) + index = self.stop_combo.findText( + json_data["analysis"]["dc"]["Stop Combo"]) self.stop_combo.setCurrentIndex(index) - self.dc_entry_var[4].setText(json_data["analysis"]["dc"]["Source 2"]) - self.dc_entry_var[5].setText(json_data["analysis"]["dc"]["Start2"]) - self.dc_entry_var[6].setText(json_data["analysis"]["dc"]["Increment2"]) - self.dc_entry_var[7].setText(json_data["analysis"]["dc"]["Stop2"]) - index = self.start_combo2.findText(json_data["analysis"]["dc"]["Start Combo2"]) + self.dc_entry_var[4].setText( + json_data["analysis"]["dc"]["Source 2"]) + self.dc_entry_var[5].setText( + json_data["analysis"]["dc"]["Start2"]) + self.dc_entry_var[6].setText( + json_data["analysis"]["dc"]["Increment2"]) + self.dc_entry_var[7].setText( + json_data["analysis"]["dc"]["Stop2"]) + index = self.start_combo2.findText( + json_data["analysis"]["dc"]["Start Combo2"]) self.start_combo2.setCurrentIndex(index) - index = self.increment_combo2.findText(json_data["analysis"]["dc"]["Increment Combo2"]) + index = self.increment_combo2.findText( + json_data["analysis"]["dc"]["Increment Combo2"]) self.increment_combo2.setCurrentIndex(index) - index = self.stop_combo2.findText(json_data["analysis"]["dc"]["Stop Combo2"]) + index = self.stop_combo2.findText( + json_data["analysis"]["dc"]["Stop Combo2"]) self.stop_combo2.setCurrentIndex(index) if json_data["analysis"]["dc"]["Operating Point"] == 1: self.check.setChecked(True) else: self.check.setChecked(False) - except: + except BaseException: print("DC Analysis JSON Parse Error") - + return self.dcbox - + def start_changecombo(self, text): self.dc_parameter[0] = str(text) - + def increment_changecombo(self, text): self.dc_parameter[1] = str(text) - + def stop_changecombo(self, text): self.dc_parameter[2] = str(text) - + def start_changecombo2(self, text): self.dc_parameter[3] = str(text) @@ -535,34 +576,39 @@ class Analysis(QtGui.QWidget): self.dc_parameter[4] = str(text) def stop_changecombo2(self, text): - self.dc_parameter[5] = str(text) + self.dc_parameter[5] = str(text) def setflag(self): if self.check.isChecked(): self.track_obj.op_check.append(1) else: - self.track_obj.op_check.append(0) - + self.track_obj.op_check.append(0) + def createTRANgroup(self): kicadFile = self.clarg1 - (projpath,filename) = os.path.split(kicadFile) + (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.json"),'r') + f = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'r') data = f.read() json_data = json.loads(data) - except: + except BaseException: check = 0 print("Transient Previous Values JSON is Empty") - + self.trbox = QtGui.QGroupBox() self.trbox.setTitle("Transient Analysis") - #self.trbox.setDisabled(True) - self.trgrid = QtGui.QGridLayout() + # self.trbox.setDisabled(True) + self.trgrid = QtGui.QGridLayout() self.trbox.setLayout(self.trgrid) - + self.start = QtGui.QLabel("Start Time") self.step = QtGui.QLabel("Step Time") self.stop = QtGui.QLabel("Stop Time") @@ -570,7 +616,7 @@ class Analysis(QtGui.QWidget): self.trgrid.addWidget(self.step, 2, 0) self.trgrid.addWidget(self.stop, 3, 0) self.count = 0 - + self.tran_entry_var[self.count] = QtGui.QLineEdit() self.trgrid.addWidget(self.tran_entry_var[self.count], 1, 1) self.tran_entry_var[self.count].setMaximumWidth(150) @@ -585,7 +631,7 @@ class Analysis(QtGui.QWidget): self.trgrid.addWidget(self.tran_entry_var[self.count], 3, 1) self.tran_entry_var[self.count].setMaximumWidth(150) self.count += 1 - + self.parameter_cnt = 0 self.start_combobox = QtGui.QComboBox() self.start_combobox.addItem("Sec") @@ -596,13 +642,14 @@ class Analysis(QtGui.QWidget): self.trgrid.addWidget(self.start_combobox, 1, 3) try: - self.tran_parameter[self.parameter_cnt] = str(json_data["analysis"]["tran"]["Start Combo"]) - except: + self.tran_parameter[self.parameter_cnt] = str( + json_data["analysis"]["tran"]["Start Combo"]) + except BaseException: self.tran_parameter[self.parameter_cnt] = "Sec" self.start_combobox.activated[str].connect(self.start_combo_change) self.parameter_cnt += 1 - + self.step_combobox = QtGui.QComboBox() self.step_combobox.addItem("Sec") self.step_combobox.addItem("ms") @@ -611,13 +658,14 @@ class Analysis(QtGui.QWidget): self.step_combobox.addItem("ps") self.trgrid.addWidget(self.step_combobox, 2, 3) try: - self.tran_parameter[self.parameter_cnt] = str(json_data["analysis"]["tran"]["Step Combo"]) - except: + self.tran_parameter[self.parameter_cnt] = str( + json_data["analysis"]["tran"]["Step Combo"]) + except BaseException: self.tran_parameter[self.parameter_cnt] = "Sec" self.step_combobox.activated[str].connect(self.step_combo_change) self.parameter_cnt += 1 - + self.stop_combobox = QtGui.QComboBox() self.stop_combobox.addItem("Sec") self.stop_combobox.addItem("ms") @@ -626,43 +674,49 @@ class Analysis(QtGui.QWidget): self.stop_combobox.addItem("ps") self.trgrid.addWidget(self.stop_combobox, 3, 3) try: - self.tran_parameter[self.parameter_cnt] = str(json_data["analysis"]["tran"]["Stop Combo"]) - except: + self.tran_parameter[self.parameter_cnt] = str( + json_data["analysis"]["tran"]["Stop Combo"]) + except BaseException: self.tran_parameter[self.parameter_cnt] = "Sec" self.stop_combobox.activated[str].connect(self.stop_combo_change) self.parameter_cnt += 1 - + self.track_obj.TRAN_entry_var["ITEMS"] = self.tran_entry_var self.track_obj.TRAN_Parameter["ITEMS"] = self.tran_parameter - - #CSS + + # CSS self.trbox.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; } \ ") if check: try: - self.tran_entry_var[0].setText(json_data["analysis"]["tran"]["Start Time"]) - self.tran_entry_var[1].setText(json_data["analysis"]["tran"]["Step Time"]) - self.tran_entry_var[2].setText(json_data["analysis"]["tran"]["Stop Time"]) - index = self.start_combobox.findText(json_data["analysis"]["tran"]["Start Combo"]) + self.tran_entry_var[0].setText( + json_data["analysis"]["tran"]["Start Time"]) + self.tran_entry_var[1].setText( + json_data["analysis"]["tran"]["Step Time"]) + self.tran_entry_var[2].setText( + json_data["analysis"]["tran"]["Stop Time"]) + index = self.start_combobox.findText( + json_data["analysis"]["tran"]["Start Combo"]) self.start_combobox.setCurrentIndex(index) - index = self.step_combobox.findText(json_data["analysis"]["tran"]["Step Combo"]) + index = self.step_combobox.findText( + json_data["analysis"]["tran"]["Step Combo"]) self.step_combobox.setCurrentIndex(index) - index = self.stop_combobox.findText(json_data["analysis"]["tran"]["Stop Combo"]) + index = self.stop_combobox.findText( + json_data["analysis"]["tran"]["Stop Combo"]) self.stop_combobox.setCurrentIndex(index) - except: + except BaseException: print("Transient Analysis JSON Parse Error") + return self.trbox - return self.trbox - def start_combo_change(self, text): self.tran_parameter[0] = str(text) - + def step_combo_change(self, text): self.tran_parameter[1] = str(text) - + def stop_combo_change(self, text): self.tran_parameter[2] = str(text) diff --git a/src/kicadtoNgspice/Convert.py b/src/kicadtoNgspice/Convert.py index baf479f7..924f94fa 100644 --- a/src/kicadtoNgspice/Convert.py +++ b/src/kicadtoNgspice/Convert.py @@ -5,26 +5,28 @@ import shutil from . import TrackWidget from xml.etree import ElementTree as ET + class Convert: """ This class has all the necessary function required to convert kicad netlist to ngspice netlist. """ - def __init__(self,sourcelisttrack,source_entry_var,schematicInfo,clarg1): + + def __init__(self, sourcelisttrack, source_entry_var, + schematicInfo, clarg1): self.sourcelisttrack = sourcelisttrack self.schematicInfo = schematicInfo self.entry_var = source_entry_var self.sourcelistvalue = [] - self.clarg1=clarg1 - - + self.clarg1 = clarg1 + def addSourceParameter(self): """ This function add the source details to schematicInfo """ - + self.start = 0 self.end = 0 - + for compline in self.sourcelisttrack: self.index = compline[0] self.addline = self.schematicInfo[self.index] @@ -32,91 +34,131 @@ class Convert: try: self.start = compline[2] self.end = compline[3] - vo_val = str(self.entry_var[self.start].text()) if len(str(self.entry_var[self.start].text())) > 0 else '0' - va_val = str(self.entry_var[self.start+1].text()) if len(str(self.entry_var[self.start+1].text())) > 0 else '0' - freq_val = str(self.entry_var[self.start+2].text()) if len(str(self.entry_var[self.start+2].text())) > 0 else '0' - td_val = str(self.entry_var[self.start+3].text()) if len(str(self.entry_var[self.start+3].text())) > 0 else '0' - 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+")" - self.sourcelistvalue.append([self.index,self.addline]) - except: - print("Caught an exception in sine voltage source ",self.addline) - + vo_val = str(self.entry_var[self.start].text()) if len( + str(self.entry_var[self.start].text())) > 0 else '0' + va_val = str(self.entry_var[self.start + 1].text()) if len( + str(self.entry_var[self.start + 1].text())) > 0 else '0' + freq_val = str(self.entry_var[self.start + 2].text()) if len( + str(self.entry_var[self.start + 2].text())) > 0 else '0' + td_val = str(self.entry_var[self.start + 3].text()) if len( + str(self.entry_var[self.start + 3].text())) > 0 else '0' + 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 + ")" + self.sourcelistvalue.append([self.index, self.addline]) + except BaseException: + print( + "Caught an exception in sine voltage source ", + self.addline) + elif compline[1] == 'pulse': try: self.start = compline[2] self.end = compline[3] - v1_val = str(self.entry_var[self.start].text()) if len(str(self.entry_var[self.start].text())) > 0 else '0' - v2_val = str(self.entry_var[self.start+1].text()) if len(str(self.entry_var[self.start+1].text())) > 0 else '0' - td_val = str(self.entry_var[self.start+2].text()) if len(str(self.entry_var[self.start+2].text())) > 0 else '0' - tr_val = str(self.entry_var[self.start+3].text()) if len(str(self.entry_var[self.start+3].text())) > 0 else '0' - tf_val = str(self.entry_var[self.start+4].text()) if len(str(self.entry_var[self.start+4].text())) > 0 else '0' - pw_val = str(self.entry_var[self.start+5].text()) if len(str(self.entry_var[self.start+5].text())) > 0 else '0' - tp_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] + "("+v1_val+" "+v2_val+" "+td_val+" "+tr_val+" "+tf_val+" "+pw_val+" "+tp_val+")" - self.sourcelistvalue.append([self.index,self.addline]) - except: - print("Caught an exception in pulse voltage source ",self.addline) - + v1_val = str(self.entry_var[self.start].text()) if len( + str(self.entry_var[self.start].text())) > 0 else '0' + v2_val = str(self.entry_var[self.start + 1].text()) if len( + str(self.entry_var[self.start + 1].text())) > 0 else '0' + td_val = str(self.entry_var[self.start + 2].text()) if len( + str(self.entry_var[self.start + 2].text())) > 0 else '0' + tr_val = str(self.entry_var[self.start + 3].text()) if len( + str(self.entry_var[self.start + 3].text())) > 0 else '0' + tf_val = str(self.entry_var[self.start + 4].text()) if len( + str(self.entry_var[self.start + 4].text())) > 0 else '0' + pw_val = str(self.entry_var[self.start + 5].text()) if len( + str(self.entry_var[self.start + 5].text())) > 0 else '0' + tp_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] + "(" + v1_val + " " + v2_val + " " + td_val + " " + tr_val + " " + tf_val + " " + pw_val + " " + tp_val + ")" + self.sourcelistvalue.append([self.index, self.addline]) + except BaseException: + print( + "Caught an exception in pulse voltage source ", + self.addline) + elif compline[1] == 'pwl': try: self.start = compline[2] self.end = compline[3] - t_v_val = str(self.entry_var[self.start].text()) if len(str(self.entry_var[self.start].text())) > 0 else '0 0' - self.addline = self.addline.partition('(')[0] + "("+t_v_val+")" - self.sourcelistvalue.append([self.index,self.addline]) - except: - print("Caught an exception in pwl voltage source ",self.addline) - + t_v_val = str(self.entry_var[self.start].text()) if len( + str(self.entry_var[self.start].text())) > 0 else '0 0' + self.addline = self.addline.partition( + '(')[0] + "(" + t_v_val + ")" + self.sourcelistvalue.append([self.index, self.addline]) + except BaseException: + print( + "Caught an exception in pwl voltage source ", + self.addline) + elif compline[1] == 'ac': try: self.start = compline[2] self.end = compline[3] - va_val=str(self.entry_var[self.start].text()) if len(str(self.entry_var[self.start].text())) > 0 else '0' - ph_val=str(self.entry_var[self.start+1].text()) if len(str(self.entry_var[self.start+1].text())) > 0 else '0' + va_val = str(self.entry_var[self.start].text()) if len( + str(self.entry_var[self.start].text())) > 0 else '0' + ph_val = str(self.entry_var[self.start + 1].text()) if len( + str(self.entry_var[self.start + 1].text())) > 0 else '0' self.addline = ' '.join(self.addline.split()) - self.addline = self.addline.partition('ac')[0] +" "+'ac'+" "+ va_val+" "+ph_val - self.sourcelistvalue.append([self.index,self.addline]) - except: - print("Caught an exception in ac voltage source ",self.addline) - + self.addline = self.addline.partition( + 'ac')[0] + " " + 'ac' + " " + va_val + " " + ph_val + self.sourcelistvalue.append([self.index, self.addline]) + except BaseException: + print( + "Caught an exception in ac voltage source ", + self.addline) + elif compline[1] == 'dc': try: self.start = compline[2] self.end = compline[3] - v1_val = str(self.entry_var[self.start].text()) if len(str(self.entry_var[self.start].text())) > 0 else '0' - self.addline = ' '.join(self.addline.split()) - self.addline = self.addline.partition('dc')[0] + " " +'dc'+ " "+v1_val - self.sourcelistvalue.append([self.index,self.addline]) - except: - print("Caught an exception in dc voltage source",self.addline) - + v1_val = str(self.entry_var[self.start].text()) if len( + str(self.entry_var[self.start].text())) > 0 else '0' + self.addline = ' '.join(self.addline.split()) + self.addline = self.addline.partition( + 'dc')[0] + " " + 'dc' + " " + v1_val + self.sourcelistvalue.append([self.index, self.addline]) + except BaseException: + print( + "Caught an exception in dc voltage source", + self.addline) + elif compline[1] == 'exp': try: self.start = compline[2] self.end = compline[3] - v1_val = str(self.entry_var[self.start].text()) if len(str(self.entry_var[self.start].text())) > 0 else '0' - v2_val = str(self.entry_var[self.start+1].text()) if len(str(self.entry_var[self.start+1].text())) > 0 else '0' - td1_val = str(self.entry_var[self.start+2].text()) if len(str(self.entry_var[self.start+2].text())) > 0 else '0' - tau1_val = str(self.entry_var[self.start+3].text()) if len(str(self.entry_var[self.start+3].text())) > 0 else '0' - td2_val = str(self.entry_var[self.start+4].text()) if len(str(self.entry_var[self.start+4].text())) > 0 else '0' - tau2_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] + "("+v1_val+" "+v2_val+" "+td1_val+" "+tau1_val+" "+td2_val+" "+tau2_val+")" - self.sourcelistvalue.append([self.index,self.addline]) - except: - print("Caught an exception in exp voltage source ",self.addline) - - #Updating Schematic with source value + v1_val = str(self.entry_var[self.start].text()) if len( + str(self.entry_var[self.start].text())) > 0 else '0' + v2_val = str(self.entry_var[self.start + 1].text()) if len( + str(self.entry_var[self.start + 1].text())) > 0 else '0' + td1_val = str(self.entry_var[self.start + 2].text()) if len( + str(self.entry_var[self.start + 2].text())) > 0 else '0' + tau1_val = str(self.entry_var[self.start + 3].text()) if len( + str(self.entry_var[self.start + 3].text())) > 0 else '0' + td2_val = str(self.entry_var[self.start + 4].text()) if len( + str(self.entry_var[self.start + 4].text())) > 0 else '0' + tau2_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] + "(" + v1_val + " " + v2_val + " " + td1_val + " " + tau1_val + " " + td2_val + " " + tau2_val + ")" + self.sourcelistvalue.append([self.index, self.addline]) + except BaseException: + print( + "Caught an exception in exp voltage source ", + self.addline) + + # Updating Schematic with source value for item in self.sourcelistvalue: del self.schematicInfo[item[0]] - self.schematicInfo.insert(item[0],item[1]) - + self.schematicInfo.insert(item[0], item[1]) + return self.schematicInfo - - - def analysisInsertor(self,ac_entry_var,dc_entry_var, tran_entry_var,set_checkbox,ac_parameter,dc_parameter,tran_parameter,ac_type,op_check): + + def analysisInsertor(self, ac_entry_var, dc_entry_var, tran_entry_var, + set_checkbox, ac_parameter, dc_parameter, tran_parameter, ac_type, op_check): """ This function creates an analysis file in current project """ @@ -124,41 +166,100 @@ class Convert: self.dc_entry_var = dc_entry_var self.tran_entry_var = tran_entry_var self.set_checkbox = set_checkbox - self.ac_parameter= ac_parameter - self.dc_parameter= dc_parameter + self.ac_parameter = ac_parameter + self.dc_parameter = dc_parameter self.trans_parameter = tran_parameter - self.ac_type= ac_type + self.ac_type = ac_type self.op_check = op_check - self.no=0 - - self.variable=self.set_checkbox - self.direct= self.clarg1 - (filepath, filemname)= os.path.split(self.direct) - self.Fileopen = os.path.join(filepath, "analysis") - self.writefile= open(self.Fileopen,"w") - if self.variable== 'AC': - self.no=0 - self.writefile.write(".ac"+' ' + self.ac_type + ' '+ str(self.defaultvalue(self.ac_entry_var[self.no+2].text()))+' ' + str(self.defaultvalue(self.ac_entry_var[self.no].text())) + self.ac_parameter[self.no]+ ' ' + str(self.defaultvalue(self.ac_entry_var[self.no+1].text())) + self.ac_parameter[self.no+1] ) - - elif self.variable=='DC': + self.no = 0 + + self.variable = self.set_checkbox + self.direct = self.clarg1 + (filepath, filemname) = os.path.split(self.direct) + self.Fileopen = os.path.join(filepath, "analysis") + self.writefile = open(self.Fileopen, "w") + if self.variable == 'AC': + self.no = 0 + self.writefile.write(".ac" + + ' ' + + self.ac_type + + ' ' + + str(self.defaultvalue(self.ac_entry_var[self.no + + 2].text())) + + ' ' + + str(self.defaultvalue(self.ac_entry_var[self.no].text())) + + self.ac_parameter[self.no] + + ' ' + + str(self.defaultvalue(self.ac_entry_var[self.no + + 1].text())) + + self.ac_parameter[self.no + + 1]) + + elif self.variable == 'DC': if self.op_check[-1] == 1: - self.no=0 + self.no = 0 self.writefile.write(".op") elif self.op_check[-1] == 0 or self.op_check[-1] == '0': - self.no=0 - self.writefile.write(".dc" +' '+ str(self.dc_entry_var[self.no].text())+ ' '+ str(self.defaultvalue(self.dc_entry_var[self.no+1].text())) + self.converttosciform(self.dc_parameter[self.no]) + ' '+ str(self.defaultvalue(self.dc_entry_var[self.no+3].text()))+ self.converttosciform(self.dc_parameter[self.no+2]) + ' '+ str(self.defaultvalue(self.dc_entry_var[self.no+2].text())) + self.converttosciform(self.dc_parameter[self.no+1])) - - if self.dc_entry_var[self.no+4].text(): - self.writefile.write(' '+ str(self.defaultvalue(self.dc_entry_var[self.no+4].text()))+ ' '+ str(self.defaultvalue(self.dc_entry_var[self.no+5].text())) + self.converttosciform(self.dc_parameter[self.no+3])+ ' '+ str(self.defaultvalue(self.dc_entry_var[self.no+7].text()))+ self.converttosciform(self.dc_parameter[self.no+5])+ ' ' + str(self.defaultvalue(self.dc_entry_var[self.no+6].text()))+ self.converttosciform(self.dc_parameter[self.no+4])) + self.no = 0 + self.writefile.write(".dc" + + ' ' + + str(self.dc_entry_var[self.no].text()) + + ' ' + + str(self.defaultvalue(self.dc_entry_var[self.no + + 1].text())) + + self.converttosciform(self.dc_parameter[self.no]) + + ' ' + + str(self.defaultvalue(self.dc_entry_var[self.no + + 3].text())) + + self.converttosciform(self.dc_parameter[self.no + + 2]) + + ' ' + + str(self.defaultvalue(self.dc_entry_var[self.no + + 2].text())) + + self.converttosciform(self.dc_parameter[self.no + + 1])) + + if self.dc_entry_var[self.no + 4].text(): + self.writefile.write(' ' + + str(self.defaultvalue(self.dc_entry_var[self.no + + 4].text())) + + ' ' + + str(self.defaultvalue(self.dc_entry_var[self.no + + 5].text())) + + self.converttosciform(self.dc_parameter[self.no + + 3]) + + ' ' + + str(self.defaultvalue(self.dc_entry_var[self.no + + 7].text())) + + self.converttosciform(self.dc_parameter[self.no + + 5]) + + ' ' + + str(self.defaultvalue(self.dc_entry_var[self.no + + 6].text())) + + self.converttosciform(self.dc_parameter[self.no + + 4])) elif self.variable == 'TRAN': - self.no= 0 - self.writefile.write(".tran" + ' '+ str(self.defaultvalue(self.tran_entry_var[self.no+1].text())) + self.converttosciform(self.trans_parameter[self.no+1]) + ' ' + str(self.defaultvalue(self.tran_entry_var[self.no+2].text())) + self.converttosciform(self.trans_parameter[self.no+2])+' '+ str(self.defaultvalue(self.tran_entry_var[self.no].text()))+ self.converttosciform(self.trans_parameter[self.no])) + self.no = 0 + self.writefile.write(".tran" + + ' ' + + str(self.defaultvalue(self.tran_entry_var[self.no + + 1].text())) + + self.converttosciform(self.trans_parameter[self.no + + 1]) + + ' ' + + str(self.defaultvalue(self.tran_entry_var[self.no + + 2].text())) + + self.converttosciform(self.trans_parameter[self.no + + 2]) + + ' ' + + str(self.defaultvalue(self.tran_entry_var[self.no].text())) + + self.converttosciform(self.trans_parameter[self.no])) else: pass self.writefile.close() - + def converttosciform(self, string_obj): """ This function is used for scientific conversion. @@ -174,90 +275,110 @@ class Convert: return "e-12" else: return "e-00" - + def defaultvalue(self, value): """ This function select default value as 0 if Analysis widget do not hold any value. """ - self.value= value + self.value = value if self.value == '': return 0 else: return self.value - - - def addModelParameter(self,schematicInfo): + + def addModelParameter(self, schematicInfo): """ This function add the Ngspice Model details to schematicInfo """ - - #Create object of TrackWidget + + # Create object of TrackWidget self.obj_track = TrackWidget.TrackWidget() - - #List to store model line + + # List to store model line addmodelLine = [] modelParamValue = [] - + for line in self.obj_track.modelTrack: #print "Model Track :",line if line[2] == 'transfo': try: - start=line[7] - end=line[8] - num_turns=str(self.obj_track.model_entry_var[start+1].text()) - - if num_turns=="": num_turns="310" - h_array= "H_array = [ " + start = line[7] + end = line[8] + num_turns = str( + self.obj_track.model_entry_var[start + 1].text()) + + if num_turns == "": + num_turns = "310" + h_array = "H_array = [ " b_array = "B_array = [ " - h1=str(self.obj_track.model_entry_var[start].text()) - b1=str(self.obj_track.model_entry_var[start+5].text()) - - if len(h1)!=0 and len(b1)!=0: - h_array=h_array+h1+" " - b_array=b_array+b1+" " - bh_array = h_array+" ] " + b_array+" ]" + h1 = str(self.obj_track.model_entry_var[start].text()) + b1 = str(self.obj_track.model_entry_var[start + 5].text()) + + if len(h1) != 0 and len(b1) != 0: + h_array = h_array + h1 + " " + b_array = b_array + b1 + " " + bh_array = h_array + " ] " + b_array + " ]" else: bh_array = "H_array = [-1000 -500 -375 -250 -188 -125 -63 0 63 125 188 250 375 500 1000] B_array = [-3.13e-3 -2.63e-3 -2.33e-3 -1.93e-3 -1.5e-3 -6.25e-4 -2.5e-4 0 2.5e-4 6.25e-4 1.5e-3 1.93e-3 2.33e-3 2.63e-3 3.13e-3]" - area=str(self.obj_track.model_entry_var[start+2].text()) - length=str(self.obj_track.model_entry_var[start+3].text()) - if area=="": area="1" - if length=="":length="0.01" - num_turns2=str(self.obj_track.model_entry_var[start+4].text()) - if num_turns2=="": num_turns2="620" - addmodelLine=".model "+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 +")" - modelParamValue.append([line[0],addmodelLine,"*iron core"]) - addmodelLine=".model "+line[3]+"_secondary lcouple (num_turns ="+num_turns2+ ")" - modelParamValue.append([line[0],addmodelLine,"*secondary lcouple"]) + area = str( + self.obj_track.model_entry_var[start + 2].text()) + length = str( + self.obj_track.model_entry_var[start + 3].text()) + if area == "": + area = "1" + if length == "": + length = "0.01" + num_turns2 = str( + self.obj_track.model_entry_var[start + 4].text()) + if num_turns2 == "": + num_turns2 = "620" + addmodelLine = ".model " + \ + 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 + ")" + modelParamValue.append( + [line[0], addmodelLine, "*iron core"]) + addmodelLine = ".model " + \ + line[3] + \ + "_secondary lcouple (num_turns =" + num_turns2 + ")" + modelParamValue.append( + [line[0], addmodelLine, "*secondary lcouple"]) except Exception as e: - print("Caught an exception in transfo model ",line[1]) - print("Exception Message : ",str(e)) - + print("Caught an exception in transfo model ", line[1]) + print("Exception Message : ", str(e)) + elif line[2] == 'ic': try: - start=line[7] - end=line[8] - for key,value in line[9].items(): - initVal = str(self.obj_track.model_entry_var[value].text()) - if initVal=="":initVal="0" - node = line[1].split()[1] #Extracting node from model line - addmodelLine = ".ic v("+node+")="+initVal - modelParamValue.append([line[0],addmodelLine,line[4]]) + start = line[7] + end = line[8] + for key, value in line[9].items(): + initVal = str( + self.obj_track.model_entry_var[value].text()) + if initVal == "": + initVal = "0" + # Extracting node from model line + node = line[1].split()[1] + addmodelLine = ".ic v(" + node + ")=" + initVal + modelParamValue.append( + [line[0], addmodelLine, line[4]]) except Exception as e: - print("Caught an exception in initial condition ",line[1]) - print("Exception Message : ",str(e)) - - + print("Caught an exception in initial condition ", line[1]) + print("Exception Message : ", str(e)) + else: try: start = line[7] end = line[8] - addmodelLine=".model "+ line[3]+" "+line[2]+"(" - for key,value in line[9].items(): + addmodelLine = ".model " + line[3] + " " + line[2] + "(" + for key, value in line[9].items(): #print "Tags: ",key #print "Value: ",value - #Checking for default value and accordingly assign param and default. + # Checking for default value and accordingly assign + # param and default. if ':' in key: key = key.split(':') param = key[0] @@ -265,55 +386,56 @@ class Convert: else: param = key default = 0 - #Cheking if value is iterable.its for vector + # Cheking if value is iterable.its for vector if hasattr(value, '__iter__'): - addmodelLine += param+"=[" + addmodelLine += param + "=[" for lineVar in value: - if str(self.obj_track.model_entry_var[lineVar].text()) == "": + if str( + self.obj_track.model_entry_var[lineVar].text()) == "": paramVal = default else: - paramVal = str(self.obj_track.model_entry_var[lineVar].text()) - addmodelLine += paramVal+" " + paramVal = str( + self.obj_track.model_entry_var[lineVar].text()) + addmodelLine += paramVal + " " addmodelLine += "] " else: - if str(self.obj_track.model_entry_var[value].text()) == "": + if str( + self.obj_track.model_entry_var[value].text()) == "": paramVal = default else: - paramVal = str(self.obj_track.model_entry_var[value].text()) - - addmodelLine += param+"="+paramVal+" " - - + paramVal = str( + self.obj_track.model_entry_var[value].text()) + + addmodelLine += param + "=" + paramVal + " " + addmodelLine += ") " - modelParamValue.append([line[0],addmodelLine,line[4]]) + modelParamValue.append([line[0], addmodelLine, line[4]]) except Exception as e: - print("Caught an exception in model ",line[1]) - print("Exception Message : ",str(e)) - - - #Adding it to schematic + print("Caught an exception in model ", 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]) + schematicInfo.insert(0, item[1]) + schematicInfo.insert(0, item[2]) else: - schematicInfo.append(item[2]) #Adding Comment - schematicInfo.append(item[1]) #Adding model line - + schematicInfo.append(item[2]) # Adding Comment + schematicInfo.append(item[1]) # Adding model line + return schematicInfo - - def addDeviceLibrary(self,schematicInfo,kicadFile): + + def addDeviceLibrary(self, schematicInfo, kicadFile): """ This function add the library details to schematicInfo """ - - (projpath,filename) = os.path.split(kicadFile) - - + + (projpath, filename) = os.path.split(kicadFile) + deviceLibList = self.obj_track.deviceModelTrack - deviceLine = {} #Key:Index, Value:with its updated line in the form of list - includeLine = [] #All .include line list - + deviceLine = {} # Key:Index, Value:with its updated line in the form of list + includeLine = [] # All .include line list + if not deviceLibList: print("No Library Added in the schematic") pass @@ -324,73 +446,75 @@ class Convert: print("Found Library line") index = schematicInfo.index(eachline) completeLibPath = deviceLibList[words[0]] - (libpath,libname) = os.path.split(completeLibPath) - print("Library Path :",libpath) - #Copying library from devicemodelLibrary to Project Path - #Special case for MOSFET + (libpath, libname) = os.path.split(completeLibPath) + print("Library Path :", libpath) + # Copying library from devicemodelLibrary to Project Path + # Special case for MOSFET if eachline[0] == 'm': - #For mosfet library name come along with MOSFET dimension information + # For mosfet library name come along with MOSFET + # dimension information tempStr = libname.split(':') libname = tempStr[0] dimension = tempStr[1] - #Replace last word with library name + # Replace last word with library name #words[-1] = libname.split('.')[0] - words[-1] = self.getRefrenceName(libname,libpath) - #Appending Dimension of MOSFET + words[-1] = self.getRefrenceName(libname, libpath) + # Appending Dimension of MOSFET words.append(dimension) - deviceLine[index] = words - includeLine.append(".include "+libname) - - #src = completeLibPath.split(':')[0] # <----- Not working in Windows - - (src_path,src_lib) = os.path.split(completeLibPath) + deviceLine[index] = words + includeLine.append(".include " + libname) + + # src = completeLibPath.split(':')[0] # <----- Not + # working in Windows + + (src_path, src_lib) = os.path.split(completeLibPath) src_lib = src_lib.split(':')[0] - src = os.path.join(src_path,src_lib) + src = os.path.join(src_path, src_lib) dst = projpath shutil.copy2(src, dst) else: - #Replace last word with library name + # Replace last word with library name #words[-1] = libname.split('.')[0] - words[-1] = self.getRefrenceName(libname,libpath) - deviceLine[index] = words - includeLine.append(".include "+libname) - + words[-1] = self.getRefrenceName(libname, libpath) + deviceLine[index] = words + includeLine.append(".include " + libname) + src = completeLibPath dst = projpath - shutil.copy2(src,dst) - + shutil.copy2(src, dst) + else: pass - - - #Adding device line to schematicInfo - for index,value in deviceLine.items(): - #Update the device line + + # Adding device line to schematicInfo + for index, value in deviceLine.items(): + # Update the device line strLine = " ".join(str(item) for item in value) schematicInfo[index] = strLine - - #This has to be second i.e after deviceLine details - #Adding .include line to Schematic Info at the start of line + + # This has to be second i.e after deviceLine details + # Adding .include line to Schematic Info at the start of line for item in list(set(includeLine)): - schematicInfo.insert(0,item) - - + schematicInfo.insert(0, item) + return schematicInfo - - def addSubcircuit(self,schematicInfo,kicadFile): + + def addSubcircuit(self, schematicInfo, kicadFile): """ This function add the subcircuit to schematicInfo """ - - (projpath,filename) = os.path.split(kicadFile) - + + (projpath, filename) = os.path.split(kicadFile) + subList = self.obj_track.subcircuitTrack - subLine = {} #Key:Index, Value:with its updated line in the form of list - includeLine = [] #All .include line list - - if len(self.obj_track.subcircuitList) != len(self.obj_track.subcircuitTrack): + subLine = {} # Key:Index, Value:with its updated line in the form of list + includeLine = [] # All .include line list + + if len(self.obj_track.subcircuitList) != len( + self.obj_track.subcircuitTrack): self.msg = QtGui.QErrorMessage() - self.msg.showMessage("Conversion failed. Please add all Subcircuits.") + self.msg.showMessage( + "Conversion failed. Please add all Subcircuits.") self.msg.setWindowTitle("Error Message") self.msg.show() raise Exception('All subcircuit directories need to be specified.') @@ -404,44 +528,43 @@ class Convert: print("Found Subcircuit line") index = schematicInfo.index(eachline) completeSubPath = subList[words[0]] - (subpath,subname) = os.path.split(completeSubPath) - print("Library Path :",subpath) - #Copying library from devicemodelLibrary to Project Path - - #Replace last word with library name + (subpath, subname) = os.path.split(completeSubPath) + print("Library Path :", subpath) + # Copying library from devicemodelLibrary to Project Path + + # Replace last word with library name words[-1] = subname.split('.')[0] - subLine[index] = words - includeLine.append(".include "+subname+".sub") - + subLine[index] = words + includeLine.append(".include " + subname + ".sub") + src = completeSubPath dst = projpath print(os.listdir(src)) for files in os.listdir(src): - if os.path.isfile(os.path.join(src,files)): + if os.path.isfile(os.path.join(src, files)): if files != "analysis": - shutil.copy2(os.path.join(src,files),dst) + shutil.copy2(os.path.join(src, files), dst) else: pass - - - #Adding subcircuit line to schematicInfo - for index,value in subLine.items(): - #Update the subcircuit line + + # Adding subcircuit line to schematicInfo + for index, value in subLine.items(): + # Update the subcircuit line strLine = " ".join(str(item) for item in value) schematicInfo[index] = strLine - - #This has to be second i.e after subcircuitLine details - #Adding .include line to Schematic Info at the start of line + + # This has to be second i.e after subcircuitLine details + # Adding .include line to Schematic Info at the start of line for item in list(set(includeLine)): - schematicInfo.insert(0,item) - - return schematicInfo - - def getRefrenceName(self,libname,libpath): - libname = libname.replace('.lib','.xml') - library = os.path.join(libpath,libname) - - #Extracting Value from XML + schematicInfo.insert(0, item) + + return schematicInfo + + def getRefrenceName(self, libname, libpath): + libname = libname.replace('.lib', '.xml') + library = os.path.join(libpath, libname) + + # Extracting Value from XML libtree = ET.parse(library) for child in libtree.iter(): if child.tag == 'ref_model': @@ -449,6 +572,3 @@ class Convert: else: pass return retVal - - - diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index ccc4c602..e94ee561 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -10,54 +10,62 @@ class DeviceModel(QtGui.QWidget): This class creates Device Library Tab in KicadtoNgspice Window It dynamically creates the widget for device like diode,mosfet,transistor and jfet. """ - + def __init__(self, schematicInfo, clarg1): - + self.clarg1 = clarg1 kicadFile = self.clarg1 - (projpath,filename) = os.path.split(kicadFile) + (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) try: - f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + f = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'r') data = f.read() json_data = json.loads(data) - except: + except BaseException: print("Device Model Previous JSON is Empty") - - + QtGui.QWidget.__init__(self) - - #Creating track widget object + + # Creating track widget object self.obj_trac = TrackWidget.TrackWidget() - - #Row and column count + + # Row and column count self.row = 0 - self.count = 1 #Entry count + self.count = 1 # Entry count self.entry_var = {} - - #For MOSFET + + # For MOSFET self.widthLabel = {} self.lengthLabel = {} self.multifactorLable = {} - self.devicemodel_dict_beg = {} - self.devicemodel_dict_end = {} - #List to hold information about device + self.devicemodel_dict_beg = {} + self.devicemodel_dict_end = {} + # List to hold information about device self.deviceDetail = {} - - #Set Layout + + # Set Layout self.grid = QtGui.QGridLayout() self.setLayout(self.grid) print("Reading Device model details from Schematic") - + for eachline in schematicInfo: words = eachline.split() if eachline[0] == 'q': - print("Device Model Transistor: ",words[0]) + print("Device Model Transistor: ", words[0]) self.devicemodel_dict_beg[words[0]] = self.count - transbox=QtGui.QGroupBox() - transgrid=QtGui.QGridLayout() - transbox.setTitle("Add library for Transistor "+words[0]+" : "+words[4]) + transbox = QtGui.QGroupBox() + transgrid = QtGui.QGridLayout() + transbox.setTitle( + "Add library for Transistor " + + words[0] + + " : " + + words[4]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") global path_name @@ -67,19 +75,22 @@ class DeviceModel(QtGui.QWidget): if key[0] == eachline[0] and key[1] == eachline[1]: #print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] try: - if os.path.exists(json_data["deviceModel"][key][0]): - self.entry_var[self.count].setText(json_data["deviceModel"][key][0]) + if os.path.exists( + json_data["deviceModel"][key][0]): + self.entry_var[self.count].setText( + json_data["deviceModel"][key][0]) path_name = json_data["deviceModel"][key][0] else: self.entry_var[self.count].setText("") - except: - print("Error when set text of device model transistor") - except: + except BaseException: + print( + "Error when set text of device model transistor") + except BaseException: pass transgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") - self.addbtn.setObjectName("%d" %self.count) + self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] @@ -87,32 +98,35 @@ class DeviceModel(QtGui.QWidget): pass else: self.trackLibraryWithoutButton(self.count, path_name) - + transgrid.addWidget(self.addbtn, self.row, 2) transbox.setLayout(transgrid) - - #CSS + + # CSS transbox.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(transbox) - - #Adding Device Details - - - #Increment row and widget count + + # 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] == 'd': - print("Device Model Diode:",words[0]) + print("Device Model Diode:", words[0]) self.devicemodel_dict_beg[words[0]] = self.count diodebox = QtGui.QGroupBox() diodegrid = QtGui.QGridLayout() - diodebox.setTitle("Add library for Diode "+words[0]+" : "+words[3]) + diodebox.setTitle( + "Add library for Diode " + + words[0] + + " : " + + words[3]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") #global path_name @@ -121,19 +135,21 @@ class DeviceModel(QtGui.QWidget): if key[0] == eachline[0] and key[1] == eachline[1]: #print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] try: - if os.path.exists(json_data["deviceModel"][key][0]): + if os.path.exists( + json_data["deviceModel"][key][0]): path_name = json_data["deviceModel"][key][0] - self.entry_var[self.count].setText(json_data["deviceModel"][key][0]) + self.entry_var[self.count].setText( + json_data["deviceModel"][key][0]) else: self.entry_var[self.count].setText("") - except: + except BaseException: print("Error when set text of device model diode") - except: + except BaseException: pass diodegrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") - self.addbtn.setObjectName("%d" %self.count) + self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] @@ -144,29 +160,32 @@ class DeviceModel(QtGui.QWidget): diodegrid.addWidget(self.addbtn, self.row, 2) diodebox.setLayout(diodegrid) - - #CSS + + # CSS diodebox.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(diodebox) - - #Adding Device Details - - - #Increment row and widget count + + # 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] == 'j': - print("Device Model JFET:",words[0]) + print("Device Model JFET:", words[0]) self.devicemodel_dict_beg[words[0]] = self.count jfetbox = QtGui.QGroupBox() jfetgrid = QtGui.QGridLayout() - jfetbox.setTitle("Add library for JFET "+words[0]+" : "+words[4]) + jfetbox.setTitle( + "Add library for JFET " + + words[0] + + " : " + + words[4]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") #global path_name @@ -175,19 +194,21 @@ class DeviceModel(QtGui.QWidget): if key[0] == eachline[0] and key[1] == eachline[1]: #print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] try: - if os.path.exists(json_data["deviceModel"][key][0]): - self.entry_var[self.count].setText(json_data["deviceModel"][key][0]) + if os.path.exists( + json_data["deviceModel"][key][0]): + self.entry_var[self.count].setText( + json_data["deviceModel"][key][0]) path_name = json_data["deviceModel"][key][0] else: self.entry_var[self.count].setText("") - except: + except BaseException: print("Error when set text of Device Model JFET ") - except: + except BaseException: pass jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") - self.addbtn.setObjectName("%d" %self.count) + self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] @@ -198,65 +219,72 @@ class DeviceModel(QtGui.QWidget): jfetgrid.addWidget(self.addbtn, self.row, 2) jfetbox.setLayout(jfetgrid) - - #CSS + + # CSS jfetbox.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(jfetbox) - - #Adding Device Details - #Increment row and widget count + + # 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] == 'm': self.devicemodel_dict_beg[words[0]] = self.count mosfetbox = QtGui.QGroupBox() mosfetgrid = QtGui.QGridLayout() i = self.count beg = self.count - mosfetbox.setTitle("Add library for MOSFET "+words[0]+" : "+words[5]) + mosfetbox.setTitle( + "Add library for MOSFET " + + words[0] + + " : " + + words[5]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") mosfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") - self.addbtn.setObjectName("%d" %self.count) + self.addbtn.setObjectName("%d" % self.count) self.addbtn.clicked.connect(self.trackLibrary) mosfetgrid.addWidget(self.addbtn, self.row, 2) - - #Adding Device Details + + # Adding Device Details self.deviceDetail[self.count] = words[0] - - #Increment row and widget count + + # Increment row and widget count self.row = self.row + 1 self.count = self.count + 1 - - #Adding to get MOSFET dimension - self.widthLabel[self.count] = QtGui.QLabel("Enter width of MOSFET "+words[0]+"(default=100u):") + + # Adding to get MOSFET dimension + self.widthLabel[self.count] = QtGui.QLabel( + "Enter width of MOSFET " + words[0] + "(default=100u):") mosfetgrid.addWidget(self.widthLabel[self.count], self.row, 0) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") self.entry_var[self.count].setMaximumWidth(150) mosfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.row = self.row + 1 - self.count = self.count+1 - - self.lengthLabel[self.count] = QtGui.QLabel("Enter length of MOSFET "+words[0]+"(default=100u):") + self.count = self.count + 1 + + self.lengthLabel[self.count] = QtGui.QLabel( + "Enter length of MOSFET " + words[0] + "(default=100u):") mosfetgrid.addWidget(self.lengthLabel[self.count], self.row, 0) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") self.entry_var[self.count].setMaximumWidth(150) mosfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.row = self.row + 1 - self.count = self.count+1 - - - self.multifactorLable[self.count] = QtGui.QLabel("Enter multiplicative factor of MOSFET "+words[0]+"(default=1):") - mosfetgrid.addWidget(self.multifactorLable[self.count], self.row, 0) + self.count = self.count + 1 + + self.multifactorLable[self.count] = QtGui.QLabel( + "Enter multiplicative factor of MOSFET " + words[0] + "(default=1):") + mosfetgrid.addWidget( + self.multifactorLable[self.count], self.row, 0) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") end = self.count @@ -264,7 +292,7 @@ class DeviceModel(QtGui.QWidget): mosfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.row = self.row + 1 self.devicemodel_dict_end[words[0]] = self.count - self.count = self.count+1 + self.count = self.count + 1 mosfetbox.setLayout(mosfetgrid) #global path_name try: @@ -272,16 +300,18 @@ class DeviceModel(QtGui.QWidget): if key[0] == eachline[0] and key[1] == eachline[1]: #print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] while i <= end: - self.entry_var[i].setText(json_data["deviceModel"][key][i-beg]) - if (i-beg) == 0: - if os.path.exists(json_data["deviceModel"][key][0]): + self.entry_var[i].setText( + json_data["deviceModel"][key][i - beg]) + if (i - beg) == 0: + if os.path.exists( + json_data["deviceModel"][key][0]): path_name = json_data["deviceModel"][key][0] else: self.entry_var[i].setText("") i = i + 1 - except: + except BaseException: pass - #CSS + # CSS mosfetbox.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; } \ @@ -290,13 +320,11 @@ class DeviceModel(QtGui.QWidget): pass else: self.trackLibraryWithoutButton(beg, path_name) - + self.grid.addWidget(mosfetbox) - - + self.show() - - + def trackLibrary(self): """ This function is use to keep track of all Device Model widget @@ -305,55 +333,66 @@ class DeviceModel(QtGui.QWidget): sending_btn = self.sender() #print "Object Called is ",sending_btn.objectName() self.widgetObjCount = int(sending_btn.objectName()) - - self.libfile = str(QtGui.QFileDialog.getOpenFileName(self,"Open Library Directory","../deviceModelLibrary","*.lib")) + + self.libfile = str( + QtGui.QFileDialog.getOpenFileName( + self, + "Open Library Directory", + "../deviceModelLibrary", + "*.lib")) #print "Selected Library File :",self.libfile - - #Setting Library to Text Edit Line + + # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.libfile) self.deviceName = self.deviceDetail[self.widgetObjCount] - - #Storing to track it during conversion - - + + # Storing to track it during conversion + if self.deviceName[0] == 'm': - width = str(self.entry_var[self.widgetObjCount+1].text()) - length = str(self.entry_var[self.widgetObjCount+2].text()) - multifactor = str(self.entry_var[self.widgetObjCount+3].text()) - if width == "" : width="100u" - if length == "": length="100u" - if multifactor == "": multifactor="1" - - self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile+":"+"W="+width+" L="+length+" M="+multifactor - + width = str(self.entry_var[self.widgetObjCount + 1].text()) + length = str(self.entry_var[self.widgetObjCount + 2].text()) + multifactor = str(self.entry_var[self.widgetObjCount + 3].text()) + if width == "": + width = "100u" + if length == "": + length = "100u" + if multifactor == "": + multifactor = "1" + + self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile + \ + ":" + "W=" + width + " L=" + length + " M=" + multifactor + else: self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile - def trackLibraryWithoutButton(self,iter_value,path_value): + + def trackLibraryWithoutButton(self, iter_value, path_value): """ This function is use to keep track of all Device Model widget """ print("Calling Track Library function Without Button") #print "Object Called is ",sending_btn.objectName() self.widgetObjCount = iter_value - print("self.widgetObjCount-----",self.widgetObjCount) + print("self.widgetObjCount-----", self.widgetObjCount) self.libfile = path_value #print "Selected Library File :",self.libfile - #Setting Library to Text Edit Line + # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.libfile) self.deviceName = self.deviceDetail[self.widgetObjCount] - #Storing to track it during conversion - + # Storing to track it during conversion if self.deviceName[0] == 'm': - width = str(self.entry_var[self.widgetObjCount+1].text()) - length = str(self.entry_var[self.widgetObjCount+2].text()) - multifactor = str(self.entry_var[self.widgetObjCount+3].text()) - if width == "" : width="100u" - if length == "": length="100u" - if multifactor == "": multifactor="1" - self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile+":"+"W="+width+" L="+length+" M="+multifactor + width = str(self.entry_var[self.widgetObjCount + 1].text()) + length = str(self.entry_var[self.widgetObjCount + 2].text()) + multifactor = str(self.entry_var[self.widgetObjCount + 3].text()) + if width == "": + width = "100u" + if length == "": + length = "100u" + if multifactor == "": + multifactor = "1" + self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile + \ + ":" + "W=" + width + " L=" + length + " M=" + multifactor else: self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile - diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py index 637d971c..9001830f 100644 --- a/src/kicadtoNgspice/KicadtoNgspice.py +++ b/src/kicadtoNgspice/KicadtoNgspice.py @@ -1,20 +1,20 @@ -#=============================================================================== +#========================================================================= # # FILE: kicadtoNgspice.py -# -# USAGE: --- -# -# DESCRIPTION: This define all configuration used in Application. -# +# +# USAGE: --- +# +# DESCRIPTION: This define all configuration used in Application. +# # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Fahim Khan, fahim.elex@gmail.com # ORGANIZATION: eSim team at FOSSEE, IIT Bombay. -# CREATED: Wednesday 04 March 2015 +# CREATED: Wednesday 04 March 2015 # REVISION: --- -#=============================================================================== +#========================================================================= import sys import os from PyQt4 import QtGui @@ -31,161 +31,164 @@ import json #from xml.etree import ElementTree as ET - class MainWindow(QtGui.QWidget): """ - This class create KicadtoNgspice window. + This class create KicadtoNgspice window. And Call Convert function if convert button is pressed. The convert function takes all the value entered by user and create a final netlist "*.cir.out". - This final netlist is compatible with NgSpice. + This final netlist is compatible with NgSpice. """ - def __init__(self,clarg1,clarg2=None): + + def __init__(self, clarg1, clarg2=None): QtGui.QWidget.__init__(self) - + print("==================================") print("Kicad to Ngspice netlist converter ") print("==================================") - global kicadNetlist,schematicInfo - global infoline,optionInfo + global kicadNetlist, schematicInfo + global infoline, optionInfo self.kicadFile = clarg1 - self.clarg1=clarg1 - self.clarg2=clarg2 - - #Create object of track widget + self.clarg1 = clarg1 + self.clarg2 = clarg2 + + # Create object of track widget self.obj_track = TrackWidget.TrackWidget() - - #Clear Dictionary/List item of sub circuit and ngspice model - #Dictionary + + # Clear Dictionary/List item of sub circuit and ngspice model + # Dictionary self.obj_track.subcircuitList.clear() self.obj_track.subcircuitTrack.clear() self.obj_track.model_entry_var.clear() - #List - self.obj_track.modelTrack[:]=[] - - #Object of Processing + # List + self.obj_track.modelTrack[:] = [] + + # Object of Processing obj_proc = PrcocessNetlist() - + # Read the netlist kicadNetlist = obj_proc.readNetlist(self.kicadFile) - - print("Given Kicad Schematic Netlist Info :",kicadNetlist) - + + print("Given Kicad Schematic Netlist Info :", kicadNetlist) + # Construct parameter information param = obj_proc.readParamInfo(kicadNetlist) - + # Replace parameter with values - netlist,infoline = obj_proc.preprocessNetlist(kicadNetlist,param) - - print("Schematic Info after processing Kicad Netlist: ",netlist) + netlist, infoline = obj_proc.preprocessNetlist(kicadNetlist, param) + + print("Schematic Info after processing Kicad Netlist: ", netlist) #print "INFOLINE",infoline - + # Separate option and schematic information optionInfo, schematicInfo = obj_proc.separateNetlistInfo(netlist) - - print("OPTIONINFO in the Netlist",optionInfo) - - #List for storing source and its value + + print("OPTIONINFO in the Netlist", optionInfo) + + # List for storing source and its value global sourcelist, sourcelisttrack - sourcelist=[] - sourcelisttrack=[] - schematicInfo,sourcelist = obj_proc.insertSpecialSourceParam(schematicInfo,sourcelist) - - #List storing model detail - global modelList,outputOption,unknownModelList,multipleModelList,plotText - - modelList = [] + sourcelist = [] + sourcelisttrack = [] + schematicInfo, sourcelist = obj_proc.insertSpecialSourceParam( + schematicInfo, sourcelist) + + # List storing model detail + global modelList, outputOption, unknownModelList, multipleModelList, plotText + + modelList = [] outputOption = [] plotText = [] - schematicInfo,outputOption,modelList,unknownModelList,multipleModelList,plotText = obj_proc.convertICintoBasicBlocks(schematicInfo,outputOption,modelList,plotText) - - print("Model available in the Schematic :",modelList) + schematicInfo, outputOption, modelList, unknownModelList, multipleModelList, plotText = obj_proc.convertICintoBasicBlocks( + schematicInfo, outputOption, modelList, plotText) + + print("Model available in the Schematic :", modelList) - """ Checking if any unknown model is used in schematic which is not recognized by NgSpice. Also if the two model of same name is present under modelParamXML directory - """ + """ if unknownModelList: - print("Unknown Model List is : ",unknownModelList) + print("Unknown Model List is : ", unknownModelList) self.msg = QtGui.QErrorMessage() - self.content = "Your schematic contain unknown model "+', '.join(unknownModelList) + self.content = "Your schematic contain unknown model " + \ + ', '.join(unknownModelList) self.msg.showMessage(self.content) self.msg.setWindowTitle("Unknown Models") - + elif multipleModelList: self.msg = QtGui.QErrorMessage() - self.mcontent = "Look like you have duplicate model in modelParamXML directory "+', '.join(multipleModelList[0]) + self.mcontent = "Look like you have duplicate model in modelParamXML directory " + \ + ', '.join(multipleModelList[0]) self.msg.showMessage(self.mcontent) self.msg.setWindowTitle("Multiple Models") - + else: self.createMainWindow() - - + def createMainWindow(self): """ This function create main window of Kicad to Ngspice converter """ - + self.vbox = QtGui.QVBoxLayout(self) - self.hbox=QtGui.QHBoxLayout(self) + self.hbox = QtGui.QHBoxLayout(self) self.hbox.addStretch(1) self.convertbtn = QtGui.QPushButton("Convert") self.convertbtn.clicked.connect(self.callConvert) self.hbox.addWidget(self.convertbtn) self.vbox.addWidget(self.createcreateConvertWidget()) self.vbox.addLayout(self.hbox) - + self.setLayout(self.vbox) self.setWindowTitle("Kicad To NgSpice Converter") self.show() - + def createcreateConvertWidget(self): global obj_analysis self.convertWindow = QtGui.QWidget() self.analysisTab = QtGui.QScrollArea() - obj_analysis=Analysis.Analysis(self.clarg1) + obj_analysis = Analysis.Analysis(self.clarg1) self.analysisTab.setWidget(obj_analysis) #self.analysisTabLayout = QtGui.QVBoxLayout(self.analysisTab.widget()) self.analysisTab.setWidgetResizable(True) global obj_source self.sourceTab = QtGui.QScrollArea() - obj_source=Source.Source(sourcelist,sourcelisttrack,self.clarg1) + obj_source = Source.Source(sourcelist, sourcelisttrack, self.clarg1) self.sourceTab.setWidget(obj_source) #self.sourceTabLayout = QtGui.QVBoxLayout(self.sourceTab.widget()) self.sourceTab.setWidgetResizable(True) global obj_model self.modelTab = QtGui.QScrollArea() - obj_model=Model.Model(schematicInfo,modelList,self.clarg1) + obj_model = Model.Model(schematicInfo, modelList, self.clarg1) self.modelTab.setWidget(obj_model) #self.modelTabLayout = QtGui.QVBoxLayout(self.modelTab.widget()) self.modelTab.setWidgetResizable(True) global obj_devicemodel self.deviceModelTab = QtGui.QScrollArea() - obj_devicemodel=DeviceModel.DeviceModel(schematicInfo,self.clarg1) + obj_devicemodel = DeviceModel.DeviceModel(schematicInfo, self.clarg1) self.deviceModelTab.setWidget(obj_devicemodel) self.deviceModelTab.setWidgetResizable(True) global obj_subcircuitTab self.subcircuitTab = QtGui.QScrollArea() - obj_subcircuitTab = SubcircuitTab.SubcircuitTab(schematicInfo,self.clarg1) + obj_subcircuitTab = SubcircuitTab.SubcircuitTab( + schematicInfo, self.clarg1) self.subcircuitTab.setWidget(obj_subcircuitTab) self.subcircuitTab.setWidgetResizable(True) self.tabWidget = QtGui.QTabWidget() - #self.tabWidget.TabShape(QtGui.QTabWidget.Rounded) - self.tabWidget.addTab(self.analysisTab,"Analysis") - self.tabWidget.addTab(self.sourceTab,"Source Details") - self.tabWidget.addTab(self.modelTab,"NgSpice Model") - self.tabWidget.addTab(self.deviceModelTab,"Device Modeling") - self.tabWidget.addTab(self.subcircuitTab,"Subcircuits") + # self.tabWidget.TabShape(QtGui.QTabWidget.Rounded) + self.tabWidget.addTab(self.analysisTab, "Analysis") + self.tabWidget.addTab(self.sourceTab, "Source Details") + self.tabWidget.addTab(self.modelTab, "NgSpice Model") + self.tabWidget.addTab(self.deviceModelTab, "Device Modeling") + self.tabWidget.addTab(self.subcircuitTab, "Subcircuits") self.mainLayout = QtGui.QVBoxLayout() self.mainLayout.addWidget(self.tabWidget) - #self.mainLayout.addStretch(1) + # self.mainLayout.addStretch(1) self.convertWindow.setLayout(self.mainLayout) self.convertWindow.show() - - return self.convertWindow - + + return self.convertWindow + def callConvert(self): """ Calling Convert Class Constructor @@ -194,20 +197,23 @@ class MainWindow(QtGui.QWidget): global analysisoutput global kicad store_schematicInfo = list(schematicInfo) - (projpath,filename) = os.path.split(self.kicadFile) + (projpath, filename) = os.path.split(self.kicadFile) project_name = os.path.basename(projpath) - - - fw = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'w') - json_data = {} + fw = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'w') + json_data = {} """ Writing Analysis values """ json_data["analysis"] = {} - + json_data["analysis"]["ac"] = {} if obj_analysis.Lin.isChecked(): json_data["analysis"]["ac"]["Lin"] = "true" @@ -223,44 +229,58 @@ class MainWindow(QtGui.QWidget): json_data["analysis"]["ac"]["Oct"] = "true" else: pass - - json_data["analysis"]["ac"]["Start Frequency"] = str(obj_analysis.ac_entry_var[0].text()) - json_data["analysis"]["ac"]["Stop Frequency"] = str(obj_analysis.ac_entry_var[1].text()) - json_data["analysis"]["ac"]["No. of points"] = str(obj_analysis.ac_entry_var[2].text()) + + json_data["analysis"]["ac"]["Start Frequency"] = str( + obj_analysis.ac_entry_var[0].text()) + json_data["analysis"]["ac"]["Stop Frequency"] = str( + obj_analysis.ac_entry_var[1].text()) + json_data["analysis"]["ac"]["No. of points"] = str( + obj_analysis.ac_entry_var[2].text()) json_data["analysis"]["ac"]["Start Fre Combo"] = obj_analysis.ac_parameter[0] json_data["analysis"]["ac"]["Stop Fre Combo"] = obj_analysis.ac_parameter[1] json_data["analysis"]["dc"] = {} - json_data["analysis"]["dc"]["Source 1"] = str(obj_analysis.dc_entry_var[0].text()) - json_data["analysis"]["dc"]["Start"] = str(obj_analysis.dc_entry_var[1].text()) - json_data["analysis"]["dc"]["Increment"] = str(obj_analysis.dc_entry_var[2].text()) - json_data["analysis"]["dc"]["Stop"] = str(obj_analysis.dc_entry_var[3].text()) - json_data["analysis"]["dc"]["Operating Point"] = str(self.obj_track.op_check[-1]) + json_data["analysis"]["dc"]["Source 1"] = str( + obj_analysis.dc_entry_var[0].text()) + json_data["analysis"]["dc"]["Start"] = str( + obj_analysis.dc_entry_var[1].text()) + json_data["analysis"]["dc"]["Increment"] = str( + obj_analysis.dc_entry_var[2].text()) + json_data["analysis"]["dc"]["Stop"] = str( + obj_analysis.dc_entry_var[3].text()) + json_data["analysis"]["dc"]["Operating Point"] = str( + self.obj_track.op_check[-1]) json_data["analysis"]["dc"]["Start Combo"] = obj_analysis.dc_parameter[0] json_data["analysis"]["dc"]["Increment Combo"] = obj_analysis.dc_parameter[1] json_data["analysis"]["dc"]["Stop Combo"] = obj_analysis.dc_parameter[2] - json_data["analysis"]["dc"]["Source 2"] = str(obj_analysis.dc_entry_var[4].text()) - json_data["analysis"]["dc"]["Start2"] = str(obj_analysis.dc_entry_var[5].text()) - json_data["analysis"]["dc"]["Increment2"] = str(obj_analysis.dc_entry_var[6].text()) - json_data["analysis"]["dc"]["Stop2"] = str(obj_analysis.dc_entry_var[7].text()) + json_data["analysis"]["dc"]["Source 2"] = str( + obj_analysis.dc_entry_var[4].text()) + json_data["analysis"]["dc"]["Start2"] = str( + obj_analysis.dc_entry_var[5].text()) + json_data["analysis"]["dc"]["Increment2"] = str( + obj_analysis.dc_entry_var[6].text()) + json_data["analysis"]["dc"]["Stop2"] = str( + obj_analysis.dc_entry_var[7].text()) json_data["analysis"]["dc"]["Start Combo2"] = obj_analysis.dc_parameter[3] json_data["analysis"]["dc"]["Increment Combo2"] = obj_analysis.dc_parameter[4] json_data["analysis"]["dc"]["Stop Combo2"] = obj_analysis.dc_parameter[5] json_data["analysis"]["tran"] = {} - json_data["analysis"]["tran"]["Start Time"] = str(obj_analysis.tran_entry_var[0].text()) - json_data["analysis"]["tran"]["Step Time"] = str(obj_analysis.tran_entry_var[1].text()) - json_data["analysis"]["tran"]["Stop Time"] = str(obj_analysis.tran_entry_var[2].text()) + json_data["analysis"]["tran"]["Start Time"] = str( + obj_analysis.tran_entry_var[0].text()) + json_data["analysis"]["tran"]["Step Time"] = str( + obj_analysis.tran_entry_var[1].text()) + json_data["analysis"]["tran"]["Stop Time"] = str( + obj_analysis.tran_entry_var[2].text()) json_data["analysis"]["tran"]["Start Combo"] = obj_analysis.tran_parameter[0] json_data["analysis"]["tran"]["Step Combo"] = obj_analysis.tran_parameter[1] json_data["analysis"]["tran"]["Stop Combo"] = obj_analysis.tran_parameter[2] - """ Writing Source values """ - json_data["source"] = {} + json_data["source"] = {} count = 1 for line in store_schematicInfo: @@ -269,10 +289,10 @@ class MainWindow(QtGui.QWidget): if wordv[0] == "v" or wordv[0] == "i": json_data["source"][wordv] = {} - json_data["source"][wordv]["type"] = words[len(words)-1] + json_data["source"][wordv]["type"] = words[len(words) - 1] json_data["source"][wordv]["values"] = [] - if words[len(words)-1] == "ac": + if words[len(words) - 1] == "ac": amp = {"Amplitude": str(obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(amp) @@ -281,13 +301,15 @@ class MainWindow(QtGui.QWidget): count += 1 json_data["source"][wordv]["values"].append(phase) - elif words[len(words)-1] == "dc": + elif words[len(words) - 1] == "dc": value = {"Value": str(obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(value) - elif words[len(words)-1] == "sine": - offset = {"Offset Value": str(obj_source.entry_var[count].text())} + elif words[len(words) - 1] == "sine": + offset = { + "Offset Value": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(offset) @@ -303,16 +325,22 @@ class MainWindow(QtGui.QWidget): count += 1 json_data["source"][wordv]["values"].append(delay) - damp = {"Damping Factor": str(obj_source.entry_var[count].text())} + damp = { + "Damping Factor": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(damp) - elif words[len(words)-1] == "pulse": - initial = {"Initial Value": str(obj_source.entry_var[count].text())} + elif words[len(words) - 1] == "pulse": + initial = { + "Initial Value": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(initial) - pulse = {"Pulse Value": str(obj_source.entry_var[count].text())} + pulse = { + "Pulse Value": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(pulse) @@ -328,7 +356,9 @@ class MainWindow(QtGui.QWidget): count += 1 json_data["source"][wordv]["values"].append(fall) - width = {"Pulse width": str(obj_source.entry_var[count].text())} + width = { + "Pulse width": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(width) @@ -336,21 +366,29 @@ class MainWindow(QtGui.QWidget): count += 1 json_data["source"][wordv]["values"].append(period) - elif words[len(words)-1]=="pwl": - pwl = {"Enter in pwl format": str(obj_source.entry_var[count].text())} + elif words[len(words) - 1] == "pwl": + pwl = { + "Enter in pwl format": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(pwl) - elif words[len(words)-1]=="exp": - initial = {"Initial Value": str(obj_source.entry_var[count].text())} + elif words[len(words) - 1] == "exp": + initial = { + "Initial Value": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(initial) - pulsed = {"Pulsed Value": str(obj_source.entry_var[count].text())} + pulsed = { + "Pulsed Value": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(pulsed) - rise = {"Rise Delay Time": str(obj_source.entry_var[count].text())} + rise = { + "Rise Delay Time": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(rise) @@ -358,19 +396,20 @@ class MainWindow(QtGui.QWidget): count += 1 json_data["source"][wordv]["values"].append(fall) - fallConstant = {"Fall Time Constant": str(obj_source.entry_var[count].text())} + fallConstant = { + "Fall Time Constant": str( + obj_source.entry_var[count].text())} count += 1 json_data["source"][wordv]["values"].append(fallConstant) else: pass - """ Writing Model values """ - i = 0 + i = 0 json_data["model"] = {} for line in modelList: @@ -378,80 +417,88 @@ class MainWindow(QtGui.QWidget): if rand_itr[2] == line[2] and rand_itr[3] == line[3]: start = rand_itr[7] end = rand_itr[8] - i = start - + i = start + json_data["model"][line[3]] = {} json_data["model"][line[3]]["type"] = line[2] - json_data["model"][line[3]]["values"] = [] - + json_data["model"][line[3]]["values"] = [] + for key, value in line[7].items(): if hasattr(value, '__iter__') and i <= end: for item in value: - fields = {item: str(obj_model.obj_trac.model_entry_var[i].text())} + fields = { + item: str( + obj_model.obj_trac.model_entry_var[i].text())} json_data["model"][line[3]]["values"].append(fields) i = i + 1 - + else: - fields = {value: str(obj_model.obj_trac.model_entry_var[i].text())} + fields = { + value: str( + obj_model.obj_trac.model_entry_var[i].text())} json_data["model"][line[3]]["values"].append(fields) i = i + 1 - """ Writing Device Model values """ - json_data["deviceModel"] = {} - + json_data["deviceModel"] = {} + for device in obj_devicemodel.devicemodel_dict_beg: json_data["deviceModel"][device] = [] it = obj_devicemodel.devicemodel_dict_beg[device] end = obj_devicemodel.devicemodel_dict_end[device] while it <= end: - json_data["deviceModel"][device].append(str(obj_devicemodel.entry_var[it].text())) + json_data["deviceModel"][device].append( + str(obj_devicemodel.entry_var[it].text())) it = it + 1 - """ Writing Subcircuit values """ - json_data["subcircuit"] = {} + json_data["subcircuit"] = {} for subckt in obj_subcircuitTab.subcircuit_dict_beg: json_data["subcircuit"][subckt] = [] it = obj_subcircuitTab.subcircuit_dict_beg[subckt] end = obj_subcircuitTab.subcircuit_dict_end[subckt] while it <= end: - json_data["subcircuit"][subckt].append(str(obj_subcircuitTab.entry_var[it].text())) + json_data["subcircuit"][subckt].append( + str(obj_subcircuitTab.entry_var[it].text())) it = it + 1 write_data = json.dumps(json_data) fw.write(write_data) - - + self.obj_convert = Convert.Convert(self.obj_track.sourcelisttrack["ITEMS"], self.obj_track.source_entry_var["ITEMS"], - store_schematicInfo,self.clarg1) - + store_schematicInfo, self.clarg1) + try: - #Adding Source Value to Schematic Info + # Adding Source Value to Schematic Info store_schematicInfo = self.obj_convert.addSourceParameter() - print("Netlist After Adding Source details :",store_schematicInfo) - - #Adding Model Value to store_schematicInfo - store_schematicInfo = self.obj_convert.addModelParameter(store_schematicInfo) - print("Netlist After Adding Ngspice Model :",store_schematicInfo) - - #Adding Device Library to SchematicInfo - store_schematicInfo = self.obj_convert.addDeviceLibrary(store_schematicInfo,self.kicadFile) - print("Netlist After Adding Device Model Library :",store_schematicInfo) - - #Adding Subcircuit Library to SchematicInfo - store_schematicInfo = self.obj_convert.addSubcircuit(store_schematicInfo, self.kicadFile) - print("Netlist After Adding subcircuits :",store_schematicInfo) - + print("Netlist After Adding Source details :", store_schematicInfo) + + # Adding Model Value to store_schematicInfo + store_schematicInfo = self.obj_convert.addModelParameter( + store_schematicInfo) + print("Netlist After Adding Ngspice Model :", store_schematicInfo) + + # Adding Device Library to SchematicInfo + store_schematicInfo = self.obj_convert.addDeviceLibrary( + store_schematicInfo, self.kicadFile) + print( + "Netlist After Adding Device Model Library :", + store_schematicInfo) + + # Adding Subcircuit Library to SchematicInfo + store_schematicInfo = self.obj_convert.addSubcircuit( + store_schematicInfo, self.kicadFile) + print("Netlist After Adding subcircuits :", store_schematicInfo) + analysisoutput = self.obj_convert.analysisInsertor(self.obj_track.AC_entry_var["ITEMS"], self.obj_track.DC_entry_var["ITEMS"], self.obj_track.TRAN_entry_var["ITEMS"], @@ -461,27 +508,28 @@ class MainWindow(QtGui.QWidget): self.obj_track.TRAN_Parameter["ITEMS"], self.obj_track.AC_type["ITEMS"], self.obj_track.op_check) - - print("Analysis OutPut ",analysisoutput) - - #Calling netlist file generation function - self.createNetlistFile(store_schematicInfo,plotText) - + + print("Analysis OutPut ", analysisoutput) + + # Calling netlist file generation function + self.createNetlistFile(store_schematicInfo, plotText) + self.msg = "The Kicad to Ngspice Conversion completed successfully!" - QtGui.QMessageBox.information(self, "Information", self.msg, QtGui.QMessageBox.Ok) - + QtGui.QMessageBox.information( + self, "Information", self.msg, QtGui.QMessageBox.Ok) + except Exception as e: - print("Exception Message: ",e) + print("Exception Message: ", e) print("There was error while converting kicad to ngspice") self.close() - + # Generate .sub file from .cir.out file if it is a subcircuit subPath = os.path.splitext(self.kicadFile)[0] - + if self.clarg2 == "sub": self.createSubFile(subPath) - - def createNetlistFile(self,store_schematicInfo,plotText): + + def createNetlistFile(self, store_schematicInfo, plotText): print("Creating Final netlist") #print "INFOLINE",infoline #print "OPTIONINFO",optionInfo @@ -489,158 +537,154 @@ class MainWindow(QtGui.QWidget): #print "SUBCKT ",subcktList #print "OUTPUTOPTION",outputOption #print "KicadfIle",kicadFile - store_optionInfo = list(optionInfo) #To avoid writing optionInfo twice in final netlist - - #checking if analysis files is present - (projpath,filename) = os.path.split(self.kicadFile) - analysisFileLoc = os.path.join(projpath,"analysis") + # To avoid writing optionInfo twice in final netlist + store_optionInfo = list(optionInfo) + + # checking if analysis files is present + (projpath, filename) = os.path.split(self.kicadFile) + analysisFileLoc = os.path.join(projpath, "analysis") #print "Analysis File Location",analysisFileLoc if os.path.exists(analysisFileLoc): try: f = open(analysisFileLoc) - #Read data + # Read data data = f.read() # Close the file f.close() - except : + except BaseException: print("Error While opening Project Analysis file. Please check it") sys.exit() else: print(analysisFileLoc + " does not exist") sys.exit() - - #Adding analysis file info to optionInfo - analysisData=data.splitlines() + + # Adding analysis file info to optionInfo + analysisData = data.splitlines() for eachline in analysisData: - eachline=eachline.strip() - if len(eachline)>1: - if eachline[0]=='.': + eachline = eachline.strip() + if len(eachline) > 1: + if eachline[0] == '.': store_optionInfo.append(eachline) else: pass - + #print "Option Info",optionInfo analysisOption = [] - initialCondOption=[] - simulatorOption =[] - #includeOption=[] #Don't know why to use it - #model = [] #Don't know why to use it - + initialCondOption = [] + simulatorOption = [] + # includeOption=[] #Don't know why to use it + # model = [] #Don't know why to use it + for eachline in store_optionInfo: - 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 - option=='.tran'): - analysisOption.append(eachline+'\n') - - elif (option=='.save' or option=='.print' or option=='.plot' or option=='.four'): - eachline=eachline.strip('.') - outputOption.append(eachline+'\n') - elif (option=='.nodeset' or option=='.ic'): - initialCondOption.append(eachline+'\n') - elif option=='.option': - simulatorOption.append(eachline+'\n') - #elif (option=='.include' or option=='.lib'): + 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 + option == '.tran'): + analysisOption.append(eachline + '\n') + + elif (option == '.save' or option == '.print' or option == '.plot' or option == '.four'): + eachline = eachline.strip('.') + outputOption.append(eachline + '\n') + elif (option == '.nodeset' or option == '.ic'): + initialCondOption.append(eachline + '\n') + elif option == '.option': + simulatorOption.append(eachline + '\n') + # elif (option=='.include' or option=='.lib'): # includeOption.append(eachline+'\n') - #elif (option=='.model'): + # elif (option=='.model'): # model.append(eachline+'\n') - elif option=='.end': - continue; - - - #Start creating final netlist cir.out file - outfile = self.kicadFile+".out" - out=open(outfile,"w") + elif option == '.end': + continue + + # Start creating final netlist cir.out file + outfile = self.kicadFile + ".out" + out = open(outfile, "w") out.writelines(infoline) out.writelines('\n') - sections=[simulatorOption, initialCondOption, store_schematicInfo, analysisOption] - + sections = [ + simulatorOption, + initialCondOption, + store_schematicInfo, + analysisOption] + for section in sections: if len(section) == 0: continue else: for line in section: - out.writelines('\n') + out.writelines('\n') out.writelines(line) - + out.writelines('\n* Control Statements \n') out.writelines('.control\n') out.writelines('run\n') - #out.writelines(outputOption) + # out.writelines(outputOption) out.writelines('print allv > plot_data_v.txt\n') out.writelines('print alli > plot_data_i.txt\n') for item in plotText: - out.writelines(item+'\n') + out.writelines(item + '\n') out.writelines('.endc\n') out.writelines('.end\n') out.close() - - - - def createSubFile(self,subPath): + + def createSubFile(self, subPath): self.project = subPath self.projName = os.path.basename(self.project) - if os.path.exists(self.project+".cir.out"): + if os.path.exists(self.project + ".cir.out"): try: - f = open(self.project+".cir.out") - except : + f = open(self.project + ".cir.out") + except BaseException: print("Error in opening .cir.out file.") else: - print(self.projName + ".cir.out does not exist. Please create a spice netlist.") - + print( + self.projName + + ".cir.out does not exist. Please create a spice netlist.") + # Read the data from file - data=f.read() + data = f.read() # Close the file - + f.close() - newNetlist=[] - netlist=iter(data.splitlines()) + newNetlist = [] + netlist = iter(data.splitlines()) for eachline in netlist: - eachline=eachline.strip() - if len(eachline)<1: + eachline = eachline.strip() + if len(eachline) < 1: continue - words=eachline.split() + words = eachline.split() if eachline[2] == 'u': - if words[len(words)-1] == "port": - subcktInfo = ".subckt "+self.projName+" " - for i in range(2,len(words)-1): - subcktInfo+=words[i]+" " + if words[len(words) - 1] == "port": + subcktInfo = ".subckt " + self.projName + " " + 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": while words[0] != ".endc": - eachline=next(netlist) - eachline=eachline.strip() - if len(eachline)<1: + eachline = next(netlist) + eachline = eachline.strip() + if len(eachline) < 1: continue - words=eachline.split() + words = eachline.split() else: newNetlist.append(eachline) - - outfile=self.project+".sub" - out=open(outfile,"w") + + outfile = self.project + ".sub" + out = open(outfile, "w") out.writelines("* Subcircuit " + self.projName) out.writelines('\n') out.writelines(subcktInfo) out.writelines('\n') - - for i in range(len(newNetlist),0,-1): - newNetlist.insert(i,'\n') - + + for i in range(len(newNetlist), 0, -1): + newNetlist.insert(i, '\n') + out.writelines(newNetlist) - out.writelines('\n') - + out.writelines('\n') + out.writelines('.ends ' + self.projName) - print("The subcircuit has been written in "+self.projName+".sub") - - - - - - - - - + print("The subcircuit has been written in " + self.projName + ".sub") diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 3f83b0d0..7366a593 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -7,73 +7,79 @@ import os class Model(QtGui.QWidget): """ - This class creates Model Tab of KicadtoNgspice window. + This class creates Model Tab of KicadtoNgspice window. The widgets are created dynamically in the Model Tab. """ - - def __init__(self,schematicInfo,modelList,clarg1): - + + def __init__(self, schematicInfo, modelList, clarg1): + QtGui.QWidget.__init__(self) - - #Processing for getting previous values + + # Processing for getting previous values kicadFile = clarg1 - (projpath,filename) = os.path.split(kicadFile) + (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) try: - f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + f = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'r') data = f.read() json_data = json.loads(data) - except: + except BaseException: print("Model Previous Values JSON is Empty") - - - - #Creating track widget object + + # Creating track widget object self.obj_trac = TrackWidget.TrackWidget() - - #for increasing row and counting/tracking line edit widget + + # for increasing row and counting/tracking line edit widget self.nextrow = 0 self.nextcount = 0 - - #for storing line edit details position details + + # for storing line edit details position details self.start = 0 self.end = 0 - - #Creating GUI dynamically for Model tab + + # Creating GUI dynamically for Model tab self.grid = QtGui.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 = {} + # Adding title label for model + # Key: Tag name,Value:Entry widget number + tag_dict = {} modelbox = QtGui.QGroupBox() modelgrid = QtGui.QGridLayout() modelbox.setTitle(line[5]) self.start = self.nextcount - #line[7] is parameter dictionary holding parameter tags. + # line[7] is parameter dictionary holding parameter tags. i = 0 - for key,value in line[7].items(): + for key, value in line[7].items(): #print "Key : ",key #print "Value : ",value - #Check if value is iterable + # Check if value is iterable if hasattr(value, '__iter__'): - #For tag having vector value + # For tag having vector value temp_tag = [] for item in value: paramLabel = QtGui.QLabel(item) modelgrid.addWidget(paramLabel, self.nextrow, 0) - self.obj_trac.model_entry_var[self.nextcount] = QtGui.QLineEdit() - modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount], self.nextrow, 1) + self.obj_trac.model_entry_var[self.nextcount] = QtGui.QLineEdit( + ) + modelgrid.addWidget( + self.obj_trac.model_entry_var[self.nextcount], self.nextrow, 1) try: for mod in json_data["model"]: if json_data["model"][mod]["type"] == line[2] and mod == line[3]: - self.obj_trac.model_entry_var[self.nextcount].setText(str(list(json_data["model"][mod]["values"][i].values())[0])) + self.obj_trac.model_entry_var[self.nextcount].setText( + str(list(json_data["model"][mod]["values"][i].values())[0])) i = i + 1 - except: + except BaseException: pass temp_tag.append(self.nextcount) @@ -84,16 +90,19 @@ class Model(QtGui.QWidget): else: paramLabel = QtGui.QLabel(value) modelgrid.addWidget(paramLabel, self.nextrow, 0) - self.obj_trac.model_entry_var[self.nextcount] = QtGui.QLineEdit() - modelgrid.addWidget(self.obj_trac.model_entry_var[self.nextcount], self.nextrow, 1) + self.obj_trac.model_entry_var[self.nextcount] = QtGui.QLineEdit( + ) + modelgrid.addWidget( + self.obj_trac.model_entry_var[self.nextcount], self.nextrow, 1) try: for mod in json_data["model"]: if json_data["model"][mod]["type"] == line[2] and mod == line[3]: - self.obj_trac.model_entry_var[self.nextcount].setText(str(list(json_data["model"][mod]["values"][i].values())[0])) + self.obj_trac.model_entry_var[self.nextcount].setText( + str(list(json_data["model"][mod]["values"][i].values())[0])) i = i + 1 - except: - pass + except BaseException: + pass tag_dict[key] = self.nextcount self.nextcount = self.nextcount + 1 @@ -102,17 +111,17 @@ class Model(QtGui.QWidget): self.end = self.nextcount - 1 #print "End",self.end modelbox.setLayout(modelgrid) - - #CSS + + # 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) - + ''' - Listing all + Listing all line[0] = index line[1] = compLine line[2] = modelname #Change from compType to modelname @@ -122,20 +131,27 @@ class Model(QtGui.QWidget): line[6] = type i.e analog or digital Now adding start,end and tag_dict which will be line[7],line[8] and line[9] respectively ''' - - #This keeps the track of Model Tab Widget - lst = [line[0], line[1], line[2], line[3], line[4], line[5], line[6], self.start, self.end, tag_dict] + + # This keeps the track of Model 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.modelTrack: if itr == lst: - check = 1 - - if check == 0: + check = 1 + + if check == 0: self.obj_trac.modelTrack.append(lst) - + #print "The tag dictionary : ",tag_dict - - - + self.show() - diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py index f9d1b4a8..a175ac8b 100644 --- a/src/kicadtoNgspice/Processing.py +++ b/src/kicadtoNgspice/Processing.py @@ -3,221 +3,244 @@ import os from xml.etree import ElementTree as ET - class PrcocessNetlist: """ - This class include all the function required for pre-proccessing of netlist + This class include all the function required for pre-proccessing of netlist before converting to Ngspice Netlist. """ modelxmlDIR = '../modelParamXML' + def __init__(self): pass - - def readNetlist(self,filename): + + def readNetlist(self, filename): f = open(filename) - data=f.read() + data = f.read() f.close() return data.splitlines() - def readParamInfo(self,kicadNetlis): + def readParamInfo(self, kicadNetlis): """Read Parameter information and store it into dictionary""" - param={} + param = {} for eachline in kicadNetlis: print(eachline) - eachline=eachline.strip() - if len(eachline)>1: - words=eachline.split() - option=words[0].lower() - if option=='.param': + eachline = eachline.strip() + if len(eachline) > 1: + words = eachline.split() + option = words[0].lower() + if option == '.param': for i in range(1, len(words), 1): - paramList=words[i].split('=') - param[paramList[0]]=paramList[1] + paramList = words[i].split('=') + param[paramList[0]] = paramList[1] return param - - def preprocessNetlist(self,kicadNetlis,param): + + def preprocessNetlist(self, kicadNetlis, param): """Preprocess netlist (replace parameters)""" - netlist=[] + netlist = [] for eachline in kicadNetlis: - # Remove leading and trailing blanks spaces from line - eachline=eachline.strip() + # Remove leading and trailing blanks spaces from line + eachline = eachline.strip() # Remove special character $ - eachline=eachline.replace('$','') + eachline = eachline.replace('$', '') # Replace parameter with values for subParam in eachline.split(): if '}' in subParam: - key=subParam.split()[0] - key=key.strip('{') - key=key.strip('}') + key = subParam.split()[0] + key = key.strip('{') + key = key.strip('}') if key in param: - eachline=eachline.replace('{'+key+'}',param[key]) + eachline = eachline.replace( + '{' + key + '}', param[key]) else: - print("Parameter " + key +" does not exists") - value=input('Enter parameter value: ') - eachline=eachline.replace('{'+key+'}',value) - #Convert netlist into lower case letter - eachline=eachline.lower() + print("Parameter " + key + " does not exists") + value = input('Enter parameter value: ') + eachline = eachline.replace('{' + key + '}', value) + # Convert netlist into lower case letter + eachline = eachline.lower() # Construct netlist - if len(eachline)>1: - if eachline[0]=='+': - netlist.append(netlist.pop()+eachline.replace('+',' ')) + if len(eachline) > 1: + if eachline[0] == '+': + netlist.append(netlist.pop() + eachline.replace('+', ' ')) else: netlist.append(eachline) - #Copy information line - infoline=netlist[0] + # Copy information line + infoline = netlist[0] netlist.remove(netlist[0]) - return netlist,infoline - - def separateNetlistInfo(self,netlist): - optionInfo=[] - schematicInfo=[] + return netlist, infoline + + def separateNetlistInfo(self, netlist): + optionInfo = [] + schematicInfo = [] for eachline in netlist: - if eachline[0]=='*': + if eachline[0] == '*': continue - elif eachline[0]=='.': + elif eachline[0] == '.': optionInfo.append(eachline) else: schematicInfo.append(eachline) - return optionInfo,schematicInfo - - - def insertSpecialSourceParam(self,schematicInfo,sourcelist): - #Inser Special source parameter - schematicInfo1=[] - + return optionInfo, schematicInfo + + def insertSpecialSourceParam(self, schematicInfo, sourcelist): + # Inser Special source parameter + schematicInfo1 = [] + print("Reading schematic info for source details") - + for compline in schematicInfo: - words=compline.split() - compName=words[0] + words = compline.split() + compName = words[0] # Ask for parameters of source - if compName[0]=='v' or compName[0]=='i': + if compName[0] == 'v' or compName[0] == 'i': # Find the index component from circuit - 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): ' - td=' Enter delay time (seconds): ' - tr=' Enter rise time (seconds): ' - tf=' Enter fall time (seconds): ' - pw=' Enter pulse width (seconds): ' - tp=' Enter period (seconds): ' - sourcelist.append([index,compline,words[3],Title,v1,v2,td,tr,tf,pw,tp]) - - elif words[3]=="sine": - Title="Add parameters for sine source "+compName - vo=' Enter offset value (Volts/Amps): ' - va=' Enter amplitude (Volts/Amps): ' - freq=' Enter frequency (Hz): ' - td=' Enter delay time (seconds): ' - theta=' Enter damping factor (1/seconds): ' - sourcelist.append([index,compline,words[3],Title,vo,va,freq,td,theta]) - - elif words[3]=="pwl": - Title="Add parameters for pwl source "+compName - t_v=' Enter in pwl format without bracket i.e t1 v1 t2 v2.... ' - sourcelist.append([index,compline,words[3],Title,t_v]) - - elif words[3]=="ac": - Title="Add parameters for ac source "+compName - v_a=' Enter amplitude (Volts/Amps): ' - p_a =' Enter Phase Shift: ' - sourcelist.append([index,compline,words[3],Title,v_a,p_a]) - - elif words[3]=="exp": - Title="Add parameters for exponential source "+compName - 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): ' - tau2=' Enter fall time constant (seconds): ' - sourcelist.append([index,compline,words[3],Title,v1,v2,td1,tau1,td2,tau2]) - - elif words[3]=="dc": - Title="Add parameters for DC source "+compName - v1=' Enter value(Volts/Amps): ' - v2=' Enter zero frequency: ' - sourcelist.append([index,compline,words[3],Title,v1,v2]) - - elif compName[0]=='h' or compName[0]=='f': + 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): ' + td = ' Enter delay time (seconds): ' + tr = ' Enter rise time (seconds): ' + tf = ' Enter fall time (seconds): ' + pw = ' Enter pulse width (seconds): ' + tp = ' Enter period (seconds): ' + sourcelist.append( + [index, compline, words[3], Title, v1, v2, td, tr, tf, pw, tp]) + + elif words[3] == "sine": + Title = "Add parameters for sine source " + compName + vo = ' Enter offset value (Volts/Amps): ' + va = ' Enter amplitude (Volts/Amps): ' + freq = ' Enter frequency (Hz): ' + td = ' Enter delay time (seconds): ' + theta = ' Enter damping factor (1/seconds): ' + sourcelist.append( + [index, compline, words[3], Title, vo, va, freq, td, theta]) + + elif words[3] == "pwl": + Title = "Add parameters for pwl source " + compName + t_v = ' Enter in pwl format without bracket i.e t1 v1 t2 v2.... ' + sourcelist.append([index, compline, words[3], Title, t_v]) + + elif words[3] == "ac": + Title = "Add parameters for ac source " + compName + v_a = ' Enter amplitude (Volts/Amps): ' + p_a = ' Enter Phase Shift: ' + sourcelist.append( + [index, compline, words[3], Title, v_a, p_a]) + + elif words[3] == "exp": + Title = "Add parameters for exponential source " + compName + 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): ' + tau2 = ' Enter fall time constant (seconds): ' + sourcelist.append( + [index, compline, words[3], Title, v1, v2, td1, tau1, td2, tau2]) + + elif words[3] == "dc": + Title = "Add parameters for DC source " + compName + v1 = ' Enter value(Volts/Amps): ' + v2 = ' Enter zero frequency: ' + sourcelist.append( + [index, compline, words[3], Title, v1, v2]) + + elif compName[0] == 'h' or compName[0] == 'f': # Find the index component from the circuit - index=schematicInfo.index(compline) + index = schematicInfo.index(compline) schematicInfo.remove(compline) - schematicInfo.insert(index,"* "+compName) - schematicInfo1.append("V"+compName+" "+words[3]+" "+words[4]+" 0") - schematicInfo1.append(compName+" "+words[1]+" "+words[2]+" "+"V"+compName+" "+words[5]) - - schematicInfo=schematicInfo+schematicInfo1 - print("Source List : ",sourcelist) + schematicInfo.insert(index, "* " + compName) + schematicInfo1.append( + "V" + compName + " " + words[3] + " " + words[4] + " 0") + schematicInfo1.append( + compName + + " " + + words[1] + + " " + + words[2] + + " " + + "V" + + compName + + " " + + words[5]) + + schematicInfo = schematicInfo + schematicInfo1 + print("Source List : ", sourcelist) #print schematicInfo - return schematicInfo,sourcelist - - - def convertICintoBasicBlocks(self,schematicInfo,outputOption,modelList,plotText): + return schematicInfo, sourcelist + + def convertICintoBasicBlocks( + self, schematicInfo, outputOption, modelList, plotText): print("Reading Schematic info for Model") - #Insert details of Ngspice model + # Insert details of Ngspice model unknownModelList = [] multipleModelList = [] - plotList = ['plot_v1','plot_v2','plot_i2','plot_log','plot_db','plot_phase'] - interMediateNodeCount=1 + plotList = [ + 'plot_v1', + 'plot_v2', + 'plot_i2', + 'plot_log', + 'plot_db', + 'plot_phase'] + interMediateNodeCount = 1 k = 1 for compline in schematicInfo: words = compline.split() compName = words[0] #print "Compline----------------->",compline #print "compName-------------->",compName - # Find the IC from schematic - if compName[0]=='u' or compName[0] == 'U': + # Find the IC from schematic + if compName[0] == 'u' or compName[0] == 'U': # Find the component from the circuit - index=schematicInfo.index(compline) - compType=words[len(words)-1]; + index = schematicInfo.index(compline) + compType = words[len(words) - 1] schematicInfo.remove(compline) paramDict = {} - #e.g compLine : u1 1 2 gain - #compType : gain - #compName : u1 - #print "Compline",compline + # e.g compLine : u1 1 2 gain + # compType : gain + # compName : u1 + #print "Compline",compline #print "CompType",compType #print "Words",words #print "compName",compName - #Looking if model file is present + # Looking if model file is present if compType != "port" and compType != "ic" and compType not in plotList and compType != 'transfo': - xmlfile = compType+".xml" #XML Model File - count = 0 #Check if model of same name is present + xmlfile = compType + ".xml" # XML Model File + count = 0 # Check if model of same name is present modelPath = [] - all_dir = [x[0] for x in os.walk(PrcocessNetlist.modelxmlDIR)] + all_dir = [x[0] + for x in os.walk(PrcocessNetlist.modelxmlDIR)] for each_dir in all_dir: all_file = os.listdir(each_dir) if xmlfile in all_file: count += 1 - modelPath.append(os.path.join(each_dir,xmlfile)) - + modelPath.append(os.path.join(each_dir, xmlfile)) + if count > 1: multipleModelList.append(modelPath) elif count == 0: unknownModelList.append(compType) elif count == 1: try: - print("Start Parsing Previous Values XML for ngspice model :",modelPath) + print( + "Start Parsing Previous Values XML for ngspice model :", modelPath) tree = ET.parse(modelPath[0]) - + root = tree.getroot() - #Getting number of nodes for model and title + # Getting number of nodes for model and title for child in tree.iter(): if child.tag == 'node_number': num_of_nodes = int(child.text) elif child.tag == 'title': - title = child.text+" "+compName + title = child.text + " " + compName elif child.tag == 'name': modelname = child.text elif child.tag == 'type': - #Checking for Analog and Digital + # Checking for Analog and Digital type = child.text elif child.tag == 'split': splitDetail = child.text - - + for param in tree.findall('param'): for item in param: #print "Tags ",item.tag @@ -226,155 +249,173 @@ class PrcocessNetlist: #print "Tag having vector attribute",item.tag,item.attrib['vector'] temp_count = 1 temp_list = [] - for i in range(0,int(item.attrib['vector'])): - temp_list.append(item.text+" "+str(temp_count)) + for i in range(0, int( + item.attrib['vector'])): + temp_list.append( + item.text + " " + str(temp_count)) temp_count += 1 if 'default' in item.attrib: - paramDict[item.tag+":"+item.attrib['default']] = temp_list + paramDict[item.tag + ":" + + item.attrib['default']] = temp_list else: paramDict[item.tag] = item.text - + else: if 'default' in item.attrib: - paramDict[item.tag+":"+item.attrib['default']] = item.text + paramDict[item.tag + ":" + + item.attrib['default']] = item.text else: paramDict[item.tag] = item.text - - + #print "Number of Nodes : ",num_of_nodes #print "Title : ",title #print "Parameters",paramDict - #Creating line for adding model line in schematic + # Creating line for adding model line in schematic if splitDetail == 'None': - modelLine = "a"+str(k)+" " - for i in range(1,num_of_nodes+1): - modelLine += words[i]+" " + modelLine = "a" + str(k) + " " + for i in range(1, num_of_nodes + 1): + modelLine += words[i] + " " modelLine += compName - + else: - print("Split Details :",splitDetail) - modelLine = "a"+str(k)+" " + print("Split Details :", splitDetail) + modelLine = "a" + str(k) + " " vectorDetail = splitDetail.split(':') #print "Vector Details",vectorDetail - pos = 1 #Node position + pos = 1 # Node position for item in vectorDetail: try: if item.split("-")[1] == 'V': #print "Vector" if compType == "aswitch": modelLine += "(" - for i in range(0,int(item.split("-")[0])): - modelLine += words[pos]+" " + for i in range(0, int( + item.split("-")[0])): + modelLine += words[pos] + " " pos += 1 modelLine += ") " else: modelLine += "[" - for i in range(0,int(item.split("-")[0])): - modelLine += words[pos]+" " + for i in range(0, int( + item.split("-")[0])): + modelLine += words[pos] + " " pos += 1 - modelLine += "] " + modelLine += "] " elif item.split("-")[1] == 'NV': - #print "Non Vector" - for i in range(0,int(item.split("-")[0])): - modelLine += words[pos]+" " + #print "Non Vector" + for i in range(0, int( + item.split("-")[0])): + modelLine += words[pos] + " " pos += 1 - - except: - print("There is error while processing Vector Details") + + except BaseException: + print( + "There is error while processing Vector Details") sys.exit(2) - modelLine += compName - + modelLine += compName + #print "Final Model Line :",modelLine try: schematicInfo.append(modelLine) - k=k+1 + k = k + 1 except Exception as e: - print("Error while appending ModelLine ",modelLine) - print("Exception Message : ",str(e)) - #Insert comment at remove line - schematicInfo.insert(index,"* "+compline) - comment = "* Schematic Name: "+compType+", NgSpice Name: "+modelname - #Here instead of adding compType(use for XML), added modelName(Unique Model Name) - modelList.append([index,compline,modelname,compName,comment,title,type,paramDict]) + print( + "Error while appending ModelLine ", modelLine) + print("Exception Message : ", str(e)) + # Insert comment at remove line + schematicInfo.insert(index, "* " + compline) + comment = "* Schematic Name: " + compType + ", NgSpice Name: " + modelname + # Here instead of adding compType(use for XML), + # added modelName(Unique Model Name) + modelList.append( + [index, compline, modelname, compName, comment, title, type, paramDict]) except Exception as e: - print("Unable to parse the model, Please check your your XML file") - print("Exception Message : ",str(e)) + print( + "Unable to parse the model, Please check your your XML file") + print("Exception Message : ", str(e)) sys.exit(2) elif compType == "ic": - schematicInfo.insert(index,"* "+compline) + schematicInfo.insert(index, "* " + compline) modelname = "ic" - comment = "* "+compline - title = "Initial Condition for "+compName - type = "NA" #Its is not model - text = "Enter initial voltage at node for "+compline + comment = "* " + compline + title = "Initial Condition for " + compName + type = "NA" # Its is not model + text = "Enter initial voltage at node for " + compline paramDict[title] = text - modelList.append([index,compline,modelname,compName,comment,title,type,paramDict]) - + modelList.append( + [index, compline, modelname, compName, comment, title, type, paramDict]) + elif compType in plotList: - schematicInfo.insert(index,"* "+compline) + schematicInfo.insert(index, "* " + compline) if compType == 'plot_v1': words = compline.split() - plotText.append("plot v("+words[1]+")") + plotText.append("plot v(" + words[1] + ")") elif compType == 'plot_v2': words = compline.split() - plotText.append("plot v("+words[1]+","+words[2]+")") + plotText.append( + "plot v(" + words[1] + "," + words[2] + ")") elif compType == 'plot_i2': words = compline.split() - #Adding zero voltage source to netlist - schematicInfo.append("v_"+words[0]+" "+words[1]+" "+words[2]+" "+"0") - plotText.append("plot i(v_"+words[0]+")") + # Adding zero voltage source to netlist + schematicInfo.append( + "v_" + words[0] + " " + words[1] + " " + words[2] + " " + "0") + plotText.append("plot i(v_" + words[0] + ")") elif compType == 'plot_log': words = compline.split() - plotText.append("plot log("+words[1]+")") + plotText.append("plot log(" + words[1] + ")") elif compType == 'plot_db': words = compline.split() - plotText.append("plot db("+words[1]+")") + plotText.append("plot db(" + words[1] + ")") elif compType == 'plot_phase': words = compline.split() - plotText.append("plot phase("+words[1]+")") - + plotText.append("plot phase(" + words[1] + ")") + elif compType == 'transfo': - schematicInfo.insert(index,"* "+compline) - - #For Primary Couple - modelLine = "a"+str(k)+" ("+words[1]+" "+words[2]+") (interNode_"+str(interMediateNodeCount)+" "+words[3]+") " - modelLine += compName+"_primary" + schematicInfo.insert(index, "* " + compline) + + # For Primary Couple + modelLine = "a" + str(k) + " (" + words[1] + " " + words[2] + ") (interNode_" + str( + interMediateNodeCount) + " " + words[3] + ") " + modelLine += compName + "_primary" schematicInfo.append(modelLine) - k=k+1 - #For iron core - modelLine = "a"+str(k)+" ("+words[4]+" "+words[2]+") (interNode_"+str(interMediateNodeCount+1)+" "+words[3]+") " - modelLine += compName+"_secondary" + k = k + 1 + # For iron core + modelLine = "a" + str(k) + " (" + words[4] + " " + words[2] + ") (interNode_" + str( + interMediateNodeCount + 1) + " " + words[3] + ") " + modelLine += compName + "_secondary" schematicInfo.append(modelLine) - k=k+1 - #For Secondary Couple - modelLine = "a"+str(k)+" (interNode_"+str(interMediateNodeCount)+" interNode_"+str(interMediateNodeCount+1)+") " - modelLine += compName+"_iron_core" + k = k + 1 + # For Secondary Couple + modelLine = "a" + str(k) + " (interNode_" + str( + interMediateNodeCount) + " interNode_" + str(interMediateNodeCount + 1) + ") " + modelLine += compName + "_iron_core" schematicInfo.append(modelLine) - k=k+1 + k = k + 1 interMediateNodeCount += 2 - + modelname = "transfo" - comment = "* "+compline - title = "Transformer details for model "+compName - type = "NA" #It is model but do not load from xml and lib file + comment = "* " + compline + title = "Transformer details for model " + compName + type = "NA" # It is model but do not load from xml and lib file paramDict['h1_array'] = "Enter the H1 array " paramDict['primary_turns'] = "Enter the primary number of turns (default=310) " paramDict['area'] = "Enter iron core area (default=1)" paramDict['secondar_turns'] = "Enter the secondary number of turns (default=620)" paramDict['length'] = "Enter iron core length (default=0.01)" paramDict['b1_array'] = "Enter the B1 array " - - - modelList.append([index,compline,modelname,compName,comment,title,type,paramDict]) - + + modelList.append( + [index, compline, modelname, compName, comment, title, type, paramDict]) + else: - schematicInfo.insert(index,"* "+compline) - - print("UnknownModelList Used in the Schematic",unknownModelList) - print("Multiple Model XML file with same name ",multipleModelList) - print("Model List Details : ",modelList) - - return schematicInfo,outputOption,modelList,unknownModelList,multipleModelList,plotText - - - + schematicInfo.insert(index, "* " + compline) + + print( + "UnknownModelList Used in the Schematic", + unknownModelList) + print( + "Multiple Model XML file with same name ", + multipleModelList) + print("Model List Details : ", modelList) + + return schematicInfo, outputOption, modelList, unknownModelList, multipleModelList, plotText diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py index 91ee8d43..613b7b36 100644 --- a/src/kicadtoNgspice/Source.py +++ b/src/kicadtoNgspice/Source.py @@ -4,52 +4,56 @@ from . import TrackWidget #from xml.etree import ElementTree as ET import json + class Source(QtGui.QWidget): """ This class create Source Tab of KicadtoNgSpice Window. """ - - def __init__(self,sourcelist,sourcelisttrack,clarg1): + + def __init__(self, sourcelist, sourcelisttrack, clarg1): QtGui.QWidget.__init__(self) - self.obj_track = TrackWidget.TrackWidget() - #Variable + self.obj_track = TrackWidget.TrackWidget() + # Variable self.count = 1 - self.clarg1=clarg1 + self.clarg1 = clarg1 self.start = 0 self.end = 0 self.row = 0 self.entry_var = {} #self.font = QtGui.QFont("Times",20,QtGui.QFont.Bold,True) - - #Creating Source Widget - self.createSourceWidget(sourcelist,sourcelisttrack) - - - - def createSourceWidget(self,sourcelist,sourcelisttrack): + + # Creating Source Widget + self.createSourceWidget(sourcelist, sourcelisttrack) + + def createSourceWidget(self, sourcelist, sourcelisttrack): """ This function dynamically create source widget in the Source tab of KicadtoNgSpice window """ kicadFile = self.clarg1 - (projpath,filename) = os.path.split(kicadFile) + (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) try: - f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + f = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'r') data = f.read() json_data = json.loads(data) - except: + except BaseException: print("Source Previous Values JSON is Empty") - + self.grid = QtGui.QGridLayout() self.setLayout(self.grid) - + if sourcelist: for line in sourcelist: #print "Voltage source line index: ",line[0] - print("SourceList line: ",line) - track_id=line[0] + print("SourceList line: ", line) + track_id = line[0] #print "track_id is ",track_id if line[2] == 'ac': acbox = QtGui.QGroupBox() @@ -69,7 +73,8 @@ class Source(QtGui.QWidget): self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) - acgrid.addWidget(self.entry_var[self.count], self.row + 1, 1) + acgrid.addWidget( + self.entry_var[self.count], self.row + 1, 1) self.entry_var[self.count].setText("") self.count += 1 @@ -77,30 +82,32 @@ class Source(QtGui.QWidget): for key in json_data["source"]: templist1 = line[1] templist2 = templist1.split(' ') - - if key==templist2[0] and json_data["source"][key]["type"]==line[2]: - self.entry_var[self.count-2].setText(str(json_data["source"][key]["values"][0]["Amplitude"])) - self.entry_var[self.count-1].setText(str(json_data["source"][key]["values"][1]["Phase"])) - except: + if key == templist2[0] and json_data["source"][key]["type"] == line[2]: + self.entry_var[self.count - 2].setText( + str(json_data["source"][key]["values"][0]["Amplitude"])) + self.entry_var[self.count - 1].setText( + str(json_data["source"][key]["values"][1]["Phase"])) + + except BaseException: pass - #Value Need to check previuouse value - #self.entry_var[self.count].setText("") + # Value Need to check previuouse value + # self.entry_var[self.count].setText("") self.row = self.row + 1 self.end = self.count + 1 self.count = self.count + 1 acbox.setLayout(acgrid) - - #CSS + + # CSS acbox.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(acbox) - sourcelisttrack.append([track_id, 'ac', self.start, self.end]) - - + sourcelisttrack.append( + [track_id, 'ac', self.start, self.end]) + elif line[2] == 'dc': dcbox = QtGui.QGroupBox() dcbox.setTitle(line[3]) @@ -120,38 +127,41 @@ class Source(QtGui.QWidget): templist2 = templist1.split(' ') if key == templist2[0] and json_data["source"][key]["type"] == line[2]: - self.entry_var[self.count].setText(str(json_data["source"][key]["values"][0]["Value"])) + self.entry_var[self.count].setText( + str(json_data["source"][key]["values"][0]["Value"])) - except: + except BaseException: pass - + self.row = self.row + 1 self.end = self.count self.count = self.count + 1 dcbox.setLayout(dcgrid) - - #CSS + + # CSS dcbox.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(dcbox) - sourcelisttrack.append([track_id, 'dc', self.start, self.end]) - + sourcelisttrack.append( + [track_id, 'dc', self.start, self.end]) + elif line[2] == 'sine': sinebox = QtGui.QGroupBox() sinebox.setTitle(line[3]) sinegrid = QtGui.QGridLayout() - self.row = self.row+1 + self.row = self.row + 1 self.start = self.count - + for it in range(4, 9): label = QtGui.QLabel(line[it]) sinegrid.addWidget(label, self.row, 0) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) - sinegrid.addWidget(self.entry_var[self.count], self.row, 1) + sinegrid.addWidget( + self.entry_var[self.count], self.row, 1) self.entry_var[self.count].setText("") try: @@ -159,25 +169,26 @@ class Source(QtGui.QWidget): templist1 = line[1] templist2 = templist1.split(' ') if key == templist2[0] and json_data["source"][key]["type"] == line[2]: - self.entry_var[self.count].setText(str(list(json_data["source"][key]["values"][it-4].values())[0])) - except: + self.entry_var[self.count].setText( + str(list(json_data["source"][key]["values"][it - 4].values())[0])) + except BaseException: pass - - + self.row = self.row + 1 - self.count = self.count + 1 + self.count = self.count + 1 self.end = self.count - 1 sinebox.setLayout(sinegrid) - - #CSS + + # CSS sinebox.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(sinebox) - sourcelisttrack.append([track_id, 'sine', self.start, self.end]) - + sourcelisttrack.append( + [track_id, 'sine', self.start, self.end]) + elif line[2] == 'pulse': pulsebox = QtGui.QGroupBox() pulsebox.setTitle(line[3]) @@ -189,33 +200,36 @@ class Source(QtGui.QWidget): pulsegrid.addWidget(label, self.row, 0) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) - pulsegrid.addWidget(self.entry_var[self.count], self.row, 1) + pulsegrid.addWidget( + self.entry_var[self.count], self.row, 1) self.entry_var[self.count].setText("") - + try: for key in json_data["source"]: templist1 = line[1] templist2 = templist1.split(' ') if key == templist2[0] and json_data["source"][key]["type"] == line[2]: - self.entry_var[self.count].setText(str(list(json_data["source"][key]["values"][it-4].values())[0])) - except: + self.entry_var[self.count].setText( + str(list(json_data["source"][key]["values"][it - 4].values())[0])) + except BaseException: pass - + self.row = self.row + 1 self.count = self.count + 1 self.end = self.count - 1 pulsebox.setLayout(pulsegrid) - - #CSS + + # CSS pulsebox.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(pulsebox) - sourcelisttrack.append([track_id, 'pulse', self.start, self.end]) - + sourcelisttrack.append( + [track_id, 'pulse', self.start, self.end]) + elif line[2] == 'pwl': pwlbox = QtGui.QGroupBox() pwlbox.setTitle(line[3]) @@ -227,81 +241,76 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setMaximumWidth(150) pwlgrid.addWidget(self.entry_var[self.count], self.row, 1) self.entry_var[self.count].setText("") - + try: for key in json_data["source"]: templist1 = line[1] templist2 = templist1.split(' ') if key == templist2[0] and json_data["source"][key]["type"] == line[2]: - self.entry_var[self.count].setText(str(json_data["source"][key]["values"][0]["Enter in pwl format"])) - except: + self.entry_var[self.count].setText( + str(json_data["source"][key]["values"][0]["Enter in pwl format"])) + except BaseException: pass - - + self.row = self.row + 1 self.end = self.count self.count = self.count + 1 pwlbox.setLayout(pwlgrid) - - #CSS + + # CSS pwlbox.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(pwlbox) - sourcelisttrack.append([track_id, 'pwl', self.start, self.end]) - + sourcelisttrack.append( + [track_id, 'pwl', self.start, self.end]) + elif line[2] == 'exp': expbox = QtGui.QGroupBox() expbox.setTitle(line[3]) expgrid = QtGui.QGridLayout() self.start = self.count - for it in range(4,10): + for it in range(4, 10): label = QtGui.QLabel(line[it]) expgrid.addWidget(label, self.row, 0) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) - expgrid.addWidget(self.entry_var[self.count], self.row, 1) + expgrid.addWidget( + self.entry_var[self.count], self.row, 1) self.entry_var[self.count].setText("") - + try: for key in json_data["source"]: templist1 = line[1] templist2 = templist1.split(' ') if key == templist2[0] and json_data["source"][key]["type"] == line[2]: - self.entry_var[self.count].setText(str(list(json_data["source"][key]["values"][it-4].values())[0])) - except: + self.entry_var[self.count].setText( + str(list(json_data["source"][key]["values"][it - 4].values())[0])) + except BaseException: pass - - + self.row = self.row + 1 self.count = self.count + 1 self.end = self.count - 1 expbox.setLayout(expgrid) - - #CSS + + # CSS expbox.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(expbox) - sourcelisttrack.append([track_id, 'exp', self.start, self.end]) - + sourcelisttrack.append( + [track_id, 'exp', self.start, self.end]) + else: print("No source is present in your circuit") - - - #This is used to keep the track of dynamically created widget + + # This is used to keep the track of dynamically created widget self.obj_track.sourcelisttrack["ITEMS"] = sourcelisttrack self.obj_track.source_entry_var["ITEMS"] = self.entry_var self.show() - - - - - - - diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py index 7a4469df..249b636b 100644 --- a/src/kicadtoNgspice/SubcircuitTab.py +++ b/src/kicadtoNgspice/SubcircuitTab.py @@ -5,56 +5,62 @@ from projManagement import Validation import os #from xml.etree import ElementTree as ET + class SubcircuitTab(QtGui.QWidget): """ This class creates Subcircuit Tab in KicadtoNgspice Window It dynamically creates the widget for subcircuits. """ - + def __init__(self, schematicInfo, clarg1): kicadFile = clarg1 - (projpath,filename) = os.path.split(kicadFile) + (projpath, filename) = os.path.split(kicadFile) project_name = os.path.basename(projpath) try: - f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + f = open( + os.path.join( + projpath, + project_name + + "_Previous_Values.json"), + 'r') data = f.read() json_data = json.loads(data) - except: + except BaseException: print("Subcircuit Previous values JSON is Empty") QtGui.QWidget.__init__(self) - - #Creating track widget object + + # Creating track widget object self.obj_trac = TrackWidget.TrackWidget() - - #Creating validation object + + # Creating validation object self.obj_validation = Validation.Validation() - #Row and column count + # Row and column count self.row = 0 - self.count = 1 #Entry count + self.count = 1 # Entry count self.entry_var = {} - self.subcircuit_dict_beg = {} - self.subcircuit_dict_end = {} - #List to hold information about subcircuit + self.subcircuit_dict_beg = {} + self.subcircuit_dict_end = {} + # List to hold information about subcircuit self.subDetail = {} - - #Stores the number of ports in each subcircuit + + # Stores the number of ports in each subcircuit self.numPorts = [] - - #Set Layout + + # Set Layout self.grid = QtGui.QGridLayout() self.setLayout(self.grid) - + for eachline in schematicInfo: words = eachline.split() if eachline[0] == 'x': - print("Subcircuit : Words",words[0]) - self.obj_trac.subcircuitList[project_name+words[0]] = words + print(("Subcircuit : Words", words[0])) + self.obj_trac.subcircuitList[project_name + words[0]] = words self.subcircuit_dict_beg[words[0]] = self.count subbox = QtGui.QGroupBox() subgrid = QtGui.QGridLayout() - subbox.setTitle("Add subcircuit for "+words[len(words)-1]) + subbox.setTitle("Add subcircuit for " + words[len(words) - 1]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") @@ -64,40 +70,42 @@ class SubcircuitTab(QtGui.QWidget): if key[0] == eachline[0] and key[1] == eachline[1]: #print "Subcircuit MATCHING---",child.tag[0], child.tag[1], eachline[0], eachline[1] try: - if os.path.exists(json_data["subcircuit"][key][0]): - self.entry_var[self.count].setText(json_data["subcircuit"][key][0]) + if os.path.exists( + json_data["subcircuit"][key][0]): + self.entry_var[self.count].setText( + json_data["subcircuit"][key][0]) path_name = json_data["subcircuit"][key][0] else: self.entry_var[self.count].setText("") - except: + except BaseException: print("Error when set text of subcircuit") - except: + except BaseException: print("Error before subcircuit") - subgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") - self.addbtn.setObjectName("%d" %self.count) - #Send the number of ports specified with the given subcircuit for verification. - #eg. If the line is 'x1 4 0 3 ua741', there are 3 ports(4, 0 and 3). - self.numPorts.append(len(words)-2) - print("Number of ports of sub circuit : ",self.numPorts) + self.addbtn.setObjectName("%d" % self.count) + # Send the number of ports specified with the given subcircuit for verification. + # eg. If the line is 'x1 4 0 3 ua741', there are 3 ports(4, 0 + # and 3). + self.numPorts.append(len(words) - 2) + print(("Number of ports of sub circuit : ", self.numPorts)) self.addbtn.clicked.connect(self.trackSubcircuit) subgrid.addWidget(self.addbtn, self.row, 2) subbox.setLayout(subgrid) - - #CSS + + # CSS subbox.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(subbox) - - #Adding Subcircuit Details + + # Adding Subcircuit Details self.subDetail[self.count] = words[0] - - #Increment row and widget count + + # Increment row and widget count if self.entry_var[self.count].text() == "": pass @@ -107,10 +115,9 @@ class SubcircuitTab(QtGui.QWidget): self.subcircuit_dict_end[words[0]] = self.count self.row = self.row + 1 self.count = self.count + 1 - + self.show() - - + def trackSubcircuit(self): """ This function is use to keep track of all Subcircuit widget @@ -118,49 +125,59 @@ class SubcircuitTab(QtGui.QWidget): sending_btn = self.sender() #print "Object Called is ",sending_btn.objectName() self.widgetObjCount = int(sending_btn.objectName()) - - self.subfile = str(QtGui.QFileDialog.getExistingDirectory(self,"Open Subcircuit","../SubcircuitLibrary")) - self.reply = self.obj_validation.validateSub(self.subfile,self.numPorts[self.widgetObjCount - 1]) + + self.subfile = str( + QtGui.QFileDialog.getExistingDirectory( + self, + "Open Subcircuit", + "../SubcircuitLibrary")) + self.reply = self.obj_validation.validateSub( + self.subfile, self.numPorts[self.widgetObjCount - 1]) if self.reply == "True": - #Setting Library to Text Edit Line + # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.subfile) self.subName = self.subDetail[self.widgetObjCount] - - #Storing to track it during conversion - + + # Storing to track it during conversion + self.obj_trac.subcircuitTrack[self.subName] = self.subfile elif self.reply == "PORT": self.msg = QtGui.QErrorMessage(self) - self.msg.showMessage("Please select a Subcircuit with correct number of ports.") + self.msg.showMessage( + "Please select a Subcircuit with correct number of ports.") self.msg.setWindowTitle("Error Message") self.msg.show() elif self.reply == "DIREC": self.msg = QtGui.QErrorMessage(self) - self.msg.showMessage("Please select a valid Subcircuit directory (Containing '.sub' file).") + self.msg.showMessage( + "Please select a valid Subcircuit directory (Containing '.sub' file).") self.msg.setWindowTitle("Error Message") self.msg.show() - def trackSubcircuitWithoutButton(self,iter_value,path_value): - + def trackSubcircuitWithoutButton(self, iter_value, path_value): + self.widgetObjCount = iter_value - + self.subfile = path_value - self.reply = self.obj_validation.validateSub(self.subfile,self.numPorts[self.widgetObjCount - 1]) + self.reply = self.obj_validation.validateSub( + self.subfile, self.numPorts[self.widgetObjCount - 1]) if self.reply == "True": - #Setting Library to Text Edit Line + # Setting Library to Text Edit Line self.entry_var[self.widgetObjCount].setText(self.subfile) self.subName = self.subDetail[self.widgetObjCount] - - #Storing to track it during conversion - + + # Storing to track it during conversion + self.obj_trac.subcircuitTrack[self.subName] = self.subfile elif self.reply == "PORT": self.msg = QtGui.QErrorMessage(self) - self.msg.showMessage("Please select a Subcircuit with correct number of ports.") + self.msg.showMessage( + "Please select a Subcircuit with correct number of ports.") self.msg.setWindowTitle("Error Message") self.msg.show() elif self.reply == "DIREC": self.msg = QtGui.QErrorMessage(self) - self.msg.showMessage("Please select a valid Subcircuit directory (Containing '.sub' file).") + self.msg.showMessage( + "Please select a valid Subcircuit directory (Containing '.sub' file).") self.msg.setWindowTitle("Error Message") self.msg.show()
\ No newline at end of file diff --git a/src/kicadtoNgspice/TrackWidget.py b/src/kicadtoNgspice/TrackWidget.py index 56e84ce3..dcf85dca 100644 --- a/src/kicadtoNgspice/TrackWidget.py +++ b/src/kicadtoNgspice/TrackWidget.py @@ -2,28 +2,28 @@ class TrackWidget: """ This Class track the dynamically created widget of KicadtoNgSpice Window. """ - #Track widget list for Source details - sourcelisttrack = {"ITEMS":"None"} - source_entry_var = {"ITEMS":"None"} - - #Track widget for analysis inserter details - AC_entry_var = {"ITEMS":"None"} - AC_Parameter = {"ITEMS":"None"} - DC_entry_var = {"ITEMS":"None"} - DC_Parameter = {"ITEMS":"None"} - TRAN_entry_var = {"ITEMS":"None"} - TRAN_Parameter = {"ITEMS":"None"} - set_CheckBox = {"ITEMS":"None"} - AC_type = {"ITEMS":"None"} + # Track widget list for Source details + sourcelisttrack = {"ITEMS": "None"} + source_entry_var = {"ITEMS": "None"} + + # Track widget for analysis inserter details + AC_entry_var = {"ITEMS": "None"} + AC_Parameter = {"ITEMS": "None"} + DC_entry_var = {"ITEMS": "None"} + DC_Parameter = {"ITEMS": "None"} + TRAN_entry_var = {"ITEMS": "None"} + TRAN_Parameter = {"ITEMS": "None"} + set_CheckBox = {"ITEMS": "None"} + AC_type = {"ITEMS": "None"} op_check = [] - #Track widget for Model detail + # Track widget for Model detail modelTrack = [] model_entry_var = {} - - #Track Widget for Device Model detail + + # Track Widget for Device Model detail deviceModelTrack = {} - - #Track Widget for Subcircuits where directory has been selected + + # Track Widget for Subcircuits where directory has been selected subcircuitTrack = {} - #Track subcircuits which are specified in .cir file - subcircuitList = {}
\ No newline at end of file + # Track subcircuits which are specified in .cir file + subcircuitList = {} |