From f54e0867d3cb568510c222e1045fe78d8bc5bf18 Mon Sep 17 00:00:00 2001 From: PSR0001 Date: Fri, 16 Jun 2023 23:43:14 +0530 Subject: Porting kicad v4 to v6 & Coordinate issue solved --- src/createKicadLibrary.py | 93 ++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/src/createKicadLibrary.py b/src/createKicadLibrary.py index ae44c03..911659e 100644 --- a/src/createKicadLibrary.py +++ b/src/createKicadLibrary.py @@ -11,16 +11,16 @@ class AutoSchematic(QtWidgets.QWidget): QtWidgets.QWidget.__init__(self) self.parent = parent self.modelname = modelname.split('.')[0] - self.template = Appconfig.kicad_lib_template.copy() + self.template = Appconfig.kicad_sym_template.copy() self.xml_loc = Appconfig.xml_loc self.lib_loc = Appconfig.lib_loc if os.name == 'nt': eSim_src = Appconfig.src_home inst_dir = eSim_src.replace('\\eSim', '') self.kicad_nghdl_lib = \ - inst_dir + '/KiCad/share/kicad/library/eSim_Nghdl.lib' + inst_dir + '/KiCad/share/kicad/symbols/eSim_Nghdl.kicad_sym' else: - self.kicad_nghdl_lib = '/usr/share/kicad/library/eSim_Nghdl.lib' + self.kicad_nghdl_lib = '/usr/share/kicad/symbols/eSim_Nghdl.kicad_sym' self.parser = Appconfig.parser_nghdl def createKicadLibrary(self): @@ -62,12 +62,14 @@ class AutoSchematic(QtWidgets.QWidget): # quit() + # getting the port information here def getPortInformation(self): 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): cwd = os.getcwd() xmlDestination = os.path.join(self.xml_loc, 'Nghdl') @@ -110,7 +112,8 @@ class AutoSchematic(QtWidgets.QWidget): def char_sum(self, ls): return sum([int(x) for x in ls]) - + + # removing the old library def removeOldLibrary(self): cwd = os.getcwd() os.chdir(self.lib_loc) @@ -123,44 +126,53 @@ class AutoSchematic(QtWidgets.QWidget): line_reading_flag = False for line in lines: - if line.startswith("DEF"): - if line.split()[1] == self.modelname: + 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("ENDDEF"): + if line.startswith("))"): # Eeschema Template end line_reading_flag = False f = open(self.kicad_nghdl_lib, 'w') for line in output: f.write(line) - + f.close() os.chdir(cwd) print("Leaving directory, ", self.lib_loc) def createLib(self): - self.dist_port = 100 # Distance between two ports - self.inc_size = 100 # Increment size of a block + 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") + content_file = file.read() + new_content_file=content_file[:-1] + file.close() + file = open(self.kicad_nghdl_lib,"w") + file.write(new_content_file) + file.close() + + # Appending New Schematic lib_file = open(self.kicad_nghdl_lib, "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("EESchema-LIBRARY Version 2.3" + "\n\n") - # lib_file.write("#encoding utf-8"+ "\n"+ "#"+ "\n" + - # "#test_compo" + "\n"+ "#"+ "\n") + 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" ) 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") @@ -176,19 +188,22 @@ class AutoSchematic(QtWidgets.QWidget): line4[1] = ' '.join(line4_2) self.template["blank_qoutes"] = line4 - lib_file.write( - line4[0] + "\n" + line4[1] + "\n" + - self.template["start_draw"] + "\n" - ) + lib_file.write(line4[0] + "\n" + line4[1] + "\n") draw_pos = self.template["draw_pos"] draw_pos = draw_pos.split() - draw_pos[4] = str( - int(draw_pos[4]) - self.findBlockSize() * self.inc_size) - self.template["draw_pos"] = ' '.join(draw_pos) + + 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] - lib_file.write(self.template["draw_pos"]+"\n") + 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" + ) + input_port = self.template["input_port"] input_port = input_port.split() output_port = self.template["output_port"] @@ -196,9 +211,9 @@ 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) + #print("INPUTS AND OUTPUTS ") + #print(inputs) + #print(outputs) inputs = self.char_sum(inputs) outputs = self.char_sum(outputs) @@ -206,39 +221,43 @@ class AutoSchematic(QtWidgets.QWidget): total = inputs+outputs port_list = [] - + + # Set input & output port + input_port[4] = draw_pos_rec + output_port[4] =draw_pos_rec + for i in range(total): if (i < inputs): - input_port[1] = "in" + str(i + 1) - input_port[2] = str(i + 1) - input_port[4] = str(int(input_port[4]) - self.dist_port) + 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_list = ' '.join(input_port) port_list.append(input_list) else: - output_port[1] = "out" + str(i - inputs + 1) - output_port[2] = str(i + 1) - output_port[4] = str(int(output_port[4]) - self.dist_port) + 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_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" + - self.template["end_def"] + "\n\n\n" + self.template["end_draw"] + "\n\n"+")" ) - + lib_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 ''' + - '''eSim_Nghdl.lib in the KiCad shared directory''', + '''eSim_Nghdl.kicad_sym in the KiCad shared directory''', QtWidgets.QMessageBox.Ok ) - +# beginning the PortInfo Class containing Port Information class PortInfo: def __init__(self, model): self.modelname = model.modelname -- cgit