Skip to content

Commit

Permalink
Better schematics filename handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MitjaNemec committed Apr 3, 2023
1 parent 18bc5fd commit 69db95c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions initial_dialog_GUI.fbp
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
<property name="style"></property>
<property name="subclass">; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="tooltip">This will place footprints which are consecutively numbered with respect to currently selected one. When the footprint selection is ready to place, the plugin sorts this list by reference number.</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
Expand Down Expand Up @@ -268,7 +268,7 @@
<property name="style"></property>
<property name="subclass">; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
<property name="tooltip">This will place only (and only) footprints from copies of the same sheet as is the currently selected one in. Once the sheet selection is ready, plugin figures out which Footprints it needs to place and sort these footprint by the reference number.</property>
<property name="validator_data_type"></property>
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
Expand Down
20 changes: 13 additions & 7 deletions place_footprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def __init__(self, board):
pass

def parse_schematic_files(self, filename, dict_of_sheets):
with open(filename) as f:
logger.info(f'Parsing: {filename}')
with open(filename, encoding='utf-8') as f:
contents = f.read().split("\n")
filename_dir = os.path.dirname(filename)
# find (sheet (at and then look in next few lines for new schematics file
for i in range(len(contents)):
line = contents[i]
Expand All @@ -192,7 +192,8 @@ def parse_schematic_files(self, filename, dict_of_sheets):
sheet_id = ""
sn_found = False
sf_found = False
for j in range(i, i + 10):
for j in range(i,i+10):
line_con = contents[j]
if "(uuid " in contents[j]:
path = contents[j].replace("(uuid ", '').rstrip(")").upper().strip()
sheet_id = path.replace('00000000-0000-0000-0000-0000', '')
Expand All @@ -215,12 +216,17 @@ def parse_schematic_files(self, filename, dict_of_sheets):
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')
f'in {filename} line:{str(i)}. Unsupported schematics file format')

sheetfilepath = os.path.join(filename_dir, sheetfile)
# here I should find all sheet data
dict_of_sheets[sheet_id] = [sheetname, sheetfile]
dict_of_sheets[sheet_id] = [sheetname, sheetfilepath]
# test if newfound file can be opened
if not os.path.exists(sheetfilepath):
raise LookupError(f'File {sheetfilepath} does not exists. This is either due to error in parsing'
f' schematics files, missing schematics file or an error within the schematics')
# open a newfound file and look for nested sheets
logger.info(f'Trying to parse: {sheetfile}, reference for which was found on line {i}')
self.parse_schematic_files(sheetfile, dict_of_sheets)
self.parse_schematic_files(sheetfilepath, dict_of_sheets)
return

def get_list_of_footprints_with_same_id(self, fp_id):
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.2
2.0.3

0 comments on commit 69db95c

Please sign in to comment.