summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/release_ubuntu.yml124
-rw-r--r--src/kicadtoNgspice/Convert.py154
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py168
-rw-r--r--src/kicadtoNgspice/Microcontroller.py283
-rw-r--r--src/kicadtoNgspice/Model.py220
-rw-r--r--src/kicadtoNgspice/Processing.py2
-rw-r--r--src/kicadtoNgspice/TrackWidget.py2
7 files changed, 748 insertions, 205 deletions
diff --git a/.github/workflows/release_ubuntu.yml b/.github/workflows/release_ubuntu.yml
new file mode 100644
index 00000000..0fc6043b
--- /dev/null
+++ b/.github/workflows/release_ubuntu.yml
@@ -0,0 +1,124 @@
+# By Sai Charan Lanka (@saicharan0112) : Nov 12, 2022
+# This is the workflow to pack the eSim for Ubuntu OS which follows the steps shown in the installer branch and release the zip file which can be uploaded onto the website
+# Note:
+# 1. Make sure the eSim manual for the version about to release, already exists in the https://static.fossee.in/esim/manuals/ location. Else the release fails.
+# 2. To trigger this workflow, create and push tags that start with "v".
+# For more info, refer to PR#230 and Issue#211
+
+
+name: Auto release of eSim for Ubuntu OS
+
+on:
+ push:
+ tags:
+ - 'v*' # Push events to matching v*, i.e. v2.2, v2.3 etc
+
+
+jobs:
+ release_eSim:
+ runs-on: ubuntu-latest
+ steps:
+
+
+# Create eSim release directory
+ - name: Preparing eSim for release
+ run: mkdir /home/runner/work/eSim_release
+
+
+# Steps to prepare nghld.zip
+ - name: Preparing nghdl for release
+ run: mkdir /home/runner/work/nghdl_release
+
+ - name: Checkout FOSSEE/nghdl installers branch
+ uses: actions/checkout@v3
+ with:
+ repository: FOSSEE/nghdl
+ ref: installers
+
+ - name: Get required data from the nghld/installers branch
+ run: |
+ cp Ubuntu/ghdl-*.tar.xz /home/runner/work/nghdl_release/.
+ cp Ubuntu/verilator-*.tar.xz /home/runner/work/nghdl_release/.
+ cp Ubuntu/install-nghdl.sh /home/runner/work/nghdl_release/.
+
+ - name: Checkout FOSSEE/nghdl installers branch
+ uses: actions/checkout@v3
+ with:
+ repository: FOSSEE/nghdl
+ ref: master
+
+ - name: Get required data from the nghld/master branch
+ run: |
+ cp -rf ./* /home/runner/work/nghdl_release/.
+ cd /home/runner/work
+ rm -rf nghdl_release/.git* nghdl_release/*.md
+
+ - name: Compress the nghdl folder and copy it to eSim release folder
+ run: |
+ zip -r nghld.zip . -i nghdl_release/.
+ cp nghld.zip /home/runner/work/eSim_release/.
+ tree /home/runner/work/
+
+
+# Steps to prepare eSim release directory
+ - name: Checkout FOSSEE/eSim master branch
+ uses: actions/checkout@v3
+ with:
+ repository: FOSSEE/eSim
+ ref: master
+
+ - name: Compress the library/kicadLibrary folder
+ run: |
+ tar cfJ kicadLibrary.tar.xz library/kicadLibrary/.
+ cp kicadLibrary.tar.xz /home/runner/work/eSim_release/.
+
+ - name: Copy all the data from eSim/master to eSim_release and delete specific data
+ run: |
+ rm -rf .git* code library/browser/User-Manual/figures
+ rm conf.py setup.py index.rst requirements.txt .travis.yml library/browser/User-Manual/eSim.html
+ cp -rf ./* /home/runner/work/eSim_release/.
+
+ - name: Checkout FOSSEE/eSim installers branch
+ uses: actions/checkout@v3
+ with:
+ repository: FOSSEE/eSim
+ ref: installers
+
+ - name: Copy install-eSim.sh script to the release directory
+ run: |
+ cp Ubuntu/install-eSim.sh /home/runner/work/eSim_release/.
+
+ # extract the number from the tag to pull the relevant manual from the website
+ - name: Copy eSim manual which is available at https://static.fossee.in/esim/manuals/
+ run: |
+ VERSION=$(echo $GITHUB_REF_NAME | cut -d 'v' -f 2)
+ wget https://static.fossee.in/esim/manuals/eSim_Manual_$VERSION.pdf
+
+ - name: Zip the eSim_release folder
+ run: |
+ cd /home/runner/work/
+ zip -r eSim-$VERSION.zip eSim_release/
+
+
+# Create a release and upload artifact
+ - name: Create Release
+ id: create_release
+ uses: actions/create-release@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ tag_name: ${{ github.ref_name }}
+ release_name: eSim-$VERSION
+ draft: false
+ prerelease: false
+
+ - name: Upload Release Asset
+ id: upload-release-asset
+ uses: actions/upload-release-asset@v1
+ env:
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ with:
+ upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
+ asset_path: /home/runner/work/eSim-$VERSION.zip
+ asset_name: eSim-$VERSION.zip
+ asset_content_type: application/zip \ No newline at end of file
diff --git a/src/kicadtoNgspice/Convert.py b/src/kicadtoNgspice/Convert.py
index 24449a3b..a5b34cee 100644
--- a/src/kicadtoNgspice/Convert.py
+++ b/src/kicadtoNgspice/Convert.py
@@ -1,9 +1,11 @@
-from PyQt5 import QtWidgets
import os
import shutil
-from . import TrackWidget
from xml.etree import ElementTree as ET
+from PyQt5 import QtWidgets
+
+from . import TrackWidget
+
class Convert:
"""
@@ -67,9 +69,8 @@ class Convert:
theta_val = str(self.entry_var[self.end].text()) if len(
str(self.entry_var[self.end].text())) > 0 else '0'
self.addline = self.addline.partition(
- '(')[0] + "(" + vo_val + " " + va_val + " " +\
- freq_val + " " + td_val + " " +\
- theta_val + ")"
+ '(')[0] + "(" + vo_val + " " + va_val + " " + \
+ freq_val + " " + td_val + " " + theta_val + ")"
self.sourcelistvalue.append([self.index, self.addline])
except BaseException:
print(
@@ -102,8 +103,8 @@ class Convert:
str(self.entry_var[self.end].text())) > 0 else '0'
self.addline = self.addline.partition(
- '(')[0] + "(" + v1_val + " " + v2_val + " " +\
- td_val + " " + tr_val + " " + tf_val + " " +\
+ '(')[0] + "(" + v1_val + " " + v2_val + " " + \
+ td_val + " " + tr_val + " " + tf_val + " " + \
pw_val + " " + tp_val + ")"
self.sourcelistvalue.append([self.index, self.addline])
except BaseException:
@@ -183,8 +184,8 @@ class Convert:
str(self.entry_var[self.end].text())) > 0 else '0'
self.addline = self.addline.partition(
- '(')[0] + "(" + v1_val + " " + v2_val + " " +\
- td1_val + " " + tau1_val + " " + td2_val +\
+ '(')[0] + "(" + v1_val + " " + v2_val + " " + \
+ td1_val + " " + tau1_val + " " + td2_val + \
" " + tau2_val + ")"
self.sourcelistvalue.append([self.index, self.addline])
except BaseException:
@@ -403,18 +404,21 @@ class Convert:
if num_turns2 == "":
num_turns2 = "620"
addmodelLine = ".model " + \
- line[3] + \
- "_primary lcouple (num_turns= " + num_turns + ")"
+ line[3] + \
+ "_primary lcouple (num_turns= " + \
+ num_turns + ")"
modelParamValue.append(
[line[0], addmodelLine, "*primary lcouple"])
addmodelLine = ".model " + \
- line[3] + "_iron_core core (" + bh_array + \
- " area = " + area + " length =" + length + ")"
+ line[3] + "_iron_core core (" + bh_array + \
+ " area = " + area + " length =" + length + \
+ ")"
modelParamValue.append(
[line[0], addmodelLine, "*iron core"])
addmodelLine = ".model " + \
- line[3] + \
- "_secondary lcouple (num_turns =" + num_turns2 + ")"
+ line[3] + \
+ "_secondary lcouple (num_turns =" + \
+ num_turns2 + ")"
modelParamValue.append(
[line[0], addmodelLine, "*secondary lcouple"])
except Exception as e:
@@ -456,8 +460,8 @@ class Convert:
default = 0
# Checking if value is iterable.its for vector
if (
- not isinstance(value, str) and
- hasattr(value, '__iter__')
+ not isinstance(value, str) and
+ hasattr(value, '__iter__')
):
addmodelLine += param + "=["
for lineVar in value:
@@ -500,6 +504,122 @@ class Convert:
return schematicInfo
+ def addMicrocontrollerParameter(self, schematicInfo):
+ """
+ This function adds the Microcontroller Model details to schematicInfo
+ """
+
+ # Create object of TrackWidget
+ self.obj_track = TrackWidget.TrackWidget()
+
+ # List to store model line
+ addmodelLine = []
+ modelParamValue = []
+
+ for line in self.obj_track.microcontrollerTrack:
+ # print "Model Track :",line
+ try:
+ start = line[7]
+ # end = line[8]
+ addmodelLine = ".model " + line[3] + " " + line[2] + "("
+ z = 0
+ for key, value in line[9].items():
+ # Checking for default value and accordingly assign
+ # param and default.
+ if ':' in key:
+ key = key.split(':')
+ param = key[0]
+ default = key[1]
+ else:
+ param = key
+ default = 0
+ # Checking if value is iterable.its for vector
+ if (
+ not isinstance(value, str) and
+ hasattr(value, '__iter__')
+ ):
+ addmodelLine += param + "=["
+ for lineVar in value:
+ if str(
+ self.obj_track.microcontroller_var
+ [lineVar].text()) == "":
+ paramVal = default
+ else:
+ paramVal = str(
+ self.obj_track.microcontroller_var
+ [lineVar].text())
+ # Checks For 5th Parameter(Hex File Path)
+ if z == 4:
+ chosen_file_path = paramVal
+ star_file_path = chosen_file_path
+ star_count = 0
+ for c in chosen_file_path:
+ # If character is uppercase
+ if c.isupper():
+ c_in = chosen_file_path.index(c)
+ c_in += star_count
+ # Adding asterisks(*) to the path
+ # around the character
+ star_file_path = \
+ star_file_path[
+ :c_in] + "*" + star_file_path[
+ c_in] + "**" + star_file_path[
+ c_in + 1:]
+ star_count += 3
+
+ paramVal = "\"" + star_file_path + "\""
+
+ addmodelLine += paramVal + " "
+ z = z + 1
+ addmodelLine += "] "
+ else:
+ if str(
+ self.obj_track.microcontroller_var
+ [value].text()) == "":
+ paramVal = default
+ else:
+ paramVal = str(
+ self.obj_track.microcontroller_var
+ [value].text())
+ # Checks For 5th Parameter(Hex File Path)
+ if z == 4:
+ chosen_file_path = paramVal
+ star_file_path = chosen_file_path
+ star_count = 0
+ for c in chosen_file_path:
+ # If character is uppercase
+ if c.isupper():
+ c_in = chosen_file_path.index(c)
+ c_in += star_count
+ # Adding asterisks(*) to the path around
+ # the character
+ star_file_path = \
+ star_file_path[:c_in] + "*" + \
+ star_file_path[c_in] + "**" + \
+ star_file_path[c_in + 1:]
+ star_count += 3
+
+ paramVal = "\"" + star_file_path + "\""
+ z = z + 1
+ addmodelLine += param + "=" + paramVal + " "
+
+ addmodelLine += ") "
+ modelParamValue.append([line[0], addmodelLine, line[4]])
+ except Exception as e:
+ print("Caught an exception in microcontroller ", line[1])
+ print("Exception Message : ", str(e))
+
+ # Adding it to schematic
+ for item in modelParamValue:
+ if ".ic" in item[1]:
+ schematicInfo.insert(0, item[1])
+ schematicInfo.insert(0, item[2])
+ else:
+ schematicInfo.append(item[2]) # Adding Comment
+ schematicInfo.append(item[1]) # Adding model line
+
+ return schematicInfo
+
def addDeviceLibrary(self, schematicInfo, kicadFile):
"""
This function add the library details to schematicInfo
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index 6a919de9..f549c5c6 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -10,24 +10,27 @@
# BUGS: ---
# NOTES: ---
# AUTHOR: Fahim Khan, fahim.elex@gmail.com
-# MODIFIED: Rahul Paknikar, rahulp@cse.iitb.ac.in
+# MODIFIED: Rahul Paknikar, rahulp@iitb.ac.in
# ORGANIZATION: eSim Team at FOSSEE, IIT Bombay
# CREATED: Wednesday 04 March 2015
-# REVISION: Sunday 18 September 2022
+# REVISION: Tuesday 25 April 2023
# =========================================================================
-import sys
import os
+import sys
+from xml.etree import ElementTree as ET
+
from PyQt5 import QtWidgets
-from .Processing import PrcocessNetlist
+
from . import Analysis
-from . import Source
-from . import Model
+from . import Convert
from . import DeviceModel
+from . import Model
+from . import Microcontroller
+from . import Source
from . import SubcircuitTab
-from . import Convert
from . import TrackWidget
-from xml.etree import ElementTree as ET
+from .Processing import PrcocessNetlist
class MainWindow(QtWidgets.QWidget):
@@ -93,10 +96,11 @@ class MainWindow(QtWidgets.QWidget):
schematicInfo, sourcelist)
# List storing model detail
- global modelList, outputOption,\
- unknownModelList, multipleModelList, plotText
+ global modelList, outputOption, unknownModelList, multipleModelList, \
+ plotText, microcontrollerList
modelList = []
+ microcontrollerList = []
outputOption = []
plotText = []
(
@@ -109,8 +113,10 @@ class MainWindow(QtWidgets.QWidget):
) = obj_proc.convertICintoBasicBlocks(
schematicInfo, outputOption, modelList, plotText
)
- # print("=======================================")
- # print("Model available in the Schematic :", modelList)
+ for line in modelList:
+ if line[6] == "Nghdl":
+ microcontrollerList.append(line)
+ modelList.remove(line)
"""
- Checking if any unknown model is used in schematic which is not
@@ -124,7 +130,7 @@ class MainWindow(QtWidgets.QWidget):
self.msg.setModal(True)
self.msg.setWindowTitle("Unknown Models")
self.content = "Your schematic contain unknown model " + \
- ', '.join(unknownModelList)
+ ', '.join(unknownModelList)
self.msg.showMessage(self.content)
self.msg.exec_()
@@ -134,7 +140,7 @@ class MainWindow(QtWidgets.QWidget):
self.msg.setWindowTitle("Multiple Models")
self.mcontent = "Look like you have duplicate model in \
modelParamXML directory " + \
- ', '.join(multipleModelList[0])
+ ', '.join(multipleModelList[0])
self.msg.showMessage(self.mcontent)
self.msg.exec_()
@@ -179,6 +185,9 @@ class MainWindow(QtWidgets.QWidget):
- Subcircuits => obj_subcircuitTab
=> SubcircuitTab.SubcircuitTab(`schematicInfo`,`path_to_projFile`)
+ - Microcontrollers => obj_microcontroller
+ => Model.Model(schematicInfo, microcontrollerList, self.clarg1)
+
- Finally pass each of these objects, to widgets
- convertWindow > mainLayout > tabWidgets > AnalysisTab, SourceTab ...
"""
@@ -213,6 +222,12 @@ class MainWindow(QtWidgets.QWidget):
schematicInfo, self.clarg1)
self.subcircuitTab.setWidget(obj_subcircuitTab)
self.subcircuitTab.setWidgetResizable(True)
+ global obj_microcontroller
+ self.microcontrollerTab = QtWidgets.QScrollArea()
+ obj_microcontroller = Microcontroller.\
+ Microcontroller(schematicInfo, microcontrollerList, self.clarg1)
+ self.microcontrollerTab.setWidget(obj_microcontroller)
+ self.microcontrollerTab.setWidgetResizable(True)
self.tabWidget = QtWidgets.QTabWidget()
# self.tabWidget.TabShape(QtWidgets.QTabWidget.Rounded)
@@ -221,6 +236,7 @@ class MainWindow(QtWidgets.QWidget):
self.tabWidget.addTab(self.modelTab, "Ngspice Model")
self.tabWidget.addTab(self.deviceModelTab, "Device Modeling")
self.tabWidget.addTab(self.subcircuitTab, "Subcircuits")
+ self.tabWidget.addTab(self.microcontrollerTab, "Microcontroller")
self.mainLayout = QtWidgets.QVBoxLayout()
self.mainLayout.addWidget(self.tabWidget)
# self.mainLayout.addStretch(1)
@@ -247,9 +263,9 @@ class MainWindow(QtWidgets.QWidget):
try:
fr = open(
- os.path.join(
- projpath, project_name + "_Previous_Values.xml"), 'r'
- )
+ os.path.join(
+ projpath, project_name + "_Previous_Values.xml"), 'r'
+ )
temp_tree = ET.parse(fr)
temp_root = temp_tree.getroot()
except BaseException:
@@ -552,7 +568,8 @@ class MainWindow(QtWidgets.QWidget):
for grand_child in child:
if i <= end:
grand_child.text = \
- str(obj_model.obj_trac.model_entry_var[i].text())
+ str(obj_model.obj_trac.model_entry_var[
+ i].text())
i = i + 1
tmp_check = 1
@@ -560,24 +577,24 @@ class MainWindow(QtWidgets.QWidget):
attr_ui = ET.SubElement(attr_model, line[3], name="type")
attr_ui.text = line[2]
for key, value in line[7].items():
- if(
- hasattr(value, '__iter__') and
- i <= end and not isinstance(value, str)
+ if (
+ hasattr(value, '__iter__') and
+ i <= end and not isinstance(value, str)
):
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()
- )
+ obj_model.obj_trac.model_entry_var[i].text()
+ )
i = i + 1
else:
ET.SubElement(
attr_ui, "field" + str(i + 1), name=value
).text = str(
- obj_model.obj_trac.model_entry_var[i].text()
- )
+ obj_model.obj_trac.model_entry_var[i].text()
+ )
i = i + 1
# Writing Device Model values
@@ -596,7 +613,7 @@ class MainWindow(QtWidgets.QWidget):
while it <= end:
ET.SubElement(attr_var, "field").text = \
- str(obj_devicemodel.entry_var[it].text())
+ str(obj_devicemodel.entry_var[it].text())
it = it + 1
# Writing Subcircuit values
@@ -615,9 +632,70 @@ class MainWindow(QtWidgets.QWidget):
while it <= end:
ET.SubElement(attr_var, "field").text = \
- str(obj_subcircuitTab.entry_var[it].text())
+ str(obj_subcircuitTab.entry_var[it].text())
it = it + 1
+ # Writing for Microcontroller
+ if check == 0:
+ attr_microcontroller = ET.SubElement(attr_parent,
+ "microcontroller")
+ if check == 1:
+ for child in attr_parent:
+ if child.tag == "microcontroller":
+ attr_microcontroller = 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 microcontrollerList:
+ tmp_check = 0
+ for rand_itr in obj_microcontroller.obj_trac.microcontrollerTrack:
+ 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_microcontroller:
+ if child.text == line[2] and child.tag == line[3]:
+ for grand_child in child:
+ if i <= end:
+ grand_child.text = \
+ str(
+ obj_microcontroller.
+ obj_trac.microcontroller_var[i].text())
+ i = i + 1
+ tmp_check = 1
+
+ if tmp_check == 0:
+ attr_ui = ET.SubElement(attr_microcontroller, line[3],
+ name="type")
+ attr_ui.text = line[2]
+ for key, value in line[7].items():
+ if (
+ hasattr(value, '__iter__') and
+ i <= end and not isinstance(value, str)
+ ):
+ for item in value:
+ ET.SubElement(
+ attr_ui, "field" + str(i + 1), name=item
+ ).text = str(
+ obj_microcontroller.
+ obj_trac.microcontroller_var[i].text()
+ )
+ i = i + 1
+ else:
+ ET.SubElement(
+ attr_ui, "field" + str(i + 1), name=value
+ ).text = str(
+ obj_microcontroller.obj_trac.microcontroller_var[
+ i].text()
+ )
+ i = i + 1
+
# xml written to previous value file for the project
tree = ET.ElementTree(attr_parent)
tree.write(fw)
@@ -650,6 +728,12 @@ class MainWindow(QtWidgets.QWidget):
print("=========================================================")
print("Netlist After Adding Ngspice Model :", store_schematicInfo)
+ store_schematicInfo = self.obj_convert.addMicrocontrollerParameter(
+ store_schematicInfo)
+ print("=========================================================")
+ print("Netlist After Adding Microcontroller Model :",
+ store_schematicInfo)
+
# Adding Device Library to SchematicInfo
store_schematicInfo = self.obj_convert.addDeviceLibrary(
store_schematicInfo, self.kicadFile)
@@ -761,14 +845,14 @@ class MainWindow(QtWidgets.QWidget):
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
+ '.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'):
+ '.plot' or option == '.four'):
eachline = eachline.strip('.')
outputOption.append(eachline + '\n')
elif (option == '.nodeset' or option == '.ic'):
@@ -849,17 +933,17 @@ class MainWindow(QtWidgets.QWidget):
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'
+ 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":
diff --git a/src/kicadtoNgspice/Microcontroller.py b/src/kicadtoNgspice/Microcontroller.py
new file mode 100644
index 00000000..a9360147
--- /dev/null
+++ b/src/kicadtoNgspice/Microcontroller.py
@@ -0,0 +1,283 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import os
+import random
+from configparser import ConfigParser
+from xml.etree import ElementTree as ET
+
+from PyQt5 import QtWidgets, QtCore
+
+from . import TrackWidget
+
+
+# Created By Vatsal Patel on 01/07/2022
+
+class Microcontroller(QtWidgets.QWidget):
+ """
+ - This class creates Model Tab of KicadtoNgspice window.
+ The widgets are created dynamically in the Model Tab.
+ """
+
+ def addHex(self):
+ """
+ This function is use to keep track of all Device Model widget
+ """
+ if os.name == 'nt':
+ self.home = os.path.join('library', 'config')
+ else:
+ self.home = os.path.expanduser('~')
+
+ self.parser = ConfigParser()
+ self.parser.read(os.path.join(
+ self.home, os.path.join('.nghdl', 'config.ini')))
+ self.nghdl_home = self.parser.get('NGHDL', 'NGHDL_HOME')
+
+ self.hexfile = QtCore.QDir.toNativeSeparators(
+ QtWidgets.QFileDialog.getOpenFileName(
+ self, "Open Hex Directory", os.path.expanduser('~'),
+ "HEX files (*.hex);;Text files (*.txt)"
+ )[0]
+ )
+
+ if not self.hexfile:
+ """If no path is selected by user function returns"""
+ return
+
+ chosen_file_path = os.path.abspath(self.hexfile)
+ btn = self.sender()
+
+ # If path is selected the clicked button is stored in btn variable and
+ # checked from list of buttons to add the file path to correct
+ # QLineEdit
+
+ if btn in self.hex_btns:
+ if "Add Hex File" in self.sender().text():
+ self.obj_trac.microcontroller_var[
+ 4 + (5 * self.hex_btns.index(btn))].setText(
+ chosen_file_path)
+
+ def __init__(
+ self,
+ schematicInfo,
+ modelList,
+ clarg1,
+ ):
+
+ QtWidgets.QWidget.__init__(self)
+
+ # Processing for getting previous values
+
+ kicadFile = clarg1
+ (projpath, filename) = os.path.split(kicadFile)
+ project_name = os.path.basename(projpath)
+ check = 1
+ try:
+ f = open(
+ os.path.join(projpath, project_name + "_Previous_Values.xml"),
+ "r",
+ )
+ tree = ET.parse(f)
+ parent_root = tree.getroot()
+ for parent in parent_root:
+ if parent.tag == "microcontroller":
+ self.root = parent
+ except BaseException:
+
+ check = 0
+ print("Microcontroller Previous Values XML is Empty")
+
+ # Creating track widget object
+
+ self.obj_trac = TrackWidget.TrackWidget()
+
+ # for increasing row and counting/tracking line edit widget
+
+ self.nextrow = 0
+ self.nextcount = 0
+
+ # for storing line edit details position details
+
+ self.start = 0
+ self.end = 0
+ self.entry_var = []
+ self.hex_btns = []
+ self.text = ""
+
+ # Creating GUI dynamically for Model tab
+
+ self.grid = QtWidgets.QGridLayout()
+ self.setLayout(self.grid)
+
+ for line in modelList:
+ # print "ModelList Item:",line
+ # Adding title label for model
+ # Key: Tag name,Value:Entry widget number
+
+ tag_dict = {}
+ modelbox = QtWidgets.QGroupBox()
+ modelgrid = QtWidgets.QGridLayout()
+ modelbox.setTitle(line[5])
+ self.start = self.nextcount
+
+ # line[7] is parameter dictionary holding parameter tags.
+
+ i = 0
+ for (key, value) in line[7].items():
+ # Check if value is iterable
+
+ if not isinstance(value, str) and hasattr(value, "__iter__"):
+
+ # For tag having vector value
+
+ temp_tag = []
+ for item in value:
+
+ paramLabel = QtWidgets.QLabel(item)
+ modelgrid.addWidget(paramLabel, self.nextrow, 0)
+ self.obj_trac.microcontroller_var[
+ self.nextcount
+ ] = QtWidgets.QLineEdit()
+ self.obj_trac.microcontroller_var[
+ self.nextcount] = QtWidgets.QLineEdit()
+ self.obj_trac.microcontroller_var[
+ self.nextcount].setText("")
+
+ if "Enter Instance ID (Between 0-99)" in value:
+ self.obj_trac.microcontroller_var[
+ self.nextcount].hide()
+ self.obj_trac.microcontroller_var[
+ self.nextcount].setText(
+ str(random.randint(0, 99)))
+ else:
+ modelgrid.addWidget(paramLabel, self.nextrow, 0)
+
+ if "Path of your .hex file" in value:
+ self.obj_trac.microcontroller_var[
+ self.nextcount].setReadOnly(True)
+ addbtn = QtWidgets.QPushButton("Add Hex File")
+ addbtn.setObjectName("%d" % self.nextcount)
+ addbtn.clicked.connect(self.addHex)
+ modelgrid.addWidget(addbtn, self.nextrow, 2)
+ modelbox.setLayout(modelgrid)
+ self.hex_btns.append(addbtn)
+ try:
+ for child in root:
+ if (
+ child.text == line[2]
+ and child.tag == line[3]
+ ):
+ self.obj_trac.microcontroller_var[
+ self.nextcount].setText(child[i].text)
+ i = i + 1
+ except BaseException:
+ print("Passes previous values")
+
+ modelgrid.addWidget(
+ self.obj_trac.microcontroller_var[self.nextcount],
+ self.nextrow,
+ 1, )
+
+ temp_tag.append(self.nextcount)
+ self.nextcount = self.nextcount + 1
+ self.nextrow = self.nextrow + 1
+
+ tag_dict[key] = temp_tag
+
+ else:
+
+ paramLabel = QtWidgets.QLabel(value)
+ self.obj_trac.microcontroller_var[
+ self.nextcount
+ ] = QtWidgets.QLineEdit()
+ self.obj_trac.microcontroller_var[
+ self.nextcount] = QtWidgets.QLineEdit()
+ self.obj_trac.microcontroller_var[self.nextcount].setText(
+ "")
+
+ if "Enter Instance ID (Between 0-99)" in value:
+ self.obj_trac.microcontroller_var[
+ self.nextcount].hide()
+ self.obj_trac.microcontroller_var[
+ self.nextcount].setText(str(random.randint(0, 99)))
+ else:
+ modelgrid.addWidget(paramLabel, self.nextrow, 0)
+
+ if "Path of your .hex file" in value:
+ self.obj_trac.microcontroller_var[
+ self.nextcount].setReadOnly(True)
+ addbtn = QtWidgets.QPushButton("Add Hex File")
+ addbtn.setObjectName("%d" % self.nextcount)
+ addbtn.clicked.connect(self.addHex)
+ modelgrid.addWidget(addbtn, self.nextrow, 2)
+ modelbox.setLayout(modelgrid)
+ self.hex_btns.append(addbtn)
+
+ # CSS
+
+ modelbox.setStyleSheet(
+ " \
+ QGroupBox { border: 1px solid gray; border-radius:\
+ 9px; margin-top: 0.5em; } \
+ QGroupBox::title { subcontrol-origin: margin; left:\
+ 10px; padding: 0 3px 0 3px; } \
+ "
+ )
+ self.grid.addWidget(modelbox)
+
+ try:
+ for child in root:
+ if child.text == line[2] and child.tag == line[3]:
+ self.obj_trac.microcontroller_var[
+ self.nextcount].setText(child[i].text)
+ i = i + 1
+
+ except BaseException:
+ print("Passes previous values")
+
+ modelgrid.addWidget(
+ self.obj_trac.microcontroller_var[self.nextcount],
+ self.nextrow,
+ 1, )
+
+ tag_dict[key] = self.nextcount
+ self.nextcount = self.nextcount + 1
+ self.nextrow = self.nextrow + 1
+
+ self.end = self.nextcount - 1
+ modelbox.setLayout(modelgrid)
+
+ # CSS
+
+ modelbox.setStyleSheet(
+ " \
+ QGroupBox { border: 1px solid gray; border-radius: \
+ 9px; margin-top: 0.5em; } \
+ QGroupBox::title { subcontrol-origin: margin; left:\
+ 10px; padding: 0 3px 0 3px; } \
+ "
+ )
+
+ self.grid.addWidget(modelbox)
+
+ # This keeps the track of Microcontroller Tab Widget
+
+ lst = [
+ line[0],
+ line[1],
+ line[2],
+ line[3],
+ line[4],
+ line[5],
+ line[6],
+ self.start,
+ self.end,
+ tag_dict,
+ ]
+ check = 0
+ for itr in self.obj_trac.microcontrollerTrack:
+ if itr == lst:
+ check = 1
+ if check == 0:
+ self.obj_trac.microcontrollerTrack.append(lst)
+
+ self.show()
diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py
index 1389e556..22fa02b5 100644
--- a/src/kicadtoNgspice/Model.py
+++ b/src/kicadtoNgspice/Model.py
@@ -1,68 +1,25 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-from PyQt5 import QtWidgets, QtCore, QtGui
-from PyQt5.QtCore import QObject, pyqtSlot
-from . import TrackWidget
-from xml.etree import ElementTree as ET
import os
-import sys
+from configparser import ConfigParser
+from xml.etree import ElementTree as ET
+from PyQt5 import QtWidgets, QtCore
+
+from . import TrackWidget
-class Model(QtWidgets.QWidget):
+class Model(QtWidgets.QWidget):
"""
- This class creates Model Tab of KicadtoNgspice window.
The widgets are created dynamically in the Model Tab.
"""
- # by Sumanto and Jay
-
- def addHex(self):
- """
- This function is use to keep track of all Device Model widget
- """
-
- # print("Calling Track Device Model Library funtion")
-
- init_path = "../../../"
- if os.name == "nt":
- init_path = ""
-
- self.hexfile = QtCore.QDir.toNativeSeparators(
- QtWidgets.QFileDialog.getOpenFileName(
- self, "Open Hex Directory", init_path + "home", "*.hex"
- )[0]
- )
- self.text = open(self.hexfile).read()
- chosen_file_path = os.path.abspath(self.hexfile)
-
- # By Sumanto and Jay
-
- def uploadHex(self):
- """
- This function is use to keep track of all Device Model widget
- """
-
- # print("Calling Track Device Model Library funtion")
-
- path1 = os.path.expanduser("~")
- path2 = "/ngspice-nghdl/src/xspice/icm/ghdl"
- init_path = path1 + path2
- if os.name == "nt":
- init_path = ""
-
- self.hexloc = QtWidgets.QFileDialog.getExistingDirectory(
- self, "Open Hex Directory", init_path
- )
- self.file = open(self.hexloc + "/hex.txt", "w")
- self.file.write(self.text)
- self.file.close()
-
def __init__(
- self,
- schematicInfo,
- modelList,
- clarg1,
+ self,
+ schematicInfo,
+ modelList,
+ clarg1,
):
QtWidgets.QWidget.__init__(self)
@@ -84,9 +41,7 @@ class Model(QtWidgets.QWidget):
if child.tag == "model":
root = child
except BaseException:
-
check = 0
- print("Model Previous Values XML is Empty")
# Creating track widget object
@@ -101,7 +56,8 @@ class Model(QtWidgets.QWidget):
self.start = 0
self.end = 0
- self.entry_var = {}
+ self.entry_var = []
+ self.hex_btns = []
self.text = ""
# Creating GUI dynamically for Model tab
@@ -110,7 +66,6 @@ class Model(QtWidgets.QWidget):
self.setLayout(self.grid)
for line in modelList:
-
# print "ModelList Item:",line
# Adding title label for model
# Key: Tag name,Value:Entry widget number
@@ -120,12 +75,14 @@ class Model(QtWidgets.QWidget):
modelgrid = QtWidgets.QGridLayout()
modelbox.setTitle(line[5])
self.start = self.nextcount
+ self.model_name = line[2]
# line[7] is parameter dictionary holding parameter tags.
i = 0
for (key, value) in line[7].items():
-
+ print(value)
+ print(key)
# Check if value is iterable
if not isinstance(value, str) and hasattr(value, "__iter__"):
@@ -134,73 +91,45 @@ class Model(QtWidgets.QWidget):
temp_tag = []
for item in value:
+
paramLabel = QtWidgets.QLabel(item)
modelgrid.addWidget(paramLabel, self.nextrow, 0)
self.obj_trac.model_entry_var[
self.nextcount
] = QtWidgets.QLineEdit()
- modelgrid.addWidget(
- self.obj_trac.model_entry_var[self.nextcount],
- self.nextrow,
- 1,
- )
+
+ self.obj_trac.model_entry_var[
+ self.nextcount] = QtWidgets.QLineEdit()
+ self.obj_trac.model_entry_var[self.nextcount].setText(
+ "")
try:
for child in root:
if (
- child.text == line[2]
- and child.tag == line[3]
+ child.text == line[2]
+ and child.tag == line[3]
):
self.obj_trac.model_entry_var
[self.nextcount].setText(child[i].text)
+ self.entry_var[self.count].setText(
+ child[0].text)
i = i + 1
except BaseException:
pass
+ modelgrid.addWidget(self.entry_var[self.nextcount],
+ self.nextrow, 1)
+
+ modelgrid.addWidget(
+ self.obj_trac.model_entry_var[self.nextcount],
+ self.nextrow,
+ 1, )
temp_tag.append(self.nextcount)
self.nextcount = self.nextcount + 1
self.nextrow = self.nextrow + 1
- if "upload_hex_file:1" in tag_dict:
- self.addbtn = QtWidgets.QPushButton("Add Hex File")
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.addHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 2)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title {subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
- self.addbtn = QtWidgets.QPushButton(
- "Upload Hex File"
- )
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.uploadHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 3)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title {subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
tag_dict[key] = temp_tag
+
else:
paramLabel = QtWidgets.QLabel(value)
@@ -208,11 +137,21 @@ class Model(QtWidgets.QWidget):
self.obj_trac.model_entry_var[
self.nextcount
] = QtWidgets.QLineEdit()
- modelgrid.addWidget(
- self.obj_trac.model_entry_var[self.nextcount],
- self.nextrow,
- 1,
+
+ self.obj_trac.model_entry_var[
+ self.nextcount] = QtWidgets.QLineEdit()
+ self.obj_trac.model_entry_var[self.nextcount].setText("")
+
+ # CSS
+ modelbox.setStyleSheet(
+ " \
+ QGroupBox { border: 1px solid gray; border-radius:\
+ 9px; margin-top: 0.5em; } \
+ QGroupBox::title { subcontrol-origin: margin; left:\
+ 10px; padding: 0 3px 0 3px; } \
+ "
)
+ self.grid.addWidget(modelbox)
try:
for child in root:
@@ -220,50 +159,22 @@ class Model(QtWidgets.QWidget):
self.obj_trac.model_entry_var[
self.nextcount
].setText(child[i].text)
+ self.entry_var[self.count].setText(
+ child[0].text)
i = i + 1
except BaseException:
pass
+ modelgrid.addWidget(self.entry_var[self.nextcount],
+ self.nextrow, 1)
+ modelgrid.addWidget(
+ self.obj_trac.model_entry_var[self.nextcount],
+ self.nextrow,
+ 1, )
+
tag_dict[key] = self.nextcount
self.nextcount = self.nextcount + 1
self.nextrow = self.nextrow + 1
- if "upload_hex_file:1" in tag_dict:
- self.addbtn = QtWidgets.QPushButton("Add Hex File")
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.addHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 2)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title { subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
- self.addbtn = QtWidgets.QPushButton("Upload Hex File")
- self.addbtn.setObjectName("%d" % self.nextcount)
- self.addbtn.clicked.connect(self.uploadHex)
- modelgrid.addWidget(self.addbtn, self.nextrow, 3)
- modelbox.setLayout(modelgrid)
-
- # CSS
-
- modelbox.setStyleSheet(
- " \
- QGroupBox { border: 1px solid gray; border-radius:\
- 9px; margin-top: 0.5em; } \
- QGroupBox::title { subcontrol-origin: margin; left:\
- 10px; padding: 0 3px 0 3px; } \
- "
- )
-
- self.grid.addWidget(modelbox)
self.end = self.nextcount - 1
modelbox.setLayout(modelgrid)
@@ -303,3 +214,22 @@ class Model(QtWidgets.QWidget):
self.obj_trac.modelTrack.append(lst)
self.show()
+
+ def add_hex_btn(self, modelgrid, modelbox):
+ self.addbtn = QtWidgets.QPushButton("Add Hex File")
+ self.addbtn.setObjectName("%d" % self.nextcount)
+ self.addbtn.clicked.connect(self.addHex)
+ modelgrid.addWidget(self.addbtn, self.nextrow, 2)
+ modelbox.setLayout(modelgrid)
+
+ # CSS
+
+ modelbox.setStyleSheet(
+ " \
+ QGroupBox { border: 1px solid gray; border-radius:\
+ 9px; margin-top: 0.5em; } \
+ QGroupBox::title { subcontrol-origin: margin; left:\
+ 10px; padding: 0 3px 0 3px; } \
+ "
+ )
+ self.grid.addWidget(modelbox)
diff --git a/src/kicadtoNgspice/Processing.py b/src/kicadtoNgspice/Processing.py
index a0b20ada..11c95965 100644
--- a/src/kicadtoNgspice/Processing.py
+++ b/src/kicadtoNgspice/Processing.py
@@ -408,7 +408,7 @@ class PrcocessNetlist:
# Insert comment at remove line
schematicInfo.insert(index, "* " + compline)
comment = "* Schematic Name:\
- " + compType + ", NgSpice Name: " + modelname
+ " + compType + ", Ngspice Name: " + modelname
# Here instead of adding compType(use for XML),
# added modelName(Unique Model Name)
modelList.append(
diff --git a/src/kicadtoNgspice/TrackWidget.py b/src/kicadtoNgspice/TrackWidget.py
index 3a8b0dac..9f1d07c2 100644
--- a/src/kicadtoNgspice/TrackWidget.py
+++ b/src/kicadtoNgspice/TrackWidget.py
@@ -24,7 +24,9 @@ class TrackWidget:
op_check = []
# Track widget for Model detail
modelTrack = []
+ microcontrollerTrack = []
model_entry_var = {}
+ microcontroller_var = {}
# Track Widget for Device Model detail
deviceModelTrack = {}