|
8 | 8 |
|
9 | 9 | import pcbnew
|
10 | 10 | import wx
|
11 |
| -from typing import Dict |
12 | 11 |
|
13 | 12 | import dialog.settings_dialog as dialog
|
14 | 13 | import units
|
@@ -50,13 +49,43 @@ def logwarn(msg):
|
50 | 49 | logger.warn(msg)
|
51 | 50 |
|
52 | 51 |
|
53 |
| -def generate_bom(pcb, config, extra_fields, filter_layer=None): |
| 52 | +def skip_component(m, config, extra_data, filter_layer): |
| 53 | + # type: (pcbnew.MODULE, Config, dict, int) -> bool |
| 54 | + # filter part by layer |
| 55 | + if filter_layer is not None and filter_layer != m.GetLayer(): |
| 56 | + return True |
| 57 | + |
| 58 | + # skip blacklisted components |
| 59 | + ref = m.GetReference() |
| 60 | + ref_prefix = re.findall('^[A-Z]*', ref)[0] |
| 61 | + if ref in config.component_blacklist: |
| 62 | + return True |
| 63 | + if ref_prefix + '*' in config.component_blacklist: |
| 64 | + return True |
| 65 | + |
| 66 | + # skip components with dnp field not empty |
| 67 | + if config.dnp_field and ref in extra_data \ |
| 68 | + and config.dnp_field in extra_data[ref] \ |
| 69 | + and extra_data[ref][config.dnp_field]: |
| 70 | + return True |
| 71 | + |
| 72 | + # skip components with wrong variant field |
| 73 | + if config.board_variant_field and config.board_variants: |
| 74 | + if ref in extra_data: |
| 75 | + ref_variant = extra_data[ref][config.board_variant_field] |
| 76 | + if ref_variant not in config.board_variants: |
| 77 | + return True |
| 78 | + |
| 79 | + return False |
| 80 | + |
| 81 | + |
| 82 | +def generate_bom(pcb, config, extra_data, filter_layer=None): |
54 | 83 | # type: (pcbnew.BOARD, Config, Dict[str, dict], int) -> list
|
55 | 84 | """
|
56 | 85 | Generate BOM from pcb layout.
|
57 | 86 | :param pcb: pcbnew BOARD object
|
58 | 87 | :param config: Config object
|
59 |
| - :param extra_fields: Extra fields data |
| 88 | + :param extra_data: Extra fields data |
60 | 89 | :param filter_layer: include only parts for given layer
|
61 | 90 | :return: BOM table (qty, value, footprint, refs)
|
62 | 91 | """
|
@@ -84,22 +113,7 @@ def natural_sort(l):
|
84 | 113 | # build grouped part list
|
85 | 114 | part_groups = {}
|
86 | 115 | for m in pcb.GetModules():
|
87 |
| - # filter part by layer |
88 |
| - if filter_layer is not None and filter_layer != m.GetLayer(): |
89 |
| - continue |
90 |
| - |
91 |
| - # skip blacklisted components |
92 |
| - ref = m.GetReference() |
93 |
| - ref_prefix = re.findall('^[A-Z]*', ref)[0] |
94 |
| - if ref in config.component_blacklist: |
95 |
| - continue |
96 |
| - if ref_prefix + '*' in config.component_blacklist: |
97 |
| - continue |
98 |
| - |
99 |
| - # skip components with dnp field not empty |
100 |
| - if config.dnp_field and ref in extra_fields \ |
101 |
| - and config.dnp_field in extra_fields[ref] \ |
102 |
| - and extra_fields[ref][config.dnp_field]: |
| 116 | + if skip_component(m, config, extra_data, filter_layer): |
103 | 117 | continue
|
104 | 118 |
|
105 | 119 | # group part refs by value and footprint
|
@@ -581,7 +595,8 @@ def Run(self):
|
581 | 595 | import argparse
|
582 | 596 |
|
583 | 597 | parser = argparse.ArgumentParser(
|
584 |
| - description='KiCad PCB pick and place assistant') |
| 598 | + description='KiCad PCB pick and place assistant', |
| 599 | + formatter_class=argparse.ArgumentDefaultsHelpFormatter) |
585 | 600 | parser.add_argument('file', type=str, help="KiCad PCB file")
|
586 | 601 | config = Config()
|
587 | 602 | config.add_options(parser)
|
|
0 commit comments