Added support for upto 9 comment lines (KiCad 6)

This commit is contained in:
Salvador E. Tropea 2021-12-31 11:43:03 -03:00
parent 64bfc4824d
commit 1eefdeb5a3
6 changed files with 39 additions and 80 deletions

View File

@ -255,10 +255,7 @@ You can always choose the file name for a particular output.
The pattern uses the following expansions:
- **%c** company from pcb/sch metadata.
- **%C1** comments line 1 from pcb/sch metadata.
- **%C2** comments line 2 from pcb/sch metadata.
- **%C3** comments line 3 from pcb/sch metadata.
- **%C4** comments line 4 from pcb/sch metadata.
- **%C`n`** comments line `n` from pcb/sch metadata.
- **%d** pcb/sch date from metadata if available, file modification date otherwise.
- **%D** date the script was started.
- **%f** original pcb/sch file name without extension.
@ -283,7 +280,7 @@ global:
output: '%f_rev_%r-%i.%x'
```
Note that the following patterns: **%c**, **%C1**, **%C2**, **%C3**, **%C4**, **%d**, **%f**, **%F**, **%p** and **%r** depends on the context.
Note that the following patterns: **%c**, **%C`n`**, **%d**, **%f**, **%F**, **%p** and **%r** depends on the context.
If you use them for an output related to the PCB these values will be obtained from the PCB.
If you need to force the origin of the data you can use **%bX** for the PCB and **%sX** for the schematic, where
**X** is the pattern to expand.

View File

@ -193,10 +193,7 @@ You can always choose the file name for a particular output.
The pattern uses the following expansions:
- **%c** company from pcb/sch metadata.
- **%C1** comments line 1 from pcb/sch metadata.
- **%C2** comments line 2 from pcb/sch metadata.
- **%C3** comments line 3 from pcb/sch metadata.
- **%C4** comments line 4 from pcb/sch metadata.
- **%C`n`** comments line `n` from pcb/sch metadata.
- **%d** pcb/sch date from metadata if available, file modification date otherwise.
- **%D** date the script was started.
- **%f** original pcb/sch file name without extension.
@ -221,7 +218,7 @@ global:
output: '%f_rev_%r-%i.%x'
```
Note that the following patterns: **%c**, **%C1**, **%C2**, **%C3**, **%C4**, **%d**, **%f**, **%F**, **%p** and **%r** depends on the context.
Note that the following patterns: **%c**, **%C`n`**, **%d**, **%f**, **%F**, **%p** and **%r** depends on the context.
If you use them for an output related to the PCB these values will be obtained from the PCB.
If you need to force the origin of the data you can use **%bX** for the PCB and **%sX** for the schematic, where
**X** is the pattern to expand.

View File

