Simplified the code that detects KiCad v6

This commit is contained in:
Diego Capusotto 2021-12-17 13:11:42 -03:00
parent 927ed3c99e
commit 6e5176b273
14 changed files with 33 additions and 35 deletions

View File

@ -73,7 +73,7 @@ logger = log.init()
from .docopt import docopt from .docopt import docopt
from .gs import (GS) from .gs import (GS)
from .misc import (NO_PCB_FILE, NO_SCH_FILE, EXIT_BAD_ARGS, W_VARSCH, W_VARCFG, W_VARPCB, NO_PCBNEW_MODULE, from .misc import (NO_PCB_FILE, NO_SCH_FILE, EXIT_BAD_ARGS, W_VARSCH, W_VARCFG, W_VARPCB, NO_PCBNEW_MODULE,
KICAD_VERSION_5_99, W_NOKIVER, hide_stderr) W_NOKIVER, hide_stderr)
from .pre_base import (BasePreFlight) from .pre_base import (BasePreFlight)
from .config_reader import (CfgYamlReader, print_outputs_help, print_output_help, print_preflights_help, create_example, from .config_reader import (CfgYamlReader, print_outputs_help, print_output_help, print_preflights_help, create_example,
print_filters_help) print_filters_help)
@ -249,7 +249,7 @@ def detect_kicad():
# KICAD_PATH isn't good on my system. # KICAD_PATH isn't good on my system.
# The kicad-nightly package overwrites the regular package!! # The kicad-nightly package overwrites the regular package!!
GS.kicad_share_path = '/usr/share/kicad' GS.kicad_share_path = '/usr/share/kicad'
if GS.kicad_version_n >= KICAD_VERSION_5_99: # pragma: no cover (Ki6) if GS.ki6(): # pragma: no cover (Ki6)
GS.kicad_conf_path = pcbnew.GetSettingsManager().GetUserSettingsPath() GS.kicad_conf_path = pcbnew.GetSettingsManager().GetUserSettingsPath()
if nightly: if nightly:
# Nightly Debian packages uses `/usr/share/kicad-nightly/kicad-nightly.env` as an environment extension # Nightly Debian packages uses `/usr/share/kicad-nightly/kicad-nightly.env` as an environment extension

View File

@ -138,7 +138,7 @@ class GS(object):
@staticmethod @staticmethod
def get_pcb_comment(title_block, num): def get_pcb_comment(title_block, num):
if GS.kicad_version_n >= KICAD_VERSION_5_99: # pragma: no cover (Ki6) if GS.ki6(): # pragma: no cover (Ki6)
# Backward compatibility ... what's this? # Backward compatibility ... what's this?
return title_block.GetComment(num) return title_block.GetComment(num)
if num == 1: if num == 1:
@ -151,13 +151,13 @@ class GS(object):
@staticmethod @staticmethod
def get_modules(): def get_modules():
if GS.kicad_version_n >= KICAD_VERSION_5_99: # pragma: no cover (Ki6) if GS.ki6(): # pragma: no cover (Ki6)
return GS.board.GetFootprints() return GS.board.GetFootprints()
return GS.board.GetModules() return GS.board.GetModules()
@staticmethod @staticmethod
def get_modules_board(board): def get_modules_board(board):
if GS.kicad_version_n >= KICAD_VERSION_5_99: # pragma: no cover (Ki6) if GS.ki6(): # pragma: no cover (Ki6)
return board.GetFootprints() return board.GetFootprints()
return board.GetModules() return board.GetModules()
@ -165,6 +165,10 @@ class GS(object):
def ki6(): def ki6():
return GS.kicad_version_n >= KICAD_VERSION_5_99 return GS.kicad_version_n >= KICAD_VERSION_5_99
@staticmethod
def ki5():
return GS.kicad_version_n < KICAD_VERSION_5_99
@staticmethod @staticmethod
def load_pcb_title_block(): def load_pcb_title_block():
if GS.pcb_title is not None: if GS.pcb_title is not None:

View File

