summaryrefslogtreecommitdiff
path: root/src/kicadtoNgspice
diff options
context:
space:
mode:
authorrahulp132020-02-23 17:06:49 +0530
committerrahulp132020-02-23 17:06:49 +0530
commitde3096c51107371de2361921dca8ee785e643fc3 (patch)
tree9383ca5dfa55da43e8a41d1a678b3127b476da59 /src/kicadtoNgspice
parent567e3b725fcc9d22e27cfd854a573d3e64deaff1 (diff)
downloadeSim-de3096c51107371de2361921dca8ee785e643fc3.tar.gz
eSim-de3096c51107371de2361921dca8ee785e643fc3.tar.bz2
eSim-de3096c51107371de2361921dca8ee785e643fc3.zip
revert to xml from json
Diffstat (limited to 'src/kicadtoNgspice')
-rw-r--r--src/kicadtoNgspice/Analysis.py168
-rw-r--r--src/kicadtoNgspice/DeviceModel.py87
-rw-r--r--src/kicadtoNgspice/KicadtoNgspice.py566
-rw-r--r--src/kicadtoNgspice/Model.py49
-rw-r--r--src/kicadtoNgspice/Source.py122
-rw-r--r--src/kicadtoNgspice/SubcircuitTab.py31
6 files changed, 522 insertions, 501 deletions
diff --git a/src/kicadtoNgspice/Analysis.py b/src/kicadtoNgspice/Analysis.py
index 9e91cca9..da030153 100644
--- a/src/kicadtoNgspice/Analysis.py
+++ b/src/kicadtoNgspice/Analysis.py
@@ -1,7 +1,7 @@
from PyQt4 import QtGui, QtCore
from . import TrackWidget
import os
-import json
+from xml.etree import ElementTree as ET
class Analysis(QtGui.QWidget):
@@ -198,7 +198,7 @@ class Analysis(QtGui.QWidget):
- 3 radio buttons - Lin | Dec | Oct
- 3 input boxes, with top 2 combos
- If previous values exist then fill default values from
- previous value json file
+ previous value xml file
"""
kicadFile = self.clarg1
(projpath, filename) = os.path.split(kicadFile)
@@ -210,13 +210,16 @@ class Analysis(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 == "analysis":
+ root = child
except BaseException:
check = 0
- print("AC Previous Values JSON is Empty")
+ print("AC Previous Values XML is Empty")
self.acbox = QtGui.QGroupBox()
self.acbox.setTitle("AC Analysis")
@@ -274,8 +277,7 @@ class Analysis(QtGui.QWidget):
# Try setting to default value from anaylsis file
try:
- self.ac_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["ac"]["Start Fre Combo"])
+ self.ac_parameter[self.parameter_cnt] = str(root[0][6].text)
except BaseException:
self.ac_parameter[self.parameter_cnt] = "Hz"
@@ -294,8 +296,7 @@ class Analysis(QtGui.QWidget):
self.ac_parameter[1] = "Hz"
try:
- self.ac_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["ac"]["Stop Fre Combo"])
+ self.ac_parameter[self.parameter_cnt] = str(root[0][7].text)
except BaseException:
self.ac_parameter[self.parameter_cnt] = "Hz"
@@ -313,36 +314,29 @@ class Analysis(QtGui.QWidget):
")
if check:
try:
- if json_data["analysis"]["ac"]["Lin"] == "true":
+ if root[0][0].text == "true":
self.Lin.setChecked(True)
self.Dec.setChecked(False)
self.Oct.setChecked(False)
- elif json_data["analysis"]["ac"]["Dec"] == "true":
+ elif root[0][1].text == "true":
self.Lin.setChecked(False)
self.Dec.setChecked(True)
self.Oct.setChecked(False)
- elif json_data["analysis"]["ac"]["Oct"] == "true":
+ elif root[0][2].text == "true":
self.Lin.setChecked(False)
self.Dec.setChecked(False)
self.Oct.setChecked(True)
- else:
- pass
-
- self.ac_entry_var[0].setText(
- json_data["analysis"]["ac"]["Start Frequency"])
- self.ac_entry_var[1].setText(
- json_data["analysis"]["ac"]["Stop Frequency"])
- self.ac_entry_var[2].setText(
- json_data["analysis"]["ac"]["No. of points"])
- index = self.start_fre_combo.findText(
- json_data["analysis"]["ac"]["Start Fre Combo"])
+
+ self.ac_entry_var[0].setText(root[0][3].text)
+ self.ac_entry_var[1].setText(root[0][4].text)
+ self.ac_entry_var[2].setText(root[0][5].text)
+ index = self.start_fre_combo.findText(root[0][6].text)
self.start_fre_combo.setCurrentIndex(index)
- index = self.stop_fre_combo.findText(
- json_data["analysis"]["ac"]["Stop Fre Combo"])
+ index = self.stop_fre_combo.findText(root[0][7].text)
self.stop_fre_combo.setCurrentIndex(index)
except BaseException:
- print("AC Analysis JSON Parse Error")
+ print("AC Analysis XML Parse Error")
return self.acbox
@@ -402,13 +396,16 @@ class Analysis(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 == "analysis":
+ root = child
except BaseException:
check = 0
- print("DC Previous Values JSON is empty")
+ print("DC Previous Values XML is empty")
self.dcbox = QtGui.QGroupBox()
self.dcbox.setTitle("DC Analysis")
@@ -497,8 +494,7 @@ class Analysis(QtGui.QWidget):
self.dcgrid.addWidget(self.start_combo, 2, 2)
try:
- self.dc_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["dc"]["Start Combo"])
+ self.dc_parameter[self.parameter_cnt] = str(root[1][5].text)
except BaseException:
self.dc_parameter[self.parameter_cnt] = "Volts or Amperes"
@@ -515,8 +511,7 @@ class Analysis(QtGui.QWidget):
self.dcgrid.addWidget(self.increment_combo, 3, 2)
try:
- self.dc_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["dc"]["Increment Combo"])
+ self.dc_parameter[self.parameter_cnt] = str(root[1][6].text)
except BaseException:
self.dc_parameter[self.parameter_cnt] = "Volts or Amperes"
@@ -533,8 +528,7 @@ class Analysis(QtGui.QWidget):
self.dcgrid.addWidget(self.stop_combo, 4, 2)
try:
- self.dc_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["dc"]["Stop Combo"])
+ self.dc_parameter[self.parameter_cnt] = str(root[1][7].text)
except BaseException:
self.dc_parameter[self.parameter_cnt] = "Volts or Amperes"
@@ -551,8 +545,7 @@ class Analysis(QtGui.QWidget):
self.dcgrid.addWidget(self.start_combo2, 6, 2)
try:
- self.dc_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["dc"]["Start Combo2"])
+ self.dc_parameter[self.parameter_cnt] = str(root[1][12].text)
except BaseException:
self.dc_parameter[self.parameter_cnt] = "Volts or Amperes"
@@ -569,8 +562,7 @@ class Analysis(QtGui.QWidget):
self.dcgrid.addWidget(self.increment_combo2, 7, 2)
try:
- self.dc_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["dc"]["Increment Combo2"])
+ self.dc_parameter[self.parameter_cnt] = str(root[1][13].text)
except BaseException:
self.dc_parameter[self.parameter_cnt] = "Volts or Amperes"
@@ -588,8 +580,7 @@ class Analysis(QtGui.QWidget):
self.dcgrid.addWidget(self.stop_combo2, 8, 2)
try:
- self.dc_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["dc"]["Stop Combo2"])
+ self.dc_parameter[self.parameter_cnt] = str(root[1][14].text)
except BaseException:
self.dc_parameter[self.parameter_cnt] = "Volts or Amperes"
@@ -599,7 +590,7 @@ class Analysis(QtGui.QWidget):
self.check = QtGui.QCheckBox('Operating Point Analysis', self)
try:
self.track_obj.op_check.append(
- str(json_data["analysis"]["dc"]["Operating Point"]))
+ str(root[1][4].text()))
except BaseException:
self.track_obj.op_check.append('0')
@@ -621,47 +612,33 @@ class Analysis(QtGui.QWidget):
")
if check:
try:
- self.dc_entry_var[0].setText(
- json_data["analysis"]["dc"]["Source 1"])
- self.dc_entry_var[1].setText(
- json_data["analysis"]["dc"]["Start"])
- self.dc_entry_var[2].setText(
- json_data["analysis"]["dc"]["Increment"])
- self.dc_entry_var[3].setText(
- json_data["analysis"]["dc"]["Stop"])
- index = self.start_combo.findText(
- json_data["analysis"]["dc"]["Start Combo"])
+ self.dc_entry_var[0].setText(root[1][0].text)
+ self.dc_entry_var[1].setText(root[1][1].text)
+ self.dc_entry_var[2].setText(root[1][2].text)
+ self.dc_entry_var[3].setText(root[1][3].text)
+ index = self.start_combo.findText(root[1][5].text)
self.start_combo.setCurrentIndex(index)
- index = self.increment_combo.findText(
- json_data["analysis"]["dc"]["Increment Combo"])
+ index = self.increment_combo.findText(root[1][6].text)
self.increment_combo.setCurrentIndex(index)
- index = self.stop_combo.findText(
- json_data["analysis"]["dc"]["Stop Combo"])
+ index = self.stop_combo.findText(root[1][7].text)
self.stop_combo.setCurrentIndex(index)
- self.dc_entry_var[4].setText(
- json_data["analysis"]["dc"]["Source 2"])
- self.dc_entry_var[5].setText(
- json_data["analysis"]["dc"]["Start2"])
- self.dc_entry_var[6].setText(
- json_data["analysis"]["dc"]["Increment2"])
- self.dc_entry_var[7].setText(
- json_data["analysis"]["dc"]["Stop2"])
- index = self.start_combo2.findText(
- json_data["analysis"]["dc"]["Start Combo2"])
+ self.dc_entry_var[4].setText(root[1][8].text)
+ self.dc_entry_var[5].setText(root[1][9].text)
+ self.dc_entry_var[6].setText(root[1][10].text)
+ self.dc_entry_var[7].setText(root[1][11].text)
+ index = self.start_combo2.findText(root[1][12].text)
self.start_combo2.setCurrentIndex(index)
- index = self.increment_combo2.findText(
- json_data["analysis"]["dc"]["Increment Combo2"])
+ index = self.increment_combo2.findText(root[1][13].text)
self.increment_combo2.setCurrentIndex(index)
- index = self.stop_combo2.findText(
- json_data["analysis"]["dc"]["Stop Combo2"])
+ index = self.stop_combo2.findText(root[1][14].text)
self.stop_combo2.setCurrentIndex(index)
- if json_data["analysis"]["dc"]["Operating Point"] == 1:
+ if root[1][4].text == 1:
self.check.setChecked(True)
else:
self.check.setChecked(False)
except BaseException:
- print("DC Analysis JSON Parse Error")
+ print("DC Analysis XML Parse Error")
return self.dcbox
@@ -719,17 +696,21 @@ class Analysis(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 == "analysis":
+ root = child
except BaseException:
check = 0
- print("Transient Previous Values JSON is Empty")
+ print("Transient Previous Values XML is Empty")
self.trbox = QtGui.QGroupBox()
self.trbox.setTitle("Transient Analysis")
# self.trbox.setDisabled(True)
+ # self.trbox.setVisible(False)
self.trgrid = QtGui.QGridLayout()
self.trbox.setLayout(self.trgrid)
@@ -745,12 +726,10 @@ class Analysis(QtGui.QWidget):
self.trgrid.addWidget(self.tran_entry_var[self.count], 1, 1)
self.tran_entry_var[self.count].setMaximumWidth(150)
self.count += 1
-
self.tran_entry_var[self.count] = QtGui.QLineEdit()
self.trgrid.addWidget(self.tran_entry_var[self.count], 2, 1)
self.tran_entry_var[self.count].setMaximumWidth(150)
self.count += 1
-
self.tran_entry_var[self.count] = QtGui.QLineEdit()
self.trgrid.addWidget(self.tran_entry_var[self.count], 3, 1)
self.tran_entry_var[self.count].setMaximumWidth(150)
@@ -766,8 +745,7 @@ class Analysis(QtGui.QWidget):
self.trgrid.addWidget(self.start_combobox, 1, 3)
try:
- self.tran_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["tran"]["Start Combo"])
+ self.tran_parameter[self.parameter_cnt] = str(root[2][3].text)
except BaseException:
self.tran_parameter[self.parameter_cnt] = "Sec"
@@ -782,8 +760,7 @@ class Analysis(QtGui.QWidget):
self.step_combobox.addItem("ps")
self.trgrid.addWidget(self.step_combobox, 2, 3)
try:
- self.tran_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["tran"]["Step Combo"])
+ self.tran_parameter[self.parameter_cnt] = str(root[2][4].text)
except BaseException:
self.tran_parameter[self.parameter_cnt] = "Sec"
@@ -798,8 +775,7 @@ class Analysis(QtGui.QWidget):
self.stop_combobox.addItem("ps")
self.trgrid.addWidget(self.stop_combobox, 3, 3)
try:
- self.tran_parameter[self.parameter_cnt] = str(
- json_data["analysis"]["tran"]["Stop Combo"])
+ self.tran_parameter[self.parameter_cnt] = str(root[2][5].text)
except BaseException:
self.tran_parameter[self.parameter_cnt] = "Sec"
@@ -818,23 +794,17 @@ class Analysis(QtGui.QWidget):
")
if check:
try:
- self.tran_entry_var[0].setText(
- json_data["analysis"]["tran"]["Start Time"])
- self.tran_entry_var[1].setText(
- json_data["analysis"]["tran"]["Step Time"])
- self.tran_entry_var[2].setText(
- json_data["analysis"]["tran"]["Stop Time"])
- index = self.start_combobox.findText(
- json_data["analysis"]["tran"]["Start Combo"])
+ self.tran_entry_var[0].setText(root[2][0].text)
+ self.tran_entry_var[1].setText(root[2][1].text)
+ self.tran_entry_var[2].setText(root[2][2].text)
+ index = self.start_combobox.findText(root[2][3].text)
self.start_combobox.setCurrentIndex(index)
- index = self.step_combobox.findText(
- json_data["analysis"]["tran"]["Step Combo"])
+ index = self.step_combobox.findText(root[2][4].text)
self.step_combobox.setCurrentIndex(index)
- index = self.stop_combobox.findText(
- json_data["analysis"]["tran"]["Stop Combo"])
+ index = self.stop_combobox.findText(root[2][5].text)
self.stop_combobox.setCurrentIndex(index)
except BaseException:
- print("Transient Analysis JSON Parse Error")
+ print("Transient Analysis XML Parse Error")
return self.trbox
diff --git a/src/kicadtoNgspice/DeviceModel.py b/src/kicadtoNgspice/DeviceModel.py
index 65e09753..d548f289 100644
--- a/src/kicadtoNgspice/DeviceModel.py
+++ b/src/kicadtoNgspice/DeviceModel.py
@@ -1,6 +1,6 @@
from PyQt4 import QtGui
import os
-import json
+from xml.etree import ElementTree as ET
from . import TrackWidget
@@ -32,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)
@@ -82,16 +85,16 @@ class DeviceModel(QtGui.QWidget):
global path_name
try:
- for key in json_data["deviceModel"]:
- if key == words[0]:
+ for child in root:
+ if child.tag[0] == eachline[0] \
+ and child.tag[1] == eachline[1]:
+ # print("DEVICE MODEL MATCHING---", child.tag[0], \
+ # child.tag[1], eachline[0], eachline[1])
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:
@@ -146,16 +149,16 @@ class DeviceModel(QtGui.QWidget):
self.entry_var[self.count].setText("")
# global path_name
try:
- for key in json_data["deviceModel"]:
- if key == words[0]:
+ for child in root:
+ if child.tag[0] == eachline[0] \
+ and child.tag[1] == eachline[1]:
+ # print("DEVICE MODEL MATCHING---", child.tag[0], \
+ # child.tag[1], eachline[0], eachline[1])
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:
@@ -209,16 +212,16 @@ class DeviceModel(QtGui.QWidget):
self.entry_var[self.count].setText("")
# global path_name
try:
- for key in json_data["deviceModel"]:
- if key == words[0]:
+ for child in root:
+ if child.tag[0] == eachline[0] \
+ and child.tag[1] == eachline[1]:
+ # print("DEVICE MODEL MATCHING---", child.tag[0], \
+ # child.tag[1], eachline[0], eachline[1])
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:
@@ -319,19 +322,21 @@ 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]:
+ for child in root:
+ if child.tag[0] == eachline[0] \
+ and child.tag[1] == eachline[1]:
+ # print("DEVICE MODEL MATCHING---", child.tag[0], \
+ # child.tag[1], eachline[0], eachline[1])
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
diff --git a/src/kicadtoNgspice/KicadtoNgspice.py b/src/kicadtoNgspice/KicadtoNgspice.py
index 18701c43..8a4d746d 100644
--- a/src/kicadtoNgspice/KicadtoNgspice.py
+++ b/src/kicadtoNgspice/KicadtoNgspice.py
@@ -27,7 +27,7 @@ from . import DeviceModel
from . import SubcircuitTab
from . import Convert
from . import TrackWidget
-import json
+from xml.etree import ElementTree as ET
class MainWindow(QtGui.QWidget):
@@ -44,7 +44,7 @@ class MainWindow(QtGui.QWidget):
def __init__(self, clarg1, clarg2=None):
QtGui.QWidget.__init__(self)
print("==================================")
- print("Kicad to Ngspice netlist converter ")
+ print("Kicad to Ngspice netlist converter")
print("==================================")
global kicadNetlist, schematicInfo
global infoline, optionInfo
@@ -232,8 +232,8 @@ 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_Values.json file in the projDirectory
+ - Pushing this data to xml, and writing it finally
+ - Written to a ..._Previous_Values.xml file in the projDirectory
- Finally, call createNetListFile, with the converted schematic
"""
global schematicInfo
@@ -242,294 +242,366 @@ class MainWindow(QtGui.QWidget):
store_schematicInfo = list(schematicInfo)
(projpath, filename) = os.path.split(self.kicadFile)
project_name = os.path.basename(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 BaseException:
+ check = 0
# Opening previous value file pertaining to the selected project
fw = open(
os.path.join(
projpath,
project_name +
- "_Previous_Values.json"),
+ "_Previous_Values.xml"),
'w')
- # Creating a dictionary to map the json data
- json_data = {}
+ if check == 0:
+ attr_parent = ET.Element("KicadtoNgspice")
+ if check == 1:
+ attr_parent = temp_root
- # Writing analysis values
- json_data["analysis"] = {}
+ 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")
- json_data["analysis"]["ac"] = {}
if obj_analysis.Lin.isChecked():
- json_data["analysis"]["ac"]["Lin"] = "true"
- json_data["analysis"]["ac"]["Dec"] = "false"
- json_data["analysis"]["ac"]["Oct"] = "false"
+ 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():
- json_data["analysis"]["ac"]["Lin"] = "false"
- json_data["analysis"]["ac"]["Dec"] = "true"
- json_data["analysis"]["ac"]["Oct"] = "false"
+ 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():
- json_data["analysis"]["ac"]["Lin"] = "false"
- json_data["analysis"]["ac"]["Dec"] = "false"
- json_data["analysis"]["ac"]["Oct"] = "true"
-
- json_data["analysis"]["ac"]["Start Frequency"] = str(
- obj_analysis.ac_entry_var[0].text())
- json_data["analysis"]["ac"]["Stop Frequency"] = str(
- obj_analysis.ac_entry_var[1].text())
- json_data["analysis"]["ac"]["No. of points"] = str(
- obj_analysis.ac_entry_var[2].text())
- json_data["analysis"]["ac"]["Start Fre Combo"] = (
- obj_analysis.ac_parameter[0]
- )
- json_data["analysis"]["ac"]["Stop Fre Combo"] = (
- obj_analysis.ac_parameter[1]
- )
-
- json_data["analysis"]["dc"] = {}
- json_data["analysis"]["dc"]["Source 1"] = str(
- obj_analysis.dc_entry_var[0].text())
- json_data["analysis"]["dc"]["Start"] = str(
- obj_analysis.dc_entry_var[1].text())
- json_data["analysis"]["dc"]["Increment"] = str(
- obj_analysis.dc_entry_var[2].text())
- json_data["analysis"]["dc"]["Stop"] = str(
- obj_analysis.dc_entry_var[3].text())
- json_data["analysis"]["dc"]["Operating Point"] = str(
- self.obj_track.op_check[-1])
- json_data["analysis"]["dc"]["Start Combo"] = (
- obj_analysis.dc_parameter[0]
- )
- json_data["analysis"]["dc"]["Increment Combo"] = (
- obj_analysis.dc_parameter[1]
- )
- json_data["analysis"]["dc"]["Stop Combo"] = (
- obj_analysis.dc_parameter[2]
- )
- json_data["analysis"]["dc"]["Source 2"] = str(
- obj_analysis.dc_entry_var[4].text())
- json_data["analysis"]["dc"]["Start2"] = str(
- obj_analysis.dc_entry_var[5].text())
- json_data["analysis"]["dc"]["Increment2"] = str(
- obj_analysis.dc_entry_var[6].text())
- json_data["analysis"]["dc"]["Stop2"] = str(
- obj_analysis.dc_entry_var[7].text())
- json_data["analysis"]["dc"]["Start Combo2"] = (
- obj_analysis.dc_parameter[3]
- )
- json_data["analysis"]["dc"]["Increment Combo2"] = (
- obj_analysis.dc_parameter[4]
- )
- json_data["analysis"]["dc"]["Stop Combo2"] = (
- obj_analysis.dc_parameter[5]
- )
-
- json_data["analysis"]["tran"] = {}
- json_data["analysis"]["tran"]["Start Time"] = str(
- obj_analysis.tran_entry_var[0].text())
- json_data["analysis"]["tran"]["Step Time"] = str(
- obj_analysis.tran_entry_var[1].text())
- json_data["analysis"]["tran"]["Stop Time"] = str(
- obj_analysis.tran_entry_var[2].text())
- json_data["analysis"]["tran"]["Start Combo"] = (
- obj_analysis.tran_parameter[0]
- )
- json_data["analysis"]["tran"]["Step Combo"] = (
- obj_analysis.tran_parameter[1]
- )
- json_data["analysis"]["tran"]["Stop Combo"] = (
- obj_analysis.tran_parameter[2]
- )
+ 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"
+
+ 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 1"
+ ).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())
+ # print("OBJ_ANALYSIS.CHECK -----", self.obj_track.op_check[-1])
+ ET.SubElement(
+ attr_dc, "field5", name="Operating Point"
+ ).text = str(self.obj_track.op_check[-1])
+ 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]
+ ET.SubElement(
+ attr_dc, "field9", name="Source 2"
+ ).text = str(obj_analysis.dc_entry_var[4].text())
+ ET.SubElement(
+ attr_dc, "field10", name="Start"
+ ).text = str(obj_analysis.dc_entry_var[5].text())
+ ET.SubElement(
+ attr_dc, "field11", name="Increment"
+ ).text = str(obj_analysis.dc_entry_var[6].text())
+ ET.SubElement(
+ attr_dc, "field12", name="Stop"
+ ).text = str(obj_analysis.dc_entry_var[7].text())
+ ET.SubElement(
+ attr_dc, "field13", name="Start Combo"
+ ).text = obj_analysis.dc_parameter[3]
+ ET.SubElement(
+ attr_dc, "field14", name="Increment Combo"
+ ).text = obj_analysis.dc_parameter[4]
+ ET.SubElement(
+ attr_dc, "field15", name="Stop Combo"
+ ).text = obj_analysis.dc_parameter[5]
+
+ 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])
+
+ 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
- # Writing source values
- json_data["source"] = {}
count = 1
+ grand_child_count = 1
- for line in store_schematicInfo:
- words = line.split(' ')
+ for i in store_schematicInfo:
+ tmp_check = 0
+ words = i.split(' ')
wordv = words[0]
-
- if wordv[0] == "v" or wordv[0] == "i":
- json_data["source"][wordv] = {}
- json_data["source"][wordv]["type"] = words[len(words) - 1]
- json_data["source"][wordv]["values"] = []
-
- if words[len(words) - 1] == "ac":
- amp = {"Amplitude": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(amp)
-
- phase = {"Phase": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(phase)
-
- elif words[len(words) - 1] == "dc":
- value = {"Value": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(value)
-
- elif words[len(words) - 1] == "sine":
- offset = {
- "Offset Value": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(offset)
-
- amp = {"Amplitude": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(amp)
-
- freq = {"Freuency": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(freq)
-
- delay = {"Delay Time": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(delay)
-
- damp = {
- "Damping Factor": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(damp)
-
- elif words[len(words) - 1] == "pulse":
- initial = {
- "Initial Value": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(initial)
-
- pulse = {
- "Pulse Value": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(pulse)
-
- delay = {"Delay Time": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(delay)
-
- rise = {"Rise Time": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(rise)
-
- fall = {"Fall Time": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(fall)
-
- width = {
- "Pulse width": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(width)
-
- period = {"Period": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(period)
-
- elif words[len(words) - 1] == "pwl":
- pwl = {
- "Enter in pwl format": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(pwl)
-
- elif words[len(words) - 1] == "exp":
- initial = {
- "Initial Value": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(initial)
-
- pulsed = {
- "Pulsed Value": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(pulsed)
-
- rise = {
- "Rise Delay Time": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(rise)
-
- fall = {"Fall Time": str(obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(fall)
-
- fallConstant = {
- "Fall Time Constant": str(
- obj_source.entry_var[count].text())}
- count += 1
- json_data["source"][wordv]["values"].append(fallConstant)
-
- else:
- pass
-
- # Writing Model values
-
+ 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 += 1
+ grand_child_count += 1
+ if tmp_check == 0:
+ words = i.split(' ')
+ wordv = words[0]
+ if wordv[0] == "v" or wordv[0] == "i":
+ 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 += 1
+ ET.SubElement(
+ attr_var, "field2", name="Phase"
+ ).text = str(obj_source.entry_var[count].text())
+ 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 += 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 += 1
+ ET.SubElement(
+ attr_var, "field2", name="Amplitude"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field3", name="Frequency"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field4", name="Delay Time"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field5", name="Damping Factor"
+ ).text = str(obj_source.entry_var[count].text())
+ 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 += 1
+ ET.SubElement(
+ attr_var, "field2", name="Pulse Value"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field3", name="Delay Time"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field4", name="Rise Time"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field5", name="Fall Time"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field5", name="Pulse width"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field5", name="Period"
+ ).text = str(obj_source.entry_var[count].text())
+ 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 += 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 += 1
+ ET.SubElement(
+ attr_var, "field2", name="Pulsed Value"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field3", name="Rise Delay Time"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field4", name="Rise Time Constant"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field5", name="Fall TIme"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 1
+ ET.SubElement(
+ attr_var, "field6", name="Fall Time Constant"
+ ).text = str(obj_source.entry_var[count].text())
+ count += 2
+
+ 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
- json_data["model"] = {}
+
+ # 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:
+ 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
- json_data["model"][line[3]] = {}
- json_data["model"][line[3]]["type"] = line[2]
- json_data["model"][line[3]]["values"] = []
-
- for key, value in line[7].items():
- if(
- hasattr(value, '__iter__') and
- i <= end and not isinstance(value, str)
- ):
- for item in value:
- fields = {
- item: str(
- obj_model.obj_trac.model_entry_var[i].text())}
- json_data["model"][line[3]]["values"].append(fields)
+ 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())
+ i = i + 1
+ 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].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_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()
+ )
i = i + 1
- else:
- fields = {
- value: str(
- obj_model.obj_trac.model_entry_var[i].text())}
- json_data["model"][line[3]]["values"].append(fields)
- i = i + 1
-
# Writing Device Model values
-
- json_data["deviceModel"] = {}
+ 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
for device in obj_devicemodel.devicemodel_dict_beg:
- json_data["deviceModel"][device] = []
+ attr_var = ET.SubElement(attr_devicemodel, device)
it = obj_devicemodel.devicemodel_dict_beg[device]
end = obj_devicemodel.devicemodel_dict_end[device]
while it <= end:
- json_data["deviceModel"][device].append(
- str(obj_devicemodel.entry_var[it].text()))
+ ET.SubElement(attr_var, "field").text = \
+ str(obj_devicemodel.entry_var[it].text())
it = it + 1
# Writing Subcircuit values
+ 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
- json_data["subcircuit"] = {}
for subckt in obj_subcircuitTab.subcircuit_dict_beg:
- json_data["subcircuit"][subckt] = []
+ attr_var = ET.SubElement(attr_subcircuit, subckt)
it = obj_subcircuitTab.subcircuit_dict_beg[subckt]
end = obj_subcircuitTab.subcircuit_dict_end[subckt]
while it <= end:
- json_data["subcircuit"][subckt].append(
- str(obj_subcircuitTab.entry_var[it].text()))
+ ET.SubElement(attr_var, "field").text = \
+ str(obj_subcircuitTab.entry_var[it].text())
it = it + 1
- # json dumped and written to previous value file for the project
- write_data = json.dumps(json_data)
- fw.write(write_data)
+ # xml written to previous value file for the project
+ tree = ET.ElementTree(attr_parent)
+ tree.write(fw)
# Create Convert object with the source details & the schematic details
print("=============================================================")
diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py
index 3cc3a0cb..6de6d8df 100644
--- a/src/kicadtoNgspice/Model.py
+++ b/src/kicadtoNgspice/Model.py
@@ -1,6 +1,6 @@
from PyQt4 import QtGui
-import json
from . import TrackWidget
+from xml.etree import ElementTree as ET
import os
@@ -18,18 +18,23 @@ class Model(QtGui.QWidget):
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.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 == "model":
+ root = child
+
except BaseException:
- print("Model Previous Values JSON is Empty")
+ check = 0
+ print("Model Previous Values XML is Empty")
# Creating track widget object
self.obj_trac = TrackWidget.TrackWidget()
@@ -73,17 +78,12 @@ class Model(QtGui.QWidget):
[self.nextcount], self.nextrow, 1)
try:
- for mod in json_data["model"]:
- if json_data["model"][mod]["type"] ==\
- line[2] and mod == line[3]:
- (
- self.obj_trac.model_entry_var
- [self.nextcount].setText(
- str(list(
- json_data
- ["model"][mod]["values"]
- [i].values())[0]))
- )
+ for child in root:
+ if child.text == line[2] \
+ and child.tag == line[3]:
+ self.obj_trac.model_entry_var
+ [self.nextcount].setText(
+ str(child[i].text))
i = i + 1
except BaseException:
pass
@@ -105,20 +105,13 @@ class Model(QtGui.QWidget):
)
try:
- for mod in json_data["model"]:
- if json_data["model"][mod]["type"] ==\
- line[2] and mod == line[3]:
- (
- self.obj_trac.model_entry_var
- [self.nextcount].setText(
- str(list(json_data
- ["model"][mod]["values"]
- [i].values())[0]))
- )
+ for child in root:
+ if child.text == line[2] and child.tag == line[3]:
+ self.obj_trac.model_entry_var[self.nextcount] \
+ .setText(str(child[i].text))
i = i + 1
except BaseException:
pass
-
tag_dict[key] = self.nextcount
self.nextcount = self.nextcount + 1
self.nextrow = self.nextrow + 1
diff --git a/src/kicadtoNgspice/Source.py b/src/kicadtoNgspice/Source.py
index e76118d4..fdcd4adc 100644
--- a/src/kicadtoNgspice/Source.py
+++ b/src/kicadtoNgspice/Source.py
@@ -1,7 +1,7 @@
import os
from PyQt4 import QtGui
from . import TrackWidget
-import json
+from xml.etree import ElementTree as ET
class Source(QtGui.QWidget):
@@ -57,16 +57,19 @@ class Source(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 == "source":
+ root = child
except BaseException:
- print("Source Previous Values JSON is Empty")
+ print("Source Previous Values XML is Empty")
self.grid = QtGui.QGridLayout()
self.setLayout(self.grid)
+ xml_num = 0
if sourcelist:
for line in sourcelist:
@@ -85,34 +88,23 @@ class Source(QtGui.QWidget):
self.entry_var[self.count] = QtGui.QLineEdit()
self.entry_var[self.count].setMaximumWidth(150)
acgrid.addWidget(self.entry_var[self.count], self.row, 1)
- self.entry_var[self.count].setText("")
- self.count += 1
-
- self.entry_var[self.count] = QtGui.QLineEdit()
- self.entry_var[self.count].setMaximumWidth(150)
+ self.entry_var[self.count + 1] = QtGui.QLineEdit()
+ self.entry_var[self.count + 1].setMaximumWidth(150)
acgrid.addWidget(
- self.entry_var[self.count], self.row + 1, 1)
+ self.entry_var[self.count+1], self.row + 1, 1)
self.entry_var[self.count].setText("")
- self.count += 1
-
+ self.entry_var[self.count+1].setText("")
try:
- for key in json_data["source"]:
+ for child in root:
templist1 = line[1]
templist2 = templist1.split(' ')
- if key == templist2[0] and \
- json_data["source"][key]["type"]\
- == line[2]:
- self.entry_var[self.count - 2].setText(
- str(
- json_data
- ["source"][key]["values"][0]
- ["Amplitude"]))
- self.entry_var[self.count - 1].setText(
- str(
- json_data["source"][key]
- ["values"][1]["Phase"]))
-
+ if child.tag == templist2[0] and \
+ child.text == line[2]:
+ self.entry_var[self.count] \
+ .setText(str(child[0].text))
+ self.entry_var[self.count + 1] \
+ .setText(str(child[1].text))
except BaseException:
pass
# Value Need to check previuouse value
@@ -138,6 +130,7 @@ class Source(QtGui.QWidget):
dcbox = QtGui.QGroupBox()
dcbox.setTitle(line[3])
dcgrid = QtGui.QGridLayout()
+ self.row = self.row + 1
self.start = self.count
label = QtGui.QLabel(line[4])
dcgrid.addWidget(label, self.row, 0)
@@ -148,18 +141,14 @@ class Source(QtGui.QWidget):
self.entry_var[self.count].setText("")
try:
- for key in json_data["source"]:
+ for child in root:
templist1 = line[1]
templist2 = templist1.split(' ')
- if key == templist2[0] and \
- json_data["source"][key]["type"]\
- == line[2]:
- self.entry_var[self.count].setText(
- str(
- json_data["source"][key]
- ["values"][0]["Value"]))
-
+ if child.tag == templist2[0] \
+ and child.text == line[2]:
+ self.entry_var[self.count] \
+ .setText(str(child[0].text))
except BaseException:
pass
@@ -197,17 +186,13 @@ class Source(QtGui.QWidget):
self.entry_var[self.count].setText("")
try:
- for key in json_data["source"]:
+ for child in root:
templist1 = line[1]
templist2 = templist1.split(' ')
- if key == templist2[0] and \
- json_data["source"][key]["type"]\
- == line[2]:
- self.entry_var[self.count].setText(
- str(
- list(json_data["source"]
- [key]["values"]
- [it - 4].values())[0]))
+ if child.tag == templist2[0] \
+ and child.text == line[2]:
+ self.entry_var[self.count] \
+ .setText(str(child[it-4].text))
except BaseException:
pass
@@ -244,17 +229,13 @@ class Source(QtGui.QWidget):
self.entry_var[self.count].setText("")
try:
- for key in json_data["source"]:
+ for child in root:
templist1 = line[1]
templist2 = templist1.split(' ')
-
- if key == templist2[0] and \
- json_data["source"][key]["type"]\
- == line[2]:
- self.entry_var[self.count].setText(
- str(list(
- json_data["source"][key]
- ["values"][it - 4].values())[0]))
+ if child.tag == templist2[0] \
+ and child.text == line[2]:
+ self.entry_var[self.count] \
+ .setText(str(child[it-4].text))
except BaseException:
pass
@@ -288,15 +269,13 @@ class Source(QtGui.QWidget):
self.entry_var[self.count].setText("")
try:
- for key in json_data["source"]:
+ for child in root:
templist1 = line[1]
templist2 = templist1.split(' ')
- if key == templist2[0] and \
- json_data["source"][key]["type"] \
- == line[2]:
- self.entry_var[self.count].setText(
- str(json_data["source"][key]
- ["values"][0]["Enter in pwl format"]))
+ if child.tag == templist2[0] \
+ and child.text == line[2]:
+ self.entry_var[self.count] \
+ .setText(str(child[0].text))
except BaseException:
pass
@@ -333,19 +312,13 @@ class Source(QtGui.QWidget):
self.entry_var[self.count].setText("")
try:
- for key in json_data["source"]:
+ for child in root:
templist1 = line[1]
templist2 = templist1.split(' ')
- if key == templist2[0] and \
- json_data["source"][key]["type"]\
- == line[2]:
- self.entry_var[self.count].setText(
- str(
- list(
- json_data["source"][key]
- ["values"][it - 4].values())[0]
- )
- )
+ if child.tag == templist2[0] \
+ and child.text == line[2]:
+ self.entry_var[self.count] \
+ .setText(str(child[it-4].text))
except BaseException:
pass
@@ -366,6 +339,9 @@ class Source(QtGui.QWidget):
sourcelisttrack.append(
[track_id, 'exp', self.start, self.end])
+ self.count = self.count + 1
+ xml_num = xml_num + 1
+
else:
print("No source is present in your circuit")
diff --git a/src/kicadtoNgspice/SubcircuitTab.py b/src/kicadtoNgspice/SubcircuitTab.py
index 35b876f0..a191c639 100644
--- a/src/kicadtoNgspice/SubcircuitTab.py
+++ b/src/kicadtoNgspice/SubcircuitTab.py
@@ -1,8 +1,8 @@
from PyQt4 import QtGui
-import json
from . import TrackWidget
from projManagement import Validation
import os
+from xml.etree import ElementTree as ET
class SubcircuitTab(QtGui.QWidget):
@@ -11,7 +11,7 @@ class SubcircuitTab(QtGui.QWidget):
- It dynamically creates the widget for subcircuits,
according to the .cir file
- Creates `lineEdit` and `Add` button, which triggers `fileSelector`
- - Also, checks `Previous_value.json` for previous subcircuit value
+ - Also, checks `Previous_value.xml` for previous subcircuit value
to autofill, the `lineEdit`
- Add button is bind to `trackSubcircuit`
- Also `trackSubcircuit` without button is triggered if `lineEdit` filled
@@ -27,12 +27,15 @@ class SubcircuitTab(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 == "subcircuit":
+ root = child
except BaseException:
- print("Subcircuit Previous values JSON is Empty")
+ print("Subcircuit Previous values XML is Empty")
QtGui.QWidget.__init__(self)
@@ -71,14 +74,16 @@ class SubcircuitTab(QtGui.QWidget):
global path_name
try:
- for key in json_data["subcircuit"]:
- if key == words[0]:
+ for child in root:
+ if child.tag[0] == eachline[0] \
+ and child.tag[1] == eachline[1]:
+ # print("Subcircuit MATCHING---", child.tag[0], \
+ # child.tag[1], eachline[0],eachline[1])
try:
- if os.path.exists(
- json_data["subcircuit"][key][0]):
- self.entry_var[self.count].setText(
- json_data["subcircuit"][key][0])
- path_name = json_data["subcircuit"][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: