From 45e670c11f3814b3a3784286106d42486ce9ef24 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 15 Mar 2022 20:26:18 -0300 Subject: [PATCH] More early text var expansions Fixes #163 --- kibot/gs.py | 6 +++--- kibot/kicad/v6_sch.py | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/kibot/gs.py b/kibot/gs.py index d36ddfa8..b3ba0bfd 100644 --- a/kibot/gs.py +++ b/kibot/gs.py @@ -166,9 +166,9 @@ class GS(object): assert GS.sch is not None GS.sch_title = GS.sch.title GS.sch_date = GS.sch.date - GS.sch_rev = GS.expand_text_variables(GS.sch.revision) - GS.sch_comp = GS.expand_text_variables(GS.sch.company) - GS.sch_com = [GS.expand_text_variables(x) for x in GS.sch.comment] + GS.sch_rev = GS.sch.revision + GS.sch_comp = GS.sch.company + GS.sch_com = GS.sch.comment @staticmethod def format_date(d, fname, what): diff --git a/kibot/kicad/v6_sch.py b/kibot/kicad/v6_sch.py index 82d72e77..600bdad6 100644 --- a/kibot/kicad/v6_sch.py +++ b/kibot/kicad/v6_sch.py @@ -1506,8 +1506,9 @@ class SchematicV6(Schematic): # The title block is optional self.date = self.title = self.revision = self.company = '' self.comment = ['']*9 + self.comment_ori = ['']*9 self.max_comments = 9 - self.title_ori = self.date_ori = None + self.title_ori = self.date_ori = self.revision_ori = self.company_ori = None self.netlist_version = 'E' def _fill_missing_title_block(self): @@ -1530,22 +1531,25 @@ class SchematicV6(Schematic): self.date_ori = _check_str(item, 1, i_type) self.date = GS.expand_text_variables(self.date_ori) elif i_type == 'rev': - self.revision = _check_str(item, 1, i_type) + self.revision_ori = _check_str(item, 1, i_type) + self.revision = GS.expand_text_variables(self.revision_ori) elif i_type == 'company': - self.company = _check_str(item, 1, i_type) + self.company_ori = _check_str(item, 1, i_type) + self.company = GS.expand_text_variables(self.company_ori) elif i_type == 'comment': index = _check_integer(item, 1, i_type) if index < 1 or index > 9: raise SchError('Unsupported comment index {} in title block'.format(index)) value = _check_str(item, 2, i_type) - self.comment[index-1] = value + self.comment_ori[index-1] = value + self.comment[index-1] = GS.expand_text_variables(value) else: raise SchError('Unsupported entry in title block ({})'.format(item)) self._fill_missing_title_block() logger.debug("SCH title: `{}`".format(self.title_ori)) logger.debug("SCH date: `{}`".format(self.date_ori)) - logger.debug("SCH revision: `{}`".format(self.revision)) - logger.debug("SCH company: `{}`".format(self.company)) + logger.debug("SCH revision: `{}`".format(self.revision_ori)) + logger.debug("SCH company: `{}`".format(self.company_ori)) def _get_lib_symbols(self, comps): if not isinstance(comps, list): @@ -1574,9 +1578,9 @@ class SchematicV6(Schematic): data = [Sep()] data += [_symbol('title', [self.title_ori]), Sep()] data += [_symbol('date', [self.date_ori]), Sep()] - data += [_symbol('rev', [self.revision]), Sep()] - data += [_symbol('company', [self.company]), Sep()] - for num, val in enumerate(self.comment): + data += [_symbol('rev', [self.revision_ori]), Sep()] + data += [_symbol('company', [self.company_ori]), Sep()] + for num, val in enumerate(self.comment_ori): data += [_symbol('comment', [num+1, val]), Sep()] return [Sep(), Sep(), _symbol('title_block', data)]