@ -22,7 +22,7 @@ from collections import OrderedDict
from .gs import GS from .gs import GS
from .misc import (PLOT_ERROR, MISSING_TOOL, CMD_EESCHEMA_DO, URL_EESCHEMA_DO, CORRUPTED_PCB, from .misc import (PLOT_ERROR, MISSING_TOOL, CMD_EESCHEMA_DO, URL_EESCHEMA_DO, CORRUPTED_PCB,
EXIT_BAD_ARGS, CORRUPTED_SCH, EXIT_BAD_CONFIG, WRONG_INSTALL, UI_SMD, UI_VIRTUAL, KICAD_VERSION_5_99, EXIT_BAD_ARGS, CORRUPTED_SCH, EXIT_BAD_CONFIG, WRONG_INSTALL, UI_SMD, UI_VIRTUAL,
MOD_SMD, MOD_THROUGH_HOLE, MOD_VIRTUAL, W_PCBNOSCH, W_NONEEDSKIP, W_WRONGCHAR, name2make, W_TIMEOUT, MOD_SMD, MOD_THROUGH_HOLE, MOD_VIRTUAL, W_PCBNOSCH, W_NONEEDSKIP, W_WRONGCHAR, name2make, W_TIMEOUT,
W_KIAUTO) W_KIAUTO)
from .error import PlotError, KiPlotConfigurationError, config_error, trace_dump from .error import PlotError, KiPlotConfigurationError, config_error, trace_dump
@ -276,7 +276,7 @@ def get_board_comps_data(comps):
c.bottom = m.IsFlipped() c.bottom = m.IsFlipped()
c.footprint_rot = m.GetOrientationDegrees() c.footprint_rot = m.GetOrientationDegrees()
attrs = m.GetAttributes() attrs = m.GetAttributes()
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
# KiCad 5 # KiCad 5
if attrs == UI_SMD: if attrs == UI_SMD:
c.smd = True c.smd = True

View File

@ -6,7 +6,7 @@
import pcbnew import pcbnew
from .optionable import Optionable from .optionable import Optionable
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99, W_NOTASCII from .misc import W_NOTASCII
from re import match from re import match
from .error import (PlotError, KiPlotConfigurationError) from .error import (PlotError, KiPlotConfigurationError)
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
@ -189,7 +189,7 @@ class Layer(Optionable):
elif layer in Layer._pcb_layers: elif layer in Layer._pcb_layers:
ext = [Layer.create_layer(layer)] ext = [Layer.create_layer(layer)]
# Give compatibility for the KiCad 5 default names (automagically renamed by KiCad 6) # Give compatibility for the KiCad 5 default names (automagically renamed by KiCad 6)
elif GS.kicad_version_n >= KICAD_VERSION_5_99 and layer in Layer.KICAD6_RENAME: # pragma: no cover (Ki6) elif GS.ki6() and layer in Layer.KICAD6_RENAME: # pragma: no cover (Ki6)
ext = [Layer.create_layer(Layer.KICAD6_RENAME[layer])] ext = [Layer.create_layer(Layer.KICAD6_RENAME[layer])]
elif layer in Layer.DEFAULT_LAYER_NAMES: elif layer in Layer.DEFAULT_LAYER_NAMES:
ext = [Layer.create_layer(layer)] ext = [Layer.create_layer(layer)]

View File

@ -8,7 +8,6 @@ from pcbnew import (PLOT_FORMAT_HPGL, PLOT_FORMAT_POST, PLOT_FORMAT_GERBER, PLOT
PLOT_FORMAT_PDF, wxPoint) PLOT_FORMAT_PDF, wxPoint)
from .optionable import (Optionable, BaseOptions) from .optionable import (Optionable, BaseOptions)
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99
from .macros import macros, document # noqa: F401 from .macros import macros, document # noqa: F401
from . import log from . import log
@ -37,7 +36,7 @@ class DrillReport(Optionable):
def get_aux_origin(board): def get_aux_origin(board):
if GS.kicad_version_n >= KICAD_VERSION_5_99: # pragma: no cover (Ki6) if GS.ki6(): # pragma: no cover (Ki6)
settings = board.GetDesignSettings() settings = board.GetDesignSettings()
return settings.GetAuxOrigin() return settings.GetAuxOrigin()
return board.GetAuxOrigin() return board.GetAuxOrigin()

View File