@ -53,19 +53,13 @@ class GS(object):
sch_date = None
sch_rev = None
sch_comp = None
sch_com1 = None
sch_com2 = None
sch_com3 = None
sch_com4 = None
sch_com = [None]*9
# Data from the board title block
pcb_title = None
pcb_date = None
pcb_rev = None
pcb_comp = None
pcb_com1 = None
pcb_com2 = None
pcb_com3 = None
pcb_com4 = None
pcb_com = [None]*9
# Current variant/s
variant = None
# All the outputs
@ -120,10 +114,7 @@ class GS(object):
GS.sch_date = GS.sch.date
GS.sch_rev = GS.sch.revision
GS.sch_comp = GS.sch.company
GS.sch_com1 = GS.sch.comment1
GS.sch_com2 = GS.sch.comment2
GS.sch_com3 = GS.sch.comment3
GS.sch_com4 = GS.sch.comment4
GS.sch_com = GS.sch.comment
@staticmethod
def format_date(d, fname, what):
@ -144,14 +135,16 @@ class GS(object):
if GS.ki6(): # pragma: no cover (Ki6)
# Backward compatibility ... what's this?
# Also: Maintaining the same numbers used before (and found in the file) is asking too much?
return title_block.GetComment(num-1)
if num == 1:
return title_block.GetComment(num)
if num == 0:
return title_block.GetComment1()
if num == 2:
if num == 1:
return title_block.GetComment2()
if num == 3:
if num == 2:
return title_block.GetComment3()
return title_block.GetComment4()
if num == 3:
return title_block.GetComment4()
return ''
@staticmethod
def get_modules():
@ -196,18 +189,14 @@ class GS(object):
GS.pcb_title = GS.pcb_basename
GS.pcb_rev = title_block.GetRevision()
GS.pcb_comp = title_block.GetCompany()
GS.pcb_com1 = GS.get_pcb_comment(title_block, 1)
GS.pcb_com2 = GS.get_pcb_comment(title_block, 2)
GS.pcb_com3 = GS.get_pcb_comment(title_block, 3)
GS.pcb_com4 = GS.get_pcb_comment(title_block, 4)
for num in range(9):
GS.pcb_com[num] = GS.get_pcb_comment(title_block, num)
logger.debug("PCB title: `{}`".format(GS.pcb_title))
logger.debug("PCB date: `{}`".format(GS.pcb_date))
logger.debug("PCB revision: `{}`".format(GS.pcb_rev))
logger.debug("PCB company: `{}`".format(GS.pcb_comp))
logger.debug("PCB comment 1: `{}`".format(GS.pcb_com1))
logger.debug("PCB comment 2: `{}`".format(GS.pcb_com2))
logger.debug("PCB comment 3: `{}`".format(GS.pcb_com3))
logger.debug("PCB comment 4: `{}`".format(GS.pcb_com4))
for num in range(4 if GS.ki5() else 9):
logger.debug("PCB comment {}: `{}`".format(num+1, GS.pcb_com[num]))
@staticmethod
def check_pcb():

View File

@ -1463,6 +1463,7 @@ class Schematic(object):
self.dcms = {}
self.lib_comps = {}
self.annotation_error = False
self.max_comments = 4
def _get_title_block(self, f):
line = f.get_line()
@ -1475,6 +1476,7 @@ class Schematic(object):
self.sheet = 1
self.nsheets = 1
self.title_block = OrderedDict()
self.comment = ['']*9
while True:
line = f.get_line()
if line.startswith('$EndDescr'):
@ -1482,10 +1484,8 @@ class Schematic(object):
self.date = self.title_block.get('Date', '')
self.revision = self.title_block.get('Rev', '')
self.company = self.title_block.get('Comp', '')
self.comment1 = self.title_block.get('Comment1', '')
self.comment2 = self.title_block.get('Comment2', '')
self.comment3 = self.title_block.get('Comment3', '')
self.comment4 = self.title_block.get('Comment4', '')
for num in range(4):
self.comment[num] = self.title_block.get('Comment'+str(num+1), '')
return
elif line.startswith('encoding'):
if line[9:14] != 'utf-8':
@ -1789,17 +1789,9 @@ class Schematic(object):
dt.text = self.date
SubElement(tblock, 'source').text = os.path.basename(self.fname)
com = SubElement(tblock, 'comment')
com.set('number', '1')
com.set('value', self.comment1)
com = SubElement(tblock, 'comment')
com.set('number', '2')
com.set('value', self.comment2)
com = SubElement(tblock, 'comment')
com.set('number', '3')
com.set('value', self.comment3)
com = SubElement(tblock, 'comment')
com.set('number', '4')
com.set('value', self.comment4)
for num in range(self.max_comments):
com.set('number', str(num+1))
com.set('value', self.comment[num])
def save_netlist_components(self, root, comps, excluded, fitted, no_field):
""" Generates the `components` section of the netlist """

View File

