summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice
diff options
context:
space:
mode:
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r--src/kicadtoNgspice/Analysis.py10
-rw-r--r--src/kicadtoNgspice/Convert.py7
-rw-r--r--src/kicadtoNgspice/DeviceModel.py6
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py188
-rw-r--r--src/kicadtoNgspice/Model.py13
-rw-r--r--src/kicadtoNgspice/Source.py5
-rw-r--r--src/kicadtoNgspice/SubcircuitTab.py6
-rw-r--r--src/kicadtoNgspice/TrackWidget.py2
8 files changed, 130 insertions, 107 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py
index 27dc740f..bdebf114 100644
--- a/src/kicadtoNgspice/Analysis.py
+++ b/src/kicadtoNgspice/Analysis.py
@@ -9,7 +9,8 @@ class Analysis(QtGui.QWidget):
"""
This class create Analysis Tab in KicadtoNgspice Window.
"""
- def __init__(self):
+ def __init__(self,clarg1):
+ self.clarg1=clarg1
QtGui.QWidget.__init__(self)
self.track_obj= TrackWidget.TrackWidget()
self.count =0
@@ -21,6 +22,7 @@ class Analysis(QtGui.QWidget):
self.dc_parameter={}
self.tran_parameter= {}
self.createAnalysisWidget()
+
def createAnalysisWidget(self):
@@ -86,7 +88,7 @@ class Analysis(QtGui.QWidget):
self.track_obj.set_CheckBox["ITEMS"]="TRAN"
def createACgroup(self):
- kicadFile = sys.argv[1]
+ kicadFile = self.clarg1
(projpath,filename)=os.path.split(kicadFile)
project_name=os.path.basename(projpath)
print "PROJECT NAME---------",project_name
@@ -226,7 +228,7 @@ class Analysis(QtGui.QWidget):
pass
def createDCgroup(self):
- kicadFile = sys.argv[1]
+ kicadFile = self.clarg1
(projpath,filename)=os.path.split(kicadFile)
project_name=os.path.basename(projpath)
print "PROJECT NAME---------",project_name
@@ -370,7 +372,7 @@ class Analysis(QtGui.QWidget):
self.track_obj.op_check.append(0)
def createTRANgroup(self):
- kicadFile = sys.argv[1]
+ kicadFile = self.clarg1
(projpath,filename)=os.path.split(kicadFile)
project_name=os.path.basename(projpath)
print "PROJECT NAME---------",project_name
diff --git a/src/kicadtoNgspice/Convert.py b/src/kicadtoNgspice/Convert.py
index 3b87e863..ae426470 100644
--- a/src/kicadtoNgspice/Convert.py
+++ b/src/kicadtoNgspice/Convert.py
@@ -10,12 +10,13 @@ class Convert:
"""
This class has all the necessary function required to convert kicad netlist to ngspice netlist.
"""
- def __init__(self,sourcelisttrack,source_entry_var,schematicInfo):
+ def __init__(self,sourcelisttrack,source_entry_var,schematicInfo,clarg1):
print "Start Conversion"
self.sourcelisttrack = sourcelisttrack
self.schematicInfo = schematicInfo
self.entry_var = source_entry_var
self.sourcelistvalue = []
+ self.clarg1=clarg1
def addSourceParameter(self):
@@ -135,7 +136,7 @@ class Convert:
self.no=0
self.variable=self.set_checkbox
- self.direct= sys.argv[1]
+ self.direct= self.clarg1
(filepath, filemname)= os.path.split(self.direct)
self.Fileopen = os.path.join(filepath, "analysis")
self.writefile= open(self.Fileopen,"w")
@@ -387,6 +388,8 @@ class Convert:
subList = self.obj_track.subcircuitTrack
subLine = {} #Key:Index, Value:with its updated line in the form of list
includeLine = [] #All .include line list
+ print "self.obj_track.subcircuitList--->",self.obj_track.subcircuitList
+ print "self.obj_track.subcircuitTrack--->",self.obj_track.subcircuitTrack
if len(self.obj_track.subcircuitList) != len(self.obj_track.subcircuitTrack):
self.msg = QtGui.QErrorMessage()
self.msg.showMessage("Conversion failed. Please add all Subcircuits.")
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py
index 7dc740d2..ee8b7d25 100644
--- a/src/kicadtoNgspice/DeviceModel.py
+++ b/src/kicadtoNgspice/DeviceModel.py
@@ -12,9 +12,11 @@ class DeviceModel(QtGui.QWidget):
It dynamically creates the widget for device like diode,mosfet,transistor and jfet.
"""
- def __init__(self,schematicInfo):
+ def __init__(self,schematicInfo,clarg1):
- kicadFile = sys.argv[1]
+
+ self.clarg1=clarg1
+ kicadFile = self.clarg1
(projpath,filename)=os.path.split(kicadFile)
project_name=os.path.basename(projpath)
print "PROJECT NAME---------",project_name
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index c3e9d637..2452d215 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -38,8 +38,66 @@ class MainWindow(QtGui.QWidget):
The convert function takes all the value entered by user and create a final netlist "*.cir.out".
This final netlist is compatible with NgSpice.
"""
- def __init__(self):
+ def __init__(self,clarg1,clarg2=None):
+
+
+
QtGui.QWidget.__init__(self)
+
+ print "=================================="
+ print "Kicad to Ngspice netlist converter "
+ print "=================================="
+ global kicadNetlist,schematicInfo
+ global infoline,optionInfo
+ self.kicadFile = clarg1
+ self.clarg1=clarg1
+ self.clarg2=clarg2
+ #Object of Processing
+ obj_proc = PrcocessNetlist()
+
+ # Read the netlist
+ kicadNetlist = obj_proc.readNetlist(self.kicadFile)
+
+ # Construct parameter information
+ param = obj_proc.readParamInfo(kicadNetlist)
+
+ # Replace parameter with values
+ netlist,infoline = obj_proc.preprocessNetlist(kicadNetlist,param)
+
+ print "NETLIST ",netlist
+ print "INFOLINE",infoline
+
+ # Separate option and schematic information
+ optionInfo, schematicInfo = obj_proc.separateNetlistInfo(netlist)
+
+ print "OPTIONINFO",optionInfo
+ print "SCHEMATICINFO",schematicInfo
+
+
+ #List for storing source and its value
+ global sourcelist, sourcelisttrack
+ sourcelist=[]
+ sourcelisttrack=[]
+ schematicInfo,sourcelist = obj_proc.insertSpecialSourceParam(schematicInfo,sourcelist)
+
+ print "SOURCELIST",sourcelist
+ print "SCHEMATICINFO",schematicInfo
+
+ #List storing model detail
+ global modelList,outputOption,unknownModelList,multipleModelList
+
+ modelList = []
+ outputOption = []
+ schematicInfo,outputOption,modelList,unknownModelList,multipleModelList = obj_proc.convertICintoBasicBlocks(schematicInfo,outputOption,modelList)
+ print "Unknown Model List",unknownModelList
+ print "Multiple Model List",multipleModelList
+ print "Model List",modelList
+ """
+ args=[clarg1,clarg2]
+ app = QtGui.QApplication(args)
+ kingWindow = MainWindow()
+ sys.exit(app.exec_())
+ """
#Create object of track widget
self.obj_track = TrackWidget.TrackWidget()
"""
@@ -69,48 +127,59 @@ class MainWindow(QtGui.QWidget):
This function create main window of Kicad to Ngspice converter
"""
- self.grid = QtGui.QGridLayout(self)
+ self.vbox = QtGui.QVBoxLayout(self)
+ self.hbox=QtGui.QHBoxLayout(self)
+ self.hbox.addStretch(1)
self.convertbtn = QtGui.QPushButton("Convert")
self.convertbtn.clicked.connect(self.callConvert)
- self.cancelbtn = QtGui.QPushButton("Cancel")
- self.cancelbtn.clicked.connect(self.close)
- self.grid.addWidget(self.createcreateConvertWidget(),0,0)
- self.grid.addWidget(self.convertbtn,1,1)
- self.grid.addWidget(self.cancelbtn,1,2)
- self.setWindowState(QtCore.Qt.WindowMaximized)
- self.setLayout(self.grid)
+ #self.cancelbtn = QtGui.QPushButton("Cancel")
+ #self.cancelbtn.clicked.connect(self.closeCancel)
+ self.hbox.addWidget(self.convertbtn)
+ self.vbox.addWidget(self.createcreateConvertWidget())
+ self.vbox.addLayout(self.hbox)
+
+ #self.grid.addWidget(self.cancelbtn,1,1)
+
+ #self.setWindowState(QtCore.Qt.WindowMaximized)
+ self.setLayout(self.vbox)
self.setWindowTitle("Kicad To NgSpice Converter")
self.show()
-
+
+ """
+ def closeCancel(self):
+ self.obj_track.modelTrack[:]=[]
+ self.obj_track.subcircuitList[:]=[]
+ self.close()
+ """
def createcreateConvertWidget(self):
global obj_analysis
self.convertWindow = QtGui.QWidget()
self.analysisTab = QtGui.QScrollArea()
- obj_analysis=Analysis.Analysis()
+ obj_analysis=Analysis.Analysis(self.clarg1)
self.analysisTab.setWidget(obj_analysis)
#self.analysisTabLayout = QtGui.QVBoxLayout(self.analysisTab.widget())
self.analysisTab.setWidgetResizable(True)
global obj_source
self.sourceTab = QtGui.QScrollArea()
- obj_source=Source.Source(sourcelist,sourcelisttrack)
+ obj_source=Source.Source(sourcelist,sourcelisttrack,self.clarg1)
self.sourceTab.setWidget(obj_source)
#self.sourceTabLayout = QtGui.QVBoxLayout(self.sourceTab.widget())
self.sourceTab.setWidgetResizable(True)
global obj_model
self.modelTab = QtGui.QScrollArea()
- obj_model=Model.Model(schematicInfo,modelList)
+ obj_model=Model.Model(schematicInfo,modelList,self.clarg1)
self.modelTab.setWidget(obj_model)
#self.modelTabLayout = QtGui.QVBoxLayout(self.modelTab.widget())
self.modelTab.setWidgetResizable(True)
global obj_devicemodel
self.deviceModelTab = QtGui.QScrollArea()
- obj_devicemodel=DeviceModel.DeviceModel(schematicInfo)
+ obj_devicemodel=DeviceModel.DeviceModel(schematicInfo,self.clarg1)
self.deviceModelTab.setWidget(obj_devicemodel)
self.deviceModelTab.setWidgetResizable(True)
global obj_subcircuitTab
self.subcircuitTab = QtGui.QScrollArea()
- obj_subcircuitTab = SubcircuitTab.SubcircuitTab(schematicInfo)
+ obj_subcircuitTab = SubcircuitTab.SubcircuitTab(schematicInfo,self.clarg1)
self.subcircuitTab.setWidget(obj_subcircuitTab)
self.subcircuitTab.setWidgetResizable(True)
@@ -136,8 +205,8 @@ class MainWindow(QtGui.QWidget):
"""
global schematicInfo
global analysisoutput
- kicadFile = sys.argv[1]
- (projpath,filename)=os.path.split(kicadFile)
+ global kicad
+ (projpath,filename)=os.path.split(self.kicadFile)
project_name=os.path.basename(projpath)
print "PROJ PATH---",projpath
@@ -399,7 +468,7 @@ class MainWindow(QtGui.QWidget):
self.obj_convert = Convert.Convert(self.obj_track.sourcelisttrack["ITEMS"],
self.obj_track.source_entry_var["ITEMS"],
- schematicInfo)
+ schematicInfo,self.clarg1)
try:
#Adding Source Value to Schematic Info
@@ -409,10 +478,10 @@ class MainWindow(QtGui.QWidget):
schematicInfo = self.obj_convert.addModelParameter(schematicInfo)
#Adding Device Library to SchematicInfo
- schematicInfo = self.obj_convert.addDeviceLibrary(schematicInfo,kicadFile)
+ schematicInfo = self.obj_convert.addDeviceLibrary(schematicInfo,self.kicadFile)
#Adding Subcircuit Library to SchematicInfo
- schematicInfo = self.obj_convert.addSubcircuit(schematicInfo, kicadFile)
+ schematicInfo = self.obj_convert.addSubcircuit(schematicInfo, self.kicadFile)
analysisoutput = self.obj_convert.analysisInsertor(self.obj_track.AC_entry_var["ITEMS"],
self.obj_track.DC_entry_var["ITEMS"],
@@ -424,24 +493,25 @@ class MainWindow(QtGui.QWidget):
self.obj_track.AC_type["ITEMS"],
self.obj_track.op_check)
#print "SchematicInfo after adding Model Details",schematicInfo
-
+
#Calling netlist file generation function
self.createNetlistFile(schematicInfo)
self.msg = "The Kicad to Ngspice Conversion completed successfully!!!!!!"
QtGui.QMessageBox.information(self, "Information", self.msg, QtGui.QMessageBox.Ok)
- self.close()
+ #self.obj_track.subcircuitList[:]=[]
+ #self.obj_track.modelTrack[:]=[]
+ #self.close()
except Exception as e:
print "Exception Message: ",e
print "There was error while converting kicad to ngspice"
self.close()
# Generate .sub file from .cir.out file if it is a subcircuit
- subPath = os.path.splitext(kicadFile)[0]
+ subPath = os.path.splitext(self.kicadFile)[0]
- if len(sys.argv)>2:
- if sys.argv[2] == "sub":
- self.createSubFile(subPath)
+ if self.clarg2 == "sub":
+ self.createSubFile(subPath)
def createNetlistFile(self,schematicInfo):
print "Creating Final netlist"
@@ -453,7 +523,7 @@ class MainWindow(QtGui.QWidget):
#print "KicadfIle",kicadFile
#checking if analysis files is present
- (projpath,filename) = os.path.split(kicadFile)
+ (projpath,filename) = os.path.split(self.kicadFile)
analysisFileLoc = os.path.join(projpath,"analysis")
#print "Analysis File Location",analysisFileLoc
if os.path.exists(analysisFileLoc):
@@ -512,7 +582,7 @@ class MainWindow(QtGui.QWidget):
#Start creating final netlist cir.out file
- outfile = kicadFile+".out"
+ outfile = self.kicadFile+".out"
out=open(outfile,"w")
out.writelines(infoline)
out.writelines('\n')
@@ -594,69 +664,7 @@ class MainWindow(QtGui.QWidget):
out.writelines('.ends ' + self.projName)
print "The subcircuit has been written in "+self.projName+".sub"
-
-#Main Function
-
-def main(args):
- print "=================================="
- print "Kicad to Ngspice netlist converter "
- print "=================================="
- global kicadFile,kicadNetlist,schematicInfo
- global infoline,optionInfo
- kicadFile = sys.argv[1]
-
- #Object of Processing
- obj_proc = PrcocessNetlist()
-
- # Read the netlist
- kicadNetlist = obj_proc.readNetlist(kicadFile)
-
- # Construct parameter information
- param = obj_proc.readParamInfo(kicadNetlist)
-
- # Replace parameter with values
- netlist,infoline = obj_proc.preprocessNetlist(kicadNetlist,param)
-
- print "NETLIST ",netlist
- print "INFOLINE",infoline
-
- # Separate option and schematic information
- optionInfo, schematicInfo = obj_proc.separateNetlistInfo(netlist)
-
- print "OPTIONINFO",optionInfo
- print "SCHEMATICINFO",schematicInfo
-
-
- #List for storing source and its value
- global sourcelist, sourcelisttrack
- sourcelist=[]
- sourcelisttrack=[]
- schematicInfo,sourcelist = obj_proc.insertSpecialSourceParam(schematicInfo,sourcelist)
-
- print "SOURCELIST",sourcelist
- print "SCHEMATICINFO",schematicInfo
-
- #List storing model detail
- global modelList,outputOption,unknownModelList,multipleModelList
-
- modelList = []
- outputOption = []
- schematicInfo,outputOption,modelList,unknownModelList,multipleModelList = obj_proc.convertICintoBasicBlocks(schematicInfo,outputOption,modelList)
- print "Unknown Model List",unknownModelList
- print "Multiple Model List",multipleModelList
- print "Model List",modelList
-
-
- app = QtGui.QApplication(args)
- kingWindow = MainWindow()
- #kingWindow.show() #No need to call show as we are doing it in createMainWindow
- sys.exit(app.exec_())
-
-
-
-if __name__ == '__main__':
- main(sys.argv)
diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py
index d1edd5a6..c7ca7b47 100644
--- a/src/kicadtoNgspice/Model.py
+++ b/src/kicadtoNgspice/Model.py
@@ -13,12 +13,12 @@ class Model(QtGui.QWidget):
The widgets are created dynamically in the Model Tab.
"""
- def __init__(self,schematicInfo,modelList):
+ def __init__(self,schematicInfo,modelList,clarg1):
QtGui.QWidget.__init__(self)
#Processing for getting previous values
- kicadFile = sys.argv[1]
+ kicadFile = clarg1
(projpath,filename)=os.path.split(kicadFile)
project_name=os.path.basename(projpath)
#print "PROJECT NAME---------",project_name
@@ -125,7 +125,14 @@ class Model(QtGui.QWidget):
'''
#This keeps the track of Model Tab Widget
- self.obj_trac.modelTrack.append([line[0],line[1],line[2],line[3],line[4],line[5],line[6],self.start,self.end,tag_dict])
+ lst=[line[0],line[1],line[2],line[3],line[4],line[5],line[6],self.start,self.end,tag_dict]
+ check=0
+ for itr in self.obj_trac.modelTrack:
+ if itr==lst:
+ check=1
+
+ if check==0:
+ self.obj_trac.modelTrack.append(lst)
print "The tag dictionary : ",tag_dict
diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py
index e0d0fe19..4841ab07 100644
--- a/src/kicadtoNgspice/Source.py
+++ b/src/kicadtoNgspice/Source.py
@@ -12,11 +12,12 @@ class Source(QtGui.QWidget):
This class create Source Tab of KicadtoNgSpice Window.
"""
- def __init__(self,sourcelist,sourcelisttrack):
+ def __init__(self,sourcelist,sourcelisttrack,clarg1):
QtGui.QWidget.__init__(self)
self.obj_track = TrackWidget.TrackWidget()
#Variable
self.count = 1
+ self.clarg1=clarg1
self.start = 0
self.end = 0
self.row = 0
@@ -32,7 +33,7 @@ class Source(QtGui.QWidget):
"""
This function dynamically create source widget in the Source tab of KicadtoNgSpice window
"""
- kicadFile = sys.argv[1]
+ kicadFile = self.clarg1
(projpath,filename)=os.path.split(kicadFile)
project_name=os.path.basename(projpath)
print "PROJECT NAME---------",project_name
diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py
index bbac5592..fa51ac6a 100644
--- a/src/kicadtoNgspice/SubcircuitTab.py
+++ b/src/kicadtoNgspice/SubcircuitTab.py
@@ -14,9 +14,9 @@ class SubcircuitTab(QtGui.QWidget):
It dynamically creates the widget for subcircuits.
"""
- def __init__(self,schematicInfo):
+ def __init__(self,schematicInfo,clarg1):
- kicadFile = sys.argv[1]
+ kicadFile = clarg1
(projpath,filename)=os.path.split(kicadFile)
project_name=os.path.basename(projpath)
print "PROJECT NAME---------",project_name
@@ -59,7 +59,7 @@ class SubcircuitTab(QtGui.QWidget):
words = eachline.split()
if eachline[0] == 'x':
print "Words",words[0]
- self.obj_trac.subcircuitList.append(words)
+ self.obj_trac.subcircuitList[project_name+words[0]]=words
self.subcircuit_dict_beg[words[0]]=self.count
subbox=QtGui.QGroupBox()
subgrid=QtGui.QGridLayout()
diff --git a/src/kicadtoNgspice/TrackWidget.py b/src/kicadtoNgspice/TrackWidget.py
index e97b317d..56e84ce3 100644
--- a/src/kicadtoNgspice/TrackWidget.py
+++ b/src/kicadtoNgspice/TrackWidget.py
@@ -26,4 +26,4 @@ class TrackWidget:
#Track Widget for Subcircuits where directory has been selected
subcircuitTrack = {}
#Track subcircuits which are specified in .cir file
- subcircuitList = [] \ No newline at end of file
+ subcircuitList = {} \ No newline at end of file