fix in pcbnew/python/swig/units.i ... added error handling

Added error handling in unit conversions for the pcbnew python bindings.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/10081
This commit is contained in:
Jacob Mealey 2021-12-25 21:34:24 -05:00 committed by Roberto Fernandez Bautista
parent 8167c69508
commit 987a6e125b
1 changed files with 8 additions and 0 deletions

View File

@ -36,24 +36,32 @@
return float(iu) / float(IU_PER_MM)
elif type(iu) in [wxPoint,wxSize]:
return tuple(map(ToMM,iu))
else:
raise TypeError("ToMM() excpects int, float, wxPoint or wxSize, instead got type " + str(type(iu)))
def FromMM(mm):
if type(mm) in [int,float]:
return int(float(mm) * float(IU_PER_MM))
elif type(mm) in [wxPoint,wxSize]:
return tuple(map(FromMM,mm))
else:
raise TypeError("FromMM() expects int, float, wxPoint or wxSize, instead got type " + str(type(mm)))
def ToMils(iu):
if type(iu) in [int,float]:
return float(iu) / float(IU_PER_MILS)
elif type(iu) in [wxPoint,wxSize]:
return tuple(map(ToMils,iu))
else:
raise TypeError("ToMils() excpects int, float, wxPoint or wxSize, instead got type " + str(type(iu)))
def FromMils(mils):
if type(mils) in [int,float]:
return int(float(mils)*float(IU_PER_MILS))
elif type(mils) in [wxPoint,wxSize]:
return tuple(map(FromMils,mils))
else:
raise TypeError("FromMils() excpects int, float, wxPoint or wxSize, instead got type " + str(type(mils)))
def PutOnGridMM(value, gridSizeMM):
thresh = FromMM(gridSizeMM)