summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kicadtoNgspice/Model.py92
-rwxr-xr-xsrc/maker/ModelGeneration.py8
-rw-r--r--src/maker/createkicad.py17
3 files changed, 47 insertions, 70 deletions
diff --git a/src/kicadtoNgspice/Model.py b/src/kicadtoNgspice/Model.py
index 55a988c0..8be92dd9 100644
--- a/src/kicadtoNgspice/Model.py
+++ b/src/kicadtoNgspice/Model.py
@@ -75,94 +75,58 @@ class Model(QtWidgets.QWidget):
print(value)
print(key)
- # Check if value is iterable
+ # VECTOR parameters
if not isinstance(value, str) and hasattr(value, "__iter__"):
- # For tag having vector value
temp_tag = []
for item in value:
+ lbl = QtWidgets.QLabel(item)
+ modelgrid.addWidget(lbl, self.nextrow, 0)
- paramLabel = QtWidgets.QLabel(item)
- modelgrid.addWidget(paramLabel, self.nextrow, 0)
- self.obj_trac.model_entry_var[
- self.nextcount
- ] = QtWidgets.QLineEdit()
-
- self.obj_trac.model_entry_var[
- self.nextcount] = QtWidgets.QLineEdit()
- self.obj_trac.model_entry_var[self.nextcount].setText(
- "")
+ # create & store one QLineEdit
+ le = QtWidgets.QLineEdit()
+ self.obj_trac.model_entry_var[self.nextcount] = le
+ le.setText("")
+ # load any previous XML value
try:
for child in root:
- if (
- 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
+ if child.text == line[2] and child.tag == line[3]:
+ le.setText(child[i].text)
+ 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, )
+ # add exactly one widget per row
+ modelgrid.addWidget(le, self.nextrow, 1)
temp_tag.append(self.nextcount)
- self.nextcount = self.nextcount + 1
- self.nextrow = self.nextrow + 1
+ self.nextcount += 1
+ self.nextrow += 1
tag_dict[key] = temp_tag
+ # SCALAR parameters
else:
- paramLabel = QtWidgets.QLabel(value)
- modelgrid.addWidget(paramLabel, self.nextrow, 0)
- self.obj_trac.model_entry_var[
- self.nextcount
- ] = QtWidgets.QLineEdit()
-
- 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)
+ lbl = QtWidgets.QLabel(value)
+ modelgrid.addWidget(lbl, self.nextrow, 0)
+
+ le = QtWidgets.QLineEdit()
+ self.obj_trac.model_entry_var[self.nextcount] = le
+ le.setText("")
try:
for child in root:
if 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
+ le.setText(child[i].text)
+ 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, )
+ modelgrid.addWidget(le, self.nextrow, 1)
- tag_dict[key] = self.nextcount
- self.nextcount = self.nextcount + 1
- self.nextrow = self.nextrow + 1
+ tag_dict[key] = self.nextcount
+ self.nextcount += 1
+ self.nextrow += 1
self.end = self.nextcount - 1
modelbox.setLayout(modelgrid)
diff --git a/src/maker/ModelGeneration.py b/src/maker/ModelGeneration.py
index 7dce1de7..f6afd5c0 100755
--- a/src/maker/ModelGeneration.py
+++ b/src/maker/ModelGeneration.py
@@ -167,6 +167,12 @@ class ModelGeneration(QtWidgets.QWidget):
code = code.replace("wire", " ")
code = code.replace("reg", " ")
+
+ header_re = re.compile(r'module\s+\w+\s*\((.*?)\)\s*;', re.S)
+ def _split_ports(match):
+ # add a newline after every comma that is inside the header
+ return match.group(0).replace(',', ',\n')
+ code = header_re.sub(_split_ports, code)
vlog_ex = vlog.VerilogExtractor()
vlog_mods = vlog_ex.extract_objects_from_source(code)
f = open(self.modelpath + "connection_info.txt", 'w')
@@ -718,7 +724,7 @@ and set the load for input ports */
int foo_''' + self.fname.split('.')[0] + '''(int init,int count)
{
int argc=1;
- char* argv[]={"fullverbose"};
+ const char* argv[]={"fullverbose"};
Verilated::commandArgs(argc, argv);
static VerilatedContext* contextp = new VerilatedContext;
static V''' + self.fname.split('.')[0] + "* " + \
diff --git a/src/maker/createkicad.py b/src/maker/createkicad.py
index 3f30e835..ccc19719 100644
--- a/src/maker/createkicad.py
+++ b/src/maker/createkicad.py
@@ -189,9 +189,14 @@ class AutoSchematic:
def createSym(self):
'''
creating the symbol
+ (pins snapped to KiCad-6 grid)
'''
- self.dist_port = 2.54 # Distance between two ports (mil)
- self.inc_size = 2.54 # Increment size of a block (mil)
+ self.grid = 0.635
+ self.dist_port = 4 * self.grid # Distance between two ports # 100 mil (= 2.54 mm)
+ self.inc_size = self.dist_port # Increment size of a block (mil)
+ def snap(val):
+ snapped = round(float(val) / self.grid) * self.grid
+ return f"{snapped:.3f}"
cwd = os.getcwd()
os.chdir(self.lib_loc)
print("Changing directory to ", self.lib_loc)
@@ -250,7 +255,7 @@ class AutoSchematic:
draw_pos = \
[w.replace('comp_name', f"{self.modelname}_0_1") for w in draw_pos]
- draw_pos[8] = str(float(draw_pos[8]) + # previously it is (-)
+ draw_pos[8] = snap(float(draw_pos[8]) + # previously it is (-)
float(self.findBlockSize() * self.inc_size))
draw_pos_rec = draw_pos[8]
@@ -265,6 +270,8 @@ class AutoSchematic:
input_port = input_port.split()
output_port = self.template["output_port"]
output_port = output_port.split()
+ input_port[3] = snap(float(input_port[3]))
+ output_port[3] = snap(float(output_port[3]))
inputs = self.portInfo[0: self.input_length]
outputs = self.portInfo[self.input_length:]
inputName = []
@@ -298,7 +305,7 @@ class AutoSchematic:
input_port[9] = f"\"{inputName[i]}\""
input_port[13] = f"\"{str(i + 1)}\""
input_port[4] = \
- str(float(input_port[4]) - float(self.dist_port))
+ snap(float(input_port[4]) - float(self.dist_port))
input_list = ' '.join(input_port)
port_list.append(input_list)
j = j + 1
@@ -307,7 +314,7 @@ class AutoSchematic:
output_port[9] = f"\"{outputName[i - inputs]}\""
output_port[13] = f"\"{str(i + 1)}\""
output_port[4] = \
- str(float(output_port[4]) - float(self.dist_port))
+ snap(float(output_port[4]) - float(self.dist_port))
output_list = ' '.join(output_port)
port_list.append(output_list)