[Position] Added support for sub-PCBs

This commit is contained in:
Salvador E. Tropea 2022-12-26 13:40:47 -03:00
parent 89be5dacdd
commit 7760019bf0
3 changed files with 41 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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