@ -14,7 +14,7 @@ from .out_base import BaseOutput, VariantOptions
from .error import PlotError, KiPlotConfigurationError from .error import PlotError, KiPlotConfigurationError
from .layer import Layer from .layer import Layer
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99, W_NOLAYER from .misc import W_NOLAYER
from .macros import macros, document # noqa: F401 from .macros import macros, document # noqa: F401
from . import log from . import log
@ -85,7 +85,7 @@ class AnyLayerOptions(VariantOptions):
po.SetPlotValue(self.plot_footprint_values) po.SetPlotValue(self.plot_footprint_values)
po.SetPlotInvisibleText(self.force_plot_invisible_refs_vals) po.SetPlotInvisibleText(self.force_plot_invisible_refs_vals)
po.SetExcludeEdgeLayer(self.exclude_edge_layer) po.SetExcludeEdgeLayer(self.exclude_edge_layer)
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
po.SetPlotPadsOnSilkLayer(not self.exclude_pads_from_silkscreen) po.SetPlotPadsOnSilkLayer(not self.exclude_pads_from_silkscreen)
po.SetPlotViaOnMaskLayer(not self.tent_vias) po.SetPlotViaOnMaskLayer(not self.tent_vias)
# Only useful for gerber outputs # Only useful for gerber outputs
@ -230,7 +230,7 @@ class AnyLayerOptions(VariantOptions):
self.force_plot_invisible_refs_vals = po.GetPlotInvisibleText() self.force_plot_invisible_refs_vals = po.GetPlotInvisibleText()
# viasonmask # viasonmask
self.tent_vias = not po.GetPlotViaOnMaskLayer() self.tent_vias = not po.GetPlotViaOnMaskLayer()
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
# padsonsilk # padsonsilk
self.exclude_pads_from_silkscreen = not po.GetPlotPadsOnSilkLayer() self.exclude_pads_from_silkscreen = not po.GetPlotPadsOnSilkLayer()

View File

@ -7,12 +7,12 @@ import os
from copy import deepcopy from copy import deepcopy
from .gs import GS from .gs import GS
from .kiplot import load_sch, get_board_comps_data from .kiplot import load_sch, get_board_comps_data
from .misc import Rect, KICAD_VERSION_5_99, W_WRONGPASTE from .misc import Rect, W_WRONGPASTE
if not GS.kicad_version_n: if not GS.kicad_version_n:
# When running the regression tests we need it # When running the regression tests we need it
from kibot.__main__ import detect_kicad from kibot.__main__ import detect_kicad
detect_kicad() detect_kicad()
if GS.kicad_version_n >= KICAD_VERSION_5_99: # pragma: no cover (Ki6) if GS.ki6(): # pragma: no cover (Ki6)
# New name, no alias ... # New name, no alias ...
from pcbnew import FP_SHAPE, wxPoint, LSET from pcbnew import FP_SHAPE, wxPoint, LSET
else: else:
@ -184,7 +184,7 @@ class VariantOptions(BaseOptions):
@staticmethod @staticmethod
def create_module_element(m): def create_module_element(m):
if GS.kicad_version_n >= KICAD_VERSION_5_99: if GS.ki6():
return FP_SHAPE(m) # pragma: no cover (Ki6) return FP_SHAPE(m) # pragma: no cover (Ki6)
return EDGE_MODULE(m) return EDGE_MODULE(m)

View File

@ -7,9 +7,8 @@ from pcbnew import PLOT_FORMAT_DXF, SKETCH, FILLED
from .out_any_layer import AnyLayer from .out_any_layer import AnyLayer
from .drill_marks import DrillMarks from .drill_marks import DrillMarks
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
if GS.kicad_version_n >= KICAD_VERSION_5_99: # pragma: no cover (Ki6) if GS.ki6(): # pragma: no cover (Ki6)
from pcbnew import DXF_UNITS_MILLIMETERS, DXF_UNITS_INCHES from pcbnew import DXF_UNITS_MILLIMETERS, DXF_UNITS_INCHES
else: else:
DXF_UNITS_MILLIMETERS = 1 DXF_UNITS_MILLIMETERS = 1

View File

