summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice/DeviceModel.py
diff options
context:
space:
mode:
authorRahul P2020-03-04 17:01:11 +0530
committerGitHub2020-03-04 17:01:11 +0530
commit8ffe81b36caa259151978de0434e4e0c5c32d217 (patch)
tree32202454d13dfabbf6556e98987f2a9632619ea9 /src/kicadtoNgspice/DeviceModel.py
parente40317e709c220176fc5b7edf23d4434504335b0 (diff)
parent13f3bcfda9416624cebbf5705de398e8efcad344 (diff)
downloadeSim-8ffe81b36caa259151978de0434e4e0c5c32d217.tar.gz
eSim-8ffe81b36caa259151978de0434e4e0c5c32d217.tar.bz2
eSim-8ffe81b36caa259151978de0434e4e0c5c32d217.zip
Merge pull request #132 from rahulp13/master
major changes
Diffstat (limited to 'src/kicadtoNgspice/DeviceModel.py')
-rw-r--r--src/kicadtoNgspice/DeviceModel.py130
1 files changed, 58 insertions, 72 deletions
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py
index 7f63a43b..c4ea9a22 100644
--- a/src/kicadtoNgspice/DeviceModel.py
+++ b/src/kicadtoNgspice/DeviceModel.py
@@ -1,7 +1,6 @@
from PyQt4 import QtGui
import os
-# from xml.etree import ElementTree as ET
-import json
+from xml.etree import ElementTree as ET
from . import TrackWidget
@@ -12,13 +11,13 @@ class DeviceModel(QtGui.QWidget):
transistor and jfet.
- Same function as the subCircuit file, except for
this takes different parameters in the if block
- - - q TRANSISTOR
- - - d DIODE
- - - j JFET
- - - m MOSFET
+ - q TRANSISTOR
+ - d DIODE
+ - j JFET
+ - m MOSFET
- Other 2 functions same as the ones in subCircuit
- - - trackLibrary
- - - trackLibraryWithoutButton
+ - trackLibrary
+ - trackLibraryWithoutButton
"""
def __init__(self, schematicInfo, clarg1):
@@ -33,12 +32,15 @@ class DeviceModel(QtGui.QWidget):
os.path.join(
projpath,
project_name +
- "_Previous_Values.json"),
+ "_Previous_Values.xml"),
'r')
- data = f.read()
- json_data = json.loads(data)
+ tree = ET.parse(f)
+ parent_root = tree.getroot()
+ for child in parent_root:
+ if child.tag == "devicemodel":
+ root = child
except BaseException:
- print("Device Model Previous JSON is Empty")
+ print("Device Model Previous XML is Empty")
QtGui.QWidget.__init__(self)
@@ -62,14 +64,14 @@ class DeviceModel(QtGui.QWidget):
# Set Layout
self.grid = QtGui.QGridLayout()
self.setLayout(self.grid)
- print("Reading Device model details from Schematic")
+ # print("Reading Device model details from Schematic")
for eachline in schematicInfo:
print("=========================================")
print(eachline)
words = eachline.split()
if eachline[0] == 'q':
- print("Device Model Transistor: ", words[0])
+ # print("Device Model Transistor: ", words[0])
self.devicemodel_dict_beg[words[0]] = self.count
transbox = QtGui.QGroupBox()
transgrid = QtGui.QGridLayout()
@@ -83,18 +85,15 @@ class DeviceModel(QtGui.QWidget):
global path_name
try:
- for key in json_data["deviceModel"]:
- if key == words[0]:
- # print "DEVICE MODEL MATCHING---",child.tag[0],\
- # child.tag[1],eachline[0],eachline[1]
+ for child in root:
+ if child.tag == words[0]:
+ # print("DEVICE MODEL MATCHING---", \
+ # child.tag, words[0])
try:
- if os.path.exists(
- json_data["deviceModel"][key][0]):
- self.entry_var[self.count].setText(
- json_data["deviceModel"][key][0])
- path_name = (
- json_data["deviceModel"][key][0]
- )
+ if os.path.exists(child[0].text):
+ self.entry_var[self.count] \
+ .setText(child[0].text)
+ path_name = child[0].text
else:
self.entry_var[self.count].setText("")
except BaseException:
@@ -128,7 +127,7 @@ class DeviceModel(QtGui.QWidget):
self.grid.addWidget(transbox)
- # Adding Device Details
+ # Adding Device Details #
# Increment row and widget count
self.row = self.row + 1
@@ -136,7 +135,7 @@ class DeviceModel(QtGui.QWidget):
self.count = self.count + 1
elif eachline[0] == 'd':
- print("Device Model Diode:", words[0])
+ # print("Device Model Diode:", words[0])
self.devicemodel_dict_beg[words[0]] = self.count
diodebox = QtGui.QGroupBox()
diodegrid = QtGui.QGridLayout()
@@ -149,18 +148,15 @@ class DeviceModel(QtGui.QWidget):
self.entry_var[self.count].setText("")
# global path_name
try:
- for key in json_data["deviceModel"]:
- if key == words[0]:
- # print "DEVICE MODEL MATCHING---",child.tag[0],\
- # child.tag[1],eachline[0],eachline[1]
+ for child in root:
+ if child.tag == words[0]:
+ # print("DEVICE MODEL MATCHING---", \
+ # child.tag, words[0])
try:
- if os.path.exists(
- json_data["deviceModel"][key][0]):
- path_name = (
- json_data["deviceModel"][key][0]
- )
- self.entry_var[self.count].setText(
- json_data["deviceModel"][key][0])
+ if os.path.exists(child[0].text):
+ path_name = child[0].text
+ self.entry_var[self.count] \
+ .setText(child[0].text)
else:
self.entry_var[self.count].setText("")
except BaseException:
@@ -193,7 +189,7 @@ class DeviceModel(QtGui.QWidget):
self.grid.addWidget(diodebox)
- # Adding Device Details
+ # Adding Device Details #
# Increment row and widget count
self.row = self.row + 1
@@ -201,7 +197,7 @@ class DeviceModel(QtGui.QWidget):
self.count = self.count + 1
elif eachline[0] == 'j':
- print("Device Model JFET:", words[0])
+ # print("Device Model JFET:", words[0])
self.devicemodel_dict_beg[words[0]] = self.count
jfetbox = QtGui.QGroupBox()
jfetgrid = QtGui.QGridLayout()
@@ -214,18 +210,15 @@ class DeviceModel(QtGui.QWidget):
self.entry_var[self.count].setText("")
# global path_name
try:
- for key in json_data["deviceModel"]:
- if key == words[0]:
- # print "DEVICE MODEL MATCHING---",child.tag[0],\
- # child.tag[1],eachline[0],eachline[1]
+ for child in root:
+ if child.tag == words[0]:
+ # print("DEVICE MODEL MATCHING---", \
+ # child.tag, words[0])
try:
- if os.path.exists(
- json_data["deviceModel"][key][0]):
- self.entry_var[self.count].setText(
- json_data["deviceModel"][key][0])
- path_name = (
- json_data["deviceModel"][key][0]
- )
+ if os.path.exists(child[0].text):
+ self.entry_var[self.count] \
+ .setText(child[0].text)
+ path_name = child[0].text
else:
self.entry_var[self.count].setText("")
except BaseException:
@@ -258,7 +251,8 @@ class DeviceModel(QtGui.QWidget):
self.grid.addWidget(jfetbox)
- # Adding Device Details
+ # Adding Device Details #
+
# Increment row and widget count
self.row = self.row + 1
self.devicemodel_dict_end[words[0]] = self.count
@@ -325,21 +319,20 @@ class DeviceModel(QtGui.QWidget):
self.devicemodel_dict_end[words[0]] = self.count
self.count = self.count + 1
mosfetbox.setLayout(mosfetgrid)
+
# global path_name
try:
- for key in json_data["deviceModel"]:
- if key == words[0]:
- # print "DEVICE MODEL MATCHING---",child.tag[0],\
- # child.tag[1],eachline[0],eachline[1]
+ for child in root:
+ if child.tag == words[0]:
+ # print("DEVICE MODEL MATCHING---", \
+ # child.tag, words[0])
while i <= end:
- self.entry_var[i].setText(
- json_data["deviceModel"][key][i - beg])
+ self.entry_var[i].setText(child[i-beg].text)
if (i - beg) == 0:
- if os.path.exists(
- json_data["deviceModel"][key][0]):
- path_name = (
- json_data["deviceModel"][key][0]
- )
+ if os.path.exists(child[0].text):
+ self.entry_var[i] \
+ .setText(child[i-beg].text)
+ path_name = child[i-beg].text
else:
self.entry_var[i].setText("")
i = i + 1
@@ -367,23 +360,19 @@ class DeviceModel(QtGui.QWidget):
"""
print("Calling Track Device Model Library funtion")
sending_btn = self.sender()
- # print "Object Called is ",sending_btn.objectName()
self.widgetObjCount = int(sending_btn.objectName())
self.libfile = str(
QtGui.QFileDialog.getOpenFileName(
- self,
- "Open Library Directory",
- "../deviceModelLibrary",
+ self, "Open Library Directory",
+ "library/deviceModelLibrary",
"*.lib"))
- # print "Selected Library File :",self.libfile
# Setting Library to Text Edit Line
self.entry_var[self.widgetObjCount].setText(self.libfile)
self.deviceName = self.deviceDetail[self.widgetObjCount]
# Storing to track it during conversion
-
if self.deviceName[0] == 'm':
width = str(self.entry_var[self.widgetObjCount + 1].text())
length = str(self.entry_var[self.widgetObjCount + 2].text())
@@ -406,19 +395,16 @@ class DeviceModel(QtGui.QWidget):
This function is use to keep track of all Device Model widget
"""
print("Calling Track Library function Without Button")
- # print "Object Called is ",sending_btn.objectName()
self.widgetObjCount = iter_value
print("self.widgetObjCount-----", self.widgetObjCount)
self.libfile = path_value
print("PATH VALUE", path_value)
- # print "Selected Library File :",self.libfile
# Setting Library to Text Edit Line
self.entry_var[self.widgetObjCount].setText(self.libfile)
self.deviceName = self.deviceDetail[self.widgetObjCount]
# Storing to track it during conversion
-
if self.deviceName[0] == 'm':
width = str(self.entry_var[self.widgetObjCount + 1].text())
length = str(self.entry_var[self.widgetObjCount + 2].text())