summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice/DeviceModel.py
diff options
context:
space:
mode:
authorAthul George2017-12-04 18:36:27 +0530
committerGitHub2017-12-04 18:36:27 +0530
commit2c905bb7414e87f253db58d0e5a3ebc2bb2d5145 (patch)
treef2b2270fd9d2da53e2a579ec8e2b2b8c71f60739 /src/kicadtoNgspice/DeviceModel.py
parent8665dbc0dae4d75377cb25f25afeb7b763b9bff2 (diff)
parent2dab710a7057db25480817943a0a839a75cd0bf4 (diff)
downloadeSim-2c905bb7414e87f253db58d0e5a3ebc2bb2d5145.tar.gz
eSim-2c905bb7414e87f253db58d0e5a3ebc2bb2d5145.tar.bz2
eSim-2c905bb7414e87f253db58d0e5a3ebc2bb2d5145.zip
Merge pull request #64 from FOSSEE/json
Json
Diffstat (limited to 'src/kicadtoNgspice/DeviceModel.py')
-rw-r--r--src/kicadtoNgspice/DeviceModel.py190
1 files changed, 96 insertions, 94 deletions
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)