From 60a2649c0f7ea5e267da83bc2f03817fe34cdfe9 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 29 Jun 2020 20:10:40 -0300 Subject: [PATCH] Moved the dril_marks attribute to a separated class. Reused by 5 output classes. --- README.md | 2 +- kiplot/drill_marks.py | 32 ++++++++++++++++++++++++++++++++ kiplot/out_any_layer.py | 6 ------ kiplot/out_dxf.py | 27 ++++++++------------------- kiplot/out_hpgl.py | 27 ++++++++------------------- kiplot/out_pdf.py | 27 ++++++++------------------- kiplot/out_ps.py | 25 +++++++------------------ kiplot/out_svg.py | 27 ++++++++------------------- 8 files changed, 72 insertions(+), 101 deletions(-) create mode 100644 kiplot/drill_marks.py diff --git a/README.md b/README.md index 538b4431..abd4c30d 100644 --- a/README.md +++ b/README.md @@ -199,7 +199,7 @@ Most options are the same you'll find in the KiCad dialogs. * Description: Exports the PCB to 2D mechanical EDA tools (like AutoCAD). This output is what you get from the File/Plot menu in pcbnew. * Options: - - `drill_marks`: [string='full'] drill_marks what to use to indicate the drill places, can be none, small or full (for real scale). + - `drill_marks`: [string='full'] what to use to indicate the drill places, can be none, small or full (for real scale). - `exclude_edge_layer`: [boolean=true] do not include the PCB edge layer. - `exclude_pads_from_silkscreen`: [boolean=false] do not plot the component pads in the silk screen. - `force_plot_invisible_refs_vals`: [boolean=false] include references and values even when they are marked as invisible. diff --git a/kiplot/drill_marks.py b/kiplot/drill_marks.py new file mode 100644 index 00000000..ecdfed4c --- /dev/null +++ b/kiplot/drill_marks.py @@ -0,0 +1,32 @@ +from pcbnew import (PCB_PLOT_PARAMS) +from .error import KiPlotConfigurationError +from kiplot.macros import macros, document, output_class # noqa: F401 + + +class DrillMarks(object): + """ This class provides the drill_marks attribute. + Used by DXF, HPGL, PDF, PS and SVG formats. """ + # Mappings to KiCad values + _drill_marks_map = { + 'none': PCB_PLOT_PARAMS.NO_DRILL_SHAPE, + 'small': PCB_PLOT_PARAMS.SMALL_DRILL_SHAPE, + 'full': PCB_PLOT_PARAMS.FULL_DRILL_SHAPE, + } + + def __init__(self): + with document: + self._drill_marks = 'full' + """ what to use to indicate the drill places, can be none, small or full (for real scale) """ # pragma: no cover + + @property + def drill_marks(self): + return self._drill_marks + + @drill_marks.setter + def drill_marks(self, val): + if val not in self._drill_marks_map: + raise KiPlotConfigurationError("Unknown drill mark type: {}".format(val)) + self._drill_marks = val + + def config(self): + self._drill_marks = DrillMarks._drill_marks_map[self._drill_marks] diff --git a/kiplot/out_any_layer.py b/kiplot/out_any_layer.py index 2de03402..96be0ae7 100644 --- a/kiplot/out_any_layer.py +++ b/kiplot/out_any_layer.py @@ -29,12 +29,6 @@ class AnyLayer(BaseOutput): """ include references and values even when they are marked as invisible """ self.tent_vias = True """ cover the vias """ # pragma: no cover - # Mappings to KiCad values - self._drill_marks_map = { - 'none': PCB_PLOT_PARAMS.NO_DRILL_SHAPE, - 'small': PCB_PLOT_PARAMS.SMALL_DRILL_SHAPE, - 'full': PCB_PLOT_PARAMS.FULL_DRILL_SHAPE, - } def config(self, outdir, options, layers): super().config(outdir, options, layers) diff --git a/kiplot/out_dxf.py b/kiplot/out_dxf.py index 7fe0b3c8..613d29dd 100644 --- a/kiplot/out_dxf.py +++ b/kiplot/out_dxf.py @@ -1,43 +1,32 @@ from pcbnew import PLOT_FORMAT_DXF -from .error import KiPlotConfigurationError -from .out_any_layer import (AnyLayer) +from kiplot.out_any_layer import AnyLayer +from kiplot.drill_marks import DrillMarks from kiplot.macros import macros, document, output_class # noqa: F401 @output_class -class DXF(AnyLayer): +class DXF(AnyLayer, DrillMarks): """ DXF (Drawing Exchange Format) Exports the PCB to 2D mechanical EDA tools (like AutoCAD). This output is what you get from the File/Plot menu in pcbnew. """ def __init__(self, name, type, description): - super(DXF, self).__init__(name, type, description) + AnyLayer.__init__(self, name, type, description) + DrillMarks.__init__(self) self._plot_format = PLOT_FORMAT_DXF # Options with document: self.use_aux_axis_as_origin = False """ use the auxiliar axis as origin for coordinates """ - self._drill_marks = 'full' - """ drill_marks what to use to indicate the drill places, can be none, small or full (for real scale) """ self.polygon_mode = True """ plot using the contour, instead of the center line """ self.sketch_plot = False """ don't fill objects, just draw the outline """ # pragma: no cover - @property - def drill_marks(self): - return self._drill_marks - - @drill_marks.setter - def drill_marks(self, val): - if val not in self._drill_marks_map: - raise KiPlotConfigurationError("Unknown drill mark type: {}".format(val)) - self._drill_marks = val - def config(self, outdir, options, layers): - super().config(outdir, options, layers) - self._drill_marks = self._drill_marks_map[self._drill_marks] + AnyLayer.config(self, outdir, options, layers) + DrillMarks.config(self) def _configure_plot_ctrl(self, po, output_dir): - super()._configure_plot_ctrl(po, output_dir) + AnyLayer._configure_plot_ctrl(self, po, output_dir) po.SetDXFPlotPolygonMode(self.polygon_mode) diff --git a/kiplot/out_hpgl.py b/kiplot/out_hpgl.py index f0574599..d525f7ee 100644 --- a/kiplot/out_hpgl.py +++ b/kiplot/out_hpgl.py @@ -1,16 +1,17 @@ -from pcbnew import (PLOT_FORMAT_HPGL) -from .out_any_layer import (AnyLayer) -from .error import KiPlotConfigurationError +from pcbnew import PLOT_FORMAT_HPGL +from kiplot.out_any_layer import AnyLayer +from kiplot.drill_marks import DrillMarks from kiplot.macros import macros, document, output_class # noqa: F401 @output_class -class HPGL(AnyLayer): +class HPGL(AnyLayer, DrillMarks): """ HPGL (Hewlett & Packard Graphics Language) Exports the PCB for plotters and laser printers. This output is what you get from the File/Plot menu in pcbnew. """ def __init__(self, name, type, description): - super(HPGL, self).__init__(name, type, description) + AnyLayer.__init__(self, name, type, description) + DrillMarks.__init__(self) self._plot_format = PLOT_FORMAT_HPGL # Options with document: @@ -20,24 +21,12 @@ class HPGL(AnyLayer): """ don't fill objects, just draw the outline """ self.scaling = 0 """ scale factor (0 means autoscaling) """ - self._drill_marks = 'full' - """ what to use to indicate the drill places, can be none, small or full (for real scale) """ self.pen_width = 0.5 """ pen diameter in MILS, useful to fill areas. However, it is in mm in HPGL files """ # pragma: no cover - @property - def drill_marks(self): - return self._drill_marks - - @drill_marks.setter - def drill_marks(self, val): - if val not in self._drill_marks_map: - raise KiPlotConfigurationError("Unknown drill mark type: {}".format(val)) - self._drill_marks = val - def config(self, outdir, options, layers): - super().config(outdir, options, layers) - self._drill_marks = self._drill_marks_map[self._drill_marks] + AnyLayer.config(self, outdir, options, layers) + DrillMarks.config(self) def _configure_plot_ctrl(self, po, output_dir): super()._configure_plot_ctrl(po, output_dir) diff --git a/kiplot/out_pdf.py b/kiplot/out_pdf.py index 0da0cd29..20dd7b5c 100644 --- a/kiplot/out_pdf.py +++ b/kiplot/out_pdf.py @@ -1,17 +1,18 @@ from pcbnew import PLOT_FORMAT_PDF -from .out_any_layer import AnyLayer -from .error import KiPlotConfigurationError +from kiplot.out_any_layer import AnyLayer +from kiplot.drill_marks import DrillMarks from kiplot.macros import macros, document, output_class # noqa: F401 @output_class -class PDF(AnyLayer): +class PDF(AnyLayer, DrillMarks): """ PDF (Portable Document Format) Exports the PCB to the most common exhange format. Suitable for printing. Note that this output isn't the best for documating your project. This output is what you get from the File/Plot menu in pcbnew. """ def __init__(self, name, type, description): - super(PDF, self).__init__(name, type, description) + AnyLayer.__init__(self, name, type, description) + DrillMarks.__init__(self) self._plot_format = PLOT_FORMAT_PDF # Options with document: @@ -20,20 +21,8 @@ class PDF(AnyLayer): self.mirror_plot = False """ plot mirrored """ self.negative_plot = False - """ invert black and white """ - self._drill_marks = 'full' - """ what to use to indicate the drill places, can be none, small or full (for real scale) """ # pragma: no cover - - @property - def drill_marks(self): - return self._drill_marks - - @drill_marks.setter - def drill_marks(self, val): - if val not in self._drill_marks_map: - raise KiPlotConfigurationError("Unknown drill mark type: {}".format(val)) - self._drill_marks = val + """ invert black and white """ # pragma: no cover def config(self, outdir, options, layers): - super().config(outdir, options, layers) - self._drill_marks = self._drill_marks_map[self._drill_marks] + AnyLayer.config(self, outdir, options, layers) + DrillMarks.config(self) diff --git a/kiplot/out_ps.py b/kiplot/out_ps.py index 4838159f..230f0cd7 100644 --- a/kiplot/out_ps.py +++ b/kiplot/out_ps.py @@ -1,16 +1,17 @@ from pcbnew import PLOT_FORMAT_POST -from .out_any_layer import AnyLayer -from .error import KiPlotConfigurationError +from kiplot.out_any_layer import AnyLayer +from kiplot.drill_marks import DrillMarks from kiplot.macros import macros, document, output_class # noqa: F401 @output_class -class PS(AnyLayer): +class PS(AnyLayer, DrillMarks): """ PS (Postscript) Exports the PCB to a format suitable for printing. This output is what you get from the File/Plot menu in pcbnew. """ def __init__(self, name, type, description): - super(PS, self).__init__(name, type, description) + AnyLayer.__init__(self, name, type, description) + DrillMarks.__init__(self) self._plot_format = PLOT_FORMAT_POST # Options with document: @@ -24,8 +25,6 @@ class PS(AnyLayer): """ don't fill objects, just draw the outline """ self.scaling = 1 """ scale factor (0 means autoscaling)""" - self._drill_marks = 'full' - """ what to use to indicate the drill places, can be none, small or full (for real scale) """ self.scale_adjust_x = 1.0 """ fine grain adjust for the X scale (floating point multiplier) """ self.scale_adjust_y = 1.0 @@ -36,19 +35,9 @@ class PS(AnyLayer): self.a4_output = True """ force A4 paper size """ # pragma: no cover - @property - def drill_marks(self): - return self._drill_marks - - @drill_marks.setter - def drill_marks(self, val): - if val not in self._drill_marks_map: - raise KiPlotConfigurationError("Unknown drill mark type: {}".format(val)) - self._drill_marks = val - def config(self, outdir, options, layers): - super().config(outdir, options, layers) - self._drill_marks = self._drill_marks_map[self._drill_marks] + AnyLayer.config(self, outdir, options, layers) + DrillMarks.config(self) def _configure_plot_ctrl(self, po, output_dir): super()._configure_plot_ctrl(po, output_dir) diff --git a/kiplot/out_svg.py b/kiplot/out_svg.py index 96be5e3a..e25e1772 100644 --- a/kiplot/out_svg.py +++ b/kiplot/out_svg.py @@ -1,17 +1,18 @@ from pcbnew import PLOT_FORMAT_SVG -from .out_any_layer import AnyLayer -from .error import KiPlotConfigurationError +from kiplot.out_any_layer import AnyLayer +from kiplot.drill_marks import DrillMarks from kiplot.macros import macros, document, output_class # noqa: F401 @output_class -class SVG(AnyLayer): +class SVG(AnyLayer, DrillMarks): """ SVG (Scalable Vector Graphics) Exports the PCB to a format suitable for 2D graphics software. Unlike bitmaps SVG drawings can be scaled without losing resolution. This output is what you get from the File/Plot menu in pcbnew. """ def __init__(self, name, type, description): - super(SVG, self).__init__(name, type, description) + AnyLayer.__init__(self, name, type, description) + DrillMarks.__init__(self) self._plot_format = PLOT_FORMAT_SVG # Options with document: @@ -20,20 +21,8 @@ class SVG(AnyLayer): self.mirror_plot = False """ plot mirrored """ self.negative_plot = False - """ invert black and white """ - self._drill_marks = 'full' - """ what to use to indicate the drill places, can be none, small or full (for real scale) """ # pragma: no cover - - @property - def drill_marks(self): - return self._drill_marks - - @drill_marks.setter - def drill_marks(self, val): - if val not in self._drill_marks_map: - raise KiPlotConfigurationError("Unknown drill mark type: {}".format(val)) - self._drill_marks = val + """ invert black and white """ # pragma: no cover def config(self, outdir, options, layers): - super().config(outdir, options, layers) - self._drill_marks = self._drill_marks_map[self._drill_marks] + AnyLayer.config(self, outdir, options, layers) + DrillMarks.config(self)