diff options
author | rahulp13 | 2023-06-29 18:50:40 +0530 |
---|---|---|
committer | rahulp13 | 2023-06-29 18:50:40 +0530 |
commit | 8a9b02d77e76a547ed807c305853a153f481df06 (patch) | |
tree | c8b32633ad8866a025bb073c2d24c9fa0db5a934 | |
parent | f54e0867d3cb568510c222e1045fe78d8bc5bf18 (diff) | |
download | nghdl-8a9b02d77e76a547ed807c305853a153f481df06.tar.gz nghdl-8a9b02d77e76a547ed807c305853a153f481df06.tar.bz2 nghdl-8a9b02d77e76a547ed807c305853a153f481df06.zip |
refactored names with kicad6 conventions
-rw-r--r-- | src/Appconfig.py | 33 | ||||
-rw-r--r-- | src/createKicadLibrary.py | 141 | ||||
-rwxr-xr-x | src/ngspice_ghdl.py | 2 |
3 files changed, 102 insertions, 74 deletions
diff --git a/src/Appconfig.py b/src/Appconfig.py index a53fee5..dee57a8 100644 --- a/src/Appconfig.py +++ b/src/Appconfig.py @@ -25,16 +25,27 @@ class Appconfig: # KiCad V6 Symbol Template kicad_sym_template = { - "start_def": "(symbol \"comp_name\" (pin_names (offset 1.016)) (in_bom yes) (on_board yes)", - "U_field":"(property \"Reference\" \"U\" (id 0) (at 6 7 0)(effects (font (size 1.524 1.524))))", - "comp_name_field":"(property \"Value\" \"comp_name\" (id 1) (at 8 10 0)(effects (font (size 1.524 1.524))))", + "start_def": "(symbol \"comp_name\" (pin_names (offset 1.016)) " + + "(in_bom yes) (on_board yes)", + "U_field": "(property \"Reference\" \"U\" (id 0) (at 6 7 0)" + + "(effects (font (size 1.524 1.524))))", + "comp_name_field": "(property \"Value\" \"comp_name\" (id 1) " + + "(at 8 10 0)(effects (font (size 1.524 1.524))))", "blank_field": [ - "(property \"Footprint\" blank_quotes (id 2) (at 72.39 49.53 0)(effects (font (size 1.524 1.524))))", - "(property \"Datasheet\" blank_quotes (id 3) (at 72.39 49.53 0)(effects (font (size 1.524 1.524))))" - ], - "draw_pos": "(symbol \"comp_name\"(rectangle (start 0 0 ) (end 15.25 2 )(stroke (width 0) (type default) (color 0 0 0 0))(fill (type none))))", - "start_draw":"(symbol", - "input_port":"(pin input line(at -5.15 0.54 0 )(length 5.08 )(name \"in\" (effects(font(size 1.27 1.27))))(number \"1\" (effects (font (size 1.27 1.27)))))", - "output_port": "(pin output line(at 20.38 0.54 180 )(length 5.08 )(name \"out\" (effects(font(size 1.27 1.27))))(number \"2\" (effects (font (size 1.27 1.27)))))", - "end_draw":"))" + "(property \"Footprint\" blank_quotes (id 2) " + + "(at 72.39 49.53 0)(effects (font (size 1.524 1.524))))", + "(property \"Datasheet\" blank_quotes (id 3) " + + "(at 72.39 49.53 0)(effects (font (size 1.524 1.524))))" + ], + "draw_pos": "(symbol \"comp_name\"(rectangle (start 0 0 ) " + + "(end 15.25 2 )(stroke (width 0) (type default) " + + "(color 0 0 0 0))(fill (type none))))", + "start_draw": "(symbol", + "input_port": "(pin input line(at -5.15 0.54 0 )(length 5.08 )" + + "(name \"in\" (effects(font(size 1.27 1.27))))" + + "(number \"1\" (effects (font (size 1.27 1.27)))))", + "output_port": "(pin output line(at 20.38 0.54 180 )(length 5.08 )" + + "(name \"out\" (effects(font(size 1.27 1.27))))" + + "(number \"2\" (effects (font (size 1.27 1.27)))))", + "end_draw": "))" } diff --git a/src/createKicadLibrary.py b/src/createKicadLibrary.py index 911659e..7bbb8c5 100644 --- a/src/createKicadLibrary.py +++ b/src/createKicadLibrary.py @@ -17,13 +17,14 @@ class AutoSchematic(QtWidgets.QWidget): if os.name == 'nt':
eSim_src = Appconfig.src_home
inst_dir = eSim_src.replace('\\eSim', '')
- self.kicad_nghdl_lib = \
+ self.kicad_nghdl_sym = \
inst_dir + '/KiCad/share/kicad/symbols/eSim_Nghdl.kicad_sym'
else:
- self.kicad_nghdl_lib = '/usr/share/kicad/symbols/eSim_Nghdl.kicad_sym'
+ self.kicad_nghdl_sym = \
+ '/usr/share/kicad/symbols/eSim_Nghdl.kicad_sym'
self.parser = Appconfig.parser_nghdl
- def createKicadLibrary(self):
+ def createKicadSymbol(self):
xmlFound = None
for root, dirs, files in os.walk(self.xml_loc):
if (str(self.modelname) + '.xml') in files:
@@ -32,7 +33,7 @@ class AutoSchematic(QtWidgets.QWidget): if xmlFound is None:
self.getPortInformation()
self.createXML()
- self.createLib()
+ self.createSym()
elif (xmlFound == os.path.join(self.xml_loc, 'Nghdl')):
print('Library already exists...')
ret = QtWidgets.QMessageBox.warning(
@@ -46,8 +47,8 @@ class AutoSchematic(QtWidgets.QWidget): print("Overwriting existing libraries")
self.getPortInformation()
self.createXML()
- self.removeOldLibrary() # Removes the exisitng library
- self.createLib()
+ self.removeOldLibrary() # Removes the existng library
+ self.createSym()
else:
print("Exiting Nghdl")
quit()
@@ -56,21 +57,25 @@ class AutoSchematic(QtWidgets.QWidget): ret = QtWidgets.QMessageBox.critical(
self.parent, "Error", '''<b>A standard library already ''' +
'''exists with this name.</b><br/><b>Please change the ''' +
- '''name of your vhdl file and upload it again</b>''',
+ '''name of your vhdl file and upload it again.</b>''',
QtWidgets.QMessageBox.Ok
)
# quit()
- # getting the port information here
def getPortInformation(self):
+ '''
+ getting the port information here
+ '''
portInformation = PortInfo(self)
portInformation.getPortInfo()
self.portInfo = portInformation.bit_list
self.input_length = portInformation.input_len
- # creating the XML files in eSim /library/modelParamXML/Nghdl
def createXML(self):
+ '''
+ creating the XML files in eSim /library/modelParamXML/Nghdl
+ '''
cwd = os.getcwd()
xmlDestination = os.path.join(self.xml_loc, 'Nghdl')
self.splitText = ""
@@ -102,8 +107,10 @@ class AutoSchematic(QtWidgets.QWidget): print("Leaving the directory ", xmlDestination)
os.chdir(cwd)
- # Calculates the maximum between input and output ports
def findBlockSize(self):
+ '''
+ Calculates the maximum between input and output ports
+ '''
ind = self.input_length
return max(
self.char_sum(self.portInfo[:ind]),
@@ -112,70 +119,76 @@ class AutoSchematic(QtWidgets.QWidget): def char_sum(self, ls):
return sum([int(x) for x in ls])
-
- # removing the old library
+
def removeOldLibrary(self):
+ '''
+ removing the old library
+ '''
cwd = os.getcwd()
os.chdir(self.lib_loc)
print("Changing directory to ", self.lib_loc)
- f = open(self.kicad_nghdl_lib)
- lines = f.readlines()
- f.close()
+ sym_file = open(self.kicad_nghdl_sym)
+ lines = sym_file.readlines()
+ sym_file.close()
output = []
line_reading_flag = False
for line in lines:
- if line.startswith("(symbol"): # Eeschema Template start
+ if line.startswith("(symbol"): # Eeschema template start
if line.split()[1] == f"\"{self.modelname}\"":
line_reading_flag = True
if not line_reading_flag:
output.append(line)
- if line.startswith("))"): # Eeschema Template end
+ if line.startswith("))"): # Eeschema template end
line_reading_flag = False
- f = open(self.kicad_nghdl_lib, 'w')
+ sym_file = open(self.kicad_nghdl_sym, 'w')
for line in output:
- f.write(line)
- f.close()
+ sym_file.write(line)
+ sym_file.close()
os.chdir(cwd)
print("Leaving directory, ", self.lib_loc)
- def createLib(self):
- self.dist_port = 2.54 # Distance between two ports(mil)
- self.inc_size = 2.54 # Increment size of a block(mil)
+ def createSym(self):
+ self.dist_port = 2.54 # Distance between two ports (mil)
+ self.inc_size = 2.54 # Increment size of a block (mil)
cwd = os.getcwd()
os.chdir(self.lib_loc)
print("Changing directory to ", self.lib_loc)
- # Removeing ")" from "eSim_Ngveri.kicad_sym"
- file = open(self.kicad_nghdl_lib,"r")
+ # Removing ")" from "eSim_Nghdl.kicad_sym"
+ file = open(self.kicad_nghdl_sym, "r")
content_file = file.read()
- new_content_file=content_file[:-1]
+ new_content_file = content_file[:-1]
file.close()
- file = open(self.kicad_nghdl_lib,"w")
+ file = open(self.kicad_nghdl_sym, "w")
file.write(new_content_file)
file.close()
- # Appending New Schematic
- lib_file = open(self.kicad_nghdl_lib, "a")
+ # Appending new schematic block
+ sym_file = open(self.kicad_nghdl_sym, "a")
line1 = self.template["start_def"]
line1 = line1.split()
line1 = [w.replace('comp_name', self.modelname) for w in line1]
self.template["start_def"] = ' '.join(line1)
- if os.stat(self.kicad_nghdl_lib).st_size == 0:
- lib_file.write("(kicad_symbol_lib (version 20211014) (generator kicad_symbol_editor)" + "\n\n") # Eeschema startar code
- lib_file.write(
- self.template["start_def"] + "\n" + self.template["U_field"]+"\n"
+ if os.stat(self.kicad_nghdl_sym).st_size == 0:
+ sym_file.write(
+ "(kicad_symbol_lib (version 20211014) " +
+ "(generator kicad_symbol_editor)" + "\n\n"
+ ) # Eeschema starter code
+
+ sym_file.write(
+ self.template["start_def"] + "\n" + self.template["U_field"] + "\n"
)
line3 = self.template["comp_name_field"]
line3 = line3.split()
- line3 = [w.replace('comp_name', self.modelname) for w in line3]
+ line3 = [w.replace('comp_name', self.modelname) for w in line3]
self.template["comp_name_field"] = ' '.join(line3)
- lib_file.write(self.template["comp_name_field"] + "\n")
+ sym_file.write(self.template["comp_name_field"] + "\n")
line4 = self.template["blank_field"]
line4_1 = line4[0]
@@ -188,22 +201,25 @@ class AutoSchematic(QtWidgets.QWidget): line4[1] = ' '.join(line4_2)
self.template["blank_qoutes"] = line4
- lib_file.write(line4[0] + "\n" + line4[1] + "\n")
+ sym_file.write(line4[0] + "\n" + line4[1] + "\n")
draw_pos = self.template["draw_pos"]
draw_pos = draw_pos.split()
-
- draw_pos= [w.replace('comp_name', f"{self.modelname}_0_1") for w in draw_pos]
- draw_pos[8] = str(float(draw_pos[8]) + float(self.findBlockSize() * self.inc_size))
- draw_pos_rec= draw_pos[8]
+
+ draw_pos = \
+ [w.replace('comp_name', f"{self.modelname}_0_1") for w in draw_pos]
+ draw_pos[8] = str(
+ float(draw_pos[8]) + float(self.findBlockSize() * self.inc_size)
+ )
+ draw_pos_rec = draw_pos[8]
self.template["draw_pos"] = ' '.join(draw_pos)
- lib_file.write(
- self.template["draw_pos"] + "\n"+
- self.template["start_draw"] + " \""+ f"{self.modelname}_1_1\""+ "\n"
+ sym_file.write(
+ self.template["draw_pos"] + "\n" + self.template["start_draw"] +
+ " \"" + f"{self.modelname}_1_1\"" + "\n"
)
-
+
input_port = self.template["input_port"]
input_port = input_port.split()
output_port = self.template["output_port"]
@@ -211,54 +227,55 @@ class AutoSchematic(QtWidgets.QWidget): inputs = self.portInfo[0: self.input_length]
outputs = self.portInfo[self.input_length:]
- #print("INPUTS AND OUTPUTS ")
- #print(inputs)
- #print(outputs)
-
inputs = self.char_sum(inputs)
outputs = self.char_sum(outputs)
- total = inputs+outputs
+ total = inputs + outputs
port_list = []
-
+
# Set input & output port
input_port[4] = draw_pos_rec
- output_port[4] =draw_pos_rec
-
+ output_port[4] = draw_pos_rec
+
for i in range(total):
if (i < inputs):
input_port[9] = f"\"in{str(i + 1)}\""
input_port[13] = f"\"{str(i + 1)}\""
- input_port[4] = str(float(input_port[4]) - float(self.dist_port))
+ input_port[4] = \
+ str(float(input_port[4]) - float(self.dist_port))
input_list = ' '.join(input_port)
port_list.append(input_list)
else:
output_port[9] = f"\"out{str(i - inputs + 1)}\""
output_port[13] = f"\"{str(i + 1)}\""
- output_port[4] = str(float(output_port[4]) - float(self.dist_port))
+ output_port[4] = \
+ str(float(output_port[4]) - float(self.dist_port))
output_list = ' '.join(output_port)
port_list.append(output_list)
for ports in port_list:
- lib_file.write(ports+"\n")
- lib_file.write(
- self.template["end_draw"] + "\n\n"+")"
+ sym_file.write(ports + "\n")
+ sym_file.write(
+ self.template["end_draw"] + "\n\n" + ")"
)
- lib_file.close()
+ sym_file.close()
os.chdir(cwd)
print('Leaving directory, ', self.lib_loc)
QtWidgets.QMessageBox.information(
- self.parent, "Library added",
- '''Library details for this model is added to the ''' +
- '''<b>eSim_Nghdl.kicad_sym</b> in the KiCad shared directory''',
+ self.parent, "Symbol Added",
+ '''Symbol details for this model is added to the \'''' +
+ '''<b>eSim_Nghdl.kicad_sym</b>\' in the KiCad shared directory.''',
QtWidgets.QMessageBox.Ok
)
-# beginning the PortInfo Class containing Port Information
+
class PortInfo:
+ '''
+ The class contains port information
+ '''
def __init__(self, model):
self.modelname = model.modelname
self.model_loc = os.path.join(
diff --git a/src/ngspice_ghdl.py b/src/ngspice_ghdl.py index e358706..663c491 100755 --- a/src/ngspice_ghdl.py +++ b/src/ngspice_ghdl.py @@ -320,7 +320,7 @@ class Mainwindow(QtWidgets.QWidget): if not self.errorFlag: print('Creating library files................................') schematicLib = AutoSchematic(self, self.modelname) - schematicLib.createKicadLibrary() + schematicLib.createKicadSymbol() else: QtWidgets.QMessageBox.critical( self, 'Error', '''Cannot create Schematic Library of ''' + |