diff options
author | xoher | 2015-06-23 18:38:02 +0530 |
---|---|---|
committer | xoher | 2015-06-23 18:38:02 +0530 |
commit | 6af9f606a72d3c4399873840de3c683d423df5a6 (patch) | |
tree | 3d4eb335a02347d289dad226d5b2ca202da9edad | |
parent | 39fecda9f1be8b1007552437d53c06bdc02f4b47 (diff) | |
download | eSim-6af9f606a72d3c4399873840de3c683d423df5a6.tar.gz eSim-6af9f606a72d3c4399873840de3c683d423df5a6.tar.bz2 eSim-6af9f606a72d3c4399873840de3c683d423df5a6.zip |
Check if path exists for DeviceModel,Subcircuit and storing previous values for Subcircuit
-rw-r--r-- | src/kicadtoNgspice/DeviceModel.py | 88 | ||||
-rw-r--r-- | src/kicadtoNgspice/KicadtoNgspice.py | 22 | ||||
-rw-r--r-- | src/kicadtoNgspice/SubcircuitTab.py | 84 |
3 files changed, 177 insertions, 17 deletions
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py index a6d11ee7..7dc740d2 100644 --- a/src/kicadtoNgspice/DeviceModel.py +++ b/src/kicadtoNgspice/DeviceModel.py @@ -64,12 +64,17 @@ class DeviceModel(QtGui.QWidget): 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]: #print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] try: - self.entry_var[self.count].setText(child[0].text) + if os.path.exists(child[0].text): + self.entry_var[self.count].setText(child[0].text) + path_name=child[0].text + else: + self.entry_var[self.count].setText("") except: print "ERROR WHEN SET TEXT" except: @@ -78,6 +83,11 @@ class DeviceModel(QtGui.QWidget): 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()=="": + pass + else: + self.trackLibraryWithourButton(self.count,path_name) transgrid.addWidget(self.addbtn,self.row,2) transbox.setLayout(transgrid) @@ -90,7 +100,7 @@ class DeviceModel(QtGui.QWidget): self.grid.addWidget(transbox) #Adding Device Details - self.deviceDetail[self.count] = words[0] + #Increment row and widget count self.row = self.row+1 @@ -105,12 +115,17 @@ class DeviceModel(QtGui.QWidget): 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]: print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] try: - self.entry_var[self.count].setText(child[0].text) + if os.path.exists(child[0].text): + path_name=child[0].text + self.entry_var[self.count].setText(child[0].text) + else: + self.entry_var[self.count].setText("") except: print "ERROR WHEN SET TEXT" except: @@ -119,6 +134,11 @@ class DeviceModel(QtGui.QWidget): 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()=="": + pass + else: + self.trackLibraryWithoutButton(self.count,path_name) diodegrid.addWidget(self.addbtn,self.row,2) diodebox.setLayout(diodegrid) @@ -131,7 +151,7 @@ class DeviceModel(QtGui.QWidget): self.grid.addWidget(diodebox) #Adding Device Details - self.deviceDetail[self.count] = words[0] + #Increment row and widget count self.row = self.row+1 @@ -146,12 +166,17 @@ class DeviceModel(QtGui.QWidget): 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]: print "DEVICE MODEL MATCHING---",child.tag[0],child.tag[1],eachline[0],eachline[1] try: - self.entry_var[self.count].setText(child[0].text) + if os.path.exists(child[0].text): + self.entry_var[self.count].setText(child[0].text) + path_name=child[0].text + else: + self.entry_var[self.count].setText("") except: print "ERROR WHEN SET TEXT" except: @@ -160,6 +185,11 @@ class DeviceModel(QtGui.QWidget): 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()=="": + pass + else: + self.trackLibraryWithoutButton(self.count,path_name) jfetgrid.addWidget(self.addbtn,self.row,2) jfetbox.setLayout(jfetgrid) @@ -172,7 +202,7 @@ class DeviceModel(QtGui.QWidget): self.grid.addWidget(jfetbox) #Adding Device Details - self.deviceDetail[self.count] = words[0] + #Increment row and widget count self.row = self.row+1 @@ -234,12 +264,19 @@ class DeviceModel(QtGui.QWidget): 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]: 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 + else: + self.entry_var[i].setText("") i=i+1 except: pass @@ -248,7 +285,10 @@ 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()=="": + pass + else: + self.trackLibraryWithoutButton(beg,path_name) self.grid.addWidget(mosfetbox) @@ -286,6 +326,34 @@ class DeviceModel(QtGui.QWidget): else: self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile - - -
\ No newline at end of file + def trackLibraryWithoutButton(self,iter_value,path_value): + """ + This function is use to keep track of all Device Model widget + """ + print "Calling Track Library funtion" + #print "Object Called is ",sending_btn.objectName() + self.widgetObjCount = iter_value + print "self.widgetObjCount-----",self.widgetObjCount + self.libfile = path_value + #print "Selected Library File :",self.libfile + + #Setting Library to Text Edit Line + self.entry_var[self.widgetObjCount].setText(self.libfile) + self.deviceName = self.deviceDetail[self.widgetObjCount] + + #Storing to track it during conversion + + + if self.deviceName[0] == 'm': + width = str(self.entry_var[self.widgetObjCount+1].text()) + length = str(self.entry_var[self.widgetObjCount+2].text()) + multifactor = str(self.entry_var[self.widgetObjCount+3].text()) + if width == "" : width="100u" + if length == "": length="100u" + if multifactor == "": multifactor="1" + + self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile+":"+"W="+width+" L="+length+" M="+multifactor + + else: + self.obj_trac.deviceModelTrack[self.deviceName] = self.libfile +
\ No newline at end of file diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py index 7e8617ae..c9b5ac02 100644 --- a/src/kicadtoNgspice/KicadtoNgspice.py +++ b/src/kicadtoNgspice/KicadtoNgspice.py @@ -348,9 +348,10 @@ class MainWindow(QtGui.QWidget): if check==1: for child in attr_parent: if child.tag=="devicemodel": + del child[:] attr_devicemodel=child - print "Device model dict",obj_devicemodel.devicemodel_dict_beg - print "Device model dict end",obj_devicemodel.devicemodel_dict_end + #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) @@ -374,6 +375,23 @@ class MainWindow(QtGui.QWidget): ################################################################################################################### + 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 + tree=ET.ElementTree(attr_parent) tree.write(fw) diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py index 2614d75a..bbac5592 100644 --- a/src/kicadtoNgspice/SubcircuitTab.py +++ b/src/kicadtoNgspice/SubcircuitTab.py @@ -2,6 +2,10 @@ from PyQt4 import QtGui import TrackWidget from projManagement import Validation +import os +import sys +from xml.etree import ElementTree as ET + class SubcircuitTab(QtGui.QWidget): @@ -11,6 +15,23 @@ class SubcircuitTab(QtGui.QWidget): """ def __init__(self,schematicInfo): + + kicadFile = sys.argv[1] + (projpath,filename)=os.path.split(kicadFile) + project_name=os.path.basename(projpath) + 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=="subcircuit": + root=child + except: + check=0 + print "Empty XML" + QtGui.QWidget.__init__(self) #Creating track widget object @@ -22,8 +43,9 @@ class SubcircuitTab(QtGui.QWidget): self.row = 0 self.count = 1 #Entry count self.entry_var = {} - - #List to hold information about device + self.subcircuit_dict_beg={} + self.subcircuit_dict_end={} + #List to hold information about subcircuit self.subDetail = {} #Stores the number of ports in each subcircuit @@ -38,11 +60,31 @@ class SubcircuitTab(QtGui.QWidget): if eachline[0] == 'x': print "Words",words[0] self.obj_trac.subcircuitList.append(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: + print "ROOT ----===-=-",root + 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] + try: + if os.path.exists(child[0].text): + self.entry_var[self.count].setText(child[0].text) + path_name=child[0].text + else: + self.entry_var[self.count].setText("") + except: + print "ERROR WHEN SET TEXT" + except: + print "ERROR BEFORE Subcircuit" + + subgrid.addWidget(self.entry_var[self.count],self.row,1) self.addbtn = QtGui.QPushButton("Add") self.addbtn.setObjectName("%d" %self.count) @@ -62,10 +104,17 @@ class SubcircuitTab(QtGui.QWidget): self.grid.addWidget(subbox) - #Adding Device Details + #Adding Subcircuit Details self.subDetail[self.count] = words[0] - + #Increment row and widget count + + if self.entry_var[self.count].text()=="": + pass + else: + self.trackSubcircuitWithoutButton(self.count,path_name) + + self.subcircuit_dict_end[words[0]]=self.count self.row = self.row+1 self.count = self.count+1 @@ -74,7 +123,7 @@ class SubcircuitTab(QtGui.QWidget): def trackSubcircuit(self): """ - This function is use to keep track of all Device Model widget + This function is use to keep track of all Subcircuit widget """ print "Calling Track Subcircuit function" sending_btn = self.sender() @@ -100,4 +149,29 @@ class SubcircuitTab(QtGui.QWidget): self.msg = QtGui.QErrorMessage(self) self.msg.showMessage("Please select a valid Subcircuit directory (Containing '.sub' file).") self.msg.setWindowTitle("Error Message") + self.msg.show() + + def trackSubcircuitWithoutButton(self,iter_value,path_value): + + self.widgetObjCount = iter_value + + self.subfile = path_value + self.reply = self.obj_validation.validateSub(self.subfile,self.numPorts[self.widgetObjCount - 1]) + if self.reply == "True": + #Setting Library to Text Edit Line + self.entry_var[self.widgetObjCount].setText(self.subfile) + self.subName = self.subDetail[self.widgetObjCount] + + #Storing to track it during conversion + + self.obj_trac.subcircuitTrack[self.subName] = self.subfile + elif self.reply == "PORT": + self.msg = QtGui.QErrorMessage(self) + self.msg.showMessage("Please select a Subcircuit with correct number of ports.") + self.msg.setWindowTitle("Error Message") + self.msg.show() + elif self.reply == "DIREC": + self.msg = QtGui.QErrorMessage(self) + self.msg.showMessage("Please select a valid Subcircuit directory (Containing '.sub' file).") + self.msg.setWindowTitle("Error Message") self.msg.show()
\ No newline at end of file |