From b73a2e51d4d56f12b6cf77cf0d53bdb8374caec9 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 18 Jan 2022 15:51:55 -0300 Subject: [PATCH] Added stackup support to the report --- kibot/globals.py | 4 +- kibot/kicad/v6_sch.py | 2 +- kibot/out_report.py | 47 ++++++++++++++++--- kibot/report_templates/report_full.txt | 10 ++++ kibot/report_templates/report_simple.txt | 10 ++++ .../reference/6_0_0/light_control-report.txt | 17 +++++++ .../6_0_0/light_control-report_simple.txt | 17 +++++++ 7 files changed, 97 insertions(+), 10 deletions(-) diff --git a/kibot/globals.py b/kibot/globals.py index e319112a..54519577 100644 --- a/kibot/globals.py +++ b/kibot/globals.py @@ -125,10 +125,10 @@ class Globals(FiltersOptions): elif ly.type == 'copper' and ly.thickness: if not len(thicknesses): thicknesses.add(ly.thickness) - self.copper_thickness = str(int(ly.thickness*1000)) + self.copper_thickness = str(int(ly.thickness)) elif ly.thickness not in thicknesses: thicknesses.add(ly.thickness) - self.copper_thickness += ' / '+str(int(ly.thickness*1000)) + self.copper_thickness += ' / '+str(int(ly.thickness)) def get_stack_up(self): logger.debug("Looking for stack-up information in the PCB") diff --git a/kibot/kicad/v6_sch.py b/kibot/kicad/v6_sch.py index ef4e1a3a..76e3b4a1 100644 --- a/kibot/kicad/v6_sch.py +++ b/kibot/kicad/v6_sch.py @@ -1411,7 +1411,7 @@ class PCBLayer(object): elif i_type == 'color': layer.color = _check_str(i, 1, tname) elif i_type == 'thickness': - layer.thickness = _check_float(i, 1, tname) + layer.thickness = _check_float(i, 1, tname)*1000 elif i_type == 'material': layer.material = _check_str(i, 1, tname) elif i_type == 'epsilon_r': diff --git a/kibot/out_report.py b/kibot/out_report.py index 3627fa77..2721923f 100644 --- a/kibot/out_report.py +++ b/kibot/out_report.py @@ -136,6 +136,11 @@ class ReportOptions(BaseOptions): continue units = None var_ori = var + m = re.match(r'^(%[^,]+),(.*)$', var) + pattern = None + if m: + pattern = m.group(1) + var = m.group(2) if var.endswith('_mm'): units = to_mm digits = self._mm_digits @@ -154,7 +159,22 @@ class ReportOptions(BaseOptions): val = 'N/A' elif units is not None and isinstance(val, (int, float)): val = units(val, digits) - line = line.replace('${'+var_ori+'}', str(val)) + if pattern is not None: + clear = False + if 's' in pattern: + val = str(val) + else: + try: + val = float(val) + except ValueError: + val = 0 + clear = True + rep = pattern % val + if clear: + rep = ' '*len(rep) + else: + rep = str(val) + line = line.replace('${'+var_ori+'}', rep) else: print('Error: Unable to expand `{}`'.format(var)) return line @@ -212,6 +232,18 @@ class ReportOptions(BaseOptions): text += self.do_replacements(line, {'drill': d, 'count': self._drills[d]}) return text + def context_stackup(self, line): + """ Replace iterator for the `stackup` context """ + text = '' + for s in self._stackup: + context = {} + for k in dir(s): + val = getattr(s, k) + if k[0] != '_' and not callable(val): + context[k] = val if val is not None else '' + text += self.do_replacements(line, context) + return text + @staticmethod def is_pure_smd_5(m): return m.GetAttributes() == UI_SMD @@ -433,7 +465,7 @@ class ReportOptions(BaseOptions): self._tracks_defined = set(self._track_sizes) def eval_conditional(self, line): - context = {k: getattr(self, k) for k in dir(self) if k[0] != '_'} + context = {k: getattr(self, k) for k in dir(self) if k[0] != '_' and not callable(getattr(self, k))} res = None text = line[2:].strip() logger.debug('- Evaluating `{}`'.format(text)) @@ -462,13 +494,12 @@ class ReportOptions(BaseOptions): elif ':' in line: context = line[1:].split(':')[0] logger.debug("- Report context: `{}`".format(context)) - try: + name = 'context_'+context + if hasattr(self, name): # Contexts are members called context_* - line = getattr(self, 'context_'+context)(line[len(context)+2:]) + line = getattr(self, name)(line[len(context)+2:]) done = True - except AttributeError: - pass - if not done: + else: raise KiPlotConfigurationError("Unknown context: `{}`".format(context)) if not done: # Just replace using any data member (_* excluded) @@ -496,6 +527,8 @@ class ReportOptions(BaseOptions): self.castellated_pads = GS.global_castellated_pads self.edge_plating = GS.global_edge_plating self.copper_thickness = GS.global_copper_thickness + self.stackup = 'yes' if GS.stackup else '' + self._stackup = GS.stackup if GS.stackup else [] self.collect_data(GS.board) self.do_template(self.template, fname) diff --git a/kibot/report_templates/report_full.txt b/kibot/report_templates/report_full.txt index f14f2cc0..e1c561ea 100644 --- a/kibot/report_templates/report_full.txt +++ b/kibot/report_templates/report_full.txt @@ -21,6 +21,16 @@ Special features: #?edge_plating - Edge plating +#?stackup +Stackup: +#?stackup +| Name | Type | Color | Thickness | Material | Epsilon_r | Loss tangent | +#?stackup +|----------------------|----------------------|----------|-----------|----------|-----------|--------------| +#?stackup +#stackup:| ${%-20s,name} | ${%-20s,type} | ${%-8s,color} | ${%9d,thickness} | ${%-8s,material} | ${%9.1f,epsilon_r} | ${%12.2f,loss_tangent} | +#?stackup + # Important sizes Clearance: ${clearance_mm} mm (${clearance_mils} mils) diff --git a/kibot/report_templates/report_simple.txt b/kibot/report_templates/report_simple.txt index d7dab450..75724b49 100644 --- a/kibot/report_templates/report_simple.txt +++ b/kibot/report_templates/report_simple.txt @@ -18,6 +18,16 @@ Special features: #?edge_plating - Edge plating +#?stackup +Stackup: +#?stackup +| Name | Type | Color | Thickness | Material | Epsilon_r | Loss tangent | +#?stackup +|----------------------|----------------------|----------|-----------|----------|-----------|--------------| +#?stackup +#stackup:| ${%-20s,name} | ${%-20s,type} | ${%-8s,color} | ${%9d,thickness} | ${%-8s,material} | ${%9.1f,epsilon_r} | ${%12.2f,loss_tangent} | +#?stackup + Materials: - ${pcb_material}, ${thickness_mm} mm - ${pcb_finish} diff --git a/tests/reference/6_0_0/light_control-report.txt b/tests/reference/6_0_0/light_control-report.txt index d8c70408..8556ea26 100644 --- a/tests/reference/6_0_0/light_control-report.txt +++ b/tests/reference/6_0_0/light_control-report.txt @@ -17,6 +17,23 @@ Special features: - Castellated pads - Edge plating +Stackup: +| Name | Type | Color | Thickness | Material | Epsilon_r | Loss tangent | +|----------------------|----------------------|----------|-----------|----------|-----------|--------------| +| F.SilkS | Top Silk Screen | White | | | | | +| F.Paste | Top Solder Paste | | | | | | +| F.Mask | Top Solder Mask | Blue | 10 | | | | +| F.Cu | copper | | 35 | | | | +| dielectric 1 | core | | 480 | FR4 | 4.5 | 0.02 | +| In1.Cu | copper | | 35 | | | | +| dielectric 2 | prepreg | | 480 | FR4 | 4.5 | 0.02 | +| In2.Cu | copper | | 35 | | | | +| dielectric 3 | core | | 480 | FR4 | 4.5 | 0.02 | +| B.Cu | copper | | 35 | | | | +| B.Mask | Bottom Solder Mask | Red | 10 | | | | +| B.Paste | Bottom Solder Paste | | | | | | +| B.SilkS | Bottom Silk Screen | Black | | | | | + # Important sizes Clearance: 0.15 mm (6 mils) diff --git a/tests/reference/6_0_0/light_control-report_simple.txt b/tests/reference/6_0_0/light_control-report_simple.txt index 1c4af8a7..ae583d9f 100644 --- a/tests/reference/6_0_0/light_control-report_simple.txt +++ b/tests/reference/6_0_0/light_control-report_simple.txt @@ -14,6 +14,23 @@ Special features: - Castellated pads - Edge plating +Stackup: +| Name | Type | Color | Thickness | Material | Epsilon_r | Loss tangent | +|----------------------|----------------------|----------|-----------|----------|-----------|--------------| +| F.SilkS | Top Silk Screen | White | | | | | +| F.Paste | Top Solder Paste | | | | | | +| F.Mask | Top Solder Mask | Blue | 10 | | | | +| F.Cu | copper | | 35 | | | | +| dielectric 1 | core | | 480 | FR4 | 4.5 | 0.02 | +| In1.Cu | copper | | 35 | | | | +| dielectric 2 | prepreg | | 480 | FR4 | 4.5 | 0.02 | +| In2.Cu | copper | | 35 | | | | +| dielectric 3 | core | | 480 | FR4 | 4.5 | 0.02 | +| B.Cu | copper | | 35 | | | | +| B.Mask | Bottom Solder Mask | Red | 10 | | | | +| B.Paste | Bottom Solder Paste | | | | | | +| B.SilkS | Bottom Silk Screen | Black | | | | | + Materials: - FR4, 1.6 mm - ENIG