summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrahulp132020-02-21 12:39:52 +0530
committerrahulp132020-02-21 12:39:52 +0530
commit567e3b725fcc9d22e27cfd854a573d3e64deaff1 (patch)
treeabd4d995d5891a1196a7ca421b7d7b33cad75552 /src
parent982b49ef618222af80162aa98c07ab281dec1692 (diff)
downloadeSim-567e3b725fcc9d22e27cfd854a573d3e64deaff1.tar.gz
eSim-567e3b725fcc9d22e27cfd854a573d3e64deaff1.tar.bz2
eSim-567e3b725fcc9d22e27cfd854a573d3e64deaff1.zip
restructured code - pyinstaller
Diffstat (limited to 'src')
-rw-r--r--src/browser/UserManual.py4
-rw-r--r--src/browser/Welcome.py4
-rw-r--r--src/configuration/Appconfig.py8
-rw-r--r--src/frontEnd/Application.py73
-rw-r--r--src/frontEnd/ProjectExplorer.py10
-rw-r--r--src/frontEnd/Workspace.py11
-rw-r--r--src/kicadtoNgspice/DeviceModel.py5
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py4
-rw-r--r--src/kicadtoNgspice/Processing.py2
-rw-r--r--src/kicadtoNgspice/SubcircuitTab.py6
-rw-r--r--src/modelEditor/ModelEditor.py12
-rw-r--r--src/ngspicetoModelica/ModelicaUI.py201
-rw-r--r--src/ngspicetoModelica/NgspicetoModelica.py189
-rw-r--r--src/subcircuit/newSub.py2
-rw-r--r--src/subcircuit/openSub.py2
-rw-r--r--src/subcircuit/uploadSub.py10
16 files changed, 252 insertions, 291 deletions
diff --git a/src/browser/UserManual.py b/src/browser/UserManual.py
index 6f09190b..f733bb93 100644
--- a/src/browser/UserManual.py
+++ b/src/browser/UserManual.py
@@ -13,9 +13,9 @@ class UserManual(QtGui.QWidget):
self.vlayout = QtGui.QVBoxLayout()
- self.url = "../browser/pages/User-Manual/eSim.html"
+ self.url = "library/browser/User-Manual/eSim.html"
self.test = webbrowser.open(
- "../browser/pages/User-Manual/eSim.html", new=2)
+ "library/browser/User-Manual/eSim.html", new=2)
self.setLayout(self.vlayout)
self.show()
diff --git a/src/browser/Welcome.py b/src/browser/Welcome.py
index 2d91bcc9..69584f10 100644
--- a/src/browser/Welcome.py
+++ b/src/browser/Welcome.py
@@ -12,7 +12,9 @@ class Welcome(QtGui.QWidget):
self.vlayout = QtGui.QVBoxLayout()
self.browser = QtGui.QTextBrowser()
- self.browser.setSource(QtCore.QUrl("../browser/pages/welcome.html"))
+ self.browser.setSource(QtCore.QUrl(
+ "library/browser/welcome.html")
+ )
self.browser.setOpenExternalLinks(True)
self.browser.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
diff --git a/src/configuration/Appconfig.py b/src/configuration/Appconfig.py
index dfe4363f..6a10f3d7 100644
--- a/src/configuration/Appconfig.py
+++ b/src/configuration/Appconfig.py
@@ -36,7 +36,7 @@ class Appconfig(QtGui.QWidget):
# Home directory
try:
file = open(os.path.join(
- os.path.expanduser("~"), ".esim/workspace.txt"), 'r'
+ os.path.expanduser("~"), ".esim/workspace.txt"), 'r'
)
workspace_check, home = file.readline().split(' ', 1)
file.close()
@@ -53,7 +53,7 @@ class Appconfig(QtGui.QWidget):
workspace_text = "eSim stores your project in a folder called "
workspace_text += "eSim-Workspace. You can choose a different "
workspace_text += "workspace folder to use for this session."
-
+
procThread_list = []
proc_dict = {} # hold pids of all external windows of the current project
dock_dict = {} # holds all dockwidgets
@@ -61,7 +61,7 @@ class Appconfig(QtGui.QWidget):
default_workspace["workspace"], ".projectExplorer.txt")
}
- noteArea = {"Note" : []}
+ noteArea = {"Note": []}
parser_esim = SafeConfigParser()
parser_esim.read(
@@ -80,7 +80,7 @@ class Appconfig(QtGui.QWidget):
# Open file and read KiCad config path
try:
- file = open('../supportFiles/kicad_config_path.txt', 'r')
+ file = open('library/supportFiles/kicad_config_path.txt', 'r')
kicad_path = file.read().rstrip()
file.close()
except BaseException as e:
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py
index 1b8a18c5..3ecf9941 100644
--- a/src/frontEnd/Application.py
+++ b/src/frontEnd/Application.py
@@ -16,7 +16,7 @@
# REVISION: Friday 14 February 2020
# =========================================================================
-import pathmagic # noqa
+from frontEnd import pathmagic # noqa
from PyQt4 import QtGui, QtCore
from configuration.Appconfig import Appconfig
from projManagement.openProject import OpenProjectInfo
@@ -64,10 +64,10 @@ class Application(QtGui.QMainWindow):
self.obj_appconfig._app_heigth)
self.setWindowTitle(self.obj_appconfig._APPLICATION)
self.showMaximized()
- self.setWindowIcon(QtGui.QIcon('../../images/logo.png'))
+ self.setWindowIcon(QtGui.QIcon('images/logo.png'))
self.systemTrayIcon = QtGui.QSystemTrayIcon(self)
- self.systemTrayIcon.setIcon(QtGui.QIcon('../../images/logo.png'))
+ self.systemTrayIcon.setIcon(QtGui.QIcon('images/logo.png'))
self.systemTrayIcon.setVisible(True)
def initToolBar(self):
@@ -83,28 +83,28 @@ class Application(QtGui.QMainWindow):
"""
# Top Tool bar
self.newproj = QtGui.QAction(
- QtGui.QIcon('../../images/newProject.png'),
+ QtGui.QIcon('images/newProject.png'),
'<b>New Project</b>', self
)
self.newproj.setShortcut('Ctrl+N')
self.newproj.triggered.connect(self.new_project)
self.openproj = QtGui.QAction(
- QtGui.QIcon('../../images/openProject.png'),
+ QtGui.QIcon('images/openProject.png'),
'<b>Open Project</b>', self
)
self.openproj.setShortcut('Ctrl+O')
self.openproj.triggered.connect(self.open_project)
self.closeproj = QtGui.QAction(
- QtGui.QIcon('../../images/closeProject.png'),
+ QtGui.QIcon('images/closeProject.png'),
'<b>Close Project</b>', self
)
self.closeproj.setShortcut('Ctrl+X')
self.closeproj.triggered.connect(self.close_project)
self.wrkspce = QtGui.QAction(
- QtGui.QIcon('../../images/workspace.ico'),
+ QtGui.QIcon('images/workspace.ico'),
'<b>Change Workspace</b>', self
)
self.wrkspce.setShortcut('Ctrl+W')
@@ -112,19 +112,19 @@ class Application(QtGui.QMainWindow):
self.switchmode = None
self.validate_mode()
- if self.online_flag == True:
+ if self.online_flag is True:
self.switchmode = QtGui.QAction(QtGui.QIcon(
- '../../images/online.png'),
+ 'images/online.png'),
'<b>Go Offline</b>', self
)
- elif self.online_flag == False:
+ elif self.online_flag is False:
self.switchmode = QtGui.QAction(QtGui.QIcon(
- '../../images/offline.png'),
+ 'images/offline.png'),
'<b>Go Online</b>', self
)
elif self.online_flag is None:
self.switchmode = QtGui.QAction(QtGui.QIcon(
- '../../images/disable.png'),
+ 'images/disable.png'),
'<b>Mode switching has been disabled. ' +
'Default mode set to offline</b>', self
)
@@ -133,7 +133,7 @@ class Application(QtGui.QMainWindow):
self.switchmode.triggered.connect(self.change_mode)
self.helpfile = QtGui.QAction(
- QtGui.QIcon('../../images/helpProject.png'), '<b>Help</b>', self
+ QtGui.QIcon('images/helpProject.png'), '<b>Help</b>', self
)
self.helpfile.setShortcut('Ctrl+H')
self.helpfile.triggered.connect(self.help_project)
@@ -156,7 +156,7 @@ class Application(QtGui.QMainWindow):
self.logo = QtGui.QLabel()
self.logopic = QtGui.QPixmap(
os.path.join(
- os.path.abspath('../..'), 'images', 'fosseeLogo.png'
+ os.path.abspath(''), 'images', 'fosseeLogo.png'
))
self.logopic = self.logopic.scaled(
QSize(150, 150), QtCore.Qt.KeepAspectRatio)
@@ -166,48 +166,45 @@ class Application(QtGui.QMainWindow):
# Left Tool bar Action Widget
self.kicad = QtGui.QAction(
- QtGui.QIcon('../../images/kicad.png'),
+ 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'),
+ 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
+ QtGui.QIcon('images/ngspice.png'), '<b>Simulation</b>', self
)
self.ngspice.triggered.connect(self.open_ngspice)
self.model = QtGui.QAction(
- QtGui.QIcon('../../images/model.png'),
- '<b>Model Editor</b>', self
+ 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
+ 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
+ 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'),
+ 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
+ QtGui.QIcon('images/omoptim.png'), '<b>OM Optimisation</b>', self
)
self.omoptim.triggered.connect(self.open_OMoptim)
@@ -353,7 +350,7 @@ class Application(QtGui.QMainWindow):
"""
This functions checks whether proper fp-lib-table* files are \
available or not. If not, then move appropriate files from \
- supportFiles folder and set `self.online_flag` accordingly.
+ library/supportFiles folder and set `self.online_flag` accordingly.
@params
@@ -385,7 +382,7 @@ class Application(QtGui.QMainWindow):
"/fp-lib-table")
else:
self.online_flag = False
-
+
if remove:
# Remove invalid files
if os.path.exists(
@@ -401,9 +398,9 @@ class Application(QtGui.QMainWindow):
"/fp-lib-table-online")
# Restore original files
- shutil.copy('../supportFiles/fp-lib-table-online',
+ shutil.copy('library/supportFiles/fp-lib-table-online',
self.obj_appconfig.kicad_path + "/")
- shutil.copy('../supportFiles/fp-lib-table',
+ shutil.copy('library/supportFiles/fp-lib-table',
self.obj_appconfig.kicad_path + "/")
self.online_flag = False
@@ -445,7 +442,7 @@ class Application(QtGui.QMainWindow):
self.obj_appconfig.kicad_path + "/fp-lib-table"
)
self.switchmode.setIcon(
- QtGui.QIcon('../../images/offline.png')
+ QtGui.QIcon('images/offline.png')
)
self.switchmode.setText('<b>Go Online</b>')
self.switchmode.setEnabled(True)
@@ -463,7 +460,7 @@ class Application(QtGui.QMainWindow):
self.obj_appconfig.kicad_path + "/fp-lib-table"
)
self.switchmode.setIcon(
- QtGui.QIcon('../../images/online.png')
+ QtGui.QIcon('images/online.png')
)
self.switchmode.setText('<b>Go Offline</b>')
self.switchmode.setEnabled(True)
@@ -471,10 +468,12 @@ class Application(QtGui.QMainWindow):
elif self.online_flag is None:
self.switchmode.setIcon(
- QtGui.QIcon('../../images/disable.png')
+ QtGui.QIcon('images/disable.png')
+ )
+ self.switchmode.setText(
+ '<b>Mode switching has been ' +
+ 'disabled. Default mode set to offline</b>.'
)
- self.switchmode.setText('<b>Mode switching has been ' +
- 'disabled. Default mode set to offline</b>.')
self.switchmode.setEnabled(False)
else:
self.msg = QtGui.QErrorMessage()
@@ -799,7 +798,7 @@ def main(args):
print("Starting eSim......")
app = QtGui.QApplication(args)
- splash_pix = QtGui.QPixmap('../../images/splash_screen_esim.png')
+ splash_pix = QtGui.QPixmap('images/splash_screen_esim.png')
splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint)
splash.setMask(splash_pix.mask())
splash.show()
@@ -809,13 +808,13 @@ def main(args):
try:
file = open(os.path.join(
- os.path.expanduser("~"),".esim/workspace.txt"), 'r'
+ os.path.expanduser("~"), ".esim/workspace.txt"), 'r'
)
work = int(file.read(1))
file.close()
except IOError:
work = 0
- if work is not 0:
+ if work != 0:
appView.obj_workspace.defaultWorkspace()
else:
appView.hide()
diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py
index 4462c584..c733c9b1 100644
--- a/src/frontEnd/ProjectExplorer.py
+++ b/src/frontEnd/ProjectExplorer.py
@@ -38,19 +38,19 @@ class ProjectExplorer(QtGui.QWidget):
QTreeView { border-radius: 15px; border: 1px \
solid gray; padding: 5px; width: 200px; height: 150px; }\
QTreeView::branch:has-siblings:!adjoins-item { \
- border-image: url(../../images/vline.png) 0;} \
+ border-image: url(images/vline.png) 0;} \
QTreeView::branch:has-siblings:adjoins-item { \
- border-image: url(../../images/branch-more.png) 0; } \
+ border-image: url(images/branch-more.png) 0; } \
QTreeView::branch:!has-children:!has-siblings:adjoins-item { \
- border-image: url(../../images/branch-end.png) 0; } \
+ border-image: url(images/branch-end.png) 0; } \
QTreeView::branch:has-children:!has-siblings:closed, \
QTreeView::branch:closed:has-children:has-siblings { \
border-image: none; \
- image: url(../../images/branch-closed.png); } \
+ image: url(images/branch-closed.png); } \
QTreeView::branch:open:has-children:!has-siblings, \
QTreeView::branch:open:has-children:has-siblings { \
border-image: none; \
- image: url(../../images/branch-open.png); } \
+ image: url(images/branch-open.png); } \
")
for parents, children in list(
diff --git a/src/frontEnd/Workspace.py b/src/frontEnd/Workspace.py
index 09092a69..6940da59 100644
--- a/src/frontEnd/Workspace.py
+++ b/src/frontEnd/Workspace.py
@@ -64,7 +64,7 @@ class Workspace(QtGui.QWidget):
self.cancelbtn = QtGui.QPushButton('Cancel')
self.cancelbtn.clicked.connect(self.defaultWorkspace)
- #Checkbox
+ # Checkbox
self.chkbox = QtGui.QCheckBox('Set Default', self)
self.chkbox.setCheckState(int(self.obj_appconfig.workspace_check))
@@ -82,7 +82,7 @@ class Workspace(QtGui.QWidget):
self.setWindowTitle("eSim")
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
self.note.setReadOnly(True)
- self.setWindowIcon(QtGui.QIcon('../../images/logo.png'))
+ self.setWindowIcon(QtGui.QIcon('images/logo.png'))
self.setLayout(self.grid)
def defaultWorkspace(self):
@@ -121,7 +121,8 @@ class Workspace(QtGui.QWidget):
file = open(os.path.join(
os.path.expanduser("~"), ".esim/workspace.txt"), 'w'
)
- file.writelines(str(self.obj_appconfig.workspace_check) +
+ file.writelines(
+ str(self.obj_appconfig.workspace_check) +
" " + self.workspace_loc.text()
)
file.close()
@@ -148,10 +149,10 @@ class Workspace(QtGui.QWidget):
self.obj_appconfig.project_explorer = json.load(
open(self.obj_appconfig.dictPath["path"])
)
- except:
+ except BaseException:
self.obj_appconfig.project_explorer = {}
- Appconfig.project_explorer = self.obj_appconfig.project_explorer
+ Appconfig.project_explorer = self.obj_appconfig.project_explorer
var_appView.obj_Mainview.obj_projectExplorer.treewidget.clear()
for parent, children in self.obj_appconfig.project_explorer.items():
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py
index 41faa6f0..65e09753 100644
--- a/src/kicadtoNgspice/DeviceModel.py
+++ b/src/kicadtoNgspice/DeviceModel.py
@@ -363,9 +363,8 @@ class DeviceModel(QtGui.QWidget):
self.libfile = str(
QtGui.QFileDialog.getOpenFileName(
- self,
- "Open Library Directory",
- "../deviceModelLibrary",
+ self, "Open Library Directory",
+ "library/deviceModelLibrary",
"*.lib"))
# Setting Library to Text Edit Line
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index cfc4f671..18701c43 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -114,7 +114,7 @@ class MainWindow(QtGui.QWidget):
"""
- Checking if any unknown model is used in schematic which is not
- recognized by NgSpice.
+ recognized by Ngspice.
- Also if the two model of same name is present under
modelParamXML directory
"""
@@ -233,7 +233,7 @@ class MainWindow(QtGui.QWidget):
- This function called when convert button clicked
- Extracting data from the objs created above
- Pushing this data to json, and dumping it finally
- - Written to a ..._Previous_Valuse.json file in the projDirectory
+ - Written to a ..._Previous_Values.json file in the projDirectory
- Finally, call createNetListFile, with the converted schematic
"""
global schematicInfo
diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py
index 427f0823..67ffd3f5 100644
--- a/src/kicadtoNgspice/Processing.py
+++ b/src/kicadtoNgspice/Processing.py
@@ -8,7 +8,7 @@ class PrcocessNetlist:
- This class include all the function required for pre-proccessing of
netlist before converting to Ngspice Netlist.
"""
- modelxmlDIR = '../modelParamXML'
+ modelxmlDIR = 'library/modelParamXML'
def __init__(self):
pass
diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py
index 08ad7332..35b876f0 100644
--- a/src/kicadtoNgspice/SubcircuitTab.py
+++ b/src/kicadtoNgspice/SubcircuitTab.py
@@ -141,9 +141,9 @@ class SubcircuitTab(QtGui.QWidget):
self.subfile = str(
QtGui.QFileDialog.getExistingDirectory(
- self,
- "Open Subcircuit",
- "../SubcircuitLibrary"))
+ self, "Open Subcircuit",
+ "library/SubcircuitLibrary")
+ )
self.reply = self.obj_validation.validateSub(
self.subfile, self.numPorts[self.widgetObjCount - 1])
if self.reply == "True":
diff --git a/src/modelEditor/ModelEditor.py b/src/modelEditor/ModelEditor.py
index 7db35251..c5bd310a 100644
--- a/src/modelEditor/ModelEditor.py
+++ b/src/modelEditor/ModelEditor.py
@@ -10,7 +10,7 @@ class ModelEditorclass(QtGui.QWidget):
- Initialise the layout for dockarea
- Use QVBoxLayout, QSplitter, QGridLayout to define the layout
- Initalise directory to save new models,
- savepathtest = '../deviceModelLibrary'
+ savepathtest = 'library/deviceModelLibrary'
- Initialise buttons and options ====>
- Name Function Called
========================================
@@ -30,7 +30,7 @@ class ModelEditorclass(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
- self.savepathtest = '../deviceModelLibrary'
+ self.savepathtest = 'library/deviceModelLibrary'
self.obj_appconfig = Appconfig()
self.newflag = 0
self.layout = QtGui.QVBoxLayout()
@@ -252,7 +252,7 @@ class ModelEditorclass(QtGui.QWidget):
- Accordingly call `createtable(path)` to draw tables usingg QTable
- Check for the state of button before rendering
'''
- self.path = '../deviceModelLibrary/Templates'
+ self.path = 'library/deviceModelLibrary/Templates'
if self.diode.isChecked():
if filetype == 'Diode':
path = os.path.join(self.path, 'D.xml')
@@ -327,7 +327,7 @@ class ModelEditorclass(QtGui.QWidget):
QtGui.QFileDialog.getOpenFileName(
self,
"Open Library Directory",
- "../deviceModelLibrary",
+ "library/deviceModelLibrary",
"*.lib"))
self.createtable(self.editfile)
except BaseException:
@@ -473,7 +473,7 @@ class ModelEditorclass(QtGui.QWidget):
ET.SubElement(param, tags).text = text
tree = ET.ElementTree(root)
defaultcwd = os.getcwd()
- self.savepath = '../deviceModelLibrary'
+ self.savepath = 'library/deviceModelLibrary'
if self.diode.isChecked():
savepath = os.path.join(self.savepath, 'Diode')
os.chdir(savepath)
@@ -687,7 +687,7 @@ class ModelEditorclass(QtGui.QWidget):
QtGui.QFileDialog.getOpenFileName(
self,
"Open Library Directory",
- "../deviceModelLibrary",
+ "library/deviceModelLibrary",
"*.lib"))
libopen = open(self.libfile)
filedata = libopen.read().split()
diff --git a/src/ngspicetoModelica/ModelicaUI.py b/src/ngspicetoModelica/ModelicaUI.py
index 168b5c14..aa7cb330 100644
--- a/src/ngspicetoModelica/ModelicaUI.py
+++ b/src/ngspicetoModelica/ModelicaUI.py
@@ -1,9 +1,9 @@
import os
-from subprocess import Popen, PIPE, STDOUT
from PyQt4 import QtGui, QtCore
from configuration.Appconfig import Appconfig
from projManagement import Worker
from projManagement.Validation import Validation
+from .NgspicetoModelica import NgMoConverter
BROWSE_LOCATION = '/home'
@@ -49,45 +49,172 @@ class OpenModelicaEditor(QtGui.QWidget):
self.FileEdit.setText(self.ngspiceNetlist)
def callConverter(self):
+
+ dir_name = os.path.dirname(os.path.realpath(self.ngspiceNetlist))
+ # file_basename = os.path.basename(self.ngspiceNetlist)
+
+ cwd = os.getcwd()
+ os.chdir(dir_name)
+
+ obj_NgMoConverter = NgMoConverter(self.map_json)
+
try:
- self.cmd1 = (
- "python3 ../ngspicetoModelica/NgspicetoModelica.py " +
- self.ngspiceNetlist + ' ' +
- self.map_json
- )
- # self.obj_workThread1 = Worker.WorkerThread(self.cmd1)
- # self.obj_workThread1.start()
- convert_process = Popen(
- self.cmd1,
- shell=True,
- stdin=PIPE,
- stdout=PIPE,
- stderr=STDOUT,
- close_fds=True)
- error_code = convert_process.stdout.read()
-
- if not error_code:
- self.msg = QtGui.QMessageBox()
- self.msg.setText(
- "Ngspice netlist successfully converted to OpenModelica" +
- "netlist"
+ # Getting all the require information
+ lines = obj_NgMoConverter.readNetlist(self.ngspiceNetlist)
+ # 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, transInfo,\
+ inbuiltModelDict = (
+ obj_NgMoConverter.addModel(optionInfo)
)
- self.obj_appconfig.print_info(
- "Ngspice netlist successfully converted to OpenModelica" +
- "netlist"
+ # print("Name of Model : " +
+ # "modelName-------------------->", modelName)
+ # print("Model Information : " +
+ # "modelInfo--------------------->", modelInfo)
+ # print("Subcircuit Name : " +
+ # "subcktName------------------------>", subcktName)
+ # print("Parameter Information : " +
+ # "paramInfo---------------------->", paramInfo)
+ # print("InBuilt Model ---------------------->", inbuiltModelDict)
+
+ modelicaParamInit = obj_NgMoConverter.processParam(paramInfo)
+ # print("Make modelicaParamInit from paramInfo : " +
+ # "processParamInit------------->", modelicaParamInit)
+ compInfo, plotInfo = obj_NgMoConverter.separatePlot(schematicInfo)
+ # 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)
+ # print "Data---------->",data
+ 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, []
)
- self.msg.exec_()
- else:
- self.err_msg = QtGui.QErrorMessage()
- self.msg.setModal(True)
- self.msg.setWindowTitle(
- "Ngspice to Modelica conversion error")
- self.err_msg.showMessage(
- 'Unable to convert NgSpice netlist to Modelica netlist.' +
- 'Check the netlist :' +
- error_code)
- self.err_msg.exec_()
- self.obj_appconfig.print_error(error_code)
+ # 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,
+ dir_name,
+ transInfo,
+ inbuiltModelDict
+ )
+ # 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, dir_name
+ )
+ ) # Adding 'numNodesSub' by Fahim
+
+ # Creating Final Output file
+ newfile = self.ngspiceNetlist.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()
+
+ os.chdir(cwd)
+
+ self.msg = QtGui.QMessageBox()
+ self.msg.setText(
+ "Ngspice netlist successfully converted to OpenModelica" +
+ "netlist"
+ )
+ self.obj_appconfig.print_info(
+ "Ngspice netlist successfully converted to OpenModelica" +
+ "netlist"
+ )
+ self.msg.exec_()
except Exception as e:
self.msg = QtGui.QErrorMessage()
diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py
index bdbd6ac2..a78bad1b 100644
--- a/src/ngspicetoModelica/NgspicetoModelica.py
+++ b/src/ngspicetoModelica/NgspicetoModelica.py
@@ -1,8 +1,6 @@
-import sys
import os
import re
import json
-from string import maketrans
class NgMoConverter:
@@ -31,10 +29,9 @@ class NgMoConverter:
except Exception as e:
print("Error in opening file")
print(str(e))
- sys.exit()
+ raise
else:
- print(filename + " does not exist")
- sys.exit()
+ raise FileNotFoundError(filename + " does not exist")
data = f.read()
data = data.splitlines()
@@ -150,10 +147,10 @@ class NgMoConverter:
f = open(filename)
except BaseException:
print("Error in opening file")
- sys.exit()
+ raise
else:
- print(filename + " does not exist")
- sys.exit()
+ raise FileNotFoundError(filename + " does not exist")
+
data = f.read()
data = data.replace(
'+',
@@ -206,7 +203,7 @@ class NgMoConverter:
line = line.split()
final_line = ','.join(line)
stat = 'parameter Real ' + final_line + ';'
- stat = stat.translate(maketrans('{}', ' '))
+ stat = stat.translate(str.maketrans('{}', ' '))
modelicaParam.append(stat)
return modelicaParam
@@ -481,8 +478,7 @@ class NgMoConverter:
["import"]
) + ".PNP"
else:
- print("Transistor " + str(trans) + " Not found")
- sys.exit(1)
+ raise NameError("Transistor " + str(trans) + " Not found")
stat = start + " " + words[0] + "("
tempstatList = []
@@ -576,8 +572,7 @@ class NgMoConverter:
["import"]
) + ".Mp"
else:
- print("MOSFET " + str(trans) + " not found")
- sys.exit(1)
+ raise NameError("MOSFET " + str(trans) + " not found")
stat = start + " " + words[0] + "("
tempstatList = []
@@ -684,8 +679,7 @@ class NgMoConverter:
["import"]
)+".J_PJFJFET"
else:
- print "JFET "+str(trans)+" Not found"
- sys.exit(1)
+ raise NameError("JFET " + str(trans) + " Not found")
"""
start = self.mappingData["Devices"][deviceName]["import"]
@@ -894,7 +888,7 @@ class NgMoConverter:
appen_line = intLine[newindex:len(intLine)]
appen_param = ','.join(appen_line)
paramLine = 'parameter Real ' + appen_param + ';'
- paramLine = paramLine.translate(maketrans('{}', ' '))
+ paramLine = paramLine.translate(str.maketrans('{}', ' '))
subParamInfo.append(paramLine)
return subParamInfo
@@ -1257,166 +1251,3 @@ class NgMoConverter:
pinInitSub,
connSubInfo
)
-
-
-def main(args):
- """
- It is main function of module Ngspice to Modelica converter
- """
- if len(sys.argv) == 3:
- filename = sys.argv[1]
- map_json = sys.argv[2]
- else:
- print("USAGE:")
- print("python3 NgspicetoModelica.py <filename>")
- sys.exit()
-
- dir_name = os.path.dirname(os.path.realpath(filename))
- # file_basename = os.path.basename(filename)
-
- cwd = os.getcwd()
- os.chdir(dir_name)
-
- obj_NgMoConverter = NgMoConverter(map_json)
-
- # 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, transInfo,\
- inbuiltModelDict = (
- 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 "InBuilt Model ---------------------->",inbuiltModelDict
-
- modelicaParamInit = obj_NgMoConverter.processParam(paramInfo)
- # print "Make modelicaParamInit from paramInfo
- # : processParamInit------------->",modelicaParamInit
- compInfo, plotInfo = obj_NgMoConverter.separatePlot(schematicInfo)
- # 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)
- # print "Data---------->",data
- 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,
- dir_name,
- transInfo,
- inbuiltModelDict
- )
- # 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, dir_name
- )
- ) # 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()
-
- os.chdir(cwd)
-
-
-# Call main function
-if __name__ == '__main__':
- main(sys.argv)
diff --git a/src/subcircuit/newSub.py b/src/subcircuit/newSub.py
index f4b3100c..5e98d24a 100644
--- a/src/subcircuit/newSub.py
+++ b/src/subcircuit/newSub.py
@@ -31,7 +31,7 @@ class NewSub(QtGui.QWidget):
# Checking if Workspace already exist or not
self.schematic_path = (
os.path.join(
- os.path.abspath('..'),
+ os.path.abspath('library'),
'SubcircuitLibrary',
self.create_schematic))
diff --git a/src/subcircuit/openSub.py b/src/subcircuit/openSub.py
index dd6e31ac..6cb4fe3e 100644
--- a/src/subcircuit/openSub.py
+++ b/src/subcircuit/openSub.py
@@ -18,7 +18,7 @@ class openSub(QtGui.QWidget):
def body(self):
self.editfile = str(
QtGui.QFileDialog.getExistingDirectory(
- None, "Open File", "../SubcircuitLibrary"))
+ None, "Open File", "library/SubcircuitLibrary"))
if self.editfile:
self.obj_Appconfig = Appconfig()
self.obj_Appconfig.current_subcircuit['SubcircuitName'] \
diff --git a/src/subcircuit/uploadSub.py b/src/subcircuit/uploadSub.py
index 4bb8df34..25a6e7d4 100644
--- a/src/subcircuit/uploadSub.py
+++ b/src/subcircuit/uploadSub.py
@@ -7,9 +7,9 @@ import shutil
class UploadSub(QtGui.QWidget):
"""
- This class contain function for ulaoding subcircuits
- in Subcircuit library present in src folder.
- A folder is created in src/SubcircuitLibrary
+ This class contain function for uploading subcircuits
+ in SubcircuitLibrary present in src folder.
+ A folder is created in library/SubcircuitLibrary
and desired file is moved to that folder.
"""
@@ -64,7 +64,9 @@ class UploadSub(QtGui.QWidget):
return
subcircuit_path = os.path.join(
- os.path.abspath('..'), 'SubcircuitLibrary', create_subcircuit)
+ os.path.abspath('library'),
+ 'SubcircuitLibrary', create_subcircuit
+ )
reply = self.obj_validation.validateNewproj(subcircuit_path)