summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/browser/pages/welcome.html4
-rw-r--r--src/configuration/Appconfig.py1
-rwxr-xr-xsrc/deviceModelLibrary/Diode/D.lib22
-rw-r--r--src/deviceModelLibrary/Diode/D.xml15
-rwxr-xr-xsrc/deviceModelLibrary/Templates/D.lib5
-rw-r--r--src/deviceModelLibrary/Templates/D.xml29
-rwxr-xr-xsrc/frontEnd/Application.py211
-rwxr-xr-xsrc/frontEnd/Application.py.bkp363
-rw-r--r--src/frontEnd/Workspace.py2
-rw-r--r--src/kicadtoNgspice/DeviceModel.py6
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py11
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py.bkp671
-rw-r--r--src/kicadtoNgspice/Processing.py37
-rw-r--r--src/modelParamXML/Nghdl/inverter.xml1
-rw-r--r--src/modelParamXML/Nghdl/myxor.xml1
-rw-r--r--src/ngspiceSimulation/NgspiceWidget.py5
-rw-r--r--src/ngspiceSimulation/pythonPlotting.py4
-rw-r--r--src/ngspicetoModelica/NgspicetoModelica.py786
-rw-r--r--src/ngspicetoModelica/__init__.py0
-rw-r--r--src/projManagement/Kicad.py7
-rw-r--r--src/projManagement/Validation.py22
21 files changed, 1070 insertions, 1133 deletions
diff --git a/src/browser/pages/welcome.html b/src/browser/pages/welcome.html
index f525d5c1..9343b8b0 100644
--- a/src/browser/pages/welcome.html
+++ b/src/browser/pages/welcome.html
@@ -40,7 +40,7 @@ pre{
<p>
<b>eSim</b> is an open source EDA tool for circuit design, simulation, analysis and PCB design. It is an integrated tool built using open source software such as KiCad (<a href=http://www.kicad-pcb.org>http://www.kicad-pcb.org</a>) and Ngspice(<a href=http://ngspice.sourceforge.net>http://ngspice.sourceforge.net</a>).
<br/>
-eSim source is released under <b>GNU General Public License.</b>
+eSim source is released under <b>GNU General Public License V3.</b>
</p>
<br/>
<p>
@@ -48,7 +48,7 @@ eSim is developed by the <b>FOSSEE team at IIT Bombay</b>. To know more about eS
</p>
<br />
<p>
-To discuss more about eSim please visits at <a href=http://freeeda.in>http://freeeda.in</a>
+To discuss more about eSim please visits at <a href=http://esim.fossee.in>http://esim.fossee.in</a>
</p>
<br />
diff --git a/src/configuration/Appconfig.py b/src/configuration/Appconfig.py
index 16e440ab..0d3e0346 100644
--- a/src/configuration/Appconfig.py
+++ b/src/configuration/Appconfig.py
@@ -44,6 +44,7 @@ class Appconfig(QtGui.QWidget):
project_explorer = json.load(open(dictPath))
except:
project_explorer= {}
+ process_obj = []
def __init__(self):
super(Appconfig, self).__init__()
diff --git a/src/deviceModelLibrary/Diode/D.lib b/src/deviceModelLibrary/Diode/D.lib
index ef18bb50..8a7fb4da 100755
--- a/src/deviceModelLibrary/Diode/D.lib
+++ b/src/deviceModelLibrary/Diode/D.lib
@@ -1,20 +1,2 @@
-.MODEL D1N750 D(
-+ Vj=.75
-+ Nbvl=14.976
-+ Cjo=175p
-+ Rs=.25
-+ Isr=1.859n
-+ Eg=1.11
-+ M=.5516
-+ Nbv=1.6989
-+ N=1
-+ Tbv1=-21.277u
-+ Bv=8.1
-+ Fc=.5
-+ Ikf=0
-+ Nr=2
-+ Ibv=20.245m
-+ Is=880.5E-18
-+ Xti=3
-+ Ibvl=1.9556m
-) \ No newline at end of file
+.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04)
+
diff --git a/src/deviceModelLibrary/Diode/D.xml b/src/deviceModelLibrary/Diode/D.xml
index 8b806d17..8b6b14c8 100644
--- a/src/deviceModelLibrary/Diode/D.xml
+++ b/src/deviceModelLibrary/Diode/D.xml
@@ -1,4 +1,15 @@
<library>
<model_name>D</model_name>
-<ref_model>D1N750</ref_model>
-<param><Vj>.75</Vj><Nbvl>14.976</Nbvl><Cjo>175p</Cjo><Rs>.25</Rs><Isr>1.859n</Isr><Eg>1.11</Eg><M>.5516</M><Nbv>1.6989</Nbv><N>1</N><Tbv1>-21.277u</Tbv1><Bv>8.1</Bv><Fc>.5</Fc><Ikf>0</Ikf><Nr>2</Nr><Ibv>20.245m</Ibv><Is>880.5E-18</Is><Xti>3</Xti><Ibvl>1.9556m</Ibvl></param></library> \ No newline at end of file
+<ref_model>1N4148</ref_model>
+<param>
+ <Is>2.495E-09</Is>
+ <Rs>4.755E-01</Rs>
+ <N>1.679E+00</N>
+ <tt>3.030E-09</tt>
+ <Cjo>1.700E-12</Cjo>
+ <M>1.959E-01</M>
+ <Vj>1</Vj>
+ <Bv>1.000E+02</Bv>
+ <Ibv>1.000E-04</Ibv>
+</param>
+</library>
diff --git a/src/deviceModelLibrary/Templates/D.lib b/src/deviceModelLibrary/Templates/D.lib
index 890c37fe..8a7fb4da 100755
--- a/src/deviceModelLibrary/Templates/D.lib
+++ b/src/deviceModelLibrary/Templates/D.lib
@@ -1,3 +1,2 @@
-.model D1N750 D( Is=880.5E-18 Rs=.25 Ikf=0 N=1 Xti=3 Eg=1.11 Cjo=175p M=.5516
-+ Vj=.75 Fc=.5 Isr=1.859n Nr=2 Bv=8.1 Ibv=20.245m Nbv=1.6989 Ibvl=1.9556m
-+ Nbvl=14.976 Tbv1=-21.277u)
+.model 1n4148 D(is=2.495E-09 rs=4.755E-01 n=1.679E+00 tt=3.030E-09 cjo=1.700E-12 vj=1 m=1.959E-01 bv=1.000E+02 ibv=1.000E-04)
+
diff --git a/src/deviceModelLibrary/Templates/D.xml b/src/deviceModelLibrary/Templates/D.xml
index 546d1156..8b6b14c8 100644
--- a/src/deviceModelLibrary/Templates/D.xml
+++ b/src/deviceModelLibrary/Templates/D.xml
@@ -1,24 +1,15 @@
<library>
<model_name>D</model_name>
-<ref_model>D1N750</ref_model>
+<ref_model>1N4148</ref_model>
<param>
- <Is>880.5E-18</Is>
- <Rs>.25</Rs>
- <Ikf>0</Ikf>
- <N>1</N>
- <Xti>3</Xti>
- <Eg>1.11</Eg>
- <Cjo>175p</Cjo>
- <M>.5516</M>
- <Vj>.75</Vj>
- <Fc>.5</Fc>
- <Isr>1.859n</Isr>
- <Nr>2</Nr>
- <Bv>8.1</Bv>
- <Ibv>20.245m</Ibv>
- <Nbv>1.6989</Nbv>
- <Ibvl>1.9556m</Ibvl>
- <Nbvl>14.976</Nbvl>
- <Tbv1>-21.277u</Tbv1>
+ <Is>2.495E-09</Is>
+ <Rs>4.755E-01</Rs>
+ <N>1.679E+00</N>
+ <tt>3.030E-09</tt>
+ <Cjo>1.700E-12</Cjo>
+ <M>1.959E-01</M>
+ <Vj>1</Vj>
+ <Bv>1.000E+02</Bv>
+ <Ibv>1.000E-04</Ibv>
</param>
</library>
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py
index 2aa7c649..6e94cbd7 100755
--- a/src/frontEnd/Application.py
+++ b/src/frontEnd/Application.py
@@ -28,9 +28,12 @@ from configuration.Appconfig import Appconfig
from projManagement.openProject import OpenProjectInfo
from projManagement.newProject import NewProjectInfo
from projManagement.Kicad import Kicad
+from projManagement.Validation import Validation
+from projManagement import Worker
from frontEnd import ProjectExplorer
from frontEnd import Workspace
from frontEnd import DockArea
+#from pspicetoKicad.ImportPspice import ImportPspiceLibrary,ConvertPspiceKicad
import time
from PyQt4.Qt import QSize
@@ -52,7 +55,7 @@ class Application(QtGui.QMainWindow):
self.obj_Mainview = MainView()
self.obj_kicad = Kicad(self.obj_Mainview.obj_dockarea)
self.obj_appconfig = Appconfig()
-
+ self.obj_validation = Validation()
#Initialize all widget
self.setCentralWidget(self.obj_Mainview)
self.initToolBar()
@@ -80,7 +83,16 @@ class Application(QtGui.QMainWindow):
self.openproj = QtGui.QAction(QtGui.QIcon('../../images/openProject.png'),'<b>Open Project</b>',self)
self.openproj.setShortcut('Ctrl+O')
self.openproj.triggered.connect(self.open_project)
-
+ '''
+ #Removing as it no longer required
+ self.importPspiceLib = QtGui.QAction(QtGui.QIcon('../../images/import_icon.png'),'<b>Import PSPICE Library</b>',self)
+ self.importPspiceLib.setShortcut('Ctrl+X')
+ self.importPspiceLib.triggered.connect(self.import_pspice_lib)
+
+ self.convertPspiceKicad = QtGui.QAction(QtGui.QIcon('../../images/Ps2Ki.png'),'<b>Convert PSPICE to KICAD</b>',self)
+ self.convertPspiceKicad.setShortcut('Ctrl+X')
+ self.convertPspiceKicad.triggered.connect(self.convert_pspice_kicad)
+ '''
self.exitproj = QtGui.QAction(QtGui.QIcon('../../images/closeProject.png'),'<b>Exit</b>',self)
self.exitproj.setShortcut('Ctrl+X')
self.exitproj.triggered.connect(self.exit_project)
@@ -92,6 +104,11 @@ class Application(QtGui.QMainWindow):
self.topToolbar = self.addToolBar('Top Tool Bar')
self.topToolbar.addAction(self.newproj)
self.topToolbar.addAction(self.openproj)
+ '''
+ #Removing as it is no longer require
+ self.topToolbar.addAction(self.importPspiceLib)
+ self.topToolbar.addAction(self.convertPspiceKicad)
+ '''
self.topToolbar.addAction(self.exitproj)
self.topToolbar.addAction(self.helpfile)
@@ -115,17 +132,29 @@ class Application(QtGui.QMainWindow):
self.ngspice = QtGui.QAction(QtGui.QIcon('../../images/ngspice.png'), '<b>Simulation</b>', self)
self.ngspice.triggered.connect(self.open_ngspice)
+ """
+ #Removing PCB and Footprint Editor as it will start from eeschema
self.footprint = QtGui.QAction(QtGui.QIcon('../../images/footprint.png'),'<b>Footprint Editor</b>',self)
self.footprint.triggered.connect(self.obj_kicad.openFootprint)
self.pcb = QtGui.QAction(QtGui.QIcon('../../images/pcb.png'),'<b>PCB Layout</b>',self)
self.pcb.triggered.connect(self.obj_kicad.openLayout)
+ """
self.model = QtGui.QAction(QtGui.QIcon('../../images/model.png'),'<b>Model Editor</b>',self)
self.model.triggered.connect(self.open_modelEditor)
self.subcircuit=QtGui.QAction(QtGui.QIcon('../../images/subckt.png'),'<b>Subcircuit</b>',self)
self.subcircuit.triggered.connect(self.open_subcircuit)
+
+ self.nghdl = QtGui.QAction(QtGui.QIcon('../../images/nghdl.png'), '<b>Nghdl</b>', self)
+ self.nghdl.triggered.connect(self.open_nghdl)
+
+ self.omedit = QtGui.QAction(QtGui.QIcon('../../images/omedit.png'),'<b>Modelica Converter</b>',self)
+ self.omedit.triggered.connect(self.open_OMedit)
+
+ self.omoptim=QtGui.QAction(QtGui.QIcon('../../images/omoptim.png'),'<b>OM Optimisation</b>',self)
+ self.omoptim.triggered.connect(self.open_OMoptim)
#Adding Action Widget to tool bar
self.lefttoolbar = QtGui.QToolBar('Left ToolBar')
@@ -133,10 +162,15 @@ class Application(QtGui.QMainWindow):
self.lefttoolbar.addAction(self.kicad)
self.lefttoolbar.addAction(self.conversion)
self.lefttoolbar.addAction(self.ngspice)
+ """
self.lefttoolbar.addAction(self.footprint)
self.lefttoolbar.addAction(self.pcb)
+ """
self.lefttoolbar.addAction(self.model)
self.lefttoolbar.addAction(self.subcircuit)
+ self.lefttoolbar.addAction(self.nghdl)
+ self.lefttoolbar.addAction(self.omedit)
+ self.lefttoolbar.addAction(self.omoptim)
self.lefttoolbar.setOrientation(QtCore.Qt.Vertical)
self.lefttoolbar.setIconSize(QSize(40,40))
@@ -160,6 +194,7 @@ class Application(QtGui.QMainWindow):
self.obj_appconfig.print_info('Current project is : ' + self.obj_appconfig.current_project["ProjectName"])
except:
pass
+
def open_project(self):
"""
This project call Open Project Info class
@@ -173,6 +208,55 @@ class Application(QtGui.QMainWindow):
except:
pass
+ def exit_project(self):
+ print "Exit Project called"
+ for proc in self.obj_appconfig.procThread_list:
+ try:
+ proc.terminate()
+ except:
+ pass
+
+ try :
+ for process_object in self.obj_appconfig.process_obj:
+ try:
+ process_object.close()
+ except:
+ pass
+ except:
+ pass
+ ##Just checking if open and New window is open. If yes just close it when application is closed
+ try:
+ self.project.close()
+ except:
+ pass
+
+ self.close()
+
+ '''
+
+ def import_pspice_lib(self):
+ print "Import Pspice Library is called"
+ self.obj_appconfig.print_info('Import Pspice Library is called')
+
+ self.obj_import_pspice = ImportPspiceLibrary()
+
+ self.obj_import_pspice.imortLib()
+
+ def convert_pspice_kicad(self):
+ print "PSPICE to KICAD converter is called"
+ self.obj_appconfig.print_info('PSPICE to KICAD converter is called')
+
+ self.obj_run_converter = ConvertPspiceKicad()
+
+ self.obj_run_converter.runConverter()
+ '''
+ def help_project(self):
+ print "Help is called"
+ self.obj_appconfig.print_info('Help is called')
+ print "Current Project : ",self.obj_appconfig.current_project
+ self.obj_Mainview.obj_dockarea.usermanual()
+
+
def open_ngspice(self):
"""
This Function execute ngspice on current project
@@ -203,45 +287,102 @@ class Application(QtGui.QMainWindow):
print "Subcircuit editor is called"
self.obj_appconfig.print_info('Subcircuit editor is called')
self.obj_Mainview.obj_dockarea.subcircuiteditor()
-
-
- def exit_project(self):
- print "Exit Project called"
- for proc in self.obj_appconfig.procThread_list:
- try:
- proc.terminate()
- except:
- pass
- ##Just checking if open and New window is open. If yes just close it when application is closed
- try:
- self.project.close()
- except:
- pass
-
- self.close()
-
- def help_project(self):
- print "Help is called"
- self.obj_appconfig.print_info('Help is called')
- print "Current Project : ",self.obj_appconfig.current_project
- self.obj_Mainview.obj_dockarea.usermanual()
-
-
+
+ def open_nghdl(self):
+ print "Nghdl is called"
+ self.obj_appconfig.print_info('Nghdl is called')
+
+ if self.obj_validation.validateTool('nghdl'):
+ self.cmd = 'nghdl -e'
+ self.obj_workThread = Worker.WorkerThread(self.cmd)
+ self.obj_workThread.start()
+
+ else:
+ self.msg = QtGui.QErrorMessage(None)
+ self.msg.showMessage('Error while opening nghdl. Please make sure nghdl is installed')
+ self.obj_appconfig.print_error('Error while opening nghdl. Please make sure nghdl is installed')
+ self.msg.setWindowTitle('nghdl Error Message')
+
+
def open_modelEditor(self):
print "model editor is called"
self.obj_appconfig.print_info('model editor is called')
self.obj_Mainview.obj_dockarea.modelEditor()
- """
- def open_kicadToNgspice(self):
- print "kicadToNgspice is called"
- self.obj_appconfig.print_info('kicadToNgspice is called')
- self.obj_Mainview.obj_dockarea.kicadToNgspiceEditor()"""
-
-
+
+
+ def open_OMedit(self):
+ """
+ This function call ngspice to OM edit converter and then launch OM edit.
+ """
+ self.obj_appconfig.print_info('OM edit is called')
+ self.projDir = self.obj_appconfig.current_project["ProjectName"]
- def testing(self):
- print "Success hit kicad button"
+ if self.projDir != None:
+ if self.obj_validation.validateCirOut(self.projDir):
+ self.projName = os.path.basename(self.projDir)
+ self.ngspiceNetlist = os.path.join(self.projDir,self.projName+".cir.out")
+ self.modelicaNetlist = os.path.join(self.projDir,self.projName+".mo")
+
+ try:
+ #Creating a command for Ngspice to Modelica converter
+ self.cmd1 = "python ../ngspicetoModelica/NgspicetoModelica.py "+self.ngspiceNetlist
+ self.obj_workThread1 = Worker.WorkerThread(self.cmd1)
+ self.obj_workThread1.start()
+
+
+ if self.obj_validation.validateTool("OMEdit"):
+ #Creating command to run OMEdit
+ self.cmd2 = "OMEdit "+self.modelicaNetlist
+ self.obj_workThread2 = Worker.WorkerThread(self.cmd2)
+ self.obj_workThread2.start()
+ else:
+ self.msg = QtGui.QMessageBox()
+ self.msgContent = "There was an error while opening OMEdit.<br/>\
+ Please make sure OpenModelica is installed in your system. <br/>\
+ To install it on Linux : Go to <a href=https://www.openmodelica.org/download/download-linux>OpenModelica Linux</a> and install nigthly build release.<br/>\
+ To install it on Windows : Go to <a href=https://www.openmodelica.org/download/download-windows>OpenModelica Windows</a> and install latest version.<br/>"
+ self.msg.setTextFormat(QtCore.Qt.RichText)
+ self.msg.setText(self.msgContent)
+ self.msg.setWindowTitle("Missing OpenModelica")
+ self.obj_appconfig.print_info(self.msgContent)
+ self.msg.exec_()
+
+ except Exception as e:
+ self.msg = QtGui.QErrorMessage()
+ self.msg.showMessage('Unable to convert NgSpice netlist to Modelica netlist :'+str(e))
+ self.msg.setWindowTitle("Ngspice to Modelica conversion error")
+ self.obj_appconfig.print_error(str(e))
+
+ else:
+ self.msg = QtGui.QErrorMessage()
+ self.msg.showMessage('Current project does not contain any ngspice file. Please create ngspice file with extension .cir.out')
+ self.msg.setWindowTitle("Missing Ngspice netlist")
+ else:
+ self.msg = QtGui.QErrorMessage()
+ self.msg.showMessage('Please select the project first. You can either create new project or open existing project')
+ self.msg.setWindowTitle("Error Message")
+
+ def open_OMoptim(self):
+ print "OM Optim is called"
+ self.obj_appconfig.print_info('OM Optim is called')
+ #Check if OMOptim is installed
+ if self.obj_validation.validateTool("OMOptim"):
+ #Creating a command to run
+ self.cmd = "OMOptim"
+ self.obj_workThread = Worker.WorkerThread(self.cmd)
+ self.obj_workThread.start()
+ else:
+ self.msg = QtGui.QMessageBox()
+ self.msgContent = "There was an error while opening OMOptim.<br/>\
+ Please make sure OpenModelica is installed in your system. <br/>\
+ To install it on Linux : Go to <a href=https://www.openmodelica.org/download/download-linux>OpenModelica Linux</a> and install nigthly build release.<br/>\
+ To install it on Windows : Go to <a href=https://www.openmodelica.org/download/download-windows>OpenModelica Windows</a> and install latest version.<br/>"
+ self.msg.setTextFormat(QtCore.Qt.RichText)
+ self.msg.setText(self.msgContent)
+ self.msg.setWindowTitle("Error Message")
+ self.obj_appconfig.print_info(self.msgContent)
+ self.msg.exec_()
class MainView(QtGui.QWidget):
"""
diff --git a/src/frontEnd/Application.py.bkp b/src/frontEnd/Application.py.bkp
deleted file mode 100755
index 408cd967..00000000
--- a/src/frontEnd/Application.py.bkp
+++ /dev/null
@@ -1,363 +0,0 @@
-#===============================================================================
-#
-# FILE: Application.py
-#
-# USAGE: ---
-#
-# DESCRIPTION: This main file use to start the Application
-#
-# OPTIONS: ---
-# REQUIREMENTS: ---
-# BUGS: ---
-# NOTES: ---
-# AUTHOR: Fahim Khan, fahim.elex@gmail.com
-# ORGANIZATION: eSim team at FOSSEE, IIT Bombay.
-# CREATED: Wednesday 21 January 2015
-# REVISION: ---
-#===============================================================================
-import os
-import sys
-#Setting PYTHONPATH
-cwd = os.getcwd()
-(setPath,fronEnd) = os.path.split(cwd)
-sys.path.append(setPath)
-
-from PyQt4 import QtGui, QtCore
-from configuration.Appconfig import Appconfig
-from projManagement.openProject import OpenProjectInfo
-from projManagement.newProject import NewProjectInfo
-from projManagement.Kicad import Kicad
-from frontEnd import ProjectExplorer
-from frontEnd import Workspace
-from frontEnd import DockArea
-import time
-from PyQt4.Qt import QSize
-
-
-class Application(QtGui.QMainWindow):
- global project_name
- """
- Its our main window of application
- """
- def __init__(self,*args):
- """
- Initialize main Application window
- """
- #Calling __init__ of super class
- QtGui.QMainWindow.__init__(self,*args)
-
- #Creating require Object
- self.obj_workspace = Workspace.Workspace()
- self.obj_kicad = Kicad()
- self.obj_Mainview = MainView()
- self.obj_appconfig = Appconfig()
-
- #Initialize all widget
- self.setCentralWidget(self.obj_Mainview)
- self.initToolBar()
-
- self.setGeometry(self.obj_appconfig._app_xpos,
- self.obj_appconfig._app_ypos,
- self.obj_appconfig._app_width,
- self.obj_appconfig._app_heigth)
- self.setWindowTitle(self.obj_appconfig._APPLICATION)
- self.showMaximized()
- self.setWindowIcon(QtGui.QIcon('../../images/logo.png'))
- #self.show()
-
-
- def initToolBar(self):
- """
- This function initialize Tool Bar
- """
- #Top Tool bar
- self.newproj = QtGui.QAction(QtGui.QIcon('../../images/newProject.png'),'<b>New Project</b>',self)
- self.newproj.setShortcut('Ctrl+N')
- self.newproj.triggered.connect(self.new_project)
- #self.newproj.connect(self.newproj,QtCore.SIGNAL('triggered()'),self,QtCore.SLOT(self.new_project()))
-
- self.openproj = QtGui.QAction(QtGui.QIcon('../../images/openProject.png'),'<b>Open Project</b>',self)
- self.openproj.setShortcut('Ctrl+O')
- self.openproj.triggered.connect(self.open_project)
-
- self.exitproj = QtGui.QAction(QtGui.QIcon('../../images/closeProject.png'),'<b>Exit</b>',self)
- self.exitproj.setShortcut('Ctrl+X')
- self.exitproj.triggered.connect(self.exit_project)
-
- self.helpfile = QtGui.QAction(QtGui.QIcon('../../images/helpProject.png'),'<b>Help</b>',self)
- self.helpfile.setShortcut('Ctrl+H')
- self.helpfile.triggered.connect(self.help_project)
-
- self.topToolbar = self.addToolBar('Top Tool Bar')
- self.topToolbar.addAction(self.newproj)
- self.topToolbar.addAction(self.openproj)
- self.topToolbar.addAction(self.exitproj)
- self.topToolbar.addAction(self.helpfile)
-
- self.spacer = QtGui.QWidget()
- self.spacer.setSizePolicy(QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
- self.topToolbar.addWidget(self.spacer)
- self.logo = QtGui.QLabel()
- self.logopic = QtGui.QPixmap(os.path.join(os.path.abspath('../..'),'images','fosseeLogo.png'))
- self.logopic = self.logopic.scaled(QSize(150,150),QtCore.Qt.KeepAspectRatio)
- self.logo.setPixmap(self.logopic)
- self.logo.setStyleSheet("padding:0 15px 0 0;")
- self.topToolbar.addWidget(self.logo)
-
- #Left Tool bar Action Widget
- self.kicad = QtGui.QAction(QtGui.QIcon('../../images/kicad.png'),'<b>Open Schematic</b>',self)
- self.kicad.triggered.connect(self.obj_kicad.openSchematic)
-
- self.conversion = QtGui.QAction(QtGui.QIcon('../../images/ki-ng.png'),'<b>Convert Kicad to Ngspice</b>',self)
- self.conversion.triggered.connect(self.obj_kicad.openKicadToNgspice)
-
- self.ngspice = QtGui.QAction(QtGui.QIcon('../../images/ngspice.png'), '<b>Simulation</b>', self)
- self.ngspice.triggered.connect(self.open_ngspice)
-
- self.footprint = QtGui.QAction(QtGui.QIcon('../../images/footprint.png'),'<b>Footprint Editor</b>',self)
- self.footprint.triggered.connect(self.obj_kicad.openFootprint)
-
- self.pcb = QtGui.QAction(QtGui.QIcon('../../images/pcb.png'),'<b>PCB Layout</b>',self)
- self.pcb.triggered.connect(self.obj_kicad.openLayout)
-
- self.model = QtGui.QAction(QtGui.QIcon('../../images/model.png'),'<b>Model Editor</b>',self)
- self.model.triggered.connect(self.open_modelEditor)
-
- self.subcircuit=QtGui.QAction(QtGui.QIcon('../../images/subckt.png'),'<b>Subcircuit</b>',self)
- self.subcircuit.triggered.connect(self.open_subcircuit)
-
- #Adding Action Widget to tool bar
- self.lefttoolbar = QtGui.QToolBar('Left ToolBar')
- self.addToolBar(QtCore.Qt.LeftToolBarArea, self.lefttoolbar)
- self.lefttoolbar.addAction(self.kicad)
- self.lefttoolbar.addAction(self.conversion)
- self.lefttoolbar.addAction(self.ngspice)
- self.lefttoolbar.addAction(self.footprint)
- self.lefttoolbar.addAction(self.pcb)
- self.lefttoolbar.addAction(self.model)
- self.lefttoolbar.addAction(self.subcircuit)
- self.lefttoolbar.setOrientation(QtCore.Qt.Vertical)
- self.lefttoolbar.setIconSize(QSize(40,40))
-
-
- def new_project(self):
- """
- This function call New Project Info class.
- """
- text, ok = QtGui.QInputDialog.getText(self, 'New Project Info','Enter Project Name:')
- if ok:
- self.projname = (str(text))
- self.project = NewProjectInfo()
- directory, filelist =self.project.createProject(self.projname)
-
- self.obj_Mainview.obj_projectExplorer.addTreeNode(directory, filelist)
-
- else:
- print "No project created"
- self.obj_appconfig.print_info('No new project created')
- try:
- self.obj_appconfig.print_info('Current project is : ' + self.obj_appconfig.current_project["ProjectName"])
- except:
- pass
- def open_project(self):
- """
- This project call Open Project Info class
- """
- print "Open Project called"
- self.project = OpenProjectInfo()
-
- try:
- directory, filelist = self.project.body()
- self.obj_Mainview.obj_projectExplorer.addTreeNode(directory, filelist)
- except:
- pass
-
- def open_ngspice(self):
- """
- This Function execute ngspice on current project
- """
-
- self.projDir = self.obj_appconfig.current_project["ProjectName"]
-
- if self.projDir != None:
- self.obj_Mainview.obj_dockarea.ngspiceEditor(self.projDir)
- time.sleep(2) #Need permanent solution
- #Calling Python Plotting
-
- try:
- self.obj_Mainview.obj_dockarea.plottingEditor()
- except Exception as e:
- self.msg = QtGui.QErrorMessage(None)
- self.msg.showMessage('Error while opening python plotting Editor.')
- print "Exception:",str(e)
- self.obj_appconfig.print_error('Exception generated : ' + str(e))
- self.msg.setWindowTitle("Error Message")
-
- else:
- self.msg = QtGui.QErrorMessage()
- self.msg.showMessage('Please select the project first. You can either create new project or open existing project')
- self.msg.setWindowTitle("Error Message")
-
- def open_subcircuit(self):
- print "Subcircuit editor is called"
- self.obj_appconfig.print_info('Subcircuit editor is called')
- self.obj_Mainview.obj_dockarea.subcircuiteditor()
-
-
- def exit_project(self):
- print "Exit Project called"
- for proc in self.obj_appconfig.procThread_list:
- try:
- proc.terminate()
- except:
- pass
- ##Just checking if open and New window is open. If yes just close it when application is closed
- try:
- self.project.close()
- except:
- pass
-
- self.close()
-
- def help_project(self):
- print "Help is called"
- self.obj_appconfig.print_info('Help is called')
- print "Current Project : ",self.obj_appconfig.current_project
- #self.obj_appconfig.print_info('Current Project : ' + self.obj_appconfig.current_project['ProjectName'])
- #self.obj_Mainview.obj_dockarea.plottingEditor()
-
-
- def open_modelEditor(self):
- print "model editor is called"
- self.obj_appconfig.print_info('model editor is called')
- self.obj_Mainview.obj_dockarea.modelEditor()
-
- def testing(self):
- print "Success hit kicad button"
-
-
-class MainView(QtGui.QWidget):
- """
- This class initialize the Main View of Application
- """
- def __init__(self, *args):
- # call init method of superclass
- QtGui.QWidget.__init__(self, *args)
-
- self.obj_appconfig = Appconfig()
-
- self.leftSplit = QtGui.QSplitter()
- self.middleSplit = QtGui.QSplitter()
-
- self.mainLayout = QtGui.QVBoxLayout()
- #Intermediate Widget
- self.middleContainer = QtGui.QWidget()
- self.middleContainerLayout = QtGui.QVBoxLayout()
-
- #Area to be included in MainView
- self.noteArea = QtGui.QTextEdit()
- self.obj_appconfig.noteArea['Note'] = self.noteArea
- self.obj_appconfig.noteArea['Note'].append(' eSim Started......')
- self.obj_appconfig.noteArea['Note'].append('Project Selected : None')
- self.obj_appconfig.noteArea['Note'].append('\n')
-
- #CSS
- self.noteArea.setStyleSheet(" \
- QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; } \
- ")
-
- self.obj_dockarea = DockArea.DockArea()
- self.obj_projectExplorer = ProjectExplorer.ProjectExplorer()
-
- #Adding content to vertical middle Split.
- self.middleSplit.setOrientation(QtCore.Qt.Vertical)
- self.middleSplit.addWidget(self.obj_dockarea)
- self.middleSplit.addWidget(self.noteArea)
-
- #Adding middle split to Middle Container Widget
- self.middleContainerLayout.addWidget(self.middleSplit)
- self.middleContainer.setLayout(self.middleContainerLayout)
-
- #Adding content of left split
- self.leftSplit.addWidget(self.obj_projectExplorer)
- self.leftSplit.addWidget(self.middleContainer)
-
-
- #Adding to main Layout
- self.mainLayout.addWidget(self.leftSplit)
- self.leftSplit.setSizes([self.width()/4.5,self.height()])
- self.middleSplit.setSizes([self.width(),self.height()/2])
- self.setLayout(self.mainLayout)
-
-
-def main(args):
- """
- It is main function of the module.It starts the application
- """
- print "Starting eSim......"
- app = QtGui.QApplication(args)
-
- splash_pix = QtGui.QPixmap('../../images/splash_screen_esim.png')
- splash = QtGui.QSplashScreen(splash_pix,QtCore.Qt.WindowStaysOnTopHint)
- splash.setMask(splash_pix.mask())
- splash.show()
- #QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("Cleanlooks"))
- appView = Application()
- appView.splash=splash
- appView.obj_workspace.returnWhetherClickedOrNot(appView)
- appView.hide()
- appView.obj_workspace.show()
- sys.exit(app.exec_())
- #appView.hide()
- ########################################################################################################################################
-
- """splash_pix = QtGui.QPixmap('../images/splash_screen_esim.png')
- splash = QtGui.QSplashScreen(splash_pix,QtCore.Qt.WindowStaysOnTopHint)
- progressBar = QtGui.QProgressBar(splash)
- progressBar.setGeometry(0,470,1004,20)
- splash.setMask(splash_pix.mask())
- splash.show()
-
- for i in range(0, 100):
- progressBar.setValue(i)
- #cond=threading.Condition()
- if i==50:
-
- appView = Application()
- appView.hide()
- #appView.obj_workspace.returnWhetherClickedOrNot(appView)
- appView.obj_workspace.show()
- #appView.obj_workspace.show()
- appView.obj_workspace.calledFromApplicationToAssignSysAndApp(sys,app)#`11 ,cond)
- #with cond:
- #cond.wait()
-
- t = time.time()
- while time.time() < t + 0.1:
- app.processEvents()
-
- #time.sleep(2)
-
- #appView = Application()
- #appView.hide()
- splash.finish(appView)
- #sys.exit(app.exec_())
-
- #QtGui.QApplication.setStyle(QtGui.QStyleFactory.create("Cleanlooks"))
- #appView.obj_workspace.returnWhetherClickedOrNot(appView)
- #appView.obj_workspace.show()
- #appView.hide()
-
- appView.show()
- sys.exit(app.exec_())"""
-######################################################################################################################################################
-
-
-
-# Call main function
-if __name__ == '__main__':
- # Create and display the splash screen
- main(sys.argv)
-
-
-
diff --git a/src/frontEnd/Workspace.py b/src/frontEnd/Workspace.py
index cd44dd71..3e3cf0de 100644
--- a/src/frontEnd/Workspace.py
+++ b/src/frontEnd/Workspace.py
@@ -90,7 +90,7 @@ class Workspace(QtGui.QWidget):
self.window_open_close=1
self.close_var=1
#with var_cond:
- # var_cond.notify()
+ # var_cond.notify()
return QtGui.QWidget.close(self, *args, **kwargs)
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py
index 90443d31..aaf02f45 100644
--- a/src/kicadtoNgspice/DeviceModel.py
+++ b/src/kicadtoNgspice/DeviceModel.py
@@ -65,7 +65,7 @@ class DeviceModel(QtGui.QWidget):
transbox.setTitle("Add library for Transistor "+words[0]+" : "+words[4])
self.entry_var[self.count] = QtGui.QLineEdit()
self.entry_var[self.count].setText("")
- #global path_name
+ global path_name
try:
for child in root:
if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]:
@@ -116,7 +116,7 @@ class DeviceModel(QtGui.QWidget):
diodebox.setTitle("Add library for Diode "+words[0]+" : "+words[3])
self.entry_var[self.count] = QtGui.QLineEdit()
self.entry_var[self.count].setText("")
- global path_name
+ #global path_name
try:
for child in root:
if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]:
@@ -167,7 +167,7 @@ class DeviceModel(QtGui.QWidget):
jfetbox.setTitle("Add library for JFET "+words[0]+" : "+words[4])
self.entry_var[self.count] = QtGui.QLineEdit()
self.entry_var[self.count].setText("")
- global path_name
+ #global path_name
try:
for child in root:
if child.tag[0]==eachline[0] and child.tag[1]==eachline[1]:
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index a3e41a5f..df776e7e 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -92,11 +92,12 @@ class MainWindow(QtGui.QWidget):
print "SCHEMATICINFO",schematicInfo
#List storing model detail
- global modelList,outputOption,unknownModelList,multipleModelList
+ global modelList,outputOption,unknownModelList,multipleModelList,plotText
modelList = []
outputOption = []
- schematicInfo,outputOption,modelList,unknownModelList,multipleModelList = obj_proc.convertICintoBasicBlocks(schematicInfo,outputOption,modelList)
+ plotText = []
+ schematicInfo,outputOption,modelList,unknownModelList,multipleModelList,plotText = obj_proc.convertICintoBasicBlocks(schematicInfo,outputOption,modelList,plotText)
print "Unknown Model List",unknownModelList
print "Multiple Model List",multipleModelList
print "Model List",modelList
@@ -495,7 +496,7 @@ class MainWindow(QtGui.QWidget):
print "Analysis OutPut------>",analysisoutput
#Calling netlist file generation function
- self.createNetlistFile(store_schematicInfo)
+ self.createNetlistFile(store_schematicInfo,plotText)
self.msg = "The Kicad to Ngspice Conversion completed successfully!!!!!!"
QtGui.QMessageBox.information(self, "Information", self.msg, QtGui.QMessageBox.Ok)
@@ -513,7 +514,7 @@ class MainWindow(QtGui.QWidget):
if self.clarg2 == "sub":
self.createSubFile(subPath)
- def createNetlistFile(self,store_schematicInfo):
+ def createNetlistFile(self,store_schematicInfo,plotText):
print "Creating Final netlist"
#print "INFOLINE",infoline
#print "OPTIONINFO",optionInfo
@@ -603,6 +604,8 @@ class MainWindow(QtGui.QWidget):
#out.writelines(outputOption)
out.writelines('print allv > plot_data_v.txt\n')
out.writelines('print alli > plot_data_i.txt\n')
+ for item in plotText:
+ out.writelines(item+'\n')
out.writelines('.endc\n')
out.writelines('.end\n')
out.close()
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py.bkp b/src/kicadtoNgspice/KicadtoNgspice.py.bkp
deleted file mode 100644
index c262f564..00000000
--- a/src/kicadtoNgspice/KicadtoNgspice.py.bkp
+++ /dev/null
@@ -1,671 +0,0 @@
-#===============================================================================
-#
-# FILE: kicadtoNgspice.py
-#
-# USAGE: ---
-#
-# DESCRIPTION: This define all configuration used in Application.
-#
-# OPTIONS: ---
-# REQUIREMENTS: ---
-# BUGS: ---
-# NOTES: ---
-# AUTHOR: Fahim Khan, fahim.elex@gmail.com
-# ORGANIZATION: eSim team at FOSSEE, IIT Bombay.
-# CREATED: Wednesday 04 March 2015
-# REVISION: ---
-#===============================================================================
-import sys
-import os
-#Setting PYTHONPATH
-cwd = os.getcwd()
-(setPath,fronEnd) = os.path.split(cwd)
-sys.path.append(setPath)
-
-from PyQt4 import QtGui,QtCore
-from Processing import PrcocessNetlist
-import Analysis
-import Source
-import Model
-import DeviceModel
-import SubcircuitTab
-import Convert
-import TrackWidget
-
-from xml.etree import ElementTree as ET
-
-
-
-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.
- """
- def __init__(self):
- QtGui.QWidget.__init__(self)
- #Create object of track widget
- self.obj_track = TrackWidget.TrackWidget()
- """
- 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
- self.msg = QtGui.QErrorMessage()
- self.content = "Your schematic contain unknown model "+', '.join(unknownModelList)
- self.msg.showMessage(self.content)
- self.msg.setWindowTitle("Unknown Models")
-
- elif multipleModelList:
- print "Multiple Model List is : ",multipleModelList
- self.msg = QtGui.QErrorMessage()
- self.mcontent = "Look like you have duplicate model in modelParamXML directory "+', '.join(multipleModelList[0])
- self.msg.showMessage(self.mcontent)
- self.msg.setWindowTitle("Multiple Models")
-
- else:
- self.createMainWindow()
-
-
- def createMainWindow(self):
- """
- This function create main window of Kicad to Ngspice converter
- """
-
- self.grid = QtGui.QGridLayout(self)
- 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.setWindowTitle("Kicad To NgSpice Converter")
- self.show()
-
-
- def createcreateConvertWidget(self):
- global obj_analysis
- self.convertWindow = QtGui.QWidget()
- self.analysisTab = QtGui.QScrollArea()
- obj_analysis=Analysis.Analysis()
- 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)
- 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)
- 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)
- self.deviceModelTab.setWidget(obj_devicemodel)
- self.deviceModelTab.setWidgetResizable(True)
- global obj_subcircuitTab
- self.subcircuitTab = QtGui.QScrollArea()
- obj_subcircuitTab = SubcircuitTab.SubcircuitTab(schematicInfo)
- self.subcircuitTab.setWidget(obj_subcircuitTab)
- self.subcircuitTab.setWidgetResizable(True)
-
- self.tabWidget = QtGui.QTabWidget()
- #self.tabWidget.TabShape(QtGui.QTabWidget.Rounded)
- self.tabWidget.addTab(self.analysisTab,"Analysis")
- self.tabWidget.addTab(self.sourceTab,"Source Details")
- self.tabWidget.addTab(self.modelTab,"NgSpice Model")
- self.tabWidget.addTab(self.deviceModelTab,"Device Modeling")
- self.tabWidget.addTab(self.subcircuitTab,"Subcircuits")
- self.mainLayout = QtGui.QVBoxLayout()
- self.mainLayout.addWidget(self.tabWidget)
- #self.mainLayout.addStretch(1)
- self.convertWindow.setLayout(self.mainLayout)
- self.convertWindow.show()
-
-
- return self.convertWindow
-
- def callConvert(self):
- """
- Calling Convert Class Constructor
- """
- global schematicInfo
- global analysisoutput
- kicadFile = sys.argv[1]
- (projpath,filename)=os.path.split(kicadFile)
- project_name=os.path.basename(projpath)
- print "PROJ PATH---",projpath
-
-
- check=1
- try:
- fr=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'r')
- temp_tree=ET.parse(fr)
- temp_root=temp_tree.getroot()
- except:
- check=0
-
-
-
- fw=open(os.path.join(projpath,project_name+"_Previous_Values.xml"),'w')
- if check==0:
- attr_parent=ET.Element("KicadtoNgspice")
- if check==1:
- attr_parent=temp_root
-
- for child in attr_parent:
- if child.tag=="analysis":
- attr_parent.remove(child)
-
- attr_analysis=ET.SubElement(attr_parent,"analysis")
- attr_ac=ET.SubElement(attr_analysis,"ac")
- if obj_analysis.Lin.isChecked():
- ET.SubElement(attr_ac,"field1",name="Lin").text="true"
- ET.SubElement(attr_ac,"field2",name="Dec").text="false"
- ET.SubElement(attr_ac,"field3",name="Oct").text="false"
- elif obj_analysis.Dec.isChecked():
- ET.SubElement(attr_ac,"field1",name="Lin").text="false"
- ET.SubElement(attr_ac,"field2",name="Dec").text="true"
- ET.SubElement(attr_ac,"field3",name="Oct").text="false"
- if obj_analysis.Oct.isChecked():
- ET.SubElement(attr_ac,"field1",name="Lin").text="false"
- ET.SubElement(attr_ac,"field2",name="Dec").text="false"
- ET.SubElement(attr_ac,"field3",name="Oct").text="true"
- else:
- pass
- ET.SubElement(attr_ac,"field4",name="Start Frequency").text= str(obj_analysis.ac_entry_var[0].text())
- ET.SubElement(attr_ac,"field5",name="Stop Frequency").text= str(obj_analysis.ac_entry_var[1].text())
- ET.SubElement(attr_ac,"field6",name="No. of points").text= str(obj_analysis.ac_entry_var[2].text())
- ET.SubElement(attr_ac,"field7",name="Start Fre Combo").text= obj_analysis.ac_parameter[0]
- ET.SubElement(attr_ac,"field8",name="Stop Fre Combo").text= obj_analysis.ac_parameter[1]
- attr_dc=ET.SubElement(attr_analysis,"dc")
- ET.SubElement(attr_dc,"field1",name="Source Name").text= str(obj_analysis.dc_entry_var[0].text())
- ET.SubElement(attr_dc,"field2",name="Start").text= str(obj_analysis.dc_entry_var[1].text())
- ET.SubElement(attr_dc,"field3",name="Increment").text= str(obj_analysis.dc_entry_var[2].text())
- ET.SubElement(attr_dc,"field4",name="Stop").text= str(obj_analysis.dc_entry_var[3].text())
- ET.SubElement(attr_dc,"field5",name="Operating Point").text=str(obj_analysis.check.isChecked())
- print "OBJ_ANALYSIS.CHECK -----",obj_analysis.check.isChecked()
- ET.SubElement(attr_dc,"field6",name="Start Combo").text= obj_analysis.dc_parameter[0]
- ET.SubElement(attr_dc,"field7",name="Increment Combo").text=obj_analysis.dc_parameter[1]
- ET.SubElement(attr_dc,"field8",name="Stop Combo").text= obj_analysis.dc_parameter[2]
- attr_tran=ET.SubElement(attr_analysis,"tran")
- ET.SubElement(attr_tran,"field1",name="Start Time").text= str(obj_analysis.tran_entry_var[0].text())
- ET.SubElement(attr_tran,"field2",name="Step Time").text= str(obj_analysis.tran_entry_var[1].text())
- ET.SubElement(attr_tran,"field3",name="Stop Time").text= str(obj_analysis.tran_entry_var[2].text())
- ET.SubElement(attr_tran,"field4",name="Start Combo").text= obj_analysis.tran_parameter[0]
- ET.SubElement(attr_tran,"field5",name="Step Combo").text= obj_analysis.tran_parameter[1]
- ET.SubElement(attr_tran,"field6",name="Stop Combo").text= obj_analysis.tran_parameter[2]
- print "TRAN PARAMETER 2-----",obj_analysis.tran_parameter[2]
-
- #tree=ET.ElementTree(attr_analysis)
- #tree.write(f)
-
-
- if check==0:
- attr_source=ET.SubElement(attr_parent,"source")
- if check==1:
- for child in attr_parent:
- if child.tag=="source":
- attr_source=child
- count=1
- grand_child_count=1
- #global tmp_check
- #tmp_check=0
- for i in schematicInfo:
- tmp_check=0
- words=i.split(' ')
- wordv=words[0]
- for child in attr_source:
- if child.tag==wordv and child.text==words[len(words)-1]:
- tmp_check=1
- for grand_child in child:
- grand_child.text=str(obj_source.entry_var[grand_child_count].text())
- grand_child_count=grand_child_count+1
- grand_child_count=grand_child_count+1
- if tmp_check==0:
- words=i.split(' ')
- wordv=words[0]
- if wordv[0]=="v":
- attr_var=ET.SubElement(attr_source,words[0],name="Source type")
- attr_var.text=words[len(words)-1]
- #ET.SubElement(attr_ac,"field1",name="Lin").text="true"
- if words[len(words)-1]=="ac":
- #attr_ac=ET.SubElement(attr_var,"ac")
- ET.SubElement(attr_var,"field1",name="Amplitude").text=str(obj_source.entry_var[count].text())
- count=count+2
- elif words[len(words)-1]=="dc":
- #attr_dc=ET.SubElement(attr_var,"dc")
- ET.SubElement(attr_var,"field1",name="Value").text=str(obj_source.entry_var[count].text())
- count=count+2
- elif words[len(words)-1]=="sine":
- #attr_sine=ET.SubElement(attr_var,"sine")
- ET.SubElement(attr_var,"field1",name="Offset Value").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field2",name="Amplitude").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field3",name="Frequency").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field4",name="Delay Time").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field5",name="Damping Factor").text=str(obj_source.entry_var[count].text())
- count=count+2
- elif words[len(words)-1]=="pulse":
- #attr_pulse=ET.SubElement(attr_var,"pulse")
- ET.SubElement(attr_var,"field1",name="Initial Value").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field2",name="Pulse Value").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field3",name="Delay Time").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field4",name="Rise Time").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field5",name="Fall Time").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field5",name="Pulse width").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field5",name="Period").text=str(obj_source.entry_var[count].text())
- count=count+2
- elif words[len(words)-1]=="pwl":
- #attr_pwl=ET.SubElement(attr_var,"pwl")
- ET.SubElement(attr_var,"field1",name="Enter in pwl format").text=str(obj_source.entry_var[count].text())
- count=count+2
- elif words[len(words)-1]=="exp":
- #attr_exp=ET.SubElement(attr_var,"exp")
- ET.SubElement(attr_var,"field1",name="Initial Value").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field2",name="Pulsed Value").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field3",name="Rise Delay Time").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field4",name="Rise Time Constant").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field5",name="Fall TIme").text=str(obj_source.entry_var[count].text())
- count=count+1
- ET.SubElement(attr_var,"field6",name="Fall Time Constant").text=str(obj_source.entry_var[count].text())
- count=count+2
- else:
- pass
-
- #tree=ET.ElementTree(attr_source)
- #tree.write(f1)
-
-
-
- if check==0:
- attr_model=ET.SubElement(attr_parent,"model")
- if check==1:
- for child in attr_parent:
- if child.tag=="model":
- attr_model=child
- i=0
- #tmp_check is a variable to check for duplicates in the xml file
- tmp_check=0
- #tmp_i is the iterator in case duplicates are there; then in that case we need to replace only the child node and not create a new parent node
-
- for line in modelList:
- print "i for each line in model List------",i
- tmp_check=0
- for rand_itr in obj_model.obj_trac.modelTrack:
- if rand_itr[2]==line[2] and rand_itr[3]==line[3]:
- start=rand_itr[7]
- end=rand_itr[8]
- i=start
- for child in attr_model:
- if child.text==line[2] and child.tag==line[3]:
- for grand_child in child:
- if i<=end:
- grand_child.text=str(obj_model.obj_trac.model_entry_var[i].text())
- print "STR OF MODEL----",str(obj_model.obj_trac.model_entry_var[i].text())
- i=i+1
- print "i incremented to ",i
- else:
- pass
- tmp_check=1
-
- if tmp_check==0:
- attr_ui=ET.SubElement(attr_model,line[3],name="type")
- attr_ui.text=line[2]
- for key,value in line[7].iteritems():
- if hasattr(value, '__iter__') and i<=end:
- for item in value:
- ET.SubElement(attr_ui,"field"+str(i+1),name=item).text=str(obj_model.obj_trac.model_entry_var[i].text())
- print "STR OF MODEL----",str(obj_model.obj_trac.model_entry_var[i].text())
- i=i+1
- print "i incremented to ",i
- else:
- ET.SubElement(attr_ui,"field"+str(i+1),name=value).text=str(obj_model.obj_trac.model_entry_var[i].text())
- print "STR OF MODEL----",str(obj_model.obj_trac.model_entry_var[i].text())
- i=i+1
- print "i incremented to ",i
- #################################################################################################################
- if check==0:
- attr_devicemodel=ET.SubElement(attr_parent,"devicemodel")
- if check==1:
- for child in attr_parent:
- if child.tag=="devicemodel":
- del child[:]
- attr_devicemodel=child
- #print "Device model dict",obj_devicemodel.devicemodel_dict_beg
- #print "Device model dict end",obj_devicemodel.devicemodel_dict_end
- ##########################
- for i in obj_devicemodel.devicemodel_dict_beg:
- attr_var=ET.SubElement(attr_devicemodel,i)
- it=obj_devicemodel.devicemodel_dict_beg[i]
- end=obj_devicemodel.devicemodel_dict_end[i]
- while it<=end:
- ET.SubElement(attr_var,"field").text=str(obj_devicemodel.entry_var[it].text())
- it=it+1
- #####################################
-
- """keys=obj_devicemodel.devicemodel_dict.keys()
- n=len(keys)
- for i in range(n):
- thisKey=keys[i]
- nextKey=keys[(i+1)%n]
- nextValue=obj_devicemodel.devicemodel_dict[nextKey]
- attr_var=ET.SubElement(attr_devicemodel,thisKey)
- it=obj_devicemodel.devicemodel_dict[thisKey]
- while it<=nextValue:
- ET.SubElement(attr_var,"field").text=obj_devicemodel.entry_var[it]"""
-
- ###################################################################################################################
-
- if check==0:
- attr_subcircuit=ET.SubElement(attr_parent,"subcircuit")
- if check==1:
- for child in attr_parent:
- if child.tag=="subcircuit":
- del child[:]
- attr_subcircuit=child
- ##########################
- for i in obj_subcircuitTab.subcircuit_dict_beg:
- attr_var=ET.SubElement(attr_subcircuit,i)
- it=obj_subcircuitTab.subcircuit_dict_beg[i]
- end=obj_subcircuitTab.subcircuit_dict_end[i]
-
- while it<=end:
- ET.SubElement(attr_var,"field").text=str(obj_subcircuitTab.entry_var[it].text())
- it=it+1
-
-
- tree=ET.ElementTree(attr_parent)
- tree.write(fw)
-
-
- self.obj_convert = Convert.Convert(self.obj_track.sourcelisttrack["ITEMS"],
- self.obj_track.source_entry_var["ITEMS"],
- schematicInfo)
-
- try:
- #Adding Source Value to Schematic Info
- schematicInfo = self.obj_convert.addSourceParameter()
-
- #Adding Model Value to schematicInfo
- schematicInfo = self.obj_convert.addModelParameter(schematicInfo)
-
- #Adding Device Library to SchematicInfo
- schematicInfo = self.obj_convert.addDeviceLibrary(schematicInfo,kicadFile)
-
- #Adding Subcircuit Library to SchematicInfo
- schematicInfo = self.obj_convert.addSubcircuit(schematicInfo, kicadFile)
-
- analysisoutput = self.obj_convert.analysisInsertor(self.obj_track.AC_entry_var["ITEMS"],
- self.obj_track.DC_entry_var["ITEMS"],
- self.obj_track.TRAN_entry_var["ITEMS"],
- self.obj_track.set_CheckBox["ITEMS"],
- self.obj_track.AC_Parameter["ITEMS"],
- self.obj_track.DC_Parameter["ITEMS"],
- self.obj_track.TRAN_Parameter["ITEMS"],
- 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()
- 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]
-
- if len(sys.argv)>2:
- if sys.argv[2] == "sub":
- self.createSubFile(subPath)
-
- def createNetlistFile(self,schematicInfo):
- print "Creating Final netlist"
- #print "INFOLINE",infoline
- #print "OPTIONINFO",optionInfo
- #print "Device MODEL LIST ",devicemodelList
- #print "SUBCKT ",subcktList
- #print "OUTPUTOPTION",outputOption
- #print "KicadfIle",kicadFile
-
- #checking if analysis files is present
- (projpath,filename) = os.path.split(kicadFile)
- analysisFileLoc = os.path.join(projpath,"analysis")
- #print "Analysis File Location",analysisFileLoc
- if os.path.exists(analysisFileLoc):
- try:
- f = open(analysisFileLoc)
- #Read data
- data = f.read()
- # Close the file
- f.close()
-
- except :
- print "Error While opening Project Analysis file. Please check it"
- sys.exit()
- else:
- print analysisFileLoc + " does not exist"
- sys.exit()
-
- #Adding analysis file info to optionInfo
- analysisData=data.splitlines()
- for eachline in analysisData:
- eachline=eachline.strip()
- if len(eachline)>1:
- if eachline[0]=='.':
- optionInfo.append(eachline)
- else:
- pass
-
- #print "Option Info",optionInfo
- analysisOption = []
- initialCondOption=[]
- simulatorOption =[]
- #includeOption=[] #Don't know why to use it
- #model = [] #Don't know why to use it
-
- for eachline in optionInfo:
- words=eachline.split()
- option=words[0]
- if (option=='.ac' or option=='.dc' or option=='.disto' or option=='.noise' or
- option=='.op' or option=='.pz' or option=='.sens' or option=='.tf' or
- option=='.tran'):
- analysisOption.append(eachline+'\n')
-
- elif (option=='.save' or option=='.print' or option=='.plot' or option=='.four'):
- eachline=eachline.strip('.')
- outputOption.append(eachline+'\n')
- elif (option=='.nodeset' or option=='.ic'):
- initialCondOption.append(eachline+'\n')
- elif option=='.option':
- simulatorOption.append(eachline+'\n')
- #elif (option=='.include' or option=='.lib'):
- # includeOption.append(eachline+'\n')
- #elif (option=='.model'):
- # model.append(eachline+'\n')
- elif option=='.end':
- continue;
-
-
- #Start creating final netlist cir.out file
- outfile = kicadFile+".out"
- out=open(outfile,"w")
- out.writelines(infoline)
- out.writelines('\n')
- sections=[simulatorOption, initialCondOption, schematicInfo, analysisOption]
- print "SECTIONS",sections
- for section in sections:
- if len(section) == 0:
- continue
- else:
- for line in section:
- out.writelines('\n')
- out.writelines(line)
-
- out.writelines('\n* Control Statements \n')
- out.writelines('.control\n')
- out.writelines('run\n')
- #out.writelines(outputOption)
- out.writelines('print allv > plot_data_v.txt\n')
- out.writelines('print alli > plot_data_i.txt\n')
- out.writelines('.endc\n')
- out.writelines('.end\n')
-
- out.close()
-
- def createSubFile(self,subPath):
- self.project = subPath
- self.projName = os.path.basename(self.project)
- if os.path.exists(self.project+".cir.out"):
- try:
- f = open(self.project+".cir.out")
- except :
- print("Error in opening .cir.out file.")
- else:
- print self.projName + ".cir.out does not exist. Please create a spice netlist."
-
- # Read the data from file
- data=f.read()
- # Close the file
-
- f.close()
- newNetlist=[]
- netlist=iter(data.splitlines())
- for eachline in netlist:
- eachline=eachline.strip()
- if len(eachline)<1:
- continue
- words=eachline.split()
- if eachline[2] == 'u':
- if words[len(words)-1] == "port":
- subcktInfo = ".subckt "+self.projName+" "
- for i in range(2,len(words)-1):
- subcktInfo+=words[i]+" "
- continue
- if words[0] == ".end" or words[0] == ".ac" or words[0] == ".dc" or words[0] == ".tran" or words[0] == '.disto' or words[0] == '.noise' or words[0] == '.op' or words[0] == '.pz' or words[0] == '.sens' or words[0] == '.tf':
- continue
- elif words[0] == ".control":
- while words[0] != ".endc":
- eachline=netlist.next()
- eachline=eachline.strip()
- if len(eachline)<1:
- continue
- words=eachline.split()
- else:
- newNetlist.append(eachline)
-
- outfile=self.project+".sub"
- out=open(outfile,"w")
- out.writelines("* Subcircuit " + self.projName)
- out.writelines('\n')
- out.writelines(subcktInfo)
- out.writelines('\n')
-
- for i in range(len(newNetlist),0,-1):
- newNetlist.insert(i,'\n')
-
- out.writelines(newNetlist)
- out.writelines('\n')
-
- 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)
-
-
-
-
-
-
- \ No newline at end of file
diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py
index b0f60826..0eaf6d2f 100644
--- a/src/kicadtoNgspice/Processing.py
+++ b/src/kicadtoNgspice/Processing.py
@@ -152,10 +152,12 @@ class PrcocessNetlist:
return schematicInfo,sourcelist
- def convertICintoBasicBlocks(self,schematicInfo,outputOption,modelList):
+ def convertICintoBasicBlocks(self,schematicInfo,outputOption,modelList,plotText):
#Insert details of Ngspice model
unknownModelList = []
multipleModelList = []
+ plotList = ['plot_v1','plot_v2','plot_i2','plot_log','plot_db','plot_phase']
+
k = 1
for compline in schematicInfo:
words = compline.split()
@@ -177,7 +179,7 @@ class PrcocessNetlist:
print "Words",words
print "compName",compName
#Looking if model file is present
- if compType != "port" and compType != "ic":
+ if compType != "port" and compType != "ic" and compType not in plotList:
xmlfile = compType+".xml" #XML Model File
count = 0 #Check if model of same name is present
modelPath = []
@@ -304,14 +306,41 @@ class PrcocessNetlist:
text = "Enter initial voltage at node for "+compline
paramDict[title] = text
modelList.append([index,compline,modelname,compName,comment,title,type,paramDict])
+
+ elif compType in plotList:
+ print "Plot Data---------->"
+ schematicInfo.insert(index,"* "+compline)
+ if compType == 'plot_v1':
+ words = compline.split()
+ plotText.append("plot v("+words[1]+")")
+ elif compType == 'plot_v2':
+ words = compline.split()
+ plotText.append("plot v("+words[1]+","+words[2]+")")
+ elif compType == 'plot_i2':
+ words = compline.split()
+ #Adding zero voltage source to netlist
+ schematicInfo.append("v_"+words[0]+" "+words[1]+" "+words[2]+" "+"0")
+ plotText.append("plot i(v_"+words[0]+")")
+ elif compType == 'plot_log':
+ words = compline.split()
+ plotText.append("plot log("+words[1]+")")
+ elif compType == 'plot_db':
+ words = compline.split()
+ plotText.append("plot db("+words[1]+")")
+ elif compType == 'plot_phase':
+ words = compline.split()
+ plotText.append("plot phase("+words[1]+")")
+
else:
schematicInfo.insert(index,"* "+compline)
+
+
#print "Count",count
#print "UnknownModelList",unknownModelList
#print "MultipleModelList",multipleModelList
- return schematicInfo,outputOption,modelList,unknownModelList,multipleModelList
+ return schematicInfo,outputOption,modelList,unknownModelList,multipleModelList,plotText
- \ No newline at end of file
+
diff --git a/src/modelParamXML/Nghdl/inverter.xml b/src/modelParamXML/Nghdl/inverter.xml
new file mode 100644
index 00000000..894389e0
--- /dev/null
+++ b/src/modelParamXML/Nghdl/inverter.xml
@@ -0,0 +1 @@
+<model><name>inverter</name><type>Nghdl</type><node_number>2</node_number><title>Add parameters for inverter</title><split>2-V:2-V</split><param><rise_delay default="1.0e-9">Enter Rise Delay (default=1.0e-9)</rise_delay><fall_delay default="1.0e-9">Enter Fall Delay (default=1.0e-9)</fall_delay><input_load default="1.0e-12">Enter Input Load (default=1.0e-12)</input_load><instance_id default="1">Enter Instance ID (Between 0-99)</instance_id></param></model> \ No newline at end of file
diff --git a/src/modelParamXML/Nghdl/myxor.xml b/src/modelParamXML/Nghdl/myxor.xml
new file mode 100644
index 00000000..c245879e
--- /dev/null
+++ b/src/modelParamXML/Nghdl/myxor.xml
@@ -0,0 +1 @@
+<model><name>myxor</name><type>Nghdl</type><node_number>3</node_number><title>Add parameters for myxor</title><split>1-V:1-V:1-V</split><param><rise_delay default="1.0e-9">Enter Rise Delay (default=1.0e-9)</rise_delay><fall_delay default="1.0e-9">Enter Fall Delay (default=1.0e-9)</fall_delay><input_load default="1.0e-12">Enter Input Load (default=1.0e-12)</input_load><instance_id default="1">Enter Instance ID (Between 0-99)</instance_id></param></model> \ No newline at end of file
diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py
index f2ad973f..402c20e3 100644
--- a/src/ngspiceSimulation/NgspiceWidget.py
+++ b/src/ngspiceSimulation/NgspiceWidget.py
@@ -15,11 +15,14 @@ class NgspiceWidget(QtGui.QWidget):
self.layout = QtGui.QVBoxLayout(self)
self.layout.addWidget(self.terminal)
print"command-------->", command
+
if platform.system() == 'Linux':
self.command = "cd "+projPath+";ngspice "+command
#Creating argument for process
- self.args = ['-into', str(self.terminal.winId()),'-hold','-e', self.command]
+ #self.args = ['-into', str(self.terminal.winId()),'-hold','-e', self.command]
+ self.args = ['-hold','-e', self.command]
self.process.start('xterm', self.args)
+ self.obj_appconfig.process_obj.append(self.process)
elif platform.system() == 'Windows':
tempdir= os.getcwd()
diff --git a/src/ngspiceSimulation/pythonPlotting.py b/src/ngspiceSimulation/pythonPlotting.py
index 7d37623d..d93ba235 100644
--- a/src/ngspiceSimulation/pythonPlotting.py
+++ b/src/ngspiceSimulation/pythonPlotting.py
@@ -3,7 +3,7 @@ import os
from PyQt4 import QtGui, QtCore
from decimal import Decimal
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
-from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
+from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from configuration.Appconfig import Appconfig
@@ -687,4 +687,4 @@ class DataExtraction:
- \ No newline at end of file
+
diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py
new file mode 100644
index 00000000..95f991bd
--- /dev/null
+++ b/src/ngspicetoModelica/NgspicetoModelica.py
@@ -0,0 +1,786 @@
+import sys
+import os
+import re
+from string import maketrans
+
+class NgMoConverter:
+ def __init__(self):
+ pass
+
+ def readNetlist(self,filename):
+ """
+ Read Ngspice Netlist
+ """
+ if os.path.exists(filename):
+ try:
+ f = open(filename)
+ except Exception as e:
+ print("Error in opening file")
+ print(str(e))
+ sys.exit()
+ else:
+ print filename + " does not exist"
+ sys.exit()
+
+ data = f.read()
+ #data = data.translate(maketrans('\n+', ' '))
+ f.close()
+ return data.splitlines()
+
+ def separateNetlistInfo(self,data):
+ """
+ Separate schematic data and option data
+ """
+ optionInfo = []
+ schematicInfo = []
+ for eachline in data:
+ if len(eachline) > 1:
+ #if eachline[0] == '+':
+ # eachline=eachline.translate(maketrans('\n+',' '))
+ if eachline[0]=='*':
+ continue
+ elif eachline[0]=='.':
+ optionInfo.append(eachline.lower())
+ else:
+ schematicInfo.append(eachline.lower())
+ return optionInfo,schematicInfo
+
+ def addModel(self,optionInfo):
+ """
+ Add model parameters in the modelica file and create dictionary of model parameters
+ This function extract model and subckt information along with their parameters with the help of optionInfo
+ """
+ modelName = []
+ modelInfo = {}
+ subcktName = []
+ paramInfo = []
+ inbuiltmodelName = []
+ inbuiltmodelInfo = {}
+ #modelInfo['paramInfo'] = {}
+ for eachline in optionInfo:
+ words = eachline.split()
+ if words[0] == '.include':
+ name = words[1].split('.')
+ if name[1] == 'lib':
+ modelName.append(name[0])
+ if name[1] == 'sub':
+ subcktName.append(name[0])
+ elif words[0] == '.param':
+ paramInfo.append(eachline)
+ elif words[0] == '.model':
+ name = words[1]+':'+words[2].split('(')[0] #model_ref_name:actual_model_name
+ inbuiltmodelName.append(name)
+ inbuiltmodelInfo[name] = {}
+ #Get all the data with () of .model line
+ paramData = re.compile("\((.*)\)" ).search(eachline).group(1)
+ info = paramData.split()
+ for eachitem in info:
+ eachitem = eachitem.split('=')
+ inbuiltmodelInfo[name][eachitem[0]] = eachitem[1]
+
+
+ #Adding details of model(external) and subckt into modelInfo and subcktInfo
+ for eachmodel in modelName:
+ filename = eachmodel + '.lib'
+ if os.path.exists(filename):
+ try:
+ f = open(filename)
+ except:
+ print("Error in opening file")
+ sys.exit()
+ else:
+ print filename + " does not exist"
+ sys.exit()
+ data = f.read()
+ data = data.lower()
+ newdata = data.split('(')
+ newdata = newdata[1].split()
+ modelInfo[eachmodel] = {}
+
+ for eachline in newdata:
+ if len(eachline) > 1:
+ info = eachline.split('=')
+ # modelInfo[eachmodel][info[0]] = {}
+ for eachitem in info:
+ modelInfo[eachmodel][info[0]] = info[1] #dic within a dic
+ #modelInfo[eachmodel] = modelInfo[eachmodel].split()
+ # modelInfo[eachmodel] = modelInfo[eachmodel].lower()
+ f.close()
+
+
+ return modelName, modelInfo, subcktName, paramInfo,inbuiltmodelName,inbuiltmodelInfo
+
+ def processParam(self,paramInfo):
+ """
+ Process parameter info and update in Modelica syntax
+ """
+ modelicaParam = []
+ for eachline in paramInfo:
+ eachline = eachline.split('.param')
+ #Include ',' in between parameter
+ #Removing leading and trailing space
+ line = eachline[1].strip()
+ line = line.split()
+ final_line = ','.join(line)
+ stat = 'parameter Real ' + final_line + ';'
+ stat = stat.translate(maketrans('{}', ' '))
+ modelicaParam.append(stat)
+ print "Modelica Parameter----------->",modelicaParam
+ return modelicaParam
+
+
+ def separatePlot(self,schematicInfo):
+ """
+ separate print plot and component statements
+ """
+ compInfo = []
+ plotInfo = []
+ for eachline in schematicInfo:
+ words = eachline.split()
+ if words[0] == 'run':
+ continue
+ elif words[0] == 'plot' or words[0] == 'print':
+ plotInfo.append(eachline)
+ else:
+ compInfo.append(eachline)
+ return compInfo, plotInfo
+
+ def separateSource(self,compInfo):
+ """
+ Find if dependent sources are present in the schematic and if so make a dictionary with source details
+ """
+ sourceInfo = {}
+ source = []
+ for eachline in compInfo:
+ words = eachline.split() ##This line need to be confirmed with Manas
+ if eachline[0] in ['f', 'h']:
+ source.append(words[3])
+ if len(source) > 0:
+ for eachline in compInfo:
+ words_s = eachline.split()
+ if words_s[0] in source:
+ sourceInfo[words_s[0]] = words_s[1:3]
+ return sourceInfo
+
+ def splitIntoVal(self,val):
+ """
+ Split the number k,u,p,t,g etc into powers e3,e-6 etc
+ """
+ print "Val------------->",val
+ for i in range(0,len(val),1):
+ print "Val[i]----------------->",val[i]
+ if val[i] in ['k','u','p','t','g','m','n','f']:
+ newval = val.split(val[i])
+ print "new Value------------>",newval
+ if val[i] == 'k':
+ value = newval[0] + 'e3'
+ if val[i] == 'u':
+ value = newval[0] + 'e-6'
+ if val[i] == 'p':
+ value = newval[0] + 'e-12'
+ if val[i] == 't':
+ value = newval[0] + 'e12'
+ if val[i] == 'g':
+ value = newval[0] + 'e9'
+ if val[i] == 'm':
+ if i != len(val)-1:
+ if val[i+1] == 'e':
+ value = newval[0] + 'e6'
+ else:
+ value = newval[0] +'e-3'
+ if val[i] == 'n':
+ value = newval[0] + 'e-9'
+ if val[i] == 'f':
+ value = newval[0] +'e-15'
+
+ else:
+ value = val
+ return value
+
+ def compInit(self,compInfo, node, modelInfo, subcktName):
+ """
+ For each component in the netlist initialise it acc to Modelica format
+ """
+ print "CompInfo inside compInit function : compInit",compInfo
+ #### initial processing to check if MOs is present. If so, library to be used is BondLib
+ modelicaCompInit = []
+ numNodesSub = {}
+ IfMOS = '0'
+ for eachline in compInfo:
+ #words = eachline.split()
+ if eachline[0] == 'm':
+ IfMOS = '1'
+ break
+ if len(subcktName) > 0:
+ subOptionInfo = []
+ subSchemInfo = []
+ for eachsub in subcktName:
+ filename_tem = eachsub + '.sub'
+ data = self.readNetlist(filename_tem)
+ subOptionInfo, subSchemInfo = self.separateNetlistInfo(data)
+ for eachline in subSchemInfo:
+ #words = eachline.split()
+ if eachline[0] == 'm':
+ IfMOS = '1'
+ break
+ for eachline in compInfo:
+ words = eachline.split()
+ val = words[3]
+ value = self.splitIntoVal(val)
+ if eachline[0] == 'r':
+ stat = 'Analog.Basic.Resistor ' + words[0] + '(R = ' + value + ');'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'c':
+ stat = 'Analog.Basic.Capacitor ' + words[0] + '(C = ' + value + ');'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'l':
+ stat = 'Analog.Basic.Inductor ' + words[0] + '(L = ' + value + ');'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'e':
+ stat = 'Analog.Basic.VCV ' + words[0] + '(gain = ' + self.splitIntoVal(words[5]) + ');'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'g':
+ stat = 'Analog.Basic.VCC ' + words[0] + '(transConductance = ' + self.splitIntoVal(words[5]) + ');'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'f':
+ stat = 'Analog.Basic.CCC ' + words[0] + '(gain = ' + self.splitIntoVal(words[4]) + ');'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'h':
+ stat = 'Analog.Basic.CCV ' + words[0] + '(transResistance = ' + self.splitIntoVal(words[4]) + ');'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'd':
+ if len(words) > 3:
+ n = float(modelInfo[words[3]]['n'])
+ vt_temp = 0.025*n
+ vt = str(vt_temp)
+ stat = 'Analog.Semiconductors.Diode ' + words[0] + '(Ids = ' + modelInfo[words[3]]['is'] + ', Vt = ' + vt + ', R = 1e12' +');'
+ else:
+ stat = 'Analog.Semiconductors.Diode ' + words[0] +';'
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'm':
+ line_l = words[7].split('=')
+ line_w = words[8].split('=')
+ line_pd = words[9].split('=')
+ line_ps = words[10].split('=')
+ line_ad = words[11].split('=')
+ line_as = words[12].split('=')
+ if words[5] == "mos_n" or words[5] == "mosfet_n":
+ start = 'BondLib.Electrical.Analog.Spice.Mn '
+ if words[5] == "mos_p" or words[5] == "mosfet_p":
+ start = 'BondLib.Electrical.Analog.Spice.Mp '
+ stat = start + words[0] + '(Tnom = 300, VT0 = ' + modelInfo[\
+ words[5]]['vto'] + ', GAMMA = ' + modelInfo[words[5]]['gamma'] +\
+ ', PHI = ' + modelInfo[words[5]]['phi'] + ', LD = ' + self.splitIntoVal(modelInfo[words[5]]['ld'])\
+ + ', U0 = ' + str(float(self.splitIntoVal(modelInfo[words[5]]['uo']))*0.0001) + ', LAMBDA = ' \
+ + modelInfo[words[5]]['lambda'] + ', TOX = ' + self.splitIntoVal(modelInfo[words[5]]['tox']) \
+ + ', PB = ' + modelInfo[words[5]]['pb'] + ', CJ = ' + self.splitIntoVal(modelInfo[words[5]]['cj']) \
+ + ', CJSW = ' + self.splitIntoVal(modelInfo[words[5]]['cjsw']) + ', MJ = ' + modelInfo[words[5]]['mj'] \
+ + ', MJSW = ' + modelInfo[words[5]]['mjsw'] + ', CGD0 = ' + self.splitIntoVal(modelInfo[words[5]]['cgdo']) \
+ + ', JS = ' + self.splitIntoVal(modelInfo[words[5]]['js']) + ', CGB0 = ' + self.splitIntoVal(modelInfo[words[5]]['cgbo']) \
+ + ', CGS0 = ' + self.splitIntoVal(modelInfo[words[5]]['cgso']) + ', L = ' + self.splitIntoVal(line_l[1]) + ', W = ' \
+ + line_w[1] + ', Level = 1' + ', AD = ' + line_ad[1] + ', AS = ' + line_as[1] + ', PD = ' \
+ + line_pd[1] + ', PS = ' + line_pd[1] + ');'
+ stat = stat.translate(maketrans('{}', ' '))
+ modelicaCompInit.append(stat)
+ elif eachline[0] == 'v':
+ typ = words[3].split('(')
+ if typ[0] == "pulse":
+ per = words[9].split(')')
+ #if IfMOS == '0':
+ #stat = 'Spice3.Sources.V_pulse '+words[0]+'(TR = '+words[6]+', V2 = '+words[4]+', PW = '+words[8]+', PER = '+per[0]+', V1 = '+typ[1]+', TD = '+words[5]+', TF = '+words[7]+');'
+ #elif IfMOS == '1':
+ stat = 'Analog.Sources.TrapezoidVoltage '+words[0]+'(rising = '+words[6]+', V = '+words[4]\
+ +', width = '+words[8]+', period = '+per[0]+', offset = '+typ[1]+', startTime = '+words[5]+', falling = '+words[7]+');'
+ modelicaCompInit.append(stat)
+ if typ[0] == "sine":
+ theta = words[7].split(')')
+ #if IfMOS == '0':
+ #stat = 'Spice3.Sources.V_sin '+words[0]+'(VO = '+typ[1]+', VA = '+words[4]+', FREQ = '+words[5]+', TD = '+words[6]+', THETA = '+theta[0]+');'
+ #elif IfMOS == '1':
+ stat = 'Analog.Sources.SineVoltage '+words[0]+'(offset = '+typ[1]+', V = '+words[4]+', freqHz = '+words[5]+', startTime = '+words[6]+', phase = '+theta[0]+');'
+ modelicaCompInit.append(stat)
+ if typ[0] == "pwl":
+ #if IfMOS == '0':
+ #keyw = 'Spice3.Sources.V_pwl '
+ #elif IfMOS == '1':
+ keyw = 'Analog.Sources.TableVoltage '
+ stat = keyw + words[0] + '(table = [' + typ[1] + ',' + words[4] + ';'
+ length = len(words);
+ for i in range(6,length,2):
+ if i == length-2:
+ w = words[i].split(')')
+ stat = stat + words[i-1] + ',' + w[0]
+ else:
+ stat = stat + words[i-1] + ',' + words[i] + ';'
+ stat = stat + ']);'
+ modelicaCompInit.append(stat)
+ if typ[0] == words[3] and typ[0] != "dc":
+ val_temp = typ[0].split('v')
+ #if IfMOS == '0':
+ stat = 'Analog.Sources.ConstantVoltage ' + words[0] + '(V = ' + val_temp[0] + ');'
+ #elif IfMOS == '1':
+ #stat = 'Analog.Sources.ConstantVoltage ' + words[0] + '(V = ' + val_temp[0] + ');'
+ modelicaCompInit.append(stat)
+ elif typ[0] == words[3] and typ[0] == "dc":
+ #if IfMOS == '0':
+ #stat = 'Spice3.Sources.V_constant ' + words[0] + '(V = ' + words[4] + ');' ### check this
+ #elif IfMOS == '1':
+ stat = 'Analog.Sources.ConstantVoltage ' + words[0] + '(V = ' + words[4] + ');' ### check this
+ modelicaCompInit.append(stat)
+
+ elif eachline[0] == 'x':
+ temp_line = eachline.split()
+ temp = temp_line[0].split('x')
+ index = temp[1]
+ for i in range(0,len(temp_line),1):
+ if temp_line[i] in subcktName:
+ subname = temp_line[i]
+ numNodesSub[subname] = i - 1
+ point = i
+ if len(temp_line) > point + 1:
+ rem = temp_line[point+1:len(temp_line)]
+ rem_new = ','.join(rem)
+ stat = subname + ' ' + subname +'_instance' + index + '(' + rem_new + ');'
+ else:
+ stat = subname + ' ' + subname +'_instance' + index + ';'
+ modelicaCompInit.append(stat)
+ else:
+ continue
+
+ if '0' in node:
+ modelicaCompInit.append('Analog.Basic.Ground g;')
+ return modelicaCompInit, numNodesSub
+
+ def getSubInterface(self,subname,numNodesSub):
+ """
+ Get the list of nodes for subcircuit in .subckt line
+ """
+ subOptionInfo_p = []
+ subSchemInfo_p = []
+ filename_t = subname + '.sub'
+ data_p = self.readNetlist(filename_t)
+ subOptionInfo_p, subSchemInfo_p = self.separateNetlistInfo(data_p)
+ if len(subOptionInfo_p) > 0:
+ newline = subOptionInfo_p[0]
+ newline = newline.split('.subckt '+ subname)
+ intLine = newline[1].split()
+ newindex = numNodesSub[subname]
+ nodesInfoLine = intLine[0:newindex]
+ return nodesInfoLine
+
+ def getSubParamLine(self,subname, numNodesSub, subParamInfo):
+ """
+ Take subcircuit name and give the info related to parameters in the first line and initislise it in
+ """
+ #nodeSubInterface = []
+ subOptionInfo_p = []
+ subSchemInfo_p = []
+ filename_t = subname + '.sub'
+ data_p = self.readNetlist(filename_t)
+ subOptionInfo_p, subSchemInfo_p = self.separateNetlistInfo(data_p)
+ print "subOptionInfo_p------------------------->",subOptionInfo_p
+ print "subSchemInfo_p----------------------------->",subSchemInfo_p
+ if len(subOptionInfo_p) > 0:
+ newline = subOptionInfo_p[0]
+ newline = newline.split('.subckt '+ subname)
+ intLine = newline[1].split()
+ print "numNodesSub Index---------->",numNodesSub
+ newindex = numNodesSub[subname]
+ appen_line = intLine[newindex:len(intLine)]
+ appen_param = ','.join(appen_line)
+ paramLine = 'parameter Real ' + appen_param + ';'
+ paramLine = paramLine.translate(maketrans('{}', ' '))
+ subParamInfo.append(paramLine)
+ return subParamInfo
+
+ def nodeSeparate(self,compInfo, ifSub, subname, subcktName,numNodesSub):
+ """
+ separate the node numbers and create nodes in modelica file;
+ the nodes in the subckt line should not be inside protected keyword. pinInit is the one that goes under protected keyword.
+ """
+ node = []
+ nodeTemp = []
+ nodeDic = {}
+ pinInit = 'Modelica.Electrical.Analog.Interfaces.Pin '
+ pinProtectedInit = 'Modelica.Electrical.Analog.Interfaces.Pin '
+ protectedNode = []
+ print "CompInfo coming to nodeSeparate function: compInfo",compInfo
+
+ #Removing '[' and ']' from compInfo for Digital node
+ for i in range(0,len(compInfo),1):
+ compInfo[i] = compInfo[i].replace("[","").replace("]","")
+
+
+
+ for eachline in compInfo:
+ words = eachline.split()
+ if eachline[0] in ['m', 'e', 'g', 't']:
+ nodeTemp.append(words[1])
+ nodeTemp.append(words[2])
+ nodeTemp.append(words[3])
+ nodeTemp.append(words[4])
+ elif eachline[0] in ['q', 'j']:
+ nodeTemp.append(words[1])
+ nodeTemp.append(words[2])
+ nodeTemp.append(words[3])
+ elif eachline[0] == 'x':
+ templine = eachline.split()
+ for i in range(0,len(templine),1):
+ if templine[i] in subcktName:
+ point = i
+ nodeTemp.extend(words[1:point])
+ else:
+ nodeTemp.append(words[1])
+ nodeTemp.append(words[2])
+ for i in nodeTemp:
+ if i not in node:
+ node.append(i)
+
+ for i in range(0, len(node),1):
+ nodeDic[node[i]] = 'n' + node[i]
+ if ifSub == '0':
+ if i != len(node)-1:
+ pinInit = pinInit + nodeDic[node[i]] + ', '
+ else:
+ pinInit = pinInit + nodeDic[node[i]]
+ else:
+ nonprotectedNode = self.getSubInterface(subname, numNodesSub)
+ if node[i] in nonprotectedNode:
+ continue
+ else:
+ protectedNode.append(node[i])
+ if ifSub == '1':
+ if len(nonprotectedNode) > 0:
+ for i in range(0, len(nonprotectedNode),1):
+ if i != len(nonprotectedNode)-1:
+ pinProtectedInit = pinProtectedInit + nodeDic[nonprotectedNode[i]] + ','
+ else:
+ pinProtectedInit = pinProtectedInit + nodeDic[nonprotectedNode[i]]
+ if len(protectedNode) > 0:
+ for i in range(0, len(protectedNode),1):
+ if i != len(protectedNode)-1:
+ pinInit = pinInit + nodeDic[protectedNode[i]] + ','
+ else:
+ pinInit = pinInit + nodeDic[protectedNode[i]]
+ pinInit = pinInit + ';'
+ pinProtectedInit = pinProtectedInit + ';'
+ return node, nodeDic, pinInit, pinProtectedInit
+
+
+ def connectInfo(self,compInfo, node, nodeDic, numNodesSub,subcktName):
+ """
+ Make node connections in the modelica netlist
+ """
+ connInfo = []
+ sourcesInfo = self.separateSource(compInfo)
+ for eachline in compInfo:
+ words = eachline.split()
+ if eachline[0] == 'r' or eachline[0] == 'c' or eachline[0] == 'd' or eachline[0] == 'l' or eachline[0] == 'v':
+ conn = 'connect(' + words[0] + '.p,' + nodeDic[words[1]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.n,' + nodeDic[words[2]] + ');'
+ connInfo.append(conn)
+ elif eachline[0] == 'm':
+ conn = 'connect(' + words[0] + '.D,' + nodeDic[words[1]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.G,' + nodeDic[words[2]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.S,' + nodeDic[words[3]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.B,' + nodeDic[words[4]] + ');'
+ connInfo.append(conn)
+ elif eachline[0] in ['f','h']:
+ vsource = words[3]
+ sourceNodes = sourcesInfo[vsource]
+ sourceNodes = sourceNodes.split()
+ conn = 'connect(' + words[0] + '.p1,'+ nodeDic[sourceNodes[0]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.n1,'+ nodeDic[sourceNodes[1]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.p2,'+ nodeDic[words[1]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.n2,'+ nodeDic[words[2]] + ');'
+ connInfo.append(conn)
+ elif eachline[0] in ['g','e']:
+ conn = 'connect(' + words[0] + '.p1,'+ nodeDic[words[3]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.n1,'+ nodeDic[words[4]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.p2,'+ nodeDic[words[1]] + ');'
+ connInfo.append(conn)
+ conn = 'connect(' + words[0] + '.n2,'+ nodeDic[words[2]] + ');'
+ connInfo.append(conn)
+ elif eachline[0] == 'x':
+ templine = eachline.split()
+ temp = templine[0].split('x')
+ index = temp[1]
+ for i in range(0,len(templine),1):
+ print "Test------------------>"
+ if templine[i] in subcktName: #Ask Manas Added subcktName in function Call
+ subname = templine[i]
+ nodeNumInfo = self.getSubInterface(subname, numNodesSub)
+ for i in range(0, numNodesSub[subname], 1):
+ #conn = 'connect(' + subname + '_instance' + index + '.' + nodeDic[nodeNumInfo[i]] + ',' + nodeDic[words[i+1]] + ');'
+ conn = 'connect(' + subname + '_instance' + index + '.' + 'n'+ nodeNumInfo[i] + ',' + nodeDic[words[i+1]] + ');'
+ connInfo.append(conn)
+ else:
+ continue
+ if '0' in node:
+ conn = 'connect(g.p,n0);'
+ connInfo.append(conn)
+
+ return connInfo
+
+
+ def procesSubckt(self,subcktName,numNodesSub):
+
+ #Process the subcircuit file .sub in the project folder
+
+ #subcktDic = {}
+ subOptionInfo = []
+ subSchemInfo = []
+ subModel = []
+ subModelInfo = {}
+ subsubName = []
+ subParamInfo = []
+ subinbuiltmodelName = []
+ subinbuiltmodelInfo = {}
+ nodeSubInterface = []
+ nodeSub = []
+ nodeDicSub = {}
+ pinInitsub = []
+ connSubInfo = []
+ print "subcktName------------------>",subcktName
+ if len(subcktName) > 0:
+ for eachsub in subcktName:
+ filename = eachsub + '.sub'
+ data = self.readNetlist(filename)
+ print "Data-------------------->",data
+ subOptionInfo, subSchemInfo = self.separateNetlistInfo(data)
+ print "SubOptionInfo------------------->",subOptionInfo
+ print "SubSchemInfo-------------------->",subSchemInfo
+ if len(subOptionInfo) > 0:
+ newline = subOptionInfo[0]
+ subInitLine = newline
+ newline = newline.split('.subckt')
+ intLine = newline[1].split()
+ for i in range(0,len(intLine),1):
+ nodeSubInterface.append(intLine[i])
+
+ subModel, subModelInfo, subsubName, subParamInfo,subinbuiltmodelName, subinbuiltmodelInfo = self.addModel(subOptionInfo)
+ print "Sub Model------------------------------------>",subModel
+ print "SubModelInfo---------------------------------->",subModelInfo
+ print "subsubName------------------------------------->",subsubName
+ print "subParamInfo----------------------------------->",subParamInfo
+ IfMOSsub = '0'
+ for eachline in subSchemInfo:
+ #words = eachline.split()
+ if eachline[0] == 'm':
+ IfMOSsub = '1'
+ break
+ subsubOptionInfo = []
+ subsubSchemInfo = []
+ if len(subsubName) > 0:
+ #subsubOptionInfo = []
+ #subsubSchemInfo = []
+ for eachsub in subsubName:
+ filename_stemp = eachsub + '.sub'
+ data = self.readNetlist(filename_stemp)
+ subsubOptionInfo, subsubSchemInfo = self.separateNetlistInfo(data)
+ for eachline in subsubSchemInfo:
+ #words = eachline.split()
+ if eachline[0] == 'm':
+ IfMOSsub = '1'
+ break
+ print "subsubOptionInfo-------------------------->",subsubOptionInfo
+ print "subsubSchemInfo-------------------------->",subsubSchemInfo
+
+ modelicaSubParam = self.processParam(subParamInfo)
+ print "modelicaSubParam------------------->",modelicaSubParam
+ nodeSub, nodeDicSub, pinInitSub, pinProtectedInitSub = self.nodeSeparate(subSchemInfo, '1', eachsub, subsubName,numNodesSub)
+ print "NodeSub------------------------->",nodeSub
+ print "NodeDicSub-------------------------->",nodeDicSub
+ print "PinInitSub-------------------------->",pinInitSub
+ print "PinProtectedInitSub------------------->",pinProtectedInitSub
+ modelicaSubCompInit, numNodesSubsub = self.compInit(subSchemInfo, nodeSub, subModelInfo, subsubName)
+ print "modelicaSubCompInit--------------------->",modelicaSubCompInit
+ print "numNodesSubsub-------------------------->",numNodesSubsub
+ modelicaSubParamNew = self.getSubParamLine(eachsub, numNodesSub, modelicaSubParam) ###Ask Manas
+ print "modelicaSubParamNew----------------->",modelicaSubParamNew
+ connSubInfo = self.connectInfo(subSchemInfo, nodeSub, nodeDicSub, numNodesSubsub,subcktName)
+ newname = filename.split('.')
+ newfilename = newname[0]
+ outfilename = newfilename+ ".mo"
+ out = open(outfilename,"w")
+ out.writelines('model ' + os.path.basename(newfilename))
+ out.writelines('\n')
+ if IfMOSsub == '0':
+ out.writelines('import Modelica.Electrical.*;')
+ elif IfMOSsub == '1':
+ out.writelines('import BondLib.Electrical.*;')
+ out.writelines('\n')
+ for eachline in modelicaSubParamNew:
+ if len(subParamInfo) == 0:
+ continue
+ else:
+ out.writelines(eachline)
+ out.writelines('\n')
+ for eachline in modelicaSubCompInit:
+ if len(subSchemInfo) == 0:
+ continue
+ else:
+ out.writelines(eachline)
+ out.writelines('\n')
+
+ out.writelines(pinProtectedInitSub)
+ out.writelines('\n')
+ if pinInitSub != 'Modelica.Electrical.Analog.Interfaces.Pin ;':
+ out.writelines('protected')
+ out.writelines('\n')
+ out.writelines(pinInitSub)
+ out.writelines('\n')
+ out.writelines('equation')
+ out.writelines('\n')
+ for eachline in connSubInfo:
+ if len(connSubInfo) == 0:
+ continue
+ else:
+ out.writelines(eachline)
+ out.writelines('\n')
+ out.writelines('end '+ os.path.basename(newfilename) + ';')
+ out.writelines('\n')
+ out.close()
+
+ return data, subOptionInfo, subSchemInfo, subModel, subModelInfo, subsubName, \
+ subParamInfo, modelicaSubCompInit, modelicaSubParam, nodeSubInterface, nodeSub, nodeDicSub, pinInitSub, connSubInfo
+
+
+
+def main(args):
+ """
+ It is main function of module Ngspice to Modelica converter
+ """
+ if len(sys.argv) == 2:
+ filename = sys.argv[1]
+ else:
+ print "USAGE:"
+ print "python NgspicetoModelica.py <filename>"
+ sys.exit()
+
+ obj_NgMoConverter = NgMoConverter()
+
+ #Getting all the require information
+ lines = obj_NgMoConverter.readNetlist(filename)
+ #print "Complete Lines of Ngspice netlist :lines ---------------->",lines
+ optionInfo, schematicInfo=obj_NgMoConverter.separateNetlistInfo(lines)
+ #print "All option details like analysis,subckt,.ic,.model : OptionInfo------------------->",optionInfo
+ #print "Schematic connection info :schematicInfo",schematicInfo
+ modelName, modelInfo, subcktName, paramInfo, inbuiltmodelName, inbuiltmodelInfo = obj_NgMoConverter.addModel(optionInfo)
+ print "Name of Model : modelName-------------------->",modelName
+ print "Model Information :modelInfo--------------------->",modelInfo
+ print "Subcircuit Name :subcktName------------------------>",subcktName
+ print "Parameter Information :paramInfo---------------------->",paramInfo
+ print "Ngspice inbuiltmodelName :inbuiltmodelName---------------------->",inbuiltmodelName
+ print "Ngspice inbuiltmodelInfo :inbuiltmodelInfo----------------------->",inbuiltmodelInfo
+
+
+ modelicaParamInit = obj_NgMoConverter.processParam(paramInfo)
+ #print "Make modelicaParamInit from paramInfo :processParamInit------------->",modelicaParamInit
+ compInfo, plotInfo = obj_NgMoConverter.separatePlot(schematicInfo)
+ #print "Info like run etc : CompInfo----------------->",compInfo
+ #print "Plot info like plot,print etc :plotInfo",plotInfo
+ IfMOS = '0'
+
+ for eachline in compInfo:
+ words = eachline.split()
+ if eachline[0] == 'm':
+ IfMOS = '1'
+ break
+ subOptionInfo = []
+ subSchemInfo = []
+ if len(subcktName) > 0:
+ #subOptionInfo = []
+ #subSchemInfo = []
+ for eachsub in subcktName:
+ filename_temp = eachsub + '.sub'
+ data = obj_NgMoConverter.readNetlist(filename_temp)
+ subOptionInfo, subSchemInfo = obj_NgMoConverter.separateNetlistInfo(data)
+ for eachline in subSchemInfo:
+ words = eachline.split()
+ if eachline[0] == 'm':
+ IfMOS = '1'
+ break
+ #print "Subcircuit OptionInfo : subOptionInfo------------------->",subOptionInfo
+ #print "Subcircuit Schematic Info :subSchemInfo-------------------->",subSchemInfo
+
+ node, nodeDic, pinInit, pinProtectedInit = obj_NgMoConverter.nodeSeparate(compInfo, '0', [], subcktName,[])
+ print "All nodes in the netlist :node---------------->",node
+ print "NodeDic which will be used for modelica : nodeDic------------->",nodeDic
+ print "PinInit-------------->",pinInit
+ print "pinProtectedInit----------->",pinProtectedInit
+
+ modelicaCompInit, numNodesSub = obj_NgMoConverter.compInit(compInfo,node, modelInfo, subcktName)
+ print "ModelicaComponents : modelicaCompInit----------->",modelicaCompInit
+ print "SubcktNumNodes : numNodesSub---------------->",numNodesSub
+
+ connInfo = obj_NgMoConverter.connectInfo(compInfo, node, nodeDic, numNodesSub,subcktName)
+
+ print "ConnInfo------------------>",connInfo
+
+
+ ###After Sub Ckt Func
+ if len(subcktName) > 0:
+ data, subOptionInfo, subSchemInfo, subModel, subModelInfo, subsubName,subParamInfo, modelicaSubCompInit, modelicaSubParam,\
+ nodeSubInterface,nodeSub, nodeDicSub, pinInitSub, connSubInfo = obj_NgMoConverter.procesSubckt(subcktName,numNodesSub) #Adding 'numNodesSub' by Fahim
+
+ #Creating Final Output file
+ newfile = filename.split('.')
+ newfilename = newfile[0]
+ outfile = newfilename + ".mo"
+ out = open(outfile,"w")
+ out.writelines('model ' + os.path.basename(newfilename))
+ out.writelines('\n')
+ if IfMOS == '0':
+ out.writelines('import Modelica.Electrical.*;')
+ elif IfMOS == '1':
+ out.writelines('import BondLib.Electrical.*;')
+ #out.writelines('import Modelica.Electrical.*;')
+ out.writelines('\n')
+
+ for eachline in modelicaParamInit:
+ if len(paramInfo) == 0:
+ continue
+ else:
+ out.writelines(eachline)
+ out.writelines('\n')
+ for eachline in modelicaCompInit:
+ if len(compInfo) == 0:
+ continue
+ else:
+ out.writelines(eachline)
+ out.writelines('\n')
+
+ out.writelines('protected')
+ out.writelines('\n')
+ out.writelines(pinInit)
+ out.writelines('\n')
+ out.writelines('equation')
+ out.writelines('\n')
+
+ for eachline in connInfo:
+ if len(connInfo) == 0:
+ continue
+ else:
+ out.writelines(eachline)
+ out.writelines('\n')
+
+ out.writelines('end '+ os.path.basename(newfilename) + ';')
+ out.writelines('\n')
+
+
+ out.close()
+
+
+# Call main function
+if __name__ == '__main__':
+ main(sys.argv) \ No newline at end of file
diff --git a/src/ngspicetoModelica/__init__.py b/src/ngspicetoModelica/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/ngspicetoModelica/__init__.py
diff --git a/src/projManagement/Kicad.py b/src/projManagement/Kicad.py
index c2a0c948..41fb8d79 100644
--- a/src/projManagement/Kicad.py
+++ b/src/projManagement/Kicad.py
@@ -29,7 +29,7 @@ class Kicad:
def __init__(self,dockarea):
self.obj_validation = Validation.Validation()
self.obj_appconfig = Appconfig()
- self.obj_dockarea=dockarea
+ self.obj_dockarea= dockarea
def openSchematic(self):
"""
@@ -60,7 +60,8 @@ class Kicad:
self.msg.setWindowTitle("Error Message")
-
+ '''
+ #Commenting as it is no longer needed as PBC and Layout will open from eeschema
def openFootprint(self):
"""
This function create command to open Footprint editor
@@ -115,6 +116,8 @@ class Kicad:
self.msg.showMessage('Please select the project first. You can either create new project or open existing project')
self.obj_appconfig.print_warning('Please select the project first. You can either create new project or open existing project')
self.msg.setWindowTitle("Error Message")
+
+ '''
def openKicadToNgspice(self):
"""
diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py
index ac0473af..bafcbe08 100644
--- a/src/projManagement/Validation.py
+++ b/src/projManagement/Validation.py
@@ -18,6 +18,7 @@
#===============================================================================
import os
import re
+import distutils.spawn
class Validation:
@@ -110,4 +111,23 @@ class Validation:
else:
return "True"
else:
- return "DIREC" \ No newline at end of file
+ return "DIREC"
+
+ def validateCirOut(self,projDir):
+ """
+ This function checks if ".cir.out" file is present.
+ """
+ projName = os.path.basename(str(projDir))
+ lookCirOut = os.path.join(str(projDir),projName+".cir.out")
+ #Check existence of project
+ if os.path.exists(lookCirOut):
+ return True
+ else:
+ return False
+
+ def validateTool(self,toolName):
+ """
+ This function check if tool is present in the system
+ """
+ return distutils.spawn.find_executable(toolName) is not None
+ \ No newline at end of file