@ -1386,7 +1386,8 @@ class SchematicV6(Schematic):
self.annotation_error = False
# The title block is optional
self.date = self.title = self.revision = self.company = ''
self.comment1 = self.comment2 = self.comment3 = self.comment4 = ''
self.comment = ['']*9
self.max_comments = 9
self.title_ori = self.date_ori = None
def _fill_missing_title_block(self):
@ -1412,17 +1413,10 @@ class SchematicV6(Schematic):
self.company = _check_str(item, 1, i_type)
elif i_type == 'comment':
index = _check_integer(item, 1, i_type)
if index < 1 or index > 4:
if index < 1 or index > 9:
raise SchError('Unsupported comment index {} in title block'.format(index))
value = _check_str(item, 2, i_type)
if index == 1:
self.comment1 = value
elif index == 2:
self.comment2 = value
elif index == 3:
self.comment3 = value
elif index == 4:
self.comment4 = value
self.comment[index-1] = value
else:
raise SchError('Unsupported entry in title block ({})'.format(item))
self._fill_missing_title_block()
@ -1460,10 +1454,8 @@ class SchematicV6(Schematic):
data += [_symbol('date', [self.date_ori]), Sep()]
data += [_symbol('rev', [self.revision]), Sep()]
data += [_symbol('company', [self.company]), Sep()]
data += [_symbol('comment', [1, self.comment1]), Sep()]
data += [_symbol('comment', [2, self.comment2]), Sep()]
data += [_symbol('comment', [3, self.comment3]), Sep()]
data += [_symbol('comment', [4, self.comment4]), Sep()]
for num, val in enumerate(self.comment):
data += [_symbol('comment', [num+1, val]), Sep()]
return [Sep(), Sep(), _symbol('title_block', data)]
def write_lib_symbols(self, cross=False):

View File

@ -230,10 +230,8 @@ class Optionable(object):
name = name.replace('%bf', GS.pcb_basename)
name = name.replace('%bp', _cl(GS.pcb_title))
name = name.replace('%br', _cl(GS.pcb_rev))
name = name.replace('%bC1', _cl(GS.pcb_com1))
name = name.replace('%bC2', _cl(GS.pcb_com2))
name = name.replace('%bC3', _cl(GS.pcb_com3))
name = name.replace('%bC4', _cl(GS.pcb_com4))
for num, val in enumerate(GS.pcb_com):
name = name.replace('%bC'+str(num+1), _cl(val))
if GS.solved_global_variant:
name = name.replace('%g', GS.solved_global_variant.file_id)
name = name.replace('%G', GS.solved_global_variant.name)
@ -245,10 +243,8 @@ class Optionable(object):
name = name.replace('%sf', GS.sch_basename)
name = name.replace('%sp', _cl(GS.sch_title))
name = name.replace('%sr', _cl(GS.sch_rev))
name = name.replace('%sC1', _cl(GS.sch_com1))
name = name.replace('%sC2', _cl(GS.sch_com2))
name = name.replace('%sC3', _cl(GS.sch_com3))
name = name.replace('%sC4', _cl(GS.sch_com4))
for num, val in enumerate(GS.sch_com):
name = name.replace('%sC'+str(num+1), _cl(val))
name = name.replace('%D', GS.n.strftime(GS.global_date_format))
name = name.replace('%T', GS.n.strftime(GS.global_time_format))
if self:
@ -292,10 +288,8 @@ class Optionable(object):
name = name.replace('%f', GS.pcb_basename)
name = name.replace('%p', _cl(GS.pcb_title))
name = name.replace('%r', _cl(GS.pcb_rev))
name = name.replace('%C1', _cl(GS.pcb_com1))
name = name.replace('%C2', _cl(GS.pcb_com2))
name = name.replace('%C3', _cl(GS.pcb_com3))
name = name.replace('%C4', _cl(GS.pcb_com4))
for num, val in enumerate(GS.pcb_com):
name = name.replace('%C'+str(num+1), _cl(val))
if GS.sch and do_sch:
name = name.replace('%c', _cl(GS.sch_comp))
name = name.replace('%d', _cl(GS.sch_date))
@ -303,10 +297,8 @@ class Optionable(object):
name = name.replace('%f', GS.sch_basename)
name = name.replace('%p', _cl(GS.sch_title))
name = name.replace('%r', _cl(GS.sch_rev))
name = name.replace('%C1', _cl(GS.sch_com1))
name = name.replace('%C2', _cl(GS.sch_com2))
name = name.replace('%C3', _cl(GS.sch_com3))
name = name.replace('%C4', _cl(GS.sch_com4))
for num, val in enumerate(GS.sch_com):
name = name.replace('%C'+str(num+1), _cl(val))
# sanitize the name to avoid characters illegal in file systems
name = name.replace('\\', '/')
name = re.sub(r'[?%*:|"<>]', '_', name)