Skip to content

Commit 54f46b2

Browse files
committed
Fix schematics parsing
1 parent f3868aa commit 54f46b2

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

save_restore_layout.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,33 @@ def parse_schematic_files(self, filename, dict_of_sheets):
196196
sheetname = ""
197197
sheetfile = ""
198198
sheet_id = ""
199+
sn_found = False
200+
sf_found = False
199201
for j in range(i,i+10):
200202
if "(uuid " in contents[j]:
201-
sheet_id = contents[j].lstrip("(uuid ").rstrip(")")
202-
if "(property \"Sheet name\"" in contents[j]:
203-
sheetname = contents[j].lstrip("(property \"Sheet name\"").split()[0].replace("\"", "")
204-
if "(property \"Sheet file\"" in contents[j]:
205-
sheetfile = contents[j].lstrip("(property \"Sheet file\"").split()[0].replace("\"", "")
203+
path = contents[j].replace("(uuid ", '').rstrip(")").upper().strip()
204+
sheet_id = path.replace('00000000-0000-0000-0000-0000', '')
205+
if "(property \"Sheet name\"" in contents[j] or "(property \"Sheetname\"" in contents[j]:
206+
if "(property \"Sheet name\"" in contents[j]:
207+
sheetname = contents[j].replace("(property \"Sheet name\"", '').split("(")[0].replace("\"", "").strip()
208+
sn_found = True
209+
if "(property \"Sheetname\"" in contents[j]:
210+
sheetname = contents[j].replace("(property \"Sheetname\"", '').split("(")[0].replace("\"", "").strip()
211+
sn_found = True
212+
if "(property \"Sheet file\"" in contents[j] or "(property \"Sheetfile\"" in contents[j]:
213+
if "(property \"Sheet file\"" in contents[j]:
214+
sheetfile = contents[j].replace("(property \"Sheet file\"", '').split("(")[0].replace("\"", "").strip()
215+
sf_found = True
216+
if "(property \"Sheetfile\"" in contents[j]:
217+
sheetfile = contents[j].replace("(property \"Sheetfile\"", '').split("(")[0].replace("\"", "").strip()
218+
sf_found = True
219+
# properly handle property not found
220+
if not sn_found or not sf_found:
221+
logger.info(f'Did not found sheetfile and/or sheetname properties in the schematic file '
222+
f'in {filename} line:{str(i)}')
223+
raise LookupError(f'Did not found sheetfile and/or sheetname properties in the schematic file '
224+
f'in {filename} line:{str(i)}. Unsupported schematics file format')
225+
206226
# here I should find all sheet data
207227
dict_of_sheets[sheet_id] = [sheetname, sheetfile]
208228
# open a newfound file and look for nested sheets

test_save_restore_layout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_restore_shallow_different_level(self):
5353
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
5454
board = pcbnew.LoadBoard(destination_file)
5555
dst_anchor_fp_ref = 'L201'
56-
restore_layout = RestoreLayout(board, dst_anchor_fp_ref)
56+
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "Shallow, different level")
5757

5858
restore_layout.restore_layout(data_file)
5959

@@ -68,7 +68,7 @@ def test_restore_shallow_same_level(self):
6868
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
6969
board = pcbnew.LoadBoard(destination_file)
7070
dst_anchor_fp_ref = 'L401'
71-
restore_layout = RestoreLayout(board, dst_anchor_fp_ref)
71+
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "Shallow_same_level")
7272

7373
restore_layout.restore_layout(data_file)
7474

@@ -83,7 +83,7 @@ def test_restore_deep(self):
8383
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
8484
board = pcbnew.LoadBoard(destination_file)
8585
dst_anchor_fp_ref = 'L401'
86-
restore_layout = RestoreLayout(board, dst_anchor_fp_ref)
86+
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, None)
8787

8888
restore_layout.restore_layout(data_file)
8989

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.5
1+
2.0.6

0 commit comments

Comments
 (0)