Moved the dril_marks attribute to a separated class.

Reused by 5 output classes.
This commit is contained in:
Salvador E. Tropea 2020-06-29 20:10:40 -03:00
parent 3c6f4950c7
commit 60a2649c0f
8 changed files with 72 additions and 101 deletions

View File

@ -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.

32
kiplot/drill_marks.py Normal file
View File

@ -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]

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)