summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice/Convert.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/kicadtoNgspice/Convert.py')
-rw-r--r--src/kicadtoNgspice/Convert.py219
1 files changed, 139 insertions, 80 deletions
diff --git a/src/kicadtoNgspice/Convert.py b/src/kicadtoNgspice/Convert.py
index 924f94fa..38234fed 100644
--- a/src/kicadtoNgspice/Convert.py
+++ b/src/kicadtoNgspice/Convert.py
@@ -8,7 +8,8 @@ from xml.etree import ElementTree as ET
class Convert:
"""
- This class has all the necessary function required to convert kicad netlist to ngspice netlist.
+ This class has all the necessary function required to convert
+ kicad netlist to ngspice netlist.
"""
def __init__(self, sourcelisttrack, source_entry_var,
@@ -36,16 +37,24 @@ class Convert:
self.end = compline[3]
vo_val = str(self.entry_var[self.start].text()) if len(
str(self.entry_var[self.start].text())) > 0 else '0'
- va_val = str(self.entry_var[self.start + 1].text()) if len(
- str(self.entry_var[self.start + 1].text())) > 0 else '0'
- freq_val = str(self.entry_var[self.start + 2].text()) if len(
- str(self.entry_var[self.start + 2].text())) > 0 else '0'
+ va_val = str(
+ self.entry_var[self.start + 1].text()
+ ) if len(
+ str(self.entry_var[self.start + 1].text())) \
+ > 0 else '0'
+ freq_val = str(self.entry_var[self.start + 2].text()) \
+ if len(
+ str(self.entry_var[self.start + 2].text())) > \
+ 0 else '0'
td_val = str(self.entry_var[self.start + 3].text()) if len(
- str(self.entry_var[self.start + 3].text())) > 0 else '0'
+ str(self.entry_var[self.start + 3].text())) > \
+ 0 else '0'
theta_val = str(self.entry_var[self.end].text()) if len(
str(self.entry_var[self.end].text())) > 0 else '0'
self.addline = self.addline.partition(
- '(')[0] + "(" + vo_val + " " + va_val + " " + freq_val + " " + td_val + " " + theta_val + ")"
+ '(')[0] + "(" + vo_val + " " + va_val + " " +\
+ freq_val + " " + td_val + " " +\
+ theta_val + ")"
self.sourcelistvalue.append([self.index, self.addline])
except BaseException:
print(
@@ -59,20 +68,28 @@ class Convert:
v1_val = str(self.entry_var[self.start].text()) if len(
str(self.entry_var[self.start].text())) > 0 else '0'
v2_val = str(self.entry_var[self.start + 1].text()) if len(
- str(self.entry_var[self.start + 1].text())) > 0 else '0'
- td_val = str(self.entry_var[self.start + 2].text()) if len(
- str(self.entry_var[self.start + 2].text())) > 0 else '0'
+ str(self.entry_var[self.start + 1].text())) > \
+ 0 else '0'
+ td_val = str(self.entry_var[self.start + 2].text()) \
+ if len(
+ str(self.entry_var[self.start + 2].text())) > \
+ 0 else '0'
tr_val = str(self.entry_var[self.start + 3].text()) if len(
- str(self.entry_var[self.start + 3].text())) > 0 else '0'
+ str(self.entry_var[self.start + 3].text())) > \
+ 0 else '0'
tf_val = str(self.entry_var[self.start + 4].text()) if len(
- str(self.entry_var[self.start + 4].text())) > 0 else '0'
+ str(self.entry_var[self.start + 4].text())) > \
+ 0 else '0'
pw_val = str(self.entry_var[self.start + 5].text()) if len(
- str(self.entry_var[self.start + 5].text())) > 0 else '0'
+ str(self.entry_var[self.start + 5].text())) > \
+ 0 else '0'
tp_val = str(self.entry_var[self.end].text()) if len(
str(self.entry_var[self.end].text())) > 0 else '0'
self.addline = self.addline.partition(
- '(')[0] + "(" + v1_val + " " + v2_val + " " + td_val + " " + tr_val + " " + tf_val + " " + pw_val + " " + tp_val + ")"
+ '(')[0] + "(" + v1_val + " " + v2_val + " " +\
+ td_val + " " + tr_val + " " + tf_val + " " +\
+ pw_val + " " + tp_val + ")"
self.sourcelistvalue.append([self.index, self.addline])
except BaseException:
print(
@@ -100,7 +117,8 @@ class Convert:
va_val = str(self.entry_var[self.start].text()) if len(
str(self.entry_var[self.start].text())) > 0 else '0'
ph_val = str(self.entry_var[self.start + 1].text()) if len(
- str(self.entry_var[self.start + 1].text())) > 0 else '0'
+ str(self.entry_var[self.start + 1].text())) > \
+ 0 else '0'
self.addline = ' '.join(self.addline.split())
self.addline = self.addline.partition(
'ac')[0] + " " + 'ac' + " " + va_val + " " + ph_val
@@ -132,18 +150,27 @@ class Convert:
v1_val = str(self.entry_var[self.start].text()) if len(
str(self.entry_var[self.start].text())) > 0 else '0'
v2_val = str(self.entry_var[self.start + 1].text()) if len(
- str(self.entry_var[self.start + 1].text())) > 0 else '0'
- td1_val = str(self.entry_var[self.start + 2].text()) if len(
- str(self.entry_var[self.start + 2].text())) > 0 else '0'
- tau1_val = str(self.entry_var[self.start + 3].text()) if len(
- str(self.entry_var[self.start + 3].text())) > 0 else '0'
- td2_val = str(self.entry_var[self.start + 4].text()) if len(
- str(self.entry_var[self.start + 4].text())) > 0 else '0'
+ str(self.entry_var[self.start + 1].text())) > \
+ 0 else '0'
+ td1_val = str(self.entry_var[self.start + 2].text()) \
+ if len(
+ str(self.entry_var[self.start + 2].text())) > \
+ 0 else '0'
+ tau1_val = str(self.entry_var[self.start + 3].text()) \
+ if len(
+ str(self.entry_var[self.start + 3].text())) > \
+ 0 else '0'
+ td2_val = str(self.entry_var[self.start + 4].text()) \
+ if len(
+ str(self.entry_var[self.start + 4].text())) > \
+ 0 else '0'
tau2_val = str(self.entry_var[self.end].text()) if len(
str(self.entry_var[self.end].text())) > 0 else '0'
self.addline = self.addline.partition(
- '(')[0] + "(" + v1_val + " " + v2_val + " " + td1_val + " " + tau1_val + " " + td2_val + " " + tau2_val + ")"
+ '(')[0] + "(" + v1_val + " " + v2_val + " " +\
+ td1_val + " " + tau1_val + " " + td2_val +\
+ " " + tau2_val + ")"
self.sourcelistvalue.append([self.index, self.addline])
except BaseException:
print(
@@ -158,7 +185,8 @@ class Convert:
return self.schematicInfo
def analysisInsertor(self, ac_entry_var, dc_entry_var, tran_entry_var,
- set_checkbox, ac_parameter, dc_parameter, tran_parameter, ac_type, op_check):
+ set_checkbox, ac_parameter, dc_parameter,
+ tran_parameter, ac_type, op_check):
"""
This function creates an analysis file in current project
"""
@@ -184,14 +212,15 @@ class Convert:
' ' +
self.ac_type +
' ' +
- str(self.defaultvalue(self.ac_entry_var[self.no +
- 2].text())) +
+ str(self.defaultvalue(
+ self.ac_entry_var[self.no + 2].text())) +
' ' +
- str(self.defaultvalue(self.ac_entry_var[self.no].text())) +
+ str(self.defaultvalue(
+ self.ac_entry_var[self.no].text())) +
self.ac_parameter[self.no] +
' ' +
- str(self.defaultvalue(self.ac_entry_var[self.no +
- 1].text())) +
+ str(self.defaultvalue(
+ self.ac_entry_var[self.no + 1].text())) +
self.ac_parameter[self.no +
1])
@@ -205,56 +234,75 @@ class Convert:
' ' +
str(self.dc_entry_var[self.no].text()) +
' ' +
- str(self.defaultvalue(self.dc_entry_var[self.no +
- 1].text())) +
- self.converttosciform(self.dc_parameter[self.no]) +
+ str(self.defaultvalue(
+ self.dc_entry_var[self.no +
+ 1].text())) +
+ self.converttosciform(
+ self.dc_parameter[self.no]) +
' ' +
- str(self.defaultvalue(self.dc_entry_var[self.no +
- 3].text())) +
- self.converttosciform(self.dc_parameter[self.no +
- 2]) +
+ str(self.defaultvalue(
+ self.dc_entry_var[self.no +
+ 3].text())) +
+ self.converttosciform(
+ self.dc_parameter[self.no +
+ 2]) +
' ' +
- str(self.defaultvalue(self.dc_entry_var[self.no +
- 2].text())) +
- self.converttosciform(self.dc_parameter[self.no +
- 1]))
+ str(self.defaultvalue(
+ self.dc_entry_var[self.no +
+ 2].text())) +
+ self.converttosciform(
+ self.dc_parameter[self.no +
+ 1]))
if self.dc_entry_var[self.no + 4].text():
self.writefile.write(' ' +
- str(self.defaultvalue(self.dc_entry_var[self.no +
- 4].text())) +
+ str(self.defaultvalue(
+ self.dc_entry_var[self.no +
+ 4].text())) +
' ' +
- str(self.defaultvalue(self.dc_entry_var[self.no +
- 5].text())) +
- self.converttosciform(self.dc_parameter[self.no +
- 3]) +
+ str(self.defaultvalue(
+ self.dc_entry_var[self.no +
+ 5].text())) +
+ self.converttosciform(
+ self.dc_parameter[self.no +
+ 3]) +
' ' +
- str(self.defaultvalue(self.dc_entry_var[self.no +
- 7].text())) +
- self.converttosciform(self.dc_parameter[self.no +
- 5]) +
+ str(self.defaultvalue(
+ self.dc_entry_var[self.no +
+ 7].text())) +
+ self.converttosciform(
+ self.dc_parameter[self.no +
+ 5]) +
' ' +
- str(self.defaultvalue(self.dc_entry_var[self.no +
- 6].text())) +
- self.converttosciform(self.dc_parameter[self.no +
- 4]))
+ str(self.defaultvalue(
+ self.dc_entry_var[self.no +
+ 6].text())) +
+ self.converttosciform(
+ self.dc_parameter[self.no +
+ 4]))
elif self.variable == 'TRAN':
self.no = 0
self.writefile.write(".tran" +
' ' +
- str(self.defaultvalue(self.tran_entry_var[self.no +
- 1].text())) +
- self.converttosciform(self.trans_parameter[self.no +
- 1]) +
+ str(self.defaultvalue(
+ self.tran_entry_var[self.no +
+ 1].text())) +
+ self.converttosciform(
+ self.trans_parameter[self.no +
+ 1]) +
' ' +
- str(self.defaultvalue(self.tran_entry_var[self.no +
- 2].text())) +
- self.converttosciform(self.trans_parameter[self.no +
- 2]) +
+ str(self.defaultvalue(
+ self.tran_entry_var[self.no +
+ 2].text())) +
+ self.converttosciform(
+ self.trans_parameter[self.no +
+ 2]) +
' ' +
- str(self.defaultvalue(self.tran_entry_var[self.no].text())) +
- self.converttosciform(self.trans_parameter[self.no]))
+ str(self.defaultvalue(
+ self.tran_entry_var[self.no].text())) +
+ self.converttosciform(
+ self.trans_parameter[self.no]))
else:
pass
@@ -278,7 +326,8 @@ class Convert:
def defaultvalue(self, value):
"""
- This function select default value as 0 if Analysis widget do not hold any value.
+ This function select default value as 0
+ if Analysis widget do not hold any value.
"""
self.value = value
if self.value == '':
@@ -299,11 +348,11 @@ class Convert:
modelParamValue = []
for line in self.obj_track.modelTrack:
- #print "Model Track :",line
+ # print "Model Track :",line
if line[2] == 'transfo':
try:
start = line[7]
- end = line[8]
+ # end = line[8]
num_turns = str(
self.obj_track.model_entry_var[start + 1].text())
@@ -319,7 +368,11 @@ class Convert:
b_array = b_array + b1 + " "
bh_array = h_array + " ] " + b_array + " ]"
else:
- bh_array = "H_array = [-1000 -500 -375 -250 -188 -125 -63 0 63 125 188 250 375 500 1000] B_array = [-3.13e-3 -2.63e-3 -2.33e-3 -1.93e-3 -1.5e-3 -6.25e-4 -2.5e-4 0 2.5e-4 6.25e-4 1.5e-3 1.93e-3 2.33e-3 2.63e-3 3.13e-3]"
+ bh_array = "H_array = [-1000 -500 -375 -250 -188 -125 \
+ -63 0 63 125 188 250 375 500 \
+ 1000] B_array = [-3.13e-3 -2.63e-3 -2.33e-3 -1.93e-3\
+ -1.5e-3 -6.25e-4 -2.5e-4 0 2.5e-4 6.25e-4 \
+ 1.5e-3 1.93e-3 2.33e-3 2.63e-3 3.13e-3]"
area = str(
self.obj_track.model_entry_var[start + 2].text())
length = str(
@@ -354,7 +407,7 @@ class Convert:
elif line[2] == 'ic':
try:
start = line[7]
- end = line[8]
+ # end = line[8]
for key, value in line[9].items():
initVal = str(
self.obj_track.model_entry_var[value].text())
@@ -372,11 +425,11 @@ class Convert:
else:
try:
start = line[7]
- end = line[8]
+ # end = line[8]
addmodelLine = ".model " + line[3] + " " + line[2] + "("
for key, value in line[9].items():
- #print "Tags: ",key
- #print "Value: ",value
+ # print "Tags: ",key
+ # print "Value: ",value
# Checking for default value and accordingly assign
# param and default.
if ':' in key:
@@ -391,20 +444,24 @@ class Convert:
addmodelLine += param + "=["
for lineVar in value:
if str(
- self.obj_track.model_entry_var[lineVar].text()) == "":
+ self.obj_track.model_entry_var
+ [lineVar].text()) == "":
paramVal = default
else:
paramVal = str(
- self.obj_track.model_entry_var[lineVar].text())
+ self.obj_track.model_entry_var
+ [lineVar].text())
addmodelLine += paramVal + " "
addmodelLine += "] "
else:
if str(
- self.obj_track.model_entry_var[value].text()) == "":
+ self.obj_track.model_entry_var
+ [value].text()) == "":
paramVal = default
else:
paramVal = str(
- self.obj_track.model_entry_var[value].text())
+ self.obj_track.model_entry_var
+ [value].text())
addmodelLine += param + "=" + paramVal + " "
@@ -433,7 +490,8 @@ class Convert:
(projpath, filename) = os.path.split(kicadFile)
deviceLibList = self.obj_track.deviceModelTrack
- deviceLine = {} # Key:Index, Value:with its updated line in the form of list
+ deviceLine = {}
+ # Key:Index, Value:with its updated line in the form of list
includeLine = [] # All .include line list
if not deviceLibList:
@@ -457,7 +515,7 @@ class Convert:
libname = tempStr[0]
dimension = tempStr[1]
# Replace last word with library name
- #words[-1] = libname.split('.')[0]
+ # words[-1] = libname.split('.')[0]
words[-1] = self.getRefrenceName(libname, libpath)
# Appending Dimension of MOSFET
words.append(dimension)
@@ -474,7 +532,7 @@ class Convert:
shutil.copy2(src, dst)
else:
# Replace last word with library name
- #words[-1] = libname.split('.')[0]
+ # words[-1] = libname.split('.')[0]
words[-1] = self.getRefrenceName(libname, libpath)
deviceLine[index] = words
includeLine.append(".include " + libname)
@@ -507,7 +565,8 @@ class Convert:
(projpath, filename) = os.path.split(kicadFile)
subList = self.obj_track.subcircuitTrack
- subLine = {} # Key:Index, Value:with its updated line in the form of list
+ subLine = {}
+ # Key:Index, Value:with its updated line in the form of list
includeLine = [] # All .include line list
if len(self.obj_track.subcircuitList) != len(