@ -7,7 +7,6 @@
# Adapted from: https://github.com/johnbeard/kiplot # Adapted from: https://github.com/johnbeard/kiplot
from pcbnew import (PLOT_FORMAT_GERBER, FromMM, ToMM) from pcbnew import (PLOT_FORMAT_GERBER, FromMM, ToMM)
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99
from .out_any_layer import (AnyLayer, AnyLayerOptions) from .out_any_layer import (AnyLayer, AnyLayerOptions)
from .error import KiPlotConfigurationError from .error import KiPlotConfigurationError
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
@ -62,7 +61,7 @@ class GerberOptions(AnyLayerOptions):
po.SetIncludeGerberNetlistInfo(self.use_gerber_net_attributes) po.SetIncludeGerberNetlistInfo(self.use_gerber_net_attributes)
po.SetUseAuxOrigin(self.use_aux_axis_as_origin) po.SetUseAuxOrigin(self.use_aux_axis_as_origin)
po.SetDrillMarksType(0) po.SetDrillMarksType(0)
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
po.SetLineWidth(FromMM(self.line_width)) po.SetLineWidth(FromMM(self.line_width))
else: else:
po.SetDisableGerberMacros(self.disable_aperture_macros) # pragma: no cover (Ki6) po.SetDisableGerberMacros(self.disable_aperture_macros) # pragma: no cover (Ki6)
@ -84,7 +83,7 @@ class GerberOptions(AnyLayerOptions):
self.subtract_mask_from_silk = po.GetSubtractMaskFromSilk() self.subtract_mask_from_silk = po.GetSubtractMaskFromSilk()
# useauxorigin # useauxorigin
self.use_aux_axis_as_origin = po.GetUseAuxOrigin() self.use_aux_axis_as_origin = po.GetUseAuxOrigin()
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
# linewidth # linewidth
self.line_width = ToMM(po.GetLineWidth()) self.line_width = ToMM(po.GetLineWidth())
else: else:

View File

@ -9,7 +9,6 @@ from pcbnew import (PLOT_FORMAT_PDF, FromMM, ToMM)
from .out_any_layer import AnyLayer from .out_any_layer import AnyLayer
from .drill_marks import DrillMarks from .drill_marks import DrillMarks
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
from . import log from . import log
@ -31,14 +30,14 @@ class PDFOptions(DrillMarks):
def _configure_plot_ctrl(self, po, output_dir): def _configure_plot_ctrl(self, po, output_dir):
super()._configure_plot_ctrl(po, output_dir) super()._configure_plot_ctrl(po, output_dir)
po.SetMirror(self.mirror_plot) po.SetMirror(self.mirror_plot)
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
po.SetLineWidth(FromMM(self.line_width)) po.SetLineWidth(FromMM(self.line_width))
po.SetNegative(self.negative_plot) po.SetNegative(self.negative_plot)
def read_vals_from_po(self, po): def read_vals_from_po(self, po):
super().read_vals_from_po(po) super().read_vals_from_po(po)
self.mirror_plot = po.GetMirror() self.mirror_plot = po.GetMirror()
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
self.line_width = ToMM(po.GetLineWidth()) self.line_width = ToMM(po.GetLineWidth())
self.negative_plot = po.GetNegative() self.negative_plot = po.GetNegative()

View File

@ -10,7 +10,7 @@ from .pre_base import BasePreFlight
from .error import (KiPlotConfigurationError) from .error import (KiPlotConfigurationError)
from .gs import (GS) from .gs import (GS)
from .kiplot import check_script, exec_with_retry, add_extra_options from .kiplot import check_script, exec_with_retry, add_extra_options
from .misc import (CMD_PCBNEW_PRINT_LAYERS, URL_PCBNEW_PRINT_LAYERS, PDF_PCB_PRINT, KICAD_VERSION_5_99) from .misc import (CMD_PCBNEW_PRINT_LAYERS, URL_PCBNEW_PRINT_LAYERS, PDF_PCB_PRINT)
from .out_base import VariantOptions from .out_base import VariantOptions
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
from .layer import Layer from .layer import Layer
@ -65,7 +65,7 @@ class PDF_Pcb_PrintOptions(VariantOptions):
@staticmethod @staticmethod
def _copy_project(fname): def _copy_project(fname):
pro_ext = '.kicad_pro' if GS.kicad_version_n >= KICAD_VERSION_5_99 else '.pro' pro_ext = '.kicad_pro' if GS.ki6() else '.pro'
pro_name = GS.pcb_file.replace('.kicad_pcb', pro_ext) pro_name = GS.pcb_file.replace('.kicad_pcb', pro_ext)
if not os.path.isfile(pro_name): if not os.path.isfile(pro_name):
return None return None

View File

