summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice
diff options
context:
space:
mode:
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r--src/kicadtoNgspice/Analysis.py86
-rw-r--r--src/kicadtoNgspice/Convert.py13
-rw-r--r--src/kicadtoNgspice/DeviceModel.py35
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py214
-rw-r--r--src/kicadtoNgspice/Model.py48
-rw-r--r--src/kicadtoNgspice/Processing.py116
-rw-r--r--src/kicadtoNgspice/Source.py21
-rw-r--r--src/kicadtoNgspice/SubcircuitTab.py27
-rw-r--r--src/kicadtoNgspice/TrackWidget.py8
9 files changed, 437 insertions, 131 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py
index cde39f8f..c5981f4d 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):
@@ -26,6 +36,14 @@ class Analysis(QtGui.QWidget):
self.createAnalysisWidget()
def createAnalysisWidget(self):
+ """
+ - Create the main anaylsis widget overwiew
+ - - Checkbox for analysis type
+ - - Respective analysis type group, AC, DC, TRAN...
+ - Check for `analysis` file, if any in projDir, extract data from it
+ - Else set the default checkbox to `TRAN`
+ - Accordingly set state for track widget options
+ """
self.grid = QtGui.QGridLayout()
self.grid.addWidget(self.createCheckBox(), 0, 0)
self.grid.addWidget(self.createACgroup(), 1, 0)
@@ -40,7 +58,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':
@@ -89,6 +109,11 @@ class Analysis(QtGui.QWidget):
self.show()
def createCheckBox(self):
+ """
+ - Create the checkboxes for analysis type, under analysis tab
+ - checkbox > checkgrid > checkgroupbtn > checkAC | checkDC | checkTRAN
+ - Trigger enableBox on clicking
+ """
self.checkbox = QtGui.QGroupBox()
self.checkbox.setTitle("Select Analysis Type")
self.checkgrid = QtGui.QGridLayout()
@@ -112,6 +137,10 @@ class Analysis(QtGui.QWidget):
return self.checkbox
def enableBox(self):
+ """
+ - Activate deactive analysis areas according to type
+ - Add analysis data to track_obj from TrackWidget
+ """
if self.checkAC.isChecked():
self.acbox.setDisabled(False)
self.dcbox.setDisabled(True)
@@ -131,6 +160,13 @@ class Analysis(QtGui.QWidget):
self.track_obj.set_CheckBox["ITEMS"] = "TRAN"
def createACgroup(self):
+ """
+ - 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
+ """
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
project_name = os.path.basename(projpath)
@@ -202,12 +238,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,13 +312,33 @@ 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):
+ """
+ - Handle start_fre_combo box event
+ - Check where it is Hz, MHz, etc.
+ - Accordingly set ac_parameter
+ """
self.ac_parameter[0] = str(text)
def stop_combovalue(self, text):
+ """
+ - Handle stop_fre_combo box event
+ - Check where it is Hz, MHz, etc.
+ - Accordingly set ac_parameter
+ """
self.ac_parameter[1] = str(text)
def set_ac_type(self):
+ """S
+ - Set track object for AC, according to the type of radio box selected
+ """
self.parameter_cnt = 0
if self.Lin.isChecked():
@@ -293,6 +351,16 @@ class Analysis(QtGui.QWidget):
pass
def createDCgroup(self):
+ """
+ - Create DC area under analysis tab
+ - Source 1 and 2, each having 4 input boxes as follows
+ - - Source
+ - - Start
+ - - Increment
+ - - Stop
+ - The last 3 have combo box pertaining to their unit as well
+ - Also in the end a checkbox, for operating system point analysis
+ """
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
project_name = os.path.basename(projpath)
@@ -564,6 +632,7 @@ 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)
@@ -583,12 +652,24 @@ class Analysis(QtGui.QWidget):
self.dc_parameter[5] = str(text)
def setflag(self):
+ """
+ - Handles the Operating point analysis checkbox
+ """
if self.check.isChecked():
self.track_obj.op_check.append(1)
else:
self.track_obj.op_check.append(0)
def createTRANgroup(self):
+ """
+ - Creating transient group under analysis and creating it's components
+ - Contains 3 inout and combo boxes for -
+ - - Start time
+ - - Step time
+ - - Stop time
+ - Input boxes for values, combo boxes for unit
+ - Accordingly also event handleres for combo boxes, creates 3 functions
+ """
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
project_name = os.path .basename(projpath)
@@ -717,6 +798,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..76b6ba57 100644
--- a/src/kicadtoNgspice/Convert.py
+++ b/src/kicadtoNgspice/Convert.py
@@ -8,7 +8,7 @@ from xml.etree import ElementTree as ET
class Convert:
"""
- This class has all the necessary function required to convert
+ - This class has all the necessary function required to convert
kicad netlist to ngspice netlist.
"""
@@ -22,7 +22,7 @@ class Convert:
def addSourceParameter(self):
"""
- This function add the source details to schematicInfo
+ - This function add the source details to schematicInfo
"""
self.start = 0
@@ -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()) \
@@ -205,6 +205,8 @@ class Convert:
self.direct = self.clarg1
(filepath, filemname) = os.path.split(self.direct)
self.Fileopen = os.path.join(filepath, "analysis")
+ print("======================================================")
+ print("FILEOPEN CONVERT ANALYS", self.Fileopen)
self.writefile = open(self.Fileopen, "w")
if self.variable == 'AC':
self.no = 0
@@ -440,7 +442,10 @@ class Convert:
param = key
default = 0
# Cheking if value is iterable.its for vector
- if hasattr(value, '__iter__'):
+ if (
+ type(value) is not str and
+ hasattr(value, '__iter__')
+ ):
addmodelLine += param + "=["
for lineVar in value:
if str(
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py
index 909756b5..57fd3f25 100644
--- a/src/kicadtoNgspice/DeviceModel.py
+++ b/src/kicadtoNgspice/DeviceModel.py
@@ -7,9 +7,18 @@ from . import TrackWidget
class DeviceModel(QtGui.QWidget):
"""
- This class creates Device Library Tab in KicadtoNgspice Window
- It dynamically creates the widget for device like diode,mosfet,
- transistor and jfet.
+ - This class creates Device Library Tab in KicadtoNgspice Window
+ It dynamically creates the widget for device like diode,mosfet,
+ transistor and jfet.
+ - Same function as the subCircuit file, except for
+ this takes different parameters in the if block
+ - - q TRANSISTOR
+ - - d DIODE
+ - - j JFET
+ - - m MOSFET
+ - Other 2 functions same as the ones in subCircuit
+ - - trackLibrary
+ - - trackLibraryWithoutButton
"""
def __init__(self, schematicInfo, clarg1):
@@ -81,8 +90,9 @@ class DeviceModel(QtGui.QWidget):
json_data["deviceModel"][key][0]):
self.entry_var[self.count].setText(
json_data["deviceModel"][key][0])
- path_name = json_data
- ["deviceModel"][key][0]
+ path_name = (
+ json_data["deviceModel"][key][0]
+ )
else:
self.entry_var[self.count].setText("")
except BaseException:
@@ -144,8 +154,9 @@ class DeviceModel(QtGui.QWidget):
try:
if os.path.exists(
json_data["deviceModel"][key][0]):
- path_name = json_data
- ["deviceModel"][key][0]
+ path_name = (
+ json_data["deviceModel"][key][0]
+ )
self.entry_var[self.count].setText(
json_data["deviceModel"][key][0])
else:
@@ -210,8 +221,9 @@ class DeviceModel(QtGui.QWidget):
json_data["deviceModel"][key][0]):
self.entry_var[self.count].setText(
json_data["deviceModel"][key][0])
- path_name = json_data
- ["deviceModel"][key][0]
+ path_name = (
+ json_data["deviceModel"][key][0]
+ )
else:
self.entry_var[self.count].setText("")
except BaseException:
@@ -323,8 +335,9 @@ class DeviceModel(QtGui.QWidget):
if (i - beg) == 0:
if os.path.exists(
json_data["deviceModel"][key][0]):
- path_name = json_data
- ["deviceModel"][key][0]
+ path_name = (
+ json_data["deviceModel"][key][0]
+ )
else:
self.entry_var[i].setText("")
i = i + 1
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index 2f9b0400..9624fc82 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -33,13 +33,14 @@ 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):
QtGui.QWidget.__init__(self)
print("==================================")
@@ -52,6 +53,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 +67,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 +77,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,23 +94,30 @@ 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)
"""
- Checking if any unknown model is used in schematic which is not
- recognized by NgSpice.
- Also if the two model of same name is present under
- modelParamXML directory
+ - Checking if any unknown model is used in schematic which is not
+ recognized by NgSpice.
+ - Also if the two model of same name is present under
+ modelParamXML directory
"""
if unknownModelList:
print("Unknown Model List is : ", unknownModelList)
@@ -131,9 +140,11 @@ class MainWindow(QtGui.QWidget):
def createMainWindow(self):
"""
- This function create main window of Kicad to Ngspice converter
+ - This function create main window of Kicad to Ngspice converter
+ - Two components
+ - - createcreateConvertWidget
+ - - Convert button => callConvert
"""
-
self.vbox = QtGui.QVBoxLayout(self)
self.hbox = QtGui.QHBoxLayout(self)
self.hbox.addStretch(1)
@@ -148,6 +159,26 @@ class MainWindow(QtGui.QWidget):
self.show()
def createcreateConvertWidget(self):
+ """
+ - Contains the tabs for various convertor elements
+ - - Analysis => obj_analysis
+ => Analysis.Analysis(`path_to_projFile`)
+
+ - - Source Details => obj_source
+ => Source.Source(`sourcelist`,`sourcelisttrack`,`path_to_projFile`)
+
+ - - NgSpice Model => obj_model
+ => Model.Model(`schematicInfo`,`modelList`,`path_to_projFile`)
+
+ - - Device Modelling => obj_devicemodel
+ => DeviceModel.DeviceModel(`schematicInfo`,`path_to_projFile`)
+
+ - - Subcircuits => obj_subcircuitTab
+ => SubcircuitTab.SubcircuitTab(`schematicInfo`,`path_to_projFile`)
+
+ - Finally pass each of these objects, to widgets
+ - convertWindow > mainLayout > tabWidgets > AnalysisTab, SourceTab ....
+ """
global obj_analysis
self.convertWindow = QtGui.QWidget()
self.analysisTab = QtGui.QScrollArea()
@@ -196,7 +227,11 @@ class MainWindow(QtGui.QWidget):
def callConvert(self):
"""
- Calling Convert Class Constructor
+ - This function called when convert button clicked
+ - Extracting data from the objs created above
+ - Pushing this data to json, and dumping it finally
+ - Written to a ..._Previous_Valuse.json file in the projDirectory
+ - Finally, call createNetListFile, with the converted schematic
"""
global schematicInfo
global analysisoutput
@@ -205,18 +240,18 @@ class MainWindow(QtGui.QWidget):
(projpath, filename) = os.path.split(self.kicadFile)
project_name = os.path.basename(projpath)
+ # Opening previous value file pertaining to the selected project
fw = open(
os.path.join(
projpath,
project_name +
"_Previous_Values.json"),
'w')
- json_data = {}
- """
- Writing Analysis values
- """
+ # Creating a dictionary to map the json data
+ json_data = {}
+ # Writing analysis values
json_data["analysis"] = {}
json_data["analysis"]["ac"] = {}
@@ -241,10 +276,12 @@ class MainWindow(QtGui.QWidget):
obj_analysis.ac_entry_var[1].text())
json_data["analysis"]["ac"]["No. of points"] = str(
obj_analysis.ac_entry_var[2].text())
- json_data
- ["analysis"]["ac"]["Start Fre Combo"] = obj_analysis.ac_parameter[0]
- json_data
- ["analysis"]["ac"]["Stop Fre Combo"] = obj_analysis.ac_parameter[1]
+ json_data["analysis"]["ac"]["Start Fre Combo"] = (
+ obj_analysis.ac_parameter[0]
+ )
+ json_data["analysis"]["ac"]["Stop Fre Combo"] = (
+ obj_analysis.ac_parameter[1]
+ )
json_data["analysis"]["dc"] = {}
json_data["analysis"]["dc"]["Source 1"] = str(
@@ -257,12 +294,15 @@ class MainWindow(QtGui.QWidget):
obj_analysis.dc_entry_var[3].text())
json_data["analysis"]["dc"]["Operating Point"] = str(
self.obj_track.op_check[-1])
- json_data
- ["analysis"]["dc"]["Start Combo"] = obj_analysis.dc_parameter[0]
- json_data
- ["analysis"]["dc"]["Increment Combo"] = obj_analysis.dc_parameter[1]
- json_data
- ["analysis"]["dc"]["Stop Combo"] = obj_analysis.dc_parameter[2]
+ json_data["analysis"]["dc"]["Start Combo"] = (
+ obj_analysis.dc_parameter[0]
+ )
+ json_data["analysis"]["dc"]["Increment Combo"] = (
+ obj_analysis.dc_parameter[1]
+ )
+ json_data["analysis"]["dc"]["Stop Combo"] = (
+ obj_analysis.dc_parameter[2]
+ )
json_data["analysis"]["dc"]["Source 2"] = str(
obj_analysis.dc_entry_var[4].text())
json_data["analysis"]["dc"]["Start2"] = str(
@@ -271,12 +311,15 @@ class MainWindow(QtGui.QWidget):
obj_analysis.dc_entry_var[6].text())
json_data["analysis"]["dc"]["Stop2"] = str(
obj_analysis.dc_entry_var[7].text())
- json_data
- ["analysis"]["dc"]["Start Combo2"] = obj_analysis.dc_parameter[3]
- json_data
- ["analysis"]["dc"]["Increment Combo2"] = obj_analysis.dc_parameter[4]
- json_data
- ["analysis"]["dc"]["Stop Combo2"] = obj_analysis.dc_parameter[5]
+ json_data["analysis"]["dc"]["Start Combo2"] = (
+ obj_analysis.dc_parameter[3]
+ )
+ json_data["analysis"]["dc"]["Increment Combo2"] = (
+ obj_analysis.dc_parameter[4]
+ )
+ json_data["analysis"]["dc"]["Stop Combo2"] = (
+ obj_analysis.dc_parameter[5]
+ )
json_data["analysis"]["tran"] = {}
json_data["analysis"]["tran"]["Start Time"] = str(
@@ -285,17 +328,17 @@ class MainWindow(QtGui.QWidget):
obj_analysis.tran_entry_var[1].text())
json_data["analysis"]["tran"]["Stop Time"] = str(
obj_analysis.tran_entry_var[2].text())
- json_data
- ["analysis"]["tran"]["Start Combo"] = obj_analysis.tran_parameter[0]
- json_data
- ["analysis"]["tran"]["Step Combo"] = obj_analysis.tran_parameter[1]
- json_data
- ["analysis"]["tran"]["Stop Combo"] = obj_analysis.tran_parameter[2]
-
- """
- Writing Source values
- """
-
+ json_data["analysis"]["tran"]["Start Combo"] = (
+ obj_analysis.tran_parameter[0]
+ )
+ json_data["analysis"]["tran"]["Step Combo"] = (
+ obj_analysis.tran_parameter[1]
+ )
+ json_data["analysis"]["tran"]["Stop Combo"] = (
+ obj_analysis.tran_parameter[2]
+ )
+
+ # Writing source values
json_data["source"] = {}
count = 1
@@ -421,9 +464,7 @@ class MainWindow(QtGui.QWidget):
else:
pass
- """
- Writing Model values
- """
+ # Writing Model values
i = 0
json_data["model"] = {}
@@ -440,7 +481,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(
@@ -455,9 +500,7 @@ class MainWindow(QtGui.QWidget):
json_data["model"][line[3]]["values"].append(fields)
i = i + 1
- """
- Writing Device Model values
- """
+ # Writing Device Model values
json_data["deviceModel"] = {}
@@ -471,9 +514,7 @@ class MainWindow(QtGui.QWidget):
str(obj_devicemodel.entry_var[it].text()))
it = it + 1
- """
- Writing Subcircuit values
- """
+ # Writing Subcircuit values
json_data["subcircuit"] = {}
for subckt in obj_subcircuitTab.subcircuit_dict_beg:
@@ -486,28 +527,42 @@ class MainWindow(QtGui.QWidget):
str(obj_subcircuitTab.entry_var[it].text()))
it = it + 1
+ # json dumped and written to previous value file for the project
write_data = json.dumps(json_data)
fw.write(write_data)
+ # Create Convert object with the source details & the schematic details
+ print("=============================================================")
+ print("SOURCE LIST TRACK")
+ print(self.obj_track.sourcelisttrack["ITEMS"])
+ print("SOURCE ENTRY VAR")
+ print(self.obj_track.source_entry_var["ITEMS"])
+ print("SCHEMATIC INFO")
+ print(store_schematicInfo)
+ print("=============================================================")
+
self.obj_convert = Convert.Convert(
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)
@@ -515,6 +570,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(
@@ -528,10 +584,14 @@ 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
+ print("=========================================================")
+ print("STORE SCHEMATIC INFO")
+ print(store_schematicInfo)
+ print("=========================================================")
self.createNetlistFile(store_schematicInfo, plotText)
self.msg = "The Kicad to Ngspice Conversion completed\
@@ -547,10 +607,25 @@ class MainWindow(QtGui.QWidget):
# Generate .sub file from .cir.out file if it is a subcircuit
subPath = os.path.splitext(self.kicadFile)[0]
+ # If sub argument passed, create subCircuit file as well
if self.clarg2 == "sub":
self.createSubFile(subPath)
def createNetlistFile(self, store_schematicInfo, plotText):
+ """
+ - Creating .cir.out file
+ - If analysis file present uses that and extract
+ - - Simulator
+ - - Initial
+ - - Analysis
+ - Finally add the following components to .cir.out file
+ - - SimulatorOption
+ - - InitialCondOption
+ - - Store_SchematicInfo
+ - - AnalysisOption
+ - In the end add control statements and allv, alli, end statements
+ """
+ print("=============================================================")
print("Creating Final netlist")
# print "INFOLINE",infoline
# print "OPTIONINFO",optionInfo
@@ -578,6 +653,7 @@ class MainWindow(QtGui.QWidget):
Please check it")
sys.exit()
else:
+ print("========================================================")
print(analysisFileLoc + " does not exist")
sys.exit()
@@ -655,6 +731,10 @@ class MainWindow(QtGui.QWidget):
out.close()
def createSubFile(self, subPath):
+ """
+ - To create subcircuit file
+ - Extract data from .cir.out file
+ """
self.project = subPath
self.projName = os.path.basename(self.project)
if os.path.exists(self.project + ".cir.out"):
@@ -663,6 +743,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.")
@@ -722,4 +803,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 7ae41791..eb1793f9 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,14 +62,14 @@ class Model(QtGui.QWidget):
# print "Key : ",key
# print "Value : ",value
# Check if value is iterable
- if hasattr(value, '__iter__'):
+ if type(value) is not str and hasattr(value, '__iter__'):
# For tag having vector value
temp_tag = []
for item in value:
paramLabel = QtGui.QLabel(item)
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
@@ -78,12 +78,15 @@ class Model(QtGui.QWidget):
try:
for mod in json_data["model"]:
if json_data["model"][mod]["type"] ==\
- line[2] and mod == line[3]:
- self.obj_trac.model_entry_var
- [self.nextcount].setText(
- str(list(
- json_data["model"][mod]["values"]
- [i].values())[0]))
+ line[2] and mod == line[3]:
+ (
+ self.obj_trac.model_entry_var
+ [self.nextcount].setText(
+ str(list(
+ json_data
+ ["model"][mod]["values"]
+ [i].values())[0]))
+ )
i = i + 1
except BaseException:
pass
@@ -96,22 +99,25 @@ 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]:
- self.obj_trac.model_entry_var
- [self.nextcount].setText(
- str(list(json_data
- ["model"][mod]["values"]
- [i].values())[0]))
+ line[2] and mod == line[3]:
+ (
+ self.obj_trac.model_entry_var
+ [self.nextcount].setText(
+ str(list(json_data
+ ["model"][mod]["values"]
+ [i].values())[0]))
+ )
i = i + 1
except BaseException:
pass
diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py
index 63847761..ebbd3429 100644
--- a/src/kicadtoNgspice/Processing.py
+++ b/src/kicadtoNgspice/Processing.py
@@ -5,23 +5,35 @@ from xml.etree import ElementTree as ET
class PrcocessNetlist:
"""
- This class include all the function required for pre-proccessing of netlist
- before converting to Ngspice Netlist.
+ - This class include all the function required for pre-proccessing of
+ netlist before converting to Ngspice Netlist.
"""
modelxmlDIR = '../modelParamXML'
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 +44,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)
+ - Separate infoline (first line) from the rest of netlist
+ """
def preprocessNetlist(self, kicadNetlis, param):
- """Preprocess netlist (replace parameters)"""
netlist = []
for eachline in kicadNetlis:
# Remove leading and trailing blanks spaces from line
@@ -66,9 +86,22 @@ 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):
+ """
+ - Remove the options such as .end, .param, starting wtih "."
+ from the netlist file
+ - This is stored as option info, whereas rest is stored as
+ schematicInfo
+ - Rest from the `* Sheet Name:` line stored as schematicInfo
+ """
optionInfo = []
schematicInfo = []
for eachline in netlist:
@@ -78,14 +111,25 @@ 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, start with v or i
+ - Then check for type whether ac, dc, sine, etc...
+ - Handle starting with h and f as well
+ """
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 +215,27 @@ 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):
+ """
+ - Parses the schematicInfo and returns
+ - - SchematicInfo
+ - - Output Option
+ - - Model List
+ - - Unkown Model List
+ - - Multiple Model List
+ - - Plot text
+ - Parsing info is provided below
+ """
+ print("=============================================================")
print("Reading Schematic info for Model")
# Insert details of Ngspice model
unknownModelList = []
@@ -228,6 +289,8 @@ class PrcocessNetlist:
unknownModelList.append(compType)
elif count == 1:
try:
+ print("==========================================\
+ ===========================")
print(
"Start Parsing Previous Values XML\
for ngspice model :", modelPath)
@@ -265,7 +328,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 +336,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 +351,8 @@ class PrcocessNetlist:
modelLine += compName
else:
+ print("=====================================\
+ ================================")
print("Split Details :", splitDetail)
modelLine = "a" + str(k) + " "
vectorDetail = splitDetail.split(':')
@@ -302,7 +367,7 @@ class PrcocessNetlist:
for i in range(0, int(
item.split("-")[0])):
modelLine += words[pos] +\
- " "
+ " "
pos += 1
modelLine += ") "
else:
@@ -310,7 +375,7 @@ class PrcocessNetlist:
for i in range(0, int(
item.split("-")[0])):
modelLine += words[pos] + \
- " "
+ " "
pos += 1
modelLine += "] "
elif item.split("-")[1] == 'NV':
@@ -376,8 +441,8 @@ class PrcocessNetlist:
words = compline.split()
# Adding zero voltage source to netlist
schematicInfo.append(
- "v_" + words[0] + " "
- + words[1] + " " + words[2] + " " + "0")
+ "v_" + words[0] + " " +
+ words[1] + " " + words[2] + " " + "0")
plotText.append("plot i(v_" + words[0] + ")")
elif compType == 'plot_log':
words = compline.split()
@@ -393,9 +458,11 @@ class PrcocessNetlist:
schematicInfo.insert(index, "* " + compline)
# For Primary Couple
- modelLine = "a" + str(k)
- + " (" + words[1] + " " + words[2] + ") (interNode_" + str(
- interMediateNodeCount) + " " + words[3] + ") "
+ modelLine = (
+ "a" + str(k) + " (" + words[1] + " " +
+ words[2] + ") (interNode_" +
+ str(interMediateNodeCount) + " " + words[3] + ") "
+ )
modelLine += compName + "_primary"
schematicInfo.append(modelLine)
k = k + 1
@@ -436,16 +503,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..c9d50a26 100644
--- a/src/kicadtoNgspice/Source.py
+++ b/src/kicadtoNgspice/Source.py
@@ -27,9 +27,23 @@ class Source(QtGui.QWidget):
def createSourceWidget(self, sourcelist, sourcelisttrack):
"""
- This function dynamically create source widget in the
+ - 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 & add
+ them by default
+ - Each line in sourcelist corresponds to a source
+ - According to the source type modify the source and add it to the tab
"""
+ print("============================================================")
+ print("SOURCE LIST TRACK", sourcelisttrack)
+ print("SOURCE LIST", sourcelist)
+ print("============================================================")
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
project_name = os.path.basename(projpath)
@@ -328,8 +342,8 @@ class Source(QtGui.QWidget):
list(
json_data["source"][key]
["values"][it - 4].values())[0]
- )
- )
+ )
+ )
except BaseException:
pass
@@ -353,6 +367,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/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py
index b9c6402b..52a7a824 100644
--- a/src/kicadtoNgspice/SubcircuitTab.py
+++ b/src/kicadtoNgspice/SubcircuitTab.py
@@ -8,8 +8,14 @@ import os
class SubcircuitTab(QtGui.QWidget):
"""
- This class creates Subcircuit Tab in KicadtoNgspice Window
- It dynamically creates the widget for subcircuits.
+ - This class creates Subcircuit Tab in KicadtoNgspice Window
+ - It dynamically creates the widget for subcircuits,
+ according to the .cir file
+ - Creates `lineEdit` and `Add` button, which triggers `fileSelector`
+ - Also, checks `Previous_value.json` for previous subcircuit value
+ to autofill, the `lineEdit`
+ - Add button is bind to `trackSubcircuit`
+ - Also `trackSubcircuit` without button is triggered if `lineEdit` filled
"""
def __init__(self, schematicInfo, clarg1):
@@ -55,7 +61,7 @@ class SubcircuitTab(QtGui.QWidget):
for eachline in schematicInfo:
words = eachline.split()
if eachline[0] == 'x':
- print(("Subcircuit : Words", words[0]))
+ print("Subcircuit : Words", words[0])
self.obj_trac.subcircuitList[project_name + words[0]] = words
self.subcircuit_dict_beg[words[0]] = self.count
subbox = QtGui.QGroupBox()
@@ -91,7 +97,7 @@ class SubcircuitTab(QtGui.QWidget):
# eg. If the line is 'x1 4 0 3 ua741', there are 3 ports(4, 0
# and 3).
self.numPorts.append(len(words) - 2)
- print(("Number of ports of sub circuit : ", self.numPorts))
+ print("Number of ports of sub circuit : ", self.numPorts)
self.addbtn.clicked.connect(self.trackSubcircuit)
subgrid.addWidget(self.addbtn, self.row, 2)
subbox.setLayout(subgrid)
@@ -124,7 +130,13 @@ class SubcircuitTab(QtGui.QWidget):
def trackSubcircuit(self):
"""
- This function is use to keep track of all Subcircuit widget
+ - This function is use to keep track of all Subcircuit widget
+ - Here the number of ports is tracked using the numPorts
+ and `Add` button objectName property, which is refered using `sender`
+ - Once a file is selected using the `QFileDialog` validate it
+ - Pass the path of subciruit and the number of ports
+ - According to validation state take further steps
+ - If validated correctly, add to TrackWidget
"""
sending_btn = self.sender()
# print "Object Called is ",sending_btn.objectName()
@@ -160,6 +172,11 @@ class SubcircuitTab(QtGui.QWidget):
self.msg.show()
def trackSubcircuitWithoutButton(self, iter_value, path_value):
+ """
+ - Same as trackSubcircuit, but here the count value is passed directly
+ without using any button as in `Add`
+ - This is triggered only once, initally
+ """
self.widgetObjCount = iter_value
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"}