diff --git a/CHANGELOG.md b/CHANGELOG.md index 348d0fb9..7fb0b01c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/docs/samples/generic_plot.kibot.yaml b/docs/samples/generic_plot.kibot.yaml index 9cb68218..766bf4b3 100644 --- a/docs/samples/generic_plot.kibot.yaml +++ b/docs/samples/generic_plot.kibot.yaml @@ -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 diff --git a/docs/source/configuration/outputs/pcb_print.rst b/docs/source/configuration/outputs/pcb_print.rst index 16405d90..93254e1f 100644 --- a/docs/source/configuration/outputs/pcb_print.rst +++ b/docs/source/configuration/outputs/pcb_print.rst @@ -65,6 +65,8 @@ Parameters: - ``holes_color`` :index:`: ` [string='#000000'] Color used for the holes when `colored_holes` is enabled. - ``line_width`` :index:`: ` [number=0.1] [0.02,2] For objects without width [mm] (KiCad 5). - ``mirror`` :index:`: ` [boolean=false] Print mirrored (X axis inverted). + - ``mirror_footprint_text`` :index:`: ` [boolean=true] Mirror text in the footprints when mirror option is enabled and we plot a user layer. + - ``mirror_pcb_text`` :index:`: ` [boolean=true] Mirror text in the PCB when mirror option is enabled and we plot a user layer. - ``monochrome`` :index:`: ` [boolean=false] Print in gray scale. - ``negative_plot`` :index:`: ` [boolean=false] Invert black and white. Only useful for a single layer. - ``page_id`` :index:`: ` [string='%02d'] Text to differentiate the pages. Use %d (like in C) to get the page number. diff --git a/kibot/out_pcb_print.py b/kibot/out_pcb_print.py index 548cd78b..24c4e05a 100644 --- a/kibot/out_pcb_print.py +++ b/kibot/out_pcb_print.py @@ -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 @@ -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 @@ -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)) @@ -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)