Skip to content

Commit

Permalink
Fix schematics parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
MitjaNemec committed Feb 25, 2023
1 parent f3868aa commit 54f46b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
30 changes: 25 additions & 5 deletions save_restore_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,33 @@ def parse_schematic_files(self, filename, dict_of_sheets):
sheetname = ""
sheetfile = ""
sheet_id = ""
sn_found = False
sf_found = False
for j in range(i,i+10):
if "(uuid " in contents[j]:
sheet_id = contents[j].lstrip("(uuid ").rstrip(")")
if "(property \"Sheet name\"" in contents[j]:
sheetname = contents[j].lstrip("(property \"Sheet name\"").split()[0].replace("\"", "")
if "(property \"Sheet file\"" in contents[j]:
sheetfile = contents[j].lstrip("(property \"Sheet file\"").split()[0].replace("\"", "")
path = contents[j].replace("(uuid ", '').rstrip(")").upper().strip()
sheet_id = path.replace('00000000-0000-0000-0000-0000', '')
if "(property \"Sheet name\"" in contents[j] or "(property \"Sheetname\"" in contents[j]:
if "(property \"Sheet name\"" in contents[j]:
sheetname = contents[j].replace("(property \"Sheet name\"", '').split("(")[0].replace("\"", "").strip()
sn_found = True
if "(property \"Sheetname\"" in contents[j]:
sheetname = contents[j].replace("(property \"Sheetname\"", '').split("(")[0].replace("\"", "").strip()
sn_found = True
if "(property \"Sheet file\"" in contents[j] or "(property \"Sheetfile\"" in contents[j]:
if "(property \"Sheet file\"" in contents[j]:
sheetfile = contents[j].replace("(property \"Sheet file\"", '').split("(")[0].replace("\"", "").strip()
sf_found = True
if "(property \"Sheetfile\"" in contents[j]:
sheetfile = contents[j].replace("(property \"Sheetfile\"", '').split("(")[0].replace("\"", "").strip()
sf_found = True
# properly handle property not found
if not sn_found or not sf_found:
logger.info(f'Did not found sheetfile and/or sheetname properties in the schematic file '
f'in {filename} line:{str(i)}')
raise LookupError(f'Did not found sheetfile and/or sheetname properties in the schematic file '
f'in {filename} line:{str(i)}. Unsupported schematics file format')

# here I should find all sheet data
dict_of_sheets[sheet_id] = [sheetname, sheetfile]
# open a newfound file and look for nested sheets
Expand Down
6 changes: 3 additions & 3 deletions test_save_restore_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_restore_shallow_different_level(self):
destination_file = os.path.join(prj_dir, 'save_restore_destination_project.kicad_pcb')
board = pcbnew.LoadBoard(destination_file)
dst_anchor_fp_ref = 'L201'
restore_layout = RestoreLayout(board, dst_anchor_fp_ref)
restore_layout = RestoreLayout(board, dst_anchor_fp_ref, "Shallow, different level")

restore_layout.restore_layout(data_file)

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

restore_layout.restore_layout(data_file)

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

restore_layout.restore_layout(data_file)

Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.5
2.0.6

0 comments on commit 54f46b2

Please sign in to comment.