diff options
Diffstat (limited to 'src/converter')
-rw-r--r-- | src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py | 17 | ||||
-rw-r--r-- | src/converter/LtspiceLibConverter.py | 19 | ||||
-rw-r--r-- | src/converter/libConverter.py | 15 | ||||
-rw-r--r-- | src/converter/ltspiceToKicad.py | 5 | ||||
-rw-r--r-- | src/converter/schematic_converters/lib/PythonLib/libParser.py | 108 |
5 files changed, 96 insertions, 68 deletions
diff --git a/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py b/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py index 2160dac5..bf1a1eac 100644 --- a/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py +++ b/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py @@ -33,16 +33,23 @@ def find_all(a_str, sub): yield start
start += len(sub) # use start += 1 to find overlapping matches
-directory = sys.argv[1]
-# out_file = sys.argv[2]
+# Always go 1 level up from the given path
+directory = os.path.abspath(os.path.join(sys.argv[1], ".."))
if directory=="." : directory = os.getcwd()
+if not os.path.isdir(directory):
+ print(f"ERROR: '{directory}' is not a valid directory.")
+ sys.exit(1)
+
+# out_file = sys.argv[2]
+
dir = os.listdir(directory)
comp = []
for component in dir:
if (component[-4:]==".asy") : comp.append(component)
-indir = directory.split("\\")
-out_file = "LTspice_" + indir[len(indir)-1] + ".lib"
+base_name = os.path.basename(os.path.normpath(directory)) # Get last folder name
+out_file = os.path.join(directory, "LTspice_" + base_name + ".lib")
+print("Output Lib File: ", out_file)
outfl = codecs.open(out_file,"w");
outfl.write("EESchema-LIBRARY Version 2.3\n#encoding utf-8\n#\n")
@@ -207,4 +214,4 @@ for component in comp : outfl.write("ENDDRAW\nENDDEF\n#\n")
-outfl.close()
\ No newline at end of file +outfl.close()
diff --git a/src/converter/LtspiceLibConverter.py b/src/converter/LtspiceLibConverter.py index 1914f8ba..2f652659 100644 --- a/src/converter/LtspiceLibConverter.py +++ b/src/converter/LtspiceLibConverter.py @@ -18,15 +18,24 @@ class LTspiceLibConverter: script_dir = os.path.dirname(os.path.abspath(__file__)) # Define the relative path to parser.py from the current script's directory - relative_parser_path = "LTSpiceToKiCadConverter/src/Ubuntu" + # Check the current operating system + if os.name == 'nt': # Windows + relative_parser_path = "LTSpiceToKiCadConverter/src/Windows" + else: + relative_parser_path = "LTSpiceToKiCadConverter/src/Ubuntu" + + # Construct the full path to libParser.py parser_path = os.path.join(script_dir, relative_parser_path) print(parser_path) - command = f"cd {parser_path} ; python3 lib_LTspice2Kicad.py {file_path}" - print(f"cd {parser_path} ; python3 lib_LTspice2Kicad.py {file_path}") + # Strip the .asy extension + file_path_no_ext = os.path.splitext(file_path)[0] + command = ["python3", "lib_LTspice2Kicad.py", file_path_no_ext] + print("Running command:", " ".join(command), "in", parser_path) try: - subprocess.run(command, shell=True, check=True) + subprocess.run(command, check=True, cwd=parser_path) + # Message box with the conversion success message msg_box = QMessageBox() msg_box.setIcon(QMessageBox.Information) @@ -81,4 +90,4 @@ class LTspiceLibConverter: msg_box.setWindowTitle("No File Selected") msg_box.setText("Please select a file before uploading.") msg_box.setStandardButtons(QMessageBox.Ok) - msg_box.exec_()
\ No newline at end of file + msg_box.exec_() diff --git a/src/converter/libConverter.py b/src/converter/libConverter.py index 617c72c2..3c30f7d3 100644 --- a/src/converter/libConverter.py +++ b/src/converter/libConverter.py @@ -22,11 +22,16 @@ class PspiceLibConverter: # Construct the full path to libParser.py parser_path = os.path.join(script_dir, relative_parser_path) - print(parser_path) - command = f"cd {parser_path} ; python3 libParser.py {file_path}" - print(f"cd {parser_path} ; python3 libParser.py {file_path}") + print("Parser Path:",parser_path) + + # Prepare the command as a list + output_dir = os.path.dirname(file_path) + + command = ["python3", "libparser.py", file_path, output_dir] + print(f"Running command: {' '.join(command)} in directory: {parser_path}") + try: - subprocess.run(command, shell=True, check=True) + subprocess.run(command, check=True, cwd=parser_path) # Message box with the conversion success message msg_box = QMessageBox() msg_box.setIcon(QMessageBox.Information) @@ -81,4 +86,4 @@ class PspiceLibConverter: msg_box.setWindowTitle("No File Selected") msg_box.setText("Please select a file before uploading.") msg_box.setStandardButtons(QMessageBox.Ok) - msg_box.exec_()
\ No newline at end of file + msg_box.exec_() diff --git a/src/converter/ltspiceToKicad.py b/src/converter/ltspiceToKicad.py index e9715f7e..7ec696a5 100644 --- a/src/converter/ltspiceToKicad.py +++ b/src/converter/ltspiceToKicad.py @@ -44,9 +44,10 @@ class LTspiceConverter: # Construct the full path to parser.py parser_path = os.path.join(script_dir, relative_parser_path) - command = f"cd {conPath} && python3 {parser_path}/sch_LTspice2Kicad.py {file_name}" + command = command = ["python3", f"{parser_path}/sch_LTspice2Kicad.py", f"{filename}.asc"] + try: - subprocess.run(command, shell=True, check=True) + subprocess.run(command, check=True, cwd=conPath) # Message box with the conversion success message msg_box = QMessageBox() msg_box.setIcon(QMessageBox.Information) diff --git a/src/converter/schematic_converters/lib/PythonLib/libParser.py b/src/converter/schematic_converters/lib/PythonLib/libParser.py index c94bd7d5..364ecedc 100644 --- a/src/converter/schematic_converters/lib/PythonLib/libParser.py +++ b/src/converter/schematic_converters/lib/PythonLib/libParser.py @@ -21,60 +21,66 @@ libDescr = 'EESchema-LIBRARY Version 4.7 Date: \n#encoding utf-8\n' nameAppend = '_PSPICE' REMOVEDCOMPONENTS = ['TITLEBLK', 'PARAM', 'readme', 'VIEWPOINT', 'LIB', 'copyright', 'WATCH1', 'VECTOR', 'NODESET1'] -for fcounter in range(1, len(sys.argv[1:])+1): - input_file = open(sys.argv[fcounter], 'r+') - fbasename = os.path.basename(sys.argv[fcounter]) - flname = fbasename[:fbasename.find('.')] + '.lib' - flib = open(flname, 'w+') #Write .lib header: - print('Library file name: ',flname) +input_file_path = sys.argv[1] +output_dir = sys.argv[2] - flib.write(libDescr) +# Prepare input/output +input_file = open(input_file_path, 'r') +fbasename = os.path.basename(input_file_path) +flname = fbasename[:fbasename.find('.')] + '.lib' +flpath = os.path.join(output_dir, flname) +os.makedirs(output_dir, exist_ok=True) - line = skipTo(input_file,'*symbol') - print('Parser',line) - ''' +flib = open(flpath, 'w+') # Output .lib file + +print('Library file name: ', flname) + + +line = skipTo(input_file,'*symbol') +print('Parser',line) +''' +while(line != '' and '*symbol' not in line): + line = input_file.readline().strip() + print(line) +''' + +while(line != '__ERROR__'): + #print(input_file.tell()) + #print('Compo line',line) + d = line.find(' ') + cnametmp = line[d+1:] + #print('cnametmp',cnametmp) + d = cnametmp.find(' ') + if d == -1: + cname = cnametmp + else: + cname = cnametmp[0:d] + + #print('cname->',cname) + + fileTMP = open(input_file_path) + c = Component(fileTMP, cname) + #print(c.ref) + fixComp(c) + #print('After fixComp',cname, 'ref=', c.ref) + + write = True + + for i in range(len(REMOVEDCOMPONENTS)): #Don't let these components be saved. + if cname == REMOVEDCOMPONENTS[i]: + write = False + break + #print('write->', write) + #print('line->', line) + if write: + c.type_ = c.type_ + nameAppend + c.print(flib) + + '''line = input_file.readline().strip() while(line != '' and '*symbol' not in line): line = input_file.readline().strip() print(line) ''' - - while(line != '__ERROR__'): - #print(input_file.tell()) - #print('Compo line',line) - d = line.find(' ') - cnametmp = line[d+1:] - #print('cnametmp',cnametmp) - d = cnametmp.find(' ') - if d == -1: - cname = cnametmp - else: - cname = cnametmp[0:d] - - #print('cname->',cname) - - fileTMP = open(sys.argv[fcounter]) - c = Component(fileTMP, cname) - #print(c.ref) - fixComp(c) - #print('After fixComp',cname, 'ref=', c.ref) - - write = True - - for i in range(len(REMOVEDCOMPONENTS)): #Don't let these components be saved. - if cname == REMOVEDCOMPONENTS[i]: - write = False - break - #print('write->', write) - #print('line->', line) - if write: - c.type_ = c.type_ + nameAppend - c.print(flib) - - '''line = input_file.readline().strip() - while(line != '' and '*symbol' not in line): - line = input_file.readline().strip() - print(line) - ''' - line = skipTo(input_file, '*symbol') - flib.write('#\n#End Library\n') - flib.close() + line = skipTo(input_file, '*symbol') +flib.write('#\n#End Library\n') +flib.close() |