[Populate] Added support for sub-PCBs

- Fixed problems when using variants and sub-PCBs, some changes
  reverted during separation.
This commit is contained in:
Salvador E. Tropea 2022-12-26 13:04:49 -03:00
parent dad174bfd3
commit 89be5dacdd
4 changed files with 86 additions and 3 deletions

View File

@ -717,7 +717,14 @@ class VariantOptions(BaseOptions):
def apply_sub_pcb(self):
with TemporaryDirectory(prefix='kibot-separate') as d:
dest = os.path.join(d, os.path.basename(GS.pcb_file))
self._sub_pcb.load_board(dest)
# Save the current PCB, with any changes applied
with NamedTemporaryFile(mode='w', suffix='.kicad_pcb', delete=False) as f:
pcb_file = f.name
GS.board.Save(pcb_file)
# Now do the separation
self._sub_pcb.load_board(pcb_file, dest)
# Remove the temporal PCB
os.remove(pcb_file)
def will_filter_pcb_components(self):
""" True if we will apply filters/variants """

View File

@ -252,6 +252,7 @@ class Render3DOptions(Base3DOptions):
if self._show_all_components:
# Don't change anything
return
logger.debug('Applying components list ...')
# The user specified a list of components, we must remove the rest
if not self._comps:
# No variant or filter applied
@ -266,6 +267,7 @@ class Render3DOptions(Base3DOptions):
if c.ref not in show_components and c.fitted:
c.fitted = False
self.undo_show.add(c.ref)
logger.debugl(2, '- Removing '+c.ref)
def undo_show_components(self):
if self._show_all_components:

View File

@ -66,11 +66,11 @@ class SubPCBOptions(PanelOptions):
return "annotation; ref: {}".format(self.reference)
return "rectangle; tlx: {}; tly: {}; brx: {}; bry: {}".format(self.tlx, self.tly, self.brx, self.bry)
def load_board(self, dest):
def load_board(self, pcb_file, dest):
# Make sure kikit is available
command = GS.ensure_tool('global', 'KiKit')
# Execute the separate
cmd = [command, 'separate', '-s', self.get_separate_source(), GS.pcb_file, dest]
cmd = [command, 'separate', '-s', self.get_separate_source(), pcb_file, dest]
run_command(cmd)
# Load this board
GS.board = None

View File

@ -0,0 +1,74 @@
kiplot:
version: 1
import:
- file: battery_pack_sub_pcbs.kibot.yaml
global:
solder_mask_color: blue
pcb_finish: ENIG
filters:
- name: all_smd
type: generic
exclude_smd: true
invert: true
- name: all_front
type: generic
exclude_bottom: true
- name: all_back
type: generic
exclude_top: true
- name: all_tht
type: generic
exclude_tht: true
invert: true
- name: all_conn
type: generic
exclude_any:
- field: Value
regex: '.*CONN.*'
- field: Value
regex: 'SERVO.*'
- field: Reference
regex: 'JP.*'
- field: Reference
regex: 'U.*'
invert: true
outputs:
- name: PcbDraw
comment: "How to draw a step"
type: pcbdraw
run_by_default: false
options:
format: png
- name: KiCad_3D
comment: "How to draw a step"
type: render_3d
run_by_default: false
options:
width: 1280
height: 960
orthographic: true
zoom: 4
ray_tracing: true
background1: "#DAF1FF"
auto_crop: true
# transparent_background: true
# transparent_background_color: "#00FF00"
# transparent_background_fuzz: 15
- name: Populate
comment: "Populate example"
type: populate
dir: PopulateWithFilter
options:
renderer: KiCad_3D
input: tests/data/with_filter_html.md