Skip to content

Commit

Permalink
[PCB Print][Added] Options to mirror the text
Browse files Browse the repository at this point in the history
In the user layers when creating a mirrored page

Closes #561
  • Loading branch information
set-soft committed Jan 18, 2024
1 parent c04067d commit c04f7e5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Expand text variables and KiBot %X markers in text objects (see #497)
- PCB Print:
- Support for CURRENT_DATE text variable
- Options to mirror the text in the user layers when creating a mirrored page
(#561)
- Populate:
- Basic support for regular list items (#480)
- Position:
Expand Down
4 changes: 4 additions & 0 deletions docs/samples/generic_plot.kibot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,10 @@ outputs:
line_width: 0.1
# [boolean=false] Print mirrored (X axis inverted)
mirror: false
# [boolean=true] Mirror text in the footprints when mirror option is enabled and we plot a user layer
mirror_footprint_text: true
# [boolean=true] Mirror text in the PCB when mirror option is enabled and we plot a user layer
mirror_pcb_text: true
# [boolean=false] Print in gray scale
monochrome: false
# [boolean=false] Invert black and white. Only useful for a single layer
Expand Down
2 changes: 2 additions & 0 deletions docs/source/configuration/outputs/pcb_print.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Parameters:
- ``holes_color`` :index:`: <pair: output - pcb_print - options - pages; holes_color>` [string='#000000'] Color used for the holes when `colored_holes` is enabled.
- ``line_width`` :index:`: <pair: output - pcb_print - options - pages; line_width>` [number=0.1] [0.02,2] For objects without width [mm] (KiCad 5).
- ``mirror`` :index:`: <pair: output - pcb_print - options - pages; mirror>` [boolean=false] Print mirrored (X axis inverted).
- ``mirror_footprint_text`` :index:`: <pair: output - pcb_print - options - pages; mirror_footprint_text>` [boolean=true] Mirror text in the footprints when mirror option is enabled and we plot a user layer.
- ``mirror_pcb_text`` :index:`: <pair: output - pcb_print - options - pages; mirror_pcb_text>` [boolean=true] Mirror text in the PCB when mirror option is enabled and we plot a user layer.
- ``monochrome`` :index:`: <pair: output - pcb_print - options - pages; monochrome>` [boolean=false] Print in gray scale.
- ``negative_plot`` :index:`: <pair: output - pcb_print - options - pages; negative_plot>` [boolean=false] Invert black and white. Only useful for a single layer.
- ``page_id`` :index:`: <pair: output - pcb_print - options - pages; page_id>` [string='%02d'] Text to differentiate the pages. Use %d (like in C) to get the page number.
Expand Down
36 changes: 36 additions & 0 deletions kibot/out_pcb_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def __init__(self):
with document:
self.mirror = False
""" Print mirrored (X axis inverted) """
self.mirror_pcb_text = True
""" Mirror text in the PCB when mirror option is enabled and we plot a user layer """
self.mirror_footprint_text = True
""" Mirror text in the footprints when mirror option is enabled and we plot a user layer """
self.monochrome = False
""" Print in gray scale """
self.scaling = None
Expand Down Expand Up @@ -1083,6 +1087,33 @@ def check_ki7_scale_issue(self):
return False
return True

def mirror_text(self, page, id):
""" Mirror text in the user layers """
if not page.mirror:
return
extra_debug = GS.debug_level > 2
if extra_debug:
logger.debug('mirror_text processing')
if page.mirror_pcb_text:
for g in GS.board.GetDrawings():
if g.GetLayer() == id:
if hasattr(g, 'GetShownText'):
if extra_debug:
logger.debug(f'- {g.GetClass()} {g.GetShownText()} @ {g.GetCenter()} mirrored: {g.IsMirrored()}'
f' just: {g.GetHorizJustify()}')
g.SetMirrored(not g.IsMirrored())
g.SetHorizJustify(-g.GetHorizJustify())
if page.mirror_footprint_text:
for m in GS.get_modules():
for g in m.GraphicalItems():
if g.GetLayer() == id:
if hasattr(g, 'GetShownText'):
if extra_debug:
logger.debug(f'- {g.GetClass()} {g.GetShownText()} @ {g.GetCenter()}'
f' mirrored: {g.IsMirrored()} just: {g.GetHorizJustify()}')
g.SetMirrored(not g.IsMirrored())
g.SetHorizJustify(-g.GetHorizJustify())

def generate_output(self, output):
self.check_tools()
# Avoid KiCad 5 complaining about fake vias diameter == drill == 0
Expand Down Expand Up @@ -1176,6 +1207,7 @@ def generate_output(self, output):
filelist = []
if self.force_edge_cuts and next(filter(lambda x: x._id == edge_id, p.layers), None) is None:
p.layers.append(edge_layer)
user_layer_ids = set(Layer._get_user().values())
for la in p.layers:
id = la._id
logger.debug('- Plotting layer {} ({})'.format(la.layer, id))
Expand All @@ -1185,8 +1217,12 @@ def generate_output(self, output):
# Avoid holes on non-copper layers
po.SetDrillMarksType(self.drill_marks if IsCopperLayer(id) else 0)
pc.SetLayer(id)
if id in user_layer_ids:
self.mirror_text(p, id)
pc.OpenPlotfile(la.suffix, PLOT_FORMAT_SVG, p.sheet)
pc.PlotLayer()
if id in user_layer_ids:
self.mirror_text(p, id)
pc.ClosePlot()
filelist.append((pc.GetPlotFileName(), la.color))
self.plot_extra_cu(id, la, pc, p, filelist)
Expand Down

0 comments on commit c04f7e5

Please sign in to comment.