New preflight to annotate power components

Closes #76
This commit is contained in:
Salvador E. Tropea 2022-02-26 13:21:40 -03:00
parent 36581d8608
commit 27c987217c
17 changed files with 2899 additions and 102 deletions

View File

@ -51,7 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Another experimental mechanism to change 3D models according to the variant.
(#103)
- A mechanism to avoid running some outputs by default. (#112)
- New pre-flight commands to replace tags in the schematic and PCB. (#93)
- New preflight commands to replace tags in the schematic and PCB. (#93)
- New preflight to annotate power components. (#76)
- Now you can compress files relative to the current working directory.
So you can create a compressed file containing the source schematic and
PCB files. (#93)

View File

@ -109,6 +109,9 @@ This section is used to specify tasks that will be executed before generating an
#### Supported preflight options:
- `annotate_power`: [boolean=false] Annotates all power components.
This preflight modifies the schematic, use it only in revision control environments.
Used to solve ERC problems when using filters that remove power reference numbers.
- `check_zone_fills`: [boolean=false] Zones are filled before doing any operation involving PCB layers.
- `erc_warnings`: [boolean=false] Option for `run_erc`. ERC warnings are considered errors.
- `filters`: [list(dict)] A list of entries to filter out ERC/DRC messages.

View File

@ -6,6 +6,10 @@ kibot:
version: 1
preflight:
# [boolean=false] Annotates all power components.
# This preflight modifies the schematic, use it only in revision control environments.
# Used to solve ERC problems when using filters that remove power reference numbers.
annotate_power: true
# [boolean=false] Zones are filled before doing any operation involving PCB layers.
check_zone_fills: true
# [boolean=false] Option for `run_erc`. ERC warnings are considered errors.

View File

@ -1145,11 +1145,14 @@ class SchematicComponent(object):
comp._validate()
return comp
def write(self, f):
# Fake lib to reflect fitted status
lib = 'y' if self.fitted or not self.included else 'n'
# Fake name using cache style
name = '{}:{}_{}'.format(lib, self.lib, self.name)
def write(self, f, crossed=False):
if crossed:
# Fake lib to reflect fitted status
lib = 'y' if self.fitted or not self.included else 'n'
# Fake name using cache style
name = '{}:{}_{}'.format(lib, self.lib, self.name)
else:
name = '{}:{}'.format(self.lib, self.name)
f.write('$Comp\n')
f.write('L {} {}\n'.format(name, self.f_ref))
f.write('U {} {} {}\n'.format(self.unit, self.unit2, self.id))
@ -1355,7 +1358,7 @@ class SchematicBitmap(object):
def write(self, f):
f.write('$Bitmap\n')
f.write('Pos {} {}\n'.format(self.x, self.y))
f.write('Scale {}\n'.format(self.scale))
f.write('Scale {0:.6f}\n'.format(self.scale))
f.write('Data')
for c, b in enumerate(self.data):
if (c % 32) == 0:
@ -1751,31 +1754,66 @@ class Schematic(object):
logger.warning(W_MISSCMP + 'Missing component `{}`'.format(k))
f.write('#\n#End Library\n')
def save(self, fname, dest_dir):
fname = os.path.join(dest_dir, fname)
with open(fname, 'wt') as f:
f.write('EESchema Schematic File Version {}\n'.format(self.version))
f.write('EELAYER {} {}\n'.format(self.eelayer_n, self.eelayer_m))
f.write('EELAYER END\n')
f.write('$Descr {} {} {}'.format(self.page_type, self.page_width, self.page_height))
if self.paper_orientation:
f.write(' {}'.format(self.paper_orientation))
f.write('\n')
f.write('encoding utf-8\n')
f.write('Sheet {} {}\n'.format(self.sheet, self.nsheets))
for k, v in self.title_block.items():
f.write('{} "{}"\n'.format(k, v))
f.write('$EndDescr\n')
for e in self.all:
e.write(f)
f.write('$EndSCHEMATC\n')
def save(self, fname=None, dest_dir=None, base_sheet=None, saved=None):
""" Save the schematic and its sub-sheets.
If dest_dir is not None all files are stored in dest_dir (for variants). """
if base_sheet is None:
# We are the base sheet
base_sheet = self
if saved is None:
# Start memorizing saved files
saved = set()
if fname is None:
# Use our name if none provided
fname = self.fname
if dest_dir is None:
# Save at the same place
if not os.path.isabs(fname):
# Use the base sheet as reference
fname = os.path.join(os.path.dirname(base_sheet.fname), fname)
else:
# Save all in dest_dir (variant)
fname = os.path.join(dest_dir, fname)
# Save the sheet
if fname not in saved:
logger.debug('Saving schematic: `{}`'.format(fname))
# Keep a back-up of existing files
if os.path.isfile(fname):
bkp = fname+'-bak'
if os.path.isfile(bkp):
os.remove(bkp)
os.rename(fname, bkp)
with open(fname, 'wt') as f:
f.write('EESchema Schematic File Version {}\n'.format(self.version))
f.write('EELAYER {} {}\n'.format(self.eelayer_n, self.eelayer_m))
f.write('EELAYER END\n')
f.write('$Descr {} {} {}'.format(self.page_type, self.page_width, self.page_height))
if self.paper_orientation:
f.write(' {}'.format(self.paper_orientation))
f.write('\n')
f.write('encoding utf-8\n')
f.write('Sheet {} {}\n'.format(self.sheet, self.nsheets))
for k, v in self.title_block.items():
f.write('{} "{}"\n'.format(k, v))
f.write('$EndDescr\n')
crossed = dest_dir is not None
for e in self.all:
if isinstance(e, SchematicComponent):
e.write(f, crossed)
else:
e.write(f)
f.write('$EndSCHEMATC\n')
saved.add(fname)
# Save sub-sheets
for c, sch in enumerate(self.sheets):
# Fake file name
file = sch.file.replace('/', '_')
self.sub_sheets[c].save(file, dest_dir)
file = sch.file
if dest_dir is not None:
# Fake file name, forcing a flat structure (all files in dest_dir)
file = file.replace('/', '_')
self.sub_sheets[c].save(file, dest_dir, base_sheet, saved)
def save_variant(self, dest_dir):
""" Save a modified schematic with crossed components """
# Currently impossible
# if not os.path.exists(dest_dir):
# os.makedirs(dest_dir)

View File

@ -955,6 +955,20 @@ class SchematicComponentV6(SchematicComponent):
else:
raise SchError('Footprint with more than one colon (`{}`)'.format(fp))
@staticmethod
def get_lib_and_name(comp, i, name):
comp.lib_id = comp.name = _check_str(i, 1, name+' lib_id')
res = comp.name.split(':')
comp.lib = None
if len(res) == 1:
comp.name = res[0]
comp.lib = ''
elif len(res) == 2:
comp.name = res[1]
comp.lib = res[0]
else:
logger.warning(W_NOLIB + "Component `{}` with more than one `:`".format(comp.name))
@staticmethod
def load(c, project, parent):
if not isinstance(c, list):
@ -977,17 +991,7 @@ class SchematicComponentV6(SchematicComponent):
i_type = _check_is_symbol_list(i)
if i_type == 'lib_id':
# First argument is the LIB:NAME
comp.lib_id = comp.name = _check_str(i, 1, name + ' lib_id')
res = comp.name.split(':')
comp.lib = None
if len(res) == 1:
comp.name = res[0]
comp.lib = ''
elif len(res) == 2:
comp.name = res[1]
comp.lib = res[0]
else:
logger.warning(W_NOLIB + "Component `{}` with more than one `:`".format(comp.name))
SchematicComponentV6.get_lib_and_name(comp, i, name)
lib_id_found = True
elif i_type == 'lib_name':
# Symbol defined in schematic
@ -1582,66 +1586,92 @@ class SchematicV6(Schematic):
data.extend([s.write(cross), Sep()])
return [Sep(), Sep(), _symbol('lib_symbols', data), Sep()]
def save(self, fname, dest_dir):
cross = True
fname = os.path.join(dest_dir, fname)
sch = [Symbol('kicad_sch')]
sch.append(_symbol('version', [self.version]))
sch.append(_symbol('generator', [Symbol(self.generator)]))
sch.append(Sep())
sch.append(Sep())
sch.append(_symbol('uuid', [Symbol(self.uuid)]))
sch.extend(self.write_paper())
if self.title_ori is not None:
sch.extend(self.write_title_block())
sch.extend(self.write_lib_symbols(cross))
# Bus aliases
_add_items(self.bus_alias, sch)
# Connections (aka Junctions)
_add_items(self.junctions, sch, pre_sep=(len(self.bus_alias) == 0))
# No connect
_add_items(self.no_conn, sch)
# Bus entry
_add_items(self.bus_entry, sch)
# Lines (wire, bus and polyline)
if self.wires:
old_type = 'none'
for e in self.wires:
if e.type != old_type and old_type != 'wire':
def save(self, fname=None, dest_dir=None, base_sheet=None, saved=None):
cross = dest_dir is not None
if base_sheet is None:
# We are the base sheet
base_sheet = self
if saved is None:
# Start memorizing saved files
saved = set()
if fname is None:
# Use our name if none provided
fname = self.fname
if dest_dir is None:
# Save at the same place
if not os.path.isabs(fname):
# Use the base sheet as reference
fname = os.path.join(os.path.dirname(base_sheet.fname), fname)
else:
# Save all in dest_dir (variant)
fname = os.path.join(dest_dir, fname)
# Save the sheet
if fname not in saved:
sch = [Symbol('kicad_sch')]
sch.append(_symbol('version', [self.version]))
sch.append(_symbol('generator', [Symbol(self.generator)]))
sch.append(Sep())
sch.append(Sep())
sch.append(_symbol('uuid', [Symbol(self.uuid)]))
sch.extend(self.write_paper())
if self.title_ori is not None:
sch.extend(self.write_title_block())
sch.extend(self.write_lib_symbols(cross))
# Bus aliases
_add_items(self.bus_alias, sch)
# Connections (aka Junctions)
_add_items(self.junctions, sch, pre_sep=(len(self.bus_alias) == 0))
# No connect
_add_items(self.no_conn, sch)
# Bus entry
_add_items(self.bus_entry, sch)
# Lines (wire, bus and polyline)
if self.wires:
old_type = 'none'
for e in self.wires:
if e.type != old_type and old_type != 'wire':
sch.append(Sep())
sch.append(e.write())
old_type = e.type
sch.append(Sep())
sch.append(e.write())
old_type = e.type
sch.append(Sep())
# Images
_add_items(self.bitmaps, sch)
# Texts
_add_items(self.texts, sch)
# Labels
_add_items(self.labels, sch)
# Global Labels
_add_items(self.glabels, sch)
# Hierarchical Labels
_add_items(self.hlabels, sch)
# Symbols
_add_items(self.symbols, sch, sep=True, cross=cross)
# Sheets
_add_items(self.sheets, sch, sep=True, cross=cross)
# Sheet instances
_add_items_list('sheet_instances', self.sheet_instances, sch)
# Symbol instances
# Copy potentially modified data from components
for s in self.symbol_instances:
comp = s.component
s.reference = comp.ref
s.value = comp.value
s.footprint = comp.footprint_lib+':'+comp.footprint if comp.footprint_lib else comp.footprint
_add_items_list('symbol_instances', self.symbol_instances, sch)
with open(fname, 'wt') as f:
f.write(dumps(sch))
f.write('\n')
# Images
_add_items(self.bitmaps, sch)
# Texts
_add_items(self.texts, sch)
# Labels
_add_items(self.labels, sch)
# Global Labels
_add_items(self.glabels, sch)
# Hierarchical Labels
_add_items(self.hlabels, sch)
# Symbols
_add_items(self.symbols, sch, sep=True, cross=cross)
# Sheets
_add_items(self.sheets, sch, sep=True, cross=cross)
# Sheet instances
_add_items_list('sheet_instances', self.sheet_instances, sch)
# Symbol instances
# Copy potentially modified data from components
for s in self.symbol_instances:
comp = s.component
s.reference = comp.ref
s.value = comp.value
s.footprint = comp.footprint_lib+':'+comp.footprint if comp.footprint_lib else comp.footprint
_add_items_list('symbol_instances', self.symbol_instances, sch)
logger.debug('Saving schematic: `{}`'.format(fname))
# Keep a back-up of existing files
if os.path.isfile(fname):
bkp = fname+'-bak'
if os.path.isfile(bkp):
os.remove(bkp)
os.rename(fname, bkp)
with open(fname, 'wt') as f:
f.write(dumps(sch))
f.write('\n')
saved.add(fname)
for sch in self.sheets:
if sch.sch:
sch.sch.save(sch.flat_file if cross else sch.file, dest_dir)
sch.sch.save(sch.flat_file if cross else sch.file, dest_dir, base_sheet, saved)
def save_variant(self, dest_dir):
fname = os.path.basename(self.fname)
@ -1760,8 +1790,6 @@ class SchematicV6(Schematic):
self.hlabels.append(HierarchicalLabel.parse(e))
elif e_type == 'symbol':
obj = SchematicComponentV6.load(e, self.project, self)
if obj.annotation_error:
self.annotation_error = True
self.symbols.append(obj)
self.symbol_uuids[obj.uuid] = obj
elif e_type == 'sheet':
@ -1778,10 +1806,7 @@ class SchematicV6(Schematic):
self._fill_missing_title_block()
# Load sub-sheets
for sch in self.sheets:
sheet = sch.load_sheet(project, fname, self)
if sheet.annotation_error:
self.annotation_error = True
sch.sch = sheet
sch.sch = sch.load_sheet(project, fname, self)
# Assign the page numbers
if parent is None:
self.all_sheets = []
@ -1806,6 +1831,9 @@ class SchematicV6(Schematic):
comp.sheet_path = path
comp.sheet_path_h = self.path_to_human(path)
comp.id = comp_uuid
if s.reference[-1] == '?':
comp.annotation_error = True
self.annotation_error = True
# Link with its library symbol
try:
lib_symbol = self.lib_symbol_names[comp.lib_id]

View File

@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2022 Salvador E. Tropea
# Copyright (c) 2022 Instituto Nacional de Tecnología Industrial
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
import os
from .error import KiPlotConfigurationError
from .gs import (GS)
from .optionable import Optionable
from .kiplot import load_sch
from .misc import W_NOANNO
from .macros import macros, pre_class # noqa: F401
from .log import get_logger
logger = get_logger(__name__)
@pre_class
class Annotate_Power(BasePreFlight): # noqa: F821
""" [boolean=false] Annotates all power components.
This preflight modifies the schematic, use it only in revision control environments.
Used to solve ERC problems when using filters that remove power reference numbers """
def __init__(self, name, value):
super().__init__(name, value)
if not isinstance(value, bool):
raise KiPlotConfigurationError('must be boolean')
self._enabled = value
self._sch_related = True
def annotate_ki5(self):
""" Annotate power components for KiCad 5 """
comps = GS.sch.get_components(exclude_power=False)
num = 1
for c in comps:
if c.is_power:
# Force a new number
c.f_ref = c.ref_prefix+'{:02d}'.format(num)
c.ref_suffix = str(num)
num = num+1
# Fix the ARs
if c.ar:
first = True
for o in c.ar:
if first:
# Copy this to the first
o.ref = c.f_ref
first = False
else:
# Allocate new numbers for the rest
o.ref = c.ref_prefix+'{:02d}'.format(num)
num = num+1
# Fix the reference field
field = next(filter(lambda x: x.number == 0, c.fields), None)
if field:
field.value = c.f_ref
def annotate_ki6(self):
""" Annotate power components for KiCad 6 """
num = 1
for ins in GS.sch.symbol_instances:
c = ins.component
if c.is_power:
c.set_ref(c.ref_prefix+'{:02d}'.format(num))
num = num+1
def run(self):
load_sch()
if not GS.sch:
return
if not GS.sch.annotation_error:
logger.warning(W_NOANNO+"No annotation problems, skipping power annotation")
return
if GS.ki5():
self.annotate_ki5()
else:
self.annotate_ki6()
GS.sch.save()

View File

@ -0,0 +1 @@
../../board_samples/kicad_5/deeper.sch

View File

@ -0,0 +1,157 @@
EESchema Schematic File Version 4
EELAYER 30 0
EELAYER END
$Descr A4 11693 8268
encoding utf-8
Sheet 2 5
Title ""
Date ""
Rev ""
Comp ""
Comment1 ""
Comment2 ""
Comment3 ""
Comment4 ""
$EndDescr
$Comp
L 74xx:74LS04 U1
U 1 1 5F34307A
P 3800 2500
AR Path="/5F342DEB/5F34307A" Ref="U1" Part="1"
AR Path="/5F34E267/5F34307A" Ref="U2" Part="1"
F 0 "U1" H 3800 2817 50 0000 C CNN
F 1 "74LS04" H 3800 2726 50 0000 C CNN
F 2 "" H 3800 2500 50 0001 C CNN
F 3 "http://www.ti.com/lit/gpn/sn74LS04" H 3800 2500 50 0001 C CNN
1 3800 2500
1 0 0 -1
$EndComp
$Comp
L 74xx:74LS04 U1
U 2 1 5F344A0E
P 4500 2500
AR Path="/5F342DEB/5F344A0E" Ref="U1" Part="2"
AR Path="/5F34E267/5F344A0E" Ref="U2" Part="2"
F 0 "U1" H 4500 2817 50 0000 C CNN
F 1 "74LS04" H 4500 2726 50 0000 C CNN
F 2 "" H 4500 2500 50 0001 C CNN
F 3 "http://www.ti.com/lit/gpn/sn74LS04" H 4500 2500 50 0001 C CNN
2 4500 2500
1 0 0 -1
$EndComp
$Comp
L 74xx:74LS04 U1
U 3 1 5F345E39
P 5200 2500
AR Path="/5F342DEB/5F345E39" Ref="U1" Part="3"
AR Path="/5F34E267/5F345E39" Ref="U2" Part="3"
F 0 "U1" H 5200 2817 50 0000 C CNN
F 1 "74LS04" H 5200 2726 50 0000 C CNN
F 2 "" H 5200 2500 50 0001 C CNN
F 3 "http://www.ti.com/lit/gpn/sn74LS04" H 5200 2500 50 0001 C CNN
3 5200 2500
1 0 0 -1
$EndComp
$Comp
L 74xx:74LS04 U1
U 4 1 5F346E8B
P 5900 2500
AR Path="/5F342DEB/5F346E8B" Ref="U1" Part="4"
AR Path="/5F34E267/5F346E8B" Ref="U2" Part="4"
F 0 "U1" H 5900 2817 50 0000 C CNN
F 1 "74LS04" H 5900 2726 50 0000 C CNN
F 2 "" H 5900 2500 50 0001 C CNN
F 3 "http://www.ti.com/lit/gpn/sn74LS04" H 5900 2500 50 0001 C CNN
4 5900 2500
1 0 0 -1
$EndComp
$Comp
L 74xx:74LS04 U1
U 5 1 5F348270
P 6600 2500
AR Path="/5F342DEB/5F348270" Ref="U1" Part="5"
AR Path="/5F34E267/5F348270" Ref="U2" Part="5"
F 0 "U1" H 6600 2817 50 0000 C CNN
F 1 "74LS04" H 6600 2726 50 0000 C CNN
F 2 "" H 6600 2500 50 0001 C CNN
F 3 "http://www.ti.com/lit/gpn/sn74LS04" H 6600 2500 50 0001 C CNN
5 6600 2500
1 0 0 -1
$EndComp
$Comp
L 74xx:74LS04 U1
U 6 1 5F348D95
P 7300 2500
AR Path="/5F342DEB/5F348D95" Ref="U1" Part="6"
AR Path="/5F34E267/5F348D95" Ref="U2" Part="6"
F 0 "U1" H 7300 2817 50 0000 C CNN
F 1 "74LS04" H 7300 2726 50 0000 C CNN
F 2 "" H 7300 2500 50 0001 C CNN
F 3 "http://www.ti.com/lit/gpn/sn74LS04" H 7300 2500 50 0001 C CNN
6 7300 2500
1 0 0 -1
$EndComp
$Comp
L 74xx:74LS04 U1
U 7 1 5F34A12F
P 5500 3500
AR Path="/5F342DEB/5F34A12F" Ref="U1" Part="7"
AR Path="/5F34E267/5F34A12F" Ref="U2" Part="7"
F 0 "U1" H 5730 3546 50 0000 L CNN
F 1 "74LS04" H 5730 3455 50 0000 L CNN
F 2 "" H 5500 3500 50 0001 C CNN
F 3 "http://www.ti.com/lit/gpn/sn74LS04" H 5500 3500 50 0001 C CNN
7 5500 3500
1 0 0 -1
$EndComp
$Comp
L power:VCC #PWR01
U 1 1 5F34BC05
P 5500 3000
AR Path="/5F342DEB/5F34BC05" Ref="#PWR01" Part="1"
AR Path="/5F34E267/5F34BC05" Ref="#PWR02" Part="1"
F 0 "#PWR01" H 5500 2850 50 0001 C CNN
F 1 "VCC" H 5515 3173 50 0000 C CNN
F 2 "" H 5500 3000 50 0001 C CNN
F 3 "" H 5500 3000 50 0001 C CNN
1 5500 3000
1 0 0 -1
$EndComp
$Comp
L power:GND #PWR03
U 1 1 5F34C535
P 5500 4000
AR Path="/5F342DEB/5F34C535" Ref="#PWR03" Part="1"
AR Path="/5F34E267/5F34C535" Ref="#PWR04" Part="1"
F 0 "#PWR03" H 5500 3750 50 0001 C CNN
F 1 "GND" H 5505 3827 50 0000 C CNN
F 2 "" H 5500 4000 50 0001 C CNN
F 3 "" H 5500 4000 50 0001 C CNN
1 5500 4000
1 0 0 -1
$EndComp
Wire Wire Line
4100 2500 4200 2500
Wire Wire Line
4800 2500 4900 2500
Wire Wire Line
5500 2500 5600 2500
Wire Wire Line
6200 2500 6300 2500
Wire Wire Line
6900 2500 7000 2500
Text HLabel 7700 2500 2 50 Output ~ 0
OUT
Wire Wire Line
7600 2500 7700 2500
Text HLabel 3350 2500 0 50 Input ~ 0
IN
Wire Wire Line
3350 2500 3500 2500
$Sheet
S 4500 5000 1000 500
U 5F3BB8BB
F0 "Deeper test" 50
F1 "deeper.sch" 50
$EndSheet
$EndSCHEMATC

View File

@ -0,0 +1 @@
../../board_samples/kicad_5/test_v5.sch

View File

@ -0,0 +1 @@
../5_1_6/deeper.sch

View File

@ -0,0 +1 @@
../5_1_6/sub-sheet.sch

View File

@ -0,0 +1 @@
../5_1_6/test_v5.sch

View File

@ -0,0 +1,83 @@
(kicad_sch (version 20211123) (generator eeschema)
(uuid 3b838d52-596d-4e4d-a6ac-e4c8e7621137)
(paper "A4")
(title_block
(title "")
(date "")
(rev "")
(company "")
(comment 1 "")
(comment 2 "")
(comment 3 "")
(comment 4 "")
(comment 5 "")
(comment 6 "")
(comment 7 "")
(comment 8 "")
(comment 9 "")
)
(lib_symbols
(symbol "Device:R" (pin_numbers hide) (pin_names (offset 0)) (in_bom yes) (on_board yes)
(property "Reference" "R" (id 0) (at 2.032 0 90)
(effects (font (size 1.27 1.27)))
)
(property "Value" "R" (id 1) (at 0 0 90)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (id 2) (at -1.778 0 90)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (id 3) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "R res resistor" (id 4) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Resistor" (id 5) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "R_*" (id 6) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "R_0_1"
(rectangle (start -1.016 -2.54) (end 1.016 2.54)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type none))
)
)
(symbol "R_1_1"
(pin passive line (at 0 3.81 270) (length 1.27)
(name "~" (effects (font (size 1.27 1.27))))
(number "1" (effects (font (size 1.27 1.27))))
)
(pin passive line (at 0 -3.81 90) (length 1.27)
(name "~" (effects (font (size 1.27 1.27))))
(number "2" (effects (font (size 1.27 1.27))))
)
)
)
)
(symbol (lib_id "Device:R") (at 139.7 80.01 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f3bbcff)
(property "Reference" "R3" (id 0) (at 141.478 78.8416 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Value" "1m" (id 1) (at 141.478 81.153 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "" (id 2) (at 137.922 80.01 90)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "~" (id 3) (at 139.7 80.01 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid c8dca1a6-f09a-4305-804d-2295b5448f55))
(pin "2" (uuid 4dec140a-3f2f-4b17-b6f0-89a0fc1cf30b))
)
)

View File

@ -0,0 +1,470 @@
(kicad_sch (version 20211123) (generator eeschema)
(uuid 5b2b5c7d-f943-4634-9f0a-e9561705c49d)
(paper "A4")
(title_block
(title "")
(date "")
(rev "")
(company "")
(comment 1 "")
(comment 2 "")
(comment 3 "")
(comment 4 "")
(comment 5 "")
(comment 6 "")
(comment 7 "")
(comment 8 "")
(comment 9 "")
)
(lib_symbols
(symbol "74xx:74LS04" (in_bom yes) (on_board yes)
(property "Reference" "U" (id 0) (at 0 1.27 0)
(effects (font (size 1.27 1.27)))
)
(property "Value" "74LS04" (id 1) (at 0 -1.27 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (id 2) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_locked" "" (id 4) (at 0 0 0)
(effects (font (size 1.27 1.27)))
)
(property "ki_keywords" "TTL not inv" (id 5) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Hex Inverter" (id 6) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_fp_filters" "DIP*W7.62mm* SSOP?14* TSSOP?14*" (id 7) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "74LS04_1_0"
(polyline
(pts
(xy -3.81 3.81)
(xy -3.81 -3.81)
(xy 3.81 0)
(xy -3.81 3.81)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
(pin input line (at -7.62 0 0) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "1" (effects (font (size 1.27 1.27))))
)
(pin output inverted (at 7.62 0 180) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "2" (effects (font (size 1.27 1.27))))
)
)
(symbol "74LS04_2_0"
(polyline
(pts
(xy -3.81 3.81)
(xy -3.81 -3.81)
(xy 3.81 0)
(xy -3.81 3.81)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
(pin input line (at -7.62 0 0) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "3" (effects (font (size 1.27 1.27))))
)
(pin output inverted (at 7.62 0 180) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "4" (effects (font (size 1.27 1.27))))
)
)
(symbol "74LS04_3_0"
(polyline
(pts
(xy -3.81 3.81)
(xy -3.81 -3.81)
(xy 3.81 0)
(xy -3.81 3.81)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
(pin input line (at -7.62 0 0) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "5" (effects (font (size 1.27 1.27))))
)
(pin output inverted (at 7.62 0 180) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "6" (effects (font (size 1.27 1.27))))
)
)
(symbol "74LS04_4_0"
(polyline
(pts
(xy -3.81 3.81)
(xy -3.81 -3.81)
(xy 3.81 0)
(xy -3.81 3.81)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
(pin output inverted (at 7.62 0 180) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "8" (effects (font (size 1.27 1.27))))
)
(pin input line (at -7.62 0 0) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "9" (effects (font (size 1.27 1.27))))
)
)
(symbol "74LS04_5_0"
(polyline
(pts
(xy -3.81 3.81)
(xy -3.81 -3.81)
(xy 3.81 0)
(xy -3.81 3.81)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
(pin output inverted (at 7.62 0 180) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "10" (effects (font (size 1.27 1.27))))
)
(pin input line (at -7.62 0 0) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "11" (effects (font (size 1.27 1.27))))
)
)
(symbol "74LS04_6_0"
(polyline
(pts
(xy -3.81 3.81)
(xy -3.81 -3.81)
(xy 3.81 0)
(xy -3.81 3.81)
)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
(pin output inverted (at 7.62 0 180) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "12" (effects (font (size 1.27 1.27))))
)
(pin input line (at -7.62 0 0) (length 3.81)
(name "~" (effects (font (size 1.27 1.27))))
(number "13" (effects (font (size 1.27 1.27))))
)
)
(symbol "74LS04_7_0"
(pin power_in line (at 0 12.7 270) (length 5.08)
(name "VCC" (effects (font (size 1.27 1.27))))
(number "14" (effects (font (size 1.27 1.27))))
)
(pin power_in line (at 0 -12.7 90) (length 5.08)
(name "GND" (effects (font (size 1.27 1.27))))
(number "7" (effects (font (size 1.27 1.27))))
)
)
(symbol "74LS04_7_1"
(rectangle (start -5.08 7.62) (end 5.08 -7.62)
(stroke (width 0.254) (type default) (color 0 0 0 0))
(fill (type background))
)
)
)
(symbol "power:GND" (power) (pin_names (offset 0)) (in_bom yes) (on_board yes)
(property "Reference" "#PWR" (id 0) (at 0 -6.35 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Value" "GND" (id 1) (at 0 -3.81 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (id 2) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (id 3) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "power-flag" (id 4) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Power symbol creates a global label with name \"GND\" , ground" (id 5) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "GND_0_1"
(polyline
(pts
(xy 0 0)
(xy 0 -1.27)
(xy 1.27 -1.27)
(xy 0 -2.54)
(xy -1.27 -1.27)
(xy 0 -1.27)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(fill (type none))
)
)
(symbol "GND_1_1"
(pin power_in line (at 0 0 270) (length 0) hide
(name "GND" (effects (font (size 1.27 1.27))))
(number "1" (effects (font (size 1.27 1.27))))
)
)
)
(symbol "power:VCC" (power) (pin_names (offset 0)) (in_bom yes) (on_board yes)
(property "Reference" "#PWR" (id 0) (at 0 -3.81 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Value" "VCC" (id 1) (at 0 3.81 0)
(effects (font (size 1.27 1.27)))
)
(property "Footprint" "" (id 2) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (id 3) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_keywords" "power-flag" (id 4) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "ki_description" "Power symbol creates a global label with name \"VCC\"" (id 5) (at 0 0 0)
(effects (font (size 1.27 1.27)) hide)
)
(symbol "VCC_0_1"
(polyline
(pts
(xy -0.762 1.27)
(xy 0 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(fill (type none))
)
(polyline
(pts
(xy 0 0)
(xy 0 2.54)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(fill (type none))
)
(polyline
(pts
(xy 0 2.54)
(xy 0.762 1.27)
)
(stroke (width 0) (type default) (color 0 0 0 0))
(fill (type none))
)
)
(symbol "VCC_1_1"
(pin power_in line (at 0 0 90) (length 0) hide
(name "VCC" (effects (font (size 1.27 1.27))))
(number "1" (effects (font (size 1.27 1.27))))
)
)
)
)
(wire (pts (xy 104.14 63.5) (xy 106.68 63.5))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 10109f84-4940-47f8-8640-91f185ac9bc1)
)
(wire (pts (xy 175.26 63.5) (xy 177.8 63.5))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 47baf4b1-0938-497d-88f9-671136aa8be7)
)
(wire (pts (xy 121.92 63.5) (xy 124.46 63.5))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid 55e740a3-0735-4744-896e-2bf5437093b9)
)
(wire (pts (xy 157.48 63.5) (xy 160.02 63.5))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid c022004a-c968-410e-b59e-fbab0e561e9d)
)
(wire (pts (xy 193.04 63.5) (xy 195.58 63.5))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid e615f7aa-337e-474d-9615-2ad82b1c44ca)
)
(wire (pts (xy 85.09 63.5) (xy 88.9 63.5))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid ef8fe2ac-6a7f-4682-9418-b801a1b10a3b)
)
(wire (pts (xy 139.7 63.5) (xy 142.24 63.5))
(stroke (width 0) (type default) (color 0 0 0 0))
(uuid f4f99e3d-7269-4f6a-a759-16ad2a258779)
)
(hierarchical_label "IN" (shape input) (at 85.09 63.5 180)
(effects (font (size 1.27 1.27)) (justify right))
(uuid 4fb02e58-160a-4a39-9f22-d0c75e82ee72)
)
(hierarchical_label "OUT" (shape output) (at 195.58 63.5 0)
(effects (font (size 1.27 1.27)) (justify left))
(uuid 77ed3941-d133-4aef-a9af-5a39322d14eb)
)
(symbol (lib_id "74xx:74LS04") (at 96.52 63.5 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f34307a)
(property "Reference" "U1" (id 0) (at 96.52 55.4482 0))
(property "Value" "74LS04" (id 1) (at 96.52 57.7596 0))
(property "Footprint" "" (id 2) (at 96.52 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 96.52 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid f1e9ac99-f8d4-4d05-beb3-290dccb8d277))
(pin "2" (uuid 014c98b2-ac35-4831-825d-74c6fa5ddc67))
)
(symbol (lib_id "74xx:74LS04") (at 114.3 63.5 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f344a0e)
(property "Reference" "U1" (id 0) (at 114.3 55.4482 0))
(property "Value" "74LS04" (id 1) (at 114.3 57.7596 0))
(property "Footprint" "" (id 2) (at 114.3 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 114.3 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "3" (uuid c1630947-26ec-4031-96dd-f1cdf939d3a7))
(pin "4" (uuid e2858b6c-d9d5-4bfd-a26d-d7110c9ff81c))
)
(symbol (lib_id "74xx:74LS04") (at 132.08 63.5 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f345e39)
(property "Reference" "U1" (id 0) (at 132.08 55.4482 0))
(property "Value" "74LS04" (id 1) (at 132.08 57.7596 0))
(property "Footprint" "" (id 2) (at 132.08 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 132.08 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "5" (uuid 9a609661-5895-4db4-a600-14bffdacc16e))
(pin "6" (uuid f6c777f1-b4a6-4529-9b29-67dfedcb1744))
)
(symbol (lib_id "74xx:74LS04") (at 149.86 63.5 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f346e8b)
(property "Reference" "U1" (id 0) (at 149.86 55.4482 0))
(property "Value" "74LS04" (id 1) (at 149.86 57.7596 0))
(property "Footprint" "" (id 2) (at 149.86 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 149.86 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "8" (uuid 47d49bdd-bacb-468f-bcfb-647fd9ccff38))
(pin "9" (uuid 71c84a4a-5d81-46df-a82f-84ff433708b7))
)
(symbol (lib_id "74xx:74LS04") (at 167.64 63.5 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f348270)
(property "Reference" "U1" (id 0) (at 167.64 55.4482 0))
(property "Value" "74LS04" (id 1) (at 167.64 57.7596 0))
(property "Footprint" "" (id 2) (at 167.64 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 167.64 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "10" (uuid 01fec0dc-78cf-4a7d-851f-e24a9edd4a86))
(pin "11" (uuid 92e30d01-6115-49a3-bead-4b8b74d533c9))
)
(symbol (lib_id "74xx:74LS04") (at 185.42 63.5 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f348d95)
(property "Reference" "U1" (id 0) (at 185.42 55.4482 0))
(property "Value" "74LS04" (id 1) (at 185.42 57.7596 0))
(property "Footprint" "" (id 2) (at 185.42 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 185.42 63.5 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "12" (uuid b9a8ff4c-342a-4f44-bfb4-1b1895e9679b))
(pin "13" (uuid 29941c34-ddd5-4a9c-bdef-5bf81398f604))
)
(symbol (lib_id "74xx:74LS04") (at 139.7 88.9 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f34a12f)
(property "Reference" "U1" (id 0) (at 145.542 87.7316 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Value" "74LS04" (id 1) (at 145.542 90.043 0)
(effects (font (size 1.27 1.27)) (justify left))
)
(property "Footprint" "" (id 2) (at 139.7 88.9 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "http://www.ti.com/lit/gpn/sn74LS04" (id 3) (at 139.7 88.9 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "14" (uuid bf0862f0-7b4d-4da4-a5e8-91a9bdbee56f))
(pin "7" (uuid 0639e567-d45a-4c84-98fa-a167b211ae20))
)
(symbol (lib_id "power:VCC") (at 139.7 76.2 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f34bc05)
(property "Reference" "#PWR?" (id 0) (at 139.7 80.01 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Value" "VCC" (id 1) (at 140.081 71.8058 0))
(property "Footprint" "" (id 2) (at 139.7 76.2 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (id 3) (at 139.7 76.2 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 0030af45-9cbd-4108-9b0f-2e3885996ada))
)
(symbol (lib_id "power:GND") (at 139.7 101.6 0)
(in_bom yes) (on_board yes)
(uuid 00000000-0000-0000-0000-00005f34c535)
(property "Reference" "#PWR?" (id 0) (at 139.7 107.95 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Value" "GND" (id 1) (at 139.827 105.9942 0))
(property "Footprint" "" (id 2) (at 139.7 101.6 0)
(effects (font (size 1.27 1.27)) hide)
)
(property "Datasheet" "" (id 3) (at 139.7 101.6 0)
(effects (font (size 1.27 1.27)) hide)
)
(pin "1" (uuid 03d3f3dc-57cc-4a5d-b588-5d7b6cd2d907))
)
(sheet (at 114.3 127) (size 25.4 12.7) (fields_autoplaced)
(stroke (width 0) (type solid) (color 0 0 0 0))
(fill (color 0 0 0 0.0))
(uuid 00000000-0000-0000-0000-00005f3bb8bb)
(property "Sheet name" "Deeper test" (id 0) (at 114.3 126.2884 0)
(effects (font (size 1.27 1.27)) (justify left bottom))
)
(property "Sheet file" "deeper.kicad_sch" (id 1) (at 114.3 140.2846 0)
(effects (font (size 1.27 1.27)) (justify left top))
)
)
)

File diff suppressed because it is too large Load Diff

View File

@ -30,6 +30,7 @@ pytest-3 --log-cli-level debug
import os
import sys
import re
import shutil
import logging
import subprocess
@ -1012,3 +1013,31 @@ def test_board_view_1(test_dir):
ctx.expect_out_file(o)
ctx.compare_txt(o)
ctx.clean_up()
def test_annotate_power_1(test_dir):
prj = 'test_v5'
ctx = context.TestContextSCH(test_dir, 'test_annotate_power_1', prj, 'annotate_power', POS_DIR)
# Copy test_v5 schematic, but replacing all #PWRxx references by #PWR?
sch_file = os.path.basename(ctx.sch_file)
sch_base = ctx.get_out_path(sch_file)
with open(ctx.sch_file, 'rt') as f:
text = f.read()
text = re.sub(r'#(PWR|FLG)\d+', r'#\1?', text)
with open(sch_base, 'wt') as f:
f.write(text)
# deeper
sch_file = 'deeper'+context.KICAD_SCH_EXT
shutil.copy2(os.path.abspath(os.path.join(ctx.get_board_dir(), sch_file)), ctx.get_out_path(sch_file))
# sub-sheet
sch_file = 'sub-sheet'+context.KICAD_SCH_EXT
with open(os.path.abspath(os.path.join(ctx.get_board_dir(), sch_file)), 'rt') as f:
text = f.read()
text = re.sub(r'#(PWR|FLG)\d+', r'#\1?', text)
with open(ctx.get_out_path(sch_file), 'wt') as f:
f.write(text)
ctx.run(extra=['-e', sch_base], no_board_file=True)
ctx.compare_txt('test_v5'+context.KICAD_SCH_EXT)
ctx.compare_txt('deeper'+context.KICAD_SCH_EXT)
ctx.compare_txt('sub-sheet'+context.KICAD_SCH_EXT)
ctx.clean_up()

View File

@ -0,0 +1,7 @@
# Example KiBot config file
kibot:
version: 1
preflight:
annotate_power: true