From 0361c38d9db49629e130e64ee037c3ac92744095 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Mon, 20 Mar 2023 14:15:46 -0300 Subject: [PATCH] [PcbDraw] Various changes in resistor color bands - Added support for values between 0.01 and 10 ohms - Avoid crash for R<0.01 ohms - Added support for 20% tolerance - Added support for tol/tolerance property - Fixed Decimal division by float - Changed default tolerance to 20%. I know this isn't reality, but if we don't know the tolerance is better to just let it blank (20% is this). --- kibot/PcbDraw/plot.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/kibot/PcbDraw/plot.py b/kibot/PcbDraw/plot.py index 8ca660e6..a262732b 100644 --- a/kibot/PcbDraw/plot.py +++ b/kibot/PcbDraw/plot.py @@ -56,6 +56,8 @@ default_style = { 7: '#cc00cc', 8: '#666666', 9: '#cccccc', + -1: '#ffc800', + -2: '#d9d9d9', '1%': '#805500', '2%': '#ff0000', '0.5%': '#00cc11', @@ -64,6 +66,7 @@ default_style = { '0.05%': '#666666', '5%': '#ffc800', '10%': '#d9d9d9', + '20%': '#ffe598', } } @@ -884,10 +887,15 @@ class PlotComponents(PlotInterface): try: res, tolerance = self._get_resistance_from_value(value) power = math.floor(res.log10()) - 1 - res = Decimal(int(res / 10 ** power)) + res = str(Decimal(int(res / Decimal(10) ** power))) + if power == -3: + power += 1 + res = '0'+res + elif power < -3: + raise UserWarning(f"Resistor value must be 0.01 or bigger") resistor_colors = [ - self._plotter.get_style("tht-resistor-band-colors", int(str(res)[0])), - self._plotter.get_style("tht-resistor-band-colors", int(str(res)[1])), + self._plotter.get_style("tht-resistor-band-colors", int(res[0])), + self._plotter.get_style("tht-resistor-band-colors", int(res[1])), self._plotter.get_style("tht-resistor-band-colors", int(power)), self._plotter.get_style("tht-resistor-band-colors", tolerance) ] @@ -914,7 +922,7 @@ class PlotComponents(PlotInterface): return def _get_resistance_from_value(self, value: str) -> Tuple[Decimal, str]: - res, tolerance = None, "5%" + res, tolerance = None, "20%" value_l = value.split(" ", maxsplit=1) try: res = read_resistance(value_l[0]) @@ -1084,6 +1092,11 @@ class PcbPlotter(): lib = str(footprint.GetFPID().GetLibNickname()).strip() name = str(footprint.GetFPID().GetLibItemName()).strip() value = footprint.GetValue().strip() + # Look for a tolerance in the properties + prop = footprint.GetProperties() + tol = prop.get('tol', prop.get('tolerance', None)) + if tol: + value = value+' '+tol ref = footprint.GetReference().strip() center = footprint.GetPosition() orient = math.radians(footprint.GetOrientation().AsDegrees())