[KiCad 7] Solved UI_PER_MM and UI_PER_MILS changes
This commit is contained in:
parent
e0fbd20419
commit
ebbfbb7b62
26
kibot/gs.py
26
kibot/gs.py
|
|
@ -20,6 +20,12 @@ from .misc import EXIT_BAD_ARGS, W_DATEFORMAT, W_UNKVAR, WRONG_INSTALL
|
|||
from .log import get_logger
|
||||
|
||||
logger = get_logger(__name__)
|
||||
if hasattr(pcbnew, 'IU_PER_MM'):
|
||||
IU_PER_MM = pcbnew.IU_PER_MM
|
||||
IU_PER_MILS = pcbnew.IU_PER_MILS
|
||||
else:
|
||||
IU_PER_MM = pcbnew.pcbIUScale.IU_PER_MM
|
||||
IU_PER_MILS = pcbnew.pcbIUScale.IU_PER_MILS
|
||||
|
||||
|
||||
class GS(object):
|
||||
|
|
@ -90,9 +96,9 @@ class GS(object):
|
|||
stackup = None
|
||||
# Preprocessor definitions
|
||||
cli_defines = {}
|
||||
kikit_units_to_kicad = {'mm': pcbnew.IU_PER_MM, 'cm': 10*pcbnew.IU_PER_MM, 'dm': 100*pcbnew.IU_PER_MM,
|
||||
'm': 1000*pcbnew.IU_PER_MM, 'mil': pcbnew.IU_PER_MILS, 'inch': 1000*pcbnew.IU_PER_MILS,
|
||||
'in': 1000*pcbnew.IU_PER_MILS}
|
||||
kikit_units_to_kicad = {'mm': IU_PER_MM, 'cm': 10*IU_PER_MM, 'dm': 100*IU_PER_MM,
|
||||
'm': 1000*IU_PER_MM, 'mil': IU_PER_MILS, 'inch': 1000*IU_PER_MILS,
|
||||
'in': 1000*IU_PER_MILS}
|
||||
#
|
||||
# Global defaults
|
||||
#
|
||||
|
|
@ -287,19 +293,23 @@ class GS(object):
|
|||
@staticmethod
|
||||
def unit_name_to_scale_factor(units):
|
||||
if units == 'millimeters':
|
||||
return 1.0/pcbnew.IU_PER_MM
|
||||
return 1.0/IU_PER_MM
|
||||
if units == 'mils':
|
||||
return 1.0/pcbnew.IU_PER_MILS
|
||||
return 1.0/IU_PER_MILS
|
||||
# Inches
|
||||
return 0.001/pcbnew.IU_PER_MILS
|
||||
return 0.001/IU_PER_MILS
|
||||
|
||||
@staticmethod
|
||||
def to_mm(val):
|
||||
return val/pcbnew.IU_PER_MM
|
||||
return val/IU_PER_MM
|
||||
|
||||
@staticmethod
|
||||
def from_mm(val):
|
||||
return int(val*pcbnew.IU_PER_MM)
|
||||
return int(val*IU_PER_MM)
|
||||
|
||||
@staticmethod
|
||||
def to_mils(val):
|
||||
return val/IU_PER_MM
|
||||
|
||||
@staticmethod
|
||||
def make_bkp(fname):
|
||||
|
|
|
|||
|
|
@ -36,9 +36,9 @@ from . import __version__
|
|||
logger = log.get_logger()
|
||||
INF = float('inf')
|
||||
# This OAR is the minimum Eurocircuits does without extra charge
|
||||
EC_SMALL_OAR = 0.125*pcbnew.IU_PER_MM
|
||||
EC_SMALL_OAR = GS.from_mm(0.125)
|
||||
# The minimum drill tool
|
||||
EC_MIN_DRILL = 0.1*pcbnew.IU_PER_MM
|
||||
EC_MIN_DRILL = GS.from_mm(0.1)
|
||||
|
||||
|
||||
def do_round(v, dig):
|
||||
|
|
@ -49,20 +49,20 @@ def do_round(v, dig):
|
|||
def to_mm(iu, dig=2):
|
||||
""" KiCad Internal Units to millimeters """
|
||||
if isinstance(iu, pcbnew.wxPoint):
|
||||
return (do_round(iu.x/pcbnew.IU_PER_MM, dig), do_round(iu.y/pcbnew.IU_PER_MM, dig))
|
||||
return (do_round(GS.to_mm(iu.x), dig), do_round(GS.to_mm(iu.y), dig))
|
||||
if isinstance(iu, pcbnew.wxSize):
|
||||
return (do_round(iu.x/pcbnew.IU_PER_MM, dig), do_round(iu.y/pcbnew.IU_PER_MM, dig))
|
||||
return do_round(iu/pcbnew.IU_PER_MM, dig)
|
||||
return (do_round(GS.to_mm(iu.x), dig), do_round(GS.to_mm(iu.y), dig))
|
||||
return do_round(GS.to_mm(iu), dig)
|
||||
|
||||
|
||||
def to_mils(iu, dig=0):
|
||||
""" KiCad Internal Units to mils (1/1000 inch) """
|
||||
return do_round(iu/pcbnew.IU_PER_MILS, dig)
|
||||
return do_round(GS.to_mils(iu), dig)
|
||||
|
||||
|
||||
def to_inches(iu, dig=2):
|
||||
""" KiCad Internal Units to inches """
|
||||
return do_round(iu/(pcbnew.IU_PER_MILS*1000), dig)
|
||||
return do_round(GS.to_mils(iu)/1000, dig)
|
||||
|
||||
|
||||
def get_class_index(val, lst):
|
||||
|
|
@ -157,9 +157,9 @@ def adjust_drill(val, is_pth=True, pad=None):
|
|||
""" Add drill_size_increment if this is a PTH hole and round it to global_extra_pth_drill """
|
||||
if val == INF:
|
||||
return val
|
||||
step = GS.global_drill_size_increment*pcbnew.IU_PER_MM
|
||||
step = GS.from_mm(GS.global_drill_size_increment)
|
||||
if is_pth:
|
||||
val += GS.global_extra_pth_drill*pcbnew.IU_PER_MM
|
||||
val += GS.from_mm(GS.global_extra_pth_drill)
|
||||
res = int((val+step/2)/step)*step
|
||||
# if pad:
|
||||
# logger.error(f"{to_mm(val)} -> {to_mm(res)} {get_pad_info(pad)}")
|
||||
|
|
@ -485,7 +485,7 @@ class ReportOptions(BaseOptions):
|
|||
def compute_oar(self, pad, hole):
|
||||
""" Compute the OAR and the corrected OAR for Eurocircuits """
|
||||
oar_ec = oar = (pad-hole)/2
|
||||
if oar < EC_SMALL_OAR and oar > 0 and hole < self.eurocircuits_reduce_holes*pcbnew.IU_PER_MM:
|
||||
if oar < EC_SMALL_OAR and oar > 0 and hole < GS.from_mm(self.eurocircuits_reduce_holes):
|
||||
# This hole is classified as "via hole" and has a problematic OAR
|
||||
hole_ec = max(adjust_drill(pad-2*EC_SMALL_OAR, is_pth=False), EC_MIN_DRILL)
|
||||
oar_ec = (pad-hole_ec)/2
|
||||
|
|
@ -524,7 +524,7 @@ class ReportOptions(BaseOptions):
|
|||
|
||||
def collect_data(self, board):
|
||||
ds = board.GetDesignSettings()
|
||||
self.extra_pth_drill = GS.global_extra_pth_drill*pcbnew.IU_PER_MM
|
||||
self.extra_pth_drill = GS.from_mm(GS.global_extra_pth_drill)
|
||||
###########################################################
|
||||
# Board size
|
||||
###########################################################
|
||||
|
|
@ -604,7 +604,7 @@ class ReportOptions(BaseOptions):
|
|||
bottom_layer = board.GetLayerID('B.Cu')
|
||||
is_pure_smd, is_not_virtual = self.get_attr_tests()
|
||||
npth_attrib = 3 if GS.ki5 else pcbnew.PAD_ATTRIB_NPTH
|
||||
min_oar = 0.1*pcbnew.IU_PER_MM
|
||||
min_oar = GS.from_mm(0.1)
|
||||
for m in modules:
|
||||
layer = m.GetLayer()
|
||||
if layer == top_layer:
|
||||
|
|
|
|||
Loading…
Reference in New Issue