diff options
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r-- | src/kicadtoNgspice/Analysis.py | 120 | ||||
-rw-r--r-- | src/kicadtoNgspice/DeviceModel.py | 78 | ||||
-rw-r--r-- | src/kicadtoNgspice/KicadtoNgspice.py | 269 | ||||
-rw-r--r-- | src/kicadtoNgspice/Model.py | 38 | ||||
-rw-r--r-- | src/kicadtoNgspice/Source.py | 103 |
5 files changed, 586 insertions, 22 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py index 58f10ce3..b679188d 100644 --- a/src/kicadtoNgspice/Analysis.py +++ b/src/kicadtoNgspice/Analysis.py @@ -1,6 +1,10 @@ from PyQt4 import QtGui,QtCore +from PyQt4.Qt import QRect import TrackWidget +import os +import sys +from xml.etree import ElementTree as ET class Analysis(QtGui.QWidget): """ @@ -83,6 +87,23 @@ class Analysis(QtGui.QWidget): self.track_obj.set_CheckBox["ITEMS"]="TRAN" def createACgroup(self): + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=projpath.split("/") + project_name=project_name[len(project_name)-1] + print "PROJECT NAME---------",project_name + 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 + except: + check=0 + print "Empty XML" + self.acbox = QtGui.QGroupBox() self.acbox.setTitle("AC Analysis") self.acgrid = QtGui.QGridLayout() @@ -160,7 +181,33 @@ class Analysis(QtGui.QWidget): 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; } \ - ") + ") + if check: + try: + if root[0][0].text=="true": + self.Lin.setChecked(True) + self.Dec.setChecked(False) + self.Oct.setChecked(False) + elif root[0][1].text=="true": + self.Lin.setChecked(False) + self.Dec.setChecked(True) + self.Oct.setChecked(False) + elif root[0][2].text=="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.start_fre_combo.setCurrentIndex(index) + index=self.stop_fre_combo.findText(root[0][7].text) + self.stop_fre_combo.setCurrentIndex(index) + except: + print "XML Parse Error" + return self.acbox def start_combovalue(self, text): @@ -181,6 +228,23 @@ class Analysis(QtGui.QWidget): pass def createDCgroup(self): + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=projpath.split("/") + project_name=project_name[len(project_name)-1] + print "PROJECT NAME---------",project_name + 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 + except: + check=0 + print "Empty XML" + self.dcbox = QtGui.QGroupBox() self.dcbox.setTitle("DC Analysis") self.dcgrid = QtGui.QGridLayout() @@ -272,7 +336,24 @@ class Analysis(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 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.start_combo.setCurrentIndex(index) + index=self.increment_combo.findText(root[1][6].text) + self.increment_combo.setCurrentIndex(index) + index=self.stop_combo.findText(root[1][7].text) + self.stop_combo.setCurrentIndex(index) + if root[1][4].text: + self.check.setCheckState(True) + else: + self.check.setCheckedState(False) + except: + print "XML Parse Error" return self.dcbox @@ -286,6 +367,23 @@ class Analysis(QtGui.QWidget): self.dc_parameter[2]=str(text) def createTRANgroup(self): + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=projpath.split("/") + project_name=project_name[len(project_name)-1] + print "PROJECT NAME---------",project_name + 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 + except: + check=0 + print "Empty XML" + self.trbox = QtGui.QGroupBox() self.trbox.setTitle("Transient Analysis") self.trgrid = QtGui.QGridLayout() @@ -356,8 +454,22 @@ class Analysis(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 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.start_combobox.setCurrentIndex(index) + index=self.step_combobox.findText(root[2][4].text) + self.step_combobox.setCurrentIndex(index) + + index=self.stop_combobox.findText(root[2][5].text) + self.stop_combobox.setCurrentIndex(index) + except: + print "XML Parse Error" + + return self.trbox def start_combo_change(self,text): diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index 0ae421b6..56ffb7f1 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -1,4 +1,7 @@ from PyQt4 import QtGui +import sys +import os +from xml.etree import ElementTree as ET import TrackWidget @@ -10,6 +13,25 @@ class DeviceModel(QtGui.QWidget): """ def __init__(self,schematicInfo): + + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=projpath.split("/") + project_name=project_name[len(project_name)-1] + print "PROJECT NAME---------",project_name + 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=="devicemodel": + root=child + except: + check=0 + print "Empty XML" + + QtGui.QWidget.__init__(self) #Creating track widget object @@ -24,8 +46,8 @@ class DeviceModel(QtGui.QWidget): self.widthLabel = {} self.lengthLabel = {} self.multifactorLable = {} - - + self.devicemodel_dict_beg={} + self.devicemodel_dict_end={} #List to hold information about device self.deviceDetail = {} @@ -37,11 +59,22 @@ class DeviceModel(QtGui.QWidget): words = eachline.split() if eachline[0] == 'q': print "Words ",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]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") + try: + for child in root: + if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: + #print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] + try: + self.entry_var[self.count].setText(child[0].text) + except: + print "ERROR WHEN SET TEXT" + except: + pass transgrid.addWidget(self.entry_var[self.count],self.row,1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) @@ -62,15 +95,27 @@ 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 elif eachline[0] == 'd': print "Words",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]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") + try: + for child in root: + if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: + print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] + try: + self.entry_var[self.count].setText(child[0].text) + except: + print "ERROR WHEN SET TEXT" + except: + pass diodegrid.addWidget(self.entry_var[self.count],self.row,1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) @@ -91,15 +136,27 @@ 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 elif eachline[0] == 'j': print "Words",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]) self.entry_var[self.count] = QtGui.QLineEdit() self.entry_var[self.count].setText("") + try: + for child in root: + if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]: + print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] + try: + self.entry_var[self.count].setText(child[0].text) + except: + print "ERROR WHEN SET TEXT" + except: + pass jfetgrid.addWidget(self.entry_var[self.count],self.row,1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) @@ -120,13 +177,17 @@ 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 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]) self.entry_var[self.count] =QtGui.QLineEdit() self.entry_var[self.count].setText("") @@ -167,12 +228,22 @@ class DeviceModel(QtGui.QWidget): 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 self.entry_var[self.count].setMaximumWidth(150) 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 mosfetbox.setLayout(mosfetgrid) - + try: + for child in root: + if child.tag[0]==eachline[0] and child.tag[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) + i=i+1 + except: + pass #CSS mosfetbox.setStyleSheet(" \ QGroupBox { border: 1px solid gray; border-radius: 9px; margin-top: 0.5em; } \ @@ -180,6 +251,7 @@ class DeviceModel(QtGui.QWidget): ") self.grid.addWidget(mosfetbox) + self.show() diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py index dbb39ddc..7c5f46b4 100644 --- a/src/kicadtoNgspice/KicadtoNgspice.py +++ b/src/kicadtoNgspice/KicadtoNgspice.py @@ -26,6 +26,8 @@ import DeviceModel import Convert import TrackWidget +from xml.etree import ElementTree as ET + class MainWindow(QtGui.QWidget): @@ -81,25 +83,29 @@ class MainWindow(QtGui.QWidget): def createcreateConvertWidget(self): - + global obj_analysis self.convertWindow = QtGui.QWidget() self.analysisTab = QtGui.QScrollArea() - self.analysisTab.setWidget(Analysis.Analysis()) + obj_analysis=Analysis.Analysis() + self.analysisTab.setWidget(obj_analysis) #self.analysisTabLayout = QtGui.QVBoxLayout(self.analysisTab.widget()) self.analysisTab.setWidgetResizable(True) - + global obj_source self.sourceTab = QtGui.QScrollArea() - self.sourceTab.setWidget(Source.Source(sourcelist,sourcelisttrack)) + obj_source=Source.Source(sourcelist,sourcelisttrack) + self.sourceTab.setWidget(obj_source) #self.sourceTabLayout = QtGui.QVBoxLayout(self.sourceTab.widget()) self.sourceTab.setWidgetResizable(True) - + global obj_model self.modelTab = QtGui.QScrollArea() - self.modelTab.setWidget(Model.Model(schematicInfo,modelList)) + obj_model=Model.Model(schematicInfo,modelList) + self.modelTab.setWidget(obj_model) #self.modelTabLayout = QtGui.QVBoxLayout(self.modelTab.widget()) self.modelTab.setWidgetResizable(True) - + global obj_devicemodel self.deviceModelTab = QtGui.QScrollArea() - self.deviceModelTab.setWidget(DeviceModel.DeviceModel(schematicInfo)) + obj_devicemodel=DeviceModel.DeviceModel(schematicInfo) + self.deviceModelTab.setWidget(obj_devicemodel) self.deviceModelTab.setWidgetResizable(True) @@ -125,6 +131,250 @@ class MainWindow(QtGui.QWidget): """ global schematicInfo global analysisoutput + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=projpath.split("/") + project_name=project_name[len(project_name)-1] + print "PROJ PATH---",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 + + + + 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) + + attr_analysis=ET.SubElement(attr_parent,"analysis") + attr_ac=ET.SubElement(attr_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" + 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" + 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" + 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 Name").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()) + ET.SubElement(attr_dc,"field5",name="Operating Point").text=str(obj_analysis.check.isChecked()) + print "OBJ_ANALYSIS.CHECK -----",obj_analysis.check.isChecked() + 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] + 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] + + #tree=ET.ElementTree(attr_analysis) + #tree.write(f) + + + 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 + #global tmp_check + #tmp_check=0 + for i in 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": + 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+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 + + #tree=ET.ElementTree(attr_source) + #tree.write(f1) + + + + 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 + + for line in modelList: + print "i for each line in model List------",i + 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()) + print "STR OF MODEL----",str(obj_model.obj_trac.model_entry_var[i].text()) + i=i+1 + print "i incremented to ",i + 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()) + print "STR OF MODEL----",str(obj_model.obj_trac.model_entry_var[i].text()) + i=i+1 + print "i incremented to ",i + else: + ET.SubElement(attr_ui,"field"+str(i+1),name=value).text=str(obj_model.obj_trac.model_entry_var[i].text()) + print "STR OF MODEL----",str(obj_model.obj_trac.model_entry_var[i].text()) + i=i+1 + print "i incremented to ",i + ################################################################################################################# + if check==0: + attr_devicemodel=ET.SubElement(attr_parent,"devicemodel") + if check==1: + for child in attr_parent: + if child.tag=="devicemodel": + attr_devicemodel=child + print "Device model dict",obj_devicemodel.devicemodel_dict_beg + print "Device model dict end",obj_devicemodel.devicemodel_dict_end + ########################## + 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 + ##################################### + + """keys=obj_devicemodel.devicemodel_dict.keys() + n=len(keys) + for i in range(n): + thisKey=keys[i] + nextKey=keys[(i+1)%n] + nextValue=obj_devicemodel.devicemodel_dict[nextKey] + attr_var=ET.SubElement(attr_devicemodel,thisKey) + it=obj_devicemodel.devicemodel_dict[thisKey] + while it<=nextValue: + ET.SubElement(attr_var,"field").text=obj_devicemodel.entry_var[it]""" + + ################################################################################################################### + + + tree=ET.ElementTree(attr_parent) + tree.write(fw) + + self.obj_convert = Convert.Convert(self.obj_track.sourcelisttrack["ITEMS"], self.obj_track.source_entry_var["ITEMS"], schematicInfo) @@ -139,8 +389,7 @@ class MainWindow(QtGui.QWidget): #Adding Device Library to SchematicInfo schematicInfo = self.obj_convert.addDeviceLibrary(schematicInfo,kicadFile) - - + 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"], diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py index 8ec6de7b..8170f056 100644 --- a/src/kicadtoNgspice/Model.py +++ b/src/kicadtoNgspice/Model.py @@ -2,6 +2,9 @@ from PyQt4 import QtGui import TrackWidget +from xml.etree import ElementTree as ET +import sys +import os class Model(QtGui.QWidget): @@ -11,6 +14,26 @@ class Model(QtGui.QWidget): """ def __init__(self,schematicInfo,modelList): + + + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=projpath.split("/") + project_name=project_name[len(project_name)-1] + #print "PROJECT NAME---------",project_name + 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=="model": + root=child + except: + check=0 + print "Empty XML" + + QtGui.QWidget.__init__(self) #Creating track widget object self.obj_trac = TrackWidget.TrackWidget() @@ -37,6 +60,7 @@ class Model(QtGui.QWidget): modelbox.setTitle(line[5]) self.start=self.nextcount #line[7] is parameter dictionary holding parameter tags. + i=0 for key,value in line[7].iteritems(): #print "Key : ",key #print "Value : ",value @@ -49,6 +73,13 @@ class Model(QtGui.QWidget): 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 + except: + pass temp_tag.append(self.nextcount) self.nextcount = self.nextcount+1 self.nextrow = self.nextrow+1 @@ -58,6 +89,13 @@ class Model(QtGui.QWidget): 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 + except: + pass tag_dict[key] = self.nextcount self.nextcount = self.nextcount+1 self.nextrow = self.nextrow+1 diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py index 3ff7c975..ef4db1cc 100644 --- a/src/kicadtoNgspice/Source.py +++ b/src/kicadtoNgspice/Source.py @@ -1,7 +1,10 @@ - +import sys +import os from PyQt4 import QtGui from Processing import PrcocessNetlist import TrackWidget +from xml.etree import ElementTree as ET + class Source(QtGui.QWidget): @@ -29,10 +32,32 @@ class Source(QtGui.QWidget): """ This function dynamically create source widget in the Source tab of KicadtoNgSpice window """ - + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=projpath.split("/") + project_name=project_name[len(project_name)-1] + print "PROJECT NAME---------",project_name + 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=="source": + root=child + except: + check=0 + print "Empty XML" + self.grid = QtGui.QGridLayout() self.setLayout(self.grid) - + xml_num=0 + """self.ac_check=0 + self.dc_check=0 + self.sine_check=0 + self.pulse_check=0 + self.pwl_check=0 + self.exp_check=0""" if sourcelist: for line in sourcelist: #print "Voltage source line index: ",line[0] @@ -51,6 +76,17 @@ class Source(QtGui.QWidget): acgrid.addWidget(self.entry_var[self.count],self.row,1) #Value Need to check previuouse value 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) + except: + pass + #Value Need to check previuouse value + #self.entry_var[self.count].setText("") self.row=self.row+1 self.end=self.count self.count=self.count+1 @@ -69,6 +105,7 @@ class Source(QtGui.QWidget): 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) @@ -76,6 +113,16 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setMaximumWidth(150) 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) + except: + pass + self.row=self.row+1 self.end=self.count self.count=self.count+1 @@ -94,6 +141,7 @@ class Source(QtGui.QWidget): sinebox=QtGui.QGroupBox() sinebox.setTitle(line[3]) sinegrid=QtGui.QGridLayout() + self.row=self.row+1 self.start=self.count for it in range(4,9): @@ -102,7 +150,17 @@ class Source(QtGui.QWidget): self.entry_var[self.count]=QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) sinegrid.addWidget(self.entry_var[self.count],self.row,1) - self.entry_var[self.count].setText("") + 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) + except: + pass + + self.row=self.row+1 self.count=self.count+1 self.end=self.count-1 @@ -129,6 +187,17 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setMaximumWidth(150) 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) + except: + pass + + self.row=self.row+1 self.count=self.count+1 self.end=self.count-1 @@ -146,6 +215,7 @@ class Source(QtGui.QWidget): 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]) @@ -153,7 +223,18 @@ class Source(QtGui.QWidget): self.entry_var[self.count]=QtGui.QLineEdit() self.entry_var[self.count].setMaximumWidth(150) pwlgrid.addWidget(self.entry_var[self.count],self.row,1) - self.entry_var[self.count].setText(""); + 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) + except: + pass + + self.row=self.row+1 self.end=self.count self.count=self.count+1 @@ -180,6 +261,17 @@ class Source(QtGui.QWidget): self.entry_var[self.count].setMaximumWidth(150) 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) + except: + pass + + self.row=self.row+1 self.count=self.count+1 self.end=self.count-1 @@ -197,6 +289,7 @@ class Source(QtGui.QWidget): self.count=self.count+1 + xml_num=xml_num+1 else: |