Skip to content

Commit a78e16f

Browse files
committed
[KiCad 10 Variants][Added] Some basic support to VARIANT*
- To the "pcb_print" output - The variables are expanded inside the worksheet and in worksheet fields - They also work in the PCB See #906
1 parent b6ba622 commit a78e16f

19 files changed

Lines changed: 1446 additions & 2 deletions

kibot/gs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ def expand_text_variables(text, extra_vars=None):
546546
value = os.environ.get(vname, None)
547547
if value is None:
548548
value = '${'+vname+'}'
549-
logger.warning(W_UNKVAR+"Unknown text variable `{}`".format(vname))
549+
if vname not in {'VARIANT', 'VARIANT_DESC'}: # These are dynamic
550+
logger.warning(W_UNKVAR+"Unknown text variable `{}`".format(vname))
550551
if match.start():
551552
new_text += text[last:match.start()]
552553
new_text += value

kibot/kiplot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ def get_board_comps_data(comps, kicad_variant=None):
581581
# We have pad a valid pad, assume this is all SMD and keep looking
582582
c.smd = True
583583
if kicad_variant is not None:
584+
logger.debug(f"Switching the PCB to {old_variant}")
584585
GS.board.SetCurrentVariant(old_variant)
585586

586587

kibot/out_base.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,19 @@ def load_list_components(self, forced=False):
11671167

11681168
def run(self, output_dir):
11691169
self.load_list_components()
1170+
variant = self.variant or GS.solved_global_variant
1171+
if variant:
1172+
GS.pro_variables['VARIANT'] = variant.name
1173+
GS.pro_variables['VARIANT_DESC'] = variant.comment
1174+
if GS.ki10 and variant.type == 'kicad' and GS.board:
1175+
logger.debug(f"Switching the PCB to {variant.name}")
1176+
GS.board.SetCurrentVariant(variant.name)
1177+
else:
1178+
# KiCad 10 behavior when "Default" variant is selected
1179+
GS.pro_variables['VARIANT'] = GS.pro_variables['VARIANT_DESC'] = ""
1180+
if GS.ki10 and GS.board:
1181+
logger.debug("Switching the PCB to 'Default' variant")
1182+
GS.board.SetCurrentVariant('')
11701183

11711184
# The following 5 members are used by 2D and 3D renderers
11721185
def setup_renderer(self, components, active_components):

kibot/out_pcb_print.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,14 @@ def fill_kicad_vars(self, page, pages, p):
660660
vars['SHEETPATH'] = '' # Only relevant for an schematic
661661
vars['LAYER'] = p.layer_var
662662
vars['PAPER'] = self.pcb.paper
663-
return vars
663+
if self.variant:
664+
vars['VARIANT'] = self.variant.name
665+
vars['VARIANT_DESC'] = self.variant.comment
666+
logger.debug(f"Defining the VARIANT* text variable using {self.variant}")
667+
else:
668+
vars['VARIANT'] = vars['VARIANT_DESC'] = ''
669+
# Solve the dynamic ${VARIANT}
670+
return {k: GS.expand_text_variables(v, vars) for k, v in vars.items()}
664671

