summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice/KicadtoNgspice.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/kicadtoNgspice/KicadtoNgspice.py')
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py103
1 files changed, 76 insertions, 27 deletions
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index 833bd6cc..9624fc82 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -41,7 +41,6 @@ class MainWindow(QtGui.QWidget):
- 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("==================================")
@@ -115,10 +114,10 @@ class MainWindow(QtGui.QWidget):
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)
@@ -139,11 +138,13 @@ class MainWindow(QtGui.QWidget):
else:
self.createMainWindow()
- """
- This function create main window of Kicad to Ngspice converter
- """
-
def createMainWindow(self):
+ """
+ - 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)
@@ -158,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()
@@ -206,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
@@ -215,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"] = {}
@@ -313,10 +338,7 @@ class MainWindow(QtGui.QWidget):
obj_analysis.tran_parameter[2]
)
- """
- Writing Source values
- """
-
+ # Writing source values
json_data["source"] = {}
count = 1
@@ -442,9 +464,7 @@ class MainWindow(QtGui.QWidget):
else:
pass
- """
- Writing Model values
- """
+ # Writing Model values
i = 0
json_data["model"] = {}
@@ -480,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"] = {}
@@ -496,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:
@@ -511,9 +527,20 @@ 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"],
@@ -561,6 +588,10 @@ class MainWindow(QtGui.QWidget):
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\
@@ -576,10 +607,24 @@ 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
@@ -686,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"):