From bb8a6a6974d2f425d51df1a3042706011ff351ad Mon Sep 17 00:00:00 2001
From: athulappadan
Date: Wed, 25 May 2016 14:17:33 +0530
Subject: DockWidget added in UI for ngspice to modelica conversion
---
src/configuration/Appconfig.py | 5 ++
src/frontEnd/Application.py | 4 ++
src/frontEnd/DockArea.py | 30 +++++++++++
src/ngspicetoModelica/ModelicaUI.py | 86 ++++++++++++++++++++++++++++++
src/ngspicetoModelica/NgspicetoModelica.py | 14 +++--
src/ngspicetoModelica/__init__.py | 0
6 files changed, 135 insertions(+), 4 deletions(-)
create mode 100644 src/ngspicetoModelica/ModelicaUI.py
create mode 100644 src/ngspicetoModelica/__init__.py
(limited to 'src')
diff --git a/src/configuration/Appconfig.py b/src/configuration/Appconfig.py
index 3e4afad6..d9479137 100644
--- a/src/configuration/Appconfig.py
+++ b/src/configuration/Appconfig.py
@@ -20,6 +20,7 @@
from PyQt4 import QtGui
import os
import json
+from ConfigParser import SafeConfigParser
class Appconfig(QtGui.QWidget):
@@ -42,6 +43,10 @@ class Appconfig(QtGui.QWidget):
dock_dict={} #holds all dockwidgets
dictPath = os.path.join(os.path.expanduser("~"), ".projectExplorer.txt")
noteArea = {}
+
+ parser_esim = SafeConfigParser()
+ parser_esim.read(os.path.join(os.path.expanduser("~"), os.path.join('.esim','config.ini')))
+ modelica_map_json = parser_esim.get('eSim', 'MODELICA_MAP_JSON')
try:
project_explorer = json.load(open(dictPath))
except:
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py
index 1008c7b5..2f9bca28 100755
--- a/src/frontEnd/Application.py
+++ b/src/frontEnd/Application.py
@@ -306,6 +306,7 @@ class Application(QtGui.QMainWindow):
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
@@ -335,6 +336,9 @@ class Application(QtGui.QMainWindow):
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))
+ """
+
+ self.obj_Mainview.obj_dockarea.modelicaEditor(self.projDir)
else:
self.msg = QtGui.QErrorMessage()
diff --git a/src/frontEnd/DockArea.py b/src/frontEnd/DockArea.py
index dcb48704..073072bf 100644
--- a/src/frontEnd/DockArea.py
+++ b/src/frontEnd/DockArea.py
@@ -7,6 +7,7 @@ from subcircuit.Subcircuit import Subcircuit
from kicadtoNgspice.KicadtoNgspice import MainWindow
from browser.Welcome import Welcome
from browser.UserManual import UserManual
+from ngspicetoModelica.ModelicaUI import OpenModelicaEditor
import os
dockList = ['Welcome']
@@ -273,6 +274,35 @@ class DockArea(QtGui.QMainWindow):
count = count + 1
+ def modelicaEditor(self, projDir):
+ """
+ This function sets up the UI for ngspice to modelica conversion
+ """
+
+ global count
+ self.modelicaWidget = QtGui.QWidget()
+ self.modelicaLayout = QtGui.QVBoxLayout()
+ self.modelicaLayout.addWidget(OpenModelicaEditor(projDir))
+
+ self.modelicaWidget.setLayout(self.modelicaLayout)
+ dock['Modelica-'+str(count)] = QtGui.QDockWidget('Modelica-'+str(count))
+ dock['Modelica-'+str(count)].setWidget(self.modelicaWidget)
+ self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock['Modelica-'+str(count)])
+ self.tabifyDockWidget(dock['Welcome'],dock['Modelica-'+str(count)])
+
+ dock['Modelica-'+str(count)].setVisible(True)
+ dock['Modelica-'+str(count)].setFocus()
+ dock['Modelica-'+str(count)].raise_()
+
+ #CSS
+ dock['Modelica-'+str(count)].setStyleSheet(" \
+ .QWidget { border-radius: 15px; border: 1px solid gray; padding: 5px; width: 200px; height: 150px; } \
+ ")
+
+ self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']].append(dock['Modelica-'+str(count)])
+
+ count = count + 1
+
def closeDock (self):
for dockwidget in self.obj_appconfig.dock_dict[self.obj_appconfig.current_project['ProjectName']]:
dockwidget.close()
diff --git a/src/ngspicetoModelica/ModelicaUI.py b/src/ngspicetoModelica/ModelicaUI.py
new file mode 100644
index 00000000..e443810d
--- /dev/null
+++ b/src/ngspicetoModelica/ModelicaUI.py
@@ -0,0 +1,86 @@
+import os
+import sys
+from PyQt4 import QtGui, QtCore
+from configuration.Appconfig import Appconfig
+from projManagement import Worker
+from projManagement.Validation import Validation
+
+BROWSE_LOCATION = '/home'
+
+class OpenModelicaEditor(QtGui.QWidget):
+
+ def __init__(self, dir=None):
+ QtGui.QWidget.__init__(self)
+ self.obj_validation = Validation()
+ self.obj_appconfig = Appconfig()
+ self.projDir = dir
+ 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")
+ self.map_json = Appconfig.modelica_map_json
+
+ self.grid = QtGui.QGridLayout()
+ self.FileEdit = QtGui.QLineEdit()
+ self.FileEdit.setText(self.ngspiceNetlist)
+ self.grid.addWidget(self.FileEdit, 0, 0)
+
+ self.browsebtn = QtGui.QPushButton("Browse")
+ self.browsebtn.clicked.connect(self.browseFile)
+ self.grid.addWidget(self.browsebtn, 0, 1)
+
+ self.convertbtn = QtGui.QPushButton("Convert")
+ self.convertbtn.clicked.connect(self.callConverter)
+ self.grid.addWidget(self.convertbtn, 2, 1)
+
+ self.loadOMbtn = QtGui.QPushButton("Load OMEdit")
+ self.loadOMbtn.clicked.connect(self.callOMEdit)
+ self.grid.addWidget(self.loadOMbtn, 3, 1)
+
+ #self.setGeometry(300, 300, 350, 300)
+ self.setLayout(self.grid)
+ self.show()
+
+ def browseFile(self):
+
+ self.ngspiceNetlist = QtGui.QFileDialog.getOpenFileName(self, 'Open Ngspice file', BROWSE_LOCATION)
+ self.FileEdit.setText(self.ngspiceNetlist)
+
+ def callConverter(self):
+
+ try:
+ self.cmd1 = "python ../ngspicetoModelica/NgspicetoModelica.py " + self.ngspiceNetlist + ' ' + self.map_json
+ self.obj_workThread1 = Worker.WorkerThread(self.cmd1)
+ self.obj_workThread1.start()
+ 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")
+ if self.obj_workThread1.finished:
+ self.msg.exec_()
+
+ except Exception as e:
+ self.msg = QtGui.QErrorMessage()
+ self.msg.showMessage('Unable to convert NgSpice netlist to Modelica netlist. Check the netlist :'+str(e))
+ self.msg.setWindowTitle("Ngspice to Modelica conversion error")
+
+
+ def callOMEdit(self):
+
+ if self.obj_validation.validateTool("OMEdit"):
+ self.cmd2 = "OMEdit " + self.modelicaNetlist
+ self.obj_workThread2 = Worker.WorkerThread(self.cmd2)
+ self.obj_workThread2.start()
+ print "OMEdit called"
+ self.obj_appconfig.print_info("OMEdit called")
+
+ else:
+ self.msg = QtGui.QMessageBox()
+ self.msgContent = "There was an error while opening OMEdit.
\
+ Please make sure OpenModelica is installed in your system.
\
+ To install it on Linux : Go to OpenModelica Linux and install nigthly build release.
\
+ To install it on Windows : Go to OpenModelica Windows and install latest version.
"
+ 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_()
+
diff --git a/src/ngspicetoModelica/NgspicetoModelica.py b/src/ngspicetoModelica/NgspicetoModelica.py
index e9855e03..7b7e4527 100644
--- a/src/ngspicetoModelica/NgspicetoModelica.py
+++ b/src/ngspicetoModelica/NgspicetoModelica.py
@@ -7,9 +7,9 @@ from string import maketrans
class NgMoConverter:
- def __init__(self):
+ def __init__(self, map_json):
#Loading JSON file which hold the mapping information between ngspice and Modelica.
- with open('Mapping.json') as mappingFile:
+ with open(map_json) as mappingFile:
self.mappingData = json.load(mappingFile)
self.ifMOS = False
@@ -987,8 +987,9 @@ def main(args):
"""
It is main function of module Ngspice to Modelica converter
"""
- if len(sys.argv) == 2:
+ if len(sys.argv) == 3:
filename = sys.argv[1]
+ map_json = sys.argv[2]
else:
print "USAGE:"
print "python NgspicetoModelica.py "
@@ -996,8 +997,11 @@ def main(args):
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()
+ obj_NgMoConverter = NgMoConverter(map_json)
#Getting all the require information
lines = obj_NgMoConverter.readNetlist(filename)
@@ -1110,6 +1114,8 @@ def main(args):
out.close()
+
+ os.chdir(cwd)
# Call main function
diff --git a/src/ngspicetoModelica/__init__.py b/src/ngspicetoModelica/__init__.py
new file mode 100644
index 00000000..e69de29b
--
cgit