[v6/7 Schematic] Hierarchy expanded only if needed

This commit is contained in:
Salvador E. Tropea 2023-04-28 10:45:38 -03:00
parent fea0d04e87
commit a05be2240e
10 changed files with 1425 additions and 1635 deletions

View File

@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.6.3] - UNRELEASED
### Changed
- KiCad v6/7 schematic:
- The hierarchy is expanded only if needed, i.e. value of an instance changed
### Fixed
- KiCad v6/7 schematic:
- Net Class Flags not saved in variants or annotated schematics

View File

@ -1974,7 +1974,60 @@ class SchematicV6(Schematic):
def check_exp_hierarchy(self):
""" Check if we really need to expand the hierarchy """
# KiCad v6: we can change the value and footprint, but won't work when imported by v7
return True
# Collect component instances (UUID -> list of instances)
instances = {}
for s in self.symbol_instances:
c_uuid = os.path.basename(s.path)
instances.setdefault(c_uuid, []).append(s.component)
# Look for variants in the instances
for _, l_ins in instances.items():
if len(l_ins) < 2:
# 0 or 1 can't be different
continue
ref_c = l_ins[0]
if any(map(lambda c: self.compare_component(ref_c, c), l_ins[1:])):
return True
# No variant
return False
@staticmethod
def compare_component(r, c):
""" Returns True if the components need separated instances (are different) """
if len(r.dfields) != len(c.dfields):
SchematicV6.log_difference(r, c, 'list of field names {} vs {}'.format(len(r.dfields), len(c.dfields)))
return True
for name, field in r.dfields.items():
if name == 'reference':
continue
field2 = c.dfields.get(name)
if field2 is None:
SchematicV6.log_difference(r, c, 'field `{}` not in the second'.format(name))
if field.value != field2.value:
SchematicV6.log_difference(r, c, '`{}` fields (`{}` != `{}`)'.format(name, field.value, field2.value))
return True
if c.fitted != r.fitted:
SchematicV6.log_difference(r, c, 'fitted status')
return True
if c.included != r.included:
SchematicV6.log_difference(r, c, 'included status')
return True
if c.fixed != r.fixed:
SchematicV6.log_difference(r, c, 'fixed status')
return True
if c.fixed != r.fixed:
SchematicV6.log_difference(r, c, 'fixed status')
return True
if c.in_bom != r.in_bom:
SchematicV6.log_difference(r, c, 'in_bom status')
return True
if c.on_board != r.on_board:
SchematicV6.log_difference(r, c, 'on_board status')
return True
return False
@staticmethod
def log_difference(r, c, msg):
logger.debug('Expanding hierarchy because {} and {} has different {}'.format(r.ref, c.ref, msg))
def _create_flat_name(self, sch):
""" Create a unique name that doesn't contain subdirs.

View File

@ -7,7 +7,7 @@
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
width="29.700220cm" height="21.000720cm" viewBox="0 0 116930 82680">
<title>SVG Picture created as test_v5.svg date 2022/10/14 10:37:51 </title>
<title>SVG Picture created as test_v5.svg date 2023/04/28 13:38:14 </title>
<desc>Picture generated by Eeschema-SVG </desc>
<g style="fill:#000000; fill-opacity:1.000000;stroke:#000000; stroke-opacity:1.000000;
stroke-linecap:round; stroke-linejoin:round;"
@ -660,9 +660,9 @@ L87319 76293
L112205 76577
" />
<text x="70079.606299" y="77424.094488"
textLength="21826.023622" font-size="787.401575" lengthAdjust="spacingAndGlyphs"
text-anchor="start" opacity="0">KiCad E.D.A. eeschema 6.0.8+dfsg-1~bpo11+1</text>
<g class="stroked-text"><desc>KiCad E.D.A. eeschema 6.0.8+dfsg-1~bpo11+1</desc>
textLength="22388.464567" font-size="787.401575" lengthAdjust="spacingAndGlyphs"
text-anchor="start" opacity="0">KiCad E.D.A. eeschema 6.0.11+dfsg-1~bpo11+1</text>
<g class="stroked-text"><desc>KiCad E.D.A. eeschema 6.0.11+dfsg-1~bpo11+1</desc>
<path d="M70250 77395
L70250 76805
" />
@ -962,185 +962,161 @@ L82792 77367
L82820 77339
L82820 77395
" />
<path d="M83186 77058
L83129 77030
L83101 77002
L83073 76946
L83073 76917
L83101 76861
L83129 76833
L83186 76805
L83298 76805
L83354 76833
L83382 76861
L83411 76917
L83411 76946
L83382 77002
L83354 77030
L83298 77058
L83186 77058
L83129 77086
L83101 77114
L83073 77170
L83073 77283
L83101 77339
L83129 77367
L83186 77395
L83298 77395
L83354 77367
L83382 77339
L83411 77283
L83411 77170
L83382 77114
L83354 77086
L83298 77058
<path d="M83411 77395
L83073 77395
" />
<path d="M83664 77170
L84114 77170
<path d="M83242 77395
L83242 76805
L83186 76889
L83129 76946
L83073 76974
" />
<path d="M83889 77395
L83889 76946
<path d="M83973 77395
L83636 77395
" />
<path d="M84648 77395
L84648 76805
<path d="M83804 77395
L83804 76805
L83748 76889
L83692 76946
L83636 76974
" />
<path d="M84648 77367
L84592 77395
L84479 77395
L84423 77367
L84395 77339
L84367 77283
L84367 77114
L84395 77058
L84423 77030
L84479 77002
L84592 77002
L84648 77030
<path d="M84226 77170
L84676 77170
" />
<path d="M84845 77002
L85070 77002
<path d="M84451 77395
L84451 76946
" />
<path d="M84929 77395
L84929 76889
L84957 76833
L85013 76805
L85070 76805
<path d="M85210 77395
L85210 76805
" />
<path d="M85238 77367
L85295 77395
L85407 77395
L85463 77367
L85492 77311
L85492 77283
L85463 77227
L85407 77199
L85323 77199
L85267 77170
L85238 77114
L85238 77086
L85267 77030
L85323 77002
L85407 77002
L85463 77030
<path d="M85210 77367
L85154 77395
L85042 77395
L84985 77367
L84957 77339
L84929 77283
L84929 77114
L84957 77058
L84985 77030
L85042 77002
L85154 77002
L85210 77030
" />
<path d="M85998 77002
L85998 77480
L85970 77536
L85941 77564
L85885 77592
L85801 77592
L85745 77564
<path d="M85407 77002
L85632 77002
" />
<path d="M85998 77367
L85941 77395
L85829 77395
L85773 77367
L85745 77339
L85717 77283
L85717 77114
L85745 77058
L85773 77030
L85829 77002
L85941 77002
L85998 77030
<path d="M85492 77395
L85492 76889
L85520 76833
L85576 76805
L85632 76805
" />
<path d="M86279 77170
L86729 77170
<path d="M85801 77367
L85857 77395
L85970 77395
L86026 77367
L86054 77311
L86054 77283
L86026 77227
L85970 77199
L85885 77199
L85829 77170
L85801 77114
L85801 77086
L85829 77030
L85885 77002
L85970 77002
L86026 77030
" />
<path d="M87319 77395
L86982 77395
<path d="M86560 77002
L86560 77480
L86532 77536
L86504 77564
L86448 77592
L86363 77592
L86307 77564
" />
<path d="M87151 77395
L87151 76805
L87094 76889
L87038 76946
L86982 76974
<path d="M86560 77367
L86504 77395
L86391 77395
L86335 77367
L86307 77339
L86279 77283
L86279 77114
L86307 77058
L86335 77030
L86391 77002
L86504 77002
L86560 77030
" />
<path d="M87488 77170
L87516 77142
L87573 77114
L87685 77170
L87741 77142
L87769 77114
<path d="M86841 77170
L87291 77170
" />
<path d="M87994 77395
L87994 76805
<path d="M87882 77395
L87544 77395
" />
<path d="M87994 77030
L88051 77002
L88163 77002
L88219 77030
L88247 77058
L88276 77114
L88276 77283
L88247 77339
L88219 77367
L88163 77395
L88051 77395
L87994 77367
<path d="M87713 77395
L87713 76805
L87657 76889
L87601 76946
L87544 76974
" />
<path d="M88529 77002
L88529 77592
<path d="M88051 77170
L88079 77142
L88135 77114
L88247 77170
L88304 77142
L88332 77114
" />
<path d="M88529 77030
L88585 77002
L88697 77002
L88754 77030
L88782 77058
L88810 77114
L88810 77283
L88782 77339
L88754 77367
L88697 77395
L88585 77395
L88529 77367
<path d="M88557 77395
L88557 76805
" />
<path d="M89147 77395
L89091 77367
L89063 77339
L89035 77283
L89035 77114
L89063 77058
L89091 77030
<path d="M88557 77030
L88613 77002
L88726 77002
L88782 77030
L88810 77058
L88838 77114
L88838 77283
L88810 77339
L88782 77367
L88726 77395
L88613 77395
L88557 77367
" />
<path d="M89091 77002
L89091 77592
" />
<path d="M89091 77030
L89147 77002
L89232 77002
L89288 77030
L89316 77058
L89344 77114
L89344 77283
L89316 77339
L89288 77367
L89232 77395
L89260 77002
L89316 77030
L89344 77058
L89372 77114
L89372 77283
L89344 77339
L89316 77367
L89260 77395
L89147 77395
L89091 77367
" />
<path d="M89907 77395
L89569 77395
" />
<path d="M89738 77395
L89738 76805
L89682 76889
L89625 76946
L89569 76974
<path d="M89710 77395
L89654 77367
L89625 77339
L89597 77283
L89597 77114
L89625 77058
L89654 77030
L89710 77002
L89794 77002
L89850 77030
L89878 77058
L89907 77114
L89907 77283
L89878 77339
L89850 77367
L89794 77395
L89710 77395
" />
<path d="M90469 77395
L90132 77395
@ -1151,20 +1127,29 @@ L90244 76889
L90188 76946
L90132 76974
" />
<path d="M90722 77170
L91172 77170
<path d="M91031 77395
L90694 77395
" />
<path d="M90947 77395
L90947 76946
<path d="M90863 77395
L90863 76805
L90807 76889
L90750 76946
L90694 76974
" />
<path d="M91763 77395
L91425 77395
<path d="M91285 77170
L91735 77170
" />
<path d="M91594 77395
L91594 76805
L91538 76889
L91481 76946
L91425 76974
<path d="M91510 77395
L91510 76946
" />
<path d="M92325 77395
L91988 77395
" />
<path d="M92156 77395
L92156 76805
L92100 76889
L92044 76946
L91988 76974
" />
</g><path d="M69685 75396
L112205 75396
@ -3980,10 +3965,10 @@ L43816 29543
<g style="fill:#725600; fill-opacity:0.0;
stroke:#725600; stroke-width:60.000000; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round;">
<text x="45352.677165" y="35882.637795"
textLength="10702.874016" font-size="666.653543" lengthAdjust="spacingAndGlyphs"
text-anchor="middle" opacity="0">File: sub-sheet_1.kicad_sch</text>
<g class="stroked-text"><desc>File: sub-sheet_1.kicad_sch</desc>
<text x="44924.094488" y="35882.637795"
textLength="9845.708661" font-size="666.653543" lengthAdjust="spacingAndGlyphs"
text-anchor="middle" opacity="0">File: sub-sheet.kicad_sch</text>
<g class="stroked-text"><desc>File: sub-sheet.kicad_sch</desc>
<path d="M40316 35596
L40150 35596
" />
@ -4146,134 +4131,122 @@ L45793 35835
L45840 35858
L45888 35858
" />
<path d="M45935 35906
L46316 35906
<path d="M46055 35811
L46078 35835
L46055 35858
L46031 35835
L46055 35811
L46055 35858
" />
<path d="M46293 35858
L46293 35358
" />
<path d="M46340 35668
L46483 35858
" />
<path d="M46483 35525
L46293 35715
" />
<path d="M46697 35858
L46412 35858
L46697 35525
" />
<path d="M46555 35858
L46555 35358
L46507 35430
L46459 35477
L46412 35501
<path d="M46697 35358
L46674 35382
L46697 35406
L46721 35382
L46697 35358
L46697 35406
" />
<path d="M46912 35811
L46935 35835
L46912 35858
L46888 35835
L46912 35811
L46912 35858
<path d="M47150 35835
L47102 35858
L47007 35858
L46959 35835
L46935 35811
L46912 35763
L46912 35620
L46935 35573
L46959 35549
L47007 35525
L47102 35525
L47150 35549
" />
<path d="M47150 35858
L47150 35358
<path d="M47578 35858
L47578 35596
L47555 35549
L47507 35525
L47412 35525
L47364 35549
" />
<path d="M47197 35668
L47340 35858
<path d="M47578 35835
L47531 35858
L47412 35858
L47364 35835
L47340 35787
L47340 35739
L47364 35692
L47412 35668
L47531 35668
L47578 35644
" />
<path d="M47340 35525
L47150 35715
<path d="M48031 35858
L48031 35358
" />
<path d="M47555 35858
L47555 35525
<path d="M48031 35835
L47983 35858
L47888 35858
L47840 35835
L47816 35811
L47793 35763
L47793 35620
L47816 35573
L47840 35549
L47888 35525
L47983 35525
L48031 35549
" />
<path d="M47555 35358
L47531 35382
L47555 35406
L47578 35382
L47555 35358
L47555 35406
<path d="M48150 35906
L48531 35906
" />
<path d="M48007 35835
L47959 35858
L47864 35858
L47816 35835
L47793 35811
L47769 35763
L47769 35620
L47793 35573
L47816 35549
L47864 35525
L47959 35525
L48007 35549
<path d="M48626 35835
L48674 35858
L48769 35858
L48816 35835
L48840 35787
L48840 35763
L48816 35715
L48769 35692
L48697 35692
L48650 35668
L48626 35620
L48626 35596
L48650 35549
L48697 35525
L48769 35525
L48816 35549
" />
<path d="M48435 35858
L48435 35596
L48412 35549
L48364 35525
L48269 35525
L48221 35549
<path d="M49269 35835
L49221 35858
L49126 35858
L49078 35835
L49055 35811
L49031 35763
L49031 35620
L49055 35573
L49078 35549
L49126 35525
L49221 35525
L49269 35549
" />
<path d="M48435 35835
L48388 35858
L48269 35858
L48221 35835
L48197 35787
L48197 35739
L48221 35692
L48269 35668
L48388 35668
L48435 35644
<path d="M49483 35858
L49483 35358
" />
<path d="M48888 35858
L48888 35358
" />
<path d="M48888 35835
L48840 35858
L48745 35858
L48697 35835
L48674 35811
L48650 35763
L48650 35620
L48674 35573
L48697 35549
L48745 35525
L48840 35525
L48888 35549
" />
<path d="M49007 35906
L49388 35906
" />
<path d="M49483 35835
L49531 35858
L49626 35858
L49674 35835
L49697 35787
L49697 35763
L49674 35715
L49626 35692
L49555 35692
L49507 35668
L49483 35620
L49483 35596
L49507 35549
L49555 35525
L49626 35525
<path d="M49697 35858
L49697 35596
L49674 35549
" />
<path d="M50126 35835
L50078 35858
L49983 35858
L49935 35835
L49912 35811
L49888 35763
L49888 35620
L49912 35573
L49935 35549
L49983 35525
L50078 35525
L50126 35549
" />
<path d="M50340 35858
L50340 35358
" />
<path d="M50555 35858
L50555 35596
L50531 35549
L50483 35525
L50412 35525
L50364 35549
L50340 35573
L49626 35525
L49555 35525
L49507 35549
L49483 35573
" />
</g></g>
<g style="fill:#FFFFFF; fill-opacity:0.0;
@ -4503,10 +4476,10 @@ L44626 37543
<g style="fill:#725600; fill-opacity:0.0;
stroke:#725600; stroke-width:60.000000; stroke-opacity:1;
stroke-linecap:round; stroke-linejoin:round;">
<text x="45352.677165" y="43882.637795"
textLength="10702.874016" font-size="666.653543" lengthAdjust="spacingAndGlyphs"
text-anchor="middle" opacity="0">File: sub-sheet_2.kicad_sch</text>
<g class="stroked-text"><desc>File: sub-sheet_2.kicad_sch</desc>
<text x="44924.094488" y="43882.637795"
textLength="9845.708661" font-size="666.653543" lengthAdjust="spacingAndGlyphs"
text-anchor="middle" opacity="0">File: sub-sheet.kicad_sch</text>
<g class="stroked-text"><desc>File: sub-sheet.kicad_sch</desc>
<path d="M40316 43596
L40150 43596
" />
@ -4669,137 +4642,122 @@ L45793 43835
L45840 43858
L45888 43858
" />
<path d="M45935 43906
L46316 43906
<path d="M46055 43811
L46078 43835
L46055 43858
L46031 43835
L46055 43811
L46055 43858
" />
<path d="M46412 43406
L46435 43382
L46483 43358
L46602 43358
L46650 43382
L46674 43406
L46697 43454
L46697 43501
L46674 43573
L46388 43858
L46697 43858
<path d="M46293 43858
L46293 43358
" />
<path d="M46912 43811
L46935 43835
L46912 43858
L46888 43835
L46912 43811
L46912 43858
<path d="M46340 43668
L46483 43858
" />
<path d="M47150 43858
L47150 43358
<path d="M46483 43525
L46293 43715
" />
<path d="M47197 43668
L47340 43858
<path d="M46697 43858
L46697 43525
" />
<path d="M47340 43525
L47150 43715
<path d="M46697 43358
L46674 43382
L46697 43406
L46721 43382
L46697 43358
L46697 43406
" />
<path d="M47555 43858
L47555 43525
<path d="M47150 43835
L47102 43858
L47007 43858
L46959 43835
L46935 43811
L46912 43763
L46912 43620
L46935 43573
L46959 43549
L47007 43525
L47102 43525
L47150 43549
" />
<path d="M47555 43358
L47531 43382
L47555 43406
L47578 43382
L47555 43358
L47555 43406
<path d="M47578 43858
L47578 43596
L47555 43549
L47507 43525
L47412 43525
L47364 43549
" />
<path d="M48007 43835
L47959 43858
L47864 43858
L47816 43835
L47793 43811
L47769 43763
L47769 43620
L47793 43573
L47816 43549
L47864 43525
L47959 43525
L48007 43549
<path d="M47578 43835
L47531 43858
L47412 43858
L47364 43835
L47340 43787
L47340 43739
L47364 43692
L47412 43668
L47531 43668
L47578 43644
" />
<path d="M48435 43858
L48435 43596
L48412 43549
L48364 43525
L48269 43525
L48221 43549
<path d="M48031 43858
L48031 43358
" />
<path d="M48435 43835
L48388 43858
L48269 43858
L48221 43835
L48197 43787
L48197 43739
L48221 43692
L48269 43668
L48388 43668
L48435 43644
<path d="M48031 43835
L47983 43858
L47888 43858
L47840 43835
L47816 43811
L47793 43763
L47793 43620
L47816 43573
L47840 43549
L47888 43525
L47983 43525
L48031 43549
" />
<path d="M48888 43858
L48888 43358
<path d="M48150 43906
L48531 43906
" />
<path d="M48888 43835
L48840 43858
L48745 43858
L48697 43835
L48674 43811
L48650 43763
L48650 43620
L48674 43573
L48697 43549
L48745 43525
L48840 43525
L48888 43549
<path d="M48626 43835
L48674 43858
L48769 43858
L48816 43835
L48840 43787
L48840 43763
L48816 43715
L48769 43692
L48697 43692
L48650 43668
L48626 43620
L48626 43596
L48650 43549
L48697 43525
L48769 43525
L48816 43549
" />
<path d="M49007 43906
L49388 43906
<path d="M49269 43835
L49221 43858
L49126 43858
L49078 43835
L49055 43811
L49031 43763
L49031 43620
L49055 43573
L49078 43549
L49126 43525
L49221 43525
L49269 43549
" />
<path d="M49483 43835
L49531 43858
L49626 43858
L49674 43835
L49697 43787
L49697 43763
L49674 43715
L49626 43692
L49555 43692
L49507 43668
L49483 43620
L49483 43596
L49507 43549
L49555 43525
L49626 43525
<path d="M49483 43858
L49483 43358
" />
<path d="M49697 43858
L49697 43596
L49674 43549
" />
<path d="M50126 43835
L50078 43858
L49983 43858
L49935 43835
L49912 43811
L49888 43763
L49888 43620
L49912 43573
L49935 43549
L49983 43525
L50078 43525
L50126 43549
" />
<path d="M50340 43858
L50340 43358
" />
<path d="M50555 43858
L50555 43596
L50531 43549
L50483 43525
L50412 43525
L50364 43549
L50340 43573
L49626 43525
L49555 43525
L49507 43549
L49483 43573
" />
</g><g >
</g>

Before

Width:  |  Height:  |  Size: 183 KiB

After

Width:  |  Height:  |  Size: 183 KiB

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 386 KiB

After

Width:  |  Height:  |  Size: 382 KiB