665672
def plot_frame_internal(self, pc, po, p, page, pages):
666673
""" Here we plot the frame manually """
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
(kicad_pcb
2+
(version 20260206)
3+
(generator "pcbnew")
4+
(generator_version "10.0")
5+
(general
6+
(thickness 1.6)
7+
(legacy_teardrops no)
8+
)
9+
(paper "A4")
10+
(title_block
11+
(title "${VARIANT}")
12+
(comment 1 "${VARIANT_DESC}")
13+
)
14+
(layers
15+
(0 "F.Cu" signal)
16+
(2 "B.Cu" signal)
17+
(9 "F.Adhes" user "F.Adhesive")
18+
(11 "B.Adhes" user "B.Adhesive")
19+
(13 "F.Paste" user)
20+
(15 "B.Paste" user)
21+
(5 "F.SilkS" user "F.Silkscreen")
22+
(7 "B.SilkS" user "B.Silkscreen")
23+
(1 "F.Mask" user)
24+
(3 "B.Mask" user)
25+
(17 "Dwgs.User" user "User.Drawings")
26+
(19 "Cmts.User" user "User.Comments")
27+
(21 "Eco1.User" user "User.Eco1")
28+
(23 "Eco2.User" user "User.Eco2")
29+
(25 "Edge.Cuts" user)
30+
(27 "Margin" user)
31+
(31 "F.CrtYd" user "F.Courtyard")
32+
(29 "B.CrtYd" user "B.Courtyard")
33+
(35 "F.Fab" user)
34+
(33 "B.Fab" user)
35+
(39 "User.1" user)
36+
(41 "User.2" user)
37+
(43 "User.3" user)
38+
(45 "User.4" user)
39+
(47 "User.5" user)
40+
(49 "User.6" user)
41+
(51 "User.7" user)
42+
(53 "User.8" user)
43+
(55 "User.9" user)
44+
)
45+
(setup
46+
(pad_to_mask_clearance 0)
47+
(allow_soldermask_bridges_in_footprints no)
48+
(tenting
49+
(front yes)
50+
(back yes)
51+
)
52+
(covering
53+
(front no)
54+
(back no)
55+
)
56+
(plugging
57+
(front no)
58+
(back no)
59+
)
60+
(capping no)
61+
(filling no)
62+
(pcbplotparams
63+
(layerselection 0x00000000_00000000_55555555_5755f5ff)
64+
(plot_on_all_layers_selection 0x00000000_00000000_00000000_00000000)
65+
(disableapertmacros no)
66+
(usegerberextensions no)
67+
(usegerberattributes yes)
68+
(usegerberadvancedattributes yes)
69+
(creategerberjobfile yes)
70+
(dashed_line_dash_ratio 12)
71+
(dashed_line_gap_ratio 3)
72+
(svgprecision 4)
73+
(plotframeref no)
74+
(mode 1)
75+
(useauxorigin no)
76+
(pdf_front_fp_property_popups yes)
77+
(pdf_back_fp_property_popups yes)
78+
(pdf_metadata yes)
79+
(pdf_single_document no)
80+
(dxfpolygonmode yes)
81+
(dxfimperialunits yes)
82+
(dxfusepcbnewfont yes)
83+
(psnegative no)
84+
(psa4output no)
85+
(plot_black_and_white yes)
86+
(sketchpadsonfab no)
87+
(plotpadnumbers no)
88+
(hidednponfab no)
89+
(sketchdnponfab yes)
90+
(crossoutdnponfab yes)
91+
(subtractmaskfromsilk no)
92+
(outputformat 1)
93+
(mirror no)
94+
(drillshape 1)
95+
(scaleselection 1)
96+
(outputdirectory "")
97+
)
98+
)
99+
(variants
100+
(variant
101+
(name "development")
102+
(description "Development variant")
103+
)
104+
(variant
105+
(name "production")
106+
(description "Production variant")
107+
)
108+
)
109+
(gr_rect
110+
(start 134.64 59.67)
111+
(end 153.37 65.97)
112+
(stroke
113+
(width 0.05)
114+
(type default)
115+
)
116+
(fill no)
117+
(layer "Edge.Cuts")
118+
(uuid "16bd1f8d-3452-445f-b270-4eca916f450d")
119+
)
120+
(gr_text "${VARIANT}"
121+
(at 137.79 62.53 0)
122+
(layer "F.Cu")
123+
(uuid "a38bf4b7-6306-4054-a57e-a2b7e219f6f1")
124+
(effects
125+
(font
126+
(size 1.5 1.5)
127+
(thickness 0.3)
128+
(bold yes)
129+
)
130+
(justify left bottom)
131+
)
132+
)
133+
(gr_text "${VARIANT_DESC}"
134+
(at 137.45 65.3 0)
135+
(layer "F.SilkS")
136+
(uuid "797b4e6f-ebee-4550-a66b-18781c18268f")
137+
(effects
138+
(font
139+
(size 1 1)
140+
(thickness 0.1)
141+
)
142+
(justify left bottom)
143+
)
144+
)
145+
(embedded_fonts no)
146+
(embedded_files
147+
(file
148+
(name "variant_var.kicad_wks")
149+
(type worksheet)
150+
(data |KLUv/WA5CfUUANbdXiEAtxsWHGS5ac4JWlhdTV1ADhVltCCdFsc54zb0/38BIAJVAE0AWQCPPxL/
151+
x2PzpH2tJ3sj5zsuFjBqzf58aEl+rVjALNp+suWX/AkAQIAUvZfTYlScKuO3oXNEsuqM38t+3UMA
152+
BAoLSulVZ+2LbZl9RAAEyhCJE3qgDRECf3GHNla7xGRFq/6S//fYvLDaEzOVMnjte056zn4zBl/s
153+
2bMKgVj82sW33/75Dq8IZ6+r/uvjiMHatcPriKsnpf3Z+7Kq2kfvPuh5xB+Xk+VCEX+NqBXLxm0a
154+
DTNyzGJRtYRaiGZM6uC0B6cNneoq2YbJNKgBZmE9KWVYiVYsUlqXPThahuM21KAb/t4j52zK/tfB
155+
NnXslyIQVptmpor1/L5v0gsQCIFComKMq16Iyrhoos6LdhWNYroeOWLHrJtKdqFYHIpIl106TYtw
156+
i8VlIShZRZtsEAsBrei9bYU1qTbptk5821Ua2n73Dyc4pAThVvV7Y8adzk56F4x2yQKAgKARQYYU
157+
mhopSFLIMAeARKTmqDqUaDDAcOWIIIoJCEAecpszKGXvooqHvkhFQiG28uvJM4eHQAh+709Se2SN
158+
7fZmG2qbN/1QC5OEnj8ZW3lkLDPwAUK2Oq0TU672a4nDEjmEFWhklqn0WFP67FIvkQYbw2kO4q6/
159+
qnWHAldYseSqixd3LE/J8NeCQI9DAc/eEQ56ASaz3qSVl0iGfyoHi20cwRsYNqCHjWUKPgIRIRMZ
160+
ml8MJWGBXuZN8Fk8JDGNHD6J7nSKOp9OnHub7M4WY9jDfxY4UCDLPHrUDohbmNiJcBAR7RFexSHX
161+
AgS3v8mzU7ToWk28KOCM2sWSXyLaQydtQvsmK0YepdjxERvjpVJ6VyjsER/x3hc6hGF89Co=|
162+
)
163+
(checksum "F47E35086DF2D1FFFBB7A2664A356353")
164+
)
165+
)
166+
)

0 commit comments

Comments
 (0)