@ -11,7 +11,7 @@ from datetime import datetime
from pcbnew import IU_PER_MM, IU_PER_MILS from pcbnew import IU_PER_MM, IU_PER_MILS
from collections import OrderedDict from collections import OrderedDict
from .gs import GS from .gs import GS
from .misc import UI_SMD, UI_VIRTUAL, KICAD_VERSION_5_99, MOD_THROUGH_HOLE, MOD_SMD, MOD_EXCLUDE_FROM_POS_FILES from .misc import UI_SMD, UI_VIRTUAL, MOD_THROUGH_HOLE, MOD_SMD, MOD_EXCLUDE_FROM_POS_FILES
from .optionable import Optionable from .optionable import Optionable
from .out_base import VariantOptions from .out_base import VariantOptions
from .error import KiPlotConfigurationError from .error import KiPlotConfigurationError
@ -201,7 +201,7 @@ class PositionOptions(VariantOptions):
@staticmethod @staticmethod
def get_attr_tests(): def get_attr_tests():
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
return PositionOptions.is_pure_smd_5, PositionOptions.is_not_virtual_5 return PositionOptions.is_pure_smd_5, PositionOptions.is_not_virtual_5
return PositionOptions.is_pure_smd_6, PositionOptions.is_not_virtual_6 # pragma: no cover (Ki6) return PositionOptions.is_pure_smd_6, PositionOptions.is_not_virtual_6 # pragma: no cover (Ki6)

View File

@ -10,7 +10,6 @@ from .misc import AUTO_SCALE
from .out_any_layer import AnyLayer from .out_any_layer import AnyLayer
from .drill_marks import DrillMarks from .drill_marks import DrillMarks
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
@ -46,7 +45,7 @@ class PSOptions(DrillMarks):
po.SetFineScaleAdjustX(self.scale_adjust_y) po.SetFineScaleAdjustX(self.scale_adjust_y)
po.SetA4Output(self.a4_output) po.SetA4Output(self.a4_output)
po.SetPlotMode(SKETCH if self.sketch_plot else FILLED) po.SetPlotMode(SKETCH if self.sketch_plot else FILLED)
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
po.SetLineWidth(FromMM(self.line_width)) po.SetLineWidth(FromMM(self.line_width))
po.SetNegative(self.negative_plot) po.SetNegative(self.negative_plot)
po.SetMirror(self.mirror_plot) po.SetMirror(self.mirror_plot)
@ -65,7 +64,7 @@ class PSOptions(DrillMarks):
self.scale_adjust_y = po.GetFineScaleAdjustX() self.scale_adjust_y = po.GetFineScaleAdjustX()
self.a4_output = po.GetA4Output() self.a4_output = po.GetA4Output()
self.sketch_plot = po.GetPlotMode() == SKETCH self.sketch_plot = po.GetPlotMode() == SKETCH
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
self.line_width = ToMM(po.GetLineWidth()) self.line_width = ToMM(po.GetLineWidth())
self.negative_plot = po.GetNegative() self.negative_plot = po.GetNegative()
self.mirror_plot = po.GetMirror() self.mirror_plot = po.GetMirror()

View File

@ -9,7 +9,6 @@ from pcbnew import (PLOT_FORMAT_SVG, FromMM, ToMM)
from .out_any_layer import AnyLayer from .out_any_layer import AnyLayer
from .drill_marks import DrillMarks from .drill_marks import DrillMarks
from .gs import GS from .gs import GS
from .misc import KICAD_VERSION_5_99
from .macros import macros, document, output_class # noqa: F401 from .macros import macros, document, output_class # noqa: F401
@ -28,13 +27,13 @@ class SVGOptions(DrillMarks):
def _configure_plot_ctrl(self, po, output_dir): def _configure_plot_ctrl(self, po, output_dir):
super()._configure_plot_ctrl(po, output_dir) super()._configure_plot_ctrl(po, output_dir)
po.SetMirror(self.mirror_plot) po.SetMirror(self.mirror_plot)
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
po.SetLineWidth(FromMM(self.line_width)) po.SetLineWidth(FromMM(self.line_width))
po.SetNegative(self.negative_plot) po.SetNegative(self.negative_plot)
def read_vals_from_po(self, po): def read_vals_from_po(self, po):
super().read_vals_from_po(po) super().read_vals_from_po(po)
if GS.kicad_version_n < KICAD_VERSION_5_99: if GS.ki5():
self.line_width = ToMM(po.GetLineWidth()) self.line_width = ToMM(po.GetLineWidth())
self.negative_plot = po.GetNegative() self.negative_plot = po.GetNegative()
self.mirror_plot = po.GetMirror() self.mirror_plot = po.GetMirror()