summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice
diff options
context:
space:
mode:
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r--src/kicadtoNgspice/Analysis.py65
-rw-r--r--src/kicadtoNgspice/Convert.py7
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py65
-rw-r--r--src/kicadtoNgspice/Model.py19
-rw-r--r--src/kicadtoNgspice/Processing.py84
-rw-r--r--src/kicadtoNgspice/Source.py25
-rw-r--r--src/kicadtoNgspice/TrackWidget.py8
7 files changed, 221 insertions, 52 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py
index cde39f8f..a60a2286 100644
--- a/src/kicadtoNgspice/Analysis.py
+++ b/src/kicadtoNgspice/Analysis.py
@@ -8,7 +8,17 @@ import json
class Analysis(QtGui.QWidget):
"""
- This class create Analysis Tab in KicadtoNgspice Window.
+ - This class create Analysis Tab in KicadtoNgspice Window.
+ - Set various track widget options here
+ - AC_entry_var
+ - AC_Parameter
+ - DC_entry_var
+ - DC_Parameter
+ - TRAN_entry_var
+ - TRAN_Parameter
+ - set_Checkbox
+ - AC_type
+ - op_check
"""
def __init__(self, clarg1):
@@ -40,7 +50,9 @@ class Analysis(QtGui.QWidget):
analysisfile = open(os.path.join(projpath, 'analysis'))
content = analysisfile.readline()
+ print("=========================================================")
print("Content of Analysis file :", content)
+ print("=========================================================")
contentlist = content.split()
if contentlist[0] == '.ac':
@@ -88,6 +100,12 @@ class Analysis(QtGui.QWidget):
self.setLayout(self.grid)
self.show()
+ '''
+ - Create the checkboxes for analysis type, under analysis tab
+ - checkbox > checkgrid > checkgroupbtn > checkAC | checkDC | checkTRAN
+ - Trigger enableBox on clicking
+ '''
+
def createCheckBox(self):
self.checkbox = QtGui.QGroupBox()
self.checkbox.setTitle("Select Analysis Type")
@@ -111,6 +129,11 @@ class Analysis(QtGui.QWidget):
return self.checkbox
+ '''
+ - Activate deactive analysis areas according to type
+ - Add analysis data to track_obj from TrackWidget
+ '''
+
def enableBox(self):
if self.checkAC.isChecked():
self.acbox.setDisabled(False)
@@ -130,6 +153,14 @@ class Analysis(QtGui.QWidget):
self.dcbox.setDisabled(True)
self.track_obj.set_CheckBox["ITEMS"] = "TRAN"
+ '''
+ - Designing of AC group in analysis tab
+ - 3 radio buttons - Lin | Dec | Oct
+ - 3 input boxes, with top 2 combos\
+ - If previous values exist then fill default values from
+ previous value json file
+ '''
+
def createACgroup(self):
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
@@ -202,12 +233,14 @@ class Analysis(QtGui.QWidget):
self.acgrid.addWidget(self.start_fre_combo, 2, 2)
self.ac_parameter[0] = "Hz"
+ # Try setting to default value from anaylsis file
try:
self.ac_parameter[self.parameter_cnt] = str(
json_data["analysis"]["ac"]["Start Fre Combo"])
except BaseException:
self.ac_parameter[self.parameter_cnt] = "Hz"
+ # Event listener for combo action
self.start_fre_combo.activated[str].connect(self.start_combovalue)
self.parameter_cnt = self.parameter_cnt + 1
@@ -274,12 +307,23 @@ class Analysis(QtGui.QWidget):
return self.acbox
+ '''
+ - Below 2 functions handle combo value event listeners for
+ - - start frequency for ac
+ - - stop frequency for ac
+ - And accordingly set the ac_parameters
+ '''
+
def start_combovalue(self, text):
self.ac_parameter[0] = str(text)
def stop_combovalue(self, text):
self.ac_parameter[1] = str(text)
+ '''
+ - Set track object for AC, according to the type of radio box selected
+ '''
+
def set_ac_type(self):
self.parameter_cnt = 0
@@ -292,6 +336,10 @@ class Analysis(QtGui.QWidget):
else:
pass
+ '''
+ - Create DC area under analysis tab
+ '''
+
def createDCgroup(self):
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
@@ -564,6 +612,10 @@ class Analysis(QtGui.QWidget):
return self.dcbox
+ '''
+ - Below 6 functions to handle combo boxes for the DC group
+ '''
+
def start_changecombo(self, text):
self.dc_parameter[0] = str(text)
@@ -582,12 +634,20 @@ class Analysis(QtGui.QWidget):
def stop_changecombo2(self, text):
self.dc_parameter[5] = str(text)
+ '''
+ - Handles the Operating point analysis checkbox
+ '''
+
def setflag(self):
if self.check.isChecked():
self.track_obj.op_check.append(1)
else:
self.track_obj.op_check.append(0)
+ '''
+ - Creating transient group under analysis and creating it's components
+ '''
+
def createTRANgroup(self):
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
@@ -717,6 +777,9 @@ class Analysis(QtGui.QWidget):
print("Transient Analysis JSON Parse Error")
return self.trbox
+ '''
+ - Below 3 functions handle event for the combo box in transient group
+ '''
def start_combo_change(self, text):
self.tran_parameter[0] = str(text)
diff --git a/src/kicadtoNgspice/Convert.py b/src/kicadtoNgspice/Convert.py
index 38234fed..51daa1de 100644
--- a/src/kicadtoNgspice/Convert.py
+++ b/src/kicadtoNgspice/Convert.py
@@ -39,7 +39,7 @@ class Convert:
str(self.entry_var[self.start].text())) > 0 else '0'
va_val = str(
self.entry_var[self.start + 1].text()
- ) if len(
+ ) if len(
str(self.entry_var[self.start + 1].text())) \
> 0 else '0'
freq_val = str(self.entry_var[self.start + 2].text()) \
@@ -440,7 +440,10 @@ class Convert:
param = key
default = 0
# Cheking if value is iterable.its for vector
- if hasattr(value, '__iter__'):
+ if (
+ hasattr(value, '__iter__')
+ and type(value) is not str
+ ):
addmodelLine += param + "=["
for lineVar in value:
if str(
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index dfc7cff8..833bd6cc 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -33,11 +33,13 @@ import json
class MainWindow(QtGui.QWidget):
"""
- This class create KicadtoNgspice window.
- And Call Convert function if convert button is pressed.
- The convert function takes all the value entered by user and create
- a final netlist "*.cir.out".
- This final netlist is compatible with NgSpice.
+ - This class create KicadtoNgspice window.
+ - And Call Convert function if convert button is pressed.
+ - The convert function takes all the value entered by user and create
+ a final netlist "*.cir.out".
+ - This final netlist is compatible with NgSpice.
+ - clarg1 is the path to the .cir file
+ - clarg2 is either None or "sub" depending on the analysis type
"""
def __init__(self, clarg1, clarg2=None):
@@ -52,6 +54,7 @@ class MainWindow(QtGui.QWidget):
self.clarg2 = clarg2
# Create object of track widget
+ # Track the dynamically created widget of KicadtoNgSpice Window
self.obj_track = TrackWidget.TrackWidget()
# Clear Dictionary/List item of sub circuit and ngspice model
@@ -65,9 +68,9 @@ class MainWindow(QtGui.QWidget):
# Object of Processing
obj_proc = PrcocessNetlist()
- # Read the netlist
+ # Read the netlist, ie the .cir file
kicadNetlist = obj_proc.readNetlist(self.kicadFile)
-
+ print("=============================================================")
print("Given Kicad Schematic Netlist Info :", kicadNetlist)
# Construct parameter information
@@ -75,13 +78,13 @@ class MainWindow(QtGui.QWidget):
# Replace parameter with values
netlist, infoline = obj_proc.preprocessNetlist(kicadNetlist, param)
-
+ print("=============================================================")
print("Schematic Info after processing Kicad Netlist: ", netlist)
# print "INFOLINE",infoline
# Separate option and schematic information
optionInfo, schematicInfo = obj_proc.separateNetlistInfo(netlist)
-
+ print("=============================================================")
print("OPTIONINFO in the Netlist", optionInfo)
# List for storing source and its value
@@ -92,15 +95,23 @@ class MainWindow(QtGui.QWidget):
schematicInfo, sourcelist)
# List storing model detail
- global modelList, outputOption, unknownModelList, multipleModelList, plotText
+ global modelList, outputOption,\
+ unknownModelList, multipleModelList, plotText
modelList = []
outputOption = []
plotText = []
- schematicInfo, outputOption, modelList, unknownModelList, multipleModelList, plotText = obj_proc.convertICintoBasicBlocks(
- schematicInfo, outputOption, modelList, plotText
- )
-
+ (
+ schematicInfo,
+ outputOption,
+ modelList,
+ unknownModelList,
+ multipleModelList,
+ plotText
+ ) = obj_proc.convertICintoBasicBlocks(
+ schematicInfo, outputOption, modelList, plotText
+ )
+ print("=======================================")
print("Model available in the Schematic :", modelList)
"""
@@ -128,11 +139,11 @@ class MainWindow(QtGui.QWidget):
else:
self.createMainWindow()
- def createMainWindow(self):
- """
- This function create main window of Kicad to Ngspice converter
- """
+ """
+ This function create main window of Kicad to Ngspice converter
+ """
+ def createMainWindow(self):
self.vbox = QtGui.QVBoxLayout(self)
self.hbox = QtGui.QHBoxLayout(self)
self.hbox.addStretch(1)
@@ -450,7 +461,11 @@ class MainWindow(QtGui.QWidget):
json_data["model"][line[3]]["values"] = []
for key, value in line[7].items():
- if hasattr(value, '__iter__') and i <= end:
+ if(
+ hasattr(value, '__iter__') and
+ i <= end and type(value) is not
+ str
+ ):
for item in value:
fields = {
item: str(
@@ -503,21 +518,24 @@ class MainWindow(QtGui.QWidget):
self.obj_track.sourcelisttrack["ITEMS"],
self.obj_track.source_entry_var["ITEMS"],
store_schematicInfo, self.clarg1
- )
+ )
try:
# Adding Source Value to Schematic Info
store_schematicInfo = self.obj_convert.addSourceParameter()
+ print("=========================================================")
print("Netlist After Adding Source details :", store_schematicInfo)
# Adding Model Value to store_schematicInfo
store_schematicInfo = self.obj_convert.addModelParameter(
store_schematicInfo)
+ print("=========================================================")
print("Netlist After Adding Ngspice Model :", store_schematicInfo)
# Adding Device Library to SchematicInfo
store_schematicInfo = self.obj_convert.addDeviceLibrary(
store_schematicInfo, self.kicadFile)
+ print("=========================================================")
print(
"Netlist After Adding Device Model Library :",
store_schematicInfo)
@@ -525,6 +543,7 @@ class MainWindow(QtGui.QWidget):
# Adding Subcircuit Library to SchematicInfo
store_schematicInfo = self.obj_convert.addSubcircuit(
store_schematicInfo, self.kicadFile)
+ print("=========================================================")
print("Netlist After Adding subcircuits :", store_schematicInfo)
analysisoutput = self.obj_convert.analysisInsertor(
@@ -538,7 +557,7 @@ class MainWindow(QtGui.QWidget):
self.obj_track.AC_type["ITEMS"],
self.obj_track.op_check
)
-
+ print("=========================================================")
print("Analysis OutPut ", analysisoutput)
# Calling netlist file generation function
@@ -561,6 +580,7 @@ class MainWindow(QtGui.QWidget):
self.createSubFile(subPath)
def createNetlistFile(self, store_schematicInfo, plotText):
+ print("=============================================================")
print("Creating Final netlist")
# print "INFOLINE",infoline
# print "OPTIONINFO",optionInfo
@@ -588,6 +608,7 @@ class MainWindow(QtGui.QWidget):
Please check it")
sys.exit()
else:
+ print("========================================================")
print(analysisFileLoc + " does not exist")
sys.exit()
@@ -673,6 +694,7 @@ class MainWindow(QtGui.QWidget):
except BaseException:
print("Error in opening .cir.out file.")
else:
+ print("=========================================================")
print(
self.projName +
".cir.out does not exist. Please create a spice netlist.")
@@ -732,4 +754,5 @@ class MainWindow(QtGui.QWidget):
out.writelines('\n')
out.writelines('.ends ' + self.projName)
+ print("=============================================================")
print("The subcircuit has been written in " + self.projName + ".sub")
diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py
index e9b5822a..9af7cbfb 100644
--- a/src/kicadtoNgspice/Model.py
+++ b/src/kicadtoNgspice/Model.py
@@ -7,8 +7,8 @@ import os
class Model(QtGui.QWidget):
"""
- This class creates Model Tab of KicadtoNgspice window.
- The widgets are created dynamically in the Model Tab.
+ - This class creates Model Tab of KicadtoNgspice window.
+ The widgets are created dynamically in the Model Tab.
"""
def __init__(self, schematicInfo, modelList, clarg1):
@@ -62,7 +62,7 @@ class Model(QtGui.QWidget):
# print "Key : ",key
# print "Value : ",value
# Check if value is iterable
- if hasattr(value, '__iter__'):
+ if hasattr(value, '__iter__') and type(value) is not str:
# For tag having vector value
temp_tag = []
for item in value:
@@ -78,7 +78,7 @@ class Model(QtGui.QWidget):
try:
for mod in json_data["model"]:
if json_data["model"][mod]["type"] ==\
- line[2] and mod == line[3]:
+ line[2] and mod == line[3]:
self.obj_trac.model_entry_var
[self.nextcount].setText(
str(list(
@@ -96,17 +96,18 @@ class Model(QtGui.QWidget):
else:
paramLabel = QtGui.QLabel(value)
modelgrid.addWidget(paramLabel, self.nextrow, 0)
- self.obj_trac.model_entry_var
- [self.nextcount] = QtGui.QLineEdit(
+ self.obj_trac.model_entry_var[self.nextcount] = (
+ QtGui.QLineEdit()
)
modelgrid.addWidget(
- self.obj_trac.model_entry_var
- [self.nextcount], self.nextrow, 1)
+ self.obj_trac.model_entry_var[self.nextcount],
+ self.nextrow, 1
+ )
try:
for mod in json_data["model"]:
if json_data["model"][mod]["type"] ==\
- line[2] and mod == line[3]:
+ line[2] and mod == line[3]:
self.obj_trac.model_entry_var
[self.nextcount].setText(
str(list(json_data
diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py
index 63847761..bd1b45dc 100644
--- a/src/kicadtoNgspice/Processing.py
+++ b/src/kicadtoNgspice/Processing.py
@@ -13,15 +13,29 @@ class PrcocessNetlist:
def __init__(self):
pass
+ """
+ - Read the circuit file and return splitted lines
+ """
+
def readNetlist(self, filename):
f = open(filename)
data = f.read()
f.close()
+ print("=============================================================")
+ print("readNetList called, from Processing")
+ print("=============================================================")
+ print("NETLIST", data.splitlines())
+ print("=============================================================")
return data.splitlines()
+ """
+ - Read Parameter information and store it into dictionary
+ - kicadNetlis is the .cir file content
+ """
+
def readParamInfo(self, kicadNetlis):
- """Read Parameter information and store it into dictionary"""
param = {}
+ print("=========================KICADNETLIST========================")
for eachline in kicadNetlis:
print(eachline)
eachline = eachline.strip()
@@ -32,10 +46,18 @@ class PrcocessNetlist:
for i in range(1, len(words), 1):
paramList = words[i].split('=')
param[paramList[0]] = paramList[1]
+ print("=============================================================")
+ print("readParamInfo called, from Processing")
+ print("=============================================================")
+ print("PARAM", param)
+ print("=============================================================")
return param
+ """
+ - Preprocess netlist (replace parameters)
+ """
+
def preprocessNetlist(self, kicadNetlis, param):
- """Preprocess netlist (replace parameters)"""
netlist = []
for eachline in kicadNetlis:
# Remove leading and trailing blanks spaces from line
@@ -66,6 +88,12 @@ class PrcocessNetlist:
# Copy information line
infoline = netlist[0]
netlist.remove(netlist[0])
+ print("=============================================================")
+ print("preprocessNetList called, from Processing")
+ print("=============================================================")
+ print("NETLIST", netlist)
+ print("INFOLINE", infoline)
+ print("=============================================================")
return netlist, infoline
def separateNetlistInfo(self, netlist):
@@ -78,14 +106,24 @@ class PrcocessNetlist:
optionInfo.append(eachline)
else:
schematicInfo.append(eachline)
+ print("=============================================================")
+ print("separateNetlistInfo called, from Processing")
+ print("=============================================================")
+ print("OPTIONINFO", optionInfo)
+ print("SCHEMATICINFO", schematicInfo)
+ print("=============================================================")
return optionInfo, schematicInfo
+ """
+ - Insert Special source parameter
+ - As per the parameters passed create source list
+ """
+
def insertSpecialSourceParam(self, schematicInfo, sourcelist):
- # Inser Special source parameter
schematicInfo1 = []
-
+ print("=============================================================")
print("Reading schematic info for source details")
-
+ print("=============================================================")
for compline in schematicInfo:
words = compline.split()
compName = words[0]
@@ -171,10 +209,17 @@ class PrcocessNetlist:
schematicInfo = schematicInfo + schematicInfo1
print("Source List : ", sourcelist)
# print schematicInfo
+ print("=============================================================")
+ print("insertSpecialSourceParam called, from Processing")
+ print("=============================================================")
+ print("SCHEMATICINFO", schematicInfo)
+ print("SOURCELIST", sourcelist)
+ print("=============================================================")
return schematicInfo, sourcelist
def convertICintoBasicBlocks(
self, schematicInfo, outputOption, modelList, plotText):
+ print("=============================================================")
print("Reading Schematic info for Model")
# Insert details of Ngspice model
unknownModelList = []
@@ -228,6 +273,8 @@ class PrcocessNetlist:
unknownModelList.append(compType)
elif count == 1:
try:
+ print("==========================================\
+ ===========================")
print(
"Start Parsing Previous Values XML\
for ngspice model :", modelPath)
@@ -265,7 +312,7 @@ class PrcocessNetlist:
if 'default' in item.attrib:
paramDict[item.tag + ":" +
item.attrib['default']] \
- = temp_list
+ = temp_list
else:
paramDict[item.tag] = item.text
@@ -273,7 +320,7 @@ class PrcocessNetlist:
if 'default' in item.attrib:
paramDict[item.tag + ":" +
item.attrib['default']]\
- = item.text
+ = item.text
else:
paramDict[item.tag] = item.text
@@ -288,6 +335,8 @@ class PrcocessNetlist:
modelLine += compName
else:
+ print("=====================================\
+ ================================")
print("Split Details :", splitDetail)
modelLine = "a" + str(k) + " "
vectorDetail = splitDetail.split(':')
@@ -302,7 +351,7 @@ class PrcocessNetlist:
for i in range(0, int(
item.split("-")[0])):
modelLine += words[pos] +\
- " "
+ " "
pos += 1
modelLine += ") "
else:
@@ -310,7 +359,7 @@ class PrcocessNetlist:
for i in range(0, int(
item.split("-")[0])):
modelLine += words[pos] + \
- " "
+ " "
pos += 1
modelLine += "] "
elif item.split("-")[1] == 'NV':
@@ -436,16 +485,27 @@ class PrcocessNetlist:
else:
schematicInfo.insert(index, "* " + compline)
-
+ print("=====================================================")
print(
"UnknownModelList Used in the Schematic",
unknownModelList)
+ print("=====================================================")
print(
"Multiple Model XML file with same name ",
multipleModelList)
+ print("=====================================================")
print("Model List Details : ", modelList)
-
+ print("=============================================================")
+ print("convertICIntoBasicBlocks called, from Processing")
+ print("=============================================================")
+ print("SCHEMATICINFO", schematicInfo)
+ print("OUTPUTOPTION", outputOption)
+ print("MODELLIST", modelList)
+ print("UNKOWNMODELLIST", unknownModelList)
+ print("MULTIPLEMODELLIST", multipleModelList)
+ print("PLOTTEST", plotText)
+ print("=============================================================")
return (
schematicInfo, outputOption, modelList, unknownModelList,
multipleModelList, plotText
- )
+ )
diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py
index 8649ce93..d8e39af4 100644
--- a/src/kicadtoNgspice/Source.py
+++ b/src/kicadtoNgspice/Source.py
@@ -25,11 +25,23 @@ class Source(QtGui.QWidget):
# Creating Source Widget
self.createSourceWidget(sourcelist, sourcelisttrack)
+ """
+ - This function dynamically create source widget in the
+ Source tab of KicadtoNgSpice window
+ - Depending on the type of source, ac, dc, sine, pwl, etc...
+ source tab is created
+ - All the entry fields, are kept into the entry_var
+ tracked by self.count
+ - Finally after each of the sourcelist is mapped to its input component
+ we move to adding these to the track widget
+ - Also check if any default values present from previous analysis and add
+ them by default
+ """
+
def createSourceWidget(self, sourcelist, sourcelisttrack):
- """
- This function dynamically create source widget in the
- Source tab of KicadtoNgSpice window
- """
+ print("============================================================")
+ print("SOURCELISTTRACK", sourcelisttrack)
+ print("============================================================")
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
project_name = os.path.basename(projpath)
@@ -328,8 +340,8 @@ class Source(QtGui.QWidget):
list(
json_data["source"][key]
["values"][it - 4].values())[0]
- )
- )
+ )
+ )
except BaseException:
pass
@@ -353,6 +365,7 @@ class Source(QtGui.QWidget):
else:
print("No source is present in your circuit")
+ print("============================================================")
# This is used to keep the track of dynamically created widget
self.obj_track.sourcelisttrack["ITEMS"] = sourcelisttrack
self.obj_track.source_entry_var["ITEMS"] = self.entry_var
diff --git a/src/kicadtoNgspice/TrackWidget.py b/src/kicadtoNgspice/TrackWidget.py
index dcf85dca..ec5c2c81 100644
--- a/src/kicadtoNgspice/TrackWidget.py
+++ b/src/kicadtoNgspice/TrackWidget.py
@@ -1,6 +1,12 @@
class TrackWidget:
"""
- This Class track the dynamically created widget of KicadtoNgSpice Window.
+ - This Class track the dynamically created widget of KicadtoNgSpice Window.
+ - Tracks using dictionary and lists ==>
+ - - Sources
+ - - Parameters
+ - - References
+ - - Model Details
+ - - ... etc
"""
# Track widget list for Source details
sourcelisttrack = {"ITEMS": "None"}