diff --git a/kibot/out_base.py b/kibot/out_base.py index b11d5ad0..382d80a9 100644 --- a/kibot/out_base.py +++ b/kibot/out_base.py @@ -721,10 +721,29 @@ class VariantOptions(BaseOptions): with NamedTemporaryFile(mode='w', suffix='.kicad_pcb', delete=False) as f: pcb_file = f.name GS.board.Save(pcb_file) + if self._comps: + # Memorize the used modules + old_modules = {m.GetReference() for m in GS.get_modules()} # Now do the separation self._sub_pcb.load_board(pcb_file, dest) # Remove the temporal PCB os.remove(pcb_file) + # Compute the modules we removed + self._excl_by_sub_pcb = set() + # Now reflect it in the list of components + if self._comps: + logger.debug('Removing components outside the sub-PCB') + # Memorize the used modules + new_modules = {m.GetReference() for m in GS.get_modules()} + diff = old_modules - new_modules + logger.debugl(3, diff) + # Exclude them from _comps + for c in diff: + cmp = self.comps_hash[c] + if cmp.included: + cmp.included = False + self._excl_by_sub_pcb.add(c) + logger.debugl(2, '- Removing '+c) def will_filter_pcb_components(self): """ True if we will apply filters/variants """ @@ -763,6 +782,8 @@ class VariantOptions(BaseOptions): # Undo the sub-PCB: just reload the PCB GS.board = None load_board() + for c in self._excl_by_sub_pcb: + self.comps_hash[c].included = True return if do_2D: self.uncross_modules(board, self.comps_hash) diff --git a/kibot/out_position.py b/kibot/out_position.py index 7cd61928..85ef8946 100644 --- a/kibot/out_position.py +++ b/kibot/out_position.py @@ -222,6 +222,7 @@ class PositionOptions(VariantOptions): def run(self, fname): super().run(fname) + self.filter_pcb_components(GS.board) output_dir = os.path.dirname(fname) columns = self.columns.values() conv = GS.unit_name_to_scale_factor(self.units) @@ -303,6 +304,7 @@ class PositionOptions(VariantOptions): self._do_position_plot_ascii(output_dir, columns, modules, maxlengths, modules_side) else: # if self.format == 'CSV': self._do_position_plot_csv(output_dir, columns, modules, modules_side) + self.unfilter_pcb_components(GS.board) @output_class diff --git a/tests/yaml_samples/position_sub_pcb_bp.kibot.yaml b/tests/yaml_samples/position_sub_pcb_bp.kibot.yaml new file mode 100644 index 00000000..25295ded --- /dev/null +++ b/tests/yaml_samples/position_sub_pcb_bp.kibot.yaml @@ -0,0 +1,18 @@ +# Example KiBot config file for a basic 2-layer board +kibot: + version: 1 + +import: + - file: battery_pack_sub_pcbs.kibot.yaml + +outputs: + + - name: 'position' + comment: "Pick and place file" + type: position + dir: positiondir + options: + format: ASCII # CSV or ASCII format + units: millimeters # millimeters or inches + separate_files_for_front_and_back: false + only_smd: false