diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/kicadtoNgspice/Analysis.py | 526 | ||||
-rw-r--r-- | src/kicadtoNgspice/DeviceModel.py | 190 | ||||
-rw-r--r-- | src/kicadtoNgspice/KicadtoNgspice.py | 452 | ||||
-rw-r--r-- | src/kicadtoNgspice/Model.py | 85 | ||||
-rw-r--r-- | src/kicadtoNgspice/Source.py | 268 | ||||
-rw-r--r-- | src/kicadtoNgspice/SubcircuitTab.py | 62 |
6 files changed, 804 insertions, 779 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py index a573c540..b9fbb006 100644 --- a/src/kicadtoNgspice/Analysis.py +++ b/src/kicadtoNgspice/Analysis.py @@ -2,75 +2,76 @@ from PyQt4 import QtGui import TrackWidget import os -from xml.etree import ElementTree as ET +#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): - self.clarg1=clarg1 + self.clarg1 = clarg1 QtGui.QWidget.__init__(self) - self.track_obj= TrackWidget.TrackWidget() - self.count =0 - self.parameter_cnt=0 - self.ac_entry_var={} - self.dc_entry_var={} - self.tran_entry_var={} - self.ac_parameter={} - self.dc_parameter={} - self.tran_parameter= {} + self.track_obj = TrackWidget.TrackWidget() + self.count = 0 + self.parameter_cnt = 0 + self.ac_entry_var = {} + self.dc_entry_var = {} + self.tran_entry_var = {} + self.ac_parameter = {} + 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) + 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')) content = analysisfile.readline() print "Content of Analysis file :", content - contentlist= content.split() - if contentlist[0]== '.ac': + contentlist= content.split() + + if contentlist[0] == '.ac': self.checkAC.setChecked(True) self.acbox.setDisabled(False) self.dcbox.setDisabled(True) self.trbox.setDisabled(True) - self.track_obj.set_CheckBox["ITEMS"]="AC" - if contentlist[1]== 'lin': + self.track_obj.set_CheckBox["ITEMS"] = "AC" + if contentlist[1] == 'lin': self.Lin.setChecked(True) - self.track_obj.AC_type["ITEMS"]="lin" - elif contentlist[1]== 'dec': + self.track_obj.AC_type["ITEMS"] = "lin" + elif contentlist[1] == 'dec': self.Dec.setChecked(True) - self.track_obj.AC_type["ITEMS"]="dec" - elif contentlist[1]== 'oct': + self.track_obj.AC_type["ITEMS"] = "dec" + elif contentlist[1] == 'oct': self.Oct.setChecked(True) - self.track_obj.AC_type["ITEMS"]="oct" + self.track_obj.AC_type["ITEMS"] = "oct" - elif contentlist[0]== '.dc': + 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': + 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" + self.track_obj.set_CheckBox["ITEMS"] = "TRAN" - elif contentlist[0]== '.op': + elif contentlist[0] == '.op': self.checkDC.setChecked(True) self.dcbox.setDisabled(False) self.acbox.setDisabled(True) @@ -78,7 +79,7 @@ class Analysis(QtGui.QWidget): self.check.setChecked(True) except: self.checkTRAN.setChecked(True) - self.track_obj.set_CheckBox["ITEMS"]="TRAN" + self.track_obj.set_CheckBox["ITEMS"] = "TRAN" self.setLayout(self.grid) self.show() @@ -92,54 +93,52 @@ class Analysis(QtGui.QWidget): self.checkAC = QtGui.QCheckBox("AC") self.checkDC = QtGui.QCheckBox("DC") self.checkTRAN = QtGui.QCheckBox("TRANSIENT") + self.checkgroupbtn.addButton(self.checkAC) self.checkgroupbtn.addButton(self.checkDC) 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.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" + 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" + 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" + self.track_obj.set_CheckBox["ITEMS"] = "TRAN" def createACgroup(self): kicadFile = self.clarg1 - (projpath,filename)=os.path.split(kicadFile) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + check = 1 + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="analysis": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) except: - check=0 - print "AC Previous Values XML is Empty" + check = 0 + print "AC Previous Values JSON is Empty" self.acbox = QtGui.QGroupBox() self.acbox.setTitle("AC Analysis") @@ -156,34 +155,34 @@ class Analysis(QtGui.QWidget): self.Lin.setChecked(True) 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.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") self.no_of_points = QtGui.QLabel("No.of Points") - self.acgrid.addWidget(self.scale,1,0) - 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.acgrid.addWidget(self.scale, 1, 0) + 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.count = 0 self.ac_entry_var[self.count] = QtGui.QLineEdit()#start - self.acgrid.addWidget(self.ac_entry_var[self.count],2,1) + 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.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.acgrid.addWidget(self.ac_entry_var[self.count], 3, 1) self.ac_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + 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.acgrid.addWidget(self.ac_entry_var[self.count], 4, 1) self.ac_entry_var[self.count].setMaximumWidth(150) - self.parameter_cnt=0 + self.parameter_cnt = 0 self.start_fre_combo = QtGui.QComboBox() self.start_fre_combo.addItem("Hz",) self.start_fre_combo.addItem("KHz") @@ -191,15 +190,17 @@ class Analysis(QtGui.QWidget): self.start_fre_combo.addItem("GHz") self.start_fre_combo.addItem("THz") self.start_fre_combo.setMaximumWidth(150) - self.acgrid.addWidget(self.start_fre_combo,2,2) - self.ac_parameter[0]= "Hz" + self.acgrid.addWidget(self.start_fre_combo, 2, 2) + self.ac_parameter[0] = "Hz" + try: - self.ac_parameter[self.parameter_cnt]= str(root[0][6].text) + self.ac_parameter[self.parameter_cnt] = str(json_data["analysis"]["ac"]["Start Fre Combo"]) except: - self.ac_parameter[self.parameter_cnt]= "Hz" + 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.parameter_cnt = self.parameter_cnt + 1 self.stop_fre_combo = QtGui.QComboBox() self.stop_fre_combo.addItem("Hz") self.stop_fre_combo.addItem("KHz") @@ -207,17 +208,18 @@ class Analysis(QtGui.QWidget): self.stop_fre_combo.addItem("GHz") self.stop_fre_combo.addItem("THz") self.stop_fre_combo.setMaximumWidth(150) - self.acgrid.addWidget(self.stop_fre_combo,3,2) - self.ac_parameter[1]= "Hz" + self.acgrid.addWidget(self.stop_fre_combo, 3, 2) + self.ac_parameter[1] = "Hz" + try: - self.ac_parameter[self.parameter_cnt]= str(root[0][7].text) + self.ac_parameter[self.parameter_cnt] = str(json_data["analysis"]["ac"]["Stop Fre Combo"]) except: - self.ac_parameter[self.parameter_cnt]= "Hz" + 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 + self.track_obj.AC_entry_var["ITEMS"] = self.ac_entry_var + self.track_obj.AC_Parameter["ITEMS"] = self.ac_parameter #CSS self.acbox.setStyleSheet(" \ @@ -226,64 +228,65 @@ class Analysis(QtGui.QWidget): ") if check: try: - if root[0][0].text=="true": + if json_data["analysis"]["ac"]["Lin"] == "true": self.Lin.setChecked(True) self.Dec.setChecked(False) self.Oct.setChecked(False) - elif root[0][1].text=="true": + elif json_data["analysis"]["ac"]["Dec"] == "true": self.Lin.setChecked(False) self.Dec.setChecked(True) self.Oct.setChecked(False) - elif root[0][2].text=="true": + elif json_data["analysis"]["ac"]["Oct"] == "true": self.Lin.setChecked(False) self.Dec.setChecked(False) self.Oct.setChecked(True) else: pass - self.ac_entry_var[0].setText(root[0][3].text) - self.ac_entry_var[1].setText(root[0][4].text) - self.ac_entry_var[2].setText(root[0][5].text) - index=self.start_fre_combo.findText(root[0][6].text) + + 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(root[0][7].text) + index = self.stop_fre_combo.findText(json_data["analysis"]["ac"]["Stop Fre Combo"]) self.stop_fre_combo.setCurrentIndex(index) + except: - print "AC Analysis XML Parse Error" + print "AC Analysis JSON Parse Error" return self.acbox def start_combovalue(self, text): - self.ac_parameter[0]= str(text) + self.ac_parameter[0] = str(text) def stop_combovalue(self, text): - self.ac_parameter[1]= str(text) + self.ac_parameter[1] = str(text) def set_ac_type(self): - self.parameter_cnt=0 + self.parameter_cnt = 0 + if self.Lin.isChecked(): - self.track_obj.AC_type["ITEMS"]="lin" + 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" + self.track_obj.AC_type["ITEMS"] = "oct" else: pass def createDCgroup(self): kicadFile = self.clarg1 - (projpath,filename)=os.path.split(kicadFile) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + check = 1 + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="analysis": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) except: - check=0 - print "DC Previous Values XML is empty" + check = 0 + print "DC Previous Values JSON is empty" self.dcbox = QtGui.QGroupBox() self.dcbox.setTitle("DC Analysis") @@ -291,83 +294,92 @@ class Analysis(QtGui.QWidget): self.dcgrid = QtGui.QGridLayout() self.dcbox.setLayout(self.dcgrid) - self.source_name= QtGui.QLabel('Enter Source 1',self) + self.source_name = QtGui.QLabel('Enter Source 1', self) self.source_name.setMaximumWidth(150) - self.start= QtGui.QLabel('Start', self) + self.start = QtGui.QLabel('Start', self) self.start.setMaximumWidth(150) - self.increment=QtGui.QLabel('Increment',self) + 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 = QtGui.QLabel('Enter Source 2', self) self.source_name2.setMaximumWidth(150) - self.start2= QtGui.QLabel('Start', self) + self.start2 = QtGui.QLabel('Start', self) self.start2.setMaximumWidth(150) - self.increment2=QtGui.QLabel('Increment',self) + self.increment2 = QtGui.QLabel('Increment', self) self.increment2.setMaximumWidth(150) - self.stop2=QtGui.QLabel('Stop',self) + self.stop2 = QtGui.QLabel('Stop', self) self.stop2.setMaximumWidth(150) - 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.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.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.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.count = 0 + self.dc_entry_var[self.count] = QtGui.QLineEdit()#source - self.dcgrid.addWidget(self.dc_entry_var[self.count],1,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 1, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.dc_entry_var[self.count] = QtGui.QLineEdit()#start - self.dcgrid.addWidget(self.dc_entry_var[self.count],2,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 2, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.dc_entry_var[self.count] = QtGui.QLineEdit()#increment - self.dcgrid.addWidget(self.dc_entry_var[self.count],3,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 3, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.dc_entry_var[self.count] = QtGui.QLineEdit()#stop - self.dcgrid.addWidget(self.dc_entry_var[self.count],4,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 4, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.count=self.count+1 + self.count += 1 self.dc_entry_var[self.count] = QtGui.QLineEdit()#source - self.dcgrid.addWidget(self.dc_entry_var[self.count],5,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 5, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.dc_entry_var[self.count] = QtGui.QLineEdit()#start - self.dcgrid.addWidget(self.dc_entry_var[self.count],6,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 6, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.dc_entry_var[self.count] = QtGui.QLineEdit()#increment - self.dcgrid.addWidget(self.dc_entry_var[self.count],7,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 7, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.dc_entry_var[self.count] = QtGui.QLineEdit()#stop - self.dcgrid.addWidget(self.dc_entry_var[self.count],8,1) + self.dcgrid.addWidget(self.dc_entry_var[self.count], 8, 1) self.dc_entry_var[self.count].setMaximumWidth(150) - self.parameter_cnt=0 - self.start_combo=QtGui.QComboBox(self) + self.parameter_cnt = 0 + self.start_combo = QtGui.QComboBox(self) self.start_combo.setMaximumWidth(150) self.start_combo.addItem('Volts or Amperes') self.start_combo.addItem('mV or mA') self.start_combo.addItem('uV or uA') self.start_combo.addItem("nV or nA") self.start_combo.addItem("pV or pA") - self.dcgrid.addWidget(self.start_combo,2,2) + self.dcgrid.addWidget(self.start_combo, 2, 2) + try: - self.dc_parameter[self.parameter_cnt]= str(root[1][5].text) + self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Start Combo"]) except: - self.dc_parameter[self.parameter_cnt]= "Volts or Amperes" + self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" + self.start_combo.activated[str].connect(self.start_changecombo) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 self.increment_combo=QtGui.QComboBox(self) self.increment_combo.setMaximumWidth(150) @@ -376,87 +388,96 @@ class Analysis(QtGui.QWidget): self.increment_combo.addItem("uV or uA") self.increment_combo.addItem("nV or nA") self.increment_combo.addItem("pV or pA") - self.dcgrid.addWidget(self.increment_combo,3,2) + self.dcgrid.addWidget(self.increment_combo, 3, 2) + try: - self.dc_parameter[self.parameter_cnt]= str(root[1][6].text) + self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Increment Combo"]) except: - self.dc_parameter[self.parameter_cnt]= "Volts or Amperes" + self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" + self.increment_combo.activated[str].connect(self.increment_changecombo) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 - self.stop_combo=QtGui.QComboBox(self) + 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.dcgrid.addWidget(self.stop_combo,4,2) + self.dcgrid.addWidget(self.stop_combo, 4, 2) + try: - self.dc_parameter[self.parameter_cnt]= str(root[1][7].text) + self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Stop Combo"]) except: - self.dc_parameter[self.parameter_cnt]= "Volts or Amperes" + self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" + self.stop_combo.activated[str].connect(self.stop_changecombo) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 - self.start_combo2=QtGui.QComboBox(self) + self.start_combo2 = QtGui.QComboBox(self) self.start_combo2.setMaximumWidth(150) self.start_combo2.addItem('Volts or Amperes') self.start_combo2.addItem('mV or mA') self.start_combo2.addItem('uV or uA') self.start_combo2.addItem("nV or nA") self.start_combo2.addItem("pV or pA") - self.dcgrid.addWidget(self.start_combo2,6,2) + self.dcgrid.addWidget(self.start_combo2, 6, 2) + try: - self.dc_parameter[self.parameter_cnt]= str(root[1][12].text) + self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Start Combo2"]) except: - self.dc_parameter[self.parameter_cnt]= "Volts or Amperes" + self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" + self.start_combo2.activated[str].connect(self.start_changecombo2) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 - self.increment_combo2=QtGui.QComboBox(self) + self.increment_combo2 = QtGui.QComboBox(self) self.increment_combo2.setMaximumWidth(150) self.increment_combo2.addItem("Volts or Amperes") self.increment_combo2.addItem("mV or mA") self.increment_combo2.addItem("uV or uA") self.increment_combo2.addItem("nV or nA") self.increment_combo2.addItem("pV or pA") - self.dcgrid.addWidget(self.increment_combo2,7,2) + self.dcgrid.addWidget(self.increment_combo2, 7, 2) + try: - self.dc_parameter[self.parameter_cnt]= str(root[1][13].text) + self.dc_parameter[self.parameter_cnt] = str(json_data["analysis"]["dc"]["Increment Combo2"]) except: - self.dc_parameter[self.parameter_cnt]= "Volts or Amperes" + self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" + self.increment_combo2.activated[str].connect(self.increment_changecombo2) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 - self.stop_combo2=QtGui.QComboBox(self) + self.stop_combo2 = QtGui.QComboBox(self) self.stop_combo2.setMaximumWidth(150) self.stop_combo2.addItem("Volts or Amperes") self.stop_combo2.addItem("mV or mA") self.stop_combo2.addItem("uV or uA") self.stop_combo2.addItem("nV or nA") self.stop_combo2.addItem("pV or pA") - self.dcgrid.addWidget(self.stop_combo2,8,2) - try: - self.dc_parameter[self.parameter_cnt]= str(root[1][14].text) + 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]= "Volts or Amperes" + self.dc_parameter[self.parameter_cnt] = "Volts or Amperes" + self.stop_combo2.activated[str].connect(self.stop_changecombo2) - self.parameter_cnt= self.parameter_cnt+1 + 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(root[1][4].text())) + self.track_obj.op_check.append(str(json_data["analysis"]["dc"]["Operating Point"])) except: self.track_obj.op_check.append(0) #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 + 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 self.dcbox.setStyleSheet(" \ @@ -465,75 +486,73 @@ class Analysis(QtGui.QWidget): ") if check: try: - self.dc_entry_var[0].setText(root[1][0].text) - self.dc_entry_var[1].setText(root[1][1].text) - self.dc_entry_var[2].setText(root[1][2].text) - self.dc_entry_var[3].setText(root[1][3].text) - index=self.start_combo.findText(root[1][5].text) + 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(root[1][6].text) + index = self.increment_combo.findText(json_data["analysis"]["dc"]["Increment Combo"]) self.increment_combo.setCurrentIndex(index) - index=self.stop_combo.findText(root[1][7].text) + index = self.stop_combo.findText(json_data["analysis"]["dc"]["Stop Combo"]) self.stop_combo.setCurrentIndex(index) - self.dc_entry_var[4].setText(root[1][8].text) - self.dc_entry_var[5].setText(root[1][9].text) - self.dc_entry_var[6].setText(root[1][10].text) - self.dc_entry_var[7].setText(root[1][11].text) - index=self.start_combo2.findText(root[1][12].text) + 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(root[1][13].text) + index = self.increment_combo2.findText(json_data["analysis"]["dc"]["Increment Combo2"]) self.increment_combo2.setCurrentIndex(index) - index=self.stop_combo2.findText(root[1][14].text) + index = self.stop_combo2.findText(json_data["analysis"]["dc"]["Stop Combo2"]) self.stop_combo2.setCurrentIndex(index) - if root[1][4].text== 1: + if json_data["analysis"]["dc"]["Operating Point"] == 1: self.check.setChecked(True) else: self.check.setChecked(False) except: - print "DC Analysis XML Parse Error" + print "DC Analysis JSON Parse Error" return self.dcbox - def start_changecombo(self,text): - self.dc_parameter[0]=str(text) + def start_changecombo(self, text): + self.dc_parameter[0] = str(text) - def increment_changecombo(self,text): - self.dc_parameter[1]=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 stop_changecombo(self, text): + self.dc_parameter[2] = str(text) - def start_changecombo2(self,text): - self.dc_parameter[3]=str(text) + def start_changecombo2(self, text): + self.dc_parameter[3] = str(text) - def increment_changecombo2(self,text): - self.dc_parameter[4]=str(text) + def increment_changecombo2(self, text): + self.dc_parameter[4] = str(text) - def stop_changecombo2(self,text): - self.dc_parameter[5]=str(text) + def stop_changecombo2(self, 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) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path .basename(projpath) + check = 1 + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="analysis": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) except: - check=0 - print "Transient Previous Values XML is Empty" + check = 0 + print "Transient Previous Values JSON is Empty" self.trbox = QtGui.QGroupBox() self.trbox.setTitle("Transient Analysis") @@ -544,38 +563,42 @@ class Analysis(QtGui.QWidget): self.start = QtGui.QLabel("Start Time") self.step = QtGui.QLabel("Step Time") self.stop = QtGui.QLabel("Stop Time") - self.trgrid.addWidget(self.start,1,0) - self.trgrid.addWidget(self.step,2,0) - self.trgrid.addWidget(self.stop,3,0) - self.count=0 + self.trgrid.addWidget(self.start, 1, 0) + 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.trgrid.addWidget(self.tran_entry_var[self.count], 1, 1) self.tran_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.tran_entry_var[self.count] = QtGui.QLineEdit() - self.trgrid.addWidget(self.tran_entry_var[self.count],2,1) + self.trgrid.addWidget(self.tran_entry_var[self.count], 2, 1) self.tran_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 + self.tran_entry_var[self.count] = QtGui.QLineEdit() - self.trgrid.addWidget(self.tran_entry_var[self.count],3,1) + self.trgrid.addWidget(self.tran_entry_var[self.count], 3, 1) self.tran_entry_var[self.count].setMaximumWidth(150) - self.count= self.count+1 + self.count += 1 - self.parameter_cnt=0 + self.parameter_cnt = 0 self.start_combobox = QtGui.QComboBox() self.start_combobox.addItem("Sec") self.start_combobox.addItem("ms") self.start_combobox.addItem("us") self.start_combobox.addItem("ns") self.start_combobox.addItem("ps") - self.trgrid.addWidget(self.start_combobox,1,3) + self.trgrid.addWidget(self.start_combobox, 1, 3) + try: - self.tran_parameter[self.parameter_cnt]= str(root[2][3].text) + self.tran_parameter[self.parameter_cnt] = str(json_data["analysis"]["tran"]["Start Combo"]) except: - self.tran_parameter[self.parameter_cnt]= "Sec" + self.tran_parameter[self.parameter_cnt] = "Sec" + self.start_combobox.activated[str].connect(self.start_combo_change) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 self.step_combobox = QtGui.QComboBox() self.step_combobox.addItem("Sec") @@ -583,13 +606,14 @@ class Analysis(QtGui.QWidget): self.step_combobox.addItem("us") self.step_combobox.addItem("ns") self.step_combobox.addItem("ps") - self.trgrid.addWidget(self.step_combobox,2,3) + self.trgrid.addWidget(self.step_combobox, 2, 3) try: - self.tran_parameter[self.parameter_cnt]= str(root[2][4].text) + self.tran_parameter[self.parameter_cnt] = str(json_data["analysis"]["tran"]["Step Combo"]) except: - self.tran_parameter[self.parameter_cnt]= "Sec" + self.tran_parameter[self.parameter_cnt] = "Sec" + self.step_combobox.activated[str].connect(self.step_combo_change) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 self.stop_combobox = QtGui.QComboBox() self.stop_combobox.addItem("Sec") @@ -597,16 +621,17 @@ class Analysis(QtGui.QWidget): self.stop_combobox.addItem("us") self.stop_combobox.addItem("ns") self.stop_combobox.addItem("ps") - self.trgrid.addWidget(self.stop_combobox,3,3) + self.trgrid.addWidget(self.stop_combobox, 3, 3) try: - self.tran_parameter[self.parameter_cnt]= str(root[2][5].text) + self.tran_parameter[self.parameter_cnt] = str(json_data["analysis"]["tran"]["Stop Combo"]) except: - self.tran_parameter[self.parameter_cnt]= "Sec" + self.tran_parameter[self.parameter_cnt] = "Sec" + self.stop_combobox.activated[str].connect(self.stop_combo_change) - self.parameter_cnt= self.parameter_cnt+1 + self.parameter_cnt += 1 - self.track_obj.TRAN_entry_var["ITEMS"]=self.tran_entry_var - self.track_obj.TRAN_Parameter["ITEMS"]=self.tran_parameter + self.track_obj.TRAN_entry_var["ITEMS"] = self.tran_entry_var + self.track_obj.TRAN_Parameter["ITEMS"] = self.tran_parameter #CSS self.trbox.setStyleSheet(" \ @@ -615,27 +640,26 @@ class Analysis(QtGui.QWidget): ") if check: try: - self.tran_entry_var[0].setText(root[2][0].text) - self.tran_entry_var[1].setText(root[2][1].text) - self.tran_entry_var[2].setText(root[2][2].text) - index=self.start_combobox.findText(root[2][3].text) + 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(root[2][4].text) + index = self.step_combobox.findText(json_data["analysis"]["tran"]["Step Combo"]) self.step_combobox.setCurrentIndex(index) - - index=self.stop_combobox.findText(root[2][5].text) + index = self.stop_combobox.findText(json_data["analysis"]["tran"]["Stop Combo"]) self.stop_combobox.setCurrentIndex(index) except: - print "Transient Analysis XML Parse Error" + print "Transient Analysis JSON Parse Error" return self.trbox - def start_combo_change(self,text): - self.tran_parameter[0]=str(text) + 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 step_combo_change(self, text): + self.tran_parameter[1] = str(text) - def stop_combo_change(self,text): - self.tran_parameter[2]=str(text) + def stop_combo_change(self, text): + self.tran_parameter[2] = str(text) diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index a982d05f..a775b8a5 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -1,7 +1,7 @@ from PyQt4 import QtGui import os -from xml.etree import ElementTree as ET - +#from xml.etree import ElementTree as ET +import json import TrackWidget @@ -11,23 +11,19 @@ class DeviceModel(QtGui.QWidget): It dynamically creates the widget for device like diode,mosfet,transistor and jfet. """ - def __init__(self,schematicInfo,clarg1): + def __init__(self, schematicInfo, clarg1): - self.clarg1=clarg1 + self.clarg1 = clarg1 kicadFile = self.clarg1 - (projpath,filename)=os.path.split(kicadFile) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="devicemodel": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) except: - check=0 - print "Device Model Previous XML is Empty" + print "Device Model Previous JSON is Empty" QtGui.QWidget.__init__(self) @@ -44,8 +40,8 @@ class DeviceModel(QtGui.QWidget): self.widthLabel = {} self.lengthLabel = {} self.multifactorLable = {} - self.devicemodel_dict_beg={} - self.devicemodel_dict_end={} + self.devicemodel_dict_beg = {} + self.devicemodel_dict_end = {} #List to hold information about device self.deviceDetail = {} @@ -58,37 +54,41 @@ class DeviceModel(QtGui.QWidget): words = eachline.split() if eachline[0] == 'q': print "Device Model Transistor: ",words[0] - self.devicemodel_dict_beg[words[0]]=self.count + self.devicemodel_dict_beg[words[0]] = self.count 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 + try: - for child in root: - if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: + for key in json_data["deviceModel"]: + 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(child[0].text): - self.entry_var[self.count].setText(child[0].text) - path_name=child[0].text + 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: pass - transgrid.addWidget(self.entry_var[self.count],self.row,1) + + transgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] - if self.entry_var[self.count].text()=="": + + if self.entry_var[self.count].text() == "": pass else: - self.trackLibraryWithoutButton(self.count,path_name) - transgrid.addWidget(self.addbtn,self.row,2) + self.trackLibraryWithoutButton(self.count, path_name) + + transgrid.addWidget(self.addbtn, self.row, 2) transbox.setLayout(transgrid) #CSS @@ -103,43 +103,46 @@ class DeviceModel(QtGui.QWidget): #Increment row and widget count - self.row = self.row+1 - self.devicemodel_dict_end[words[0]]=self.count - self.count = self.count+1 + 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] - self.devicemodel_dict_beg[words[0]]=self.count - diodebox=QtGui.QGroupBox() - diodegrid=QtGui.QGridLayout() + self.devicemodel_dict_beg[words[0]] = self.count + diodebox = QtGui.QGroupBox() + diodegrid = QtGui.QGridLayout() 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 try: - for child in root: - if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: + for key in json_data["deviceModel"]: + 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(child[0].text): - path_name=child[0].text - self.entry_var[self.count].setText(child[0].text) + 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]) else: self.entry_var[self.count].setText("") except: print "Error when set text of device model diode" except: pass - diodegrid.addWidget(self.entry_var[self.count],self.row,1) + + diodegrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] - if self.entry_var[self.count].text()=="": + + if self.entry_var[self.count].text() == "": pass else: - self.trackLibraryWithoutButton(self.count,path_name) - diodegrid.addWidget(self.addbtn,self.row,2) + self.trackLibraryWithoutButton(self.count, path_name) + + diodegrid.addWidget(self.addbtn, self.row, 2) diodebox.setLayout(diodegrid) #CSS @@ -154,43 +157,46 @@ class DeviceModel(QtGui.QWidget): #Increment row and widget count - self.row = self.row+1 - self.devicemodel_dict_end[words[0]]=self.count - self.count = self.count+1 + 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] - self.devicemodel_dict_beg[words[0]]=self.count - jfetbox=QtGui.QGroupBox() - jfetgrid=QtGui.QGridLayout() + self.devicemodel_dict_beg[words[0]] = self.count + jfetbox = QtGui.QGroupBox() + jfetgrid = QtGui.QGridLayout() 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 try: - for child in root: - if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: + for key in json_data["deviceModel"]: + 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(child[0].text): - self.entry_var[self.count].setText(child[0].text) - path_name=child[0].text + 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 JFET " except: pass - jfetgrid.addWidget(self.entry_var[self.count],self.row,1) + + jfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) self.addbtn.clicked.connect(self.trackLibrary) self.deviceDetail[self.count] = words[0] - if self.entry_var[self.count].text()=="": + + if self.entry_var[self.count].text() == "": pass else: - self.trackLibraryWithoutButton(self.count,path_name) - jfetgrid.addWidget(self.addbtn,self.row,2) + self.trackLibraryWithoutButton(self.count, path_name) + + jfetgrid.addWidget(self.addbtn, self.row, 2) jfetbox.setLayout(jfetgrid) #CSS @@ -201,83 +207,78 @@ class DeviceModel(QtGui.QWidget): self.grid.addWidget(jfetbox) - #Adding Device Details - - + #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 - - + 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 + 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]) - self.entry_var[self.count] =QtGui.QLineEdit() + self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") - mosfetgrid.addWidget(self.entry_var[self.count],self.row,1) + mosfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) self.addbtn.clicked.connect(self.trackLibrary) - mosfetgrid.addWidget(self.addbtn,self.row,2) + mosfetgrid.addWidget(self.addbtn, self.row, 2) #Adding Device Details self.deviceDetail[self.count] = words[0] #Increment row and widget count - self.row = self.row+1 - self.count = self.count+1 + 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):") - mosfetgrid.addWidget(self.widthLabel[self.count],self.row,0) + 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) + 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):") - mosfetgrid.addWidget(self.lengthLabel[self.count],self.row,0) + 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) + 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) + 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 + end = self.count self.entry_var[self.count].setMaximumWidth(150) - mosfetgrid.addWidget(self.entry_var[self.count],self.row,1) + mosfetgrid.addWidget(self.entry_var[self.count], self.row, 1) self.row = self.row + 1 - self.devicemodel_dict_end[words[0]]=self.count + self.devicemodel_dict_end[words[0]] = self.count self.count = self.count+1 mosfetbox.setLayout(mosfetgrid) #global path_name try: - for child in root: - if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: + for key in json_data["deviceModel"]: + 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(child[i-beg].text) - if (i-beg)==0: - if os.path.exists(child[0].text): - self.entry_var[i].setText(child[i-beg].text) - path_name=child[i-beg].text + 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]): + path_name = json_data["deviceModel"][key][0] else: self.entry_var[i].setText("") - i=i+1 + i = i + 1 except: pass #CSS @@ -285,10 +286,11 @@ class DeviceModel(QtGui.QWidget): 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 self.entry_var[beg].text()=="": + if self.entry_var[beg].text() == "": pass else: - self.trackLibraryWithoutButton(beg,path_name) + self.trackLibraryWithoutButton(beg, path_name) + self.grid.addWidget(mosfetbox) diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py index 4215f6f8..07948b04 100644 --- a/src/kicadtoNgspice/KicadtoNgspice.py +++ b/src/kicadtoNgspice/KicadtoNgspice.py @@ -26,8 +26,9 @@ import DeviceModel import SubcircuitTab import Convert import TrackWidget +import json -from xml.etree import ElementTree as ET +#from xml.etree import ElementTree as ET @@ -98,6 +99,7 @@ class MainWindow(QtGui.QWidget): 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. @@ -192,243 +194,241 @@ class MainWindow(QtGui.QWidget): global analysisoutput global kicad store_schematicInfo = list(schematicInfo) - (projpath,filename)=os.path.split(self.kicadFile) - project_name=os.path.basename(projpath) - - check=1 - try: - fr=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - temp_tree=ET.parse(fr) - temp_root=temp_tree.getroot() - except: - check=0 + (projpath,filename) = os.path.split(self.kicadFile) + project_name = os.path.basename(projpath) - fw=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'w') - if check==0: - attr_parent=ET.Element("KicadtoNgspice") - if check==1: - attr_parent=temp_root - - for child in attr_parent: - if child.tag=="analysis": - attr_parent.remove(child) + fw = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'w') + json_data = {} + + + """ + Writing Analysis values + """ + + json_data["analysis"] = {} - attr_analysis=ET.SubElement(attr_parent,"analysis") - attr_ac=ET.SubElement(attr_analysis,"ac") + json_data["analysis"]["ac"] = {} if obj_analysis.Lin.isChecked(): - ET.SubElement(attr_ac,"field1",name="Lin").text="true" - ET.SubElement(attr_ac,"field2",name="Dec").text="false" - ET.SubElement(attr_ac,"field3",name="Oct").text="false" + json_data["analysis"]["ac"]["Lin"] = "true" + json_data["analysis"]["ac"]["Dec"] = "false" + json_data["analysis"]["ac"]["Oct"] = "false" elif obj_analysis.Dec.isChecked(): - ET.SubElement(attr_ac,"field1",name="Lin").text="false" - ET.SubElement(attr_ac,"field2",name="Dec").text="true" - ET.SubElement(attr_ac,"field3",name="Oct").text="false" + json_data["analysis"]["ac"]["Lin"] = "false" + json_data["analysis"]["ac"]["Dec"] = "true" + json_data["analysis"]["ac"]["Oct"] = "false" if obj_analysis.Oct.isChecked(): - ET.SubElement(attr_ac,"field1",name="Lin").text="false" - ET.SubElement(attr_ac,"field2",name="Dec").text="false" - ET.SubElement(attr_ac,"field3",name="Oct").text="true" + json_data["analysis"]["ac"]["Lin"] = "false" + json_data["analysis"]["ac"]["Dec"] = "false" + json_data["analysis"]["ac"]["Oct"] = "true" else: pass - ET.SubElement(attr_ac,"field4",name="Start Frequency").text= str(obj_analysis.ac_entry_var[0].text()) - ET.SubElement(attr_ac,"field5",name="Stop Frequency").text= str(obj_analysis.ac_entry_var[1].text()) - ET.SubElement(attr_ac,"field6",name="No. of points").text= str(obj_analysis.ac_entry_var[2].text()) - ET.SubElement(attr_ac,"field7",name="Start Fre Combo").text= obj_analysis.ac_parameter[0] - ET.SubElement(attr_ac,"field8",name="Stop Fre Combo").text= obj_analysis.ac_parameter[1] - attr_dc=ET.SubElement(attr_analysis,"dc") - ET.SubElement(attr_dc,"field1",name="Source 1").text= str(obj_analysis.dc_entry_var[0].text()) - ET.SubElement(attr_dc,"field2",name="Start").text= str(obj_analysis.dc_entry_var[1].text()) - ET.SubElement(attr_dc,"field3",name="Increment").text= str(obj_analysis.dc_entry_var[2].text()) - ET.SubElement(attr_dc,"field4",name="Stop").text= str(obj_analysis.dc_entry_var[3].text()) - #print "OBJ_ANALYSIS.CHECK -----",self.obj_track.op_check[-1] - ET.SubElement(attr_dc,"field5",name="Operating Point").text=str(self.obj_track.op_check[-1]) - ET.SubElement(attr_dc,"field6",name="Start Combo").text= obj_analysis.dc_parameter[0] - ET.SubElement(attr_dc,"field7",name="Increment Combo").text=obj_analysis.dc_parameter[1] - ET.SubElement(attr_dc,"field8",name="Stop Combo").text= obj_analysis.dc_parameter[2] - ET.SubElement(attr_dc,"field9",name="Source 2").text= str(obj_analysis.dc_entry_var[4].text()) - ET.SubElement(attr_dc,"field10",name="Start").text= str(obj_analysis.dc_entry_var[5].text()) - ET.SubElement(attr_dc,"field11",name="Increment").text= str(obj_analysis.dc_entry_var[6].text()) - ET.SubElement(attr_dc,"field12",name="Stop").text= str(obj_analysis.dc_entry_var[7].text()) - ET.SubElement(attr_dc,"field13",name="Start Combo").text= obj_analysis.dc_parameter[3] - ET.SubElement(attr_dc,"field14",name="Increment Combo").text=obj_analysis.dc_parameter[4] - ET.SubElement(attr_dc,"field15",name="Stop Combo").text= obj_analysis.dc_parameter[5] - - - attr_tran=ET.SubElement(attr_analysis,"tran") - ET.SubElement(attr_tran,"field1",name="Start Time").text= str(obj_analysis.tran_entry_var[0].text()) - ET.SubElement(attr_tran,"field2",name="Step Time").text= str(obj_analysis.tran_entry_var[1].text()) - ET.SubElement(attr_tran,"field3",name="Stop Time").text= str(obj_analysis.tran_entry_var[2].text()) - ET.SubElement(attr_tran,"field4",name="Start Combo").text= obj_analysis.tran_parameter[0] - ET.SubElement(attr_tran,"field5",name="Step Combo").text= obj_analysis.tran_parameter[1] - ET.SubElement(attr_tran,"field6",name="Stop Combo").text= obj_analysis.tran_parameter[2] - #print "TRAN PARAMETER 2-----",obj_analysis.tran_parameter[2] - - if check==0: - attr_source=ET.SubElement(attr_parent,"source") - if check==1: - for child in attr_parent: - if child.tag=="source": - attr_source=child - count=1 - grand_child_count=1 - - for i in store_schematicInfo: - tmp_check=0 - words=i.split(' ') - wordv=words[0] - for child in attr_source: - if child.tag==wordv and child.text==words[len(words)-1]: - tmp_check=1 - for grand_child in child: - grand_child.text=str(obj_source.entry_var[grand_child_count].text()) - grand_child_count=grand_child_count+1 - grand_child_count=grand_child_count+1 - if tmp_check==0: - words=i.split(' ') - wordv=words[0] - if wordv[0]=="v" or wordv[0]=="i": - attr_var=ET.SubElement(attr_source,words[0],name="Source type") - attr_var.text=words[len(words)-1] - #ET.SubElement(attr_ac,"field1",name="Lin").text="true" - if words[len(words)-1]=="ac": - #attr_ac=ET.SubElement(attr_var,"ac") - ET.SubElement(attr_var,"field1",name="Amplitude").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var, "field2", name = "Phase").text = str(obj_source.entry_var[count].text()) - count=count+2 - elif words[len(words)-1]=="dc": - #attr_dc=ET.SubElement(attr_var,"dc") - ET.SubElement(attr_var,"field1",name="Value").text=str(obj_source.entry_var[count].text()) - count=count+2 - elif words[len(words)-1]=="sine": - #attr_sine=ET.SubElement(attr_var,"sine") - ET.SubElement(attr_var,"field1",name="Offset Value").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field2",name="Amplitude").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field3",name="Frequency").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field4",name="Delay Time").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field5",name="Damping Factor").text=str(obj_source.entry_var[count].text()) - count=count+2 - elif words[len(words)-1]=="pulse": - #attr_pulse=ET.SubElement(attr_var,"pulse") - ET.SubElement(attr_var,"field1",name="Initial Value").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field2",name="Pulse Value").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field3",name="Delay Time").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field4",name="Rise Time").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field5",name="Fall Time").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field5",name="Pulse width").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field5",name="Period").text=str(obj_source.entry_var[count].text()) - count=count+2 - elif words[len(words)-1]=="pwl": - #attr_pwl=ET.SubElement(attr_var,"pwl") - ET.SubElement(attr_var,"field1",name="Enter in pwl format").text=str(obj_source.entry_var[count].text()) - count=count+2 - elif words[len(words)-1]=="exp": - #attr_exp=ET.SubElement(attr_var,"exp") - ET.SubElement(attr_var,"field1",name="Initial Value").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field2",name="Pulsed Value").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field3",name="Rise Delay Time").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field4",name="Rise Time Constant").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field5",name="Fall TIme").text=str(obj_source.entry_var[count].text()) - count=count+1 - ET.SubElement(attr_var,"field6",name="Fall Time Constant").text=str(obj_source.entry_var[count].text()) - count=count+2 - else: - pass - - - if check==0: - attr_model=ET.SubElement(attr_parent,"model") - if check==1: - for child in attr_parent: - if child.tag=="model": - attr_model=child - i=0 - #tmp_check is a variable to check for duplicates in the xml file - tmp_check=0 - #tmp_i is the iterator in case duplicates are there; then in that case we need to replace only the child node and not create a new parent node - + + 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"]["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"]["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 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"] = {} + count = 1 + + for line in store_schematicInfo: + words = line.split(' ') + wordv = words[0] + + 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]["values"] = [] + + if words[len(words)-1] == "ac": + amp = {"Amplitude": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(amp) + + phase = {"Phase": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(phase) + + 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())} + count += 1 + json_data["source"][wordv]["values"].append(offset) + + amp = {"Amplitude": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(amp) + + freq = {"Freuency": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(freq) + + delay = {"Delay Time": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(delay) + + 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())} + count += 1 + json_data["source"][wordv]["values"].append(initial) + + pulse = {"Pulse Value": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(pulse) + + delay = {"Delay Time": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(delay) + + rise = {"Rise Time": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(rise) + + fall = {"Fall Time": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(fall) + + width = {"Pulse width": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(width) + + period = {"Period": str(obj_source.entry_var[count].text())} + 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())} + 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())} + count += 1 + json_data["source"][wordv]["values"].append(initial) + + 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())} + count += 1 + json_data["source"][wordv]["values"].append(rise) + + fall = {"Fall Time": str(obj_source.entry_var[count].text())} + count += 1 + json_data["source"][wordv]["values"].append(fall) + + 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 + json_data["model"] = {} + for line in modelList: - tmp_check=0 for rand_itr in obj_model.obj_trac.modelTrack: - if rand_itr[2]==line[2] and rand_itr[3]==line[3]: - start=rand_itr[7] - end=rand_itr[8] - i=start - for child in attr_model: - if child.text==line[2] and child.tag==line[3]: - for grand_child in child: - if i<=end: - grand_child.text=str(obj_model.obj_trac.model_entry_var[i].text()) - i=i+1 - else: - pass - tmp_check=1 - - if tmp_check==0: - attr_ui=ET.SubElement(attr_model,line[3],name="type") - attr_ui.text=line[2] - for key,value in line[7].iteritems(): - if hasattr(value, '__iter__') and i<=end: - for item in value: - ET.SubElement(attr_ui,"field"+str(i+1),name=item).text=str(obj_model.obj_trac.model_entry_var[i].text()) - i=i+1 + if rand_itr[2] == line[2] and rand_itr[3] == line[3]: + start = rand_itr[7] + end = rand_itr[8] + i = start + + json_data["model"][line[3]] = {} + json_data["model"][line[3]]["type"] = line[2] + json_data["model"][line[3]]["values"] = [] + + for key, value in line[7].iteritems(): + if hasattr(value, '__iter__') and i <= end: + for item in value: + fields = {item: str(obj_model.obj_trac.model_entry_var[i].text())} + json_data["model"][line[3]]["values"].append(fields) + i = i + 1 - else: - ET.SubElement(attr_ui,"field"+str(i+1),name=value).text=str(obj_model.obj_trac.model_entry_var[i].text()) - - i=i+1 - - if check==0: - attr_devicemodel=ET.SubElement(attr_parent,"devicemodel") - if check==1: - for child in attr_parent: - if child.tag=="devicemodel": - del child[:] - attr_devicemodel=child - + else: + 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"] = {} - for i in obj_devicemodel.devicemodel_dict_beg: - attr_var=ET.SubElement(attr_devicemodel,i) - it=obj_devicemodel.devicemodel_dict_beg[i] - end=obj_devicemodel.devicemodel_dict_end[i] - while it<=end: - ET.SubElement(attr_var,"field").text=str(obj_devicemodel.entry_var[it].text()) - it=it+1 - - if check==0: - attr_subcircuit=ET.SubElement(attr_parent,"subcircuit") - if check==1: - for child in attr_parent: - if child.tag=="subcircuit": - del child[:] - attr_subcircuit=child - - for i in obj_subcircuitTab.subcircuit_dict_beg: - attr_var=ET.SubElement(attr_subcircuit,i) - it=obj_subcircuitTab.subcircuit_dict_beg[i] - end=obj_subcircuitTab.subcircuit_dict_end[i] - - while it<=end: - ET.SubElement(attr_var,"field").text=str(obj_subcircuitTab.entry_var[it].text()) - it=it+1 + 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] - - tree=ET.ElementTree(attr_parent) - tree.write(fw) + while it <= end: + json_data["deviceModel"][device].append(str(obj_devicemodel.entry_var[it].text())) + it = it + 1 + + + """ + Writing Subcircuit values + """ + + 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())) + it = it + 1 + + write_data = json.dumps(json_data) + fw.write(write_data) self.obj_convert = Convert.Convert(self.obj_track.sourcelisttrack["ITEMS"], @@ -643,4 +643,4 @@ class MainWindow(QtGui.QWidget): -
\ No newline at end of file + diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 25a23d8c..ca6eaeff 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -1,8 +1,7 @@ - from PyQt4 import QtGui - +import json import TrackWidget -from xml.etree import ElementTree as ET +#from xml.etree import ElementTree as ET import os @@ -18,19 +17,15 @@ class Model(QtGui.QWidget): #Processing for getting previous values kicadFile = clarg1 - (projpath,filename)=os.path.split(kicadFile) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="model": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) except: - check=0 - print "Model Previous Values XML is Empty" + print "Model Previous Values JSON is Empty" @@ -54,12 +49,12 @@ class Model(QtGui.QWidget): #Adding title label for model #Key: Tag name,Value:Entry widget number tag_dict = {} - modelbox=QtGui.QGroupBox() - modelgrid=QtGui.QGridLayout() + modelbox = QtGui.QGroupBox() + modelgrid = QtGui.QGridLayout() modelbox.setTitle(line[5]) - self.start=self.nextcount + self.start = self.nextcount #line[7] is parameter dictionary holding parameter tags. - i=0 + i = 0 for key,value in line[7].iteritems(): #print "Key : ",key #print "Value : ",value @@ -69,36 +64,42 @@ class Model(QtGui.QWidget): 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) + 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) + try: - for child in root: - if child.text==line[2] and child.tag==line[3]: - self.obj_trac.model_entry_var[self.nextcount].setText(child[i].text) - i=i+1 + for key in json_data["model"]: + if json_data["model"][key]["type"] == line[2] and key == line[3]: + self.obj_trac.model_entry_var[self.nextcount].setText(str(json_data["model"][key]["values"][i].values()[0])) + i = i + 1 except: pass + temp_tag.append(self.nextcount) - self.nextcount = self.nextcount+1 - self.nextrow = self.nextrow+1 + self.nextcount = self.nextcount + 1 + self.nextrow = self.nextrow + 1 tag_dict[key] = temp_tag + 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) + 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) + try: - for child in root: - if child.text==line[2] and child.tag==line[3]: - self.obj_trac.model_entry_var[self.nextcount].setText(child[i].text) - i=i+1 + for key in json_data["model"]: + if json_data["model"][key]["type"] == line[2] and key == line[3]: + self.obj_trac.model_entry_var[self.nextcount].setText(str(json_data["model"][key]["values"][i].values()[0])) + i = i + 1 except: pass + tag_dict[key] = self.nextcount - self.nextcount = self.nextcount+1 - self.nextrow = self.nextrow+1 - self.end= self.nextcount-1 + self.nextcount = self.nextcount + 1 + self.nextrow = self.nextrow + 1 + + self.end = self.nextcount - 1 #print "End",self.end modelbox.setLayout(modelgrid) @@ -123,13 +124,13 @@ class Model(QtGui.QWidget): ''' #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 + 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 itr == lst: + check = 1 - if check==0: + if check == 0: self.obj_trac.modelTrack.append(lst) #print "The tag dictionary : ",tag_dict diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py index 1cf1487d..d66cfa81 100644 --- a/src/kicadtoNgspice/Source.py +++ b/src/kicadtoNgspice/Source.py @@ -1,7 +1,8 @@ import os from PyQt4 import QtGui import TrackWidget -from xml.etree import ElementTree as ET +#from xml.etree import ElementTree as ET +import json class Source(QtGui.QWidget): """ @@ -30,23 +31,19 @@ class Source(QtGui.QWidget): This function dynamically create source widget in the Source tab of KicadtoNgSpice window """ kicadFile = self.clarg1 - (projpath,filename)=os.path.split(kicadFile) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="source": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) + except: - check=0 - print "Source Previous Values XML is Empty" + print "Source Previous Values JSON is Empty" self.grid = QtGui.QGridLayout() self.setLayout(self.grid) - xml_num=0 if sourcelist: for line in sourcelist: @@ -54,38 +51,44 @@ class Source(QtGui.QWidget): print "SourceList line: ",line track_id=line[0] #print "track_id is ",track_id - if line[2]=='ac': - acbox=QtGui.QGroupBox() + if line[2] == 'ac': + acbox = QtGui.QGroupBox() acbox.setTitle(line[3]) - acgrid=QtGui.QGridLayout() - self.start=self.count - label1=QtGui.QLabel(line[4]) + acgrid = QtGui.QGridLayout() + self.start = self.count + label1 = QtGui.QLabel(line[4]) label2 = QtGui.QLabel(line[5]) - acgrid.addWidget(label1,self.row,0) - acgrid.addWidget(label2, self.row+1, 0) - self.entry_var[self.count]=QtGui.QLineEdit() + acgrid.addWidget(label1, self.row, 0) + acgrid.addWidget(label2, self.row + 1, 0) + + self.entry_var[self.count] = QtGui.QLineEdit() + self.entry_var[self.count].setMaximumWidth(150) + acgrid.addWidget(self.entry_var[self.count], self.row, 1) + self.entry_var[self.count].setText("") + self.count += 1 + + self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) - acgrid.addWidget(self.entry_var[self.count],self.row,1) - self.entry_var[self.count+1]=QtGui.QLineEdit() - self.entry_var[self.count+1].setMaximumWidth(150) - acgrid.addWidget(self.entry_var[self.count+1],self.row+1,1) + acgrid.addWidget(self.entry_var[self.count], self.row + 1, 1) self.entry_var[self.count].setText("") - self.entry_var[self.count+1].setText("") + self.count += 1 + try: - for child in root: - templist1=line[1] - templist2=templist1.split(' ') + for key in json_data["source"]: + templist1 = line[1] + templist2 = templist1.split(' ') - if child.tag==templist2[0] and child.text==line[2]: - self.entry_var[self.count].setText(child[0].text) - self.entry_var[self.count+1].setText(child[1].text) + 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: pass #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 + self.row = self.row + 1 + self.end = self.count + 1 + self.count = self.count + 1 acbox.setLayout(acgrid) #CSS @@ -95,34 +98,36 @@ class Source(QtGui.QWidget): ") 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() + elif line[2] == 'dc': + dcbox = QtGui.QGroupBox() dcbox.setTitle(line[3]) - dcgrid=QtGui.QGridLayout() - self.row=self.row+1 - self.start=self.count - label=QtGui.QLabel(line[4]) - dcgrid.addWidget(label,self.row,0) - self.entry_var[self.count]=QtGui.QLineEdit() + dcgrid = QtGui.QGridLayout() + self.start = self.count + label = QtGui.QLabel(line[4]) + dcgrid.addWidget(label, self.row, 0) + + self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) - dcgrid.addWidget(self.entry_var[self.count],self.row,1) + dcgrid.addWidget(self.entry_var[self.count], self.row, 1) self.entry_var[self.count].setText("") + try: - for child in root: - templist1=line[1] - templist2=templist1.split(' ') - - if child.tag==templist2[0] and child.text==line[2]: - self.entry_var[self.count].setText(child[0].text) + 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]["Value"])) + except: pass - self.row=self.row+1 - self.end=self.count - self.count=self.count+1 + self.row = self.row + 1 + self.end = self.count + self.count = self.count + 1 dcbox.setLayout(dcgrid) #CSS @@ -132,35 +137,36 @@ class Source(QtGui.QWidget): ") 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() + elif line[2] == 'sine': + sinebox = QtGui.QGroupBox() sinebox.setTitle(line[3]) - sinegrid=QtGui.QGridLayout() - self.row=self.row+1 - self.start=self.count + sinegrid = QtGui.QGridLayout() + 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() + 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: - for child in root: - templist1=line[1] - templist2=templist1.split(' ') - if child.tag==templist2[0] and child.text==line[2]: - self.entry_var[self.count].setText(child[it-4].text) + 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"][it-4].values()[0])) except: pass - self.row=self.row+1 - self.count=self.count+1 - self.end=self.count-1 + self.row = self.row + 1 + self.count = self.count + 1 + self.end = self.count - 1 sinebox.setLayout(sinegrid) #CSS @@ -170,34 +176,35 @@ class Source(QtGui.QWidget): ") 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() + elif line[2] == 'pulse': + pulsebox = QtGui.QGroupBox() pulsebox.setTitle(line[3]) - pulsegrid=QtGui.QGridLayout() - self.start=self.count - for it in range(4,11): - label=QtGui.QLabel(line[it]) - pulsegrid.addWidget(label,self.row,0) - self.entry_var[self.count]=QtGui.QLineEdit() + pulsegrid = QtGui.QGridLayout() + self.start = self.count + + for it in range(4, 11): + label = QtGui.QLabel(line[it]) + 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 child in root: - templist1=line[1] - templist2=templist1.split(' ') - if child.tag==templist2[0] and child.text==line[2]: - self.entry_var[self.count].setText(child[it-4].text) + 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"][it-4].values()[0])) except: pass - - self.row=self.row+1 - self.count=self.count+1 - self.end=self.count-1 + self.row = self.row + 1 + self.count = self.count + 1 + self.end = self.count - 1 pulsebox.setLayout(pulsegrid) #CSS @@ -207,34 +214,33 @@ class Source(QtGui.QWidget): ") 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() + elif line[2] == 'pwl': + pwlbox = QtGui.QGroupBox() pwlbox.setTitle(line[3]) - self.start=self.count - pwlgrid=QtGui.QGridLayout() - self.start=self.count - label=QtGui.QLabel(line[4]) - pwlgrid.addWidget(label,self.row,0) - self.entry_var[self.count]=QtGui.QLineEdit() + self.start = self.count + pwlgrid = QtGui.QGridLayout() + label = QtGui.QLabel(line[4]) + pwlgrid.addWidget(label, self.row, 0) + self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) - pwlgrid.addWidget(self.entry_var[self.count],self.row,1) + pwlgrid.addWidget(self.entry_var[self.count], self.row, 1) self.entry_var[self.count].setText("") try: - for child in root: - templist1=line[1] - templist2=templist1.split(' ') - if child.tag==templist2[0] and child.text==line[2]: - self.entry_var[self.count].setText(child[0].text) + 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: pass - self.row=self.row+1 - self.end=self.count - self.count=self.count+1 + self.row = self.row + 1 + self.end = self.count + self.count = self.count + 1 pwlbox.setLayout(pwlgrid) #CSS @@ -244,34 +250,35 @@ class Source(QtGui.QWidget): ") 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() + elif line[2] == 'exp': + expbox = QtGui.QGroupBox() expbox.setTitle(line[3]) - expgrid=QtGui.QGridLayout() - self.start=self.count + expgrid = QtGui.QGridLayout() + self.start = self.count + for it in range(4,10): - label=QtGui.QLabel(line[it]) - expgrid.addWidget(label,self.row,0) - self.entry_var[self.count]=QtGui.QLineEdit() + 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 child in root: - templist1=line[1] - templist2=templist1.split(' ') - if child.tag==templist2[0] and child.text==line[2]: - self.entry_var[self.count].setText(child[it-4].text) + 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"][it-4].values()[0])) except: pass - self.row=self.row+1 - self.count=self.count+1 - self.end=self.count-1 + self.row = self.row + 1 + self.count = self.count + 1 + self.end = self.count - 1 expbox.setLayout(expgrid) #CSS @@ -281,12 +288,7 @@ class Source(QtGui.QWidget): ") self.grid.addWidget(expbox) - sourcelisttrack.append([track_id,'exp',self.start,self.end]) - - - self.count=self.count+1 - xml_num=xml_num+1 - + sourcelisttrack.append([track_id, 'exp', self.start, self.end]) else: print "No source is present in your circuit" diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py index e7a9ed66..aba2a145 100644 --- a/src/kicadtoNgspice/SubcircuitTab.py +++ b/src/kicadtoNgspice/SubcircuitTab.py @@ -1,9 +1,9 @@ from PyQt4 import QtGui - +import json import TrackWidget from projManagement import Validation import os -from xml.etree import ElementTree as ET +#from xml.etree import ElementTree as ET class SubcircuitTab(QtGui.QWidget): """ @@ -11,21 +11,17 @@ class SubcircuitTab(QtGui.QWidget): It dynamically creates the widget for subcircuits. """ - def __init__(self,schematicInfo,clarg1): + def __init__(self, schematicInfo, clarg1): kicadFile = clarg1 - (projpath,filename)=os.path.split(kicadFile) - project_name=os.path.basename(projpath) - check=1 + (projpath,filename) = os.path.split(kicadFile) + project_name = os.path.basename(projpath) + try: - f=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r') - tree=ET.parse(f) - parent_root=tree.getroot() - for child in parent_root: - if child.tag=="subcircuit": - root=child + f = open(os.path.join(projpath,project_name+"_Previous_Values.json"),'r') + data = f.read() + json_data = json.loads(data) except: - check=0 - print "Subcircuit Previous values XML is Empty" + print "Subcircuit Previous values JSON is Empty" QtGui.QWidget.__init__(self) @@ -38,8 +34,8 @@ class SubcircuitTab(QtGui.QWidget): self.row = 0 self.count = 1 #Entry count self.entry_var = {} - self.subcircuit_dict_beg={} - self.subcircuit_dict_end={} + self.subcircuit_dict_beg = {} + self.subcircuit_dict_end = {} #List to hold information about subcircuit self.subDetail = {} @@ -54,23 +50,23 @@ class SubcircuitTab(QtGui.QWidget): words = eachline.split() if eachline[0] == 'x': 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() + 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]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") global path_name try: - for child in root: - if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: - print "Subcircuit MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] + for key in json_data["subcircuit"]: + 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(child[0].text): - self.entry_var[self.count].setText(child[0].text) - path_name=child[0].text + 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: @@ -79,7 +75,7 @@ class SubcircuitTab(QtGui.QWidget): print "Error before subcircuit" - subgrid.addWidget(self.entry_var[self.count],self.row,1) + 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. @@ -87,7 +83,7 @@ class SubcircuitTab(QtGui.QWidget): 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) + subgrid.addWidget(self.addbtn, self.row, 2) subbox.setLayout(subgrid) #CSS @@ -103,14 +99,14 @@ class SubcircuitTab(QtGui.QWidget): #Increment row and widget count - if self.entry_var[self.count].text()=="": + if self.entry_var[self.count].text() == "": pass else: - self.trackSubcircuitWithoutButton(self.count,path_name) + self.trackSubcircuitWithoutButton(self.count, path_name) - self.subcircuit_dict_end[words[0]]=self.count - self.row = self.row+1 - self.count = self.count+1 + self.subcircuit_dict_end[words[0]] = self.count + self.row = self.row + 1 + self.count = self.count + 1 self.show() |